01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.objectserver.core.impl;
05:
06: import com.tc.object.ObjectID;
07: import com.tc.objectserver.managedobject.BackReferences;
08: import com.tc.test.TCTestCase;
09:
10: import java.util.HashSet;
11: import java.util.Set;
12:
13: public class BackReferencesTest extends TCTestCase {
14:
15: public void testBasic() throws Exception {
16: BackReferences br = new BackReferences();
17: assertTrue(br.getAllParents().isEmpty());
18:
19: Set actualParents = new HashSet();
20: Set actualRefChildren = new HashSet();
21:
22: // 1 -> 2
23: ObjectID p = new ObjectID(1);
24: ObjectID c = new ObjectID(2);
25:
26: actualParents.add(p);
27: actualRefChildren.add(c);
28:
29: br.addBackReference(c, p);
30: Set parents = br.getAllParents();
31: assertEquals(actualParents, parents);
32: Set referencedChildren = br.addReferencedChildrenTo(
33: new HashSet(), parents);
34: assertEquals(actualRefChildren, referencedChildren);
35:
36: // 3 ->5 4 ->5
37: p = new ObjectID(3);
38: c = new ObjectID(5);
39:
40: actualParents.add(p);
41: br.addBackReference(c, p);
42:
43: p = new ObjectID(4);
44: actualParents.add(p);
45: br.addBackReference(c, p);
46:
47: parents = br.getAllParents();
48: assertEquals(actualParents, parents);
49:
50: Set interestedParents = new HashSet();
51: interestedParents.add(new ObjectID(1));
52:
53: referencedChildren = br.addReferencedChildrenTo(new HashSet(),
54: interestedParents);
55: assertEquals(actualRefChildren, referencedChildren);
56:
57: interestedParents.add(new ObjectID(3));
58: actualRefChildren.add(new ObjectID(5));
59:
60: referencedChildren = br.addReferencedChildrenTo(new HashSet(),
61: interestedParents);
62: assertEquals(actualRefChildren, referencedChildren);
63:
64: // 5 -> 1
65: p = new ObjectID(5);
66: c = new ObjectID(1);
67:
68: actualParents.add(p);
69: br.addBackReference(c, p);
70:
71: parents = br.getAllParents();
72: assertEquals(actualParents, parents);
73:
74: interestedParents = new HashSet();
75: interestedParents.add(new ObjectID(3));
76: actualRefChildren = new HashSet();
77: actualRefChildren.add(new ObjectID(5));
78: actualRefChildren.add(new ObjectID(1));
79: actualRefChildren.add(new ObjectID(2));
80:
81: referencedChildren = br.addReferencedChildrenTo(new HashSet(),
82: interestedParents);
83: assertEquals(actualRefChildren, referencedChildren);
84:
85: }
86: }
|