/
JsfClientBase.java
191 lines (163 loc) · 6.91 KB
/
JsfClientBase.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
/*
* Copyright (c) 2009, 2020 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
*/
/*
* $Id$
*/
package com.sun.ts.tests.ejb30.timer.interceptor.aroundtimeout.common;
import java.util.List;
import com.sun.ts.tests.ejb30.common.helper.Helper;
import jakarta.ejb.EJB;
public class JsfClientBase extends com.sun.ts.tests.ejb30.timer.common.JsfClientBase {
@EJB(beanName = "AroundTimeoutBean")
private AroundTimeoutIF aroundTimeoutBean;
@EJB(beanName = "AroundTimeoutOverrideBean")
private AroundTimeoutIF aroundTimeoutOverrideBean;
@EJB(beanName = "AroundTimeoutComplementBean")
private AroundTimeoutIF aroundTimeoutComplementBean;
@EJB(beanName = "InvocationContextMethodsBean")
private AroundTimeoutIF invocationContextMethodsBean;
@EJB(beanName = "MethodOverrideBean")
private AroundTimeoutIF methodOverrideBean;
@EJB(beanName = "MethodOverride2Bean")
private AroundTimeoutIF methodOverride2Bean;
protected AroundTimeoutIF getAroundTimeoutExceptionBean() {
return null;
}
/*
* testName: allInterceptors
*
* @test_Strategy: all interceptors at default and class-level should be
* invoked. //default interceptors 2, 1 //class-level interceptors 4, 3
* //method-level interceptors 6, 5
*/
public void allInterceptors() {
String[] expectedAroundTimeout = { "InterceptorBase", "Interceptor2",
"InterceptorBase", "Interceptor1",
"InterceptorBase", "Interceptor4", "InterceptorBase", "Interceptor3",
"InterceptorBase", "Interceptor6", "InterceptorBase", "Interceptor5",
"AroundTimeoutBeanBase", "AroundTimeoutBean",
"AroundTimeoutBeanBase.timeout" };
aroundTimeoutTest(aroundTimeoutBean, expectedAroundTimeout, true);
}
/*
* testName: allInterceptorsOverride
*
* @test_Strategy: For AroundTimeoutOverrideBean, interceptor-order in
* ejb-jar.xml is used to override the ordering of class-level interceptors.
* exclude-default-interceptors is also applied for AroundTimeoutOverrideBean.
*/
public void allInterceptorsOverride() {
String[] expectedAroundTimeout = { "InterceptorBase", "Interceptor3",
"InterceptorBase", "Interceptor4",
"InterceptorBase", "Interceptor6", "InterceptorBase", "Interceptor5",
"AroundTimeoutBeanBase", "AroundTimeoutOverrideBean",
"AroundTimeoutBeanBase.timeout" };
aroundTimeoutTest(aroundTimeoutOverrideBean, expectedAroundTimeout, true);
}
/*
* testName: allInterceptorsComplement
*
* @test_Strategy: AroundTimeoutComplementBean's interceptors are also
* declared in ejb-jar.xml to complement the class-level interceptors.
* AroundTimeoutComplementBean excludes default interceptors.
*/
public void allInterceptorsComplement() {
String[] expectedAroundTimeout = { "InterceptorBase", "Interceptor4",
"InterceptorBase", "Interceptor3", "InterceptorBase", "Interceptor2",
"InterceptorBase", "Interceptor1",
"InterceptorBase", "Interceptor6", "InterceptorBase", "Interceptor5",
"AroundTimeoutBeanBase", "AroundTimeoutComplementBean",
"AroundTimeoutBeanBase.timeout" };
aroundTimeoutTest(aroundTimeoutComplementBean, expectedAroundTimeout, true);
}
/*
* testName: aroundTimeoutMethod
*
* @test_Strategy: override @AroundTimeout method with @AroundTimeout method
* and verify that the superclass' @AroundTimeout is disabled, and
* subclass' @AroundTimeout method is invoked
*/
public void aroundTimeoutMethod() {
String[] expectedAroundTimeout = { "InterceptorBase", "Interceptor2",
"InterceptorBase", "Interceptor1", "MethodOverrideBean",
"MethodOverrideBeanBase.timeout" };
aroundTimeoutTest(methodOverrideBean, expectedAroundTimeout, true);
}
/*
* testName: aroundTimeoutMethod2
*
* @test_Strategy:override @AroundTimeout method with non-AroundTimeout method
* and verify that the superclass' @AroundTimeout is disabled
*/
public void aroundTimeoutMethod2() {
String[] expectedAroundTimeout = { "InterceptorBase", "Interceptor2",
"InterceptorBase", "Interceptor1", "MethodOverrideBeanBase.timeout" };
aroundTimeoutTest(methodOverride2Bean, expectedAroundTimeout, true);
}
/*
* testName: aroundTimeoutException
*
* @test_Strategy: Interceptor1 catches and suppresses the RuntimeException
* from bean class' AroundTimeout method.
*/
public void aroundTimeoutException() {
String[] expectedAroundTimeout = { "InterceptorBase", "Interceptor2",
"InterceptorBase", "Interceptor1", "AroundTimeoutExceptionBeanBase",
"RuntimeException" };
aroundTimeoutTest(getAroundTimeoutExceptionBean(), expectedAroundTimeout,
false);
}
/*
* testName: invocationContextMethods
*
* @test_Strategy: invokes various methods on InvocationContext
* inside @AroundTimeout method.
*/
public void invocationContextMethods() {
String[] expectedAroundTimeout = {
// method-level interceptors on AroundTimeoutBeanBase.timeout
"InterceptorBase", "Interceptor6", "InterceptorBase", "Interceptor5",
"getMethod", "getParameters", "getTarget", "getContextData",
"setParameters", "AroundTimeoutBeanBase.timeout" };
aroundTimeoutTest(invocationContextMethodsBean, expectedAroundTimeout,
true);
}
protected String getAroundTimeoutRecordKey() {
return getTestName() + AroundTimeoutIF.AROUND_TIMEOUT_RECORD_KEY_SUFFIX;
}
private void aroundTimeoutTest(AroundTimeoutIF b,
String[] expectedAroundTimeout, boolean timeoutInvoked) {
// use getTestName() + ".around-timeout" as the key for
// around-timeout-related records,
// separate from timeout records.
statusSingleton.removeRecords(getAroundTimeoutRecordKey());
b.createSecondLaterTimer(getTestName(), 2);
checkAndClearAroundTimeoutRecords(expectedAroundTimeout,
getAroundTimeoutRecordKey(), timeoutInvoked);
}
private void checkAndClearAroundTimeoutRecords(String[] expected,
String aroundTimeoutRecordKey, boolean timeoutInvoked) {
if (timeoutInvoked) {
passIfTimeout();
} else {
passIfNoTimeout();
}
List<String> records = statusSingleton.getRecords(aroundTimeoutRecordKey);
statusSingleton.removeStatus(getTestName());
statusSingleton.removeRecords(aroundTimeoutRecordKey);
appendReason(Helper.compareResultList(expected, records));
}
}