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.List;
26
27 /***
28 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
29 */
30 public final class SessionProxyTest extends BaseProxyTest {
31
32 /***
33 * @param name the name of the test
34 */
35 public SessionProxyTest(String name) {
36 super(name);
37 }
38
39 /***
40 * Setup test case.
41 */
42 public void setUp() {
43 baseSetUp();
44 }
45
46 /***
47 * Tests the ability to create a database.
48 */
49 public void testCreateDatabase() {
50 System.out.println("-> testCreateDatabase");
51
52 String dbName = System.currentTimeMillis() + "SessionProxyTest.nsf";
53 DDatabase database = getSession().createDatabase("", dbName);
54 assertNotNull("Database file should exist.", database);
55
56 DDocument doc = database.createDocument();
57 assertTrue("Document should have been saved.", doc.save());
58
59 database.remove();
60 }
61
62 /***
63 * Tests a session to provide existing databases.
64 */
65 public void testGetDatabase() {
66 System.out.println("-> testGetDatabase");
67 String databaseName = "log.nsf";
68 DDatabase database = null;
69 try {
70 database = getSession().getDatabase(getServerName(), databaseName);
71 } catch (DNotesException e) {
72 e.printStackTrace();
73 fail("Cannot open database " + getServerName() + "!!" + databaseName);
74 }
75 assertTrue("Database name should be '" + databaseName + "'.", database != null
76 && databaseName.equals(database.getFilePath()));
77 }
78
79 /***
80 * Tests a session to return the user's name.
81 */
82 public void testGetUserName() {
83 System.out.println("-> testGetUserName");
84 String userName = getSession().getUserName();
85 assertTrue("At least a string longer than 0 should be returned.", userName != null && userName.length() > 0);
86 }
87
88 /***
89 * Tests a session to return the common user's name.
90 */
91 public void testGetCommonUserName() {
92 System.out.println("-> testGetCommonUserName");
93 String userName = getSession().getCommonUserName();
94 assertTrue("At least a string longer than 0 should be returned.", userName != null && userName.length() > 0);
95 }
96
97 /***
98 * Tests a session to return the common user's name.
99 */
100 public void testGetCanonicalUserName() {
101 System.out.println("-> testGetCanonicalUserName");
102 String userName = getSession().getCanonicalUserName();
103 assertTrue("At least a string longer than 0 should be returned.", userName != null && userName.length() > 0);
104 }
105
106 /***
107 * Tests a session to return the common user's name.
108 */
109 public void testIsOnServer() {
110 System.out.println("-> testIsOnServer");
111 boolean isOnServer = getSession().isOnServer();
112 assertTrue("Method isOnServer Should return false.", !isOnServer);
113 }
114
115 /***
116 * Tests getEnvironmentString(String).
117 */
118 public void testGetEnvironmentString() {
119 System.out.println("-> testGetEnvironmentString");
120 String env = "Directory";
121 getSession().setEnvironmentString(env, "XXX", false);
122 String value = getSession().getEnvironmentString(env);
123 assertTrue("Environment not found: " + env, value != null && ((String) value).length() > 0);
124 }
125
126 /***
127 * Tests getEnvironmentValue(String).
128 */
129 public void testGetEnvironmentValue() {
130 System.out.println("-> testGetEnvironmentString");
131 String env = "Directory";
132 getSession().setEnvironmentString(env, "XXX", false);
133 Object value = getSession().getEnvironmentValue(env);
134 assertTrue(value instanceof String);
135 assertTrue("Environment not found: " + env, value != null && ((String) value).length() > 0);
136 }
137
138 /***
139 * Tests getEnvironmentString(String, boolean).
140 */
141 public void testGetEnvironmentStringFalse() {
142 System.out.println("-> testGetEnvironmentString");
143 String env = "Directory";
144 String value = getSession().getEnvironmentString(env, false);
145 assertTrue("Environment not found: " + env, value != null && ((String) value).length() > 0);
146 }
147
148 /***
149 * Tests getEnvironmentValue(String, boolean).
150 */
151 public void testGetEnvironmentValueFalse() {
152 System.out.println("-> testGetEnvironmentString");
153 String env = "Directory";
154 Object value = getSession().getEnvironmentValue(env, false);
155 assertTrue(value instanceof String);
156 assertTrue("Environment not found: " + env, value != null && ((String) value).length() > 0);
157 }
158
159 /***
160 * Tests evaluate method.
161 */
162 public void testEvaluate() {
163 System.out.println("-> testEvaluate");
164 Object obj = null;
165 try {
166 obj = getSession().evaluate("\"A\": \"B\": \"C\"");
167 } catch (DNotesException e) {
168 fail(e.getMessage());
169 e.printStackTrace();
170 }
171 assertTrue(obj instanceof List);
172 List list = (List) obj;
173 assertTrue(list.size() == 3);
174 assertTrue("A".equals(list.get(0)));
175 assertTrue("B".equals(list.get(1)));
176 assertTrue("C".equals(list.get(2)));
177
178 DDatabase db = null;
179 DDocument doc = null;
180
181 doc = (DDocument) getDatabase().getAllDocuments().next();
182 try {
183 obj = getSession().evaluate("@UserNamesList", doc);
184 System.out.println("result: " + obj);
185 } catch (DNotesException e) {
186 fail(e.getMessage());
187 e.printStackTrace();
188 }
189
190 String databaseName = "log.nsf";
191 try {
192 db = getSession().getDatabase("", databaseName);
193 } catch (DNotesException e1) {
194 e1.printStackTrace();
195 fail("Cannot open local database " + databaseName);
196 }
197 doc = (DDocument) db.getAllDocuments().next();
198 try {
199 obj = getSession().evaluate("@UserNamesList", doc);
200 System.out.println("result: " + obj);
201 } catch (DNotesException e) {
202 fail(e.getMessage());
203 e.printStackTrace();
204 }
205 assertTrue(obj instanceof List);
206 doc = null;
207 db = null;
208
209 assertTrue(obj instanceof List);
210 }
211
212 /***
213 * Tests createLog(String).
214 */
215 public void testCreateLog() {
216 System.out.println("-> testCreateLog");
217 DLog log = getSession().createLog("Domingo_Log");
218 log.openNotesLog(getServerName(), "log.nsf");
219 log.logAction("log something");
220 }
221 }