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.endpoint.outbound;
12  
13  import org.mule.api.MuleEvent;
14  import org.mule.api.endpoint.EndpointException;
15  import org.mule.api.lifecycle.InitialisationException;
16  import org.mule.api.processor.InterceptingMessageProcessor;
17  import org.mule.api.transaction.Transaction;
18  import org.mule.endpoint.AbstractMessageProcessorTestCase;
19  import org.mule.tck.testmodels.mule.TestTransaction;
20  import org.mule.transaction.TransactionCoordination;
21  
22  public class OutboundTxRollbackMessageProcessorTestCase extends AbstractMessageProcessorTestCase
23  {
24  
25      public void testNoRollback() throws InitialisationException, EndpointException, Exception
26      {
27          InterceptingMessageProcessor mp = new OutboundTxRollbackMessageProcessor();
28          TestListener listener = new TestListener();
29          mp.setListener(listener);
30  
31          MuleEvent event = createTestOutboundEvent(createTestOutboundEndpoint(null, null));
32          mp.process(event);
33  
34          assertSame(event, listener.sensedEvent);
35      }
36  
37      public void testRollback() throws InitialisationException, EndpointException, Exception
38      {
39          InterceptingMessageProcessor mp = new OutboundTxRollbackMessageProcessor();
40          TestListener listener = new TestListener();
41          mp.setListener(listener);
42  
43          Transaction tx = new TestTransaction(muleContext);
44          try
45          {
46              TransactionCoordination.getInstance().bindTransaction(tx);
47              tx.setRollbackOnly();
48  
49              MuleEvent event = createTestOutboundEvent(createTestOutboundEndpoint(null, null));
50              MuleEvent result = mp.process(event);
51  
52              assertNull(listener.sensedEvent);
53              assertSame(result, event);
54          }
55          finally
56          {
57              TransactionCoordination.getInstance().unbindTransaction(tx);
58          }
59  
60      }
61  }