KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.mmbase.tests.*;
14 /**
15  * Test class <code>Cloud</code> from the bridge package.
16  *
17  * @author Jaco de Groot
18  */

19 public class CloudTest extends BridgeTest {
20     Cloud cloud;
21     Node aaNode1;
22     Node aaNode2;
23     Node bbNode;
24     Node[] bbNodes;
25     int nrOfBBNodes;
26
27     public CloudTest(String JavaDoc name) {
28         super(name);
29     }
30
31     public void setUp() {
32         // Create a test node.
33
cloud = getCloud();
34         aaNode1 = cloud.getNodeManager("aa").createNode();
35         aaNode1.setStringValue("stringfield", "startnode1");
36         aaNode1.commit();
37         aaNode2 = cloud.getNodeManager("aa").createNode();
38         aaNode2.setStringValue("stringfield", "startnode2");
39         aaNode2.commit();
40         bbNode = cloud.getNodeManager("bb").createNode();
41         bbNode.setStringValue("stringfield", "bbNode");
42         bbNode.commit();
43         RelationManager relationManager;
44         relationManager = cloud.getRelationManager("aa", "bb", "related");
45         Relation relation;
46         relation = relationManager.createRelation(aaNode2, bbNode);
47         relation.commit();
48         bbNodes = new Node[11];
49         nrOfBBNodes = 0;
50         for (int i = -5; i < 6; i++) {
51             String JavaDoc s = new Integer JavaDoc(i).toString();
52             Node node;
53             node = cloud.getNodeManager("bb").createNode();
54             node.setByteValue("bytefield", s.getBytes());
55             node.setDoubleValue("doublefield", i);
56             node.setFloatValue("floatfield", i);
57             node.setIntValue("intfield", i);
58             node.setLongValue("longfield", i);
59             node.setStringValue("stringfield", s);
60             node.commit();
61             bbNodes[nrOfBBNodes] = node;
62             relation = relationManager.createRelation(aaNode1, node);
63             relation.commit();
64             nrOfBBNodes++;
65         }
66     }
67
68     public void tearDown() {
69         // Remove test nodes.
70
aaNode1.delete(true);
71         aaNode2.delete(true);
72         bbNode.delete(true);
73         for (int i = 0; i < nrOfBBNodes; i++) {
74             bbNodes[i].delete(true);
75         }
76     }
77
78     public void testGetList() {
79         NodeList nodeList;
80         nodeList = cloud.getList("" + aaNode1.getNumber(), "aa,bb", "aa.bytefield", "", "", "", "", false);
81         assertTrue(nodeList.size() == nrOfBBNodes);
82     }
83
84     public void testGetListWithNullParameters() {
85         try {
86             cloud.getList(null, null, null, null, null, null, null, false);
87             fail("Should raise a BridgeException");
88         } catch (BridgeException e) {}
89     }
90
91     public void testGetListWithEmptyParameters() {
92         try {
93             cloud.getList("", "", "", "", "", "", "", false);
94             fail("Should raise a BridgeException");
95         } catch (BridgeException e) {}
96     }
97
98     public void testGetListWithNullParameterStartNodes() {
99         NodeList nodeList;
100         nodeList = cloud.getList(null, "aa,bb", "aa.bytefield", "", "", "", "", false);
101         assertTrue(nodeList.size() == nrOfBBNodes + 1);
102     }
103
104     public void testGetListWithEmptyParameterStartNodes() {
105         NodeList nodeList;
106         nodeList = cloud.getList("", "aa,bb", "aa.bytefield", "", "", "", "", false);
107         assertTrue(nodeList.size() == nrOfBBNodes + 1);
108     }
109
110     /*
111     This test is obsolete, the new API allows these queries
112      
113     public void testGetListWithInvalidParameterStartNodes() {
114         try {
115             NodeList nodeList;
116             nodeList = cloud.getList("" + bbNode.getNumber(), "aa,bb", "aa.bytefield", "", "", "", "", false);
117             fail("Should raise a BridgeException, but gave following list: " + nodeList);
118         } catch (BridgeException e) {}
119     }
120     */

121
122     public void testGetListWithNullParameterNodePath() {
123         try {
124             cloud.getList(null, null, "bytefield", "", "", "", "", false);
125             fail("Should raise a BridgeException");
126         } catch (BridgeException e) {}
127     }
128
129     public void testGetListWithEmptyParameterNodePath() {
130         try {
131             cloud.getList(null, "", "bytefield", "", "", "", "", false);
132             fail("Should raise a BridgeException");
133         } catch (BridgeException e) {}
134     }
135
136     public void testGetListWithInvalidParameterNodePath() {
137         try {
138             cloud.getList(null, "x", "bytefield", "", "", "", "", false);
139             fail("Should raise a BridgeException");
140         } catch (BridgeException e) {}
141     }
142
143     /*
144     This test is now obsolete, the new API allows these queries
145     public void testGetListWithNullParameterFields() {
146         try {
147             NodeList nodeList;
148             nodeList = cloud.getList(null, "aa,bb", null, "", "", "", "", false);
149             fail("Should raise a BridgeException, but returned: " + nodeList);
150         } catch (BridgeException e) {}
151     }
152
153     */

154     
155     /*
156     This test is now obsolete, the new API allows these queries
157     public void testGetListWithEmptyParameterFields() {
158         try {
159             NodeList nodeList;
160             nodeList = cloud.getList(null, "aa,bb", "", "", "", "", "", false);
161             fail("Should raise a BridgeException, but returned: " + nodeList);
162         } catch (BridgeException e) {}
163     }
164     */

165     
166     public void testGetListWithInvalidParameterFields() {
167         try {
168             NodeList nodeList;
169             nodeList = cloud.getList(null, "aa,bb", "x", "", "", "", "", false);
170             fail("Should raise a BridgeException, but returned: " + nodeList);
171         } catch (BridgeException e) {}
172     }
173
174     public void testGetListWithConstraint() {
175         cloud.getList(null, //java.lang.String startNodes,
176
"aa,bb,aa", //java.lang.String nodePath,
177
"bb.number,bb.owner", //java.lang.String fields,
178
"bb.owner ='test'", //java.lang.String constraints,
179
"bb.number", //java.lang.String orderby,
180
"UP", //java.lang.String directions,
181
"destination", //java.lang.String searchDir,
182
false //boolean distinct
183
);
184     };
185
186     public void testGetListWithConstraint2() {
187         cloud.getList(null, //java.lang.String startNodes,
188
"aa,bb,aa", //java.lang.String nodePath,
189
"bb.number,bb.owner", //java.lang.String fields,
190
"bb.number <>1234", //java.lang.String constraints,
191
"bb.number", //java.lang.String orderby,
192
"UP", //java.lang.String directions,
193
"destination", //java.lang.String searchDir,
194
false //boolean distinct
195
);
196     }
197     /*
198     public void testGetListWithQuery() {
199     
200         org.mmbase.cache.Cache cache = org.mmbase.cache.MultilevelCache.getCache();
201         NodeList nodeList;
202         Query query = new BasicSearchQuery();
203         NodeManager a = cloud.getNodeManager("aa");
204         Step stepa = query.addStep(a);
205         RelationManager relationManager = cloud.getRelationManager("aa", "bb", "related");
206         query.addRelationStep(relationManager, cloud.getNodeManager("bb"));
207         query.addField(stepa, a.getField("stringfield"));
208         nodeList = cloud.getList(query);
209         assertTrue(cache.size() == 1);
210         
211     }
212     */

213
214     // Add some more list test.
215

216 }
217
Popular Tags