Changeset 1294 for trunk/autoquest-test-utils
- Timestamp:
- 08/14/13 17:04:42 (11 years ago)
- Location:
- trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeChecker.java
r1146 r1294 20 20 import java.util.HashMap; 21 21 import java.util.Iterator; 22 import java.util.LinkedList; 22 23 import java.util.List; 23 24 import java.util.Map; … … 27 28 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 28 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 29 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 30 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 31 35 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 32 36 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; … … 70 74 * 71 75 */ 72 public void assert TaskInstanceList(String userSessionSpec, ITaskInstanceList taskInstances) {76 public void assertUserSession(String userSessionSpec, IUserSession session) { 73 77 if (doTrace) { 74 new TaskTreeEncoder().encode( taskInstances, System.err);78 new TaskTreeEncoder().encode(session, System.err); 75 79 } 76 80 … … 86 90 87 91 if (taskInstanceSpec != null) { 88 assertTaskInstanceList(taskInstanceSpec, taskInstances, tasks); 92 assertUserSession(taskInstanceSpec, session, tasks); 93 } 94 } 95 } 96 97 /** 98 * 99 */ 100 public void assertTaskInstance(String userSessionSpec, ITaskInstance taskInstance) { 101 if (doTrace) { 102 new TaskTreeEncoder().encode(taskInstance, System.err); 103 } 104 105 TaskSpec taskInstanceSpec = null; 106 107 Matcher taskMatcher = taskPattern.matcher(userSessionSpec); 108 109 Map<String, ITask> tasks = new HashMap<String, ITask>(); 110 111 while (taskMatcher.find()) { 112 113 taskInstanceSpec = parseTaskInstance(taskMatcher); 114 115 if (taskInstanceSpec != null) { 116 assertTaskInstance(taskInstanceSpec, taskInstance, tasks); 89 117 } 90 118 } … … 154 182 } 155 183 156 List<ITaskInstance> expectedChildren = expected.getChildren();157 List<ITaskInstance> checkedChildren = checked.getChildren();184 List<ITaskInstance> expectedChildren = getChildren(expected); 185 List<ITaskInstance> checkedChildren = getChildren(checked); 158 186 159 187 if ((expectedChildren != null) && (expectedChildren.size() > 0)) { … … 241 269 * @param taskMapCopy 242 270 */ 243 private void assert TaskInstanceList(TaskSpec taskSpec,244 ITaskInstanceList taskInstances,245 271 private void assertUserSession(TaskSpec taskSpec, 272 IUserSession session, 273 Map<String, ITask> tasks) 246 274 { 247 275 if (doTrace) { 248 System.err.println("\ncomparing " + taskSpec.type + " with " + taskInstances+ "\n");249 } 250 251 if ( (taskInstances instanceof IUserSession) && (!"UserSession".equals(taskSpec.type))) {276 System.err.println("\ncomparing " + taskSpec.type + " with " + session + "\n"); 277 } 278 279 if (!"UserSession".equals(taskSpec.type)) { 252 280 fail("can not compare a task instance with a user session"); 253 281 } 254 else if ((!(taskInstances instanceof IUserSession)) && 255 (!"TaskInstances".equals(taskSpec.type))) 256 { 282 283 List<ITaskInstance> children = session.getExecutedTasks(); 284 285 if (taskSpec.children.length != children.size()) { 286 fail("number of task instances in task instance list does not match"); 287 } 288 289 for (int i = 0; i < children.size(); i++) { 290 TaskSpec childSpec = taskSpec.children[i]; 291 assertTrue(taskSpecEqualsTaskInstance(childSpec, children.get(i), tasks)); 292 } 293 } 294 295 /** 296 * @param task 297 * @param taskMapCopy 298 */ 299 private void assertTaskInstance(TaskSpec taskSpec, 300 ITaskInstance taskInstance, 301 Map<String, ITask> tasks) 302 { 303 if (doTrace) { 304 System.err.println("\ncomparing " + taskSpec.type + " with " + taskInstance + "\n"); 305 } 306 307 if (!"TaskInstances".equals(taskSpec.type)) { 257 308 fail("can not compare a task instance with a task instance list"); 258 309 } 259 310 260 if (taskSpec.children.length != taskInstances.size()) { 311 List<ITaskInstance> children = getChildren(taskInstance); 312 313 if (taskSpec.children.length != children.size()) { 261 314 fail("number of task instances in task instance list does not match"); 262 315 } 263 316 264 for (int i = 0; i < taskInstances.size(); i++) {317 for (int i = 0; i < children.size(); i++) { 265 318 TaskSpec childSpec = taskSpec.children[i]; 266 assertTrue(taskSpecEqualsTaskInstance(childSpec, taskInstances.get(i), tasks));319 assertTrue(taskSpecEqualsTaskInstance(childSpec, children.get(i), tasks)); 267 320 } 268 321 } … … 284 337 if (("Event".equals(taskSpec.type) && (!(task instanceof IEventTask))) || 285 338 ("TextInputEvent".equals(taskSpec.type) && 286 ((!(task instanceof IEventTask)) ||287 (!(((IEventTask ) task).getEventType() instanceof TextInput)))) ||339 ((!(taskInstance instanceof IEventTaskInstance)) || 340 (!(((IEventTaskInstance) taskInstance).getEvent().getType() instanceof TextInput)))) || 288 341 ("Sequence".equals(taskSpec.type) && (!(task instanceof ISequence))) || 289 342 ("Selection".equals(taskSpec.type) && (!(task instanceof ISelection))) || … … 306 359 307 360 if ("TextInputEvent".equals(taskSpec.type)) { 308 TextInput eventType = (TextInput) ((IEventTask) task).getEventType(); 361 TextInput eventType = (TextInput) 362 ((IEventTaskInstance) taskInstance).getEvent().getType(); 363 309 364 if ((taskSpec.additionalInfo != null) && 310 365 !"".equals(taskSpec.additionalInfo) && … … 319 374 } 320 375 } 321 else if ((task instanceof IEventTask) && (((IEventTask) task).getEventType() != null) && 322 (!taskSpec.name.equals(((IEventTask) task).getEventType().getName()))) 376 else if ((task instanceof IEventTask) && 377 (((IEventTaskInstance) taskInstance).getEvent().getType() != null) && 378 (!taskSpec.name.equals(((IEventTaskInstance) taskInstance).getEvent().getType().getName()))) 323 379 { 324 380 // simple event names do not match. But what about the event name in … … 328 384 (!"".equals(taskSpec.additionalInfo) ? " " + taskSpec.additionalInfo : ""); 329 385 330 if (!complexName.equals(((IEventTask ) task).getEventType().getName())) {386 if (!complexName.equals(((IEventTaskInstance) taskInstance).getEvent().getType().getName())) { 331 387 if (doTrace) { 332 System.err.println("event names do not match: " + taskSpec.name + " != " + 333 ((IEventTask) task).getEventType().getName() + "\n"); 388 System.err.println 389 ("event names do not match: " + taskSpec.name + " != " + 390 ((IEventTaskInstance) taskInstance).getEvent().getType().getName() + "\n"); 334 391 } 335 392 return false; … … 358 415 } 359 416 360 if (((taskSpec.children == null) && (taskInstance.getChildren().size() > 0)) || 417 List<ITaskInstance> children = getChildren(taskInstance); 418 419 if (((taskSpec.children == null) && (children.size() > 0)) || 361 420 ((taskSpec.children != null) && 362 (taskSpec.children.length != taskInstance.getChildren().size())))421 (taskSpec.children.length != children.size()))) 363 422 { 364 423 if (doTrace) { … … 366 425 ("numbers of children do not match: " + 367 426 (taskSpec.children == null ? "0" : taskSpec.children.length) + " != " + 368 (taskInstance.getChildren() == null ? "0" : 369 taskInstance.getChildren().size()) + "\n"); 427 (children == null ? "0" : children.size()) + "\n"); 370 428 } 371 429 return false; 372 430 } 373 431 374 Iterator<ITaskInstance> children = taskInstance.getChildren().iterator();432 Iterator<ITaskInstance> childrenIterator = children.iterator(); 375 433 if (taskSpec.children != null) { 376 434 for (TaskSpec child : taskSpec.children) { 377 if (!taskSpecEqualsTaskInstance(child, children .next(), tasks)) {435 if (!taskSpecEqualsTaskInstance(child, childrenIterator.next(), tasks)) { 378 436 if (doTrace) { 379 437 System.err.println("one of the children does not match\n"); … … 384 442 } 385 443 386 if (!children .hasNext()) {444 if (!childrenIterator.hasNext()) { 387 445 if (doTrace) { 388 446 System.err.println("nodes match\n"); … … 398 456 } 399 457 458 /** 459 * <p> 460 * TODO: comment 461 * </p> 462 * 463 * @param taskInstance 464 * @return 465 */ 466 private List<ITaskInstance> getChildren(ITaskInstance taskInstance) { 467 List<ITaskInstance> result = new LinkedList<ITaskInstance>(); 468 469 if (taskInstance instanceof ITaskInstanceList) { 470 for (ITaskInstance child : (ITaskInstanceList) taskInstance) { 471 result.add(child); 472 } 473 } 474 else if (taskInstance instanceof ISelectionInstance) { 475 result.add(((ISelectionInstance) taskInstance).getChild()); 476 } 477 else if (taskInstance instanceof IOptionalInstance) { 478 result.add(((IOptionalInstance) taskInstance).getChild()); 479 } 480 481 return result; 482 } 483 400 484 /** 401 485 * -
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeDecoder.java
r1212 r1294 26 26 import de.ugoe.cs.autoquest.eventcore.StringEventType; 27 27 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 28 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 29 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 30 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 35 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 31 36 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 37 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 32 38 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 33 39 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskBuilder; … … 173 179 } 174 180 else { 175 task = createUserInteractionTask (matcher);181 task = createUserInteractionTaskInstance(matcher).getTask(); 176 182 } 177 183 tasks.put(id, task); 178 184 } 179 185 180 if ((matcher.group(5) != null) && (!"".equals(matcher.group(5).trim()))) { 181 taskBuilder.setDescription(task, matcher.group(5).trim()); 182 } 183 184 ITaskInstance instance = taskFactory.createNewTaskInstance(task); 186 ITaskInstance instance; 187 188 if (task instanceof ISequence) { 189 instance = taskFactory.createNewTaskInstance((ISequence) task); 190 } 191 else if (task instanceof ISelection) { 192 instance = taskFactory.createNewTaskInstance((ISelection) task); 193 } 194 else if (task instanceof IIteration) { 195 instance = taskFactory.createNewTaskInstance((IIteration) task); 196 } 197 else if (task instanceof IOptional) { 198 instance = taskFactory.createNewTaskInstance((IOptional) task); 199 } 200 else { 201 instance = taskFactory.createNewTaskInstance 202 ((IEventTask) task, 203 ((IEventTaskInstance) task.getInstances().iterator().next()).getEvent()); 204 } 185 205 186 206 while (taskMatcher.find() && !"}".equals(taskMatcher.group(0))) { … … 216 236 } 217 237 218 taskBuilder.addChild(instance, childInstance); 238 if (instance instanceof ISequenceInstance) { 239 taskBuilder.addChild((ISequenceInstance) instance, childInstance); 240 } 241 else if (instance instanceof ISelectionInstance) { 242 taskBuilder.setChild((ISelectionInstance) instance, childInstance); 243 } 244 else if (instance instanceof IIterationInstance) { 245 taskBuilder.addChild((IIterationInstance) instance, childInstance); 246 } 247 else if (instance instanceof IOptionalInstance) { 248 taskBuilder.setChild((IOptionalInstance) instance, childInstance); 249 } 219 250 } 220 251 … … 229 260 * @return 230 261 */ 231 private ITask createUserInteractionTask(Matcher matcher) {262 private ITaskInstance createUserInteractionTaskInstance(Matcher matcher) { 232 263 String evenType = matcher.group(1); 233 264 String id = matcher.group(2); 234 IEventTarget even Target = targets.get(id);235 if (even Target == null) {236 even Target = determineTarget(evenType, id, matcher.group(4));237 targets.put(id, even Target);265 IEventTarget eventTarget = targets.get(id); 266 if (eventTarget == null) { 267 eventTarget = determineTarget(evenType, id, matcher.group(4)); 268 targets.put(id, eventTarget); 238 269 } 239 270 IEventType eventType = determineType(evenType, matcher.group(4)); 240 return taskFactory.createNewEventTask(eventType, evenTarget); 271 IEventTask task = taskFactory.createNewEventTask(eventType + " --> " + eventTarget); 272 273 return taskFactory.createNewTaskInstance(task, new Event(eventType, eventTarget)); 241 274 } 242 275 -
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeEncoder.java
r1146 r1294 24 24 import java.util.Map; 25 25 26 import de.ugoe.cs.autoquest.eventcore.Event; 26 27 import de.ugoe.cs.autoquest.eventcore.gui.TextInput; 27 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 28 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 29 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 30 33 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 34 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 31 35 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 32 36 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; … … 141 145 else if (task instanceof IEventTask) { 142 146 out.print(indent); 143 out.print(((IEventTask) task).getEventType()); 144 out.print(" "); 145 out.print(((IEventTask) task).getEventTarget().getStringIdentifier()); 146 // if (((IEventTask) node).getEventTarget() instanceof IGUIElement) { 147 // out.print(" "); 148 // out.print(((IGUIElement) ((IEventTask) node).getEventTarget()).getSpecification()); 149 // } 147 out.print(task); 150 148 } 151 149 else { … … 154 152 155 153 int i = 0; 156 for (ITaskInstance child : taskInstance.getChildren()) { 157 encode(child, out, indent + " ", i++); 154 155 if (taskInstance instanceof ITaskInstanceList) { 156 for (ITaskInstance child : (ITaskInstanceList) taskInstance) { 157 encode(child, out, indent + " ", i++); 158 } 159 } 160 else if (taskInstance instanceof ISelectionInstance) { 161 encode(((ISelectionInstance) taskInstance).getChild(), out, indent + " ", i++); 162 } 163 else if (taskInstance instanceof IOptionalInstance) { 164 encode(((IOptionalInstance) taskInstance).getChild(), out, indent + " ", i++); 158 165 } 159 166 … … 221 228 } 222 229 else if (task instanceof IEventTask) { 223 if (((IEventTask) task).getEventType() instanceof TextInput) { 230 Event event = ((IEventTaskInstance) taskInstance).getEvent(); 231 if (event.getType() instanceof TextInput) { 224 232 if (id == null) { 225 233 id = "textInput" + typeCounters[3]++; … … 229 237 System.out.print(id); 230 238 System.out.print(" \""); 231 System.out.print(((TextInput) ((IEventTask) task).getEventType()).getEnteredText());239 System.out.print(((TextInput) event.getType()).getEnteredText()); 232 240 System.out.print("\""); 233 241 } … … 240 248 System.out.print(id); 241 249 System.out.print(' '); 242 System.out.print( ((IEventTask) task).getEventType().getName());250 System.out.print(event.getType().getName()); 243 251 } 244 252 System.out.print(" {}\" +"); … … 250 258 taskIds.put(task, id); 251 259 252 for (ITaskInstance child : taskInstance.getChildren()) { 253 dumpTaskInstanceAsCheckString(child, typeCounters, taskIds, indent + " "); 260 if (taskInstance instanceof ITaskInstanceList) { 261 for (ITaskInstance child : (ITaskInstanceList) taskInstance) { 262 dumpTaskInstanceAsCheckString(child, typeCounters, taskIds, indent + " "); 263 } 264 } 265 else if (taskInstance instanceof ISelectionInstance) { 266 dumpTaskInstanceAsCheckString 267 (((ISelectionInstance) taskInstance).getChild(), typeCounters, taskIds, indent + " "); 268 } 269 else if (taskInstance instanceof IOptionalInstance) { 270 dumpTaskInstanceAsCheckString 271 (((IOptionalInstance) taskInstance).getChild(), typeCounters, taskIds, indent + " "); 254 272 } 255 273 -
trunk/autoquest-test-utils/src/main/java/de/ugoe/cs/autoquest/tasktrees/TaskTreeValidator.java
r1146 r1294 20 20 21 21 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTask; 22 import de.ugoe.cs.autoquest.tasktrees.treeifc.IEventTaskInstance; 22 23 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIteration; 24 import de.ugoe.cs.autoquest.tasktrees.treeifc.IIterationInstance; 23 25 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptional; 26 import de.ugoe.cs.autoquest.tasktrees.treeifc.IOptionalInstance; 24 27 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelection; 28 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISelectionInstance; 25 29 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequence; 30 import de.ugoe.cs.autoquest.tasktrees.treeifc.ISequenceInstance; 26 31 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITask; 27 32 import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstance; … … 66 71 67 72 assertEquals("number of children of sequence instance must match sequence model", 68 taskInstance.size(), task.getChildren().size());73 ((ISequenceInstance) taskInstance).size(), task.getChildren().size()); 69 74 70 for (int i = 0; i < taskInstance.size(); i++) { 71 assertNotNull("sequence instance child " + i + " was null", taskInstance.get(i)); 72 ITask childTask = taskInstance.get(i).getTask(); 75 for (int i = 0; i < ((ISequenceInstance) taskInstance).size(); i++) { 76 assertNotNull("sequence instance child " + i + " was null", 77 ((ISequenceInstance) taskInstance).get(i)); 78 ITask childTask = ((ISequenceInstance) taskInstance).get(i).getTask(); 73 79 assertSame("task of sequence child " + i + " does not match sequence model", 74 80 childTask, task.getChildren().get(i)); … … 78 84 ISelection task = (ISelection) taskInstance.getTask(); 79 85 80 assert Equals81 ("number of children of selection instance must be 1", 1, taskInstance.size());86 assertNotNull("number of children of selection instance must be 1", 87 ((ISelectionInstance) taskInstance).getChild()); 82 88 assertTrue 83 89 ("number of children of selection must be larger 0", task.getChildren().size() > 0); … … 90 96 assertFalse("child of selection model must not be an optional", 91 97 childTask instanceof IOptional); 92 if (childTask.equals( taskInstance.get(0).getTask())) {98 if (childTask.equals(((ISelectionInstance) taskInstance).getChild().getTask())) { 93 99 found = true; 94 100 break; … … 107 113 childTask instanceof IOptional); 108 114 109 for (int i = 0; i < taskInstance.size(); i++) { 110 assertNotNull("iteration instance child " + i + " was null", taskInstance.get(i)); 115 for (int i = 0; i < ((IIterationInstance) taskInstance).size(); i++) { 116 assertNotNull("iteration instance child " + i + " was null", 117 ((IIterationInstance) taskInstance).get(i)); 111 118 assertSame("task of iteration child " + i + " does not match iteration model", 112 childTask, taskInstance.get(i).getTask());119 childTask, ((IIterationInstance) taskInstance).get(i).getTask()); 113 120 } 114 121 } … … 119 126 childTask instanceof IOptional); 120 127 121 assert Equals122 ("number of children of optional instance must be 1", 1, taskInstance.size());128 assertNotNull("number of children of optional instance must be 1", 129 ((IOptionalInstance) taskInstance).getChild()); 123 130 124 131 assertEquals("task of optional child does not match optional model", 125 childTask, taskInstance.get(0).getTask());132 childTask, ((IOptionalInstance) taskInstance).getChild().getTask()); 126 133 } 127 134 else if (taskInstance.getTask() instanceof IEventTask) { 128 135 IEventTask task = (IEventTask) taskInstance.getTask(); 129 136 assertNotNull("event task model must not be null", task); 130 assertNotNull("event type of event task model must not be null", task.getEventType()); 131 assertNotNull 132 ("event target of event task model must not be null", task.getEventTarget()); 133 134 assertEquals("event task instance must not have children", 0, taskInstance.size()); 137 assertNotNull("event of event task instance must not be null", 138 ((IEventTaskInstance) taskInstance).getEvent()); 135 139 } 136 140 else { … … 138 142 } 139 143 140 for (ITaskInstance child : taskInstance) { 141 validate(child); 144 if (taskInstance instanceof ITaskInstanceList) { 145 for (ITaskInstance child : (ITaskInstanceList) taskInstance) { 146 validate(child); 147 } 148 } 149 else if (taskInstance instanceof ISelectionInstance) { 150 validate(((ISelectionInstance) taskInstance).getChild()); 151 } 152 else if (taskInstance instanceof IOptionalInstance) { 153 validate(((IOptionalInstance) taskInstance).getChild()); 142 154 } 143 155 }
Note: See TracChangeset
for help on using the changeset viewer.