use of io.irontest.models.DataTable in project irontest by zheng-wang.
the class UtilsDAO method getTestcaseDataTable.
/**
* @param testcaseId
* @param fetchFirstRowOnly if true, only the first data table row (if exists) will be fetched; if false, all rows will be fetched.
* @return
*/
@Transaction
public DataTable getTestcaseDataTable(long testcaseId, boolean fetchFirstRowOnly) {
DataTable dataTable = new DataTable();
List<DataTableColumn> columns = dataTableColumnDAO().findByTestcaseId(testcaseId);
// populate the data table rows Java model column by column
List<LinkedHashMap<String, Object>> rows = new ArrayList<>();
for (DataTableColumn column : columns) {
List<DataTableCell> columnCells = dataTableCellDAO().findByColumnId(column.getId());
for (DataTableCell columnCell : columnCells) {
short rowSequence = columnCell.getRowSequence();
if (rows.size() < rowSequence) {
rows.add(new LinkedHashMap<String, Object>());
}
Object cellObject;
if (columnCell.getValue() != null) {
cellObject = columnCell.getValue();
} else {
cellObject = endpointDAO().findById(columnCell.getEndpointId());
}
rows.get(rowSequence - 1).put(column.getName(), cellObject);
if (fetchFirstRowOnly && rows.size() == 1) {
break;
}
}
}
if (columns.size() > 0) {
dataTable = new DataTable();
dataTable.setColumns(columns);
dataTable.setRows(rows);
}
return dataTable;
}
use of io.irontest.models.DataTable 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.DataTable 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.DataTable 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