Search in sources :

Example 1 with TestItemReport

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;
}
Also used : TestFolderReport(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestFolderReport) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) LinkedHashMap(java.util.LinkedHashMap) Item(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.Item) TestItemReport(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestItemReport) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with TestItemReport

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;
}
Also used : TestItemReport(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestItemReport) TestExecReport(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestExecReport)

Example 3 with TestItemReport

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;
}
Also used : Item(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.Item) TestItemReport(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestItemReport) TestFolderReport(de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestFolderReport) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

TestItemReport (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestItemReport)3 Item (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.config.Item)2 TestFolderReport (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestFolderReport)2 LinkedHashMap (java.util.LinkedHashMap)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 TestExecReport (de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestExecReport)1 ArrayList (java.util.ArrayList)1