View Javadoc

1   /*
2    * $Id: SimpleServiceTestCase.java 22377 2011-07-11 12:41:42Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
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  import java.util.Collections;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  
25  public class SimpleServiceTestCase extends AbstractFlowConstuctTestCase
26  {
27      private SimpleService simpleService;
28  
29      @SuppressWarnings("unchecked")
30      @Override
31      protected void doSetUp() throws Exception
32      {
33          super.doSetUp();
34  
35          simpleService = new SimpleService("test-simple-service", muleContext, directInboundMessageSource,
36              Collections.EMPTY_LIST, Collections.EMPTY_LIST, new StringReverserComponent(), Type.DIRECT);
37      }
38  
39      @Override
40      protected AbstractFlowConstruct getFlowConstruct()
41      {
42          return simpleService;
43      }
44  
45      @Test
46      public void testProcess() throws Exception
47      {
48          simpleService.initialise();
49          simpleService.start();
50          MuleEvent response = directInboundMessageSource.process(MuleTestUtils.getTestEvent("hello",
51              muleContext));
52  
53          assertEquals("olleh", response.getMessageAsString());
54      }
55  
56      private static class StringReverserComponent extends AbstractComponent
57      {
58          @Override
59          protected Object doInvoke(MuleEvent event) throws Exception
60          {
61              return StringUtils.reverse(event.getMessageAsString());
62          }
63      }
64  }