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