1
2
3
4
5
6
7
8
9
10
11 package org.mule.construct;
12
13 import org.mule.api.MuleEvent;
14 import org.mule.component.AbstractComponent;
15 import org.mule.construct.SimpleService.Type;
16 import org.mule.tck.MuleTestUtils;
17 import org.mule.util.StringUtils;
18
19 public class SimpleServiceTestCase extends AbstractFlowConstuctTestCase
20 {
21 private static final StringReverserComponent COMPONENT = new StringReverserComponent();
22 private SimpleService simpleService;
23
24 @Override
25 protected void doSetUp() throws Exception
26 {
27 super.doSetUp();
28
29 simpleService = new SimpleService("test-simple-service", muleContext, directInboundMessageSource,
30 COMPONENT, Type.DIRECT);
31 }
32
33 @Override
34 protected AbstractFlowConstruct getFlowConstruct()
35 {
36 return simpleService;
37 }
38
39 public void testProcess() throws Exception
40 {
41 simpleService.initialise();
42 simpleService.start();
43 MuleEvent response = directInboundMessageSource.process(MuleTestUtils.getTestInboundEvent("hello",
44 muleContext));
45
46 assertEquals("olleh", response.getMessageAsString());
47 }
48
49 private static class StringReverserComponent extends AbstractComponent
50 {
51 @Override
52 protected Object doInvoke(MuleEvent event) throws Exception
53 {
54 return StringUtils.reverse(event.getMessageAsString());
55 }
56 }
57
58 }