Search in sources :

Example 6 with Teststep

use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.

the class TestcaseDAO method findById_Complete_NoTransaction.

/**
 * User defined properties are not included.
 * @param id
 * @return
 */
public Testcase findById_Complete_NoTransaction(long id) {
    Testcase result = _findById(id);
    result.setFolderPath(getFolderPath(id));
    List<Teststep> teststeps = teststepDAO().findByTestcaseId(id);
    result.setTeststeps(teststeps);
    return result;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) Testcase(io.irontest.models.Testcase)

Example 7 with Teststep

use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.

the class DataDrivenTestcaseRunner method run.

@Override
public TestcaseRun run() throws JsonProcessingException {
    DataDrivenTestcaseRun testcaseRun = new DataDrivenTestcaseRun();
    Cloner cloner = new Cloner();
    preProcessingForIIBTestcase();
    startTestcaseRun(testcaseRun);
    for (int dataTableRowIndex = 0; dataTableRowIndex < dataTable.getRows().size(); dataTableRowIndex++) {
        LinkedHashMap<String, Object> dataTableRow = dataTable.getRows().get(dataTableRowIndex);
        TestcaseIndividualRun individualRun = new TestcaseIndividualRun();
        testcaseRun.getIndividualRuns().add(individualRun);
        // start test case individual run
        individualRun.setStartTime(new Date());
        LOGGER.info("Start individually running test case with data table row: " + individualRun.getCaption());
        individualRun.setResult(TestResult.PASSED);
        getTestcaseRunContext().setTestcaseIndividualRunStartTime(individualRun.getStartTime());
        if (isTestcaseHasWaitForProcessingCompletionAction()) {
            // milliseconds
            long secondFraction = individualRun.getStartTime().getTime() % 1000;
            long millisecondsUntilNextSecond = 1000 - secondFraction;
            Teststep waitStep = getTestcase().getTeststeps().get(0);
            waitStep.setName("Wait " + millisecondsUntilNextSecond + " milliseconds");
            waitStep.setOtherProperties(new WaitTeststepProperties(millisecondsUntilNextSecond));
        }
        getReferenceableStringProperties().put(IMPLICIT_PROPERTY_NAME_TEST_CASE_INDIVIDUAL_START_TIME, IMPLICIT_PROPERTY_DATE_TIME_FORMAT.format(individualRun.getStartTime()));
        individualRun.setCaption((String) dataTableRow.get(DataTableColumn.COLUMN_NAME_CAPTION));
        getReferenceableEndpointProperties().putAll(dataTable.getEndpointPropertiesInRow(dataTableRowIndex));
        getReferenceableStringProperties().putAll(dataTable.getStringPropertiesInRow(dataTableRowIndex));
        // run test steps
        for (Teststep teststep : getTestcase().getTeststeps()) {
            Teststep clonedTeststep = cloner.deepClone(teststep);
            individualRun.getStepRuns().add(runTeststep(clonedTeststep));
        }
        // test case individual run ends
        individualRun.setDuration(new Date().getTime() - individualRun.getStartTime().getTime());
        LOGGER.info("Finish individually running test case with data table row: " + individualRun.getCaption());
        for (TeststepRun teststepRun : individualRun.getStepRuns()) {
            if (TestResult.FAILED == teststepRun.getResult()) {
                individualRun.setResult(TestResult.FAILED);
                break;
            }
        }
    }
    // test case run ends
    testcaseRun.setDuration(new Date().getTime() - testcaseRun.getStartTime().getTime());
    LOGGER.info("Finish running test case: " + getTestcase().getName());
    for (TestcaseIndividualRun individualRun : testcaseRun.getIndividualRuns()) {
        if (TestResult.FAILED == individualRun.getResult()) {
            testcaseRun.setResult(TestResult.FAILED);
            break;
        }
    }
    // persist test case run details into database
    getTestcaseRunDAO().insert(testcaseRun);
    return testcaseRun;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) WaitTeststepProperties(io.irontest.models.teststep.WaitTeststepProperties) TeststepRun(io.irontest.models.testrun.TeststepRun) TestcaseIndividualRun(io.irontest.models.testrun.TestcaseIndividualRun) DataDrivenTestcaseRun(io.irontest.models.testrun.DataDrivenTestcaseRun) Date(java.util.Date) Cloner(com.rits.cloning.Cloner)

