/
Client.java
224 lines (192 loc) · 6.94 KB
/
Client.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
/*
* 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.mdcomplete;
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.whitebox.TSConnection;
import com.sun.ts.tests.common.connector.whitebox.TSDataSource;
import com.sun.ts.tests.connector.util.DBSupport;
/*
* These are the tests that are used to validate behavior
* with RA's that utilize combinations of annotations and DD's.
*/
public class Client extends ServiceEETest implements Serializable {
private TSNamingContext nctx = null;
private TSConnection con2 = null;
private String completeMDJndiName = null;
private String uname = null;
private String password = null;
private TSDataSource ds2 = null;
private DBSupport dbutil = null;
/* Run test in standalone mode */
public static void main(String[] args) {
Client theTests = new Client();
Status s = theTests.run(args, System.out, System.err);
s.exit();
}
/*
* @class.setup_props: whitebox-mdcomplete; 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.
completeMDJndiName = p.getProperty("whitebox-mdcomplete");
System.out.println("completeMDJndiName = : " + completeMDJndiName);
uname = p.getProperty("rauser1");
password = p.getProperty("rapassword1");
logMsg("Using: " + completeMDJndiName);
// 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();
ds2 = (TSDataSource) nctx.lookup(completeMDJndiName);
if (ds2 == null) {
TestUtil.logMsg("ds2 lookup failed and is null");
} else {
TestUtil.logMsg("ds2 lookup is not null");
}
TestUtil.logMsg("ds2 JNDI lookup: " + ds2);
} catch (Exception e) {
TestUtil.printStackTrace(e);
TestUtil.logMsg("Exception during JNDI lookup: " + e.getMessage());
}
}
/*
* @testName: testMDCompleteConfigProp
*
* @assertion_ids: Connector:SPEC:266; Connector:JAVADOC:140;
* Connector:JAVADOC:142; Connector:JAVADOC:144; Connector:JAVADOC:139;
* Connector:JAVADOC:143;
*
* @test_Strategy: This is testing that a RA with annotations and a
* metadata-complete DD will take the DD's config property and set it within
* the ManagedConnectionFactory. The DD takes precedence and this is confirmed
* by checking that the setter for the config property was called. The DD
* (which has metadata-complete = true) should have all its attrs used and any
* duplicate annotation attrs should NOT get used. This is another variant of
* testing assertion 266.
*/
public void testMDCompleteConfigProp() throws Fault {
Vector log = null;
boolean b1 = false;
boolean b2 = false;
String toCheck1 = "setRAName called with raname=MDCompleteRA";
String toCheck2 = "setRAName called with raname=BAD_RAName_value";
// Obtain connection, perform API verification
try {
ds2.setLogFlag(true);
con2 = ds2.getConnection();
log = ds2.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)) {
// we should find this
b1 = true;
}
if (str.startsWith(toCheck2)) {
// we should NOT find this!
b2 = true;
}
}
if (b1 && !b2) {
TestUtil.logMsg("testMDCompleteConfigProp called correctly");
} else {
throw new Fault("Metadata-complete config prop Failure.");
}
}
/*
* @testName: testMDCompleteMCFAnno
*
* @assertion_ids: Connector:SPEC:266;
*
* @test_Strategy: This is testing that an RA with that has ra.xml with
* metadata-complete DD will use the DD's specified MCF and will NOT use an
* annotated MCF that is bundled in the same jar. Thus the metadata-complete
* DD gets its MCF used and the other is ignored. This is another variant of
* testing assertion 266.
*/
public void testMDCompleteMCFAnno() throws Fault {
Vector log = null;
boolean b1 = false;
boolean b2 = false;
String toCheck1 = "MDCompleteMCF constructor";
String toCheck2 = "MDAnnotatedMCF constructor";
// Obtain connection, perform API verification
try {
ds2.setLogFlag(true);
con2 = ds2.getConnection();
log = ds2.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)) {
// we should find this
b1 = true;
}
if (str.startsWith(toCheck2)) {
// we should NOT find this!
b2 = true;
}
}
if (b1 && !b2) {
TestUtil.logMsg("testMDCompleteMCFAnno called correctly");
} else {
throw new Fault(
"Annotated MCF erroneously called despite metadata-complete=true.");
}
}
/* cleanup */
public void cleanup() throws Fault {
if (ds2 != null) {
ds2.clearLog();
}
TestUtil.logMsg("Cleanup");
try {
TestUtil.logTrace("Closing connection in cleanup.");
if (con2 != null) {
con2.close();
}
} catch (Exception sqle) {
TestUtil.logErr("Exception on cleanup: " + sqle.getMessage(), sqle);
}
}
}