1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo;
24
25 import java.util.ResourceBundle;
26
27 import junit.framework.TestCase;
28
29 /***
30 * Base class for all domingo test cases.
31 *
32 * @author MarcusT
33 */
34 public abstract class BaseProxyTest extends TestCase {
35
36 private static ResourceBundle myResources = ResourceBundle.getBundle("de.bea.domingo.test");
37
38 private static final String SERVER_URL = myResources.getString("test.server");
39 private static final String USERNAME = myResources.getString("test.username");
40 private static final String PASSWORD = myResources.getString("test.password");
41
42 private DNotesFactory factory;
43 private DSession session;
44 private DDatabase logDatabase;
45 private String serverName = "";
46
47 /***
48 * @param name the name of the test
49 */
50 public BaseProxyTest(String name) {
51 super(name);
52 }
53
54 /***
55 * Sets up the test class.
56 */
57 protected final void baseSetUp() {
58 try {
59 factory = DNotesFactory.getInstance();
60 if (isAssignableFrom(factory, "de.bea.domingo.http.NotesHttpFactory")) {
61 session = factory.getSession(SERVER_URL, USERNAME, PASSWORD);
62 logDatabase = session.getDatabase("", "log.nsf");
63 } else {
64 session = factory.getSession();
65 logDatabase = session.getDatabase(serverName, "log.nsf");
66 }
67 } catch (Exception e) {
68 e.printStackTrace();
69 fail(e.getMessage());
70 }
71 }
72
73 /***
74 * Dynamic checks if an object is an instance of a class given by its name.
75 *
76 * @param object the object to check
77 * @param className the class name to check against
78 * @return <code>true</code> if the object is an instance of the specified class, else <code>false</code>
79 */
80 private boolean isAssignableFrom(final Object object, final String className) {
81 if (object == null) {
82 return false;
83 }
84 try {
85 return object.getClass().isAssignableFrom(Class.forName(className));
86 } catch (ClassNotFoundException e) {
87 return false;
88 }
89 }
90
91 /***
92 * Returns the current session.
93 *
94 * @return session
95 */
96 protected final DSession getSession() {
97 return session;
98 }
99
100 /***
101 * Returns a log database of the specified server to test with.
102 *
103 * @return the log database
104 */
105 protected final DDatabase getDatabase() {
106 return logDatabase;
107 }
108
109 /***
110 * Returns the name of the server to test with.
111 *
112 * @return server name
113 */
114 protected final String getServerName() {
115 return serverName;
116 }
117 }