001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.db4ounit.common.soda.classes.untypedhierarchy;
022:
023: import com.db4o.db4ounit.common.soda.classes.typedhierarchy.*;
024: import com.db4o.query.*;
025:
026: /** UH: Untyped Hierarchy */
027: public class STUH1TestCase extends
028: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
029:
030: public Object h2;
031: public Object foo1;
032:
033: public STUH1TestCase() {
034: }
035:
036: public STUH1TestCase(STUH2 a2) {
037: h2 = a2;
038: }
039:
040: public STUH1TestCase(String str) {
041: foo1 = str;
042: }
043:
044: public STUH1TestCase(STUH2 a2, String str) {
045: h2 = a2;
046: foo1 = str;
047: }
048:
049: public Object[] createData() {
050: return new Object[] {
051: new STUH1TestCase(),
052: new STUH1TestCase("str1"),
053: new STUH1TestCase(new STUH2()),
054: new STUH1TestCase(new STUH2("str2")),
055: new STUH1TestCase(new STUH2(new STUH3("str3"))),
056: new STUH1TestCase(new STUH2(new STUH3("str3"), "str2")), };
057: }
058:
059: public void testStrNull() {
060: Query q = newQuery();
061: q.constrain(new STUH1TestCase());
062: q.descend("foo1").constrain(null);
063:
064: expect(q, new int[] { 0, 2, 3, 4, 5 });
065: }
066:
067: public void testBothNull() {
068: Query q = newQuery();
069: q.constrain(new STUH1TestCase());
070: q.descend("foo1").constrain(null);
071: q.descend("h2").constrain(null);
072: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
073: _array[0]);
074: }
075:
076: public void testDescendantNotNull() {
077: Query q = newQuery();
078:
079: q.constrain(new STUH1TestCase());
080: q.descend("h2").constrain(null).not();
081: expect(q, new int[] { 2, 3, 4, 5 });
082: }
083:
084: public void testDescendantDescendantNotNull() {
085: Query q = newQuery();
086:
087: q.constrain(new STUH1TestCase());
088: q.descend("h2").descend("h3").constrain(null).not();
089: expect(q, new int[] { 4, 5 });
090: }
091:
092: public void testDescendantExists() {
093: Query q = newQuery();
094:
095: q.constrain(_array[2]);
096: expect(q, new int[] { 2, 3, 4, 5 });
097: }
098:
099: public void testDescendantValue() {
100: Query q = newQuery();
101:
102: q.constrain(_array[3]);
103: expect(q, new int[] { 3, 5 });
104: }
105:
106: public void testDescendantDescendantExists() {
107: Query q = newQuery();
108:
109: q.constrain(new STUH1TestCase(new STUH2(new STUH3())));
110: expect(q, new int[] { 4, 5 });
111: }
112:
113: public void testDescendantDescendantValue() {
114: Query q = newQuery();
115:
116: q.constrain(new STUH1TestCase(new STUH2(new STUH3("str3"))));
117: expect(q, new int[] { 4, 5 });
118: }
119:
120: public void testDescendantDescendantStringPath() {
121: Query q = newQuery();
122:
123: q.constrain(new STUH1TestCase());
124: q.descend("h2").descend("h3").descend("foo3").constrain("str3");
125: expect(q, new int[] { 4, 5 });
126: }
127:
128: public void testSequentialAddition() {
129: Query q = newQuery();
130: q.constrain(new STUH1TestCase());
131:
132: Query cur = q.descend("h2");
133: cur.constrain(new STUH2());
134: cur.descend("foo2").constrain("str2");
135: cur = cur.descend("h3");
136: cur.constrain(new STUH3());
137: cur.descend("foo3").constrain("str3");
138: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
139: _array[5]);
140: }
141:
142: public void testTwoLevelOr() {
143: Query q = newQuery();
144:
145: q.constrain(new STUH1TestCase("str1"));
146: q.descend("foo1").constraints().or(
147: q.descend("h2").descend("h3").descend("foo3")
148: .constrain("str3"));
149: expect(q, new int[] { 1, 4, 5 });
150: }
151:
152: public void testThreeLevelOr() {
153: Query q = newQuery();
154:
155: q.constrain(new STUH1TestCase("str1"));
156: q.descend("foo1").constraints().or(
157: q.descend("h2").descend("foo2").constrain("str2")).or(
158: q.descend("h2").descend("h3").descend("foo3")
159: .constrain("str3"));
160:
161: expect(q, new int[] { 1, 3, 4, 5 });
162: }
163:
164: public void testNonExistentDescendant() {
165: Query q = newQuery();
166: STUH1TestCase constraint = new STUH1TestCase();
167: constraint.foo1 = new STETH2();
168: q.constrain(constraint);
169: expect(q, new int[] {});
170: }
171:
172: }
|