1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.jboss.as.quickstarts.wsat.simple;
18
19 import com.arjuna.mw.wst11.UserTransaction;
20 import com.arjuna.mw.wst11.UserTransactionFactory;
21
22 import org.jboss.arquillian.container.test.api.Deployment;
23 import org.jboss.arquillian.junit.Arquillian;
24 import org.jboss.as.quickstarts.wsat.simple.jaxws.RestaurantServiceAT;
25 import org.jboss.shrinkwrap.api.ArchivePaths;
26 import org.jboss.shrinkwrap.api.ShrinkWrap;
27 import org.jboss.shrinkwrap.api.asset.EmptyAsset;
28 import org.jboss.shrinkwrap.api.asset.StringAsset;
29 import org.jboss.shrinkwrap.api.spec.WebArchive;
30 import org.junit.Assert;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33
34 import javax.inject.Inject;
35
36
37
38
39
40
41 @RunWith(Arquillian.class)
42 public class ClientTest {
43
44 private static final String ManifestMF = "Manifest-Version: 1.0\n"
45 + "Dependencies: org.jboss.xts,org.jboss.modules,org.jboss.msc\n";
46
47 @Inject
48 @ClientStub
49 private RestaurantServiceAT client;
50
51
52
53
54
55
56 @Deployment
57 public static WebArchive createTestArchive() {
58
59 return ShrinkWrap.create(WebArchive.class, "wsat-simple.war")
60 .addPackages(true, RestaurantServiceATImpl.class.getPackage()).addAsResource("context-handlers.xml")
61 .addAsWebInfResource(EmptyAsset.INSTANCE, ArchivePaths.create("beans.xml"))
62 .setManifest(new StringAsset(ManifestMF));
63 }
64
65
66
67
68
69
70 @Test
71 public void testCommit() throws Exception {
72
73 System.out
74 .println("\n\nStarting 'testCommit'. This test invokes a WS within an AT. The AT is later committed, which causes the back-end resource(s) to be committed.");
75 System.out.println("[CLIENT] Creating a new WS-AT User Transaction");
76 UserTransaction ut = UserTransactionFactory.userTransaction();
77 try {
78 System.out
79 .println("[CLIENT] Beginning Atomic Transaction (All calls to Web services that support WS-AT wil be included in this transaction)");
80 ut.begin();
81 System.out.println("[CLIENT] invoking makeBooking() on WS");
82 client.makeBooking();
83 System.out.println("[CLIENT] committing Atomic Transaction (This will cause the AT to complete successfully)");
84 ut.commit();
85
86
87 Assert.assertEquals(1, client.getBookingCount());
88
89 } finally {
90 rollbackIfActive(ut);
91 client.reset();
92 }
93 }
94
95
96
97
98
99
100 @Test
101 public void testRollback() throws Exception {
102
103 System.out
104 .println("\n\nStarting 'testRollback'. This test invokes a WS within an AT. The AT is later rolled back, which causes the back-end resource(s) to be rolled back.");
105 System.out.println("[CLIENT] Creating a new WS-AT User Transaction");
106 UserTransaction ut = UserTransactionFactory.userTransaction();
107 try {
108 System.out
109 .println("[CLIENT] Beginning Atomic Transaction (All calls to Web services that support WS-AT wil be included in this transaction)");
110 ut.begin();
111 System.out.println("[CLIENT] invoking makeBooking() on WS");
112 client.makeBooking();
113 System.out
114 .println("[CLIENT] rolling back Atomic Transaction (This will cause the AT and thus the enlisted back-end resources to rollback)");
115 ut.rollback();
116
117
118 Assert.assertEquals(0, client.getBookingCount());
119
120 } finally {
121 rollbackIfActive(ut);
122 client.reset();
123 }
124 }
125
126
127
128
129
130
131 private void rollbackIfActive(UserTransaction ut) {
132 try {
133 ut.rollback();
134 } catch (Throwable th2) {
135
136 }
137 }
138 }