use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestExecReport in project IPK-BrAPI-Validator by plantbreeding.
the class TestItemRunner method saveVariable.
/**
* Save a element from the query to a variable in VariableStorage.
*
* @param path JsonNode path to the variable.
* @param variableName Key to store the variable.
* @return TestItemReport
*/
private TestExecReport saveVariable(String path, String variableName) {
LOGGER.info("Store variable: " + variableName + " | " + path);
String json = this.vr.extract().asString();
ObjectMapper mapper = new ObjectMapper();
TestExecReport ter = new TestExecReport("Save variable at: " + path + " | Key: " + variableName, false);
ter.setType("error storing variable");
try {
JsonNode root = mapper.readTree(json);
JsonNode value = root.at(path);
if (value.asText().equals("") || value.isNull()) {
throw new IllegalArgumentException("Value is empty string, null, or was not found.");
}
this.variables.setVariable(variableName, value);
ter.setPassed(true);
ter.addMessage("Stored value: " + value);
return ter;
} catch (IOException | IllegalArgumentException e) {
ter.addMessage(e.getMessage());
return ter;
}
}
use of de.ipk_gatersleben.bit.bi.bridge.brapicomp.testing.reports.TestExecReport in project IPK-BrAPI-Validator by plantbreeding.
the class TestItemRunner method schemaMatch.
/**
* Check if response matches schema
*
* @param p Path to the schema to be tested
* @return TestItemReport
*/
private TestExecReport schemaMatch(String p) {
LOGGER.info("Testing Schema");
TestExecReport tr = new TestExecReport("Json matches schema: " + p, false);
tr.setType("schema mismatch");
tr.setSchema(p);
try {
String jsonString = vr.extract().response().asString();
SchemaValidator schemaValidator = new SchemaValidator();
ProcessingReport r = schemaValidator.validate(p, jsonString);
if (r.isSuccess()) {
LOGGER.info("Schema Test Passed");
tr.addMessage("Response structure matches schema.");
tr.setPassed(true);
} else {
LOGGER.info("Schema Test Failed");
tr.addMessage("Response structure doesn't match schema.");
r.forEach(message -> tr.addError(message.asJson()));
}
return tr;
} catch (ConnectionClosedException | JsonParseException e1) {
LOGGER.info("Invalid response");
LOGGER.info("== cause ==");
LOGGER.info(e1.getMessage());
tr.addMessage("Server response is not valid JSON.");
return tr;
} catch (AssertionError | IOException | ProcessingException e1) {
LOGGER.info("Doesn't match schema");
LOGGER.info("== cause ==");
LOGGER.info(e1.getMessage());
tr.addMessage(e1.getMessage());
return tr;
}
}
Aggregations