Example 8 with Teststep

use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.

the class TestcaseDAO method findById_TestcaseEditView.

@Transaction
public Testcase findById_TestcaseEditView(long id) {
    Testcase result = _findById(id);
    if (result != null) {
        List<Teststep> teststeps = teststepDAO().findByTestcaseId_TestcaseEditView(id);
        result.setTeststeps(teststeps);
    }
    return result;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) Testcase(io.irontest.models.Testcase)

Example 9 with Teststep

use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.

the class TestcaseDAO method duplicate.

/**
 * Clone the test case and its contents.
 * @param oldTestcaseId id of the test case to be cloned
 * @param targetFolderId id of the folder in which the new test case will be created
 * @return ID of the new test case
 */
@Transaction
public long duplicate(long oldTestcaseId, long targetFolderId) throws JsonProcessingException {
    Testcase oldTestcase = findById_Complete_NoTransaction(oldTestcaseId);
    // resolve new test case name
    String newTestcaseName = oldTestcase.getName();
    if (oldTestcase.getParentFolderId() == targetFolderId) {
        int copyIndex = 1;
        newTestcaseName = oldTestcase.getName() + " - Copy";
        while (_nameExistsInFolder(newTestcaseName, targetFolderId)) {
            copyIndex++;
            newTestcaseName = oldTestcase.getName() + " - Copy (" + copyIndex + ")";
        }
    }
    // duplicate the test case record
    Testcase newTestcase = new Testcase();
    newTestcase.setName(newTestcaseName);
    newTestcase.setDescription(oldTestcase.getDescription());
    newTestcase.setParentFolderId(targetFolderId);
    newTestcase = insert_NoTransaction(newTestcase);
    // duplicate user defined properties
    udpDAO().duplicateByTestcase(oldTestcaseId, newTestcase.getId());
    // duplicate test steps
    for (Teststep oldTeststep : oldTestcase.getTeststeps()) {
        Teststep newTeststep = new Teststep();
        newTeststep.setName(oldTeststep.getName());
        newTeststep.setTestcaseId(newTestcase.getId());
        newTeststep.setSequence(oldTeststep.getSequence());
        newTeststep.setType(oldTeststep.getType());
        newTeststep.setDescription(oldTeststep.getDescription());
        newTeststep.setAction(oldTeststep.getAction());
        if (oldTeststep.getRequestType() == TeststepRequestType.TEXT) {
            newTeststep.setRequest(oldTeststep.getRequest());
        } else {
            newTeststep.setRequest(teststepDAO().getBinaryRequestById(oldTeststep.getId()));
        }
        newTeststep.setRequestType(oldTeststep.getRequestType());
        newTeststep.setRequestFilename(oldTeststep.getRequestFilename());
        newTeststep.setOtherProperties(oldTeststep.getOtherProperties());
        Endpoint oldEndpoint = oldTeststep.getEndpoint();
        if (oldEndpoint != null) {
            Endpoint newEndpoint = new Endpoint();
            newTeststep.setEndpoint(newEndpoint);
            if (oldEndpoint.isManaged()) {
                newEndpoint.setId(oldEndpoint.getId());
            } else {
                newEndpoint.setName(oldEndpoint.getName());
                newEndpoint.setType(oldEndpoint.getType());
                newEndpoint.setDescription(oldEndpoint.getDescription());
                newEndpoint.setUrl(oldEndpoint.getUrl());
                newEndpoint.setUsername(oldEndpoint.getUsername());
                newEndpoint.setPassword(oldEndpoint.getPassword());
                newEndpoint.setOtherProperties(oldEndpoint.getOtherProperties());
            }
        }
        long newTeststepId = teststepDAO().insert_NoTransaction(newTeststep, null);
        // duplicate assertions
        for (Assertion oldAssertion : oldTeststep.getAssertions()) {
            Assertion newAssertion = new Assertion();
            newAssertion.setTeststepId(newTeststepId);
            newAssertion.setName(oldAssertion.getName());
            newAssertion.setType(oldAssertion.getType());
            newAssertion.setOtherProperties(oldAssertion.getOtherProperties());
            assertionDAO().insert_NoTransaction(newAssertion);
        }
    }
    return newTestcase.getId();
}
Also used : Teststep(io.irontest.models.teststep.Teststep) Testcase(io.irontest.models.Testcase) Endpoint(io.irontest.models.endpoint.Endpoint) Assertion(io.irontest.models.assertion.Assertion) Endpoint(io.irontest.models.endpoint.Endpoint)

