1
|
|
package junit.extensions.xml;
|
2
|
|
|
3
|
|
import java.util.Arrays;
|
4
|
|
import java.util.List;
|
5
|
|
|
6
|
|
import junit.framework.TestCase;
|
7
|
|
|
8
|
|
|
9
|
|
|
10
|
|
|
11
|
|
|
12
|
|
|
13
|
|
|
14
|
|
|
15
|
|
public class XMLObjectCacheT
|
16
|
|
extends TestCase {
|
17
|
|
|
18
|
|
|
19
|
|
|
20
|
|
|
21
|
|
private XMLObjectCache m_parent = null;
|
22
|
|
|
23
|
|
|
24
|
|
|
25
|
|
|
26
|
|
private XMLObjectCache m_xmlObjectCache = null;
|
27
|
|
|
28
|
|
|
29
|
|
|
30
|
|
|
31
|
|
|
32
|
11
|
public XMLObjectCacheT(final String name) {
|
33
|
11
|
super(name);
|
34
|
|
}
|
35
|
|
|
36
|
|
|
37
|
|
|
38
|
|
|
39
|
|
|
40
|
11
|
protected void setUp() throws Exception {
|
41
|
11
|
super.setUp();
|
42
|
11
|
m_parent = new XMLObjectCache();
|
43
|
11
|
m_xmlObjectCache = new XMLObjectCache();
|
44
|
11
|
m_xmlObjectCache.setParent(m_parent);
|
45
|
|
}
|
46
|
|
|
47
|
|
|
48
|
|
|
49
|
|
|
50
|
|
|
51
|
11
|
protected void tearDown() throws Exception {
|
52
|
11
|
m_xmlObjectCache = null;
|
53
|
11
|
m_parent = null;
|
54
|
11
|
super.tearDown();
|
55
|
|
}
|
56
|
|
|
57
|
|
|
58
|
|
|
59
|
|
|
60
|
1
|
public void testXMLObjectCache1() {
|
61
|
1
|
m_xmlObjectCache = new XMLObjectCache(m_parent);
|
62
|
1
|
assertSame(m_parent, m_xmlObjectCache.getParent());
|
63
|
|
|
64
|
1
|
m_xmlObjectCache = new XMLObjectCache(null);
|
65
|
1
|
assertNull("Parent should be null", m_xmlObjectCache.getParent());
|
66
|
|
|
67
|
|
}
|
68
|
|
|
69
|
|
|
70
|
|
|
71
|
|
|
72
|
1
|
public void testClear() {
|
73
|
1
|
m_parent.put("ABC", "DEF");
|
74
|
1
|
String[] names = m_parent.getNames();
|
75
|
1
|
m_xmlObjectCache.put("TEST", "ABC");
|
76
|
1
|
assertTrue("Should be more names from local+parent than local",
|
77
|
|
m_xmlObjectCache.getNames().length > names.length);
|
78
|
1
|
m_xmlObjectCache.clear();
|
79
|
1
|
assertEquals("Clear should remove all objects from the local cache",
|
80
|
|
names.length, m_xmlObjectCache.getNames().length);
|
81
|
|
}
|
82
|
|
|
83
|
|
|
84
|
|
|
85
|
|
|
86
|
1
|
public void testGet() {
|
87
|
1
|
String name = "TEST";
|
88
|
1
|
Object expectedReturn = "VAL";
|
89
|
1
|
m_xmlObjectCache.put(name, expectedReturn);
|
90
|
1
|
Object actualReturn = m_xmlObjectCache.get(name);
|
91
|
1
|
assertEquals("return value", expectedReturn, actualReturn);
|
92
|
|
}
|
93
|
|
|
94
|
|
|
95
|
|
|
96
|
|
|
97
|
1
|
public void testGetNull() {
|
98
|
1
|
String name = null;
|
99
|
1
|
Object expectedReturn = null;
|
100
|
1
|
Object actualReturn = m_xmlObjectCache.get(name);
|
101
|
1
|
assertEquals("return value", expectedReturn, actualReturn);
|
102
|
|
}
|
103
|
|
|
104
|
|
|
105
|
|
|
106
|
|
|
107
|
1
|
public void testGetInvalidKey() {
|
108
|
1
|
String name = "TEST";
|
109
|
1
|
Object expectedReturn = null;
|
110
|
1
|
Object actualReturn = m_xmlObjectCache.get(name);
|
111
|
1
|
assertEquals("return value", expectedReturn, actualReturn);
|
112
|
|
}
|
113
|
|
|
114
|
|
|
115
|
|
|
116
|
|
|
117
|
1
|
public void testGetName() {
|
118
|
1
|
m_xmlObjectCache.put("CDDE", "DRF");
|
119
|
1
|
m_xmlObjectCache.put("WGH", "DDF");
|
120
|
1
|
m_xmlObjectCache.put("ABC", "DEF");
|
121
|
1
|
String actualReturn = m_xmlObjectCache.getName("DEF");
|
122
|
1
|
assertEquals("return value", "ABC", actualReturn);
|
123
|
|
|
124
|
1
|
actualReturn = m_xmlObjectCache.getName("XYZ");
|
125
|
|
}
|
126
|
|
|
127
|
|
|
128
|
|
|
129
|
|
|
130
|
1
|
public void testGetNames() {
|
131
|
1
|
String[] expectedReturn = new String[0];
|
132
|
1
|
String[] actualReturn = m_xmlObjectCache.getNames();
|
133
|
1
|
assertEquals("return value", expectedReturn.length, actualReturn.length);
|
134
|
1
|
for (int i = 0; i < expectedReturn.length; i++) {
|
135
|
0
|
assertEquals("value " + i + ":", expectedReturn[i], actualReturn[i]);
|
136
|
|
}
|
137
|
|
}
|
138
|
|
|
139
|
|
|
140
|
|
|
141
|
|
|
142
|
1
|
public void testGetNamesWithValues() {
|
143
|
1
|
String[] expectedReturn = new String[] {
|
144
|
|
"abc",
|
145
|
|
"def"
|
146
|
|
};
|
147
|
1
|
m_xmlObjectCache.put("abc", "xyz");
|
148
|
1
|
m_xmlObjectCache.put("def", "ABC");
|
149
|
1
|
String[] actualReturn = m_xmlObjectCache.getNames();
|
150
|
1
|
List l = Arrays.asList(actualReturn);
|
151
|
1
|
assertEquals("return value", expectedReturn.length, actualReturn.length);
|
152
|
1
|
for (int i = 0; i < expectedReturn.length; i++) {
|
153
|
2
|
assertTrue("value " + i + ":", l.contains(expectedReturn[i]));
|
154
|
|
}
|
155
|
|
}
|
156
|
|
|
157
|
|
|
158
|
|
|
159
|
|
|
160
|
1
|
public void testPut() {
|
161
|
1
|
String name = null;
|
162
|
1
|
Object value = null;
|
163
|
1
|
m_xmlObjectCache.put("ABC", "DEF");
|
164
|
1
|
m_xmlObjectCache.put("../ABC", "EFG");
|
165
|
1
|
m_xmlObjectCache.put("./ABC", "FGH");
|
166
|
|
|
167
|
1
|
assertEquals("FGH", m_xmlObjectCache.get("./ABC"));
|
168
|
1
|
assertEquals("EFG", m_xmlObjectCache.get("../ABC"));
|
169
|
1
|
assertEquals("FGH", m_xmlObjectCache.get("ABC"));
|
170
|
1
|
m_xmlObjectCache.remove("ABC");
|
171
|
1
|
assertEquals("EFG", m_xmlObjectCache.get("ABC"));
|
172
|
1
|
m_xmlObjectCache.remove("../ABC");
|
173
|
1
|
assertEquals(null, m_xmlObjectCache.get("ABC"));
|
174
|
|
}
|
175
|
|
|
176
|
|
|
177
|
|
|
178
|
|
|
179
|
1
|
public void testRemove() {
|
180
|
1
|
String name = null;
|
181
|
1
|
m_xmlObjectCache.put("ABC", "DEF");
|
182
|
1
|
m_xmlObjectCache.remove("./ABC");
|
183
|
|
}
|
184
|
|
|
185
|
|
|
186
|
|
|
187
|
|
|
188
|
1
|
public void testSetParent() {
|
189
|
1
|
m_xmlObjectCache = new XMLObjectCache();
|
190
|
1
|
m_parent = new XMLObjectCache();
|
191
|
1
|
m_xmlObjectCache.put("../ABC", "ABC");
|
192
|
1
|
m_xmlObjectCache.put("ABC", "CDE");
|
193
|
1
|
m_xmlObjectCache.setParent(m_parent);
|
194
|
|
|
195
|
1
|
assertEquals("CDE", m_xmlObjectCache.get("ABC"));
|
196
|
1
|
assertEquals("ABC", m_xmlObjectCache.get("../ABC"));
|
197
|
1
|
assertEquals("ABC", m_parent.get("ABC"));
|
198
|
|
}
|
199
|
|
|
200
|
|
}
|
201
|
|
|