/
JsfClientBase.java
164 lines (143 loc) · 6.03 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
/*
* 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
*/
/*
* $Id$
*/
package com.sun.ts.tests.ejb30.lite.interceptor.common.lifecycle;
import java.util.List;
import com.sun.ts.tests.ejb30.common.helper.Helper;
import com.sun.ts.tests.ejb30.common.lite.EJBLiteJsfClientBase;
import jakarta.ejb.EJB;
public class JsfClientBase extends EJBLiteJsfClientBase {
@EJB(name = "historySingletonBean", beanName = "HistorySingletonBean")
protected HistorySingletonBean historySingletonBean;
// injected in subclass, with @EJB for EJB beans, and @Resource for managed
// beans
protected InterceptorIF bean;
protected InterceptorIF overrideBean;
protected InterceptorIF override34Bean;
protected InterceptorIF aroundConstructBean;
protected InterceptorIF getBean() {
return bean;
}
protected InterceptorIF getOverrideBean() {
return overrideBean;
}
protected InterceptorIF getOverride34Bean() {
return override34Bean;
}
protected InterceptorIF getAroundConstructBean() {
return aroundConstructBean;
}
/*
* testName: allInterceptors
*
* @test_Strategy: all interceptors at default and class-level should be
* invoked, as well as PostConstruct methods on bean class. For Interceptor8,
* the PostConstruct methods from super and super-super classes are overridden
* and therefore are not invoked.
*/
public void allInterceptors() {
String[] expectedPostConstruct = {
// default interceptors 2, 1, 3
"InterceptorBaseBase", "InterceptorBase", "Interceptor2",
"InterceptorBaseBase", "InterceptorBase", "Interceptor1",
"InterceptorBaseBase", "InterceptorBase", "Interceptor3",
// class-level interceptors 5, 4
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase", "Interceptor4", "Interceptor8",
// AroundInvoke methods on bean superclass and bean class
"InterceptorBeanBase", "InterceptorBean" };
String[] expectedAroundInvoke = {
// default interceptors 2, 1, 3
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase", "InterceptorBaseBase", "InterceptorBase",
// class-level interceptors 5, 4, 8
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase", "InterceptorBaseBase",
// method-level interceptors 7, 6
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase" };
interceptorTest(getBean(), expectedPostConstruct, expectedAroundInvoke);
}
/*
* testName: overrideBeanInterceptorMethod
*
* @test_Strategy: If a PostConstruct method is overridden, it is no longer
* invoked. This test override with a non-PostConstruct method. This test also
* excludes default and class-level interceptors.
*/
public void overrideBeanInterceptorMethod() {
String[] expectedPostConstruct = { "InterceptorOverrideBean" };
String[] expectedAroundInvoke = {
// method-level interceptors 7, 6
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase" };
interceptorTest(getOverrideBean(), expectedPostConstruct,
expectedAroundInvoke);
}
/*
* testName: overrideBeanInterceptorMethod3
*
* @test_Strategy: If a PostConstruct method is overridden, it is no longer
* invoked. This test override with a PostConstruct method.
*/
public void overrideBeanInterceptorMethod3() {
String[] expectedPostConstruct = { "InterceptorOverride34Bean" };
String[] expectedAroundInvoke = {
// method-level interceptors 7, 6
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase" };
interceptorTest(getOverride34Bean(), expectedPostConstruct,
expectedAroundInvoke);
}
public void aroundConstructInterceptorTest() {
String[] expectedPostConstruct = {
// class-level AroundConstruct interceptors 9, A. It's in reverse order
// because the record has to be added after InvocationContext.proceed().
// "Interceptor9",
// "Interceptor9", "InterceptorA",
"InterceptorA", "Interceptor9", "Interceptor9",
// class-level PostConstructor interceptors 9, A
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase",
// PostConstruct methods on bean superclass and bean class
"InterceptorBeanBase", "AroundConstructInterceptorBean" };
String[] expectedAroundInvoke = {
// class-level interceptors 9, A
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase",
// method-level interceptors 7, 6
"InterceptorBaseBase", "InterceptorBase", "InterceptorBaseBase",
"InterceptorBase" };
interceptorTest(getAroundConstructBean(), expectedPostConstruct,
expectedAroundInvoke);
}
private void interceptorTest(InterceptorIF b, String[] expectedPostConstruct,
String[] expectedAroundInvoke) {
try {
List<String> actualPostConstruct = b.allInterceptors();
appendReason(
Helper.compareResultList(expectedPostConstruct, actualPostConstruct));
List<String> actualAroundInvoke = historySingletonBean
.getAroundInvokeRecords();
appendReason(
Helper.compareResultList(expectedAroundInvoke, actualAroundInvoke));
} finally {
historySingletonBean.clearAroundInvokeRecords();
}
}
}