Search in sources :

Example 1 with Teststep

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

the class RegularTestcaseRunner method run.

@Override
public TestcaseRun run() throws JsonProcessingException {
    RegularTestcaseRun testcaseRun = new RegularTestcaseRun();
    preProcessingForIIBTestcase();
    startTestcaseRun(testcaseRun);
    if (isTestcaseHasWaitForProcessingCompletionAction()) {
        // milliseconds
        long secondFraction = getTestcaseRunContext().getTestcaseRunStartTime().getTime() % 1000;
        long millisecondsUntilNextSecond = 1000 - secondFraction;
        Teststep waitStep = getTestcase().getTeststeps().get(0);
        waitStep.setName("Wait " + millisecondsUntilNextSecond + " milliseconds");
        waitStep.setOtherProperties(new WaitTeststepProperties(millisecondsUntilNextSecond));
    }
    // run test steps
    for (Teststep teststep : getTestcase().getTeststeps()) {
        testcaseRun.getStepRuns().add(runTeststep(teststep));
    }
    // test case run ends
    testcaseRun.setDuration(new Date().getTime() - testcaseRun.getStartTime().getTime());
    LOGGER.info("Finish running test case: " + getTestcase().getName());
    for (TeststepRun teststepRun : testcaseRun.getStepRuns()) {
        if (TestResult.FAILED == teststepRun.getResult()) {
            testcaseRun.setResult(TestResult.FAILED);
            break;
        }
    }
    // persist test case run details into database
    getTestcaseRunDAO().insert(testcaseRun);
    // prepare return object for UI (reduced contents for performance)
    List<TeststepRun> teststepRunsForUI = new ArrayList<>();
    for (TeststepRun stepRun : testcaseRun.getStepRuns()) {
        TeststepRun teststepRunForUI = new TeststepRun();
        teststepRunForUI.setId(stepRun.getId());
        teststepRunForUI.setResult(stepRun.getResult());
        Teststep teststepForUI = new Teststep();
        teststepForUI.setId(stepRun.getTeststep().getId());
        teststepRunForUI.setTeststep(teststepForUI);
        teststepRunsForUI.add(teststepRunForUI);
    }
    RegularTestcaseRun testcaseRunForUI = new RegularTestcaseRun();
    testcaseRunForUI.setId(testcaseRun.getId());
    testcaseRunForUI.setResult(testcaseRun.getResult());
    testcaseRunForUI.setStepRuns(teststepRunsForUI);
    return testcaseRunForUI;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) WaitTeststepProperties(io.irontest.models.teststep.WaitTeststepProperties) TeststepRun(io.irontest.models.testrun.TeststepRun) ArrayList(java.util.ArrayList) RegularTestcaseRun(io.irontest.models.testrun.RegularTestcaseRun) Date(java.util.Date)

Example 2 with Teststep

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

the class TestcaseRunner method preProcessingForIIBTestcase.

protected void preProcessingForIIBTestcase() {
    for (Teststep teststep : testcase.getTeststeps()) {
        if (Teststep.TYPE_IIB.equals(teststep.getType()) && Teststep.ACTION_WAIT_FOR_PROCESSING_COMPLETION.equals(teststep.getAction())) {
            testcaseHasWaitForProcessingCompletionAction = true;
        }
    }
    if (testcaseHasWaitForProcessingCompletionAction) {
        Teststep waitStep = new Teststep();
        waitStep.setType(Teststep.TYPE_WAIT);
        testcase.getTeststeps().add(0, waitStep);
    }
}
Also used : Teststep(io.irontest.models.teststep.Teststep)

Example 3 with Teststep

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

the class TeststepRunner method resolveReferenceableStringProperties.

/**
 * Resolve as many string property references as possible. For unresolved references, throw exception in the end.
 * @throws IOException
 */
