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.references;
22:
23: import com.db4o.db4ounit.common.btree.*;
24: import com.db4o.internal.*;
25:
26: import db4ounit.extensions.*;
27:
28: public class ReferenceSystemTestCase extends AbstractDb4oTestCase {
29:
30: private static final int[] IDS = new int[] { 100, 134, 689, 666,
31: 775 };
32:
33: private static final Object[] REFERENCES = createReferences();
34:
35: public static void main(String[] args) {
36: new ReferenceSystemTestCase().runSolo();
37: }
38:
39: public void testTransactionalReferenceSystem() {
40: TransactionalReferenceSystem transactionalReferenceSystem = new TransactionalReferenceSystem();
41: assertAllRerefencesAvailableOnNew(transactionalReferenceSystem);
42: transactionalReferenceSystem.rollback();
43: assertEmpty(transactionalReferenceSystem);
44: assertAllRerefencesAvailableOnCommit(transactionalReferenceSystem);
45: }
46:
47: public void testHashCodeReferenceSystem() {
48: HashcodeReferenceSystem hashcodeReferenceSystem = new HashcodeReferenceSystem();
49: assertAllRerefencesAvailableOnNew(hashcodeReferenceSystem);
50: }
51:
52: private void assertAllRerefencesAvailableOnCommit(
53: ReferenceSystem referenceSystem) {
54: fillReferenceSystem(referenceSystem);
55: referenceSystem.commit();
56: assertAllReferencesAvailable(referenceSystem);
57: }
58:
59: private void assertAllRerefencesAvailableOnNew(
60: ReferenceSystem referenceSystem) {
61: fillReferenceSystem(referenceSystem);
62: assertAllReferencesAvailable(referenceSystem);
63: }
64:
65: private void assertEmpty(ReferenceSystem referenceSystem) {
66: assertContains(referenceSystem, new Object[] {});
67: }
68:
69: private void assertAllReferencesAvailable(
70: ReferenceSystem referenceSystem) {
71: assertContains(referenceSystem, REFERENCES);
72: }
73:
74: private void assertContains(ReferenceSystem referenceSystem,
75: final Object[] objects) {
76: ExpectingVisitor expectingVisitor = new ExpectingVisitor(
77: objects);
78: referenceSystem.traverseReferences(expectingVisitor);
79: expectingVisitor.assertExpectations();
80: }
81:
82: private void fillReferenceSystem(ReferenceSystem referenceSystem) {
83: for (int i = 0; i < REFERENCES.length; i++) {
84: referenceSystem
85: .addNewReference((ObjectReference) REFERENCES[i]);
86: }
87: }
88:
89: private static Object[] createReferences() {
90: Object[] references = new Object[IDS.length];
91: for (int i = 0; i < IDS.length; i++) {
92: ObjectReference ref = new ObjectReference(IDS[i]);
93: ref.setObject(new Integer(IDS[i]).toString());
94: references[i] = ref;
95: }
96: return references;
97: }
98:
99: }
|