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