source: trunk/EventBenchConsole/src/de/ugoe/cs/eventbench/efg/GUITARTestCaseParser.java @ 414

Last change on this file since 414 was 227, checked in by sherbold, 13 years ago
  • extracted class de.ugoe.cs.eventbench.efg.EFGModelGenerator from de.ugoe.cs.eventbench.efg.commands.CMDefgToMM

+ added command efgToDFA

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