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.regression;
022:
023: import com.db4o.ObjectSet;
024: import com.db4o.config.Configuration;
025: import com.db4o.query.Query;
026:
027: import db4ounit.Assert;
028: import db4ounit.extensions.AbstractDb4oTestCase;
029:
030: /**
031: * @exclude
032: */
033: public class COR57TestCase extends AbstractDb4oTestCase {
034:
035: public static void main(String[] args) {
036: new COR57TestCase().runSolo();
037: }
038:
039: public static class Base {
040: public String name;
041:
042: public Base() {
043: }
044:
045: public Base(String name_) {
046: name = name_;
047: }
048:
049: public String toString() {
050: return getClass() + ":" + name;
051: }
052: }
053:
054: public static class BaseExt extends Base {
055: public BaseExt() {
056: }
057:
058: public BaseExt(String name_) {
059: super (name_);
060: }
061: }
062:
063: public static class BaseExtExt extends BaseExt {
064: public BaseExtExt() {
065: }
066:
067: public BaseExtExt(String name_) {
068: super (name_);
069: }
070: }
071:
072: protected void configure(Configuration config) {
073: config.objectClass(Base.class).objectField("name")
074: .indexed(true);
075: }
076:
077: protected void store() throws Exception {
078: for (int i = 0; i < 5; i++) {
079: String name = String.valueOf(i);
080: db().set(new Base(name));
081: db().set(new BaseExt(name));
082: db().set(new BaseExtExt(name));
083: }
084: }
085:
086: public void testQBE() {
087: assertQBE(1, new BaseExtExt("1"));
088: assertQBE(2, new BaseExt("1"));
089: assertQBE(3, new Base("1"));
090: }
091:
092: public void testSODA() {
093: assertSODA(1, new BaseExtExt("1"));
094: assertSODA(2, new BaseExt("1"));
095: assertSODA(3, new Base("1"));
096: }
097:
098: private void assertSODA(int expectedCount, final Base template) {
099: assertQueryResult(expectedCount, template, createSODA(template)
100: .execute());
101: }
102:
103: private Query createSODA(final Base template) {
104: final Query q = newQuery(template.getClass());
105: q.descend("name").constrain(template.name);
106: return q;
107: }
108:
109: private void assertQBE(int expectedCount, final Base template) {
110: assertQueryResult(expectedCount, template, db().get(template));
111: }
112:
113: private void assertQueryResult(int expectedCount,
114: final Base expectedTemplate, final ObjectSet result) {
115: Assert.areEqual(expectedCount, result.size(),
116: simpleName(expectedTemplate.getClass()));
117: while (result.hasNext()) {
118: Base actual = (Base) result.next();
119: Assert.areEqual(expectedTemplate.name, actual.name);
120: Assert.isInstanceOf(expectedTemplate.getClass(), actual);
121: }
122: }
123:
124: private String simpleName(Class c) {
125: final String name = c.getName();
126: return name.substring(name.lastIndexOf('$') + 1);
127: }
128: }
|