/
annotationClient.java
348 lines (294 loc) · 10.7 KB
/
annotationClient.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
/*
* 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
*/
package com.sun.ts.tests.connector.annotations.anno;
import java.io.Serializable;
import java.util.Properties;
import java.util.Vector;
import com.sun.javatest.Status;
import com.sun.ts.lib.harness.ServiceEETest;
import com.sun.ts.lib.util.TSNamingContext;
import com.sun.ts.lib.util.TestUtil;
import com.sun.ts.tests.common.connector.util.ConnectorStatus;
import com.sun.ts.tests.common.connector.whitebox.TSConnection;
import com.sun.ts.tests.common.connector.whitebox.TSDataSource;
import com.sun.ts.tests.connector.util.DBSupport;
/*
* These are tests used to validate functionality associated with connector annotations.
*/
public class annotationClient extends ServiceEETest implements Serializable {
private TSNamingContext nctx = null;
private TSConnection con1 = null;
private TSConnection con2 = null;
private String partialMDJndiName = null;
private String annoJndiName = null;
private String uname = null;
private String password = null;
private TSDataSource ds1 = null;
private DBSupport dbutil = null;
/* Run test in standalone mode */
public static void main(String[] args) {
annotationClient theTests = new annotationClient();
Status s = theTests.run(args, System.out, System.err);
s.exit();
}
/*
* @class.setup_props: whitebox-anno_no_md; whitebox-mixedmode; rauser1;
* rapassword1;
*
*/
public void setup(String[] args, Properties p) throws Fault {
// Get JNDI lookups for both adapters. The harness will throw if these
// properties can not be retrieved, so there is no need for error checking
// here.
annoJndiName = p.getProperty("whitebox-anno_no_md");
System.out.println("annoJndiName = : " + annoJndiName);
uname = p.getProperty("rauser1");
password = p.getProperty("rapassword1");
logMsg("Using: " + annoJndiName);
// Construct our DBSupport object. This object performs interactions
// on a table, based on the properties object supplied.
try {
dbutil = new DBSupport();
} catch (Exception e) {
throw new Fault(
"Exception constructing DBSupport object: " + e.getMessage(), e);
}
try {
nctx = new TSNamingContext();
ds1 = (TSDataSource) nctx.lookup(annoJndiName);
if (ds1 == null) {
TestUtil.logMsg("ds1 lookup failed and is null");
} else {
TestUtil.logMsg("ds1 lookup is not null");
}
TestUtil.logMsg("ds1 JNDI lookup: " + ds1);
} catch (Exception e) {
TestUtil.printStackTrace(e);
TestUtil.logMsg("Exception during JNDI lookup: " + e.getMessage());
}
}
/*
* @testName: testConnectorAnnotation
*
* @assertion_ids: Connector:SPEC:268; Connector:JAVADOC:306;
* Connector:SPEC:267; Connector:JAVADOC:259; Connector:JAVADOC:123;
* Connector:JAVADOC:123; Connector:JAVADOC:123; Connector:JAVADOC:149;
* Connector:JAVADOC:165; Connector:JAVADOC:166; Connector:JAVADOC:167;
* Connector:JAVADOC:168; Connector:JAVADOC:168; Connector:JAVADOC:170;
* Connector:JAVADOC:171; Connector:JAVADOC:172; Connector:JAVADOC:173;
* Connector:JAVADOC:174; Connector:JAVADOC:176; Connector:JAVADOC:177;
* Connector:JAVADOC:178; Connector:JAVADOC:287; Connector:JAVADOC:288;
* Connector:JAVADOC:295; Connector:JAVADOC:296; Connector:JAVADOC:124;
* Connector:JAVADOC:126; Connector:JAVADOC:125;
*
* @test_Strategy: This is testing that the @Connector annotation is processed
* when there is no DD (eg ra.xml). (no DD also means there is no DD value for
* the DD element of "metadata-complete".) This also uses the authMechanism
* anno.
*/
public void testConnectorAnnotation() throws Fault {
Vector log = null;
boolean b1 = false;
// Obtain connection, perform API verification
try {
ds1.setLogFlag(true);
con1 = ds1.getConnection();
log = ds1.getStateLog();
TestUtil.logTrace("Got connection.");
} catch (Exception sqle) {
TestUtil.logMsg("Exception caught on creating connection:");
throw new Fault(sqle.getMessage(), sqle);
}
// our annotated RA should have called start when it was bootstrapped
String toCheck1 = "AnnotatedResourceAdapterImpl.start called";
// Turn tracing on if you want to see the log contents
TestUtil.logTrace(log.toString());
for (int i = 0; i < log.size(); i++) {
String str = (String) log.elementAt(i);
if (str.startsWith(toCheck1)) {
b1 = true;
}
}
if (b1) {
TestUtil.logMsg("Methods called correctly");
} else {
throw new Fault("@Connection annotation not processed correctly.");
}
// Verify connection object works by doing some end to end tests.
TestUtil.logMsg("Performing end to end verification...");
// Insert into table
try {
dbutil.insertIntoTable(con1);
TestUtil.logMsg("Values inserted into table!");
} catch (Exception sqle) {
TestUtil.logMsg("Exception inserting into table.");
throw new Fault(sqle.getMessage(), sqle);
}
// Drop the table
try {
dbutil.dropTable(con1);
TestUtil.logMsg("Table has been dropped!");
} catch (Exception sqle) {
TestUtil.logMsg("Exception dropping table.");
throw new Fault(sqle.getMessage(), sqle);
}
}
/*
* @testName: testSetterMethodConfigPropAnno
*
* @assertion_ids: Connector:SPEC:278; Connector:JAVADOC:306;
*
* @test_Strategy: This is testing that the @ConfigProperty annotation is
* processed.
*
*/
public void testSetterMethodConfigPropAnno() throws Fault {
Vector log = null;
boolean b1 = false;
String toCheck1 = "AnnotatedResourceAdapterImpl.setSetterMethodVal=NONDEFAULT";
// Obtain connection, perform API verification
try {
ds1.setLogFlag(true);
con1 = ds1.getConnection();
log = ds1.getStateLog();
TestUtil.logTrace("Got connection.");
} catch (Exception sqle) {
TestUtil.logMsg("Exception caught on creating connection:");
throw new Fault(sqle.getMessage(), sqle);
}
// Turn tracing on if you want to see the log contents
TestUtil.logTrace(log.toString());
for (int i = 0; i < log.size(); i++) {
String str = (String) log.elementAt(i);
if (str.startsWith(toCheck1)) {
b1 = true;
}
}
if (b1) {
TestUtil.logMsg("Methods called correctly");
} else {
throw new Fault(
"@ConfigProperty on setter method not processed correctly.");
}
}
/*
* @testName: testConfigPropertyAnnotation
*
* @assertion_ids: Connector:SPEC:268; Connector:SPEC:279; Connector:SPEC:277;
* Connector:JAVADOC:306; Connector:SPEC:280; Connector:JAVADOC:234;
*
* @test_Strategy: This is testing that the @ConfigProperty annotation is
* processed for both the @Conenction and @ConenctionDefinition annos. This
* also tests that Config tools properly used interospection to discover
* config properties that were not defined in the DD.
*/
public void testConfigPropertyAnnotation() throws Fault {
Vector log = null;
boolean b1 = false;
boolean b2 = false;
String toCheck1 = "setRAName called with raname=AnnotatedResourceAdapterImpl";
String toCheck2 = "AnnoManagedConnectionFactory factoryName=AnnoManagedConnectionFactory";
// Obtain connection, perform API verification
try {
ds1.setLogFlag(true);
con1 = ds1.getConnection();
log = ds1.getStateLog();
TestUtil.logTrace("Got connection.");
} catch (Exception sqle) {
TestUtil.logMsg("Exception caught on creating connection:");
throw new Fault(sqle.getMessage(), sqle);
}
// Turn tracing on if you want to see the log contents
TestUtil.logTrace(log.toString());
for (int i = 0; i < log.size(); i++) {
String str = (String) log.elementAt(i);
if (str.startsWith(toCheck1)) {
b1 = true;
}
if (str.startsWith(toCheck2)) {
b2 = true;
}
}
if (b1 && b2) {
TestUtil.logMsg("Methods called correctly");
} else {
throw new Fault("@ConfigProperty annotation not processed correctly.");
}
}
/*
* @testName: testRAAccessibility
*
* @assertion_ids: Connector:SPEC:301;
*
* @test_Strategy: This is testing that the resource-ref'd annotation jar file
* classes of the standalone rar are made available to this application. In
* order to test this, we will attempt to submit a logmessage using the RA's
* logging mechanism; then we will retrieve the log and ensure that (a) the
* client side log succeeded and (b) we logged it to the same log file that
* our RA is using.
*
*/
public void testRAAccessibility() throws Fault {
Vector log = null;
boolean b1 = false;
boolean b2 = false;
String toCheck1 = "testRAAccessibility: accessibility test";
String toCheck2 = "AnnotatedResourceAdapterImpl.start called";
// lets directly test assertion 301
ConnectorStatus.getConnectorStatus().logState(toCheck1);
// Obtain connection, perform API verification
try {
ds1.setLogFlag(true);
con1 = ds1.getConnection();
log = ds1.getStateLog();
TestUtil.logTrace("Got connection.");
} catch (Exception sqle) {
TestUtil.logMsg("Exception caught on creating connection:");
throw new Fault(sqle.getMessage(), sqle);
}
// Turn tracing on if you want to see the log contents
TestUtil.logTrace(log.toString());
for (int i = 0; i < log.size(); i++) {
String str = (String) log.elementAt(i);
if (str.startsWith(toCheck1)) {
b1 = true;
}
if (str.startsWith(toCheck2)) {
b2 = true;
}
}
if (b1 && b2) {
TestUtil.logMsg("Methods called correctly");
} else {
throw new Fault("standalone RA classes are available to app.");
}
}
/* cleanup */
public void cleanup() throws Fault {
if (ds1 != null) {
ds1.clearLog();
}
TestUtil.logMsg("Cleanup");
try {
TestUtil.logTrace("Closing connection in cleanup.");
if (con1 != null) {
con1.close();
}
} catch (Exception sqle) {
TestUtil.logErr("Exception on cleanup: " + sqle.getMessage(), sqle);
}
}
}