[1040] | 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.
|
---|
[1030] | 14 |
|
---|
| 15 | package de.ugoe.cs.autoquest.usability.testutil;
|
---|
| 16 |
|
---|
[1218] | 17 | import java.util.Arrays;
|
---|
[1165] | 18 | import java.util.List;
|
---|
[1030] | 19 | import java.util.logging.Level;
|
---|
| 20 |
|
---|
[1165] | 21 | import com.google.common.collect.Lists;
|
---|
| 22 |
|
---|
[1030] | 23 | import de.ugoe.cs.autoquest.commands.sequences.CMDcondenseGuiModel;
|
---|
| 24 | import de.ugoe.cs.autoquest.commands.sequences.CMDcondenseMouseClicks;
|
---|
| 25 | import de.ugoe.cs.autoquest.commands.sequences.CMDcorrectKeyInteractionTargets;
|
---|
| 26 | import de.ugoe.cs.autoquest.commands.sequences.CMDdetectTextInputEvents;
|
---|
| 27 | import de.ugoe.cs.autoquest.commands.sequences.CMDsortKeyInteractions;
|
---|
| 28 | import de.ugoe.cs.autoquest.commands.usability.CMDgenerateTaskTree;
|
---|
| 29 | import de.ugoe.cs.autoquest.plugin.jfc.commands.CMDparseJFC;
|
---|
[1152] | 30 | import de.ugoe.cs.autoquest.tasktrees.TaskTreeDecoder;
|
---|
[1165] | 31 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskFactory;
|
---|
| 32 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskInstanceList;
|
---|
| 33 | import de.ugoe.cs.autoquest.tasktrees.treeifc.ITaskModel;
|
---|
| 34 | import de.ugoe.cs.autoquest.tasktrees.treeifc.IUserSession;
|
---|
| 35 | import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskBuilder;
|
---|
| 36 | import de.ugoe.cs.autoquest.tasktrees.treeimpl.TaskFactory;
|
---|
[1030] | 37 | import de.ugoe.cs.autoquest.test.CommandRunner;
|
---|
[1326] | 38 | import de.ugoe.cs.util.console.Command;
|
---|
[1030] | 39 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
| 40 | import de.ugoe.cs.util.console.TextConsole;
|
---|
| 41 |
|
---|
[1040] | 42 | /**
|
---|
| 43 | * <p>
|
---|
| 44 | * TODO comment
|
---|
| 45 | * </p>
|
---|
| 46 | *
|
---|
| 47 | * @author Alexander Deicke
|
---|
| 48 | */
|
---|
[1165] | 49 | public class GenerateTaskModelUtil {
|
---|
[1040] | 50 |
|
---|
[1030] | 51 | private static final String seqName = "sequences";
|
---|
| 52 |
|
---|
| 53 | private static final String taskTreeName = "taskTree";
|
---|
[1141] | 54 |
|
---|
[1218] | 55 | public static ITaskModel getTaskModelFromSpec(String... userSessions) {
|
---|
[1165] | 56 | ITaskFactory factory = new TaskFactory();
|
---|
[1218] | 57 | TaskTreeDecoder taskTreeDecoder = new TaskTreeDecoder(factory, new TaskBuilder());
|
---|
| 58 | List<IUserSession> userSessionsList = Lists.newArrayList();
|
---|
| 59 | for(String userSession: Arrays.asList(userSessions)) {
|
---|
| 60 | ITaskInstanceList taskInstances = taskTreeDecoder.decode(userSession);
|
---|
| 61 | userSessionsList.add((IUserSession) taskInstances);
|
---|
| 62 | }
|
---|
| 63 | return factory.createTaskModel(userSessionsList);
|
---|
[1141] | 64 | }
|
---|
| 65 |
|
---|
[1165] | 66 | public static ITaskModel getTaskTreeFromFile(String filename) {
|
---|
[1326] | 67 | return getTaskTreeFromFile(filename, CMDparseJFC.class);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | public static ITaskModel getTaskTreeFromFile(String filename, Class<? extends Command> parserClass) {
|
---|
[1218] | 71 | new TextConsole(Level.ALL);
|
---|
[1326] | 72 | parseTraceFile(filename, parserClass);
|
---|
[1030] | 73 | condenseGuiModel();
|
---|
| 74 | sortKeyInteractions();
|
---|
| 75 | correctKeyInteractionTargets();
|
---|
| 76 | detectTextInputEvents();
|
---|
| 77 | condenseMouseClicks();
|
---|
[1165] | 78 | return generateTaskModel();
|
---|
[1030] | 79 | }
|
---|
| 80 |
|
---|
[1326] | 81 | static private void parseTraceFile(String filetoparse, Class<? extends Command> parserClass) {
|
---|
| 82 | CommandRunner.runCommand(parserClass, ClassLoader.getSystemResource(filetoparse)
|
---|
[1030] | 83 | .getFile(), seqName);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | private static void condenseGuiModel() {
|
---|
| 87 | CommandRunner.runCommand(CMDcondenseGuiModel.class, seqName);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | private static void sortKeyInteractions() {
|
---|
| 91 | CommandRunner.runCommand(CMDsortKeyInteractions.class, seqName);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
| 94 | private static void correctKeyInteractionTargets() {
|
---|
| 95 | CommandRunner.runCommand(CMDcorrectKeyInteractionTargets.class, seqName);
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | private static void detectTextInputEvents() {
|
---|
| 99 | CommandRunner.runCommand(CMDdetectTextInputEvents.class, seqName);
|
---|
| 100 | }
|
---|
| 101 |
|
---|
| 102 | private static void condenseMouseClicks() {
|
---|
| 103 | CommandRunner.runCommand(CMDcondenseMouseClicks.class, seqName);
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[1165] | 106 | private static ITaskModel generateTaskModel() {
|
---|
[1030] | 107 | CommandRunner.runCommand(CMDgenerateTaskTree.class, seqName, taskTreeName);
|
---|
| 108 | GlobalDataContainer dataContainer = GlobalDataContainer.getInstance();
|
---|
[1165] | 109 | return (ITaskModel) dataContainer.getData(taskTreeName);
|
---|
[1030] | 110 | }
|
---|
| 111 |
|
---|
| 112 | }
|
---|