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;
022:
023: import java.util.*;
024:
025: import com.db4o.*;
026: import com.db4o.query.*;
027:
028: import db4ounit.*;
029: import db4ounit.extensions.*;
030:
031: public class QueryUnknownClassTestCase extends AbstractDb4oTestCase {
032:
033: public static class Data {
034: public int _id;
035:
036: public Data(int id) {
037: _id = id;
038: }
039: }
040:
041: public static class DataHolder {
042: public Vector _data;
043:
044: public DataHolder(Object data) {
045: _data = new Vector();
046: _data.addElement(data);
047: }
048: }
049:
050: public static class Unrelated {
051: public int _uid;
052:
053: public Unrelated(int id) {
054: _uid = id;
055: }
056: }
057:
058: public void testQueryUnknownClass() {
059: Query query = newQuery(Data.class);
060: query.descend("_id").constrain(new Integer(42));
061: ObjectSet result = query.execute();
062: Assert.areEqual(0, result.size());
063: }
064:
065: public void testQueryUnknownClassInUnknownCollection() {
066: Query query = newQuery(DataHolder.class);
067: query.descend("_data").descend("_id")
068: .constrain(new Integer(42));
069: ObjectSet result = query.execute();
070: Assert.areEqual(0, result.size());
071: }
072:
073: public void _testQueryUnknownClassInCollection() {
074: store(new DataHolder(new Unrelated(42)));
075: Query query = newQuery(DataHolder.class);
076: query.descend("_data").descend("_id")
077: .constrain(new Integer(42));
078: ObjectSet result = query.execute();
079: Assert.areEqual(0, result.size());
080: }
081:
082: public void _testQueryUnknownClassInCollectionConjunction() {
083: store(new DataHolder(new Unrelated(42)));
084: Query query = newQuery(DataHolder.class);
085: query.descend("_data").descend("_id")
086: .constrain(new Integer(42)).and(
087: query.descend("_data").descend("_uid")
088: .constrain(new Integer(42)));
089: ObjectSet result = query.execute();
090: Assert.areEqual(0, result.size());
091: }
092:
093: public void testQueryUnknownClassInCollectionDisjunction() {
094: store(new DataHolder(new Unrelated(42)));
095: Query query = newQuery(DataHolder.class);
096: query.descend("_data").descend("_id")
097: .constrain(new Integer(42)).or(
098: query.descend("_data").descend("_uid")
099: .constrain(new Integer(42)));
100: ObjectSet result = query.execute();
101: Assert.areEqual(1, result.size());
102: }
103: }
|