Line 0
Link Here
|
|
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 1998, 2007 Oracle. All rights reserved. |
3 |
* This program and the accompanying materials are made available under the |
4 |
* terms of the Eclipse Public License v1.0, which accompanies this distribution |
5 |
* and is available at http://www.eclipse.org/legal/epl-v10.html. |
6 |
* |
7 |
* Contributors: |
8 |
* Oracle - initial API and implementation from Oracle TopLink |
9 |
******************************************************************************/ |
10 |
package org.eclipse.persistence.testing.tests.sessionsxml; |
11 |
|
12 |
import java.io.File; |
13 |
import java.io.FileReader; |
14 |
import java.io.FileWriter; |
15 |
import java.util.Vector; |
16 |
|
17 |
import org.eclipse.persistence.oxm.XMLContext; |
18 |
import org.eclipse.persistence.oxm.XMLUnmarshaller; |
19 |
import org.eclipse.persistence.testing.framework.AutoVerifyTestCase; |
20 |
import org.eclipse.persistence.testing.framework.TestErrorException; |
21 |
import org.eclipse.persistence.internal.sessions.factories.*; |
22 |
import org.eclipse.persistence.internal.sessions.factories.model.SessionConfigs; |
23 |
import org.eclipse.persistence.internal.sessions.factories.model.clustering.RMIJNDIClusteringConfig; |
24 |
import org.eclipse.persistence.internal.sessions.factories.model.csm.CacheSynchronizationManagerConfig; |
25 |
import org.eclipse.persistence.internal.sessions.factories.model.log.DefaultSessionLogConfig; |
26 |
import org.eclipse.persistence.internal.sessions.factories.model.login.DatabaseLoginConfig; |
27 |
import org.eclipse.persistence.internal.sessions.factories.model.platform.CustomServerPlatformConfig; |
28 |
import org.eclipse.persistence.internal.sessions.factories.model.platform.ServerPlatformConfig; |
29 |
import org.eclipse.persistence.internal.sessions.factories.model.pool.PoolsConfig; |
30 |
import org.eclipse.persistence.internal.sessions.factories.model.pool.ReadConnectionPoolConfig; |
31 |
import org.eclipse.persistence.internal.sessions.factories.model.pool.WriteConnectionPoolConfig; |
32 |
import org.eclipse.persistence.internal.sessions.factories.model.project.ProjectClassConfig; |
33 |
import org.eclipse.persistence.internal.sessions.factories.model.property.PropertyConfig; |
34 |
import org.eclipse.persistence.internal.sessions.factories.model.rcm.RemoteCommandManagerConfig; |
35 |
import org.eclipse.persistence.internal.sessions.factories.model.session.DatabaseSessionConfig; |
36 |
import org.eclipse.persistence.internal.sessions.factories.model.session.ServerSessionConfig; |
37 |
import org.eclipse.persistence.internal.sessions.factories.model.transport.JMSTopicTransportManagerConfig; |
38 |
import org.eclipse.persistence.internal.sessions.factories.model.transport.naming.JNDINamingServiceConfig; |
39 |
|
40 |
/** |
41 |
* Tests the OX writing portion of the XMLSessionConfig model. |
42 |
* |
43 |
* @author Guy Pelletier |
44 |
* @version 1.0 |
45 |
* @date November 18, 2003 |
46 |
*/ |
47 |
public class SessionsXMLSchemaWriteTest extends AutoVerifyTestCase { |
48 |
private File m_resource; |
49 |
private DatabaseSessionConfig m_session; |
50 |
|
51 |
public SessionsXMLSchemaWriteTest() { |
52 |
setDescription("Test the writing portion of the session xml against the XML Schema"); |
53 |
} |
54 |
|
55 |
public void reset() { |
56 |
} |
57 |
|
58 |
protected void setup() throws Exception { |
59 |
m_resource = new File("XMLSchemaWriteTest.xml"); |
60 |
|
61 |
SessionConfigs sessions = new SessionConfigs(); |
62 |
|
63 |
DatabaseSessionConfig dbSessionConfig = new DatabaseSessionConfig(); |
64 |
|
65 |
// Cache synchronization manager |
66 |
CacheSynchronizationManagerConfig csmConfig = new CacheSynchronizationManagerConfig(); |
67 |
|
68 |
// Clustering service |
69 |
RMIJNDIClusteringConfig csConfig = new RMIJNDIClusteringConfig(); |
70 |
csConfig.setMulticastPort(new Integer(1973)); |
71 |
csConfig.setMulticastGroupAddress("somewhereunknown"); |
72 |
csConfig.setPacketTimeToLive(new Integer(31473)); |
73 |
csConfig.setJNDIPassword("password"); |
74 |
csConfig.setJNDIUsername("username"); |
75 |
csConfig.setNamingServiceInitialContextFactoryName("initialContextFactoryName"); |
76 |
csConfig.setNamingServiceURL("localhost:1099"); |
77 |
csmConfig.setClusteringServiceConfig(csConfig); |
78 |
|
79 |
csmConfig.setIsAsynchronous(true); |
80 |
csmConfig.setRemoveConnectionOnError(true); |
81 |
|
82 |
dbSessionConfig.setCacheSynchronizationManagerConfig(csmConfig); |
83 |
|
84 |
// Exception handler class |
85 |
dbSessionConfig.setExceptionHandlerClass("handlerClass"); |
86 |
|
87 |
// CustomServerPlatformConfid & External transaction controller |
88 |
CustomServerPlatformConfig platformConfig = new CustomServerPlatformConfig(); |
89 |
platformConfig.setExternalTransactionControllerClass("externalTransactionController"); |
90 |
dbSessionConfig.setServerPlatformConfig(platformConfig); |
91 |
|
92 |
// Log config |
93 |
DefaultSessionLogConfig logConfig = new DefaultSessionLogConfig(); |
94 |
logConfig.setLogLevel("severe"); |
95 |
logConfig.setFilename("logfile"); |
96 |
dbSessionConfig.setLogConfig(logConfig); |
97 |
|
98 |
// Login |
99 |
DatabaseLoginConfig loginConfig = new DatabaseLoginConfig(); |
100 |
loginConfig.setBatchWriting(true); |
101 |
loginConfig.setBindAllParameters(true); |
102 |
loginConfig.setByteArrayBinding(false); |
103 |
loginConfig.setCacheAllStatements(false); |
104 |
loginConfig.setConnectionURL("jdbc:oracle:thin:@otl-ora8infmx73:1521:toplinkj"); |
105 |
loginConfig.setDriverClass("oracle.jdbc.OracleDriver"); |
106 |
loginConfig.setExternalConnectionPooling(false); |
107 |
loginConfig.setExternalTransactionController(false); |
108 |
loginConfig.setForceFieldNamesToUppercase(false); |
109 |
loginConfig.setJdbcBatchWriting(false); |
110 |
loginConfig.setMaxBatchWritingSize(new Integer(5)); |
111 |
loginConfig.setNativeSequencing(false); |
112 |
loginConfig.setNativeSQL(false); |
113 |
loginConfig.setOptimizeDataConversion(true); |
114 |
loginConfig.setPassword("password"); |
115 |
loginConfig.setPlatformClass("platform"); |
116 |
loginConfig.setSequenceCounterField("SEQ_COUNT"); |
117 |
loginConfig.setSequenceNameField("SEQ_NAME"); |
118 |
loginConfig.setSequencePreallocationSize(new Integer(99)); |
119 |
loginConfig.setSequenceTable("SEQUENCE"); |
120 |
loginConfig.setStreamsForBinding(false); |
121 |
loginConfig.setStringBinding(false); |
122 |
loginConfig.setTableQualifier("table:"); |
123 |
loginConfig.setTrimStrings(true); |
124 |
loginConfig.setUsername("tljtest1"); |
125 |
dbSessionConfig.setLoginConfig(loginConfig); |
126 |
|
127 |
// Name |
128 |
dbSessionConfig.setName("EmployeeSession"); |
129 |
|
130 |
// Profiler |
131 |
dbSessionConfig.setProfiler("toplink"); |
132 |
|
133 |
// Primary project |
134 |
ProjectClassConfig projectConfig = new ProjectClassConfig(); |
135 |
projectConfig.setProjectString("org.eclipse.persistence.demos.employee.relational.EmployeeProject"); |
136 |
dbSessionConfig.setPrimaryProject(projectConfig); |
137 |
|
138 |
// Remote command manager |
139 |
RemoteCommandManagerConfig rcmConfig = new RemoteCommandManagerConfig(); |
140 |
rcmConfig.setChannel("new_channel"); |
141 |
|
142 |
// Transport Manager |
143 |
JMSTopicTransportManagerConfig transportConfig = new JMSTopicTransportManagerConfig(); |
144 |
transportConfig.setOnConnectionError("KeepConnection"); |
145 |
transportConfig.setTopicHostURL("ormi://jms_topic_host"); |
146 |
transportConfig.setTopicConnectionFactoryName("test-topic-connection-factory-name"); |
147 |
transportConfig.setTopicName("test-topic-name"); |
148 |
|
149 |
// Naming |
150 |
JNDINamingServiceConfig namingConfig = new JNDINamingServiceConfig(); |
151 |
namingConfig.setURL("new_jndi_url"); |
152 |
namingConfig.setUsername("guy"); |
153 |
namingConfig.setPassword("password"); |
154 |
namingConfig.setInitialContextFactoryName("new_initial_context_factory_name"); |
155 |
|
156 |
Vector props = new Vector(); |
157 |
PropertyConfig one = new PropertyConfig(); |
158 |
one.setName("name1"); |
159 |
one.setValue("value1"); |
160 |
props.add(one); |
161 |
PropertyConfig two = new PropertyConfig(); |
162 |
two.setName("name2"); |
163 |
two.setValue("value2"); |
164 |
props.add(two); |
165 |
namingConfig.setPropertyConfigs(props); |
166 |
|
167 |
transportConfig.setJNDINamingServiceConfig(namingConfig); |
168 |
|
169 |
rcmConfig.setTransportManagerConfig(transportConfig); |
170 |
dbSessionConfig.setRemoteCommandManagerConfig(rcmConfig); |
171 |
|
172 |
// Session customizer |
173 |
dbSessionConfig.setSessionCustomizerClass("sessionCustomizer"); |
174 |
|
175 |
sessions.addSessionConfig(dbSessionConfig); |
176 |
|
177 |
ServerSessionConfig serverSessionConfig = new ServerSessionConfig(); |
178 |
serverSessionConfig.setPoolsConfig(new PoolsConfig()); |
179 |
ReadConnectionPoolConfig readPool = new ReadConnectionPoolConfig(); |
180 |
readPool.setMaxConnections(new Integer(2)); |
181 |
readPool.setMinConnections(new Integer(2)); |
182 |
serverSessionConfig.getPoolsConfig().setReadConnectionPoolConfig(readPool); |
183 |
WriteConnectionPoolConfig writePool = new WriteConnectionPoolConfig(); |
184 |
writePool.setMaxConnections(new Integer(10)); |
185 |
writePool.setMinConnections(new Integer(5)); |
186 |
serverSessionConfig.getPoolsConfig().setWriteConnectionPoolConfig(writePool); |
187 |
WriteConnectionPoolConfig userPool = new WriteConnectionPoolConfig(); |
188 |
userPool.setMaxConnections(new Integer(5)); |
189 |
userPool.setMinConnections(new Integer(0)); |
190 |
serverSessionConfig.getPoolsConfig().addConnectionPoolConfig(userPool); |
191 |
sessions.addSessionConfig(serverSessionConfig); |
192 |
FileWriter writer = new FileWriter(m_resource); |
193 |
XMLSessionConfigWriter.write(sessions, writer); |
194 |
writer.close(); |
195 |
} |
196 |
|
197 |
public void test() { |
198 |
try { |
199 |
FileReader reader = new FileReader(m_resource); |
200 |
|
201 |
// XMLSessionConfigWriter uses the latest version of XMLSessionConfigProject to write; |
202 |
// therefore the latest version of XMLSessionConfigWriter should be used for reading, too. |
203 |
XMLContext context = new XMLContext(new XMLSessionConfigProject_11_1_1()); |
204 |
XMLUnmarshaller unmarshaller = context.createUnmarshaller(); |
205 |
SessionConfigs eclipseLinkSessions = (SessionConfigs)unmarshaller.unmarshal(reader); |
206 |
m_session = (DatabaseSessionConfig)eclipseLinkSessions.getSessionConfigs().firstElement(); |
207 |
} catch (Exception exception) { |
208 |
m_session = null; |
209 |
} |
210 |
} |
211 |
|
212 |
protected void verify() { |
213 |
if (m_session == null) { |
214 |
throw new TestErrorException("The session on read back was null"); |
215 |
} |
216 |
|
217 |
// Name |
218 |
check("Name", m_session.getName(), "EmployeeSession"); |
219 |
|
220 |
// Profiler |
221 |
check("Profiler", m_session.getProfiler(), "toplink"); |
222 |
|
223 |
// Primary project |
224 |
if (m_session.getPrimaryProject() != null) { |
225 |
check("ProjectClass", m_session.getPrimaryProject().getProjectString(), "org.eclipse.persistence.demos.employee.relational.EmployeeProject"); |
226 |
} else { |
227 |
throw new TestErrorException("ProjectClass was null"); |
228 |
} |
229 |
|
230 |
// Exception handler class |
231 |
check("ExceptionHandlerClass", m_session.getExceptionHandlerClass(), "handlerClass"); |
232 |
|
233 |
// guy |
234 |
// Custom server platform config |
235 |
if (m_session.getServerPlatformConfig() != null) { |
236 |
ServerPlatformConfig platformConfig = m_session.getServerPlatformConfig(); |
237 |
if (platformConfig instanceof CustomServerPlatformConfig) { |
238 |
check("ExternalTransactionControllerClass", ((CustomServerPlatformConfig)platformConfig).getExternalTransactionControllerClass(), "externalTransactionController"); |
239 |
} else { |
240 |
throw new TestErrorException("ServerPlatformConfig not correct type"); |
241 |
} |
242 |
} else { |
243 |
throw new TestErrorException("ServerPlatformConfig was null"); |
244 |
} |
245 |
|
246 |
// Session customizer |
247 |
check("SessionCustomizer", m_session.getSessionCustomizerClass(), "sessionCustomizer"); |
248 |
|
249 |
// Cache synchronization manager |
250 |
CacheSynchronizationManagerConfig csmConfig = m_session.getCacheSynchronizationManagerConfig(); |
251 |
|
252 |
if (csmConfig == null) { |
253 |
throw new TestErrorException("CacheSynchronizationManagerConfig was null"); |
254 |
} else { |
255 |
checkBoolean("IsAsynchronous", csmConfig.getIsAsynchronous(), true); |
256 |
checkBoolean("RemoveConnectionOnError", csmConfig.getRemoveConnectionOnError(), true); |
257 |
|
258 |
// Clustering service |
259 |
if (!(csmConfig.getClusteringServiceConfig() instanceof RMIJNDIClusteringConfig)) { |
260 |
throw new TestErrorException("ClusteringServiceConfig not correct type"); |
261 |
} |
262 |
|
263 |
RMIJNDIClusteringConfig csConfig = (RMIJNDIClusteringConfig)csmConfig.getClusteringServiceConfig(); |
264 |
check("MulticastPort", csConfig.getMulticastPort(), new Integer(1973)); |
265 |
check("MulticastGroupAddress", csConfig.getMulticastGroupAddress(), "somewhereunknown"); |
266 |
check("PacketTimeToLive", csConfig.getPacketTimeToLive(), new Integer(31473)); |
267 |
check("JNDIPassword", csConfig.getJNDIPassword(), "password"); |
268 |
check("JNDIUsername", csConfig.getJNDIUsername(), "username"); |
269 |
check("NamingServiceInitialContextFactoryName", csConfig.getNamingServiceInitialContextFactoryName(), "initialContextFactoryName"); |
270 |
check("NamingServiceURL", csConfig.getNamingServiceURL(), "localhost:1099"); |
271 |
} |
272 |
|
273 |
// Log config |
274 |
if (m_session.getLogConfig() instanceof DefaultSessionLogConfig) { |
275 |
DefaultSessionLogConfig logConfig = (DefaultSessionLogConfig)m_session.getLogConfig(); |
276 |
check("LogLevel", logConfig.getLogLevel(), "severe"); |
277 |
check("Filename", logConfig.getFilename(), "logfile"); |
278 |
} else { |
279 |
throw new TestErrorException("LogConfig not correct type"); |
280 |
} |
281 |
|
282 |
// Login |
283 |
if (m_session.getLoginConfig() instanceof DatabaseLoginConfig) { |
284 |
DatabaseLoginConfig loginConfig = (DatabaseLoginConfig)m_session.getLoginConfig(); |
285 |
checkBoolean("BatchWriting", loginConfig.getBatchWriting(), true); |
286 |
checkBoolean("BindAllParameters", loginConfig.getBindAllParameters(), true); |
287 |
checkBoolean("ByteArrayBinding", loginConfig.getByteArrayBinding(), false); |
288 |
checkBoolean("CacheAllStatements", loginConfig.getCacheAllStatements(), false); |
289 |
check("ConnectionURL", loginConfig.getConnectionURL(), "jdbc:oracle:thin:@otl-ora8infmx73:1521:toplinkj"); |
290 |
check("DriverClass", loginConfig.getDriverClass(), "oracle.jdbc.OracleDriver"); |
291 |
checkBoolean("ExternalConnectionPooling", loginConfig.getExternalConnectionPooling(), false); |
292 |
checkBoolean("ExternalTransactionController", loginConfig.getExternalTransactionController(), false); |
293 |
checkBoolean("ForceFieldNamesToUppercase", loginConfig.getForceFieldNamesToUppercase(), false); |
294 |
checkBoolean("JdbcBatchWriting", loginConfig.getJdbcBatchWriting(), false); |
295 |
check("MaxBatchWritingSize", loginConfig.getMaxBatchWritingSize(), new Integer(5)); |
296 |
checkBoolean("NativeSequencing", loginConfig.getNativeSequencing(), false); |
297 |
checkBoolean("NativeSQL", loginConfig.getNativeSQL(), false); |
298 |
checkBoolean("OptimizeDataConversion", loginConfig.getOptimizeDataConversion(), true); |
299 |
check("Password", loginConfig.getPassword(), "password"); |
300 |
check("PlatformClass", loginConfig.getPlatformClass(), "platform"); |
301 |
check("SequenceCounterField", loginConfig.getSequenceCounterField(), "SEQ_COUNT"); |
302 |
check("SequenceNameField", loginConfig.getSequenceNameField(), "SEQ_NAME"); |
303 |
check("SequencePreallocationSize", loginConfig.getSequencePreallocationSize(), new Integer(99)); |
304 |
check("SequenceTable", loginConfig.getSequenceTable(), "SEQUENCE"); |
305 |
checkBoolean("StreamsForBinding", loginConfig.getStreamsForBinding(), false); |
306 |
checkBoolean("StringBinding", loginConfig.getStringBinding(), false); |
307 |
check("TableQualifier", loginConfig.getTableQualifier(), "table:"); |
308 |
checkBoolean("TrimStrings", loginConfig.getTrimStrings(), true); |
309 |
check("Username", loginConfig.getUsername(), "tljtest1"); |
310 |
} else { |
311 |
throw new TestErrorException("LogConfig not correct type"); |
312 |
} |
313 |
|
314 |
// Remote command manager |
315 |
RemoteCommandManagerConfig rcmConfig = m_session.getRemoteCommandManagerConfig(); |
316 |
|
317 |
if (rcmConfig == null) { |
318 |
throw new TestErrorException("RemoteCommandManagerConfig was null"); |
319 |
} else { |
320 |
// Channel |
321 |
check("Channel", rcmConfig.getChannel(), "new_channel"); |
322 |
|
323 |
if (rcmConfig.getTransportManagerConfig() instanceof JMSTopicTransportManagerConfig) { |
324 |
// Transport manager |
325 |
JMSTopicTransportManagerConfig transportConfig = (JMSTopicTransportManagerConfig)rcmConfig.getTransportManagerConfig(); |
326 |
check("OnConnectionError", transportConfig.getOnConnectionError(), "KeepConnection"); |
327 |
check("TopicHostURL", transportConfig.getTopicHostURL(), "ormi://jms_topic_host"); |
328 |
check("TopicConnectionFactoryName", transportConfig.getTopicConnectionFactoryName(), "test-topic-connection-factory-name"); |
329 |
check("TopicName", transportConfig.getTopicName(), "test-topic-name"); |
330 |
|
331 |
// Naming |
332 |
JNDINamingServiceConfig namingConfig = transportConfig.getJNDINamingServiceConfig(); |
333 |
|
334 |
if (namingConfig == null) { |
335 |
throw new TestErrorException("JNDINamingServiceConfig was null"); |
336 |
} else { |
337 |
check("Naming URL", namingConfig.getURL(), "new_jndi_url"); |
338 |
check("Naming Username", namingConfig.getUsername(), "guy"); |
339 |
check("Naming Password", namingConfig.getPassword(), "password"); |
340 |
check("InitialContextFactoryName", namingConfig.getInitialContextFactoryName(), "new_initial_context_factory_name"); |
341 |
|
342 |
// Properties |
343 |
Vector propertyConfigs = namingConfig.getPropertyConfigs(); |
344 |
|
345 |
if (propertyConfigs == null) { |
346 |
throw new TestErrorException("PropertyConfigs were null"); |
347 |
} else if (propertyConfigs.size() != 2) { |
348 |
throw new TestErrorException("PropertyConfigs were not the correct size"); |
349 |
} else { |
350 |
PropertyConfig one = (PropertyConfig)propertyConfigs.firstElement(); |
351 |
check("Property name", one.getName(), "name1"); |
352 |
check("Property value", one.getValue(), "value1"); |
353 |
|
354 |
PropertyConfig two = (PropertyConfig)propertyConfigs.lastElement(); |
355 |
check("Property name", two.getName(), "name2"); |
356 |
check("Property value", two.getValue(), "value2"); |
357 |
} |
358 |
} |
359 |
} else { |
360 |
throw new TestErrorException("TransportManagerConfig not correct type"); |
361 |
} |
362 |
} |
363 |
} |
364 |
|
365 |
private void checkBoolean(String name, boolean one, boolean two) { |
366 |
if (one != two) { |
367 |
throw new TestErrorException("For: " + name + ", expecting: " + one + ", found: " + two); |
368 |
} |
369 |
} |
370 |
|
371 |
private void check(String name, Object one, Object two) { |
372 |
if (!one.equals(two)) { |
373 |
throw new TestErrorException("For: " + name + ", expecting: " + one + ", found: " + two); |
374 |
} |
375 |
} |
376 |
} |