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.tasktrees.treeimpl; |
---|
16 | |
---|
17 | import static org.junit.Assert.*; |
---|
18 | |
---|
19 | import java.util.HashMap; |
---|
20 | import java.util.LinkedList; |
---|
21 | import java.util.List; |
---|
22 | import java.util.Map; |
---|
23 | |
---|
24 | import org.junit.Test; |
---|
25 | |
---|
26 | import de.ugoe.cs.autoquest.eventcore.IEventTarget; |
---|
27 | import de.ugoe.cs.autoquest.eventcore.IEventType; |
---|
28 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; |
---|
29 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; |
---|
30 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; |
---|
31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; |
---|
32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; |
---|
33 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; |
---|
34 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; |
---|
35 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel; |
---|
36 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; |
---|
37 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory; |
---|
38 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInfo; |
---|
39 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession; |
---|
40 | import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskInfo; |
---|
41 | import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskBuilder; |
---|
42 | import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskFactory; |
---|
43 | import de.ugoe.cs.autoquest.test.DummyGUIElement; |
---|
44 | import de.ugoe.cs.autoquest.test.DummyInteraction; |
---|
45 | |
---|
46 | /** |
---|
47 | * TODO comment |
---|
48 | * |
---|
49 | * @version $Revision: $ $Date: 02.04.2012$ |
---|
50 | * @author 2012, last modified by $Author: patrick$ |
---|
51 | */ |
---|
52 | public class TaskModelTest { |
---|
53 | |
---|
54 | /** */ |
---|
55 | private static final int MAX_TREE_DEPTH = 15; |
---|
56 | |
---|
57 | /** */ |
---|
58 | private ITaskBuilder taskBuilder = new TaskBuilder(); |
---|
59 | |
---|
60 | /** */ |
---|
61 | private ITaskFactory taskFactory = new TaskFactory(); |
---|
62 | |
---|
63 | /** |
---|
64 | * |
---|
65 | */ |
---|
66 | @Test |
---|
67 | public void test_EventTask_01() throws Exception { |
---|
68 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
69 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
70 | |
---|
71 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
72 | |
---|
73 | assertNotNull(task); |
---|
74 | assertNotNull(task.getDescription()); |
---|
75 | assertNotNull(task.getId()); |
---|
76 | assertTrue(task.equals(task)); |
---|
77 | |
---|
78 | assertEquals(eventType, task.getEventType()); |
---|
79 | assertEquals(eventTarget, task.getEventTarget()); |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * |
---|
84 | */ |
---|
85 | @Test |
---|
86 | public void test_EventTask_02() throws Exception { |
---|
87 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
88 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
89 | |
---|
90 | IEventTask task1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
91 | IEventTask task2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
92 | |
---|
93 | // the tasks will not be equal as they should have a different id |
---|
94 | assertFalse(task1.equals(task2)); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * |
---|
99 | */ |
---|
100 | @Test |
---|
101 | public void test_EventTask_03() throws Exception { |
---|
102 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
103 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
104 | |
---|
105 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
106 | ITaskInstance taskInstance1 = taskFactory.createNewTaskInstance(task); |
---|
107 | ITaskInstance taskInstance2 = taskFactory.createNewTaskInstance(task); |
---|
108 | |
---|
109 | assertFalse(taskInstance1.equals(taskInstance2)); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * |
---|
114 | */ |
---|
115 | @Test |
---|
116 | public void test_Sequence_01() throws Exception { |
---|
117 | ISequence task = taskFactory.createNewSequence(); |
---|
118 | |
---|
119 | assertNotNull(task); |
---|
120 | assertNotNull(task.getDescription()); |
---|
121 | assertNotNull(task.getId()); |
---|
122 | assertNotNull(task.getChildren()); |
---|
123 | assertEquals(0, task.getChildren().size()); |
---|
124 | assertTrue(task.equals(task)); |
---|
125 | } |
---|
126 | |
---|
127 | /** |
---|
128 | * |
---|
129 | */ |
---|
130 | @Test |
---|
131 | public void test_Sequence_02() throws Exception { |
---|
132 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
133 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
134 | |
---|
135 | IEventTask child = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
136 | |
---|
137 | ISequence task = taskFactory.createNewSequence(); |
---|
138 | |
---|
139 | taskBuilder.addChild(task, child); |
---|
140 | |
---|
141 | assertNotNull(task.getChildren()); |
---|
142 | assertEquals(1, task.getChildren().size()); |
---|
143 | assertEquals(child, task.getChildren().get(0)); |
---|
144 | } |
---|
145 | |
---|
146 | /** |
---|
147 | * |
---|
148 | */ |
---|
149 | @Test |
---|
150 | public void test_Sequence_03() throws Exception { |
---|
151 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
152 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
153 | |
---|
154 | IEventTask child1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
155 | IEventTask child2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
156 | IEventTask child3 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
157 | IEventTask child4 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
158 | IEventTask child5 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
159 | |
---|
160 | ISequence task = taskFactory.createNewSequence(); |
---|
161 | |
---|
162 | taskBuilder.addChild(task, child1); |
---|
163 | taskBuilder.addChild(task, child2); |
---|
164 | taskBuilder.addChild(task, child3); |
---|
165 | taskBuilder.addChild(task, child4); |
---|
166 | taskBuilder.addChild(task, child5); |
---|
167 | |
---|
168 | assertNotNull(task.getChildren()); |
---|
169 | assertEquals(5, task.getChildren().size()); |
---|
170 | assertEquals(child1, task.getChildren().get(0)); |
---|
171 | assertEquals(child2, task.getChildren().get(1)); |
---|
172 | assertEquals(child3, task.getChildren().get(2)); |
---|
173 | assertEquals(child4, task.getChildren().get(3)); |
---|
174 | assertEquals(child5, task.getChildren().get(4)); |
---|
175 | } |
---|
176 | |
---|
177 | /** |
---|
178 | * |
---|
179 | */ |
---|
180 | @Test |
---|
181 | public void test_Selection_01() throws Exception { |
---|
182 | ISelection task = taskFactory.createNewSelection(); |
---|
183 | |
---|
184 | assertNotNull(task); |
---|
185 | assertNotNull(task.getDescription()); |
---|
186 | assertNotNull(task.getId()); |
---|
187 | assertNotNull(task.getChildren()); |
---|
188 | assertEquals(0, task.getChildren().size()); |
---|
189 | assertTrue(task.equals(task)); |
---|
190 | } |
---|
191 | |
---|
192 | /** |
---|
193 | * |
---|
194 | */ |
---|
195 | @Test |
---|
196 | public void test_Selection_02() throws Exception { |
---|
197 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
198 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
199 | |
---|
200 | IEventTask child = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
201 | |
---|
202 | ISelection task = taskFactory.createNewSelection(); |
---|
203 | |
---|
204 | taskBuilder.addChild(task, child); |
---|
205 | |
---|
206 | assertNotNull(task.getChildren()); |
---|
207 | assertEquals(1, task.getChildren().size()); |
---|
208 | assertEquals(child, task.getChildren().get(0)); |
---|
209 | } |
---|
210 | |
---|
211 | /** |
---|
212 | * |
---|
213 | */ |
---|
214 | @Test |
---|
215 | public void test_Selection_03() throws Exception { |
---|
216 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
217 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
218 | |
---|
219 | IEventTask child1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
220 | IEventTask child2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
221 | IEventTask child3 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
222 | IEventTask child4 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
223 | IEventTask child5 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
224 | |
---|
225 | ISelection task = taskFactory.createNewSelection(); |
---|
226 | |
---|
227 | taskBuilder.addChild(task, child1); |
---|
228 | taskBuilder.addChild(task, child2); |
---|
229 | taskBuilder.addChild(task, child3); |
---|
230 | taskBuilder.addChild(task, child4); |
---|
231 | taskBuilder.addChild(task, child5); |
---|
232 | |
---|
233 | assertNotNull(task.getChildren()); |
---|
234 | assertEquals(5, task.getChildren().size()); |
---|
235 | assertEquals(child1, task.getChildren().get(0)); |
---|
236 | assertEquals(child2, task.getChildren().get(1)); |
---|
237 | assertEquals(child3, task.getChildren().get(2)); |
---|
238 | assertEquals(child4, task.getChildren().get(3)); |
---|
239 | assertEquals(child5, task.getChildren().get(4)); |
---|
240 | } |
---|
241 | |
---|
242 | /** |
---|
243 | * |
---|
244 | */ |
---|
245 | @Test |
---|
246 | public void test_Iteration_01() throws Exception { |
---|
247 | IIteration task = taskFactory.createNewIteration(); |
---|
248 | |
---|
249 | assertNotNull(task); |
---|
250 | assertNotNull(task.getDescription()); |
---|
251 | assertNotNull(task.getId()); |
---|
252 | assertNull(task.getMarkedTask()); |
---|
253 | assertTrue(task.equals(task)); |
---|
254 | } |
---|
255 | |
---|
256 | /** |
---|
257 | * |
---|
258 | */ |
---|
259 | @Test |
---|
260 | public void test_Iteration_02() throws Exception { |
---|
261 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
262 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
263 | |
---|
264 | IEventTask child = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
265 | |
---|
266 | IIteration task = taskFactory.createNewIteration(); |
---|
267 | |
---|
268 | taskBuilder.setMarkedTask(task, child); |
---|
269 | |
---|
270 | assertEquals(child, task.getMarkedTask()); |
---|
271 | } |
---|
272 | |
---|
273 | /** |
---|
274 | * |
---|
275 | */ |
---|
276 | @Test |
---|
277 | public void test_Iteration_03() throws Exception { |
---|
278 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
279 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
280 | |
---|
281 | IEventTask child1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
282 | IEventTask child2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
283 | |
---|
284 | IIteration task = taskFactory.createNewIteration(); |
---|
285 | |
---|
286 | taskBuilder.setMarkedTask(task, child1); |
---|
287 | taskBuilder.setMarkedTask(task, child2); |
---|
288 | |
---|
289 | assertEquals(child2, task.getMarkedTask()); |
---|
290 | } |
---|
291 | |
---|
292 | /** |
---|
293 | * |
---|
294 | */ |
---|
295 | @Test |
---|
296 | public void test_Optional_01() throws Exception { |
---|
297 | IOptional task = taskFactory.createNewOptional(); |
---|
298 | |
---|
299 | assertNotNull(task); |
---|
300 | assertNotNull(task.getDescription()); |
---|
301 | assertNotNull(task.getId()); |
---|
302 | assertNull(task.getMarkedTask()); |
---|
303 | assertTrue(task.equals(task)); |
---|
304 | } |
---|
305 | |
---|
306 | /** |
---|
307 | * |
---|
308 | */ |
---|
309 | @Test |
---|
310 | public void test_Optional_02() throws Exception { |
---|
311 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
312 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
313 | |
---|
314 | IEventTask child = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
315 | |
---|
316 | IOptional task = taskFactory.createNewOptional(); |
---|
317 | |
---|
318 | taskBuilder.setMarkedTask(task, child); |
---|
319 | |
---|
320 | assertEquals(child, task.getMarkedTask()); |
---|
321 | } |
---|
322 | |
---|
323 | /** |
---|
324 | * |
---|
325 | */ |
---|
326 | @Test |
---|
327 | public void test_Optional_03() throws Exception { |
---|
328 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
329 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
330 | |
---|
331 | IEventTask child1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
332 | IEventTask child2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
333 | |
---|
334 | IOptional task = taskFactory.createNewOptional(); |
---|
335 | |
---|
336 | taskBuilder.setMarkedTask(task, child1); |
---|
337 | taskBuilder.setMarkedTask(task, child2); |
---|
338 | |
---|
339 | assertEquals(child2, task.getMarkedTask()); |
---|
340 | } |
---|
341 | |
---|
342 | /** |
---|
343 | * |
---|
344 | */ |
---|
345 | @Test |
---|
346 | public void test_EventTaskInstance_01() throws Exception { |
---|
347 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
348 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
349 | |
---|
350 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
351 | |
---|
352 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
353 | |
---|
354 | assertNotNull(taskInstance); |
---|
355 | assertEquals(task, taskInstance.getTask()); |
---|
356 | assertTrue(taskInstance.equals(taskInstance)); |
---|
357 | assertFalse(taskInstance.equals(task)); |
---|
358 | assertNotNull(taskInstance.getChildren()); |
---|
359 | assertEquals(0, taskInstance.getChildren().size()); |
---|
360 | } |
---|
361 | |
---|
362 | /** |
---|
363 | * |
---|
364 | */ |
---|
365 | @Test |
---|
366 | public void test_EventTaskInstance_02() throws Exception { |
---|
367 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
368 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
369 | |
---|
370 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
371 | |
---|
372 | ITaskInstance taskInstance1 = taskFactory.createNewTaskInstance(task); |
---|
373 | ITaskInstance taskInstance2 = taskFactory.createNewTaskInstance(task); |
---|
374 | |
---|
375 | assertFalse(taskInstance1.equals(taskInstance2)); |
---|
376 | } |
---|
377 | |
---|
378 | /** |
---|
379 | * |
---|
380 | */ |
---|
381 | @Test(expected=IllegalArgumentException.class) |
---|
382 | public void test_EventTaskInstance_03() throws Exception { |
---|
383 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
384 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
385 | |
---|
386 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
387 | |
---|
388 | ITaskInstance taskInstance1 = taskFactory.createNewTaskInstance(task); |
---|
389 | ITaskInstance taskInstance2 = taskFactory.createNewTaskInstance(task); |
---|
390 | |
---|
391 | taskBuilder.addChild(taskInstance1, taskInstance2); |
---|
392 | } |
---|
393 | |
---|
394 | /** |
---|
395 | * |
---|
396 | */ |
---|
397 | @Test(expected=IllegalArgumentException.class) |
---|
398 | public void test_SequenceInstance_01() throws Exception { |
---|
399 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
400 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
401 | |
---|
402 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
403 | |
---|
404 | ISequence sequence = taskFactory.createNewSequence(); |
---|
405 | |
---|
406 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
407 | ITaskInstance sequenceInstance = taskFactory.createNewTaskInstance(sequence); |
---|
408 | |
---|
409 | taskBuilder.addChild(sequenceInstance, taskInstance); |
---|
410 | } |
---|
411 | |
---|
412 | /** |
---|
413 | * |
---|
414 | */ |
---|
415 | @Test |
---|
416 | public void test_SequenceInstance_02() throws Exception { |
---|
417 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
418 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
419 | |
---|
420 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
421 | |
---|
422 | ISequence sequence = taskFactory.createNewSequence(); |
---|
423 | taskBuilder.addChild(sequence, task); |
---|
424 | |
---|
425 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
426 | ITaskInstance sequenceInstance = taskFactory.createNewTaskInstance(sequence); |
---|
427 | |
---|
428 | taskBuilder.addChild(sequenceInstance, taskInstance); |
---|
429 | |
---|
430 | assertNotNull(sequenceInstance.getChildren()); |
---|
431 | assertEquals(1, sequenceInstance.getChildren().size()); |
---|
432 | assertEquals(taskInstance, sequenceInstance.getChildren().get(0)); |
---|
433 | } |
---|
434 | |
---|
435 | /** |
---|
436 | * |
---|
437 | */ |
---|
438 | @Test |
---|
439 | public void test_SequenceInstance_03() throws Exception { |
---|
440 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
441 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
442 | |
---|
443 | IEventTask task1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
444 | IEventTask task2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
445 | IEventTask task3 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
446 | IEventTask task4 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
447 | IEventTask task5 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
448 | |
---|
449 | ISequence sequence = taskFactory.createNewSequence(); |
---|
450 | taskBuilder.addChild(sequence, task1); |
---|
451 | taskBuilder.addChild(sequence, task2); |
---|
452 | taskBuilder.addChild(sequence, task3); |
---|
453 | taskBuilder.addChild(sequence, task4); |
---|
454 | taskBuilder.addChild(sequence, task5); |
---|
455 | |
---|
456 | ITaskInstance taskInstance1 = taskFactory.createNewTaskInstance(task1); |
---|
457 | ITaskInstance taskInstance2 = taskFactory.createNewTaskInstance(task2); |
---|
458 | ITaskInstance taskInstance3 = taskFactory.createNewTaskInstance(task3); |
---|
459 | ITaskInstance taskInstance4 = taskFactory.createNewTaskInstance(task4); |
---|
460 | ITaskInstance taskInstance5 = taskFactory.createNewTaskInstance(task5); |
---|
461 | ITaskInstance sequenceInstance = taskFactory.createNewTaskInstance(sequence); |
---|
462 | |
---|
463 | taskBuilder.addChild(sequenceInstance, taskInstance1); |
---|
464 | taskBuilder.addChild(sequenceInstance, taskInstance2); |
---|
465 | taskBuilder.addChild(sequenceInstance, taskInstance3); |
---|
466 | taskBuilder.addChild(sequenceInstance, taskInstance4); |
---|
467 | taskBuilder.addChild(sequenceInstance, taskInstance5); |
---|
468 | |
---|
469 | assertNotNull(sequenceInstance.getChildren()); |
---|
470 | assertEquals(5, sequenceInstance.getChildren().size()); |
---|
471 | assertEquals(taskInstance1, sequenceInstance.getChildren().get(0)); |
---|
472 | assertEquals(taskInstance2, sequenceInstance.getChildren().get(1)); |
---|
473 | assertEquals(taskInstance3, sequenceInstance.getChildren().get(2)); |
---|
474 | assertEquals(taskInstance4, sequenceInstance.getChildren().get(3)); |
---|
475 | assertEquals(taskInstance5, sequenceInstance.getChildren().get(4)); |
---|
476 | } |
---|
477 | |
---|
478 | /** |
---|
479 | * |
---|
480 | */ |
---|
481 | @Test(expected=IllegalArgumentException.class) |
---|
482 | public void test_SelectionInstance_01() throws Exception { |
---|
483 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
484 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
485 | |
---|
486 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
487 | |
---|
488 | ISelection selection = taskFactory.createNewSelection(); |
---|
489 | |
---|
490 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
491 | ITaskInstance selectionInstance = taskFactory.createNewTaskInstance(selection); |
---|
492 | |
---|
493 | taskBuilder.addChild(selectionInstance, taskInstance); |
---|
494 | } |
---|
495 | |
---|
496 | /** |
---|
497 | * |
---|
498 | */ |
---|
499 | @Test |
---|
500 | public void test_SelectionInstance_02() throws Exception { |
---|
501 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
502 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
503 | |
---|
504 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
505 | |
---|
506 | ISelection selection = taskFactory.createNewSelection(); |
---|
507 | taskBuilder.addChild(selection, task); |
---|
508 | |
---|
509 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
510 | ITaskInstance selectionInstance = taskFactory.createNewTaskInstance(selection); |
---|
511 | |
---|
512 | taskBuilder.addChild(selectionInstance, taskInstance); |
---|
513 | |
---|
514 | assertNotNull(selectionInstance.getChildren()); |
---|
515 | assertEquals(1, selectionInstance.getChildren().size()); |
---|
516 | assertEquals(taskInstance, selectionInstance.getChildren().get(0)); |
---|
517 | } |
---|
518 | |
---|
519 | /** |
---|
520 | * |
---|
521 | */ |
---|
522 | @Test(expected=IllegalArgumentException.class) |
---|
523 | public void test_SelectionInstance_03() throws Exception { |
---|
524 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
525 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
526 | |
---|
527 | IEventTask task1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
528 | IEventTask task2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
529 | IEventTask task3 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
530 | IEventTask task4 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
531 | IEventTask task5 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
532 | |
---|
533 | ISelection selection = taskFactory.createNewSelection(); |
---|
534 | taskBuilder.addChild(selection, task1); |
---|
535 | taskBuilder.addChild(selection, task2); |
---|
536 | taskBuilder.addChild(selection, task3); |
---|
537 | taskBuilder.addChild(selection, task4); |
---|
538 | taskBuilder.addChild(selection, task5); |
---|
539 | |
---|
540 | ITaskInstance taskInstance1 = taskFactory.createNewTaskInstance(task1); |
---|
541 | ITaskInstance taskInstance2 = taskFactory.createNewTaskInstance(task2); |
---|
542 | ITaskInstance selectionInstance = taskFactory.createNewTaskInstance(selection); |
---|
543 | |
---|
544 | taskBuilder.addChild(selectionInstance, taskInstance1); |
---|
545 | taskBuilder.addChild(selectionInstance, taskInstance2); |
---|
546 | } |
---|
547 | |
---|
548 | /** |
---|
549 | * |
---|
550 | */ |
---|
551 | @Test(expected=IllegalArgumentException.class) |
---|
552 | public void test_IterationInstance_01() throws Exception { |
---|
553 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
554 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
555 | |
---|
556 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
557 | |
---|
558 | IIteration iteration = taskFactory.createNewIteration(); |
---|
559 | |
---|
560 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
561 | ITaskInstance iterationInstance = taskFactory.createNewTaskInstance(iteration); |
---|
562 | |
---|
563 | taskBuilder.addChild(iterationInstance, taskInstance); |
---|
564 | } |
---|
565 | |
---|
566 | /** |
---|
567 | * |
---|
568 | */ |
---|
569 | @Test |
---|
570 | public void test_IterationInstance_02() throws Exception { |
---|
571 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
572 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
573 | |
---|
574 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
575 | |
---|
576 | IIteration iteration = taskFactory.createNewIteration(); |
---|
577 | taskBuilder.setMarkedTask(iteration, task); |
---|
578 | |
---|
579 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
580 | ITaskInstance iterationInstance = taskFactory.createNewTaskInstance(iteration); |
---|
581 | |
---|
582 | taskBuilder.addChild(iterationInstance, taskInstance); |
---|
583 | |
---|
584 | assertNotNull(iterationInstance.getChildren()); |
---|
585 | assertEquals(1, iterationInstance.getChildren().size()); |
---|
586 | assertEquals(taskInstance, iterationInstance.getChildren().get(0)); |
---|
587 | } |
---|
588 | |
---|
589 | /** |
---|
590 | * |
---|
591 | */ |
---|
592 | @Test(expected=IllegalArgumentException.class) |
---|
593 | public void test_IterationInstance_03() throws Exception { |
---|
594 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
595 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
596 | |
---|
597 | IEventTask task1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
598 | IEventTask task2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
599 | |
---|
600 | IIteration iteration = taskFactory.createNewIteration(); |
---|
601 | taskBuilder.setMarkedTask(iteration, task1); |
---|
602 | taskBuilder.setMarkedTask(iteration, task2); |
---|
603 | |
---|
604 | ITaskInstance taskInstance1 = taskFactory.createNewTaskInstance(task1); |
---|
605 | ITaskInstance iterationInstance = taskFactory.createNewTaskInstance(iteration); |
---|
606 | |
---|
607 | taskBuilder.addChild(iterationInstance, taskInstance1); |
---|
608 | } |
---|
609 | |
---|
610 | /** |
---|
611 | * |
---|
612 | */ |
---|
613 | @Test |
---|
614 | public void test_IterationInstance_04() throws Exception { |
---|
615 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
616 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
617 | |
---|
618 | IEventTask task1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
619 | IEventTask task2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
620 | |
---|
621 | IIteration iteration = taskFactory.createNewIteration(); |
---|
622 | taskBuilder.setMarkedTask(iteration, task1); |
---|
623 | taskBuilder.setMarkedTask(iteration, task2); |
---|
624 | |
---|
625 | ITaskInstance taskInstance2 = taskFactory.createNewTaskInstance(task2); |
---|
626 | ITaskInstance iterationInstance = taskFactory.createNewTaskInstance(iteration); |
---|
627 | |
---|
628 | taskBuilder.addChild(iterationInstance, taskInstance2); |
---|
629 | |
---|
630 | assertNotNull(iterationInstance.getChildren()); |
---|
631 | assertEquals(1, iterationInstance.getChildren().size()); |
---|
632 | assertEquals(taskInstance2, iterationInstance.getChildren().get(0)); |
---|
633 | } |
---|
634 | |
---|
635 | /** |
---|
636 | * |
---|
637 | */ |
---|
638 | @Test(expected=IllegalArgumentException.class) |
---|
639 | public void test_OptionalInstance_01() throws Exception { |
---|
640 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
641 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
642 | |
---|
643 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
644 | |
---|
645 | IOptional optional = taskFactory.createNewOptional(); |
---|
646 | |
---|
647 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
648 | ITaskInstance optionalInstance = taskFactory.createNewTaskInstance(optional); |
---|
649 | |
---|
650 | taskBuilder.addChild(optionalInstance, taskInstance); |
---|
651 | } |
---|
652 | |
---|
653 | /** |
---|
654 | * |
---|
655 | */ |
---|
656 | @Test |
---|
657 | public void test_OptionalInstance_02() throws Exception { |
---|
658 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
659 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
660 | |
---|
661 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
662 | |
---|
663 | IOptional optional = taskFactory.createNewOptional(); |
---|
664 | taskBuilder.setMarkedTask(optional, task); |
---|
665 | |
---|
666 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
667 | ITaskInstance optionalInstance = taskFactory.createNewTaskInstance(optional); |
---|
668 | |
---|
669 | taskBuilder.addChild(optionalInstance, taskInstance); |
---|
670 | |
---|
671 | assertNotNull(optionalInstance.getChildren()); |
---|
672 | assertEquals(1, optionalInstance.getChildren().size()); |
---|
673 | assertEquals(taskInstance, optionalInstance.getChildren().get(0)); |
---|
674 | } |
---|
675 | |
---|
676 | /** |
---|
677 | * |
---|
678 | */ |
---|
679 | @Test(expected=IllegalArgumentException.class) |
---|
680 | public void test_OptionalInstance_03() throws Exception { |
---|
681 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
682 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
683 | |
---|
684 | IEventTask task1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
685 | IEventTask task2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
686 | |
---|
687 | IOptional optional = taskFactory.createNewOptional(); |
---|
688 | taskBuilder.setMarkedTask(optional, task1); |
---|
689 | taskBuilder.setMarkedTask(optional, task2); |
---|
690 | |
---|
691 | ITaskInstance taskInstance1 = taskFactory.createNewTaskInstance(task1); |
---|
692 | ITaskInstance optionalInstance = taskFactory.createNewTaskInstance(optional); |
---|
693 | |
---|
694 | taskBuilder.addChild(optionalInstance, taskInstance1); |
---|
695 | } |
---|
696 | |
---|
697 | /** |
---|
698 | * |
---|
699 | */ |
---|
700 | @Test |
---|
701 | public void test_OptionalInstance_04() throws Exception { |
---|
702 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
703 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
704 | |
---|
705 | IEventTask task1 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
706 | IEventTask task2 = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
707 | |
---|
708 | IOptional optional = taskFactory.createNewOptional(); |
---|
709 | taskBuilder.setMarkedTask(optional, task1); |
---|
710 | taskBuilder.setMarkedTask(optional, task2); |
---|
711 | |
---|
712 | ITaskInstance taskInstance2 = taskFactory.createNewTaskInstance(task2); |
---|
713 | ITaskInstance optionalInstance = taskFactory.createNewTaskInstance(optional); |
---|
714 | |
---|
715 | taskBuilder.addChild(optionalInstance, taskInstance2); |
---|
716 | |
---|
717 | assertNotNull(optionalInstance.getChildren()); |
---|
718 | assertEquals(1, optionalInstance.getChildren().size()); |
---|
719 | assertEquals(taskInstance2, optionalInstance.getChildren().get(0)); |
---|
720 | } |
---|
721 | |
---|
722 | /** |
---|
723 | * |
---|
724 | */ |
---|
725 | @Test |
---|
726 | public void test_UserSession_01() throws Exception { |
---|
727 | IUserSession userSession = taskFactory.createUserSession(); |
---|
728 | |
---|
729 | assertNotNull(userSession); |
---|
730 | assertNotNull(userSession.getExecutedTasks()); |
---|
731 | assertEquals(0, userSession.getExecutedTasks().size()); |
---|
732 | } |
---|
733 | |
---|
734 | /** |
---|
735 | * |
---|
736 | */ |
---|
737 | @Test |
---|
738 | public void test_UserSession_02() throws Exception { |
---|
739 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
740 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
741 | |
---|
742 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
743 | |
---|
744 | IUserSession userSession = taskFactory.createUserSession(); |
---|
745 | |
---|
746 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
747 | |
---|
748 | taskBuilder.addExecutedTask(userSession, taskInstance); |
---|
749 | |
---|
750 | assertNotNull(userSession.getExecutedTasks()); |
---|
751 | assertEquals(1, userSession.getExecutedTasks().size()); |
---|
752 | assertEquals(taskInstance, userSession.getExecutedTasks().get(0)); |
---|
753 | } |
---|
754 | |
---|
755 | /** |
---|
756 | * |
---|
757 | */ |
---|
758 | @Test |
---|
759 | public void test_UserSession_03() throws Exception { |
---|
760 | IEventType eventType = new DummyInteraction("interaction", 1); |
---|
761 | IEventTarget eventTarget = new DummyGUIElement("elem"); |
---|
762 | |
---|
763 | IEventTask task = taskFactory.createNewEventTask(eventType, eventTarget); |
---|
764 | ISequence sequence = taskFactory.createNewSequence(); |
---|
765 | ISelection selection = taskFactory.createNewSelection(); |
---|
766 | IIteration iteration = taskFactory.createNewIteration(); |
---|
767 | IOptional optional = taskFactory.createNewOptional(); |
---|
768 | |
---|
769 | taskBuilder.addChild(sequence, task); |
---|
770 | taskBuilder.addChild(selection, task); |
---|
771 | taskBuilder.setMarkedTask(iteration, task); |
---|
772 | taskBuilder.setMarkedTask(optional, task); |
---|
773 | |
---|
774 | ITaskInstance taskInstance = taskFactory.createNewTaskInstance(task); |
---|
775 | ITaskInstance sequenceInstance = taskFactory.createNewTaskInstance(sequence); |
---|
776 | ITaskInstance selectionInstance = taskFactory.createNewTaskInstance(selection); |
---|
777 | ITaskInstance iterationInstance = taskFactory.createNewTaskInstance(iteration); |
---|
778 | ITaskInstance optionalInstance = taskFactory.createNewTaskInstance(optional); |
---|
779 | |
---|
780 | taskBuilder.addChild(sequenceInstance, taskFactory.createNewTaskInstance(task)); |
---|
781 | taskBuilder.addChild(selectionInstance, taskFactory.createNewTaskInstance(task)); |
---|
782 | taskBuilder.addChild(iterationInstance, taskFactory.createNewTaskInstance(task)); |
---|
783 | taskBuilder.addChild(optionalInstance, taskFactory.createNewTaskInstance(task)); |
---|
784 | |
---|
785 | IUserSession userSession = taskFactory.createUserSession(); |
---|
786 | |
---|
787 | taskBuilder.addExecutedTask(userSession, taskInstance); |
---|
788 | taskBuilder.addExecutedTask(userSession, sequenceInstance); |
---|
789 | taskBuilder.addExecutedTask(userSession, selectionInstance); |
---|
790 | taskBuilder.addExecutedTask(userSession, iterationInstance); |
---|
791 | taskBuilder.addExecutedTask(userSession, optionalInstance); |
---|
792 | |
---|
793 | assertNotNull(userSession.getExecutedTasks()); |
---|
794 | assertEquals(5, userSession.getExecutedTasks().size()); |
---|
795 | assertEquals(taskInstance, userSession.getExecutedTasks().get(0)); |
---|
796 | assertEquals(sequenceInstance, userSession.getExecutedTasks().get(1)); |
---|
797 | assertEquals(selectionInstance, userSession.getExecutedTasks().get(2)); |
---|
798 | assertEquals(iterationInstance, userSession.getExecutedTasks().get(3)); |
---|
799 | assertEquals(optionalInstance, userSession.getExecutedTasks().get(4)); |
---|
800 | } |
---|
801 | |
---|
802 | /** |
---|
803 | * |
---|
804 | */ |
---|
805 | @Test |
---|
806 | public void testRandomTrees() throws Exception { |
---|
807 | int noOfTrees = 10; |
---|
808 | int noOfMaxChildren = 8; |
---|
809 | int maxDepth = MAX_TREE_DEPTH; |
---|
810 | |
---|
811 | for (int i = 0; i < noOfTrees; i++) { |
---|
812 | System.err.println("\niteration " + (i + 1) + ":"); |
---|
813 | System.err.println(" creating tasks"); |
---|
814 | Map<ITask, ITaskInfo> expectedTaskInfos = new HashMap<ITask, ITaskInfo>(); |
---|
815 | ITask task = createTaskTree(noOfMaxChildren, maxDepth, expectedTaskInfos); |
---|
816 | if (!(task instanceof ISequence)) { |
---|
817 | ISequence sequence = taskFactory.createNewSequence(); |
---|
818 | taskBuilder.addChild(sequence, task); |
---|
819 | task = sequence; |
---|
820 | } |
---|
821 | else { |
---|
822 | expectedTaskInfos.remove(task); |
---|
823 | } |
---|
824 | |
---|
825 | ITaskInstance taskInstance = instantiateTask(task, noOfMaxChildren); |
---|
826 | |
---|
827 | System.err.println(" creating user session"); |
---|
828 | |
---|
829 | IUserSession session = taskFactory.createUserSession(); |
---|
830 | |
---|
831 | for (ITaskInstance child : taskInstance.getChildren()) { |
---|
832 | taskBuilder.addExecutedTask(session, child); |
---|
833 | } |
---|
834 | |
---|
835 | List<IUserSession> sessions = new LinkedList<IUserSession>(); |
---|
836 | sessions.add(session); |
---|
837 | |
---|
838 | ITaskModel taskTree = taskFactory.createTaskModel(sessions); |
---|
839 | |
---|
840 | System.err.println(" validating task tree"); |
---|
841 | Map<ITask, ITaskInfo> actualTaskInfos = new HashMap<ITask, ITaskInfo>(); |
---|
842 | |
---|
843 | for (ITask currentTask : taskTree.getTasks()) { |
---|
844 | actualTaskInfos.put(currentTask, taskTree.getTaskInfo(currentTask)); |
---|
845 | } |
---|
846 | |
---|
847 | assertMapsEqual(expectedTaskInfos, actualTaskInfos); |
---|
848 | } |
---|
849 | } |
---|
850 | |
---|
851 | /** |
---|
852 | * |
---|
853 | */ |
---|
854 | private void assertMapsEqual(Map<ITask, ITaskInfo> map1, |
---|
855 | Map<ITask, ITaskInfo> map2) |
---|
856 | { |
---|
857 | try { |
---|
858 | if (map1 == null) { |
---|
859 | assertNull(map2); |
---|
860 | return; |
---|
861 | } |
---|
862 | |
---|
863 | assertEquals(map1.size(), map2.size()); |
---|
864 | |
---|
865 | for (Map.Entry<ITask, ITaskInfo> entry : map1.entrySet()) { |
---|
866 | ITaskInfo value2 = map2.get(entry.getKey()); |
---|
867 | assertNotNull(value2); |
---|
868 | assertEquals(entry.getValue().getTask(), value2.getTask()); |
---|
869 | //assertEquals(entry.getValue().getNoOfOccurencesInTree(), |
---|
870 | // value2.getNoOfOccurencesInTree()); |
---|
871 | } |
---|
872 | } |
---|
873 | catch (AssertionError e) { |
---|
874 | dumpMap(map1); |
---|
875 | dumpMap(map2); |
---|
876 | throw e; |
---|
877 | } |
---|
878 | } |
---|
879 | |
---|
880 | /** |
---|
881 | * |
---|
882 | */ |
---|
883 | private void dumpMap(Map<ITask, ITaskInfo> map) { |
---|
884 | System.err.println(); |
---|
885 | |
---|
886 | if (map == null) { |
---|
887 | System.err.println("map is null"); |
---|
888 | } |
---|
889 | else { |
---|
890 | System.err.println("map:"); |
---|
891 | for (Map.Entry<ITask, ITaskInfo> entry : map.entrySet()) { |
---|
892 | System.err.print(" "); |
---|
893 | System.err.print(entry.getKey()); |
---|
894 | for (int i = entry.getKey().toString().length(); i < 60; i++) { |
---|
895 | System.err.print(" "); |
---|
896 | } |
---|
897 | System.err.print(" : "); |
---|
898 | System.err.println(entry.getValue()); |
---|
899 | } |
---|
900 | } |
---|
901 | |
---|
902 | System.err.println(); |
---|
903 | } |
---|
904 | |
---|
905 | /** |
---|
906 | * |
---|
907 | */ |
---|
908 | private ITask createTaskTree(int maxNoOfChildren, |
---|
909 | int maxDepth, |
---|
910 | Map<ITask, ITaskInfo> taskInfos) |
---|
911 | throws Exception |
---|
912 | { |
---|
913 | |
---|
914 | ITask task; |
---|
915 | |
---|
916 | // integrating the maximum depth here assures, that either something between 0 and 8 will |
---|
917 | // be the type, or if the max depth decreases near 0 only event tasks will be created |
---|
918 | // to finish the tree creation |
---|
919 | int type = randomize(Math.min(10, maxDepth)); |
---|
920 | |
---|
921 | switch (type) |
---|
922 | { |
---|
923 | case 0: { |
---|
924 | // System.err.print("creating new event task "); |
---|
925 | task = createNewEventTask(taskInfos); |
---|
926 | break; |
---|
927 | } |
---|
928 | case 1: { |
---|
929 | // System.err.print("reusing event task "); |
---|
930 | task = reuseEventTask(taskInfos); |
---|
931 | break; |
---|
932 | } |
---|
933 | case 2: { |
---|
934 | // System.err.println("creating new sequence {"); |
---|
935 | task = createNewSequence(maxNoOfChildren, maxDepth, taskInfos); |
---|
936 | break; |
---|
937 | } |
---|
938 | case 3: { |
---|
939 | // System.err.println("reusing sequence {"); |
---|
940 | task = reuseSequence(maxNoOfChildren, maxDepth, taskInfos); |
---|
941 | break; |
---|
942 | } |
---|
943 | case 4: { |
---|
944 | // System.err.println("creating new selection {"); |
---|
945 | task = createNewSelection(maxNoOfChildren, maxDepth, taskInfos); |
---|
946 | break; |
---|
947 | } |
---|
948 | case 5: { |
---|
949 | // System.err.println("reusing selection {"); |
---|
950 | task = reuseSelection(maxNoOfChildren, maxDepth, taskInfos); |
---|
951 | break; |
---|
952 | } |
---|
953 | case 6: { |
---|
954 | // System.err.println("creating new iteration {"); |
---|
955 | task = createNewIteration(maxNoOfChildren, maxDepth, taskInfos); |
---|
956 | break; |
---|
957 | } |
---|
958 | case 7: { |
---|
959 | // System.err.println("reusing iteration {"); |
---|
960 | task = reuseIteration(maxNoOfChildren, maxDepth, taskInfos); |
---|
961 | break; |
---|
962 | } |
---|
963 | case 8: { |
---|
964 | // System.err.println("creating new optional {"); |
---|
965 | task = createNewOptional(maxNoOfChildren, maxDepth, taskInfos); |
---|
966 | break; |
---|
967 | } |
---|
968 | case 9: { |
---|
969 | // System.err.println("reusing optional {"); |
---|
970 | task = reuseOptional(maxNoOfChildren, maxDepth, taskInfos); |
---|
971 | break; |
---|
972 | } |
---|
973 | default: { |
---|
974 | // System.err.print("creating new event task per default "); |
---|
975 | task = createNewEventTask(taskInfos); |
---|
976 | } |
---|
977 | } |
---|
978 | |
---|
979 | return task; |
---|
980 | } |
---|
981 | |
---|
982 | /** |
---|
983 | * |
---|
984 | */ |
---|
985 | private ITask createNewEventTask(Map<ITask, ITaskInfo> taskInfos) |
---|
986 | throws Exception |
---|
987 | { |
---|
988 | Thread.sleep(2); |
---|
989 | long id = System.currentTimeMillis(); |
---|
990 | IEventTask task = taskFactory.createNewEventTask |
---|
991 | (new DummyInteraction("interaction" + id, 1), new DummyGUIElement("elem" + id)); |
---|
992 | |
---|
993 | taskInfos.put(task, new TaskInfo(task)); |
---|
994 | |
---|
995 | return task; |
---|
996 | } |
---|
997 | |
---|
998 | /** |
---|
999 | * |
---|
1000 | */ |
---|
1001 | private ITask reuseEventTask(Map<ITask, ITaskInfo> taskInfos) |
---|
1002 | throws Exception |
---|
1003 | { |
---|
1004 | ITask eventTask = reuseTask(taskInfos, IEventTask.class); |
---|
1005 | |
---|
1006 | if (eventTask == null) { |
---|
1007 | eventTask = createNewEventTask(taskInfos); |
---|
1008 | } |
---|
1009 | |
---|
1010 | return eventTask; |
---|
1011 | } |
---|
1012 | |
---|
1013 | /** |
---|
1014 | * |
---|
1015 | */ |
---|
1016 | private ITask createNewSequence(int maxNoOfChildren, |
---|
1017 | int maxDepth, |
---|
1018 | Map<ITask, ITaskInfo> taskInfos) |
---|
1019 | throws Exception |
---|
1020 | { |
---|
1021 | ISequence sequence = taskFactory.createNewSequence(); |
---|
1022 | |
---|
1023 | // ensure at the minimum 2 children |
---|
1024 | int noOfChildren = randomize(2, maxNoOfChildren); |
---|
1025 | |
---|
1026 | for (int i = 0; i < noOfChildren; i++) { |
---|
1027 | ITask child = createTaskTree(maxNoOfChildren, maxDepth - 1, taskInfos); |
---|
1028 | taskBuilder.addChild(sequence, child); |
---|
1029 | } |
---|
1030 | |
---|
1031 | taskInfos.put(sequence, new TaskInfo(sequence)); |
---|
1032 | return sequence; |
---|
1033 | } |
---|
1034 | |
---|
1035 | /** |
---|
1036 | * |
---|
1037 | */ |
---|
1038 | private ITask reuseSequence(int maxNoOfChildren, |
---|
1039 | int maxDepth, |
---|
1040 | Map<ITask, ITaskInfo> taskInfos) |
---|
1041 | throws Exception |
---|
1042 | { |
---|
1043 | ITask sequence = reuseTask(taskInfos, ISequence.class); |
---|
1044 | |
---|
1045 | if (sequence == null) { |
---|
1046 | sequence = createNewSequence(maxNoOfChildren, maxDepth, taskInfos); |
---|
1047 | } |
---|
1048 | |
---|
1049 | return sequence; |
---|
1050 | } |
---|
1051 | |
---|
1052 | /** |
---|
1053 | * |
---|
1054 | */ |
---|
1055 | private ITask createNewSelection(int maxNoOfChildren, |
---|
1056 | int maxDepth, |
---|
1057 | Map<ITask, ITaskInfo> taskInfos) |
---|
1058 | throws Exception |
---|
1059 | { |
---|
1060 | ISelection selection = taskFactory.createNewSelection(); |
---|
1061 | |
---|
1062 | // ensure at the minimum 1 child |
---|
1063 | int noOfChildren = randomize(1, maxNoOfChildren); |
---|
1064 | |
---|
1065 | for (int i = 0; i < noOfChildren; i++) { |
---|
1066 | ITask child = createTaskTree(maxNoOfChildren, maxDepth - 1, taskInfos); |
---|
1067 | taskBuilder.addChild(selection, child); |
---|
1068 | } |
---|
1069 | |
---|
1070 | taskInfos.put(selection, new TaskInfo(selection)); |
---|
1071 | return selection; |
---|
1072 | } |
---|
1073 | |
---|
1074 | /** |
---|
1075 | * |
---|
1076 | */ |
---|
1077 | private ITask reuseSelection(int maxNoOfChildren, |
---|
1078 | int maxDepth, |
---|
1079 | Map<ITask, ITaskInfo> taskInfos) |
---|
1080 | throws Exception |
---|
1081 | { |
---|
1082 | ITask selection = reuseTask(taskInfos, ISelection.class); |
---|
1083 | |
---|
1084 | if (selection == null) { |
---|
1085 | selection = createNewSelection(maxNoOfChildren, maxDepth, taskInfos); |
---|
1086 | } |
---|
1087 | |
---|
1088 | return selection; |
---|
1089 | } |
---|
1090 | |
---|
1091 | /** |
---|
1092 | * |
---|
1093 | */ |
---|
1094 | private ITask createNewIteration(int maxNoOfChildren, |
---|
1095 | int maxDepth, |
---|
1096 | Map<ITask, ITaskInfo> taskInfos) |
---|
1097 | throws Exception |
---|
1098 | { |
---|
1099 | IIteration iteration = taskFactory.createNewIteration(); |
---|
1100 | |
---|
1101 | ITask child = createTaskTree(maxNoOfChildren, maxDepth - 1, taskInfos); |
---|
1102 | taskBuilder.setMarkedTask(iteration, child); |
---|
1103 | |
---|
1104 | taskInfos.put(iteration, new TaskInfo(iteration)); |
---|
1105 | return iteration; |
---|
1106 | } |
---|
1107 | |
---|
1108 | /** |
---|
1109 | * |
---|
1110 | */ |
---|
1111 | private ITask reuseIteration(int maxNoOfChildren, |
---|
1112 | int maxDepth, |
---|
1113 | Map<ITask, ITaskInfo> taskInfos) |
---|
1114 | throws Exception |
---|
1115 | { |
---|
1116 | ITask iteration = reuseTask(taskInfos, IIteration.class); |
---|
1117 | |
---|
1118 | if (iteration == null) { |
---|
1119 | iteration = createNewIteration(maxNoOfChildren, maxDepth, taskInfos); |
---|
1120 | } |
---|
1121 | |
---|
1122 | return iteration; |
---|
1123 | } |
---|
1124 | |
---|
1125 | /** |
---|
1126 | * |
---|
1127 | */ |
---|
1128 | private ITask createNewOptional(int maxNoOfChildren, |
---|
1129 | int maxDepth, |
---|
1130 | Map<ITask, ITaskInfo> taskInfos) |
---|
1131 | throws Exception |
---|
1132 | { |
---|
1133 | IOptional optional = taskFactory.createNewOptional(); |
---|
1134 | |
---|
1135 | ITask child = createTaskTree(maxNoOfChildren, maxDepth - 1, taskInfos); |
---|
1136 | taskBuilder.setMarkedTask(optional, child); |
---|
1137 | |
---|
1138 | taskInfos.put(optional, new TaskInfo(optional)); |
---|
1139 | return optional; |
---|
1140 | } |
---|
1141 | |
---|
1142 | /** |
---|
1143 | * |
---|
1144 | */ |
---|
1145 | private ITask reuseOptional(int maxNoOfChildren, |
---|
1146 | int maxDepth, |
---|
1147 | Map<ITask, ITaskInfo> taskInfos) |
---|
1148 | throws Exception |
---|
1149 | { |
---|
1150 | ITask optional = reuseTask(taskInfos, IOptional.class); |
---|
1151 | |
---|
1152 | if (optional == null) { |
---|
1153 | optional = createNewOptional(maxNoOfChildren, maxDepth, taskInfos); |
---|
1154 | } |
---|
1155 | |
---|
1156 | return optional; |
---|
1157 | } |
---|
1158 | |
---|
1159 | /** |
---|
1160 | * |
---|
1161 | */ |
---|
1162 | private ITask reuseTask(Map<ITask, ITaskInfo> taskInfos, Class<? extends ITask> type) |
---|
1163 | throws Exception |
---|
1164 | { |
---|
1165 | int noOfTasks = 0; |
---|
1166 | |
---|
1167 | for (Map.Entry<ITask, ITaskInfo> entry : taskInfos.entrySet()) { |
---|
1168 | if (type.isInstance(entry.getKey())) { |
---|
1169 | noOfTasks++; |
---|
1170 | } |
---|
1171 | } |
---|
1172 | |
---|
1173 | if (noOfTasks > 0) { |
---|
1174 | noOfTasks = randomize(noOfTasks); |
---|
1175 | |
---|
1176 | for (Map.Entry<ITask, ITaskInfo> entry : taskInfos.entrySet()) { |
---|
1177 | if (type.isInstance(entry.getKey())) { |
---|
1178 | if (--noOfTasks <= 0) { |
---|
1179 | return entry.getKey(); |
---|
1180 | } |
---|
1181 | } |
---|
1182 | } |
---|
1183 | } |
---|
1184 | else { |
---|
1185 | return null; |
---|
1186 | } |
---|
1187 | |
---|
1188 | throw new RuntimeException("this is an implementation error"); |
---|
1189 | } |
---|
1190 | |
---|
1191 | /** |
---|
1192 | * |
---|
1193 | */ |
---|
1194 | private ITaskInstance instantiateTask(ITask task, int maxIterationCount) throws Exception { |
---|
1195 | ITaskInstance instance = taskFactory.createNewTaskInstance(task); |
---|
1196 | |
---|
1197 | if (task instanceof ISequence) { |
---|
1198 | for (ITask child : ((ISequence) task).getChildren()) { |
---|
1199 | taskBuilder.addChild(instance, instantiateTask(child, maxIterationCount)); |
---|
1200 | } |
---|
1201 | } |
---|
1202 | else if (task instanceof ISelection) { |
---|
1203 | List<ITask> children = ((ISelection) task).getChildren(); |
---|
1204 | int index = randomize(children.size()); |
---|
1205 | taskBuilder.addChild(instance, instantiateTask(children.get(index), maxIterationCount)); |
---|
1206 | } |
---|
1207 | else if (task instanceof IIteration) { |
---|
1208 | int count = randomize(maxIterationCount); |
---|
1209 | ITask child = ((IIteration) task).getMarkedTask(); |
---|
1210 | |
---|
1211 | for (int i = 0; i < count; i++) { |
---|
1212 | taskBuilder.addChild(instance, instantiateTask(child, maxIterationCount)); |
---|
1213 | } |
---|
1214 | } |
---|
1215 | else if (task instanceof IOptional) { |
---|
1216 | ITask child = ((IOptional) task).getMarkedTask(); |
---|
1217 | |
---|
1218 | if (randomize(1) == 0) { |
---|
1219 | taskBuilder.addChild(instance, instantiateTask(child, maxIterationCount)); |
---|
1220 | } |
---|
1221 | } |
---|
1222 | |
---|
1223 | return instance; |
---|
1224 | } |
---|
1225 | |
---|
1226 | /** |
---|
1227 | * |
---|
1228 | */ |
---|
1229 | private int randomize(int max) throws Exception { |
---|
1230 | return randomize(0, max); |
---|
1231 | } |
---|
1232 | |
---|
1233 | /** |
---|
1234 | * |
---|
1235 | */ |
---|
1236 | private int randomize(int min, int max) throws Exception { |
---|
1237 | if (min > max) { |
---|
1238 | throw new IllegalArgumentException("min must always be smaller or equal than max"); |
---|
1239 | } |
---|
1240 | |
---|
1241 | int deviation = max - min; |
---|
1242 | int value = (int) (Math.random() * deviation); |
---|
1243 | |
---|
1244 | return value + min; |
---|
1245 | } |
---|
1246 | } |
---|