View Javadoc

1   /*
2    * $Id: SimpleServiceTestCase.java 20320 2010-11-24 15:03:31Z dfeist $
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  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  }