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