1 package org.drools.reteoo.impl;
2
3 import org.drools.rule.Declaration;
4 import org.drools.semantics.java.ClassObjectType;
5
6 import junit.framework.TestCase;
7
8 public class TupleKeyTest extends TestCase
9 {
10 private TupleKey key;
11
12 private Declaration decl1;
13 private Declaration decl2;
14
15 private Object obj1;
16 private Object obj2;
17
18 public TupleKeyTest(String name)
19 {
20 super( name );
21 }
22
23 public void setUp()
24 {
25 this.key = new TupleKey();
26
27 this.decl1 = new Declaration( new ClassObjectType( Object.class ),
28 "declOne" );
29
30 this.decl2 = new Declaration( new ClassObjectType( Object.class ),
31 "declTwo" );
32
33 this.obj1 = new Object();
34 this.obj2 = new Object();
35 }
36
37 public void tearDown()
38 {
39 this.key = null;
40 this.decl1 = null;
41 this.decl2 = null;
42 this.obj1 = null;
43 this.obj2 = null;
44 }
45
46 public void testPutAll()
47 {
48 this.key.put( this.decl1,
49 this.obj1 );
50
51 this.key.put( this.decl2,
52 this.obj2 );
53
54 TupleKey otherKey = new TupleKey();
55
56 otherKey.putAll( this.key );
57
58 assertEquals( 2,
59 otherKey.size() );
60
61 assertTrue( otherKey.containsDeclaration( this.decl1 ) );
62 assertTrue( otherKey.containsDeclaration( this.decl2 ) );
63
64 assertTrue( otherKey.containsRootFactObject( this.obj1 ) );
65 assertTrue( otherKey.containsRootFactObject( this.obj2 ) );
66
67 assertSame( this.obj1,
68 otherKey.get( this.decl1 ) );
69 assertSame( this.obj2,
70 otherKey.get( this.decl2 ) );
71 }
72
73 public void testContainsAll_Exact()
74 {
75 TupleKey otherKey = new TupleKey();
76
77 this.key.put( this.decl1,
78 this.obj1 );
79
80 this.key.put( this.decl2,
81 this.obj2 );
82
83 otherKey.put( this.decl1,
84 this.obj1 );
85
86 otherKey.put( this.decl2,
87 this.obj2 );
88
89 assertTrue( this.key.containsAll( otherKey ) );
90 assertTrue( otherKey.containsAll( this.key ) );
91 }
92
93 public void testContainsAll_Superset()
94 {
95 TupleKey otherKey = new TupleKey();
96
97 this.key.put( this.decl1,
98 this.obj1 );
99
100 this.key.put( this.decl2,
101 this.obj2 );
102
103 otherKey.put( this.decl1,
104 this.obj1 );
105
106 assertTrue( this.key.containsAll( otherKey ) );
107 assertTrue( ! otherKey.containsAll( this.key ) );
108 }
109
110 public void testContainsAll_Subset()
111 {
112 TupleKey otherKey = new TupleKey();
113
114 this.key.put( this.decl1,
115 this.obj1 );
116
117 otherKey.put( this.decl1,
118 this.obj1 );
119
120 otherKey.put( this.decl2,
121 this.obj2 );
122
123
124 assertTrue( ! this.key.containsAll( otherKey ) );
125 assertTrue( otherKey.containsAll( this.key ) );
126 }
127
128 public void testContainsAll_Null_Null()
129 {
130 TupleKey otherKey = new TupleKey();
131
132 this.key.put( this.decl1,
133 this.obj1 );
134
135 this.key.put( this.decl2,
136 null );
137
138 otherKey.put( this.decl1,
139 this.obj1 );
140
141 otherKey.put( this.decl2,
142 null );
143
144 assertTrue( this.key.containsAll( otherKey ) );
145 assertTrue( otherKey.containsAll( this.key ) );
146 }
147
148 public void testContainsAll_Null_NotNull()
149 {
150 TupleKey otherKey = new TupleKey();
151
152 this.key.put( this.decl1,
153 this.obj1 );
154
155 this.key.put( this.decl2,
156 null );
157
158 otherKey.put( this.decl1,
159 this.obj1 );
160
161 otherKey.put( this.decl2,
162 this.obj2 );
163
164 assertTrue( ! this.key.containsAll( otherKey ) );
165 assertTrue( ! otherKey.containsAll( this.key ) );
166 }
167
168 public void testContainsAll_MismatchValues()
169 {
170 TupleKey otherKey = new TupleKey();
171
172 this.key.put( this.decl1,
173 this.obj1 );
174
175 this.key.put( this.decl2,
176 this.obj2 );
177
178 otherKey.put( this.decl1,
179 this.obj1 );
180
181 otherKey.put( this.decl2,
182 new Object() );
183
184 assertTrue( ! this.key.containsAll( otherKey ) );
185 assertTrue( ! otherKey.containsAll( this.key ) );
186 }
187
188 public void testContainsAll_MismatchDecls()
189 {
190 TupleKey otherKey = new TupleKey();
191
192 Declaration decl = new Declaration( new ClassObjectType( Object.class ),
193 "yetAnother" );
194
195 this.key.put( this.decl1,
196 this.obj1 );
197
198 this.key.put( this.decl2,
199 this.obj2 );
200
201 otherKey.put( this.decl1,
202 this.obj1 );
203
204 otherKey.put( decl,
205 this.obj2 );
206
207 assertTrue( ! this.key.containsAll( otherKey ) );
208 assertTrue( ! otherKey.containsAll( this.key ) );
209 }
210 }
This page was automatically generated by Maven