01: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
02:
03: This file is part of the db4o open source object database.
04:
05: db4o is free software; you can redistribute it and/or modify it under
06: the terms of version 2 of the GNU General Public License as published
07: by the Free Software Foundation and as clarified by db4objects' GPL
08: interpretation policy, available at
09: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11: Suite 350, San Mateo, CA 94403, USA.
12:
13: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14: WARRANTY; without even the implied warranty of MERCHANTABILITY or
15: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16: for more details.
17:
18: You should have received a copy of the GNU General Public License along
19: with this program; if not, write to the Free Software Foundation, Inc.,
20: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21: package com.db4o.db4ounit.common.defragment;
22:
23: import java.io.*;
24:
25: import com.db4o.*;
26: import com.db4o.defragment.*;
27: import com.db4o.query.*;
28:
29: import db4ounit.*;
30:
31: public class SlotDefragmentTestCase implements TestLifeCycle {
32:
33: public void testPrimitiveIndex() throws Exception {
34: SlotDefragmentFixture
35: .assertIndex(SlotDefragmentFixture.PRIMITIVE_FIELDNAME);
36: }
37:
38: public void testWrapperIndex() throws Exception {
39: SlotDefragmentFixture
40: .assertIndex(SlotDefragmentFixture.WRAPPER_FIELDNAME);
41: }
42:
43: public void testTypedObjectIndex() throws Exception {
44: SlotDefragmentFixture.forceIndex();
45: Defragment.defrag(SlotDefragmentTestConstants.FILENAME,
46: SlotDefragmentTestConstants.BACKUPFILENAME);
47: ObjectContainer db = Db4o.openFile(Db4o.newConfiguration(),
48: SlotDefragmentTestConstants.FILENAME);
49: Query query = db.query();
50: query.constrain(SlotDefragmentFixture.Data.class);
51: query.descend(SlotDefragmentFixture.TYPEDOBJECT_FIELDNAME)
52: .descend(SlotDefragmentFixture.PRIMITIVE_FIELDNAME)
53: .constrain(new Integer(SlotDefragmentFixture.VALUE));
54: ObjectSet result = query.execute();
55: Assert.areEqual(1, result.size());
56: db.close();
57: }
58:
59: public void testNoForceDelete() throws Exception {
60: Defragment.defrag(SlotDefragmentTestConstants.FILENAME,
61: SlotDefragmentTestConstants.BACKUPFILENAME);
62: Assert.expect(IOException.class, new CodeBlock() {
63: public void run() throws Throwable {
64: Defragment.defrag(SlotDefragmentTestConstants.FILENAME,
65: SlotDefragmentTestConstants.BACKUPFILENAME);
66: }
67: });
68: }
69:
70: public void setUp() throws Exception {
71: new File(SlotDefragmentTestConstants.FILENAME).delete();
72: new File(SlotDefragmentTestConstants.BACKUPFILENAME).delete();
73: SlotDefragmentFixture
74: .createFile(SlotDefragmentTestConstants.FILENAME);
75: }
76:
77: public void tearDown() throws Exception {
78: }
79: }
|