1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37 package junitx.ddtunit.data;
38
39 import java.util.Collection;
40 import java.util.Iterator;
41 import java.util.List;
42 import java.util.Map;
43
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46
47
48
49
50 public class TestClusterDataSet extends DataSet {
51 private Logger log = LoggerFactory.getLogger(TestClusterDataSet.class);
52
53
54
55
56
57 public TestClusterDataSet(String setId, IDataSet parent) {
58 super(setId, parent);
59 }
60
61
62
63
64 public int size() {
65 int count = 0;
66 for (Iterator iter = getSubDataIterator(); iter.hasNext();) {
67 count += ((TestGroupDataSet) ((Map.Entry) iter.next()).getValue())
68 .size();
69 }
70 return count;
71 }
72
73
74
75
76 public int size(String group) {
77 int count = 0;
78 if (containsKey(group)) {
79 count = ((TestGroupDataSet) get(group)).size();
80 }
81 return count;
82 }
83
84
85
86
87
88
89
90
91
92
93 public boolean containsTest(String groupId, String testId) {
94 boolean check = false;
95 if (containsKey(groupId)
96 && ((TestGroupDataSet) get(groupId)).containsKey(testId)) {
97 check = true;
98 }
99 return check;
100 }
101
102
103
104
105
106
107
108
109
110
111
112
113
114 public TestDataSet getTestDataSet(String groupId, String testId) {
115 if (groupId == null || testId == null) {
116 throw new IllegalArgumentException(
117 "Xml Ids of <group/> and <test/> must be not null.");
118 }
119 log.debug("getTestDataSet(" + groupId + ", " + testId + ") - START");
120 TestDataSet dataSet = null;
121 if ((groupId != null) && containsKey(groupId)) {
122 TestGroupDataSet groupDataSet = (TestGroupDataSet) this
123 .get(groupId);
124
125 if (testId != null && groupDataSet.containsKey(testId)) {
126 dataSet = (TestDataSet) groupDataSet.get(testId);
127 }
128 }
129
130 log.debug("getTestDataSet(" + groupId + ", " + testId + ") - END");
131
132 return dataSet;
133 }
134
135
136
137
138
139
140
141
142 public Iterator getTestEntries(String groupName) {
143 Iterator iter = null;
144 if (containsKey(groupName)) {
145 iter = ((TestGroupDataSet) get(groupName)).getSubDataIterator();
146 }
147 return iter;
148 }
149
150
151
152
153
154
155
156
157 public Iterator getTestDataSets(String groupId) {
158 Iterator dataIterator = null;
159 if (containsKey(groupId)) {
160 Collection collection = null;
161 collection = ((TestGroupDataSet) get(groupId)).getSubDataValues();
162 dataIterator = collection.iterator();
163 }
164 return dataIterator;
165 }
166
167
168
169
170
171
172
173
174
175
176
177
178 public TypedObject getObject(String groupId, String testId, String objectId) {
179 TypedObject typedObject = this.getTestDataSet(groupId, testId)
180 .findObject(objectId);
181 return typedObject;
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197 public TypedObject getObject(String groupId, String testId,
198 String objectId, String objectType) {
199 TypedObject typedObject = this.getTestDataSet(groupId, testId)
200 .findObject(objectId, objectType);
201 return typedObject;
202 }
203
204
205
206
207
208
209
210
211
212
213
214
215 public AssertObject getAssert(String groupId, String testId, String assertId) {
216 AssertObject assertObject = this.getTestDataSet(groupId, testId)
217 .getAssert(assertId);
218 return assertObject;
219 }
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234 public AssertObject getAssert(String groupId, String testId,
235 String assertId, String assertType) {
236 AssertObject assertObject = this.getTestDataSet(groupId, testId)
237 .getAssert(assertId, assertType);
238 return assertObject;
239 }
240
241 public TypedObjectMap getAssertMap(String groupId, String testId) {
242 TypedObjectMap assertMap = this.getTestDataSet(groupId, testId)
243 .getAssertMap();
244 return (TypedObjectMap) assertMap;
245 }
246
247 public List<String> getOrderedTestKeys(String groupName) {
248 return ((TestGroupDataSet) get(groupName)).getOrderedSubKeys();
249 }
250 }