public class TestsGeneratorHelper {
public static TestSuite generateTests(TCGActivity tcgActivity,
Collection<Path> paths) {
TestsFactory factory = TestsFactory.eINSTANCE;
TestSuite result = factory.createTestSuite();
SUT sut = factory.createSUT();
sut.setName(tcgActivity.getClassName());
sut.setPackageName(tcgActivity.getPackageName());
result.getSut().add(sut);
JAMPL ampl = AmplFactory.createJAMPL();
String solver = null;
// Transform Model to AMPL
String amplModel = ActTCG2AMPLModel.transform(tcgActivity);
ampl.getCli().sendCommand(amplModel);
// Create one Testcase per Path
for (Path p : paths) {
// Generate AMPL Data for each Path
String data = Path2AMPLData.transform(p);
ampl.loadData(data);
if (solver == null) {
InputDialog d = new InputDialog(null, "W�hlen sie den Solver",
"Welchen Solver m�chten sie verwenden", "couenne", null);
d.create();
d.open();
solver = d.getValue();
ampl.setSolver(solver);
}
// Solve the Model and Data to get Input data
SolveResult solved;
try {
solved = ampl.solve();
} catch (IOException e) {
ampl = AmplFactory.createJAMPL();
ampl.setSolver(solver);
ampl.loadModel(ActTCG2AMPLModel.transform(tcgActivity));
System.out.println("RESET!!!");
ampl.loadData(Path2AMPLData.transform(p));
try {
solved = ampl.solve();
} catch (IOException e1) {
e1.printStackTrace();
break;
}
}
// Read Values from Solver and store in Model
if (solved == SolveResult.Solved) {
TestCase tc = factory.createTestCase();
result.getTests().add(tc);
FunctionCall func = factory.createFunctionCall();
func.setName(tcgActivity.getName());
func.setActivity(tcgActivity);
tc.setFunction(func);
for (TCGVariable var : tcgActivity.getVariables()) {