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 | 0 | public class TransactionalFunctionalTestComponent extends FunctionalTestComponent |
19 | |
{ |
20 | 0 | private boolean expectTransaction = true; |
21 | 0 | private boolean rollback = true; |
22 | |
|
23 | |
|
24 | |
public Object onCall(MuleEventContext context) throws Exception |
25 | |
{ |
26 | 0 | Object replyMessage = super.onCall(context); |
27 | |
|
28 | 0 | if (expectTransaction) |
29 | |
{ |
30 | |
|
31 | 0 | Transaction currentTx = context.getCurrentTransaction(); |
32 | 0 | if (currentTx == null || !currentTx.isBegun()) |
33 | |
{ |
34 | 0 | context.setStopFurtherProcessing(true); |
35 | 0 | throw new TransactionException(MessageFactory.createStaticMessage("Trying to roll back transaction but no transaction is underway.")); |
36 | |
} |
37 | |
|
38 | 0 | if (rollback) |
39 | |
{ |
40 | |
|
41 | 0 | logger.info("@@@@ Rolling back transaction @@@@"); |
42 | 0 | currentTx.setRollbackOnly(); |
43 | |
} |
44 | |
} |
45 | |
|
46 | 0 | return replyMessage; |
47 | |
} |
48 | |
|
49 | |
public boolean isRollback() |
50 | |
{ |
51 | 0 | return rollback; |
52 | |
} |
53 | |
|
54 | |
public void setRollback(boolean rollback) |
55 | |
{ |
56 | 0 | this.rollback = rollback; |
57 | 0 | } |
58 | |
|
59 | |
public boolean isExpectTransaction() |
60 | |
{ |
61 | 0 | return expectTransaction; |
62 | |
} |
63 | |
|
64 | |
public void setExpectTransaction(boolean expectTransaction) |
65 | |
{ |
66 | 0 | this.expectTransaction = expectTransaction; |
67 | 0 | } |
68 | |
} |
69 | |
|