KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > core > impl > BackReferencesTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.objectserver.core.impl;
5
6 import com.tc.object.ObjectID;
7 import com.tc.objectserver.managedobject.BackReferences;
8 import com.tc.test.TCTestCase;
9
10 import java.util.HashSet JavaDoc;
11 import java.util.Set JavaDoc;
12
13 public class BackReferencesTest extends TCTestCase {
14
15   public void testBasic() throws Exception JavaDoc {
16     BackReferences br = new BackReferences();
17     assertTrue(br.getAllParents().isEmpty());
18     
19     Set JavaDoc actualParents = new HashSet JavaDoc();
20     Set JavaDoc actualRefChildren = new HashSet JavaDoc();
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 JavaDoc parents = br.getAllParents();
31     assertEquals(actualParents, parents);
32     Set JavaDoc referencedChildren = br.addReferencedChildrenTo(new HashSet JavaDoc(), parents);
33     assertEquals(actualRefChildren, referencedChildren);
34     
35     // 3 ->5 4 ->5
36
p = new ObjectID(3);
37     c = new ObjectID(5);
38     
39     actualParents.add(p);
40     br.addBackReference(c, p);
41     
42     p = new ObjectID(4);
43     actualParents.add(p);
44     br.addBackReference(c, p);
45     
46     parents = br.getAllParents();
47     assertEquals(actualParents, parents);
48     
49     Set JavaDoc interestedParents = new HashSet JavaDoc();
50     interestedParents.add(new ObjectID(1));
51     
52     referencedChildren = br.addReferencedChildrenTo(new HashSet JavaDoc(), interestedParents);
53     assertEquals(actualRefChildren, referencedChildren);
54     
55     interestedParents.add(new ObjectID(3));
56     actualRefChildren.add(new ObjectID(5));
57     
58     referencedChildren = br.addReferencedChildrenTo(new HashSet JavaDoc(), interestedParents);
59     assertEquals(actualRefChildren, referencedChildren);
60     
61     
62     // 5 -> 1
63
p = new ObjectID(5);
64     c = new ObjectID(1);
65     
66     actualParents.add(p);
67     br.addBackReference(c, p);
68     
69     parents = br.getAllParents();
70     assertEquals(actualParents, parents);
71     
72     interestedParents = new HashSet JavaDoc();
73     interestedParents.add(new ObjectID(3));
74     actualRefChildren = new HashSet JavaDoc();
75     actualRefChildren.add(new ObjectID(5));
76     actualRefChildren.add(new ObjectID(1));
77     actualRefChildren.add(new ObjectID(2));
78     
79     referencedChildren = br.addReferencedChildrenTo(new HashSet JavaDoc(), interestedParents);
80     assertEquals(actualRefChildren, referencedChildren);
81     
82   }
83 }
84
Popular Tags