01: package org.dbbrowser.drivermanager;
02:
03: import java.io.File;
04: import java.io.IOException;
05: import java.util.ArrayList;
06: import java.util.Date;
07: import java.util.List;
08: import infrastructure.logging.Log;
09: import junit.framework.TestCase;
10:
11: public class ConnectionInfoTest extends TestCase {
12: public ConnectionInfoTest(String name) {
13: super (name);
14: }
15:
16: public void testSerializeConnectionInfo() {
17: Log.getInstance().debugMessage(
18: "Test serialize Connection Info",
19: this .getClass().getName());
20:
21: ConnectionInfo connectionInfo = new ConnectionInfo(
22: "oracle.jdbc.OracleDriver", new File(
23: "C:/projects/DBBrowser/lib/ojdbc14.jar"),
24: "Oracle XCS Charging connection", "Oracle",
25: "jdbc:oracle:thin:@localhost:1521:xcs", "system",
26: "qwerty", null, null);
27: connectionInfo.setLastUsed(new Date());
28: ArrayList listOfconnectionInfos = new ArrayList();
29: listOfconnectionInfos.add(connectionInfo);
30:
31: //Serialize the object
32: /*try
33: {
34: ConnectionInfoSerializer.serialize( listOfconnectionInfos );
35: }
36: catch(IOException exc)
37: {
38: Log.getInstance().fatalMessage("*** IOException *** " + exc.getMessage(), this.getClass().getName());
39: fail(exc.getMessage());
40: }*/
41: }
42:
43: public void testDeSerializeConnectionInfo() {
44: Log.getInstance().debugMessage(
45: "Test de-serialize Connection Info",
46: this .getClass().getName());
47:
48: ConnectionInfo connectionInfo1 = new ConnectionInfo(
49: "oracle.jdbc.OracleDriver", new File(
50: "C:/projects/DBBrowser/lib/ojdbc14.jar"),
51: "Oracle XCS Charging connection", "Oracle",
52: "jdbc:oracle:thin:@localhost:1521:xcs", "system",
53: "qwerty", null, null);
54:
55: //Serialize the object
56: try {
57: List listOfconnectionInfos = ConnectionInfoSerializer
58: .deserialize();
59:
60: ConnectionInfo connectionInfo2 = (ConnectionInfo) listOfconnectionInfos
61: .get(0);
62: Log.getInstance().debugMessage(connectionInfo2.toString(),
63: this .getClass().getName());
64:
65: //asserts
66: assertEquals(connectionInfo1.getName(), connectionInfo2
67: .getName());
68: assertEquals(connectionInfo1.getDatabaseURL(),
69: connectionInfo2.getDatabaseURL());
70: assertEquals(connectionInfo1.getDriverClassName(),
71: connectionInfo2.getDriverClassName());
72: assertEquals(
73: connectionInfo1.getJdbcDriverJarFileLocation(),
74: connectionInfo2.getJdbcDriverJarFileLocation());
75: assertEquals(connectionInfo1.getUsername(), connectionInfo2
76: .getUsername());
77: assertEquals(connectionInfo1.getPassword(), connectionInfo2
78: .getPassword());
79: } catch (IOException exc) {
80: Log.getInstance().fatalMessage(
81: "*** IOException *** " + exc.getMessage(),
82: this .getClass().getName());
83: fail(exc.getMessage());
84: } catch (ClassNotFoundException exc) {
85: Log.getInstance().fatalMessage(
86: "*** IOException *** " + exc.getMessage(),
87: this.getClass().getName());
88: fail(exc.getMessage());
89: }
90: }
91: }
|