private void resolveReferenceableStringProperties() throws IOException {
    List<String> undefinedStringProperties = new ArrayList<String>();
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_CONTROL_CHARS, true);
    // resolve property references in teststep.otherProperties
    String otherPropertiesJSON = objectMapper.writeValueAsString(teststep.getOtherProperties());
    MapValueLookup propertyReferenceResolver = new MapValueLookup(referenceableStringProperties, true);
    String resolvedOtherPropertiesJSON = new StrSubstitutor(propertyReferenceResolver).replace(otherPropertiesJSON);
    undefinedStringProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
    String tempStepJSON = "{\"type\":\"" + teststep.getType() + "\",\"otherProperties\":" + resolvedOtherPropertiesJSON + "}";
    Teststep tempStep = objectMapper.readValue(tempStepJSON, Teststep.class);
    teststep.setOtherProperties(tempStep.getOtherProperties());
    // resolve property references in teststep.request (text type)
    if (teststep.getRequestType() == TeststepRequestType.TEXT) {
        propertyReferenceResolver = new MapValueLookup(referenceableStringProperties, false);
        teststep.setRequest(new StrSubstitutor(propertyReferenceResolver).replace((String) teststep.getRequest()));
        undefinedStringProperties.addAll(propertyReferenceResolver.getUnfoundKeys());
    }
    if (!undefinedStringProperties.isEmpty()) {
        throw new RuntimeException("String properties " + undefinedStringProperties + " not defined.");
    }
}
Also used : Teststep(io.irontest.models.teststep.Teststep) StrSubstitutor(org.apache.commons.text.StrSubstitutor) MapValueLookup(io.irontest.core.MapValueLookup) ArrayList(java.util.ArrayList) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 4 with Teststep

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

the class TeststepRunDAO method insert_NoTransaction.

public void insert_NoTransaction(long testcaseRunId, Long testcaseIndividualRunId, TeststepRun teststepRun) throws JsonProcessingException {
    // remove contents that are not to be serialized into the teststep column
    Teststep teststep = teststepRun.getTeststep();
    teststep.getAssertions().clear();
    Endpoint endpoint = teststep.getEndpoint();
    if (endpoint != null) {
        endpoint.setPassword(null);
    }
    ObjectMapper objectMapper = new ObjectMapper();
    long id = _insert(testcaseRunId, testcaseIndividualRunId, objectMapper.writeValueAsString(teststep), objectMapper.writeValueAsString(teststepRun.getResponse()), teststepRun.getInfoMessage(), teststepRun.getErrorMessage(), objectMapper.writeValueAsString(teststepRun.getAssertionVerifications()), teststepRun.getStartTime(), teststepRun.getDuration(), teststepRun.getResult().toString());
    teststepRun.setId(id);
}
Also used : Teststep(io.irontest.models.teststep.Teststep) Endpoint(io.irontest.models.endpoint.Endpoint) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with Teststep

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

the class TeststepRunMapper method map.

public TeststepRun map(int index, ResultSet rs, StatementContext ctx) throws SQLException {
    TeststepRun teststepRun = new TeststepRun();
    ObjectMapper objectMapper = new ObjectMapper();
    teststepRun.setStartTime(rs.getTimestamp("starttime"));
    teststepRun.setDuration(rs.getLong("duration"));
    teststepRun.setResult(TestResult.getByText(rs.getString("result")));
    Teststep teststep = null;
    try {
        teststep = objectMapper.readValue(rs.getString("teststep"), Teststep.class);
    } catch (IOException e) {
        throw new SQLException("Failed to deserialize teststep JSON.", e);
    }
    teststepRun.setTeststep(teststep);
    // Use LinkedHashMap here instead of Object (for covering specific response type like DBAPIResponse),
    // because TeststepRun is used for displaying report, so JSON representation of the response is sufficient.
    LinkedHashMap response = null;
    try {
        response = objectMapper.readValue(rs.getString("response"), LinkedHashMap.class);
    } catch (IOException e) {
        throw new SQLException("Failed to deserialize response JSON.", e);
    }
    teststepRun.setResponse(response);
    teststepRun.setInfoMessage(rs.getString("info_message"));
    teststepRun.setErrorMessage(rs.getString("error_message"));
    List<AssertionVerification> assertionVerifications = null;
    try {
        assertionVerifications = new ObjectMapper().readValue(rs.getString("assertion_verifications"), new TypeReference<List<AssertionVerification>>() {
        });
    } catch (IOException e) {
        throw new SQLException("Failed to deserialize stepruns JSON.", e);
    }
    teststepRun.setAssertionVerifications(assertionVerifications);
    return teststepRun;
}
Also used : Teststep(io.irontest.models.teststep.Teststep) TeststepRun(io.irontest.models.testrun.TeststepRun) SQLException(java.sql.SQLException) IOException(java.io.IOException) AssertionVerification(io.irontest.models.assertion.AssertionVerification) TypeReference(com.fasterxml.jackson.core.type.TypeReference) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LinkedHashMap(java.util.LinkedHashMap)

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