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()) {
Value v = factory.createValue();
v.setName(var.getName());
v.setVariable(var);
if (var.isIsParameter()) {
Double value = null;
try {
value = ampl.getParameter(var.getName());
} catch (IOException e) {
e.printStackTrace();
continue;
}
v.setValue(value);
switch (var.getUsage()) {
case IN_PARAMETER:
func.getParameters().add(v);
break;
case OUT_PARAMETER:
tc.getTestForValue().add(v);
break;
case INOUT_PARAMETER:
// XXX INOUT parameters currently can not be handled
// since there is only one value. For in/out
// Parameters a pre and a post Value would be
// necessary.
// func.getParameters().add(v); //@pre
// tc.getTestForValue().add(v); //post
break;
case RETURN_PARAMETER:
tc.getTestForValue().add(v);
break;
default:
break;
}
} else {
List<Double> trace = null;
try {
trace = ampl.getVariable(var.getName());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
continue;
}