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