1
2
3
4
5
6
7 package org.mule.construct;
8
9 import org.mule.api.MuleEvent;
10 import org.mule.component.AbstractComponent;
11 import org.mule.construct.SimpleService.Type;
12 import org.mule.tck.MuleTestUtils;
13 import org.mule.util.StringUtils;
14
15 import org.junit.Test;
16
17 import static org.junit.Assert.assertEquals;
18
19 public class SimpleServiceTestCase extends AbstractFlowConstuctTestCase
20 {
21 private SimpleService simpleService;
22
23 @Override
24 protected void doSetUp() throws Exception
25 {
26 super.doSetUp();
27
28 simpleService = new SimpleService("test-simple-service", muleContext, directInboundMessageSource,
29 new StringReverserComponent(), Type.DIRECT);
30 }
31
32 @Override
33 protected AbstractFlowConstruct getFlowConstruct()
34 {
35 return simpleService;
36 }
37
38 @Test
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 }