01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: 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: public class BasicClusterTest {
33:
34: public String _name;
35:
36: public static final String SECOND_FILE = "second.yap";
37:
38: public BasicClusterTest() {
39:
40: }
41:
42: public BasicClusterTest(String name) {
43: _name = name;
44: }
45:
46: public void store() {
47: new File(SECOND_FILE).delete();
48: Test.store(new BasicClusterTest("inOne"));
49: Test.store(new BasicClusterTest("inBoth"));
50: ObjectContainer second = Db4o.openFile(SECOND_FILE);
51: second.set(new BasicClusterTest("inBoth"));
52: second.set(new BasicClusterTest("inTwo"));
53: second.close();
54: }
55:
56: public void testConstrained() {
57: ObjectContainer second = Db4o.openFile(SECOND_FILE);
58: Cluster cluster = new Cluster(new ObjectContainer[] {
59: Test.objectContainer(), second });
60: tQuery(cluster, "inOne", 1);
61: tQuery(cluster, "inTwo", 1);
62: tQuery(cluster, "inBoth", 2);
63: second.close();
64: }
65:
66: public void testPlain() {
67: ObjectContainer second = Db4o.openFile(SECOND_FILE);
68: Cluster cluster = new Cluster(new ObjectContainer[] {
69: Test.objectContainer(), second });
70: Query q = cluster.query();
71: q.constrain(this .getClass());
72: ObjectSet result = q.execute();
73: Test.ensure(result.size() == 4);
74: while (result.hasNext()) {
75: Test.ensure(result.next() instanceof BasicClusterTest);
76: }
77: second.close();
78: }
79:
80: private void tQuery(Cluster cluster, String name, int expected) {
81: Query q = cluster.query();
82: q.constrain(this .getClass());
83: q.descend("_name").constrain(name);
84: ObjectSet result = q.execute();
85: Assert.areEqual(expected, result.size());
86: while (result.hasNext()) {
87: Test.ensure(result.next() instanceof BasicClusterTest);
88: }
89: }
90:
91: }
|