/
JsfClient.java
974 lines (866 loc) · 34.3 KB
/
JsfClient.java
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
/*
* Copyright (c) 2022 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
* version 2 with the GNU Classpath Exception, which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
*/
package com.sun.ts.tests.jta.ee.transactional;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import com.sun.ts.tests.ejb30.common.lite.EJBLiteJsfClientBase;
import jakarta.annotation.Resource;
import jakarta.enterprise.context.ContextNotActiveException;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptor;
import jakarta.transaction.InvalidTransactionException;
import jakarta.transaction.Status;
import jakarta.transaction.SystemException;
import jakarta.transaction.TransactionRequiredException;
import jakarta.transaction.TransactionalException;
import jakarta.transaction.UserTransaction;
@jakarta.inject.Named("client")
@jakarta.enterprise.context.RequestScoped
public class JsfClient extends EJBLiteJsfClientBase implements Serializable {
private static final long serialVersionUID = 1L;
private static StringBuilder callRecords = new StringBuilder();
@Inject
@OneManagedQualifier
OneManagedBean one;
@Inject
TransactionScopedBean tscopedBean;
@Resource(lookup = "java:comp/UserTransaction")
private UserTransaction ut;
public static void main(String[] args) {
JsfClient theTests = new JsfClient();
com.sun.javatest.Status s = theTests.run(args, System.out, System.err);
s.exit();
}
@Inject
@TwoManagedQualifier
TwoManagedBean two;
/*
* @testName: txTypeRequired_withoutTransaction
*
* @test_Strategy: TxType.REQUIRED: If called outside a transaction context,
* the interceptor must begin a new JTA transaction, the managed bean method
* execution must then continue inside this transaction context, and the
* transaction must be completed by the interceptor.
*
* If called inside a transaction context, the managed bean method execution
* must then continue inside this transaction context.
*/
public void txTypeRequired_withoutTransaction() throws Fault {
Helper.assertEquals("\n", "txTypeRequired called successfully",
one.txTypeRequired(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult("txTypeRequired called successfully",
one.txTypeRequired()));
}
/*
* @testName: txTypeRequired_withTransaction
*
* @test_Strategy: TxType.REQUIRED: If called outside a transaction context,
* the interceptor must begin a new JTA transaction, the managed bean method
* execution must then continue inside this transaction context, and the
* transaction must be completed by the interceptor.
*
* If called inside a transaction context, the managed bean method execution
* must then continue inside this transaction context.
*/
public void txTypeRequired_withTransaction() throws Fault {
try {
ut.begin();
Helper.assertEquals(null, "txTypeRequired called successfully",
one.txTypeRequired(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult("txTypeRequired called successfully",
one.txTypeRequired()));
ut.commit();
} catch (Exception e) {
Helper.getLogger().log(Level.INFO, null, e);
throw new Fault("txTypeRequired_withTransaction failed");
}
}
/*
* @testName: txTypeRequired_IllegalStateException
*
* @test_Strategy: If an attempt is made to call any method of the
* UserTransaction interface from within a bean or method annotated with
*
* @Transactional and a Transactional.TxType other than NOT_SUPPORTED or
* NEVER, an IllegalStateException must be thrown.
*/
public void txTypeRequired_IllegalStateException() throws Fault {
Helper.assertEquals(null, "IllegalStateException",
one.txTypeRequiredIllegalStateException(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult("IllegalStateException",
one.txTypeRequiredIllegalStateException()));
}
/*
* @testName: txTypeRequiresNew
*
* @test_Strategy: If called outside a transaction context, the interceptor
* must begin a new JTA transaction, the managed bean method execution must
* then continue inside this transaction context, and the transaction must be
* completed by the interceptor.
*
* If called inside a transaction context, the current transaction context
* must be suspended, a new JTA transaction will begin, the managed bean
* method execution must then continue inside this transaction context, the
* transaction must be completed, and the previously suspended transaction
* must be resumed.
*/
public void txTypeRequiresNew() throws Fault {
Helper.assertEquals(null, "txTypeRequiresNew called successfully",
one.txTypeRequiresNew(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult("txTypeRequiresNew called successfully",
one.txTypeRequiresNew()));
}
/*
* @testName: txTypeRequiresNew_withTransaction
*
* @test_Strategy: If called outside a transaction context, the interceptor
* must begin a new JTA transaction, the managed bean method execution must
* then continue inside this transaction context, and the transaction must be
* completed by the interceptor.
*
* If called inside a transaction context, the current transaction context
* must be suspended, a new JTA transaction will begin, the managed bean
* method execution must then continue inside this transaction context, the
* transaction must be completed, and the previously suspended transaction
* must be resumed.
*/
public void txTypeRequiresNew_withTransaction() throws Fault {
try {
ut.begin();
Helper.assertEquals(null, "txTypeRequiresNew called successfully",
one.txTypeRequiresNew(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult("txTypeRequiresNew called successfully",
one.txTypeRequiresNew()));
ut.commit();
} catch (Exception e) {
Helper.getLogger().log(Level.INFO, null, e);
throw new Fault("txTypeRequiresNew_withTransaction failed");
}
}
/*
* @testName: txTypeMandatory_withoutTransaction
*
* @test_Strategy: If called outside a transaction context, a
* TransactionalException with a nested TransactionRequiredException must be
* thrown.
*
* If called inside a transaction context, managed bean method execution will
* then continue under that context.
*/
public void txTypeMandatory_withoutTransaction() throws Fault {
String result = "TransactionalException not received";
try {
Helper.getLogger().info(
"Invoking OneManagedBean.txTypeManadatory() without a transaction Context");
one.txTypeMandatory();
} catch (TransactionalException te) {
if (te.getCause() instanceof TransactionRequiredException) {
result = "Received expected TransactionalException with nested TransactionRequiredException";
} else {
throw new Fault(
"Received TransactionalException without nested TransactionRequiredExecption");
}
} catch (Exception e) {
e.printStackTrace();
result = "Received unexcepted Exception :" + e.getMessage();
}
if (result.equals(
"Received expected TransactionalException with nested TransactionRequiredException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(
"Received expected TransactionalException with nested TransactionRequiredException");
} else {
throw new Fault(result);
}
}
/*
* @testName: txTypeMandatory_withTransaction
*
* @test_Strategy: If called outside a transaction context, a
* TransactionalException with a nested TransactionRequiredException must be
* thrown.
*
* If called inside a transaction context, managed bean method execution will
* then continue under that context.
*/
public void txTypeMandatory_withTransaction() throws Fault {
try {
ut.begin();
Helper.assertEquals(null, "txTypeMandatory called successfully",
one.txTypeMandatory(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult("txTypeMandatory called successfully",
one.txTypeMandatory()));
ut.commit();
} catch (Exception e) {
Helper.getLogger().log(Level.INFO, null, e);
throw new Fault("txTypeRequiresNew_withTransaction failed");
}
}
/*
* @testName: txTypeSupports_withoutTransaction
*
* @test_Strategy: If called outside a transaction context, managed bean
* method execution must then continue outside a transaction context.
*
* If called inside a transaction context, the managed bean method execution
* must then continue inside this transaction context.
*/
public void txTypeSupports_withoutTransaction() throws Fault {
Helper.assertEquals(null, "txTypeSupports run without active transaction",
one.txTypeSupportsWithoutTransaction(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(
Helper.compareResult("txTypeSupports run without active transaction",
one.txTypeSupportsWithoutTransaction()));
}
/*
* @testName: txTypeSupports_withTransaction
*
* @test_Strategy: If called outside a transaction context, managed bean
* method execution must then continue outside a transaction context.
*
* If called inside a transaction context, the managed bean method execution
* must then continue inside this transaction context.
*/
public void txTypeSupports_withTransaction() throws Fault {
try {
ut.begin();
Helper.assertEquals(null, "txTypeSupports called successfully",
one.txTypeSupports(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult("txTypeSupports called successfully",
one.txTypeSupports()));
ut.commit();
} catch (Exception e) {
Helper.getLogger().log(Level.INFO, null, e);
throw new Fault("txTypeSupports failed");
}
}
/*
* @testName: txTypeNotSupported_withoutTransaction
*
* @test_Strategy: If called outside a transaction context, managed bean
* method execution must then continue outside a transaction context.
*
* If called inside a transaction context, the current transaction context
* must be suspended, the managed bean method execution must then continue
* outside a transaction context, and the previously suspended transaction
* must be resumed by the interceptor that suspended it after the method
* execution has completed.
*/
public void txTypeNotSupported_withoutTransaction() throws Fault {
Helper.assertEquals(null,
"txTypeNotSupported run without active transaction",
one.txTypeNotSupported(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult(
"txTypeNotSupported run without active transaction",
one.txTypeNotSupported()));
}
/*
* @testName: txTypeNotSupported_withTransaction
*
* @test_Strategy: If called outside a transaction context, managed bean
* method execution must then continue outside a transaction context.
*
* If called inside a transaction context, the current transaction context
* must be suspended, the managed bean method execution must then continue
* outside a transaction context, and the previously suspended transaction
* must be resumed by the interceptor that suspended it after the method
* execution has completed.
*/
public void txTypeNotSupported_withTransaction() throws Fault {
try {
ut.begin();
Helper.assertEquals(null,
"txTypeNotSupported run without active transaction",
one.txTypeNotSupported(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult(
"txTypeNotSupported run without active transaction",
one.txTypeNotSupported()));
ut.commit();
} catch (Exception e) {
Helper.getLogger().log(Level.INFO, null, e);
throw new Fault("txTypeSupports failed");
}
}
/*
* @testName: txTypeNever_withoutTransaction
*
* @test_Strategy: If called outside a transaction context, managed bean
* method execution must then continue outside a transaction context.
*
* If called inside a transaction context, a TransactionalException with a
* nested InvalidTransactionException must be thrown
*/
public void txTypeNever_withoutTransaction() throws Fault {
Helper.assertEquals(null, "txTypeNever run without active transaction",
one.txTypeNever(), callRecords);
// Helper.getLogger().info(callRecords.toString());
appendReason(Helper.compareResult(
"txTypeNever run without active transaction", one.txTypeNever()));
}
/*
* @testName: txTypeNever_withTransaction
*
* @test_Strategy: If called outside a transaction context, managed bean
* method execution must then continue outside a transaction context.
*
* If called inside a transaction context, a TransactionalException with a
* nested InvalidTransactionException must be thrown
*/
public void txTypeNever_withTransaction() throws Fault {
String result = "Expected TransactionalException not received";
try {
Helper.getLogger().info(
"Invoking OneManagedBean.txTypeNever() with a transaction Context");
ut.begin();
one.txTypeNever();
ut.commit();
} catch (TransactionalException te) {
if (te.getCause() instanceof InvalidTransactionException) {
result = "Received expected TransactionalException with nested InvalidTransactionException";
} else {
throw new Fault(
"Received expected TransactionalException without nested InvalidTransactionException");
}
} catch (Exception e) {
e.printStackTrace();
result = "Received unexcepted Exception :" + e.getMessage();
}
if (result.equals(
"Received expected TransactionalException with nested InvalidTransactionException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(
"Received expected TransactionalException with nested InvalidTransactionException");
} else {
throw new Fault(result);
}
}
/*
* @testName: rollbackOnException
*
* @test_Strategy: The rollbackOn element can be set to indicate exceptions
* that must cause the interceptor to mark the transaction for rollback.
*
* Conversely, the dontRollbackOn element can be set to indicate exceptions
* that must not cause the interceptor to mark the transaction for rollback.
*/
public void rollbackOnException() throws Fault {
String result = "failed to set STATUS_MARKED_ROLLBACK on CTSRollbackException";
int status;
try {
ut.begin();
if (ut.getStatus() == Status.STATUS_ACTIVE) {
Helper.getLogger()
.info("Current Transaction Status is = " + ut.getStatus());
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_ACTIVE = "
+ Status.STATUS_ACTIVE);
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_NO_TRANSACTION = "
+ Status.STATUS_NO_TRANSACTION);
Helper.getLogger().info(
"Transaction Status value for Status.STATUS_MARKED_ROLLBACK = "
+ Status.STATUS_MARKED_ROLLBACK);
Helper.getLogger().info("Calling one.rollbackOnException()");
one.rollbackOnException();
}
} catch (CTSRollbackException ce) {
Helper.getLogger().info("Received Expected CTSRollbackException");
try {
if (ut.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
result = "Transaction STATUS_MARKED_ROLLBACK on CTSRollbackException";
} else {
result = "Transaction Status is set to : " + ut.getStatus();
}
} catch (SystemException se) {
result = "failed to get transaction status";
}
} catch (Exception e) {
result = "Received unexpected exception :" + e.getClass();
}
if (result
.equals("Transaction STATUS_MARKED_ROLLBACK on CTSRollbackException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(result);
} else {
appendReason(result);
throw new Fault(result);
}
}
/*
* @testName: rollbackOnExceptionTwo
*
* @test_Strategy: The rollbackOn element can be set to indicate exceptions
* that must cause the interceptor to mark the transaction for rollback.
*
* Conversely, the dontRollbackOn element can be set to indicate exceptions
* that must not cause the interceptor to mark the transaction for rollback.
*
* When a class is specified for either of these elements, the designated
* behavior applies to subclasses of that class as well.
*
* Note: This test verifies the behavior in SubClass
*
*/
public void rollbackOnExceptionTwo() throws Fault {
String result = "failed to set STATUS_MARKED_ROLLBACK on CTSRollbackException";
int status;
try {
ut.begin();
if (ut.getStatus() == Status.STATUS_ACTIVE) {
Helper.getLogger()
.info("Current Transaction Status is = " + ut.getStatus());
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_ACTIVE = "
+ Status.STATUS_ACTIVE);
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_NO_TRANSACTION = "
+ Status.STATUS_NO_TRANSACTION);
Helper.getLogger().info(
"Transaction Status value for Status.STATUS_MARKED_ROLLBACK = "
+ Status.STATUS_MARKED_ROLLBACK);
Helper.getLogger().info("Calling one.rollbackOnException()");
two.rollbackOnException();
}
} catch (CTSRollbackException ce) {
Helper.getLogger().info("Received Expected CTSRollbackException");
try {
if (ut.getStatus() == Status.STATUS_MARKED_ROLLBACK) {
result = "Transaction STATUS_MARKED_ROLLBACK on CTSRollbackException";
} else {
result = "Transaction Status is set to : " + ut.getStatus();
}
} catch (SystemException se) {
result = "failed to get transaction status";
}
} catch (Exception e) {
result = "Received unexpected exception :" + e.getClass();
}
if (result
.equals("Transaction STATUS_MARKED_ROLLBACK on CTSRollbackException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(result);
} else {
appendReason(result);
throw new Fault(result);
}
}
/*
* @testName: dontRollbackOnException
*
* @test_Strategy: The rollbackOn element can be set to indicate exceptions
* that must cause the interceptor to mark the transaction for rollback.
*
* Conversely, the dontRollbackOn element can be set to indicate exceptions
* that must not cause the interceptor to mark the transaction for rollback.
*/
public void dontRollbackOnException() throws Fault {
String result = "";
int status;
try {
ut.begin();
if (ut.getStatus() == Status.STATUS_ACTIVE) {
Helper.getLogger()
.info("Current Transaction Status is = " + ut.getStatus());
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_ACTIVE = "
+ Status.STATUS_ACTIVE);
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_NO_TRANSACTION = "
+ Status.STATUS_NO_TRANSACTION);
Helper.getLogger().info(
"Transaction Status value for Status.STATUS_MARKED_ROLLBACK = "
+ Status.STATUS_MARKED_ROLLBACK);
Helper.getLogger().info("Calling one.dontRollbackOnException()");
one.dontRollbackOnException();
}
} catch (CTSDontRollbackException ce) {
Helper.getLogger().info("Received Expected CTSDontRollbackException");
try {
if (ut.getStatus() == Status.STATUS_ACTIVE) {
result = "Transaction Status not changed on CTSDontRollbackException";
} else {
result = "Transaction Status is set to : " + ut.getStatus();
}
} catch (SystemException se) {
result = "failed to get transaction status";
}
} catch (Exception e) {
result = "Received unexpected exception :" + e.getClass();
e.printStackTrace();
}
if (result
.equals("Transaction Status not changed on CTSDontRollbackException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(result);
} else {
appendReason(result);
throw new Fault(result);
}
}
/*
* @testName: dontRollbackOnExceptionTwo
*
* @test_Strategy: The rollbackOn element can be set to indicate exceptions
* that must cause the interceptor to mark the transaction for rollback.
*
* Conversely, the dontRollbackOn element can be set to indicate exceptions
* that must not cause the interceptor to mark the transaction for rollback.
*
* When a class is specified for either of these elements, the designated
* behavior applies to subclasses of that class as well.
*
* Note: This test verifies the behavior in SubClass
*
*/
public void dontRollbackOnExceptionTwo() throws Fault {
String result = "";
int status;
try {
ut.begin();
if (ut.getStatus() == Status.STATUS_ACTIVE) {
Helper.getLogger()
.info("Current Transaction Status is = " + ut.getStatus());
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_ACTIVE = "
+ Status.STATUS_ACTIVE);
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_NO_TRANSACTION = "
+ Status.STATUS_NO_TRANSACTION);
Helper.getLogger().info(
"Transaction Status value for Status.STATUS_MARKED_ROLLBACK = "
+ Status.STATUS_MARKED_ROLLBACK);
Helper.getLogger().info("Calling two.dontRollbackOnException()");
two.dontRollbackOnException();
}
} catch (CTSDontRollbackException ce) {
Helper.getLogger().info("Received Expected CTSDontRollbackException");
try {
if (ut.getStatus() == Status.STATUS_ACTIVE) {
result = "Transaction Status not changed on CTSDontRollbackException";
} else {
result = "Transaction Status is set to : " + ut.getStatus();
}
} catch (SystemException se) {
result = "failed to get transaction status";
}
} catch (Exception e) {
result = "Received unexpected exception :" + e.getClass();
e.printStackTrace();
}
if (result
.equals("Transaction Status not changed on CTSDontRollbackException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(result);
} else {
appendReason(result);
throw new Fault(result);
}
}
/*
* @testName: rollbackAndDontRollback
*
* @test_Strategy: The rollbackOn element can be set to indicate exceptions
* that must cause the interceptor to mark the transaction for rollback.
*
* Conversely, the dontRollbackOn element can be set to indicate exceptions
* that must not cause the interceptor to mark the transaction for rollback.
*
* When a class is specified for either of these elements, the designated
* behavior applies to subclasses of that class as well. If both elements are
* specified, dontRollbackOn takes precedence.
*/
public void rollbackAndDontRollback() throws Fault {
String result = "";
int status;
try {
ut.begin();
if (ut.getStatus() == Status.STATUS_ACTIVE) {
Helper.getLogger()
.info("Current Transaction Status is = " + ut.getStatus());
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_ACTIVE = "
+ Status.STATUS_ACTIVE);
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_NO_TRANSACTION = "
+ Status.STATUS_NO_TRANSACTION);
Helper.getLogger().info(
"Transaction Status value for Status.STATUS_MARKED_ROLLBACK = "
+ Status.STATUS_MARKED_ROLLBACK);
Helper.getLogger().info("Calling one.rollbackAndDontRollback()");
one.rollbackAndDontRollback();
}
} catch (CTSRollbackException ce) {
Helper.getLogger().info("Received Expected CTSRollbackException");
try {
if (ut.getStatus() == Status.STATUS_ACTIVE) {
result = "Transaction Status not changed on CTSRollbackException";
} else {
result = "Transaction Status is set to : " + ut.getStatus();
}
} catch (SystemException se) {
result = "failed to get transaction status";
}
} catch (Exception e) {
result = "Received unexpected exception :" + e.getClass();
}
if (result
.equals("Transaction Status not changed on CTSRollbackException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(result);
} else {
appendReason(result);
throw new Fault(result);
}
}
/*
* @testName: rollbackAndDontRollbackTwo
*
* @test_Strategy: The rollbackOn element can be set to indicate exceptions
* that must cause the interceptor to mark the transaction for rollback.
*
* Conversely, the dontRollbackOn element can be set to indicate exceptions
* that must not cause the interceptor to mark the transaction for rollback.
*
* When a class is specified for either of these elements, the designated
* behavior applies to subclasses of that class as well. If both elements are
* specified, dontRollbackOn takes precedence.
*
* Note: This test verifies the behavior in SubClass
*
*/
public void rollbackAndDontRollbackTwo() throws Fault {
String result = "";
int status;
try {
ut.begin();
if (ut.getStatus() == Status.STATUS_ACTIVE) {
Helper.getLogger()
.info("Current Transaction Status is = " + ut.getStatus());
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_ACTIVE = "
+ Status.STATUS_ACTIVE);
Helper.getLogger()
.info("Transaction Status value for Status.STATUS_NO_TRANSACTION = "
+ Status.STATUS_NO_TRANSACTION);
Helper.getLogger().info(
"Transaction Status value for Status.STATUS_MARKED_ROLLBACK = "
+ Status.STATUS_MARKED_ROLLBACK);
Helper.getLogger().info("Calling two.rollbackAndDontRollback()");
two.rollbackAndDontRollback();
}
} catch (CTSRollbackException ce) {
Helper.getLogger().info("Received Expected CTSRollbackException");
try {
if (ut.getStatus() == Status.STATUS_ACTIVE) {
result = "Transaction Status not changed on CTSRollbackException";
} else {
result = "Transaction Status is set to : " + ut.getStatus();
}
} catch (SystemException se) {
result = "failed to get transaction status";
}
} catch (Exception e) {
result = "Received unexpected exception :" + e.getClass();
}
if (result
.equals("Transaction Status not changed on CTSRollbackException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(result);
} else {
appendReason(result);
throw new Fault(result);
}
}
/*
* @testName: transactionScopedBean_withoutTransaction
*
* @test_Strategy:
*
* The jakarta.transaction.TransactionScoped annotation provides the ability to
* specify a standard CDI scope to define bean instances whose lifecycle is
* scoped to the currently active JTA transaction.
*
* The transaction scope is active when the return from a call to
* UserTransaction.getStatus or TransactionManager.getStatus is one of the
* following states: Status.STATUS_ACTIVE Status.STATUS_MARKED_ROLLBACK
* Status.STATUS_PREPARED Status.STATUS_UNKNOWN Status.STATUS_PREPARING
* Status.STATUS_COMMITTING Status.STATUS_ROLLING_BACK
*
* A jakarta.enterprise.context.ContextNotActiveException must be thrown if a
* bean with this annotation is used when the transaction context is not
* active.
*
*/
public void transactionScopedBean_withoutTransaction() throws Fault {
String result = "ContextNotActiveException not received";
try {
Helper.getLogger().info(
"Invoking TransactionScopedBean.test() without a transaction Context");
tscopedBean.test();
} catch (ContextNotActiveException te) {
result = "Received expected ContextNotActiveException";
} catch (Exception e) {
result = "Received unexcepted Exception :" + e.getClass();
e.printStackTrace();
}
if (result.equals("Received expected ContextNotActiveException")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(result);
} else {
throw new Fault(result);
}
}
/*
* @testName: transactionScopedBean_withTransaction
*
* @test_Strategy:
*
* The jakarta.transaction.TransactionScoped annotation provides the ability to
* specify a standard CDI scope to define bean instances whose lifecycle is
* scoped to the currently active JTA transaction.
*
* The transaction scope is active when the return from a call to
* UserTransaction.getStatus or TransactionManager.getStatus is one of the
* following states: Status.STATUS_ACTIVE Status.STATUS_MARKED_ROLLBACK
* Status.STATUS_PREPARED Status.STATUS_UNKNOWN Status.STATUS_PREPARING
* Status.STATUS_COMMITTING Status.STATUS_ROLLING_BACK
*
* A jakarta.enterprise.context.ContextNotActiveException must be thrown if a
* bean with this annotation is used when the transaction context is not
* active.
*/
public void transactionScopedBean_withTransaction() throws Fault {
String result = "";
try {
ut.begin();
Helper.getLogger().info(
"Invoking TransactionScopedBean.test() with a transaction Context");
result = tscopedBean.test();
ut.commit();
} catch (Exception e) {
result = "Received unexcepted Exception :" + e.getClass();
e.printStackTrace();
}
if (result
.equals("TransactionScopedBean.test called with active transaction")) {
Helper.getLogger().log(Level.INFO, result);
appendReason(result);
} else {
throw new Fault(result);
}
}
/*
* @testName: getInterceptorPriorityForTxTypeRequired
*
* @test_Strategy: The Transactional interceptors must have a priority of
* Interceptor.Priority.PLATFORM_BEFORE+200
*
*/
public void getInterceptorPriorityForTxTypeRequired() throws Fault {
String methodName = "txTypeRequired";
List<Integer> priorityList = one.getPriority(methodName);
verifyInterceptorPriority(priorityList, "TxType.REQUIRED");
}
/*
* @testName: getInterceptorPriorityForTxTypeRequiresNew
*
* @test_Strategy: The Transactional interceptors must have a priority of
* Interceptor.Priority.PLATFORM_BEFORE+200
*
*/
public void getInterceptorPriorityForTxTypeRequiresNew() throws Fault {
String methodName = "txTypeRequiresNew";
List<Integer> priorityList = one.getPriority(methodName);
verifyInterceptorPriority(priorityList, "TxType.REQUIRES_NEW");
}
/*
* @testName: getInterceptorPriorityForTxTypeMandatory
*
* @test_Strategy: The Transactional interceptors must have a priority of
* Interceptor.Priority.PLATFORM_BEFORE+200
*
*/
public void getInterceptorPriorityForTxTypeMandatory() throws Fault {
String methodName = "txTypeMandatory";
List<Integer> priorityList = one.getPriority(methodName);
verifyInterceptorPriority(priorityList, "TxType.MANDATORY");
}
/*
* @testName: getInterceptorPriorityForTxTypeSupports
*
* @test_Strategy: The Transactional interceptors must have a priority of
* Interceptor.Priority.PLATFORM_BEFORE+200
*
*/
public void getInterceptorPriorityForTxTypeSupports() throws Fault {
String methodName = "txTypeSupports";
List<Integer> priorityList = one.getPriority(methodName);
verifyInterceptorPriority(priorityList, "TxType.SUPPORTS");
}
/*
* @testName: getInterceptorPriorityForTxTypeNotSupported
*
* @test_Strategy: The Transactional interceptors must have a priority of
* Interceptor.Priority.PLATFORM_BEFORE+200
*
*/
public void getInterceptorPriorityForTxTypeNotSupported() throws Fault {
String methodName = "txTypeNotSupported";
List<Integer> priorityList = one.getPriority(methodName);
verifyInterceptorPriority(priorityList, "TxType.NOT_SUPPORTED");
}
/*
* @testName: getInterceptorPriorityForTxTypeNever
*
* @test_Strategy: The Transactional interceptors must have a priority of
* Interceptor.Priority.PLATFORM_BEFORE+200
*
*/
public void getInterceptorPriorityForTxTypeNever() throws Fault {
String methodName = "txTypeNever";
List<Integer> priorityList = one.getPriority(methodName);
verifyInterceptorPriority(priorityList, "TxType.NEVER");
}
private void verifyInterceptorPriority(List<Integer> priorityList,
String txType) throws Fault {
String result = null;
if (priorityList.contains(Interceptor.Priority.PLATFORM_BEFORE + 200)) {
Helper.getLogger().log(Level.INFO, "Transactional Interceptor for "
+ txType + " has right interceptor priority");
result = "Transactional Interceptor for " + txType
+ " has right interceptor priority";
} else {
throw new Fault("Transactional Interceptor for " + txType
+ " has incorrect interceptor priority : "
+ Arrays.toString(priorityList.toArray()) + " Excpected value is :"
+ Interceptor.Priority.PLATFORM_BEFORE + 200);
}
if (result != null)
appendReason(result);
}
}