1 | package de.ugoe.cs.eventbench.efg.commands;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.security.InvalidParameterException;
|
---|
5 | import java.util.Collection;
|
---|
6 | import java.util.LinkedList;
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.eventbench.data.Event;
|
---|
10 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
11 | import de.ugoe.cs.eventbench.efg.data.EFGEvent;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 | import edu.umd.cs.guitar.model.IO;
|
---|
15 | import edu.umd.cs.guitar.model.data.StepType;
|
---|
16 | import edu.umd.cs.guitar.model.data.TestCase;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * <p>
|
---|
20 | * Command to load a set of sequences from a set of GUITAR test cases.
|
---|
21 | * </p>
|
---|
22 | *
|
---|
23 | * @author Steffen Herbold
|
---|
24 | * @version 1.0
|
---|
25 | */
|
---|
26 | public class CMDefgTestCasesToSequences implements Command {
|
---|
27 |
|
---|
28 | /*
|
---|
29 | * (non-Javadoc)
|
---|
30 | *
|
---|
31 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
32 | */
|
---|
33 | @Override
|
---|
34 | public void run(List<Object> parameters) {
|
---|
35 | String foldername;
|
---|
36 | String sequencesName = "sequences";
|
---|
37 | try {
|
---|
38 | foldername = (String) parameters.get(0);
|
---|
39 | if (parameters.size() >= 2) {
|
---|
40 | sequencesName = (String) parameters.get(1);
|
---|
41 | }
|
---|
42 | } catch (Exception e) {
|
---|
43 | throw new InvalidParameterException();
|
---|
44 | }
|
---|
45 |
|
---|
46 | File folder = new File(foldername);
|
---|
47 | // TODO would be more robust with filter
|
---|
48 | File[] testcaseFiles = folder.listFiles();
|
---|
49 | Collection<List<Event<?>>> sequences = new LinkedList<List<Event<?>>>();
|
---|
50 | for (File testcaseFile : testcaseFiles) {
|
---|
51 | Console.traceln("Loading from file "
|
---|
52 | + testcaseFile.getAbsolutePath());
|
---|
53 | TestCase testcase = (TestCase) IO.readObjFromFile(
|
---|
54 | testcaseFile.getAbsolutePath(), TestCase.class);
|
---|
55 | List<StepType> steps = testcase.getStep();
|
---|
56 | List<Event<?>> sequence = new LinkedList<Event<?>>();
|
---|
57 | for (StepType step : steps) {
|
---|
58 | step.getEventId();
|
---|
59 | sequence.add(new EFGEvent(step.getEventId()));
|
---|
60 | /*
|
---|
61 | * Problem: widgetId unknown! Therefore, the events will not be
|
---|
62 | * equal to those in the generated from a EFG.
|
---|
63 | */
|
---|
64 | }
|
---|
65 | sequences.add(sequence);
|
---|
66 | }
|
---|
67 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
68 | Console.traceln("Old data \"" + sequencesName + "\" overwritten");
|
---|
69 | }
|
---|
70 |
|
---|
71 | }
|
---|
72 |
|
---|
73 | /*
|
---|
74 | * (non-Javadoc)
|
---|
75 | *
|
---|
76 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
77 | */
|
---|
78 | @Override
|
---|
79 | public void help() {
|
---|
80 | Console.println("Usage: efgTestCasesToSequences <folder> {<sequencesName>}");
|
---|
81 | }
|
---|
82 |
|
---|
83 | }
|
---|