19
19
import java .util .HashMap ;
20
20
import java .util .Map ;
21
21
22
- import javax . naming . InitialContext ;
23
- import javax . naming . NamingException ;
24
-
22
+ import org . jboss . arquillian . container . test . api . Deployment ;
23
+ import org . jboss . shrinkwrap . api . ShrinkWrap ;
24
+ import org . jboss . shrinkwrap . api . spec . WebArchive ;
25
25
import org .testng .annotations .Test ;
26
26
27
- import jakarta .enterprise .concurrent .tck .framework .TestClient ;
28
- import jakarta .enterprise .concurrent .tck .framework .TestUtil ;
29
-
30
- import jakarta .enterprise .concurrent .ContextService ;
31
27
import jakarta .enterprise .concurrent .ManagedTaskListener ;
28
+ import jakarta .enterprise .concurrent .tck .framework .ArquillianTests ;
32
29
import jakarta .enterprise .concurrent .tck .framework .TestLogger ;
30
+ import jakarta .enterprise .concurrent .tck .framework .TestUtil ;
33
31
34
- public class ContextServiceTests extends TestClient {
32
+ public class ContextServiceTests extends ArquillianTests {
35
33
36
34
private static final TestLogger log = TestLogger .get (ContextServiceTests .class );
35
+
36
+ //TODO deploy as EJB and JSP artifacts
37
+ @ Deployment (name ="ContextService" )
38
+ public static WebArchive createDeployment () {
39
+ return ShrinkWrap .create (WebArchive .class )
40
+ .addPackages (true , getFrameworkPackage (), ContextServiceTests .class .getPackage ());
41
+ }
37
42
38
43
/*
39
44
* @testName: ContextServiceWithIntf
@@ -47,12 +52,8 @@ public class ContextServiceTests extends TestClient {
47
52
public void ContextServiceWithIntf () {
48
53
boolean pass = false ;
49
54
try {
50
- InitialContext ctx = new InitialContext ();
51
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
52
- Runnable proxy = (Runnable ) cs .createContextualProxy (new TestRunnableWork (), Runnable .class );
55
+ Runnable proxy = (Runnable ) TestUtil .getContextService ().createContextualProxy (new TestRunnableWork (), Runnable .class );
53
56
pass = true ;
54
- } catch (NamingException ne ) {
55
- log .severe ("Failed to lookup default ContextService" + ne );
56
57
} catch (Exception e ) {
57
58
log .severe ("Unexpected Exception Caught" , e );
58
59
}
@@ -72,11 +73,7 @@ public void ContextServiceWithIntf() {
72
73
public void ContextServiceWithIntfAndIntfNoImplemented () {
73
74
boolean pass = false ;
74
75
try {
75
- InitialContext ctx = new InitialContext ();
76
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
77
- Object proxy = cs .createContextualProxy (new Object (), Runnable .class );
78
- } catch (NamingException ne ) {
79
- log .severe ("Failed to lookup default ContextService" + ne );
76
+ Object proxy = TestUtil .getContextService ().createContextualProxy (new Object (), Runnable .class );
80
77
} catch (IllegalArgumentException ie ) {
81
78
pass = true ;
82
79
} catch (Exception e ) {
@@ -98,12 +95,8 @@ public void ContextServiceWithIntfAndIntfNoImplemented() {
98
95
public void ContextServiceWithIntfAndInstanceIsNull () {
99
96
boolean pass = false ;
100
97
try {
101
- InitialContext ctx = new InitialContext ();
102
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
103
- Object proxy = cs .createContextualProxy (null , Runnable .class );
98
+ Object proxy = TestUtil .getContextService ().createContextualProxy (null , Runnable .class );
104
99
log .info (proxy .toString ());
105
- } catch (NamingException ne ) {
106
- log .severe ("Failed to lookup default ContextService" + ne );
107
100
} catch (IllegalArgumentException ie ) {
108
101
pass = true ;
109
102
} catch (Exception e ) {
@@ -124,12 +117,8 @@ public void ContextServiceWithIntfAndInstanceIsNull() {
124
117
public void ContextServiceWithMultiIntfs () {
125
118
boolean pass = false ;
126
119
try {
127
- InitialContext ctx = new InitialContext ();
128
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
129
- Object proxy = cs .createContextualProxy (new TestRunnableWork (), Runnable .class , TestWorkInterface .class );
120
+ Object proxy = TestUtil .getContextService ().createContextualProxy (new TestRunnableWork (), Runnable .class , TestWorkInterface .class );
130
121
pass = proxy instanceof Runnable && proxy instanceof TestWorkInterface ;
131
- } catch (NamingException ne ) {
132
- log .severe ("Failed to lookup default ContextService" + ne );
133
122
} catch (Exception e ) {
134
123
log .severe ("Unexpected Exception Caught" , e );
135
124
}
@@ -149,12 +138,8 @@ public void ContextServiceWithMultiIntfs() {
149
138
public void ContextServiceWithMultiIntfsAndIntfNoImplemented () {
150
139
boolean pass = false ;
151
140
try {
152
- InitialContext ctx = new InitialContext ();
153
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
154
- Object proxy = cs .createContextualProxy (new TestRunnableWork (), Runnable .class , TestWorkInterface .class ,
141
+ Object proxy = TestUtil .getContextService ().createContextualProxy (new TestRunnableWork (), Runnable .class , TestWorkInterface .class ,
155
142
ManagedTaskListener .class );
156
- } catch (NamingException ne ) {
157
- log .severe ("Failed to lookup default ContextService" + ne );
158
143
} catch (IllegalArgumentException ie ) {
159
144
pass = true ;
160
145
} catch (Exception e ) {
@@ -176,12 +161,8 @@ public void ContextServiceWithMultiIntfsAndIntfNoImplemented() {
176
161
public void ContextServiceWithMultiIntfsAndInstanceIsNull () {
177
162
boolean pass = false ;
178
163
try {
179
- InitialContext ctx = new InitialContext ();
180
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
181
- Object proxy = cs .createContextualProxy (null , Runnable .class , TestWorkInterface .class );
164
+ Object proxy = TestUtil .getContextService ().createContextualProxy (null , Runnable .class , TestWorkInterface .class );
182
165
log .info (proxy .toString ());
183
- } catch (NamingException ne ) {
184
- log .severe ("Failed to lookup default ContextService" + ne );
185
166
} catch (IllegalArgumentException ie ) {
186
167
pass = true ;
187
168
} catch (Exception e ) {
@@ -202,18 +183,12 @@ public void ContextServiceWithMultiIntfsAndInstanceIsNull() {
202
183
public void ContextServiceWithIntfAndProperties () {
203
184
boolean pass = false ;
204
185
try {
205
- InitialContext ctx = new InitialContext ();
206
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
207
-
208
186
Map <String , String > execProps = new HashMap <String , String >();
209
187
execProps .put ("vendor_a.security.tokenexpiration" , "15000" );
210
188
execProps .put ("USE_PARENT_TRANSACTION" , "true" );
211
189
212
- Runnable proxy = (Runnable ) cs .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class );
190
+ Runnable proxy = (Runnable ) TestUtil . getContextService () .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class );
213
191
pass = true ;
214
-
215
- } catch (NamingException ne ) {
216
- log .severe ("Failed to lookup default ContextService" + ne );
217
192
} catch (Exception e ) {
218
193
log .severe ("Unexpected Exception Caught" , e );
219
194
}
@@ -232,18 +207,13 @@ public void ContextServiceWithIntfAndProperties() {
232
207
public void ContextServiceWithMultiIntfsAndProperties () {
233
208
boolean pass = false ;
234
209
try {
235
- InitialContext ctx = new InitialContext ();
236
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
237
-
238
210
Map <String , String > execProps = new HashMap <String , String >();
239
211
execProps .put ("vendor_a.security.tokenexpiration" , "15000" );
240
212
execProps .put ("USE_PARENT_TRANSACTION" , "true" );
241
213
242
- Object proxy = cs .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class ,
214
+ Object proxy = TestUtil . getContextService () .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class ,
243
215
TestWorkInterface .class );
244
216
pass = proxy instanceof Runnable && proxy instanceof TestWorkInterface ;
245
- } catch (NamingException ne ) {
246
- log .severe ("Failed to lookup default ContextService" + ne );
247
217
} catch (Exception e ) {
248
218
log .severe ("Unexpected Exception Caught" , e );
249
219
}
@@ -263,17 +233,12 @@ public void ContextServiceWithMultiIntfsAndProperties() {
263
233
public void ContextServiceWithIntfAndPropertiesAndIntfNoImplemented () {
264
234
boolean pass = false ;
265
235
try {
266
- InitialContext ctx = new InitialContext ();
267
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
268
-
269
236
Map <String , String > execProps = new HashMap <String , String >();
270
237
execProps .put ("vendor_a.security.tokenexpiration" , "15000" );
271
238
execProps .put ("USE_PARENT_TRANSACTION" , "true" );
272
239
273
- Object proxy = cs .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class ,
240
+ Object proxy = TestUtil . getContextService () .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class ,
274
241
ManagedTaskListener .class );
275
- } catch (NamingException ne ) {
276
- log .severe ("Failed to lookup default ContextService" + ne );
277
242
} catch (IllegalArgumentException ie ) {
278
243
pass = true ;
279
244
} catch (Exception e ) {
@@ -295,17 +260,12 @@ public void ContextServiceWithIntfAndPropertiesAndIntfNoImplemented() {
295
260
public void ContextServiceWithIntfsAndPropertiesAndInstanceIsNull () {
296
261
boolean pass = false ;
297
262
try {
298
- InitialContext ctx = new InitialContext ();
299
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
300
-
301
263
Map <String , String > execProps = new HashMap <String , String >();
302
264
execProps .put ("vendor_a.security.tokenexpiration" , "15000" );
303
265
execProps .put ("USE_PARENT_TRANSACTION" , "true" );
304
266
305
- Object proxy = cs .createContextualProxy (null , execProps , Runnable .class );
267
+ Object proxy = TestUtil . getContextService () .createContextualProxy (null , execProps , Runnable .class );
306
268
log .info (proxy .toString ());
307
- } catch (NamingException ne ) {
308
- log .severe ("Failed to lookup default ContextService" + ne );
309
269
} catch (IllegalArgumentException ie ) {
310
270
pass = true ;
311
271
} catch (Exception e ) {
@@ -327,17 +287,12 @@ public void ContextServiceWithIntfsAndPropertiesAndInstanceIsNull() {
327
287
public void ContextServiceWithMultiIntfsAndPropertiesAndIntfNoImplemented () {
328
288
boolean pass = false ;
329
289
try {
330
- InitialContext ctx = new InitialContext ();
331
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
332
-
333
290
Map <String , String > execProps = new HashMap <String , String >();
334
291
execProps .put ("vendor_a.security.tokenexpiration" , "15000" );
335
292
execProps .put ("USE_PARENT_TRANSACTION" , "true" );
336
293
337
- Object proxy = cs .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class ,
294
+ Object proxy = TestUtil . getContextService () .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class ,
338
295
TestWorkInterface .class , ManagedTaskListener .class );
339
- } catch (NamingException ne ) {
340
- log .severe ("Failed to lookup default ContextService" + ne );
341
296
} catch (IllegalArgumentException ie ) {
342
297
pass = true ;
343
298
} catch (Exception e ) {
@@ -359,17 +314,12 @@ public void ContextServiceWithMultiIntfsAndPropertiesAndIntfNoImplemented() {
359
314
public void ContextServiceWithMultiIntfsAndPropertiesAndInstanceIsNull () {
360
315
boolean pass = false ;
361
316
try {
362
- InitialContext ctx = new InitialContext ();
363
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
364
-
365
317
Map <String , String > execProps = new HashMap <String , String >();
366
318
execProps .put ("vendor_a.security.tokenexpiration" , "15000" );
367
319
execProps .put ("USE_PARENT_TRANSACTION" , "true" );
368
320
369
- Object proxy = cs .createContextualProxy (null , execProps , Runnable .class , TestWorkInterface .class );
321
+ Object proxy = TestUtil . getContextService () .createContextualProxy (null , execProps , Runnable .class , TestWorkInterface .class );
370
322
log .info (proxy .toString ());
371
- } catch (NamingException ne ) {
372
- log .severe ("Failed to lookup default ContextService" + ne );
373
323
} catch (IllegalArgumentException ie ) {
374
324
pass = true ;
375
325
} catch (Exception e ) {
@@ -391,23 +341,18 @@ public void ContextServiceWithMultiIntfsAndPropertiesAndInstanceIsNull() {
391
341
public void GetExecutionProperties () {
392
342
boolean pass = false ;
393
343
try {
394
- InitialContext ctx = new InitialContext ();
395
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
396
-
397
344
Map <String , String > execProps = new HashMap <String , String >();
398
345
execProps .put ("USE_PARENT_TRANSACTION" , "true" );
399
346
400
- Object proxy = cs .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class ,
347
+ Object proxy = TestUtil . getContextService () .createContextualProxy (new TestRunnableWork (), execProps , Runnable .class ,
401
348
TestWorkInterface .class );
402
- Map <String , String > returnedExecProps = cs .getExecutionProperties (proxy );
349
+ Map <String , String > returnedExecProps = TestUtil . getContextService () .getExecutionProperties (proxy );
403
350
404
351
if (!"true" .equals (returnedExecProps .get ("USE_PARENT_TRANSACTION" ))) {
405
352
log .severe ("Expected:true, actual message=" + returnedExecProps .get ("USE_PARENT_TRANSACTION" ));
406
353
} else {
407
354
pass = true ;
408
355
}
409
- } catch (NamingException ne ) {
410
- log .severe ("Failed to lookup default ContextService" + ne );
411
356
} catch (Exception e ) {
412
357
log .severe ("Unexpected Exception Caught" , e );
413
358
}
@@ -426,12 +371,8 @@ public void GetExecutionProperties() {
426
371
public void GetExecutionPropertiesNoProxy () {
427
372
boolean pass = false ;
428
373
try {
429
- InitialContext ctx = new InitialContext ();
430
- ContextService cs = (ContextService ) ctx .lookup ("java:comp/DefaultContextService" );
431
- Map <String , String > returnedExecProps = cs .getExecutionProperties (new Object ());
374
+ Map <String , String > returnedExecProps = TestUtil .getContextService ().getExecutionProperties (new Object ());
432
375
pass = true ;
433
- } catch (NamingException ne ) {
434
- log .severe ("Failed to lookup default ContextService" + ne );
435
376
} catch (IllegalArgumentException ie ) {
436
377
pass = true ;
437
378
} catch (Exception e ) {
0 commit comments