Example 10 with Teststep

use of io.irontest.models.teststep.Teststep in project irontest by zheng-wang.

the class TeststepMapper method map.

public Teststep map(int index, ResultSet rs, StatementContext ctx) throws SQLException {
    List<String> fields = IronTestUtils.getFieldsPresentInResultSet(rs);
    Teststep teststep = null;
    String type = rs.getString("type");
    if (fields.contains("other_properties") && rs.getString("other_properties") != null) {
        String tempTeststepJSON = "{\"type\":\"" + type + "\",\"otherProperties\":" + rs.getString("other_properties") + "}";
        try {
            teststep = new ObjectMapper().readValue(tempTeststepJSON, Teststep.class);
        } catch (IOException e) {
            throw new SQLException("Failed to deserialize other_properties JSON.", e);
        }
    } else {
        teststep = new Teststep();
    }
    teststep.setId(rs.getLong("id"));
    teststep.setTestcaseId(rs.getLong("testcase_id"));
    teststep.setSequence(rs.getShort("sequence"));
    teststep.setName(rs.getString("name"));
    teststep.setType(type);
    teststep.setDescription(rs.getString("description"));
    teststep.setAction(fields.contains("action") ? rs.getString("action") : null);
    // this line must go before the 'if (fields.contains("request")) {' block
    teststep.setRequestType(fields.contains("request_type") ? TeststepRequestType.getByText(rs.getString("request_type")) : null);
    if (fields.contains("request")) {
        // no use of retrieving request file here
        Object request = teststep.getRequestType() == TeststepRequestType.FILE ? null : rs.getBytes("request") == null ? null : new String(rs.getBytes("request"));
        teststep.setRequest(request);
    }
    teststep.setRequestFilename(fields.contains("request_filename") ? rs.getString("request_filename") : null);
    if (fields.contains("endpoint_id")) {
        Endpoint endpoint = new Endpoint();
        endpoint.setId(rs.getLong("endpoint_id"));
        teststep.setEndpoint(endpoint);
    }
    teststep.setEndpointProperty(fields.contains("endpoint_property") ? rs.getString("endpoint_property") : null);
    return teststep;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) Endpoint(io.irontest.models.endpoint.Endpoint) SQLException(java.sql.SQLException) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

Teststep (io.irontest.models.teststep.Teststep)10 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Testcase (io.irontest.models.Testcase)3 Endpoint (io.irontest.models.endpoint.Endpoint)3 TeststepRun (io.irontest.models.testrun.TeststepRun)3 WaitTeststepProperties (io.irontest.models.teststep.WaitTeststepProperties)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Cloner (com.rits.cloning.Cloner)1 MapValueLookup (io.irontest.core.MapValueLookup)1 Assertion (io.irontest.models.assertion.Assertion)1 AssertionVerification (io.irontest.models.assertion.AssertionVerification)1 DataDrivenTestcaseRun (io.irontest.models.testrun.DataDrivenTestcaseRun)1 RegularTestcaseRun (io.irontest.models.testrun.RegularTestcaseRun)1 TestcaseIndividualRun (io.irontest.models.testrun.TestcaseIndividualRun)1 LinkedHashMap (java.util.LinkedHashMap)1 StrSubstitutor (org.apache.commons.text.StrSubstitutor)1