1
2
3
4
5
6
7 package org.mule.tck.functional;
8
9 import org.mule.api.MuleEventContext;
10 import org.mule.api.transaction.Transaction;
11 import org.mule.api.transaction.TransactionException;
12 import org.mule.config.i18n.MessageFactory;
13
14
15
16
17
18 public class TransactionalFunctionalTestComponent extends FunctionalTestComponent
19 {
20 private boolean expectTransaction = true;
21 private boolean rollback = true;
22
23
24 public Object onCall(MuleEventContext context) throws Exception
25 {
26 Object replyMessage = super.onCall(context);
27
28 if (expectTransaction)
29 {
30
31 Transaction currentTx = context.getCurrentTransaction();
32 if (currentTx == null || !currentTx.isBegun())
33 {
34 context.setStopFurtherProcessing(true);
35 throw new TransactionException(MessageFactory.createStaticMessage("Trying to roll back transaction but no transaction is underway."));
36 }
37
38 if (rollback)
39 {
40
41 logger.info("@@@@ Rolling back transaction @@@@");
42 currentTx.setRollbackOnly();
43 }
44 }
45
46 return replyMessage;
47 }
48
49 public boolean isRollback()
50 {
51 return rollback;
52 }
53
54 public void setRollback(boolean rollback)
55 {
56 this.rollback = rollback;
57 }
58
59 public boolean isExpectTransaction()
60 {
61 return expectTransaction;
62 }
63
64 public void setExpectTransaction(boolean expectTransaction)
65 {
66 this.expectTransaction = expectTransaction;
67 }
68 }
69