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

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