1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.eventcore.guimodel; |
---|
16 | |
---|
17 | import static org.junit.Assert.*; |
---|
18 | |
---|
19 | import java.util.ArrayList; |
---|
20 | import java.util.Arrays; |
---|
21 | import java.util.List; |
---|
22 | |
---|
23 | import org.junit.Test; |
---|
24 | |
---|
25 | import de.ugoe.cs.autoquest.eventcore.EventTargetModelConfigurationException; |
---|
26 | import de.ugoe.cs.autoquest.eventcore.HierarchicalEventTargetModel; |
---|
27 | import de.ugoe.cs.autoquest.eventcore.IEventTargetFactory; |
---|
28 | import de.ugoe.cs.autoquest.eventcore.IEventTargetSpec; |
---|
29 | import de.ugoe.cs.autoquest.eventcore.IHierarchicalEventTarget; |
---|
30 | import de.ugoe.cs.autoquest.eventcore.IHierarchicalEventTargetModel; |
---|
31 | |
---|
32 | /** |
---|
33 | * |
---|
34 | * @author Patrick Harms |
---|
35 | */ |
---|
36 | public class GUIModelTest { |
---|
37 | |
---|
38 | /** |
---|
39 | * |
---|
40 | */ |
---|
41 | private IEventTargetFactory guiElementFactory = new TestGUIElementFactory(); |
---|
42 | |
---|
43 | /** |
---|
44 | * |
---|
45 | */ |
---|
46 | @Test |
---|
47 | public void test_PathIntegration_01() throws Exception { |
---|
48 | GUIModel model = new GUIModel(); |
---|
49 | |
---|
50 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
51 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
52 | |
---|
53 | IGUIElement element = model.integratePath(guiElementPath, guiElementFactory); |
---|
54 | |
---|
55 | assertTrue(element instanceof TestGUIElement); |
---|
56 | assertEquals(guiElementPath.get(0), element.getSpecification()); |
---|
57 | assertNull(element.getParent()); |
---|
58 | |
---|
59 | assertNotNull(model.getRootElements()); |
---|
60 | assertEquals(1, model.getRootElements().size()); |
---|
61 | assertEquals(element, model.getRootElements().get(0)); |
---|
62 | |
---|
63 | assertNotNull(model.getChildren(element)); |
---|
64 | assertTrue(model.getChildren(element).isEmpty()); |
---|
65 | |
---|
66 | assertNull(model.getParent(element)); |
---|
67 | } |
---|
68 | |
---|
69 | /** |
---|
70 | * |
---|
71 | */ |
---|
72 | @Test |
---|
73 | public void test_PathIntegration_02() throws Exception { |
---|
74 | GUIModel model = new GUIModel(); |
---|
75 | |
---|
76 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
77 | for (int i = 0; i < 5; i++) { |
---|
78 | guiElementPath.add(new TestGUIElementSpec("guiElem" + i)); |
---|
79 | } |
---|
80 | |
---|
81 | IGUIElement element = model.integratePath(guiElementPath, guiElementFactory); |
---|
82 | |
---|
83 | for (int i = 4; i >= 0; i--) { |
---|
84 | assertTrue(element instanceof TestGUIElement); |
---|
85 | assertEquals(guiElementPath.get(i), element.getSpecification()); |
---|
86 | |
---|
87 | assertNotNull(model.getChildren(element)); |
---|
88 | |
---|
89 | if (i == 4) { |
---|
90 | assertTrue(model.getChildren(element).isEmpty()); |
---|
91 | } |
---|
92 | else { |
---|
93 | assertEquals(1, model.getChildren(element).size()); |
---|
94 | assertEquals(guiElementPath.get(i + 1), |
---|
95 | model.getChildren(element).get(0).getSpecification()); |
---|
96 | } |
---|
97 | |
---|
98 | element = element.getParent(); |
---|
99 | } |
---|
100 | |
---|
101 | assertNull(element); |
---|
102 | |
---|
103 | assertNotNull(model.getRootElements()); |
---|
104 | assertEquals(1, model.getRootElements().size()); |
---|
105 | assertNotNull(model.getRootElements().get(0)); |
---|
106 | assertEquals(guiElementPath.get(0), model.getRootElements().get(0).getSpecification()); |
---|
107 | } |
---|
108 | |
---|
109 | /** |
---|
110 | * |
---|
111 | */ |
---|
112 | @Test |
---|
113 | public void test_PathIntegration_03() throws Exception { |
---|
114 | GUIModel model = new GUIModel(); |
---|
115 | |
---|
116 | for (int i = 0; i < 20; i++) { |
---|
117 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
118 | |
---|
119 | for (int j = 0; j < 5; j++) { |
---|
120 | guiElementPath.add(new TestGUIElementSpec("guiElem_" + i + "_" + j)); |
---|
121 | } |
---|
122 | |
---|
123 | IGUIElement element = model.integratePath(guiElementPath, guiElementFactory); |
---|
124 | |
---|
125 | for (int j = 4; j >= 0; j--) { |
---|
126 | assertTrue(element instanceof TestGUIElement); |
---|
127 | assertEquals(guiElementPath.get(j), element.getSpecification()); |
---|
128 | |
---|
129 | assertNotNull(model.getChildren(element)); |
---|
130 | |
---|
131 | if (j == 4) { |
---|
132 | assertTrue(model.getChildren(element).isEmpty()); |
---|
133 | } |
---|
134 | else { |
---|
135 | assertEquals(1, model.getChildren(element).size()); |
---|
136 | assertEquals(guiElementPath.get(j + 1), |
---|
137 | model.getChildren(element).get(0).getSpecification()); |
---|
138 | } |
---|
139 | |
---|
140 | element = element.getParent(); |
---|
141 | } |
---|
142 | |
---|
143 | assertNull(element); |
---|
144 | |
---|
145 | } |
---|
146 | |
---|
147 | assertNotNull(model.getRootElements()); |
---|
148 | assertEquals(20, model.getRootElements().size()); |
---|
149 | } |
---|
150 | |
---|
151 | /** |
---|
152 | * |
---|
153 | */ |
---|
154 | @Test |
---|
155 | public void test_PathIntegration_04() throws Exception { |
---|
156 | GUIModel model = new GUIModel(); |
---|
157 | |
---|
158 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
159 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
160 | |
---|
161 | IGUIElement element1 = model.integratePath(guiElementPath, guiElementFactory); |
---|
162 | |
---|
163 | guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
164 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
165 | |
---|
166 | IGUIElement element2 = model.integratePath(guiElementPath, guiElementFactory); |
---|
167 | |
---|
168 | assertSame(element1, element2); |
---|
169 | } |
---|
170 | |
---|
171 | /** |
---|
172 | * |
---|
173 | */ |
---|
174 | @Test |
---|
175 | public void test_PathIntegration_05() throws Exception { |
---|
176 | GUIModel model = new GUIModel(); |
---|
177 | |
---|
178 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
179 | for (int i = 0; i < 5; i++) { |
---|
180 | guiElementPath.add(new TestGUIElementSpec("guiElem" + i)); |
---|
181 | } |
---|
182 | |
---|
183 | IGUIElement element1 = model.integratePath(guiElementPath, guiElementFactory); |
---|
184 | |
---|
185 | guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
186 | for (int i = 0; i < 5; i++) { |
---|
187 | guiElementPath.add(new TestGUIElementSpec("guiElem" + i)); |
---|
188 | } |
---|
189 | |
---|
190 | IGUIElement element2 = model.integratePath(guiElementPath, guiElementFactory); |
---|
191 | |
---|
192 | assertSame(element1, element2); |
---|
193 | } |
---|
194 | |
---|
195 | /** |
---|
196 | * |
---|
197 | */ |
---|
198 | @Test |
---|
199 | public void test_PathIntegration_06() throws Exception { |
---|
200 | GUIModel model = new GUIModel(); |
---|
201 | |
---|
202 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
203 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
204 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
205 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
206 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
207 | |
---|
208 | IGUIElement element1 = model.integratePath(guiElementPath, guiElementFactory); |
---|
209 | |
---|
210 | guiElementPath.remove(2); |
---|
211 | guiElementPath.remove(2); |
---|
212 | |
---|
213 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
214 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
215 | |
---|
216 | IGUIElement element2 = model.integratePath(guiElementPath, guiElementFactory); |
---|
217 | |
---|
218 | assertFalse(element1.equals(element2)); |
---|
219 | |
---|
220 | element1 = element1.getParent(); |
---|
221 | assertFalse(element1.equals(element2)); |
---|
222 | |
---|
223 | element2 = element2.getParent(); |
---|
224 | assertFalse(element1.equals(element2)); |
---|
225 | |
---|
226 | element1 = element1.getParent(); |
---|
227 | assertFalse(element1.equals(element2)); |
---|
228 | |
---|
229 | element2 = element2.getParent(); |
---|
230 | assertSame(element1, element2); |
---|
231 | } |
---|
232 | |
---|
233 | /** |
---|
234 | * |
---|
235 | */ |
---|
236 | @Test |
---|
237 | public void test_CondenseModel_01() throws Exception { |
---|
238 | GUIModel model = new GUIModel(); |
---|
239 | |
---|
240 | for (int i = 0; i < 20; i++) { |
---|
241 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
242 | |
---|
243 | for (int j = 0; j < 5; j++) { |
---|
244 | guiElementPath.add(new TestGUIElementSpec("guiElem_" + i + "_" + j, "spec_" + j)); |
---|
245 | } |
---|
246 | |
---|
247 | model.integratePath(guiElementPath, guiElementFactory); |
---|
248 | } |
---|
249 | |
---|
250 | assertNotNull(model.getRootElements()); |
---|
251 | assertEquals(20, model.getRootElements().size()); |
---|
252 | |
---|
253 | model.condenseModel(); |
---|
254 | |
---|
255 | assertNotNull(model.getRootElements()); |
---|
256 | assertEquals(1, model.getRootElements().size()); |
---|
257 | |
---|
258 | IGUIElement element = model.getRootElements().get(0); |
---|
259 | |
---|
260 | for (int i = 0; i < 5; i++) { |
---|
261 | assertNotNull(element); |
---|
262 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
263 | assertTrue(((TestGUIElementSpec) element.getSpecification()).id.endsWith("_" + i)); |
---|
264 | |
---|
265 | if (i < 4) { |
---|
266 | assertNotNull(model.getChildren(element)); |
---|
267 | assertEquals(1, model.getChildren(element).size()); |
---|
268 | element = model.getChildren(element).get(0); |
---|
269 | } |
---|
270 | else { |
---|
271 | assertNotNull(model.getChildren(element)); |
---|
272 | assertEquals(0, model.getChildren(element).size()); |
---|
273 | } |
---|
274 | } |
---|
275 | } |
---|
276 | |
---|
277 | /** |
---|
278 | * |
---|
279 | */ |
---|
280 | @Test |
---|
281 | public void test_CondenseModel_02() throws Exception { |
---|
282 | GUIModel model = new GUIModel(); |
---|
283 | |
---|
284 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
285 | for (int j = 0; j < 3; j++) { |
---|
286 | guiElementPath.add(new TestGUIElementSpec("guiElem_" + j)); |
---|
287 | } |
---|
288 | |
---|
289 | for (int i = 0; i < 20; i++) { |
---|
290 | for (int j = 3; j < 5; j++) { |
---|
291 | guiElementPath.add(new TestGUIElementSpec("guiElem_" + i + "_" + j, "spec_" + j)); |
---|
292 | } |
---|
293 | |
---|
294 | model.integratePath(guiElementPath, guiElementFactory); |
---|
295 | |
---|
296 | for (int j = 3; j < 5; j++) { |
---|
297 | guiElementPath.remove(3); |
---|
298 | } |
---|
299 | } |
---|
300 | |
---|
301 | assertNotNull(model.getRootElements()); |
---|
302 | assertEquals(1, model.getRootElements().size()); |
---|
303 | |
---|
304 | IGUIElement element = model.getRootElements().get(0); |
---|
305 | |
---|
306 | for (int i = 0; i < 3; i++) { |
---|
307 | assertNotNull(element); |
---|
308 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
309 | assertEquals("guiElem_" + i, ((TestGUIElementSpec) element.getSpecification()).id); |
---|
310 | |
---|
311 | if (i < 2) { |
---|
312 | assertNotNull(model.getChildren(element)); |
---|
313 | assertEquals(1, model.getChildren(element).size()); |
---|
314 | element = model.getChildren(element).get(0); |
---|
315 | } |
---|
316 | else { |
---|
317 | assertNotNull(model.getChildren(element)); |
---|
318 | assertEquals(20, model.getChildren(element).size()); |
---|
319 | } |
---|
320 | } |
---|
321 | |
---|
322 | model.condenseModel(); |
---|
323 | |
---|
324 | assertNotNull(model.getRootElements()); |
---|
325 | assertEquals(1, model.getRootElements().size()); |
---|
326 | |
---|
327 | element = model.getRootElements().get(0); |
---|
328 | |
---|
329 | for (int i = 0; i < 5; i++) { |
---|
330 | assertNotNull(element); |
---|
331 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
332 | assertTrue(((TestGUIElementSpec) element.getSpecification()).id.endsWith("_" + i)); |
---|
333 | |
---|
334 | if (i < 4) { |
---|
335 | assertNotNull(model.getChildren(element)); |
---|
336 | assertEquals(1, model.getChildren(element).size()); |
---|
337 | element = model.getChildren(element).get(0); |
---|
338 | } |
---|
339 | else { |
---|
340 | assertNotNull(model.getChildren(element)); |
---|
341 | assertEquals(0, model.getChildren(element).size()); |
---|
342 | } |
---|
343 | } |
---|
344 | } |
---|
345 | |
---|
346 | /** |
---|
347 | * |
---|
348 | */ |
---|
349 | @Test |
---|
350 | public void test_GroupGUIElements_01() throws Exception { |
---|
351 | GUIModel model = new GUIModel(); |
---|
352 | |
---|
353 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
354 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
355 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
356 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
357 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
358 | |
---|
359 | model.integratePath(guiElementPath, guiElementFactory); |
---|
360 | |
---|
361 | guiElementPath.remove(2); |
---|
362 | guiElementPath.remove(2); |
---|
363 | |
---|
364 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
365 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
366 | |
---|
367 | model.integratePath(guiElementPath, guiElementFactory); |
---|
368 | |
---|
369 | guiElementPath.remove(3); |
---|
370 | |
---|
371 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
372 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
373 | |
---|
374 | model.integratePath(guiElementPath, guiElementFactory); |
---|
375 | |
---|
376 | guiElementPath.remove(1); |
---|
377 | guiElementPath.remove(1); |
---|
378 | guiElementPath.remove(1); |
---|
379 | guiElementPath.remove(1); |
---|
380 | |
---|
381 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
382 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
383 | |
---|
384 | model.integratePath(guiElementPath, guiElementFactory); |
---|
385 | |
---|
386 | // the model created is |
---|
387 | // guiElem1 |
---|
388 | // |-- guiElem2 |
---|
389 | // | |-- guiElem3 |
---|
390 | // | | \-- guiElem4 |
---|
391 | // | | |
---|
392 | // | \-- guiElem5 |
---|
393 | // | |-- guiElem6 |
---|
394 | // | \-- guiElem7 |
---|
395 | // | \-- guiElem8 |
---|
396 | // \-- guiElem9 |
---|
397 | // \-- guiElem10 |
---|
398 | |
---|
399 | assertNotNull(model.getRootElements()); |
---|
400 | assertEquals(1, model.getRootElements().size()); |
---|
401 | |
---|
402 | IGUIElement guiElem1 = model.getRootElements().get(0); |
---|
403 | |
---|
404 | assertEquals(2, model.getChildren(guiElem1).size()); |
---|
405 | IGUIElement guiElem2 = model.getChildren(guiElem1).get(0); |
---|
406 | IGUIElement guiElem9 = model.getChildren(guiElem1).get(1); |
---|
407 | |
---|
408 | model.groupEventTargets(Arrays.asList(guiElem2, guiElem9), "newGroup", guiElementFactory); |
---|
409 | |
---|
410 | assertEquals(1, model.getChildren(guiElem1).size()); |
---|
411 | IGUIElement group = model.getChildren(guiElem1).get(0); |
---|
412 | |
---|
413 | assertEquals(2, model.getChildren(group).size()); |
---|
414 | assertEquals(guiElem2, model.getChildren(group).get(0)); |
---|
415 | assertEquals(guiElem9, model.getChildren(group).get(1)); |
---|
416 | |
---|
417 | assertEquals(group, guiElem2.getParent()); |
---|
418 | assertEquals(group, guiElem9.getParent()); |
---|
419 | } |
---|
420 | |
---|
421 | /** |
---|
422 | * |
---|
423 | */ |
---|
424 | @Test |
---|
425 | public void test_GroupGUIElements_02() throws Exception { |
---|
426 | GUIModel model = new GUIModel(); |
---|
427 | |
---|
428 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
429 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
430 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
431 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
432 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
433 | |
---|
434 | model.integratePath(guiElementPath, guiElementFactory); |
---|
435 | |
---|
436 | guiElementPath.remove(2); |
---|
437 | guiElementPath.remove(2); |
---|
438 | |
---|
439 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
440 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
441 | |
---|
442 | model.integratePath(guiElementPath, guiElementFactory); |
---|
443 | |
---|
444 | guiElementPath.remove(3); |
---|
445 | |
---|
446 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
447 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
448 | |
---|
449 | model.integratePath(guiElementPath, guiElementFactory); |
---|
450 | |
---|
451 | guiElementPath.remove(1); |
---|
452 | guiElementPath.remove(1); |
---|
453 | guiElementPath.remove(1); |
---|
454 | guiElementPath.remove(1); |
---|
455 | |
---|
456 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
457 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
458 | |
---|
459 | model.integratePath(guiElementPath, guiElementFactory); |
---|
460 | |
---|
461 | // the model created is |
---|
462 | // guiElem1 |
---|
463 | // |-- guiElem2 |
---|
464 | // | |-- guiElem3 |
---|
465 | // | | \-- guiElem4 |
---|
466 | // | | |
---|
467 | // | \-- guiElem5 |
---|
468 | // | |-- guiElem6 |
---|
469 | // | \-- guiElem7 |
---|
470 | // | \-- guiElem8 |
---|
471 | // \-- guiElem9 |
---|
472 | // \-- guiElem10 |
---|
473 | |
---|
474 | assertNotNull(model.getRootElements()); |
---|
475 | assertEquals(1, model.getRootElements().size()); |
---|
476 | |
---|
477 | IGUIElement guiElem1 = model.getRootElements().get(0); |
---|
478 | IGUIElement guiElem2 = model.getChildren(guiElem1).get(0); |
---|
479 | |
---|
480 | assertEquals(2, model.getChildren(guiElem2).size()); |
---|
481 | IGUIElement guiElem3 = model.getChildren(guiElem2).get(0); |
---|
482 | IGUIElement guiElem5 = model.getChildren(guiElem2).get(1); |
---|
483 | |
---|
484 | model.groupEventTargets(Arrays.asList(guiElem3, guiElem5), "newGroup", guiElementFactory); |
---|
485 | |
---|
486 | assertEquals(1, model.getChildren(guiElem2).size()); |
---|
487 | IGUIElement group = model.getChildren(guiElem2).get(0); |
---|
488 | |
---|
489 | assertEquals(2, model.getChildren(group).size()); |
---|
490 | assertEquals(guiElem3, model.getChildren(group).get(0)); |
---|
491 | assertEquals(guiElem5, model.getChildren(group).get(1)); |
---|
492 | |
---|
493 | assertEquals(group, guiElem3.getParent()); |
---|
494 | assertEquals(group, guiElem5.getParent()); |
---|
495 | } |
---|
496 | |
---|
497 | /** |
---|
498 | * |
---|
499 | */ |
---|
500 | @Test |
---|
501 | public void test_GroupGUIElements_03() throws Exception { |
---|
502 | GUIModel model = new GUIModel(); |
---|
503 | |
---|
504 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
505 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
506 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
507 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
508 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
509 | |
---|
510 | model.integratePath(guiElementPath, guiElementFactory); |
---|
511 | |
---|
512 | guiElementPath.remove(2); |
---|
513 | guiElementPath.remove(2); |
---|
514 | |
---|
515 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
516 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
517 | |
---|
518 | model.integratePath(guiElementPath, guiElementFactory); |
---|
519 | |
---|
520 | guiElementPath.remove(3); |
---|
521 | |
---|
522 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
523 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
524 | |
---|
525 | model.integratePath(guiElementPath, guiElementFactory); |
---|
526 | |
---|
527 | guiElementPath.remove(1); |
---|
528 | guiElementPath.remove(1); |
---|
529 | guiElementPath.remove(1); |
---|
530 | guiElementPath.remove(1); |
---|
531 | |
---|
532 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
533 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
534 | |
---|
535 | model.integratePath(guiElementPath, guiElementFactory); |
---|
536 | |
---|
537 | // the model created is |
---|
538 | // guiElem1 |
---|
539 | // |-- guiElem2 |
---|
540 | // | |-- guiElem3 |
---|
541 | // | | \-- guiElem4 |
---|
542 | // | | |
---|
543 | // | \-- guiElem5 |
---|
544 | // | |-- guiElem6 |
---|
545 | // | \-- guiElem7 |
---|
546 | // | \-- guiElem8 |
---|
547 | // \-- guiElem9 |
---|
548 | // \-- guiElem10 |
---|
549 | |
---|
550 | assertNotNull(model.getRootElements()); |
---|
551 | assertEquals(1, model.getRootElements().size()); |
---|
552 | |
---|
553 | IGUIElement guiElem1 = model.getRootElements().get(0); |
---|
554 | IGUIElement guiElem2 = model.getChildren(guiElem1).get(0); |
---|
555 | IGUIElement guiElem3 = model.getChildren(guiElem2).get(0); |
---|
556 | |
---|
557 | assertEquals(1, model.getChildren(guiElem3).size()); |
---|
558 | IGUIElement guiElem4 = model.getChildren(guiElem3).get(0); |
---|
559 | |
---|
560 | model.groupEventTargets(Arrays.asList(guiElem4), "newGroup", guiElementFactory); |
---|
561 | |
---|
562 | assertEquals(1, model.getChildren(guiElem3).size()); |
---|
563 | IGUIElement group = model.getChildren(guiElem3).get(0); |
---|
564 | |
---|
565 | assertEquals(1, model.getChildren(group).size()); |
---|
566 | assertEquals(guiElem4, model.getChildren(group).get(0)); |
---|
567 | |
---|
568 | assertEquals(group, guiElem4.getParent()); |
---|
569 | } |
---|
570 | |
---|
571 | /** |
---|
572 | * |
---|
573 | */ |
---|
574 | @Test(expected = java.lang.IllegalArgumentException.class) |
---|
575 | public void test_GroupGUIElements_04() throws Exception { |
---|
576 | GUIModel model = new GUIModel(); |
---|
577 | |
---|
578 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
579 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
580 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
581 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
582 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
583 | |
---|
584 | model.integratePath(guiElementPath, guiElementFactory); |
---|
585 | |
---|
586 | guiElementPath.remove(2); |
---|
587 | guiElementPath.remove(2); |
---|
588 | |
---|
589 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
590 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
591 | |
---|
592 | model.integratePath(guiElementPath, guiElementFactory); |
---|
593 | |
---|
594 | guiElementPath.remove(3); |
---|
595 | |
---|
596 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
597 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
598 | |
---|
599 | model.integratePath(guiElementPath, guiElementFactory); |
---|
600 | |
---|
601 | guiElementPath.remove(1); |
---|
602 | guiElementPath.remove(1); |
---|
603 | guiElementPath.remove(1); |
---|
604 | guiElementPath.remove(1); |
---|
605 | |
---|
606 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
607 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
608 | |
---|
609 | model.integratePath(guiElementPath, guiElementFactory); |
---|
610 | |
---|
611 | // the model created is |
---|
612 | // guiElem1 |
---|
613 | // |-- guiElem2 |
---|
614 | // | |-- guiElem3 |
---|
615 | // | | \-- guiElem4 |
---|
616 | // | | |
---|
617 | // | \-- guiElem5 |
---|
618 | // | |-- guiElem6 |
---|
619 | // | \-- guiElem7 |
---|
620 | // | \-- guiElem8 |
---|
621 | // \-- guiElem9 |
---|
622 | // \-- guiElem10 |
---|
623 | |
---|
624 | assertNotNull(model.getRootElements()); |
---|
625 | assertEquals(1, model.getRootElements().size()); |
---|
626 | |
---|
627 | IGUIElement guiElem1 = model.getRootElements().get(0); |
---|
628 | IGUIElement guiElem2 = model.getChildren(guiElem1).get(0); |
---|
629 | IGUIElement guiElem3 = model.getChildren(guiElem2).get(0); |
---|
630 | IGUIElement guiElem5 = model.getChildren(guiElem2).get(1); |
---|
631 | |
---|
632 | assertEquals(1, model.getChildren(guiElem3).size()); |
---|
633 | IGUIElement guiElem4 = model.getChildren(guiElem3).get(0); |
---|
634 | |
---|
635 | assertEquals(2, model.getChildren(guiElem5).size()); |
---|
636 | IGUIElement guiElem6 = model.getChildren(guiElem5).get(0); |
---|
637 | |
---|
638 | model.groupEventTargets(Arrays.asList(guiElem4, guiElem6), "newGroup", guiElementFactory); |
---|
639 | } |
---|
640 | |
---|
641 | /** |
---|
642 | * |
---|
643 | */ |
---|
644 | @Test |
---|
645 | public void test_Traverser_01() throws Exception { |
---|
646 | GUIModel model = new GUIModel(); |
---|
647 | |
---|
648 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
649 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
650 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
651 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
652 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
653 | |
---|
654 | model.integratePath(guiElementPath, guiElementFactory); |
---|
655 | |
---|
656 | guiElementPath.remove(2); |
---|
657 | guiElementPath.remove(2); |
---|
658 | |
---|
659 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
660 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
661 | |
---|
662 | model.integratePath(guiElementPath, guiElementFactory); |
---|
663 | |
---|
664 | guiElementPath.remove(3); |
---|
665 | |
---|
666 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
667 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
668 | |
---|
669 | model.integratePath(guiElementPath, guiElementFactory); |
---|
670 | |
---|
671 | guiElementPath.remove(1); |
---|
672 | guiElementPath.remove(1); |
---|
673 | guiElementPath.remove(1); |
---|
674 | guiElementPath.remove(1); |
---|
675 | |
---|
676 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
677 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
678 | |
---|
679 | model.integratePath(guiElementPath, guiElementFactory); |
---|
680 | |
---|
681 | // the model created is |
---|
682 | // guiElem1 |
---|
683 | // |-- guiElem2 |
---|
684 | // | |-- guiElem3 |
---|
685 | // | | \-- guiElem4 |
---|
686 | // | | |
---|
687 | // | \-- guiElem5 |
---|
688 | // | |-- guiElem6 |
---|
689 | // | \-- guiElem7 |
---|
690 | // | \-- guiElem8 |
---|
691 | // \-- guiElem9 |
---|
692 | // \-- guiElem10 |
---|
693 | |
---|
694 | IHierarchicalEventTargetModel.Traverser<IGUIElement> traverser = model.getTraverser(); |
---|
695 | assertNotNull(traverser); |
---|
696 | assertTrue(traverser.hasFirstChild()); |
---|
697 | assertFalse(traverser.hasNextSibling()); |
---|
698 | assertNull(traverser.parent()); |
---|
699 | |
---|
700 | // guiElem1 |
---|
701 | IGUIElement element = traverser.firstChild(); |
---|
702 | assertNotNull(element); |
---|
703 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
704 | assertEquals("guiElem1", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
705 | assertTrue(traverser.hasFirstChild()); |
---|
706 | assertFalse(traverser.hasNextSibling()); |
---|
707 | assertNull(traverser.nextSibling()); |
---|
708 | |
---|
709 | // guiElem2 |
---|
710 | element = traverser.firstChild(); |
---|
711 | assertNotNull(element); |
---|
712 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
713 | assertEquals("guiElem2", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
714 | assertTrue(traverser.hasFirstChild()); |
---|
715 | assertTrue(traverser.hasNextSibling()); |
---|
716 | |
---|
717 | // guiElem3 |
---|
718 | element = traverser.firstChild(); |
---|
719 | assertNotNull(element); |
---|
720 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
721 | assertEquals("guiElem3", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
722 | assertTrue(traverser.hasFirstChild()); |
---|
723 | assertTrue(traverser.hasNextSibling()); |
---|
724 | |
---|
725 | // guiElem4 |
---|
726 | element = traverser.firstChild(); |
---|
727 | assertNotNull(element); |
---|
728 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
729 | assertEquals("guiElem4", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
730 | assertFalse(traverser.hasFirstChild()); |
---|
731 | assertNull(traverser.firstChild()); |
---|
732 | assertFalse(traverser.hasNextSibling()); |
---|
733 | assertNull(traverser.nextSibling()); |
---|
734 | |
---|
735 | // guiElem3 |
---|
736 | element = traverser.parent(); |
---|
737 | assertNotNull(element); |
---|
738 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
739 | assertEquals("guiElem3", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
740 | assertTrue(traverser.hasFirstChild()); |
---|
741 | assertTrue(traverser.hasNextSibling()); |
---|
742 | |
---|
743 | // guiElem5 |
---|
744 | element = traverser.nextSibling(); |
---|
745 | assertNotNull(element); |
---|
746 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
747 | assertEquals("guiElem5", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
748 | assertTrue(traverser.hasFirstChild()); |
---|
749 | assertFalse(traverser.hasNextSibling()); |
---|
750 | assertNull(traverser.nextSibling()); |
---|
751 | |
---|
752 | // guiElem6 |
---|
753 | element = traverser.firstChild(); |
---|
754 | assertNotNull(element); |
---|
755 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
756 | assertEquals("guiElem6", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
757 | assertFalse(traverser.hasFirstChild()); |
---|
758 | assertNull(traverser.firstChild()); |
---|
759 | assertTrue(traverser.hasNextSibling()); |
---|
760 | |
---|
761 | // guiElem7 |
---|
762 | element = traverser.nextSibling(); |
---|
763 | assertNotNull(element); |
---|
764 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
765 | assertEquals("guiElem7", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
766 | assertTrue(traverser.hasFirstChild()); |
---|
767 | assertFalse(traverser.hasNextSibling()); |
---|
768 | assertNull(traverser.nextSibling()); |
---|
769 | |
---|
770 | // guiElem8 |
---|
771 | element = traverser.firstChild(); |
---|
772 | assertNotNull(element); |
---|
773 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
774 | assertEquals("guiElem8", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
775 | assertFalse(traverser.hasFirstChild()); |
---|
776 | assertNull(traverser.firstChild()); |
---|
777 | assertFalse(traverser.hasNextSibling()); |
---|
778 | assertNull(traverser.nextSibling()); |
---|
779 | |
---|
780 | // guiElem7 |
---|
781 | element = traverser.parent(); |
---|
782 | assertNotNull(element); |
---|
783 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
784 | assertEquals("guiElem7", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
785 | assertTrue(traverser.hasFirstChild()); |
---|
786 | assertFalse(traverser.hasNextSibling()); |
---|
787 | assertNull(traverser.nextSibling()); |
---|
788 | |
---|
789 | // guiElem5 |
---|
790 | element = traverser.parent(); |
---|
791 | assertNotNull(element); |
---|
792 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
793 | assertEquals("guiElem5", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
794 | assertTrue(traverser.hasFirstChild()); |
---|
795 | assertFalse(traverser.hasNextSibling()); |
---|
796 | assertNull(traverser.nextSibling()); |
---|
797 | |
---|
798 | // guiElem2 |
---|
799 | element = traverser.parent(); |
---|
800 | assertNotNull(element); |
---|
801 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
802 | assertEquals("guiElem2", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
803 | assertTrue(traverser.hasFirstChild()); |
---|
804 | assertTrue(traverser.hasNextSibling()); |
---|
805 | |
---|
806 | // guiElem9 |
---|
807 | element = traverser.nextSibling(); |
---|
808 | assertNotNull(element); |
---|
809 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
810 | assertEquals("guiElem9", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
811 | assertTrue(traverser.hasFirstChild()); |
---|
812 | assertFalse(traverser.hasNextSibling()); |
---|
813 | assertNull(traverser.nextSibling()); |
---|
814 | |
---|
815 | // guiElem10 |
---|
816 | element = traverser.firstChild(); |
---|
817 | assertNotNull(element); |
---|
818 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
819 | assertEquals("guiElem10", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
820 | assertFalse(traverser.hasFirstChild()); |
---|
821 | assertNull(traverser.firstChild()); |
---|
822 | assertFalse(traverser.hasNextSibling()); |
---|
823 | assertNull(traverser.nextSibling()); |
---|
824 | |
---|
825 | // guiElem9 |
---|
826 | element = traverser.parent(); |
---|
827 | assertNotNull(element); |
---|
828 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
829 | assertEquals("guiElem9", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
830 | assertTrue(traverser.hasFirstChild()); |
---|
831 | assertFalse(traverser.hasNextSibling()); |
---|
832 | assertNull(traverser.nextSibling()); |
---|
833 | |
---|
834 | // guiElem1 |
---|
835 | element = traverser.parent(); |
---|
836 | assertNotNull(element); |
---|
837 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
838 | assertEquals("guiElem1", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
839 | assertTrue(traverser.hasFirstChild()); |
---|
840 | assertFalse(traverser.hasNextSibling()); |
---|
841 | assertNull(traverser.nextSibling()); |
---|
842 | |
---|
843 | assertNull(traverser.parent()); |
---|
844 | } |
---|
845 | |
---|
846 | /** |
---|
847 | * |
---|
848 | */ |
---|
849 | @Test |
---|
850 | public void test_Traverser_02() throws Exception { |
---|
851 | GUIModel model = new GUIModel(); |
---|
852 | |
---|
853 | List<IGUIElementSpec> guiElementPath = new ArrayList<IGUIElementSpec>(); |
---|
854 | guiElementPath.add(new TestGUIElementSpec("guiElem1")); |
---|
855 | guiElementPath.add(new TestGUIElementSpec("guiElem2")); |
---|
856 | guiElementPath.add(new TestGUIElementSpec("guiElem3")); |
---|
857 | guiElementPath.add(new TestGUIElementSpec("guiElem4")); |
---|
858 | |
---|
859 | model.integratePath(guiElementPath, guiElementFactory); |
---|
860 | |
---|
861 | guiElementPath.remove(2); |
---|
862 | guiElementPath.remove(2); |
---|
863 | |
---|
864 | guiElementPath.add(new TestGUIElementSpec("guiElem5")); |
---|
865 | guiElementPath.add(new TestGUIElementSpec("guiElem6")); |
---|
866 | |
---|
867 | IGUIElement target = model.integratePath(guiElementPath, guiElementFactory); |
---|
868 | |
---|
869 | guiElementPath.remove(3); |
---|
870 | |
---|
871 | guiElementPath.add(new TestGUIElementSpec("guiElem7")); |
---|
872 | guiElementPath.add(new TestGUIElementSpec("guiElem8")); |
---|
873 | |
---|
874 | model.integratePath(guiElementPath, guiElementFactory); |
---|
875 | |
---|
876 | guiElementPath.remove(1); |
---|
877 | guiElementPath.remove(1); |
---|
878 | guiElementPath.remove(1); |
---|
879 | guiElementPath.remove(1); |
---|
880 | |
---|
881 | guiElementPath.add(new TestGUIElementSpec("guiElem9")); |
---|
882 | guiElementPath.add(new TestGUIElementSpec("guiElem10")); |
---|
883 | |
---|
884 | model.integratePath(guiElementPath, guiElementFactory); |
---|
885 | |
---|
886 | // the model created is |
---|
887 | // guiElem1 |
---|
888 | // |-- guiElem2 |
---|
889 | // | |-- guiElem3 |
---|
890 | // | | \-- guiElem4 |
---|
891 | // | | |
---|
892 | // | \-- guiElem5 |
---|
893 | // | |-- guiElem6 |
---|
894 | // | \-- guiElem7 |
---|
895 | // | \-- guiElem8 |
---|
896 | // \-- guiElem9 |
---|
897 | // \-- guiElem10 |
---|
898 | |
---|
899 | IHierarchicalEventTargetModel.Traverser<IGUIElement> traverser = model.getTraverser(target); |
---|
900 | assertNotNull(traverser); |
---|
901 | assertFalse(traverser.hasFirstChild()); |
---|
902 | assertNull(traverser.firstChild()); |
---|
903 | assertTrue(traverser.hasNextSibling()); |
---|
904 | |
---|
905 | // guiElem7 |
---|
906 | IGUIElement element = traverser.nextSibling(); |
---|
907 | assertNotNull(element); |
---|
908 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
909 | assertEquals("guiElem7", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
910 | assertTrue(traverser.hasFirstChild()); |
---|
911 | assertFalse(traverser.hasNextSibling()); |
---|
912 | assertNull(traverser.nextSibling()); |
---|
913 | |
---|
914 | // guiElem8 |
---|
915 | element = traverser.firstChild(); |
---|
916 | assertNotNull(element); |
---|
917 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
918 | assertEquals("guiElem8", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
919 | assertFalse(traverser.hasFirstChild()); |
---|
920 | assertNull(traverser.firstChild()); |
---|
921 | assertFalse(traverser.hasNextSibling()); |
---|
922 | assertNull(traverser.nextSibling()); |
---|
923 | |
---|
924 | // guiElem7 |
---|
925 | element = traverser.parent(); |
---|
926 | assertNotNull(element); |
---|
927 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
928 | assertEquals("guiElem7", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
929 | assertTrue(traverser.hasFirstChild()); |
---|
930 | assertFalse(traverser.hasNextSibling()); |
---|
931 | assertNull(traverser.nextSibling()); |
---|
932 | |
---|
933 | // guiElem5 |
---|
934 | element = traverser.parent(); |
---|
935 | assertNotNull(element); |
---|
936 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
937 | assertEquals("guiElem5", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
938 | assertTrue(traverser.hasFirstChild()); |
---|
939 | assertFalse(traverser.hasNextSibling()); |
---|
940 | assertNull(traverser.nextSibling()); |
---|
941 | |
---|
942 | // guiElem2 |
---|
943 | element = traverser.parent(); |
---|
944 | assertNotNull(element); |
---|
945 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
946 | assertEquals("guiElem2", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
947 | assertTrue(traverser.hasFirstChild()); |
---|
948 | assertTrue(traverser.hasNextSibling()); |
---|
949 | |
---|
950 | // guiElem9 |
---|
951 | element = traverser.nextSibling(); |
---|
952 | assertNotNull(element); |
---|
953 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
954 | assertEquals("guiElem9", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
955 | assertTrue(traverser.hasFirstChild()); |
---|
956 | assertFalse(traverser.hasNextSibling()); |
---|
957 | assertNull(traverser.nextSibling()); |
---|
958 | |
---|
959 | // guiElem10 |
---|
960 | element = traverser.firstChild(); |
---|
961 | assertNotNull(element); |
---|
962 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
963 | assertEquals("guiElem10", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
964 | assertFalse(traverser.hasFirstChild()); |
---|
965 | assertNull(traverser.firstChild()); |
---|
966 | assertFalse(traverser.hasNextSibling()); |
---|
967 | assertNull(traverser.nextSibling()); |
---|
968 | |
---|
969 | // guiElem9 |
---|
970 | element = traverser.parent(); |
---|
971 | assertNotNull(element); |
---|
972 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
973 | assertEquals("guiElem9", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
974 | assertTrue(traverser.hasFirstChild()); |
---|
975 | assertFalse(traverser.hasNextSibling()); |
---|
976 | assertNull(traverser.nextSibling()); |
---|
977 | |
---|
978 | // guiElem1 |
---|
979 | element = traverser.parent(); |
---|
980 | assertNotNull(element); |
---|
981 | assertTrue(element.getSpecification() instanceof TestGUIElementSpec); |
---|
982 | assertEquals("guiElem1", ((TestGUIElementSpec) element.getSpecification()).id); |
---|
983 | assertTrue(traverser.hasFirstChild()); |
---|
984 | assertFalse(traverser.hasNextSibling()); |
---|
985 | assertNull(traverser.nextSibling()); |
---|
986 | |
---|
987 | assertNull(traverser.parent()); |
---|
988 | } |
---|
989 | |
---|
990 | /** |
---|
991 | * |
---|
992 | * @author Patrick Harms |
---|
993 | */ |
---|
994 | private class TestGUIElementFactory implements IEventTargetFactory { |
---|
995 | |
---|
996 | /* (non-Javadoc) |
---|
997 | * @see IGUIElementFactory#instantiateGUIElement(IGUIElementSpec, IGUIElement) |
---|
998 | */ |
---|
999 | @SuppressWarnings("unchecked") |
---|
1000 | @Override |
---|
1001 | public <T extends IHierarchicalEventTarget> T instantiateEventTarget(IEventTargetSpec specification, |
---|
1002 | T parent) |
---|
1003 | throws EventTargetModelConfigurationException |
---|
1004 | { |
---|
1005 | assertTrue(specification instanceof TestGUIElementSpec); |
---|
1006 | |
---|
1007 | return (T) new TestGUIElement((TestGUIElementSpec) specification, (IGUIElement) parent); |
---|
1008 | } |
---|
1009 | |
---|
1010 | /* (non-Javadoc) |
---|
1011 | * @see IEventTargetFactory#instantiateGroup(String, IHierarchicalEventTarget, HierarchicalEventTargetModel) |
---|
1012 | */ |
---|
1013 | @SuppressWarnings("unchecked") |
---|
1014 | @Override |
---|
1015 | public <T extends IHierarchicalEventTarget> T instantiateGroup(String groupName, |
---|
1016 | T parent, |
---|
1017 | HierarchicalEventTargetModel<T> hierarchicalEventTargetModel) |
---|
1018 | { |
---|
1019 | return (T) new GUIElementGroup(groupName, (IGUIElement) parent, (GUIModel) hierarchicalEventTargetModel); |
---|
1020 | } |
---|
1021 | |
---|
1022 | } |
---|
1023 | |
---|
1024 | /** |
---|
1025 | * |
---|
1026 | * @author Patrick Harms |
---|
1027 | */ |
---|
1028 | private class TestGUIElementSpec implements IGUIElementSpec { |
---|
1029 | |
---|
1030 | /** */ |
---|
1031 | private static final long serialVersionUID = 1L; |
---|
1032 | |
---|
1033 | /** */ |
---|
1034 | private String id; |
---|
1035 | |
---|
1036 | /** */ |
---|
1037 | private String similarityId; |
---|
1038 | |
---|
1039 | /** |
---|
1040 | * |
---|
1041 | */ |
---|
1042 | public TestGUIElementSpec(String id) { |
---|
1043 | this(id, ""); |
---|
1044 | } |
---|
1045 | |
---|
1046 | /** |
---|
1047 | * |
---|
1048 | */ |
---|
1049 | public TestGUIElementSpec(String id, String similarityId) { |
---|
1050 | this.id = id; |
---|
1051 | this.similarityId = similarityId; |
---|
1052 | assertNotNull(id); |
---|
1053 | assertNotNull(similarityId); |
---|
1054 | } |
---|
1055 | |
---|
1056 | /* (non-Javadoc) |
---|
1057 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getType() |
---|
1058 | */ |
---|
1059 | @Override |
---|
1060 | public String getType() { |
---|
1061 | return "TestGUIElement"; |
---|
1062 | } |
---|
1063 | |
---|
1064 | /* (non-Javadoc) |
---|
1065 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec#getTypeHierarchy() |
---|
1066 | */ |
---|
1067 | @Override |
---|
1068 | public String[] getTypeHierarchy() { |
---|
1069 | return new String[] { "TestGUIElement" }; |
---|
1070 | } |
---|
1071 | |
---|
1072 | /* (non-Javadoc) |
---|
1073 | * @see IGUIElementSpec#getSimilarity(IGUIElementSpec) |
---|
1074 | */ |
---|
1075 | @Override |
---|
1076 | public boolean getSimilarity(IEventTargetSpec other) { |
---|
1077 | return (other instanceof TestGUIElementSpec ? |
---|
1078 | ((TestGUIElementSpec) other).similarityId.equals(similarityId) : false); |
---|
1079 | } |
---|
1080 | |
---|
1081 | /* (non-Javadoc) |
---|
1082 | * @see java.lang.Object#equals(java.lang.Object) |
---|
1083 | */ |
---|
1084 | @Override |
---|
1085 | public boolean equals(Object other) { |
---|
1086 | return (other instanceof TestGUIElementSpec ? |
---|
1087 | ((TestGUIElementSpec) other).id.equals(id) : false); |
---|
1088 | } |
---|
1089 | |
---|
1090 | } |
---|
1091 | |
---|
1092 | /** |
---|
1093 | * |
---|
1094 | * @author Patrick Harms |
---|
1095 | */ |
---|
1096 | public class TestGUIElement extends AbstractDefaultGUIElement implements IGUIElement { |
---|
1097 | |
---|
1098 | /** */ |
---|
1099 | private static final long serialVersionUID = 1L; |
---|
1100 | |
---|
1101 | /** |
---|
1102 | * |
---|
1103 | */ |
---|
1104 | public TestGUIElement(TestGUIElementSpec specification, IGUIElement parent) { |
---|
1105 | super(specification, parent); |
---|
1106 | } |
---|
1107 | |
---|
1108 | /* (non-Javadoc) |
---|
1109 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getPlatform() |
---|
1110 | */ |
---|
1111 | @Override |
---|
1112 | public String getPlatform() { |
---|
1113 | return "TEST"; |
---|
1114 | } |
---|
1115 | |
---|
1116 | /* (non-Javadoc) |
---|
1117 | * @see de.ugoe.cs.autoquest.eventcore.IEventTarget#getStringIdentifier() |
---|
1118 | */ |
---|
1119 | @Override |
---|
1120 | public String getStringIdentifier() { |
---|
1121 | return ((TestGUIElementSpec) super.getSpecification()).id; |
---|
1122 | } |
---|
1123 | |
---|
1124 | /* (non-Javadoc) |
---|
1125 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#updateSpecification(de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElementSpec) |
---|
1126 | */ |
---|
1127 | @Override |
---|
1128 | public void updateSpecification(IEventTargetSpec furtherSpec) { |
---|
1129 | // do nothing |
---|
1130 | } |
---|
1131 | |
---|
1132 | /* (non-Javadoc) |
---|
1133 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getView() |
---|
1134 | */ |
---|
1135 | @Override |
---|
1136 | public IGUIView getView() { |
---|
1137 | return null; |
---|
1138 | } |
---|
1139 | |
---|
1140 | /* (non-Javadoc) |
---|
1141 | * @see de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement#getDistanceTo(IGUIElement) |
---|
1142 | */ |
---|
1143 | @Override |
---|
1144 | public double getDistanceTo(IGUIElement otherElement) { |
---|
1145 | if (this == otherElement) { |
---|
1146 | return 0.0; |
---|
1147 | } |
---|
1148 | else { |
---|
1149 | return 1.0; |
---|
1150 | } |
---|
1151 | } |
---|
1152 | |
---|
1153 | } |
---|
1154 | |
---|
1155 | } |
---|