KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mmbase > bridge > NodeTest


1 /*
2
3 This software is OSI Certified Open Source Software.
4 OSI Certified is a certification mark of the Open Source Initiative.
5
6 The license (Mozilla version 1.0) can be read at the MMBase site.
7 See http://www.MMBase.org/license
8
9 */

10
11 package org.mmbase.bridge;
12
13 import java.util.Iterator JavaDoc;
14 import org.mmbase.tests.*;
15
16 /**
17  * Basic test class to test <code>Node</code> from the bridge package.
18  *
19  * @author Michiel Meeuwissen
20  * @author Jaco de Groot
21  */

22 public abstract class NodeTest extends BridgeTest {
23     protected Node node;
24     protected static String JavaDoc[] fieldTypes = {"byte", "double", "float", "int", "long", "string", "xml", "node", "datetime", "boolean"}; //, "list"};
25
//protected static String[] fieldTypes = {"datetime"};
26

27     public NodeTest(String JavaDoc name) {
28         super(name);
29     }
30
31     protected String JavaDoc getNodeManager() {
32         return "aa";
33     }
34
35     abstract public void testGetValue();
36
37     public void testGetValueCache() {
38         // Test if the first call doesn't make MMBase cache an incorrect value.
39
testGetValue();
40         testGetByteValue();
41         testGetDoubleValue();
42         testGetFloatValue();
43         testGetIntValue();
44         testGetLongValue();
45         testGetStringValue();
46         testGetXMLValue();
47         testGetNodeValue();
48         testGetBooleanValue();
49         testGetDateTimeValue();
50         testGetListValue();
51     }
52
53     abstract public void testGetByteValue();
54
55     public void testGetByteValueCache() {
56         // Test if the first call doesn't make MMBase cache an incorrect value.
57
testGetByteValue();
58         testGetValue();
59         testGetDoubleValue();
60         testGetFloatValue();
61         testGetIntValue();
62         testGetLongValue();
63         testGetStringValue();
64         testGetXMLValue();
65         testGetNodeValue();
66         testGetBooleanValue();
67         testGetDateTimeValue();
68         testGetListValue();
69     }
70
71     abstract public void testGetDoubleValue();
72
73     public void testGetDoubleValueCache() {
74         // Test if the first call doesn't make MMBase cache an incorrect value.
75
testGetDoubleValue();
76         testGetValue();
77         testGetByteValue();
78         testGetFloatValue();
79         testGetIntValue();
80         testGetLongValue();
81         testGetStringValue();
82         testGetXMLValue();
83         testGetNodeValue();
84         testGetBooleanValue();
85         testGetDateTimeValue();
86         testGetListValue();
87     }
88
89     abstract public void testGetFloatValue();
90
91     public void testGetFloatValueCache() {
92         // Test if the first call doesn't make MMBase cache an incorrect value.
93
testGetFloatValue();
94         testGetValue();
95         testGetByteValue();
96         testGetDoubleValue();
97         testGetIntValue();
98         testGetLongValue();
99         testGetStringValue();
100         testGetXMLValue();
101         testGetNodeValue();
102     }
103
104     abstract public void testGetIntValue();
105
106     public void testGetIntValueCache() {
107         // Test if the first call doesn't make MMBase cache an incorrect value.
108
testGetIntValue();
109         testGetValue();
110         testGetByteValue();
111         testGetDoubleValue();
112         testGetFloatValue();
113         testGetLongValue();
114         testGetStringValue();
115         testGetXMLValue();
116         testGetNodeValue();
117         testGetBooleanValue();
118         testGetDateTimeValue();
119         testGetListValue();
120     }
121
122     abstract public void testGetLongValue();
123
124     public void testGetLongValueCache() {
125         // Test if the first call doesn't make MMBase cache an incorrect value.
126
testGetLongValue();
127         testGetValue();
128         testGetByteValue();
129         testGetDoubleValue();
130         testGetFloatValue();
131         testGetIntValue();
132         testGetStringValue();
133         testGetXMLValue();
134         testGetNodeValue();
135         testGetBooleanValue();
136         testGetDateTimeValue();
137         testGetListValue();
138     }
139
140     abstract public void testGetStringValue();
141
142     public void testGetStringValueCache() {
143         // Test if the first call doesn't make MMBase cache an incorrect value.
144
testGetStringValue();
145         testGetValue();
146         testGetByteValue();
147         testGetDoubleValue();
148         testGetFloatValue();
149         testGetIntValue();
150         testGetLongValue();
151         testGetXMLValue();
152         testGetNodeValue();
153         testGetBooleanValue();
154         testGetDateTimeValue();
155         testGetListValue();
156     }
157
158     abstract public void testGetXMLValue();
159
160     public void testGetXMLValueCache() {
161         // Test if the first call doesn't make MMBase cache an incorrect value.
162
testGetXMLValue();
163         testGetValue();
164         testGetByteValue();
165         testGetDoubleValue();
166         testGetFloatValue();
167         testGetIntValue();
168         testGetLongValue();
169         testGetStringValue();
170         testGetNodeValue();
171         testGetBooleanValue();
172         testGetDateTimeValue();
173         testGetListValue();
174     }
175
176     abstract public void testGetNodeValue();
177
178     public void testGetNodeValueCache() {
179         // Test if the first call doesn't make MMBase cache an incorrect value.
180
testGetNodeValue();
181         testGetValue();
182         testGetByteValue();
183         testGetDoubleValue();
184         testGetFloatValue();
185         testGetIntValue();
186         testGetLongValue();
187         testGetStringValue();
188         testGetXMLValue();
189         testGetBooleanValue();
190         testGetDateTimeValue();
191         testGetListValue();
192     }
193
194     abstract public void testGetBooleanValue();
195
196     public void testGetBooleanValueCache() {
197         // Test if the first call doesn't make MMBase cache an incorrect value.
198
testGetBooleanValue();
199         testGetValue();
200         testGetByteValue();
201         testGetDoubleValue();
202         testGetFloatValue();
203         testGetIntValue();
204         testGetLongValue();
205         testGetStringValue();
206         testGetXMLValue();
207         testGetNodeValue();
208         testGetDateTimeValue();
209         testGetListValue();
210     }
211
212     abstract public void testGetDateTimeValue();
213
214     public void testGetDateTimeValueCache() {
215         // Test if the first call doesn't make MMBase cache an incorrect value.
216
testGetDateTimeValue();
217         testGetValue();
218         testGetByteValue();
219         testGetDoubleValue();
220         testGetFloatValue();
221         testGetIntValue();
222         testGetLongValue();
223         testGetStringValue();
224         testGetXMLValue();
225         testGetNodeValue();
226         testGetBooleanValue();
227         testGetListValue();
228     }
229
230     abstract public void testGetListValue();
231
232     public void testGetListValueCache() {
233         // Test if the first call doesn't make MMBase cache an incorrect value.
234
testGetListValue();
235         testGetValue();
236         testGetByteValue();
237         testGetDoubleValue();
238         testGetFloatValue();
239         testGetIntValue();
240         testGetLongValue();
241         testGetStringValue();
242         testGetXMLValue();
243         testGetNodeValue();
244         testGetBooleanValue();
245         testGetDateTimeValue();
246     }
247
248     public void testSetSNumber() {
249         try {
250             node.setIntValue("snumber", 100);
251             fail("Should raise a BridgeException");
252         } catch (BridgeException e) {
253         }
254     }
255
256     public void testSetDNumber() {
257         try {
258             node.setIntValue("dnumber", 100);
259             fail("Should raise a BridgeException");
260         } catch (BridgeException e) {
261         }
262     }
263
264     public void testSetRNumber() {
265         try {
266             node.setIntValue("rnumber", 100);
267             fail("Should raise a BridgeException");
268         } catch (BridgeException e) {
269         }
270     }
271
272
273     public void testSetOType() {
274         try {
275             node.setIntValue("otype", 100);
276             fail("Should raise a BridgeException");
277         } catch (BridgeException e) {
278         }
279     }
280
281     public void testCreateAlias() {
282         node.createAlias("node_alias");
283         node.commit();
284         // look it up again
285
boolean found = false;
286         Iterator JavaDoc i = node.getAliases().iterator();
287         while (i.hasNext()) {
288             String JavaDoc alias = (String JavaDoc)i.next();
289             if ("node_alias".equals(alias)) found = true;
290         }
291         assertTrue(found);
292     }
293
294     protected String JavaDoc getOtherContext(Node n) {
295         String JavaDoc context = n.getContext();
296         StringIterator possibleContexts = n.getPossibleContexts().stringIterator();
297         while (possibleContexts.hasNext()) {
298             String JavaDoc listContext = possibleContexts.nextString();
299             if (! context.equals(listContext)){
300                 return listContext;
301             }
302         }
303         return context;
304     }
305
306
307     public void testSetContext() {
308
309         String JavaDoc context = node.getContext();
310         String JavaDoc otherContext = getOtherContext(node);
311
312         if (otherContext.equals(context)) {
313             otherContext = context + "other";
314             System.err.println("Could not find other context than " + context + ", setting to '" + otherContext + "'");
315         }
316
317         // set context to something different:
318
node.setContext(otherContext);
319         // now, the new context must be equal to otherContext
320
assertEquals("Context did not change '" + otherContext + "' != '" + node.getContext() + "'", otherContext, node.getContext());
321         assertEquals(node.getContext(), node.getValue("owner"));
322         node.commit();
323
324         assertEquals("Context did not change '" + otherContext + "' != '" + node.getContext() + "'", otherContext, node.getContext());
325         assertEquals(node.getContext(), node.getValue("owner"));
326     }
327
328     public void testSetOwner() {
329         String JavaDoc context = node.getContext();
330         String JavaDoc otherContext = getOtherContext(node);
331
332         if (otherContext.equals(context)) {
333             otherContext = context + "other";
334             System.err.println("Could not find other context than " + context + ", setting to '" + otherContext + "'");
335         }
336
337         // set context to something different:
338
node.setValue("owner", otherContext);
339         // now, the new context must be equal to otherContext
340
assertEquals("Context did not change '" + otherContext + "' != '" + node.getContext() + "'", otherContext, node.getContext());
341         assertEquals(node.getContext(), node.getValue("owner"));
342
343         node.commit();
344
345         assertEquals("Context did not change '" + otherContext + "' != '" + node.getContext() + "'", otherContext, node.getContext());
346         assertEquals(node.getContext(), node.getValue("owner"));
347
348
349     }
350
351     public void testFieldGUI() {
352         try {
353             node.getStringValue("gui()");
354             node.getValue("gui()");
355         } catch (Throwable JavaDoc e) {
356             fail("Should not raise exception but gave: " + e.getMessage() + org.mmbase.util.logging.Logging.stackTrace(e, 20));
357         }
358     }
359
360 }
361
Popular Tags