|
1 |
| |
|
2 |
| |
|
3 |
| |
|
4 |
| |
|
5 |
| |
|
6 |
| |
|
7 |
| |
|
8 |
| |
|
9 |
| |
|
10 |
| |
|
11 |
| |
|
12 |
| |
|
13 |
| |
|
14 |
| |
|
15 |
| |
|
16 |
| |
|
17 |
| |
|
18 |
| |
|
19 |
| |
|
20 |
| |
|
21 |
| |
|
22 |
| |
|
23 |
| |
|
24 |
| |
|
25 |
| package org.objectweb.easybeans.tests.transaction.beanmanaged; |
|
26 |
| |
|
27 |
| import static org.testng.Assert.fail; |
|
28 |
| |
|
29 |
| import java.sql.SQLException; |
|
30 |
| |
|
31 |
| import javax.naming.NamingException; |
|
32 |
| |
|
33 |
| import org.objectweb.easybeans.log.JLog; |
|
34 |
| import org.objectweb.easybeans.log.JLogFactory; |
|
35 |
| import org.objectweb.easybeans.tests.common.ejbs.base.ItfBeanManagedTransaction; |
|
36 |
| import org.objectweb.easybeans.tests.common.ejbs.stateless.beanmanaged.SLSBBeanManagedTransaction; |
|
37 |
| import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.ItfDatabaseManager; |
|
38 |
| import org.objectweb.easybeans.tests.common.ejbs.stateless.containermanaged.SLSBDatabaseManager; |
|
39 |
| import org.objectweb.easybeans.tests.common.helper.EJBHelper; |
|
40 |
| import org.objectweb.easybeans.tests.common.helper.EmbeddedHelper; |
|
41 |
| import org.testng.annotations.Configuration; |
|
42 |
| import org.testng.annotations.ExpectedExceptions; |
|
43 |
| import org.testng.annotations.Test; |
|
44 |
| |
|
45 |
| |
|
46 |
| |
|
47 |
| |
|
48 |
| |
|
49 |
| |
|
50 |
| |
|
51 |
| |
|
52 |
| |
|
53 |
| |
|
54 |
| |
|
55 |
| |
|
56 |
| |
|
57 |
| public class TestTransactionCommitSLSB { |
|
58 |
| |
|
59 |
| |
|
60 |
| |
|
61 |
| |
|
62 |
| private ItfBeanManagedTransaction slsbBeanManagedTransaction; |
|
63 |
| |
|
64 |
| |
|
65 |
| |
|
66 |
| |
|
67 |
| private ItfDatabaseManager slsbDatabaseManager; |
|
68 |
| |
|
69 |
| |
|
70 |
| |
|
71 |
| |
|
72 |
| private static JLog logger = JLogFactory.getLog(TestTransactionCommitSLSB.class); |
|
73 |
| |
|
74 |
| |
|
75 |
| |
|
76 |
| |
|
77 |
| private static final String DATABASE = "jdbc_1"; |
|
78 |
| |
|
79 |
| |
|
80 |
| |
|
81 |
| |
|
82 |
| |
|
83 |
2
| @Configuration(beforeTestClass = true)
|
|
84 |
| public void setup() throws Exception { |
|
85 |
| |
|
86 |
| |
|
87 |
| |
|
88 |
2
| EmbeddedHelper.bindDatasource();
|
|
89 |
| |
|
90 |
2
| slsbDatabaseManager = EJBHelper.getBeanRemoteInstance(SLSBDatabaseManager.class, ItfDatabaseManager.class);
|
|
91 |
| } |
|
92 |
| |
|
93 |
| |
|
94 |
| |
|
95 |
| |
|
96 |
| |
|
97 |
| |
|
98 |
| |
|
99 |
| |
|
100 |
| |
|
101 |
| |
|
102 |
| |
|
103 |
1
| @Test
|
|
104 |
| public void testBeginWithoutCommit() throws Exception { |
|
105 |
1
| try {
|
|
106 |
| |
|
107 |
1
| slsbBeanManagedTransaction.insertTableWithoutCommit(ItfBeanManagedTransaction.CREATE_TABLE, DATABASE);
|
|
108 |
0
| fail("The container must to throw the javax.ejb.EJBException, if the stateless bean does not make the commit. "
|
|
109 |
| + "However the container did not throw any exception."); |
|
110 |
| } catch (Exception e) { |
|
111 |
1
| if (!(e instanceof javax.ejb.EJBException)) {
|
|
112 |
0
| fail("The container must to throw the javax.ejb.EJBException, if the stateless bean does not makes the commit. "
|
|
113 |
| + "However the container did not throw the correct exception."); |
|
114 |
| } |
|
115 |
| } |
|
116 |
| |
|
117 |
1
| try {
|
|
118 |
1
| slsbDatabaseManager.verifyTable(DATABASE, ItfBeanManagedTransaction.TABLE);
|
|
119 |
0
| fail("The container must to make the rollback, if the stateless bean does not make the commit.");
|
|
120 |
| } catch (SQLException e) { |
|
121 |
1
| logger.debug("the container made the rollback {0}", e);
|
|
122 |
| } |
|
123 |
| |
|
124 |
| |
|
125 |
| |
|
126 |
| |
|
127 |
| } |
|
128 |
| |
|
129 |
| |
|
130 |
| |
|
131 |
| |
|
132 |
| |
|
133 |
| |
|
134 |
| |
|
135 |
1
| @Test
|
|
136 |
| public void testTransInSameMethod() throws Exception { |
|
137 |
1
| slsbBeanManagedTransaction.insertTableWithBeginCommit(ItfBeanManagedTransaction.CREATE_TABLE, DATABASE);
|
|
138 |
| |
|
139 |
1
| slsbDatabaseManager.verifyTable(DATABASE, ItfBeanManagedTransaction.TABLE);
|
|
140 |
| } |
|
141 |
| |
|
142 |
| |
|
143 |
| |
|
144 |
| |
|
145 |
| |
|
146 |
| |
|
147 |
| |
|
148 |
1
| @Test
|
|
149 |
| @ExpectedExceptions(value = java.lang.IllegalStateException.class) |
|
150 |
| public void testSetRollbackOnly() throws Exception { |
|
151 |
| |
|
152 |
1
| slsbBeanManagedTransaction.setRollbackOnly();
|
|
153 |
| } |
|
154 |
| |
|
155 |
| |
|
156 |
| |
|
157 |
| |
|
158 |
| |
|
159 |
| |
|
160 |
| |
|
161 |
1
| @Test
|
|
162 |
| @ExpectedExceptions(value = java.lang.IllegalStateException.class) |
|
163 |
| public void testGetRollbackOnly() throws Exception { |
|
164 |
| |
|
165 |
1
| slsbBeanManagedTransaction.getRollbackOnly();
|
|
166 |
| } |
|
167 |
| |
|
168 |
| |
|
169 |
| |
|
170 |
| |
|
171 |
| |
|
172 |
1
| @Configuration(afterTestClass = true)
|
|
173 |
| public void tierDown() throws Exception { |
|
174 |
| |
|
175 |
| |
|
176 |
1
| EmbeddedHelper.unbindDatasource();
|
|
177 |
| } |
|
178 |
| |
|
179 |
| |
|
180 |
| |
|
181 |
| |
|
182 |
4
| @Configuration(beforeTestMethod = true)
|
|
183 |
| public void deletesTable() { |
|
184 |
| |
|
185 |
4
| try {
|
|
186 |
4
| slsbDatabaseManager.deleteTable(DATABASE, ItfBeanManagedTransaction.TABLE);
|
|
187 |
| } catch (SQLException e) { |
|
188 |
1
| logger.debug("The table delete threw an error during the execution {0}", e);
|
|
189 |
| } catch (NamingException e) { |
|
190 |
0
| logger.debug("The table delete threw an error during the execution {0}", e);
|
|
191 |
| } |
|
192 |
| } |
|
193 |
| |
|
194 |
| |
|
195 |
| |
|
196 |
| |
|
197 |
| |
|
198 |
| |
|
199 |
4
| @Configuration(beforeTestMethod = true)
|
|
200 |
| public void createBean() throws Exception { |
|
201 |
| |
|
202 |
4
| slsbBeanManagedTransaction = EJBHelper.getBeanRemoteInstance(SLSBBeanManagedTransaction.class,
|
|
203 |
| ItfBeanManagedTransaction.class); |
|
204 |
| } |
|
205 |
| |
|
206 |
| } |