View Javadoc

1   /*
2    * $Id$
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.processor;
12  
13  import org.mule.MessageExchangePattern;
14  import org.mule.api.MuleEvent;
15  import org.mule.api.processor.MessageProcessor;
16  import org.mule.api.transaction.Transaction;
17  import org.mule.tck.testmodels.mule.TestTransaction;
18  import org.mule.transaction.TransactionCoordination;
19  
20  import java.beans.ExceptionListener;
21  
22  public class OptionalAsyncInterceptingMessageProcessorTestCase extends
23      AsyncInterceptingMessageProcessorTestCase implements ExceptionListener
24  {
25  
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      public void testProcessOneWay() throws Exception
35      {
36          MuleEvent event = getTestEvent(TEST_MESSAGE, getTestInboundEndpoint(MessageExchangePattern.ONE_WAY));
37  
38          assertAsync(messageProcessor, event);
39      }
40  
41      public void testProcessOneWayWithTx() throws Exception
42      {
43          MuleEvent event = getTestEvent(TEST_MESSAGE,
44              getTestTransactedInboundEndpoint(MessageExchangePattern.ONE_WAY));
45          Transaction transaction = new TestTransaction(muleContext);
46          TransactionCoordination.getInstance().bindTransaction(transaction);
47  
48          try
49          {
50              assertSync(messageProcessor, event);
51          }
52          finally
53          {
54              TransactionCoordination.getInstance().unbindTransaction(transaction);
55          }
56      }
57  
58      public void testProcessRequestResponseWithTx() throws Exception
59      {
60          MuleEvent event = getTestEvent(TEST_MESSAGE,
61              getTestTransactedInboundEndpoint(MessageExchangePattern.REQUEST_RESPONSE));
62          Transaction transaction = new TestTransaction(muleContext);
63          TransactionCoordination.getInstance().bindTransaction(transaction);
64  
65          try
66          {
67              assertSync(messageProcessor, event);
68          }
69          finally
70          {
71              TransactionCoordination.getInstance().unbindTransaction(transaction);
72          }
73      }
74  
75      protected AsyncInterceptingMessageProcessor createAsyncInterceptingMessageProcessor(MessageProcessor listener)
76          throws Exception
77      {
78          AsyncInterceptingMessageProcessor mp = new OptionalAsyncInterceptingMessageProcessor(
79              new TestWorkManagerSource(), true);
80          mp.setListener(listener);
81          return mp;
82      }
83  
84  }