source: trunk/quest-core-tasktrees-test/src/test/java/de/ugoe/cs/quest/tasktrees/manager/TaskTreeManagerTest.java @ 452

Last change on this file since 452 was 452, checked in by pharms, 12 years ago

refactored to integrate it into QUEST

  • Property svn:executable set to *
File size: 20.0 KB
Line 
1//-------------------------------------------------------------------------------------------------
2// Module    : $RCSfile: TaskTreeManagerTest.java,v $
3// Version   : $Revision: 0.0 $  $Author: Patrick $  $Date: 08.11.2011 21:32:36 $
4// Project   : TaskTreePerformanceTest
5// Creation  : 2011 by Patrick
6// Copyright : Patrick Harms, 2011
7//-------------------------------------------------------------------------------------------------
8
9package de.ugoe.cs.quest.tasktrees.manager;
10
11import java.util.logging.Logger;
12
13import org.junit.After;
14import org.junit.Before;
15import org.junit.Test;
16
17import de.ugoe.cs.quest.eventcore.guimodel.GUIElement;
18import de.ugoe.cs.quest.eventcore.userinteraction.Interaction;
19import de.ugoe.cs.quest.eventcore.userinteraction.InteractionEvent;
20import de.ugoe.cs.quest.tasktrees.testutils.DummyGUIElement;
21import de.ugoe.cs.quest.tasktrees.testutils.DummyInteraction;
22import de.ugoe.cs.quest.tasktrees.testutils.SimpleLogFormatter;
23import de.ugoe.cs.quest.tasktrees.testutils.TaskTreeChecker;
24
25//-------------------------------------------------------------------------------------------------
26/**
27 * TODO comment
28 *
29 * @version $Revision: $ $Date: $
30 * @author  2011, last modified by $Author: $
31 */
32//-------------------------------------------------------------------------------------------------
33
34public class TaskTreeManagerTest
35{
36  /** */
37  TaskTreeManager mManager;
38 
39  //-----------------------------------------------------------------------------------------------
40  /**
41   *
42   */
43  //-----------------------------------------------------------------------------------------------
44  @Before
45  public void setUp()
46  {
47    Logger.getLogger("").getHandlers()[0].setFormatter(new SimpleLogFormatter());
48   
49    mManager = new TaskTreeManager();
50  }
51
52  //-----------------------------------------------------------------------------------------------
53  /**
54   *
55   */
56  //-----------------------------------------------------------------------------------------------
57  @After
58  public void tearDown()
59  {
60    mManager = null;
61    ComponentManager.clearInstance();
62  }
63
64  //-----------------------------------------------------------------------------------------------
65  /**
66   *
67   */
68  //-----------------------------------------------------------------------------------------------
69  @Test
70  public void testOneInteractionOnOneElement()
71  {
72    simulateInteraction(new DummyGUIElement("elem1"), new DummyInteraction("bla", 1));
73    new TaskTreeChecker().assertTaskMap
74      ("Sequence sequence {" +
75       "  Interaction bla {}" +
76       "}", mManager.getTaskTree().getTaskMap());
77  }
78 
79  //-----------------------------------------------------------------------------------------------
80  /**
81   *
82   */
83  //-----------------------------------------------------------------------------------------------
84  @Test
85  public void testManyInteractionsOnOneElement()
86  {
87    GUIElement element = new DummyGUIElement("elem1");
88    simulateInteraction(element, new DummyInteraction("bla", 1));
89    simulateInteraction(element, new DummyInteraction("bli", 1));
90    simulateInteraction(element, new DummyInteraction("blo", 1));
91    simulateInteraction(element, new DummyInteraction("blu", 1));
92    simulateInteraction(element, new DummyInteraction("bla", 1));
93
94    new TaskTreeChecker().assertTaskMap
95      ("Sequence sequence {" +
96       "  Interaction bla {}" +
97       "  Interaction bli {}" +
98       "  Interaction blo {}" +
99       "  Interaction blu {}" +
100       "  Interaction bla {}" +
101       "}", mManager.getTaskTree().getTaskMap());
102  }
103 
104  //-----------------------------------------------------------------------------------------------
105  /**
106   *
107   */
108  //-----------------------------------------------------------------------------------------------
109  @Test
110  public void testOneInteractionOnManyElements()
111  {
112    GUIElement element1 = new DummyGUIElement("elem1");
113    GUIElement element2 = new DummyGUIElement("elem2");
114    GUIElement element3 = new DummyGUIElement("elem3");
115    GUIElement element4 = new DummyGUIElement("elem4");
116    GUIElement element5 = new DummyGUIElement("elem5");
117    GUIElement element6 = new DummyGUIElement("elem6");
118    simulateInteraction(element1, new DummyInteraction("bla", 1));
119    simulateInteraction(element2, new DummyInteraction("bli", 1));
120    simulateInteraction(element3, new DummyInteraction("bla", 1));
121    simulateInteraction(element4, new DummyInteraction("bli", 1));
122    simulateInteraction(element5, new DummyInteraction("blo", 1));
123    simulateInteraction(element6, new DummyInteraction("bla", 1));
124   
125    new TaskTreeChecker().assertTaskMap
126      ("Sequence sequence0 {" +
127       "  Sequence sequence1 {" +
128       "    Interaction bla {}" +
129       "  }" +
130       "  Sequence sequence2 {" +
131       "    Interaction bli {}" +
132       "  }" +
133       "  Sequence sequence3 {" +
134       "    Interaction bla {}" +
135       "  }" +
136       "  Sequence sequence4 {" +
137       "    Interaction bli {}" +
138       "  }" +
139       "  Sequence sequence5 {" +
140       "    Interaction blo {}" +
141       "  }" +
142       "  Sequence sequence6 {" +
143       "    Interaction bla {}" +
144       "  }" +
145       "}", mManager.getTaskTree().getTaskMap());
146  }
147
148  //-----------------------------------------------------------------------------------------------
149  /**
150   *
151   */
152  //-----------------------------------------------------------------------------------------------
153  @Test
154  public void testManyInteractionsOnManyElements()
155  {
156    GUIElement element1 = new DummyGUIElement("elem1");
157    GUIElement element2 = new DummyGUIElement("elem2");
158    GUIElement element3 = new DummyGUIElement("elem3");
159    GUIElement element4 = new DummyGUIElement("elem4");
160    GUIElement element5 = new DummyGUIElement("elem5");
161    GUIElement element6 = new DummyGUIElement("elem6");
162    simulateInteraction(element1, new DummyInteraction("bla", 1));
163    simulateInteraction(element1, new DummyInteraction("bli", 1));
164    simulateInteraction(element1, new DummyInteraction("bla", 1));
165    simulateInteraction(element2, new DummyInteraction("bli", 1));
166    simulateInteraction(element2, new DummyInteraction("blo", 1));
167    simulateInteraction(element3, new DummyInteraction("bla", 1));
168    simulateInteraction(element4, new DummyInteraction("bli", 1));
169    simulateInteraction(element4, new DummyInteraction("bla", 1));
170    simulateInteraction(element4, new DummyInteraction("bli", 1));
171    simulateInteraction(element4, new DummyInteraction("blo", 1));
172    simulateInteraction(element5, new DummyInteraction("bla", 1));
173    simulateInteraction(element6, new DummyInteraction("bli", 1));
174    simulateInteraction(element6, new DummyInteraction("bla", 1));
175    simulateInteraction(element6, new DummyInteraction("bli", 1));
176    simulateInteraction(element6, new DummyInteraction("blo", 1));
177
178    new TaskTreeChecker().assertTaskMap
179      ("Sequence sequence0 {" +
180       "  Sequence sequence1 {" +
181       "    Interaction bla {}" +
182       "    Interaction bli {}" +
183       "    Interaction bla {}" +
184       "  }" +
185       "  Sequence sequence2 {" +
186       "    Interaction bli {}" +
187       "    Interaction blo {}" +
188       "  }" +
189       "  Sequence sequence3 {" +
190       "    Interaction bla {}" +
191       "  }" +
192       "  Sequence sequence4 {" +
193       "    Interaction bli {}" +
194       "    Interaction bla {}" +
195       "    Interaction bli {}" +
196       "    Interaction blo {}" +
197       "  }" +
198       "  Sequence sequence5 {" +
199       "    Interaction bla {}" +
200       "  }" +
201       "  Sequence sequence6 {" +
202       "    Interaction bli {}" +
203       "    Interaction bla {}" +
204       "    Interaction bli {}" +
205       "    Interaction blo {}" +
206       "  }" +
207       "}", mManager.getTaskTree().getTaskMap());
208  }
209
210  //-----------------------------------------------------------------------------------------------
211  /**
212   *
213   */
214  //-----------------------------------------------------------------------------------------------
215  @Test
216  public void testInteractionIterationDetection() throws Exception
217  {
218    GUIElement element1 = new DummyGUIElement("elem1");
219    Interaction interaction1 = new DummyInteraction("bla", 1);
220    simulateInteraction(element1, interaction1);
221    new TaskTreeChecker().assertTaskMap
222      ("Sequence sequence1 {" +
223       "  Interaction bla {}" +
224       "}", mManager.getTaskTree().getTaskMap());   
225
226    simulateInteraction(element1, interaction1);
227    new TaskTreeChecker().assertTaskMap
228      ("Sequence sequence1 {" +
229       "  Iteration iteration1 {" +
230       "    Interaction bla {}" +
231       "  }" +
232       "}", mManager.getTaskTree().getTaskMap());   
233
234    simulateInteraction(element1, interaction1);
235    new TaskTreeChecker().assertTaskMap
236      ("Sequence sequence1 {" +
237       "  Iteration iteration1 {" +
238       "    Interaction bla {}" +
239       "  }" +
240       "}", mManager.getTaskTree().getTaskMap());   
241
242    for (int i = 0; i < 10; i++)
243    {
244      simulateInteraction(element1, interaction1);
245    }
246   
247    new TaskTreeChecker().assertTaskMap
248      ("Sequence sequence1 {" +
249       "  Iteration iteration1 {" +
250       "    Interaction bla {}" +
251       "  }" +
252       "}", mManager.getTaskTree().getTaskMap());   
253   
254    // now test with preceding and trailing other interactions
255    Interaction interaction2 = new DummyInteraction("bli", 1);
256    Interaction interaction3 = new DummyInteraction("blup", 1);
257
258    simulateInteraction(element1, interaction2);
259    simulateInteraction(element1, interaction3);
260    for (int i = 0; i < 10; i++)
261    {
262      simulateInteraction(element1, interaction1);
263    }
264    simulateInteraction(element1, interaction3);
265    simulateInteraction(element1, interaction2);
266   
267    new TaskTreeChecker().assertTaskMap
268      ("Sequence sequence1 {" +
269       "  Iteration iteration1 {" +
270       "    Interaction bla {}" +
271       "  }" +
272       "  Interaction bli {}" +
273       "  Interaction blup {}" +
274       "  Iteration iteration2 {" +
275       "    Interaction bla {}" +
276       "  }" +
277       "  Interaction blup {}" +
278       "  Interaction bli {}" +
279       "}", mManager.getTaskTree().getTaskMap());   
280 
281    // now test with iterations of iterations
282
283    for (int i = 0; i < 10; i++)
284    {
285      for (int j = 0; j < 5; j++)
286      {
287        simulateInteraction(element1, interaction1);
288      }
289      for (int j = 0; j < 5; j++)
290      {
291        simulateInteraction(element1, interaction2);
292      }
293      for (int j = 0; j < 5; j++)
294      {
295        simulateInteraction(element1, interaction3);
296      }
297    }
298   
299    new TaskTreeChecker().assertTaskMap
300      ("Sequence sequence0 {" +
301       "  Iteration iteration0 {" +
302       "    Interaction bla {}" +
303       "  }" +
304       "  Interaction bli {}" +
305       "  Interaction blup {}" +
306       "  Iteration iteration1 {" +
307       "    Interaction bla {}" +
308       "  }" +
309       "  Interaction blup {}" +
310       "  Interaction bli {}" +
311       "  Iteration iteration2 {" +
312       "    Sequence sequence1 {" +
313       "      Iteration iteration3 {" +
314       "        Interaction bla {}" +
315       "      }" +
316       "      Iteration iteration4 {" +
317       "        Interaction bli {}" +
318       "      }" +
319       "      Iteration iteration5 {" +
320       "        Interaction blup {}" +
321       "      }" +
322       "    }" +
323       "  }" +
324       "}", mManager.getTaskTree().getTaskMap());   
325 
326  }
327 
328  //-----------------------------------------------------------------------------------------------
329  /**
330   *
331   */
332  //-----------------------------------------------------------------------------------------------
333  @Test
334  public void testSequenceIterationDetection() throws Exception
335  {
336    GUIElement element1 = new DummyGUIElement("elem1");
337    Interaction interaction1 = new DummyInteraction("bla", 1);
338    Interaction interaction2 = new DummyInteraction("bli", 1);
339    Interaction interaction3 = new DummyInteraction("blup", 1);
340    simulateInteraction(element1, interaction1);
341    simulateInteraction(element1, interaction2);
342    simulateInteraction(element1, interaction3);
343    new TaskTreeChecker().assertTaskMap
344      ("Sequence sequence1 {" +
345       "  Interaction bla {}" +
346       "  Interaction bli {}" +
347       "  Interaction blup {}" +
348       "}", mManager.getTaskTree().getTaskMap());   
349
350    simulateInteraction(element1, interaction1);
351    simulateInteraction(element1, interaction2);
352    simulateInteraction(element1, interaction3);
353    new TaskTreeChecker().assertTaskMap
354      ("Sequence sequence1 {" +
355       "  Iteration iteration1 {" +
356       "    Sequence sequence2 {" +
357       "      Interaction bla {}" +
358       "      Interaction bli {}" +
359       "      Interaction blup {}" +
360       "    }" +
361       "  }" +
362       "}", mManager.getTaskTree().getTaskMap());   
363
364    simulateInteraction(element1, interaction1);
365    simulateInteraction(element1, interaction2);
366    simulateInteraction(element1, interaction3);
367    new TaskTreeChecker().assertTaskMap
368      ("Sequence sequence1 {" +
369       "  Iteration iteration1 {" +
370       "    Sequence sequence2 {" +
371       "      Interaction bla {}" +
372       "      Interaction bli {}" +
373       "      Interaction blup {}" +
374       "    }" +
375       "  }" +
376       "}", mManager.getTaskTree().getTaskMap());   
377
378    for (int i = 0; i < 10; i++)
379    {
380      simulateInteraction(element1, interaction1);
381      simulateInteraction(element1, interaction2);
382      simulateInteraction(element1, interaction3);
383    }
384   
385    new TaskTreeChecker().assertTaskMap
386      ("Sequence sequence1 {" +
387       "  Iteration iteration1 {" +
388       "    Sequence sequence2 {" +
389       "      Interaction bla {}" +
390       "      Interaction bli {}" +
391       "      Interaction blup {}" +
392       "    }" +
393       "  }" +
394       "}", mManager.getTaskTree().getTaskMap());   
395   
396    // now test with preceding and trailing other interactions
397    Interaction interaction4 = new DummyInteraction("ble", 1);
398    Interaction interaction5 = new DummyInteraction("blo", 1);
399    Interaction interaction6 = new DummyInteraction("blu", 1);
400    simulateInteraction(element1, interaction4);
401    simulateInteraction(element1, interaction5);
402    simulateInteraction(element1, interaction6);
403    for (int i = 0; i < 10; i++)
404    {
405      simulateInteraction(element1, interaction1);
406      simulateInteraction(element1, interaction2);
407      simulateInteraction(element1, interaction3);
408    }
409    simulateInteraction(element1, interaction6);
410    simulateInteraction(element1, interaction5);
411    simulateInteraction(element1, interaction4);
412   
413    new TaskTreeChecker().assertTaskMap
414    ("Sequence sequence1 {" +
415     "  Iteration iteration1 {" +
416     "    Sequence sequence2 {" +
417     "      Interaction bla {}" +
418     "      Interaction bli {}" +
419     "      Interaction blup {}" +
420     "    }" +
421     "  }" +
422     "  Interaction ble {}" +
423     "  Interaction blo {}" +
424     "  Interaction blu {}" +
425     "  Iteration iteration2 {" +
426     "    Sequence sequence3 {" +
427     "      Interaction bla {}" +
428     "      Interaction bli {}" +
429     "      Interaction blup {}" +
430     "    }" +
431     "  }" +
432     "  Interaction blu {}" +
433     "  Interaction blo {}" +
434     "  Interaction ble {}" +
435     "}", mManager.getTaskTree().getTaskMap());   
436 
437    // now test with iterations of iterations
438    for (int i = 0; i < 10; i++)
439    {
440      for (int j = 0; j < 5; j++)
441      {
442        simulateInteraction(element1, interaction1);
443        simulateInteraction(element1, interaction2);
444        simulateInteraction(element1, interaction3);
445      }
446      for (int j = 0; j < 5; j++)
447      {
448        simulateInteraction(element1, interaction2);
449        simulateInteraction(element1, interaction1);
450        simulateInteraction(element1, interaction3);
451      }
452      for (int j = 0; j < 5; j++)
453      {
454        simulateInteraction(element1, interaction1);
455        simulateInteraction(element1, interaction2);
456        simulateInteraction(element1, interaction3);
457      }
458    }
459   
460    new TaskTreeChecker().assertTaskMap
461      ("Sequence sequence1 {" +
462       "  Iteration iteration1 {" +
463       "    Sequence sequence2 {" +
464       "      Interaction bla {}" +
465       "      Interaction bli {}" +
466       "      Interaction blup {}" +
467       "    }" +
468       "  }" +
469       "  Interaction ble {}" +
470       "  Interaction blo {}" +
471       "  Interaction blu {}" +
472       "  Iteration iteration2 {" +
473       "    Sequence sequence3 {" +
474       "      Interaction bla {}" +
475       "      Interaction bli {}" +
476       "      Interaction blup {}" +
477       "    }" +
478       "  }" +
479       "  Interaction blu {}" +
480       "  Interaction blo {}" +
481       "  Interaction ble {}" +
482       "  Iteration iteration3 {" +
483       "    Sequence sequence4 {" +
484       "      Iteration iteration4 {" +
485       "        Sequence sequence4 {" +
486       "          Interaction bla {}" +
487       "          Interaction bli {}" +
488       "          Interaction blup {}" +
489       "        }" +
490       "      }" +
491       "      Iteration iteration5 {" +
492       "        Sequence sequence5 {" +
493       "          Interaction bli {}" +
494       "          Interaction bla {}" +
495       "          Interaction blup {}" +
496       "        }" +
497       "      }" +
498       "      Iteration iteration6 {" +
499       "        Sequence sequence6 {" +
500       "          Interaction bla {}" +
501       "          Interaction bli {}" +
502       "          Interaction blup {}" +
503       "        }" +
504       "      }" +
505       "    }" +
506       "  }" +
507       "}", mManager.getTaskTree().getTaskMap());   
508  }
509 
510  //-----------------------------------------------------------------------------------------------
511  /**
512   *
513   */
514  //-----------------------------------------------------------------------------------------------
515  @Test
516  public void testGUIElementHierarchyChanges() throws Exception
517  {
518    GUIElement element1 = new DummyGUIElement("elem1");
519    GUIElement element2 = new DummyGUIElement("elem2");
520    GUIElement element3 = new DummyGUIElement("elem3");
521    GUIElement parent1 = new DummyGUIElement("parent1");
522    GUIElement parent2 = new DummyGUIElement("parent2");
523    GUIElement parent3 = new DummyGUIElement("parent3");
524   
525    element1.setParent(parent1);
526    element2.setParent(parent2);
527    element3.setParent(parent3);
528   
529    parent1.setParent(parent2);
530    parent2.setParent(parent3);
531   
532    Interaction interaction1 = new DummyInteraction("bla", 1);
533    simulateInteraction(element1, interaction1);
534    simulateInteraction(element2, interaction1);
535    simulateInteraction(element3, interaction1);
536    simulateInteraction(element2, interaction1);
537    simulateInteraction(element3, interaction1);
538    simulateInteraction(element2, interaction1);
539    simulateInteraction(element1, interaction1);
540   
541    new TaskTreeChecker().assertTaskMap
542      ("Sequence sequence0 {" +
543       "  Sequence sequence1 {" +
544       "    Interaction bla {}" +
545       "  }" +
546       "  Sequence sequence2 {" +
547       "    Interaction bla {}" +
548       "  }" +
549       "  Iteration iteration0 {" +
550       "    Sequence sequence3 {" +
551       "      Sequence sequence4 {" +
552       "        Interaction bla {}" +
553       "      }" +
554       "      Sequence sequence5 {" +
555       "        Interaction bla {}" +
556       "      }" +
557       "    }" +
558       "  }" +
559       "  Sequence sequence6 {" +
560       "    Interaction bla {}" +
561       "  }" +
562       "}", mManager.getTaskTree().getTaskMap());   
563
564  }
565 
566  //-----------------------------------------------------------------------------------------------
567  /**
568   * @param interactionsDoNotOverwriteElement
569   */
570  //-----------------------------------------------------------------------------------------------
571  private void simulateInteraction(GUIElement GUIElement, Interaction interaction)
572  {
573    mManager.handleNewInteractionEvent(new InteractionEvent(GUIElement, interaction));
574  }
575
576}
Note: See TracBrowser for help on using the repository browser.