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.jre12.assorted;
022:
023: import com.db4o.*;
024: import com.db4o.config.*;
025: import com.db4o.db4ounit.common.handlers.*;
026: import com.db4o.ext.*;
027: import com.db4o.internal.*;
028: import com.db4o.internal.btree.*;
029: import com.db4o.internal.classindex.*;
030: import com.db4o.query.*;
031: import com.db4o.reflect.*;
032: import com.db4o.test.*;
033:
034: import db4ounit.*;
035:
036: public class UpdatingDb4oVersionsTestCase extends
037: FormatMigrationTestCaseBase {
038:
039: public static void main(String[] args) {
040: new TestRunner(UpdatingDb4oVersionsTestCase.class).run();
041: }
042:
043: protected void configure(Configuration config) {
044: config.objectClass(UpdatingDb4oVersions.class).objectField(
045: "name").indexed(true);
046: }
047:
048: protected void store(ExtObjectContainer oc) {
049: UpdatingDb4oVersions udv = new UpdatingDb4oVersions();
050: udv.name = "check";
051: udv.list = oc.collections().newLinkedList();
052: udv.map = oc.collections().newHashMap(1);
053: oc.set(udv);
054: udv.list.add("check");
055: udv.map.put("check", "check");
056: }
057:
058: protected void assertObjectsAreReadable(
059: ExtObjectContainer objectContainer) {
060: checkStoredObjectsArePresent(objectContainer);
061: checkBTreeSize(objectContainer);
062: }
063:
064: private void checkBTreeSize(ExtObjectContainer objectContainer) {
065: ObjectContainerBase container = (ObjectContainerBase) objectContainer;
066: Reflector reflector = container.reflector();
067: ReflectClass claxx = reflector
068: .forClass(UpdatingDb4oVersions.class);
069: ClassMetadata yc = container
070: .classMetadataForReflectClass(claxx);
071: BTreeClassIndexStrategy btreeClassIndexStrategy = (BTreeClassIndexStrategy) yc
072: .index();
073: BTree btree = btreeClassIndexStrategy.btree();
074: Assert.isNotNull(btree);
075: int size = btree.size(container.transaction());
076: Assert.areEqual(1, size);
077: }
078:
079: private void checkStoredObjectsArePresent(
080: ExtObjectContainer objectContainer) {
081: Query q = objectContainer.query();
082: q.constrain(UpdatingDb4oVersions.class);
083: ObjectSet objectSet = q.execute();
084: Assert.areEqual(1, objectSet.size());
085: UpdatingDb4oVersions udv = (UpdatingDb4oVersions) objectSet
086: .next();
087: Assert.areEqual("check", udv.name);
088: Assert.areEqual(1, udv.list.size());
089: Assert.areEqual("check", udv.list.get(0));
090: Assert.areEqual("check", udv.map.get("check"));
091: }
092:
093: protected String[] versionNames() {
094: return UpdatingDb4oVersions.VERSIONS;
095: }
096:
097: protected String fileNamePrefix() {
098: return "";
099: }
100:
101: }
|