use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestItemReport in project IPK-BrAPI-Validator by plantbreeding.
the class TestFolderRunner method runTestsFromCall.
public TestFolderReport runTestsFromCall(List<String> doneTests) {
TestFolderReport tcr = new TestFolderReport(this.baseUrl);
tcr.setName(this.folder.getName());
tcr.setDescription(this.folder.getDescription());
List<String> inCalls = new ArrayList<String>();
JsonNode calls = storage.getVariable("callResult");
if (calls != null && calls.isArray()) {
ObjectMapper mapper = new ObjectMapper();
for (JsonNode call : calls) {
inCalls.add("/" + mapper.convertValue(call.get("call"), String.class));
}
}
LinkedHashMap<String, Object> folderTests = new LinkedHashMap<String, Object>();
List<Item> itemList = this.folder.getItem();
itemList.forEach(item -> {
if (inCalls.contains(item.getEndpoint())) {
if (storage.getKeys().containsAll(item.getRequires())) {
TestItemRunner tir = new TestItemRunner(item, storage);
TestItemReport tiReport = tir.runTests();
tcr.addTestReport(tiReport);
doneTests.add(item.getName());
folderTests.put(item.getName(), tiReport);
} else {
folderTests.put(item.getName(), "missingReqs");
}
} else {
folderTests.put(item.getName(), "skipped");
}
});
tcr.setTestsShort(folderTests);
return tcr;
}
use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestItemReport in project IPK-BrAPI-Validator by plantbreeding.
the class TestItemRunner method runTests.
/**
* Run the tests
*
* @return Report
*/
public TestItemReport runTests() {
this.vr = connect();
// TODO: Only first event in Item.event is executed.
List<String> execList = this.item.getEvent().get(0).getExec();
TestItemReport tir = new TestItemReport(this.item.getName(), this.url, this.method);
if (this.vr == null) {
TestExecReport ter1 = new TestExecReport("Can't connect to tested server or missing parameters. Test cancelled.", false);
ter1.setType("can't connect");
ter1.addMessage("Can't connect to tested server or missing parameters. Test cancelled.");
tir.addTest(ter1);
tir.addTestStatus(ter1.getType());
return tir;
}
for (int i = 0; i < execList.size(); i++) {
String exec = execList.get(i);
String[] execSplit = exec.split(":");
TestExecReport ter = new TestExecReport("Invalid exec command", false);
if (execSplit.length >= 1) {
boolean breakIfFalse = false;
if (execSplit.length > 2 && execSplit[execSplit.length - 1].equals("breakiffalse")) {
breakIfFalse = true;
}
switch(execSplit[0]) {
case "StatusCode":
ter = statusCode(Integer.parseInt(execSplit[1]));
break;
case "ContentType":
ter = contentType(execSplit[1]);
break;
case "Schema":
ter = schemaMatch("/schemas" + execSplit[1] + ".json");
break;
case "GetValue":
if (execSplit.length < 3) {
ter.addMessage("Missing parameters");
break;
}
ter = saveVariable(execSplit[1], execSplit[2]);
break;
case "IsEqual":
if (execSplit.length < 3) {
ter.addMessage("Missing parameters");
}
ter = isEqual(execSplit[1], execSplit[2]);
break;
case "SaveCalls":
ter = saveCalls();
break;
}
if (ter != null && !ter.isPassed() && breakIfFalse) {
String msg = "Test failed. Won't continue testing this resource.";
LOGGER.info(msg);
ter.addMessage(msg);
tir.addTest(ter);
tir.addTestStatus(ter.getType());
break;
}
if (ter != null) {
tir.addTest(ter);
if (!ter.isPassed()) {
tir.addTestStatus(ter.getType());
}
}
}
}
tir.setResponseTime(this.vr.extract().time());
tir.setCached(this.cached);
return tir;
}
use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestItemReport in project IPK-BrAPI-Validator by plantbreeding.
the class TestFolderRunner method runTests.
/**
* Runs the tests specified in the Folder config
* @param doneTests
*
* @return Test report.
*/
public TestFolderReport runTests(List<String> doneTests) {
TestFolderReport tcr = new TestFolderReport(this.baseUrl);
tcr.setName(this.folder.getName());
tcr.setDescription(this.folder.getDescription());
List<Item> itemList = this.folder.getItem();
LinkedHashMap<String, Object> folderTests = new LinkedHashMap<String, Object>();
itemList.forEach(item -> {
TestItemRunner tir = new TestItemRunner(item, storage);
TestItemReport tiReport = tir.runTests();
tcr.addTestReport(tiReport);
doneTests.add(item.getName());
folderTests.put(item.getName(), tiReport);
});
tcr.setTestsShort(folderTests);
return tcr;
}
Aggregations