KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > db4ounit > common > defragment > SlotDefragmentTestCase


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 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 JavaDoc {
34         SlotDefragmentFixture.assertIndex(SlotDefragmentFixture.PRIMITIVE_FIELDNAME);
35     }
36
37     public void testWrapperIndex() throws Exception JavaDoc {
38         SlotDefragmentFixture.assertIndex(SlotDefragmentFixture.WRAPPER_FIELDNAME);
39     }
40
41     public void testTypedObjectIndex() throws Exception JavaDoc {
42         SlotDefragmentFixture.forceIndex();
43         Defragment.defrag(SlotDefragmentConstants.FILENAME,SlotDefragmentConstants.BACKUPFILENAME);
44         ObjectContainer db=Db4o.openFile(Db4o.newConfiguration(),SlotDefragmentConstants.FILENAME);
45         Query query=db.query();
46         query.constrain(SlotDefragmentFixture.Data.class);
47         query.descend(SlotDefragmentFixture.TYPEDOBJECT_FIELDNAME).descend(SlotDefragmentFixture.PRIMITIVE_FIELDNAME).constrain(new Integer JavaDoc(SlotDefragmentFixture.VALUE));
48         ObjectSet result=query.execute();
49         Assert.areEqual(1,result.size());
50         db.close();
51     }
52
53     public void testNoForceDelete() throws Exception JavaDoc {
54         Defragment.defrag(SlotDefragmentConstants.FILENAME,SlotDefragmentConstants.BACKUPFILENAME);
55         Assert.expect(IOException.class, new CodeBlock() {
56             public void run() throws Exception JavaDoc {
57                 Defragment.defrag(SlotDefragmentConstants.FILENAME,SlotDefragmentConstants.BACKUPFILENAME);
58             }
59         });
60     }
61
62     public void setUp() throws Exception JavaDoc {
63         new File(SlotDefragmentConstants.FILENAME).delete();
64         new File(SlotDefragmentConstants.BACKUPFILENAME).delete();
65         SlotDefragmentFixture.createFile(SlotDefragmentConstants.FILENAME);
66     }
67
68     public void tearDown() throws Exception JavaDoc {
69     }
70 }
71
Popular Tags