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