View Javadoc

1   /*
2    * $Id: OutboundTxRollbackMessageProcessorTestCase.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.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  import org.junit.Test;
23  
24  import static org.junit.Assert.assertNull;
25  import static org.junit.Assert.assertSame;
26  
27  public class OutboundTxRollbackMessageProcessorTestCase extends AbstractMessageProcessorTestCase
28  {
29  
30      @Test
31      public void testNoRollback() throws InitialisationException, EndpointException, Exception
32      {
33          InterceptingMessageProcessor mp = new OutboundTxRollbackMessageProcessor();
34          TestListener listener = new TestListener();
35          mp.setListener(listener);
36  
37          MuleEvent event = createTestOutboundEvent();
38          mp.process(event);
39  
40          assertSame(event, listener.sensedEvent);
41      }
42  
43      @Test
44      public void testRollback() throws InitialisationException, EndpointException, Exception
45      {
46          InterceptingMessageProcessor mp = new OutboundTxRollbackMessageProcessor();
47          TestListener listener = new TestListener();
48          mp.setListener(listener);
49  
50          Transaction tx = new TestTransaction(muleContext);
51          try
52          {
53              TransactionCoordination.getInstance().bindTransaction(tx);
54              tx.setRollbackOnly();
55  
56              MuleEvent event = createTestOutboundEvent();
57              MuleEvent result = mp.process(event);
58  
59              assertNull(listener.sensedEvent);
60              assertSame(result, event);
61          }
62          finally
63          {
64              TransactionCoordination.getInstance().unbindTransaction(tx);
65          }
66      }
67  }