Changeset 1327
- Timestamp:
- 01/15/14 16:05:34 (11 years ago)
- Location:
- trunk/autoquest-test-utils/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
r1325 r1327 17 17 import java.util.ArrayList; 18 18 import java.util.HashMap; 19 import java.util.HashSet; 19 20 import java.util.LinkedList; 20 21 import java.util.List; 21 22 import java.util.Map; 23 import java.util.Set; 22 24 import java.util.regex.Matcher; 23 25 import java.util.regex.Pattern; … … 99 101 } 100 102 103 correctTargets(taskInstanceList); 104 101 105 return taskInstanceList; 102 106 } … … 190 194 } 191 195 else { 192 Event event = !task.getInstances().isEmpty() ? 193 ((IEventTaskInstance) task.getInstances().iterator().next()).getEvent() : 194 createUserInteractionEvent(type, id, matcher.group(4)); 195 196 Event event = createUserInteractionEvent(type, id, matcher.group(4)); 196 197 instance = taskFactory.createNewTaskInstance((IEventTask) task, event); 197 198 } … … 237 238 238 239 /** 239 * <p> 240 * TODO: comment 241 * </p> 242 * 243 * @param id 244 * @param type 245 * @param children 246 * @return 240 * 247 241 */ 248 242 private ITask getCreateTask(String id, String type, List<ITaskInstance> children) { 249 ITask task = tasks.get(id); 243 String effectiveId = id; 244 ITask task = tasks.get(effectiveId); 250 245 251 246 if (task == null) { … … 263 258 } 264 259 else { 265 task = taskFactory.createNewEventTask(type + " --> " + id); 260 effectiveId = type + " --> " + id; 261 task = tasks.get(effectiveId); 262 263 if (task == null) { 264 task = taskFactory.createNewEventTask(effectiveId); 265 } 266 266 } 267 tasks.put( id, task);267 tasks.put(effectiveId, task); 268 268 269 269 for (ITaskInstance childInstance : children) { … … 332 332 IEventTarget eventTarget = targets.get(targetId); 333 333 if (eventTarget == null) { 334 eventTarget = determineTarget(type, targetId, furtherInfo);334 eventTarget = new DummyGUIElement(targetId); 335 335 targets.put(targetId, eventTarget); 336 336 } 337 337 338 IEventType eventType = determineType(type, furtherInfo); 338 339 339 340 return new Event(eventType, eventTarget); 340 }341 342 /**343 * <p>344 * </p>345 *346 * @param type347 * @param id348 * @param enteredText349 * @return350 */351 private IEventTarget determineTarget(String type, String id, String enteredText) {352 if ("TextInput".equals(type) && enteredText != null) {353 return new DummyTextField(enteredText);354 }355 else {356 return new DummyGUIElement(id);357 }358 341 } 359 342 … … 367 350 */ 368 351 private IEventType determineType(String type, String enteredText) { 369 if ("TextInput".equals(type) && enteredText != null) {352 if ("TextInput".equals(type)) { 370 353 return new TextInput(enteredText, new ArrayList<Event>()); 371 354 } … … 375 358 } 376 359 360 /** 361 * 362 */ 363 private void correctTargets(ITaskInstanceList taskInstanceList) { 364 Set<IEventTarget> textInputTargets = new HashSet<IEventTarget>(); 365 366 for (ITaskInstance instance : taskInstanceList) { 367 getTextInputTargets(instance, textInputTargets); 368 } 369 370 Map<IEventTarget, IEventTarget> replacements = new HashMap<IEventTarget, IEventTarget>(); 371 372 for (IEventTarget oldTarget : textInputTargets) { 373 replacements.put(oldTarget, new DummyTextField(oldTarget.toString())); 374 } 375 376 for (int i = 0; i < taskInstanceList.size(); i++) { 377 taskBuilder.setTaskInstance 378 (taskInstanceList, i, replaceTargets(taskInstanceList.get(i), replacements)); 379 } 380 381 } 382 383 /** 384 * 385 */ 386 private void getTextInputTargets(ITaskInstance instance, Set<IEventTarget> textInputTargets) { 387 if (instance instanceof ISequenceInstance) { 388 for (ITaskInstance child : (ISequenceInstance) instance) { 389 getTextInputTargets(child, textInputTargets); 390 } 391 } 392 else if (instance instanceof ISelectionInstance) { 393 getTextInputTargets(((ISelectionInstance) instance).getChild(), textInputTargets); 394 } 395 else if (instance instanceof IIterationInstance) { 396 for (ITaskInstance child : (IIterationInstance) instance) { 397 getTextInputTargets(child, textInputTargets); 398 } 399 } 400 else if (instance instanceof IOptionalInstance) { 401 getTextInputTargets(((IOptionalInstance) instance).getChild(), textInputTargets); 402 } 403 else if ((instance instanceof IEventTaskInstance) && 404 (((IEventTaskInstance) instance).getEvent().getType() instanceof TextInput)) 405 { 406 textInputTargets.add(((IEventTaskInstance) instance).getEvent().getTarget()); 407 } 408 } 409 410 /** 411 * 412 */ 413 private ITaskInstance replaceTargets(ITaskInstance instance, 414 Map<IEventTarget, IEventTarget> replacements) 415 { 416 ITaskInstance replacement = instance; 417 if (instance instanceof ITaskInstanceList) { 418 for (int i = 0; i < ((ITaskInstanceList) instance).size(); i++) { 419 taskBuilder.setTaskInstance 420 ((ITaskInstanceList) instance, i, 421 replaceTargets(((ITaskInstanceList) instance).get(i), replacements)); 422 } 423 } 424 else if (instance instanceof ISelectionInstance) { 425 ISelectionInstance selInst = (ISelectionInstance) instance; 426 taskBuilder.setChild(selInst, replaceTargets(selInst.getChild(), replacements)); 427 } 428 else if (instance instanceof IOptionalInstance) { 429 IOptionalInstance optInst = (IOptionalInstance) instance; 430 taskBuilder.setChild(optInst, replaceTargets(optInst.getChild(), replacements)); 431 } 432 else if ((instance instanceof IEventTaskInstance) && 433 (replacements.containsKey(((IEventTaskInstance) instance).getEvent().getTarget()))) 434 { 435 Event origEvent = ((IEventTaskInstance) instance).getEvent(); 436 replacement = taskFactory.createNewTaskInstance 437 (((IEventTaskInstance) instance).getEventTask(), 438 new Event(origEvent.getType(), replacements.get(origEvent.getTarget()))); 439 } 440 441 return replacement; 442 } 443 377 444 } -
trunk/autoquest-test-utils/src/test/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoderTest.java
r1325 r1327 19 19 import org.junit.Test; 20 20 21 import de.ugoe.cs.autoquest.eventcore.Event; 22 import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; 23 import de.ugoe.cs.autoquest.eventcore.guimodel.ITextArea; 24 import de.ugoe.cs.autoquest.eventcore.guimodel.ITextField; 21 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 22 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; … … 237 241 assertFalse(list.get(0).equals(list.get(1))); 238 242 assertTrue(list.get(0).getTask().equals(list.get(1).getTask())); 243 244 new TaskTreeValidator().validate(list); 245 } 246 247 /** 248 * 249 */ 250 @Test 251 public void test_GuiElements_01() { 252 String blub = 253 "UserSession {" + 254 " MouseClick elem1 { }" + 255 "}"; 256 257 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 258 259 ITaskInstanceList list = decoder.decode(blub); 260 261 assertTrue(list.get(0) instanceof IEventTaskInstance); 262 263 Event event = ((IEventTaskInstance) list.get(0)).getEvent(); 264 265 assertTrue(event.getTarget() instanceof IGUIElement); 266 assertFalse(event.getTarget() instanceof ITextArea); 267 assertFalse(event.getTarget() instanceof ITextField); 268 269 new TaskTreeValidator().validate(list); 270 } 271 272 /** 273 * 274 */ 275 @Test 276 public void test_GuiElements_02() { 277 String blub = 278 "UserSession {" + 279 " TextInput elem1 { }" + 280 "}"; 281 282 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 283 284 ITaskInstanceList list = decoder.decode(blub); 285 286 assertTrue(list.get(0) instanceof IEventTaskInstance); 287 288 Event event = ((IEventTaskInstance) list.get(0)).getEvent(); 289 290 assertTrue(event.getTarget() instanceof IGUIElement); 291 assertFalse(event.getTarget() instanceof ITextArea); 292 assertTrue(event.getTarget() instanceof ITextField); 293 294 new TaskTreeValidator().validate(list); 295 } 296 297 /** 298 * 299 */ 300 @Test 301 public void test_GuiElements_03() { 302 String blub = 303 "UserSession {" + 304 " OtherInteraction elem1 { }" + 305 " TextInput elem1 { }" + 306 "}"; 307 308 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 309 310 ITaskInstanceList list = decoder.decode(blub); 311 312 assertTrue(list.get(0) instanceof IEventTaskInstance); 313 314 Event event = ((IEventTaskInstance) list.get(0)).getEvent(); 315 316 assertTrue(event.getTarget() instanceof IGUIElement); 317 assertFalse(event.getTarget() instanceof ITextArea); 318 assertTrue(event.getTarget() instanceof ITextField); 319 320 assertTrue(list.get(1) instanceof IEventTaskInstance); 321 322 event = ((IEventTaskInstance) list.get(1)).getEvent(); 323 324 assertTrue(event.getTarget() instanceof IGUIElement); 325 assertFalse(event.getTarget() instanceof ITextArea); 326 assertTrue(event.getTarget() instanceof ITextField); 327 328 new TaskTreeValidator().validate(list); 329 } 330 331 /** 332 * 333 */ 334 @Test 335 public void test_GuiElements_04() { 336 String blub = 337 "UserSession {" + 338 " Sequence seq1 {" + 339 " TextInput elem1 { }" + 340 " }" + 341 "}"; 342 343 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 344 345 ITaskInstanceList list = decoder.decode(blub); 346 347 assertTrue(list.get(0) instanceof ISequenceInstance); 348 assertTrue(((ISequenceInstance) list.get(0)).get(0) instanceof IEventTaskInstance); 349 350 Event event = ((IEventTaskInstance) ((ISequenceInstance) list.get(0)).get(0)).getEvent(); 351 352 assertTrue(event.getTarget() instanceof IGUIElement); 353 assertFalse(event.getTarget() instanceof ITextArea); 354 assertTrue(event.getTarget() instanceof ITextField); 355 356 new TaskTreeValidator().validate(list); 357 } 358 359 /** 360 * 361 */ 362 @Test 363 public void test_GuiElements_05() { 364 String blub = 365 "UserSession {" + 366 " Selection sel1 {" + 367 " TextInput elem1 { }" + 368 " }" + 369 "}"; 370 371 TaskTreeDecoder decoder = new TaskTreeDecoder(new TaskFactory(), new TaskBuilder()); 372 373 ITaskInstanceList list = decoder.decode(blub); 374 375 assertTrue(list.get(0) instanceof ISelectionInstance); 376 assertTrue(((ISelectionInstance) list.get(0)).getChild() instanceof IEventTaskInstance); 377 378 Event event = 379 ((IEventTaskInstance) ((ISelectionInstance) list.get(0)).getChild()).getEvent(); 380 381 assertTrue(event.getTarget() instanceof IGUIElement); 382 assertFalse(event.getTarget() instanceof ITextArea); 383 assertTrue(event.getTarget() instanceof ITextField); 239 384 240 385 new TaskTreeValidator().validate(list);
Note: See TracChangeset
for help on using the changeset viewer.