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 java.io.*;
024:
025: import com.db4o.*;
026: import com.db4o.query.*;
027:
028: public class STIntegerWUTestCase extends
029: com.db4o.db4ounit.common.soda.util.SodaBaseTestCase implements
030: Serializable {
031:
032: public Object i_int;
033:
034: public STIntegerWUTestCase() {
035: }
036:
037: private STIntegerWUTestCase(int a_int) {
038: i_int = new Integer(a_int);
039: }
040:
041: public Object[] createData() {
042: return new Object[] { new STIntegerWUTestCase(0),
043: new STIntegerWUTestCase(1),
044: new STIntegerWUTestCase(99),
045: new STIntegerWUTestCase(909) };
046: }
047:
048: public void testEquals() {
049: Query q = newQuery();
050: q.constrain(new STIntegerWUTestCase(0));
051:
052: // Primitive default values are ignored, so we need an
053: // additional constraint:
054: q.descend("i_int").constrain(new Integer(0));
055: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
056: _array[0]);
057: }
058:
059: public void testNotEquals() {
060: Query q = newQuery();
061:
062: q.constrain(new STIntegerWUTestCase());
063: q.descend("i_int").constrain(new Integer(0)).not();
064: expect(q, new int[] { 1, 2, 3 });
065: }
066:
067: public void testGreater() {
068: Query q = newQuery();
069: q.constrain(new STIntegerWUTestCase(9));
070: q.descend("i_int").constraints().greater();
071:
072: expect(q, new int[] { 2, 3 });
073: }
074:
075: public void testSmaller() {
076: Query q = newQuery();
077: q.constrain(new STIntegerWUTestCase(1));
078: q.descend("i_int").constraints().smaller();
079: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
080: _array[0]);
081: }
082:
083: public void testContains() {
084: Query q = newQuery();
085: q.constrain(new STIntegerWUTestCase(9));
086: q.descend("i_int").constraints().contains();
087:
088: expect(q, new int[] { 2, 3 });
089: }
090:
091: public void testNotContains() {
092: Query q = newQuery();
093: q.constrain(new STIntegerWUTestCase());
094: q.descend("i_int").constrain(new Integer(0)).contains().not();
095:
096: expect(q, new int[] { 1, 2 });
097: }
098:
099: public void testLike() {
100: Query q = newQuery();
101: q.constrain(new STIntegerWUTestCase(90));
102: q.descend("i_int").constraints().like();
103: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
104: new STIntegerWUTestCase(909));
105: q = newQuery();
106: q.constrain(new STIntegerWUTestCase(10));
107: q.descend("i_int").constraints().like();
108: expect(q, new int[] {});
109: }
110:
111: public void testNotLike() {
112: Query q = newQuery();
113: q.constrain(new STIntegerWUTestCase(1));
114: q.descend("i_int").constraints().like().not();
115:
116: expect(q, new int[] { 0, 2, 3 });
117: }
118:
119: public void testIdentity() {
120: Query q = newQuery();
121: q.constrain(new STIntegerWUTestCase(1));
122: ObjectSet set = q.execute();
123: STIntegerWUTestCase identityConstraint = (STIntegerWUTestCase) set
124: .next();
125: identityConstraint.i_int = new Integer(9999);
126: q = newQuery();
127: q.constrain(identityConstraint).identity();
128: identityConstraint.i_int = new Integer(1);
129: com.db4o.db4ounit.common.soda.util.SodaTestUtil.expectOne(q,
130: _array[1]);
131: }
132:
133: public void testNotIdentity() {
134: Query q = newQuery();
135: q.constrain(new STIntegerWUTestCase(1));
136: ObjectSet set = q.execute();
137: STIntegerWUTestCase identityConstraint = (STIntegerWUTestCase) set
138: .next();
139: identityConstraint.i_int = new Integer(9080);
140: q = newQuery();
141: q.constrain(identityConstraint).identity().not();
142: identityConstraint.i_int = new Integer(1);
143:
144: expect(q, new int[] { 0, 2, 3 });
145: }
146:
147: public void testConstraints() {
148: Query q = newQuery();
149: q.constrain(new STIntegerWUTestCase(1));
150: q.constrain(new STIntegerWUTestCase(0));
151: Constraints cs = q.constraints();
152: Constraint[] csa = cs.toArray();
153: if (csa.length != 2) {
154: db4ounit.Assert.fail("Constraints not returned");
155: }
156: }
157:
158: public void testEvaluation() {
159: Query q = newQuery();
160: q.constrain(new STIntegerWUTestCase());
161: q.constrain(new Evaluation() {
162: public void evaluate(Candidate candidate) {
163: STIntegerWUTestCase sti = (STIntegerWUTestCase) candidate
164: .getObject();
165: candidate
166: .include((((Integer) sti.i_int).intValue() + 2) > 100);
167: }
168: });
169:
170: expect(q, new int[] { 2, 3 });
171: }
172:
173: }
|