1
2
3
4
5
6
7
8
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 }