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 |
|
---|
15 | package de.ugoe.cs.autoquest.usability.testutil;
|
---|
16 |
|
---|
17 | import java.util.Arrays;
|
---|
18 | import java.util.List;
|
---|
19 | import java.util.logging.Level;
|
---|
20 |
|
---|
21 | import com.google.common.collect.Lists;
|
---|
22 |
|
---|
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;
|
---|
30 | import de.ugoe.cs.autoquest.tasktrees.TaskTreeDecoder;
|
---|
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;
|
---|
37 | import de.ugoe.cs.autoquest.test.CommandRunner;
|
---|
38 | import de.ugoe.cs.util.console.Command;
|
---|
39 | import de.ugoe.cs.util.console.GlobalDataContainer;
|
---|
40 | import de.ugoe.cs.util.console.TextConsole;
|
---|
41 |
|
---|
42 | /**
|
---|
43 | * <p>
|
---|
44 | * TODO comment
|
---|
45 | * </p>
|
---|
46 | *
|
---|
47 | * @author Alexander Deicke
|
---|
48 | */
|
---|
49 | public class GenerateTaskModelUtil {
|
---|
50 |
|
---|
51 | private static final String seqName = "sequences";
|
---|
52 |
|
---|
53 | private static final String taskTreeName = "taskTree";
|
---|
54 |
|
---|
55 | public static ITaskModel getTaskModelFromSpec(String... userSessions) {
|
---|
56 | ITaskFactory factory = new TaskFactory();
|
---|
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);
|
---|
64 | }
|
---|
65 |
|
---|
66 | public static ITaskModel getTaskTreeFromFile(String filename) {
|
---|
67 | return getTaskTreeFromFile(filename, CMDparseJFC.class);
|
---|
68 | }
|
---|
69 |
|
---|
70 | public static ITaskModel getTaskTreeFromFile(String filename, Class<? extends Command> parserClass) {
|
---|
71 | new TextConsole(Level.ALL);
|
---|
72 | parseTraceFile(filename, parserClass);
|
---|
73 | condenseGuiModel();
|
---|
74 | sortKeyInteractions();
|
---|
75 | correctKeyInteractionTargets();
|
---|
76 | detectTextInputEvents();
|
---|
77 | condenseMouseClicks();
|
---|
78 | return generateTaskModel();
|
---|
79 | }
|
---|
80 |
|
---|
81 | static private void parseTraceFile(String filetoparse, Class<? extends Command> parserClass) {
|
---|
82 | CommandRunner.runCommand(parserClass, ClassLoader.getSystemResource(filetoparse)
|
---|
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 |
|
---|
106 | private static ITaskModel generateTaskModel() {
|
---|
107 | CommandRunner.runCommand(CMDgenerateTaskTree.class, seqName, taskTreeName);
|
---|
108 | GlobalDataContainer dataContainer = GlobalDataContainer.getInstance();
|
---|
109 | return (ITaskModel) dataContainer.getData(taskTreeName);
|
---|
110 | }
|
---|
111 |
|
---|
112 | }
|
---|