use of io.irontest.models.UserDefinedProperty in project irontest by zheng-wang.
the class AssertionResource method verify.
/**
* This is a stateless operation, i.e. not persisting anything in database.
* @param assertionVerificationRequest
* @return
*/
@POST
@Path("assertions/{assertionId}/verify")
@PermitAll
public AssertionVerificationResult verify(AssertionVerificationRequest assertionVerificationRequest) {
Assertion assertion = assertionVerificationRequest.getAssertion();
// gather referenceable string properties
List<UserDefinedProperty> testcaseUDPs = udpDAO.findTestcaseUDPsByTeststepId(assertion.getTeststepId());
Map<String, String> referenceableStringProperties = IronTestUtils.udpListToMap(testcaseUDPs);
DataTable dataTable = utilsDAO.getTestcaseDataTable(teststepDAO.findTestcaseIdById(assertion.getTeststepId()), true);
if (dataTable.getRows().size() == 1) {
referenceableStringProperties.putAll(dataTable.getStringPropertiesInRow(0));
}
AssertionVerifier assertionVerifier = AssertionVerifierFactory.getInstance().create(assertion.getType(), referenceableStringProperties);
AssertionVerificationResult result;
try {
result = assertionVerifier.verify(assertion, assertionVerificationRequest.getInput());
} catch (Exception e) {
LOGGER.error("Failed to verify assertion", e);
result = new AssertionVerificationResult();
result.setResult(TestResult.FAILED);
result.setError(e.getMessage());
}
return result;
}
use of io.irontest.models.UserDefinedProperty in project irontest by zheng-wang.
the class TestcaseRunResource method create.
@POST
@Path("testcaseruns")
@PermitAll
public TestcaseRun create(@QueryParam("testcaseId") long testcaseId) throws JsonProcessingException {
Testcase testcase = testcaseDAO.findById_Complete(testcaseId);
List<UserDefinedProperty> testcaseUDPs = udpDAO.findByTestcaseId(testcaseId);
DataTable dataTable = utilsDAO.getTestcaseDataTable(testcaseId, false);
TestcaseRunner testcaseRunner;
if (dataTable.getRows().isEmpty()) {
testcaseRunner = new RegularTestcaseRunner(testcase, testcaseUDPs, teststepDAO, utilsDAO, testcaseRunDAO);
} else {
testcaseRunner = new DataDrivenTestcaseRunner(testcase, testcaseUDPs, dataTable, teststepDAO, utilsDAO, testcaseRunDAO);
}
return testcaseRunner.run();
}
use of io.irontest.models.UserDefinedProperty in project irontest by zheng-wang.
the class TeststepResource method run.
/**
* Run a test step individually (not as part of test case running).
* This is a stateless operation, i.e. not persisting anything in database.
* @param teststep
* @return
*/
@POST
@Path("{teststepId}/run")
@PermitAll
public BasicTeststepRun run(Teststep teststep) throws Exception {
// workaround for Chrome's 'Failed to load response data' problem (still exist in Chrome 65)
Thread.sleep(100);
// gather referenceable string properties and endpoint properties
List<UserDefinedProperty> testcaseUDPs = udpDAO.findByTestcaseId(teststep.getTestcaseId());
Map<String, String> referenceableStringProperties = IronTestUtils.udpListToMap(testcaseUDPs);
referenceableStringProperties.put(IMPLICIT_PROPERTY_NAME_TEST_STEP_START_TIME, IMPLICIT_PROPERTY_DATE_TIME_FORMAT.format(new Date()));
Map<String, Endpoint> referenceableEndpointProperties = new HashMap<>();
DataTable dataTable = utilsDAO.getTestcaseDataTable(teststep.getTestcaseId(), true);
if (dataTable.getRows().size() == 1) {
referenceableStringProperties.putAll(dataTable.getStringPropertiesInRow(0));
referenceableEndpointProperties.putAll(dataTable.getEndpointPropertiesInRow(0));
}
// run the test step
TeststepRunner teststepRunner = TeststepRunnerFactory.getInstance().newTeststepRunner(teststep, teststepDAO, utilsDAO, referenceableStringProperties, referenceableEndpointProperties, null);
BasicTeststepRun basicTeststepRun = teststepRunner.run();
// for better display in browser, transform XML response to be pretty-printed
if (Teststep.TYPE_SOAP.equals(teststep.getType())) {
SOAPAPIResponse soapAPIResponse = (SOAPAPIResponse) basicTeststepRun.getResponse();
soapAPIResponse.setHttpBody(XMLUtils.prettyPrintXML(soapAPIResponse.getHttpBody()));
} else if (Teststep.TYPE_MQ.equals(teststep.getType()) && Teststep.ACTION_DEQUEUE.equals(teststep.getAction())) {
MQAPIResponse mqAPIResponse = (MQAPIResponse) basicTeststepRun.getResponse();
mqAPIResponse.setValue(XMLUtils.prettyPrintXML((String) mqAPIResponse.getValue()));
}
return basicTeststepRun;
}
Aggregations