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