source: trunk/autoquest-plugin-guitar/src/main/java/de/ugoe/cs/autoquest/plugin/guitar/GUITARTestCaseParser.java @ 922

Last change on this file since 922 was 922, checked in by sherbold, 12 years ago
  • renaming of packages from de.ugoe.cs.quest to de.ugoe.cs.autoquest
  • Property svn:mime-type set to text/plain
File size: 3.0 KB
Line 
1package de.ugoe.cs.autoquest.plugin.guitar;
2
3import java.io.File;
4import java.util.LinkedList;
5import java.util.List;
6
7import de.ugoe.cs.autoquest.eventcore.Event;
8import de.ugoe.cs.autoquest.plugin.guitar.eventcore.GUITAREventTarget;
9import de.ugoe.cs.autoquest.plugin.guitar.eventcore.GUITAREventType;
10import de.ugoe.cs.autoquest.plugin.guitar.eventcore.GUITARReplayable;
11import edu.umd.cs.guitar.model.IO;
12import edu.umd.cs.guitar.model.data.EFG;
13import edu.umd.cs.guitar.model.data.EventType;
14import edu.umd.cs.guitar.model.data.StepType;
15import edu.umd.cs.guitar.model.data.TestCase;
16
17/**
18 * <p>
19 * Parser for GUITAR test case files.
20 * </p>
21 *
22 * @author Steffen Herbold
23 * @version 1.0
24 */
25public class GUITARTestCaseParser {
26
27        /**
28         * <p>
29         * Name of the EFG file for the application the test cases that are parsed
30         * are generated for.
31         * </p>
32         */
33        private String efgFileName = null;
34
35        /**
36         * <p>
37         * Internal handle to the parsed EFG.
38         * </p>
39         */
40        private EFG efg = null;
41
42        /**
43         * <p>
44         * Constructor. Creates a new GUITARTestCaseParser. No EFG file is
45         * associated with this parser.
46         * </p>
47         */
48        public GUITARTestCaseParser() {
49
50        }
51
52        /**
53         * <p>
54         * Constructor. Creates a new GUITARTestCaseParser.
55         * </p>
56         *
57         * @param efgFileName
58         *            EFG file associated with the test cases that are parsed.
59         */
60        public GUITARTestCaseParser(String efgFileName) {
61                this.efgFileName = efgFileName;
62        }
63
64        /**
65         * <p>
66         * Parses a GUITAR test case file and returns its contents as an event
67         * sequence.
68         * </p>
69         *
70         * @param testcaseFile
71         *            file that is parsed
72         * @return event sequence describing the test case
73         */
74        public List<Event> parseTestCaseFile(File testcaseFile) {
75                TestCase testcase = (TestCase) IO.readObjFromFile(
76                                testcaseFile.getAbsolutePath(), TestCase.class);
77                List<StepType> steps = testcase.getStep();
78                List<Event> sequence = new LinkedList<Event>();
79                for (StepType step : steps) {
80                        String eventId = step.getEventId();
81                        GUITAREventType type = new GUITAREventType(eventId);
82                        GUITAREventTarget target = new GUITAREventTarget(getWidgetId(eventId));
83                        Event event = new Event(type, target);
84                        event.addReplayable(new GUITARReplayable(eventId));
85                        sequence.add(event);
86                }
87                return sequence;
88        }
89
90        /**
91         * <p>
92         * If {@link #efgFileName} is specified, this function retrieves the
93         * widgetId of the widget the event with id eventId belongs to from the EFG.
94         * </p>
95         *
96         * @param eventId
97         * @return widgetId of the associated widget; null if {@link #efgFileName}
98         *         ==null or no widgetId for the event is found in the EFG
99         */
100        private String getWidgetId(String eventId) {
101                if (eventId != null && efgFileName != null) {
102                        if (efg == null) {
103                                efg = (EFG) IO.readObjFromFile(efgFileName, EFG.class);
104                        }
105                        for (EventType event : efg.getEvents().getEvent()) {
106                                if (eventId.equals(event.getEventId())) {
107                                        return event.getWidgetId();
108                                }
109                        }
110                }
111                return null;
112        }
113}
Note: See TracBrowser for help on using the repository browser.