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.wrapper.untyped;
022:
023: import com.db4o.*;
024: import com.db4o.query.*;
025:
026: public class STStringUTestCase extends
027: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase {
028:
029: public Object str;
030:
031: public STStringUTestCase() {
032: }
033:
034: public STStringUTestCase(String str) {
035: this .str = str;
036: }
037:
038: public Object[] createData() {
039: return new Object[] { new STStringUTestCase(null),
040: new STStringUTestCase("aaa"),
041: new STStringUTestCase("bbb"),
042: new STStringUTestCase("dod") };
043: }
044:
045: public void testEquals() {
046: Query q = newQuery();
047: q.constrain(_array[2]);
048: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
049: _array[2]);
050: }
051:
052: public void testNotEquals() {
053: Query q = newQuery();
054: q.constrain(_array[2]);
055: q.descend("str").constraints().not();
056:
057: expect(q, new int[] { 0, 1, 3 });
058: }
059:
060: public void testDescendantEquals() {
061: Query q = newQuery();
062: q.constrain(new STStringUTestCase());
063: q.descend("str").constrain("bbb");
064: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
065: new STStringUTestCase("bbb"));
066: }
067:
068: public void testContains() {
069: Query q = newQuery();
070: q.constrain(new STStringUTestCase("od"));
071: q.descend("str").constraints().contains();
072: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
073: new STStringUTestCase("dod"));
074: }
075:
076: public void testNotContains() {
077: Query q = newQuery();
078: q.constrain(new STStringUTestCase("od"));
079: q.descend("str").constraints().contains().not();
080: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(q,
081: new Object[] { new STStringUTestCase(null),
082: new STStringUTestCase("aaa"),
083: new STStringUTestCase("bbb") });
084: }
085:
086: public void testLike() {
087: Query q = newQuery();
088: q.constrain(new STStringUTestCase("do"));
089: q.descend("str").constraints().like();
090: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
091: new STStringUTestCase("dod"));
092: q = newQuery();
093: q.constrain(new STStringUTestCase("od"));
094: q.descend("str").constraints().like();
095: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
096: _array[3]);
097: }
098:
099: public void testNotLike() {
100: Query q = newQuery();
101: q.constrain(new STStringUTestCase("aaa"));
102: q.descend("str").constraints().like().not();
103: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(q,
104: new Object[] { new STStringUTestCase(null),
105: new STStringUTestCase("bbb"),
106: new STStringUTestCase("dod") });
107: q = newQuery();
108: q.constrain(new STStringUTestCase("xxx"));
109: q.descend("str").constraints().like();
110: expect(q, new int[] {});
111: }
112:
113: public void testIdentity() {
114: Query q = newQuery();
115: q.constrain(new STStringUTestCase("aaa"));
116: ObjectSet set = q.execute();
117: STStringUTestCase identityConstraint = (STStringUTestCase) set
118: .next();
119: identityConstraint.str = "hihs";
120: q = newQuery();
121: q.constrain(identityConstraint).identity();
122: identityConstraint.str = "aaa";
123: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
124: new STStringUTestCase("aaa"));
125: }
126:
127: public void testNotIdentity() {
128: Query q = newQuery();
129: q.constrain(new STStringUTestCase("aaa"));
130: ObjectSet set = q.execute();
131: STStringUTestCase identityConstraint = (STStringUTestCase) set
132: .next();
133: identityConstraint.str = null;
134: q = newQuery();
135: q.constrain(identityConstraint).identity().not();
136: identityConstraint.str = "aaa";
137: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(q,
138: new Object[] { new STStringUTestCase(null),
139: new STStringUTestCase("bbb"),
140: new STStringUTestCase("dod") });
141: }
142:
143: public void testNull() {
144: Query q = newQuery();
145: q.constrain(new STStringUTestCase(null));
146: q.descend("str").constrain(null);
147: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
148: new STStringUTestCase(null));
149: }
150:
151: public void testNotNull() {
152: Query q = newQuery();
153: q.constrain(new STStringUTestCase(null));
154: q.descend("str").constrain(null).not();
155: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expect(q,
156: new Object[] { new STStringUTestCase("aaa"),
157: new STStringUTestCase("bbb"),
158: new STStringUTestCase("dod") });
159: }
160:
161: public void testConstraints() {
162: Query q = newQuery();
163: q.constrain(new STStringUTestCase("aaa"));
164: q.constrain(new STStringUTestCase("bbb"));
165: Constraints cs = q.constraints();
166: Constraint[] csa = cs.toArray();
167: if (csa.length != 2) {
168: db4ounit.Assert.fail("Constraints not returned");
169: }
170: }
171:
172: }
|