Search in sources :

Example 1 with UserDefinedProperty

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;
}
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 2 with UserDefinedProperty

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();
}
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 3 with UserDefinedProperty

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;
}
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)3 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 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 Date (java.util.Date)1 HashMap (java.util.HashMap)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1