KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > cluster > BasicClusterTest


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test.cluster;
22
23 import java.io.*;
24
25 import com.db4o.*;
26 import com.db4o.cluster.*;
27 import com.db4o.query.*;
28 import com.db4o.test.*;
29
30 import db4ounit.Assert;
31
32
33 public class BasicClusterTest {
34     
35     public String JavaDoc _name;
36     
37     public static final String JavaDoc SECOND_FILE = "second.yap";
38     
39     public BasicClusterTest(){
40         
41     }
42     
43     public BasicClusterTest(String JavaDoc name){
44         _name = name;
45     }
46     
47     public void store(){
48         new File(SECOND_FILE).delete();
49         Test.store(new BasicClusterTest("inOne"));
50         Test.store(new BasicClusterTest("inBoth"));
51         ObjectContainer second = Db4o.openFile(SECOND_FILE);
52         second.set(new BasicClusterTest("inBoth"));
53         second.set(new BasicClusterTest("inTwo"));
54         second.close();
55     }
56     
57     public void testConstrained(){
58         ObjectContainer second = Db4o.openFile(SECOND_FILE);
59         Cluster cluster = new Cluster(new ObjectContainer[]{
60             Test.objectContainer(),
61             second
62         });
63         tQuery(cluster, "inOne", 1);
64         tQuery(cluster, "inTwo", 1);
65         tQuery(cluster, "inBoth", 2);
66         second.close();
67     }
68
69     public void testPlain(){
70         ObjectContainer second = Db4o.openFile(SECOND_FILE);
71         Cluster cluster = new Cluster(new ObjectContainer[]{
72             Test.objectContainer(),
73             second
74         });
75         Query q = cluster.query();
76         q.constrain(this.getClass());
77         ObjectSet result=q.execute();
78         Test.ensure(result.size() == 4);
79         while(result.hasNext()) {
80             Test.ensure(result.next() instanceof BasicClusterTest);
81         }
82         second.close();
83     }
84
85     private void tQuery(Cluster cluster, String JavaDoc name, int expected){
86         Query q = cluster.query();
87         q.constrain(this.getClass());
88         q.descend("_name").constrain(name);
89         ObjectSet result=q.execute();
90         Assert.areEqual(expected, result.size());
91         while(result.hasNext()) {
92             Test.ensure(result.next() instanceof BasicClusterTest);
93         }
94     }
95     
96     
97
98 }
99
Popular Tags