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.typedhierarchy;
022:
023: import com.db4o.query.*;
024:
025: /** TH: Typed Hierarchy */
026: public class STTH1TestCase extends
027: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
028:
029: public STTH2 h2;
030: public String foo1;
031:
032: public STTH1TestCase() {
033: }
034:
035: public STTH1TestCase(STTH2 a2) {
036: h2 = a2;
037: }
038:
039: public STTH1TestCase(String str) {
040: foo1 = str;
041: }
042:
043: public STTH1TestCase(STTH2 a2, String str) {
044: h2 = a2;
045: foo1 = str;
046: }
047:
048: public Object[] createData() {
049: return new Object[] { new STTH1TestCase(),
050: new STTH1TestCase("str1"),
051: new STTH1TestCase(new STTH2()),
052: new STTH1TestCase(new STTH2("str2")),
053: new STTH1TestCase(new STTH2(new STTH3("str3"))),
054: new STTH1TestCase(new STTH2(new STTH3("str3"), "str2")) };
055: }
056:
057: public void testStrNull() {
058: Query q = newQuery();
059: q.constrain(new STTH1TestCase());
060: q.descend("foo1").constrain(null);
061:
062: expect(q, new int[] { 0, 2, 3, 4, 5 });
063: }
064:
065: public void testBothNull() {
066: Query q = newQuery();
067: q.constrain(new STTH1TestCase());
068: q.descend("foo1").constrain(null);
069: q.descend("h2").constrain(null);
070: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
071: _array[0]);
072: }
073:
074: public void testDescendantNotNull() {
075: Query q = newQuery();
076:
077: q.constrain(new STTH1TestCase());
078: q.descend("h2").constrain(null).not();
079: expect(q, new int[] { 2, 3, 4, 5 });
080: }
081:
082: public void testDescendantDescendantNotNull() {
083: Query q = newQuery();
084:
085: q.constrain(new STTH1TestCase());
086: q.descend("h2").descend("h3").constrain(null).not();
087: expect(q, new int[] { 4, 5 });
088: }
089:
090: public void testDescendantExists() {
091: Query q = newQuery();
092:
093: q.constrain(_array[2]);
094: expect(q, new int[] { 2, 3, 4, 5 });
095: }
096:
097: public void testDescendantValue() {
098: Query q = newQuery();
099:
100: q.constrain(_array[3]);
101: expect(q, new int[] { 3, 5 });
102: }
103:
104: public void testDescendantDescendantExists() {
105: Query q = newQuery();
106:
107: q.constrain(new STTH1TestCase(new STTH2(new STTH3())));
108: expect(q, new int[] { 4, 5 });
109: }
110:
111: public void testDescendantDescendantValue() {
112: Query q = newQuery();
113:
114: q.constrain(new STTH1TestCase(new STTH2(new STTH3("str3"))));
115: expect(q, new int[] { 4, 5 });
116: }
117:
118: public void testDescendantDescendantStringPath() {
119: Query q = newQuery();
120:
121: q.constrain(new STTH1TestCase());
122: q.descend("h2").descend("h3").descend("foo3").constrain("str3");
123: expect(q, new int[] { 4, 5 });
124: }
125:
126: public void testSequentialAddition() {
127: Query q = newQuery();
128:
129: q.constrain(new STTH1TestCase());
130: Query cur = q.descend("h2");
131: cur.constrain(new STTH2());
132: cur.descend("foo2").constrain("str2");
133: cur = cur.descend("h3");
134: cur.constrain(new STTH3());
135: cur.descend("foo3").constrain("str3");
136: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
137: _array[5]);
138: }
139:
140: public void testTwoLevelOr() {
141: Query q = newQuery();
142:
143: q.constrain(new STTH1TestCase("str1"));
144: q.descend("foo1").constraints().or(
145: q.descend("h2").descend("h3").descend("foo3")
146: .constrain("str3"));
147: expect(q, new int[] { 1, 4, 5 });
148: }
149:
150: public void testThreeLevelOr() {
151: Query q = newQuery();
152:
153: q.constrain(new STTH1TestCase("str1"));
154: q.descend("foo1").constraints().or(
155: q.descend("h2").descend("foo2").constrain("str2")).or(
156: q.descend("h2").descend("h3").descend("foo3")
157: .constrain("str3"));
158: expect(q, new int[] { 1, 3, 4, 5 });
159: }
160: }
|