View Javadoc

1   /*
2    * $Id: BridgeTestCase.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.MessageExchangePattern;
14  import org.mule.api.MuleEvent;
15  import org.mule.api.endpoint.OutboundEndpoint;
16  import org.mule.api.transport.Connector;
17  import org.mule.tck.MuleTestUtils;
18  
19  import java.util.Collections;
20  
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  
25  public class BridgeTestCase extends AbstractFlowConstuctTestCase
26  {
27      private Bridge bridge;
28      protected Connector testConnector;
29  
30      @SuppressWarnings("unchecked")
31      @Override
32      protected void doSetUp() throws Exception
33      {
34          super.doSetUp();
35  
36          final OutboundEndpoint testOutboundEndpoint = MuleTestUtils.getTestOutboundEndpoint(
37              MessageExchangePattern.REQUEST_RESPONSE, muleContext);
38          testConnector = testOutboundEndpoint.getConnector();
39          muleContext.getRegistry().registerConnector(testConnector);
40          testConnector.start();
41  
42          bridge = new Bridge("test-bridge", muleContext, directInboundMessageSource, testOutboundEndpoint,
43              Collections.EMPTY_LIST, Collections.EMPTY_LIST, MessageExchangePattern.REQUEST_RESPONSE, false);
44      }
45  
46      @Override
47      protected AbstractFlowConstruct getFlowConstruct() throws Exception
48      {
49          return bridge;
50      }
51  
52      @Test
53      public void testProcess() throws Exception
54      {
55          bridge.initialise();
56          bridge.start();
57          MuleEvent response = directInboundMessageSource.process(MuleTestUtils.getTestEvent("hello",
58              muleContext));
59  
60          assertEquals("hello", response.getMessageAsString());
61      }
62  }