Search in sources :

Example 1 with DataTable

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;
}
Also used : DataTableCell(io.irontest.models.DataTableCell) DataTable(io.irontest.models.DataTable) DataTableColumn(io.irontest.models.DataTableColumn) ArrayList(java.util.ArrayList) CreateSqlObject(org.skife.jdbi.v2.sqlobject.CreateSqlObject) LinkedHashMap(java.util.LinkedHashMap) Transaction(org.skife.jdbi.v2.sqlobject.Transaction)

Example 2 with 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;
}
Also used : AssertionVerifier(io.irontest.core.assertion.AssertionVerifier) DataTable(io.irontest.models.DataTable) UserDefinedProperty(io.irontest.models.UserDefinedProperty) AssertionVerificationResult(io.irontest.models.assertion.AssertionVerificationResult) Assertion(io.irontest.models.assertion.Assertion) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) PermitAll(javax.annotation.security.PermitAll)

Example 3 with DataTable

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();
}
Also used : DataTable(io.irontest.models.DataTable) RegularTestcaseRunner(io.irontest.core.runner.RegularTestcaseRunner) UserDefinedProperty(io.irontest.models.UserDefinedProperty) Testcase(io.irontest.models.Testcase) TestcaseRunner(io.irontest.core.runner.TestcaseRunner) RegularTestcaseRunner(io.irontest.core.runner.RegularTestcaseRunner) DataDrivenTestcaseRunner(io.irontest.core.runner.DataDrivenTestcaseRunner) DataDrivenTestcaseRunner(io.irontest.core.runner.DataDrivenTestcaseRunner) PermitAll(javax.annotation.security.PermitAll)

Example 4 with DataTable

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;
}
Also used : DataTable(io.irontest.models.DataTable) UserDefinedProperty(io.irontest.models.UserDefinedProperty) HashMap(java.util.HashMap) Date(java.util.Date) Endpoint(io.irontest.models.endpoint.Endpoint) PermitAll(javax.annotation.security.PermitAll)

Aggregations

DataTable (io.irontest.models.DataTable)4 UserDefinedProperty (io.irontest.models.UserDefinedProperty)3 PermitAll (javax.annotation.security.PermitAll)3 AssertionVerifier (io.irontest.core.assertion.AssertionVerifier)1 DataDrivenTestcaseRunner (io.irontest.core.runner.DataDrivenTestcaseRunner)1 RegularTestcaseRunner (io.irontest.core.runner.RegularTestcaseRunner)1 TestcaseRunner (io.irontest.core.runner.TestcaseRunner)1 DataTableCell (io.irontest.models.DataTableCell)1 DataTableColumn (io.irontest.models.DataTableColumn)1 Testcase (io.irontest.models.Testcase)1 Assertion (io.irontest.models.assertion.Assertion)1 AssertionVerificationResult (io.irontest.models.assertion.AssertionVerificationResult)1 Endpoint (io.irontest.models.endpoint.Endpoint)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 CreateSqlObject (org.skife.jdbi.v2.sqlobject.CreateSqlObject)1