View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.processor;
8   
9   import org.mule.MessageExchangePattern;
10  import org.mule.api.MuleEvent;
11  import org.mule.api.processor.MessageProcessor;
12  import org.mule.api.transaction.Transaction;
13  import org.mule.tck.testmodels.mule.TestTransaction;
14  import org.mule.transaction.TransactionCoordination;
15  
16  import java.beans.ExceptionListener;
17  
18  import org.junit.Test;
19  
20  public class OptionalAsyncInterceptingMessageProcessorTestCase extends
21      AsyncInterceptingMessageProcessorTestCase implements ExceptionListener
22  {
23  
24      @Override
25      @Test
26      public void testProcessRequestResponse() throws Exception
27      {
28          MuleEvent event = getTestEvent(TEST_MESSAGE,
29              getTestInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE));
30  
31          assertSync(messageProcessor, event);
32      }
33  
34      @Override
35      @Test
36      public void testProcessOneWay() throws Exception
37      {
38          MuleEvent event = getTestEvent(TEST_MESSAGE, getTestInboundEndpoint(MessageExchangePattern.ONE_WAY));
39  
40          assertAsync(messageProcessor, event);
41      }
42  
43      @Override
44      @Test
45      public void testProcessOneWayWithTx() throws Exception
46      {
47          MuleEvent event = getTestEvent(TEST_MESSAGE,
48              getTestTransactedInboundEndpoint(MessageExchangePattern.ONE_WAY));
49          Transaction transaction = new TestTransaction(muleContext);
50          TransactionCoordination.getInstance().bindTransaction(transaction);
51  
52          try
53          {
54              assertSync(messageProcessor, event);
55          }
56          finally
57          {
58              TransactionCoordination.getInstance().unbindTransaction(transaction);
59          }
60      }
61  
62      @Override
63      @Test
64      public void testProcessRequestResponseWithTx() throws Exception
65      {
66          MuleEvent event = getTestEvent(TEST_MESSAGE,
67              getTestTransactedInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE));
68          Transaction transaction = new TestTransaction(muleContext);
69          TransactionCoordination.getInstance().bindTransaction(transaction);
70  
71          try
72          {
73              assertSync(messageProcessor, event);
74          }
75          finally
76          {
77              TransactionCoordination.getInstance().unbindTransaction(transaction);
78          }
79      }
80  
81      @Override
82      protected AsyncInterceptingMessageProcessor createAsyncInterceptingMessageProcessor(MessageProcessor listener)
83          throws Exception
84      {
85          AsyncInterceptingMessageProcessor mp = new OptionalAsyncInterceptingMessageProcessor(
86              new TestWorkManagerSource());
87          mp.setListener(listener);
88          return mp;
89      }
90  }