Search in sources :

Example 1 with HTTPStubsSetupTeststepProperties

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

the class HTTPStubsSetupTeststepRunner method run.

@Override
public BasicTeststepRun run() {
    WireMockServer wireMockServer = getTestcaseRunContext().getWireMockServer();
    // reset mock server
    wireMockServer.resetAll();
    // load stub mappings into mock server
    Map<Short, UUID> httpStubMappingInstanceIds = getTestcaseRunContext().getHttpStubMappingInstanceIds();
    HTTPStubsSetupTeststepProperties otherProperties = (HTTPStubsSetupTeststepProperties) getTeststep().getOtherProperties();
    wireMockServer.loadMappingsUsing(stubMappings -> {
        for (HTTPStubMapping stubMapping : otherProperties.getHttpStubMappings()) {
            StubMapping stubInstance = IronTestUtils.createStubInstance(stubMapping.getId(), stubMapping.getNumber(), stubMapping.getSpec());
            stubMappings.addMapping(stubInstance);
            httpStubMappingInstanceIds.put(stubMapping.getNumber(), stubInstance.getId());
        }
    });
    return new BasicTeststepRun();
}
Also used : HTTPStubMapping(io.irontest.models.HTTPStubMapping) HTTPStubsSetupTeststepProperties(io.irontest.models.teststep.HTTPStubsSetupTeststepProperties) HTTPStubMapping(io.irontest.models.HTTPStubMapping) StubMapping(com.github.tomakehurst.wiremock.stubbing.StubMapping) UUID(java.util.UUID) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer)

Example 2 with HTTPStubsSetupTeststepProperties

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

the class TeststepRunnerFactory method newTeststepRunner.

/**
 * This method modifies content of the propertyExtractor object.
 * @param teststep
 * @param utilsDAO
 * @param referenceableStringProperties
 * @param referenceableEndpointProperties
 * @param testcaseRunContext
 * @return
 */
public TeststepRunner newTeststepRunner(Teststep teststep, UtilsDAO utilsDAO, Map<String, String> referenceableStringProperties, Map<String, Endpoint> referenceableEndpointProperties, TestcaseRunContext testcaseRunContext) throws Exception {
    TeststepRunner runner;
    Class runnerClass = Class.forName(resolveTeststepRunnerClassName(teststep));
    Constructor<TeststepRunner> constructor = runnerClass.getConstructor();
    runner = constructor.newInstance();
    resolveReferenceableStringProperties(teststep, referenceableStringProperties);
    // must do this after resolving referenceable string properties
    if (teststep.getOtherProperties() instanceof HTTPStubsSetupTeststepProperties) {
        HTTPStubsSetupTeststepProperties httpStubsSetupTeststepProperties = (HTTPStubsSetupTeststepProperties) teststep.getOtherProperties();
        IronTestUtils.substituteRequestBodyMainPatternValue(httpStubsSetupTeststepProperties.getHttpStubMappings());
    }
    // resolve endpoint property if set on test step
    if (teststep.getEndpointProperty() != null) {
        teststep.setEndpoint(referenceableEndpointProperties.get(teststep.getEndpointProperty()));
        if (teststep.getEndpoint() == null) {
            throw new RuntimeException("Endpoint property " + teststep.getEndpointProperty() + " not defined or is null.");
        }
    }
    // decrypt password from endpoint
    // not modifying the endpoint object. Reasons
    // 1. Avoid the decrypted password leaking out of this runner (moving around with the Endpoint object)
    // 2. Avoid affecting other step runs when the endpoint object comes from a referenceable property (like from data table)
    Endpoint endpoint = teststep.getEndpoint();
    if (endpoint != null && endpoint.getPassword() != null) {
        runner.setDecryptedEndpointPassword(utilsDAO.decryptEndpointPassword(endpoint.getPassword()));
    }
    runner.setTeststep(teststep);
    runner.setTestcaseRunContext(testcaseRunContext);
    return runner;
}
Also used : Endpoint(io.irontest.models.endpoint.Endpoint) HTTPStubsSetupTeststepProperties(io.irontest.models.teststep.HTTPStubsSetupTeststepProperties)

Example 3 with HTTPStubsSetupTeststepProperties

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

the class TestcaseRunner method preProcessing.

// process the test case before starting to run it
void preProcessing() {
    if (!testcase.getHttpStubMappings().isEmpty()) {
        // add HTTPStubsSetup step
        Teststep httpStubsSetupStep = new Teststep(Teststep.TYPE_HTTP_STUBS_SETUP);
        httpStubsSetupStep.setName("Set up HTTP stubs");
        HTTPStubsSetupTeststepProperties stubsSetupTeststepProperties = new HTTPStubsSetupTeststepProperties();
        stubsSetupTeststepProperties.setHttpStubMappings(testcase.getHttpStubMappings());
        httpStubsSetupStep.setOtherProperties(stubsSetupTeststepProperties);
        testcase.getTeststeps().add(0, httpStubsSetupStep);
        // add HTTPStubRequestsCheck step and its assertions
        Teststep stubRequestsCheckStep = new Teststep(Teststep.TYPE_HTTP_STUB_REQUESTS_CHECK);
        testcase.getTeststeps().add(testcase.getTeststeps().size(), stubRequestsCheckStep);
        stubRequestsCheckStep.setName("Check HTTP stub requests");
        for (HTTPStubMapping stub : testcase.getHttpStubMappings()) {
            Assertion stubHitAssertion = new Assertion(Assertion.TYPE_HTTP_STUB_HIT);
            stubHitAssertion.setName("Stub was hit");
            stubHitAssertion.setOtherProperties(new HTTPStubHitAssertionProperties(stub.getNumber(), stub.getExpectedHitCount()));
            stubRequestsCheckStep.getAssertions().add(stubHitAssertion);
        }
        if (testcase.getHttpStubMappings().size() > 1 && testcase.isCheckHTTPStubsHitOrder()) {
            Assertion stubsHitInOrderAssertion = new Assertion(Assertion.TYPE_HTTP_STUBS_HIT_IN_ORDER);
            stubsHitInOrderAssertion.setName("Stubs were hit in order");
            List<Short> expectedHitOrder = new ArrayList<>();
            for (HTTPStubMapping stub : testcase.getHttpStubMappings()) {
                expectedHitOrder.add(stub.getNumber());
            }
            stubsHitInOrderAssertion.setOtherProperties(new HTTPStubsHitInOrderAssertionProperties(expectedHitOrder));
            stubRequestsCheckStep.getAssertions().add(stubsHitInOrderAssertion);
        }
        Assertion allStubRequestsMatchedAssertion = new Assertion(Assertion.TYPE_ALL_HTTP_STUB_REQUESTS_MATCHED);
        allStubRequestsMatchedAssertion.setName("All stub requests were matched");
        stubRequestsCheckStep.getAssertions().add(allStubRequestsMatchedAssertion);
    }
    for (Teststep teststep : testcase.getTeststeps()) {
        if (Teststep.TYPE_IIB.equals(teststep.getType()) && Teststep.ACTION_WAIT_FOR_PROCESSING_COMPLETION.equals(teststep.getAction())) {
            Teststep waitUntilNextSecondStep = new Teststep(Teststep.TYPE_WAIT_UNTIL_NEXT_SECOND);
            waitUntilNextSecondStep.setName("Wait until next second");
            testcase.getTeststeps().add(0, waitUntilNextSecondStep);
            break;
        }
    }
}
Also used : Teststep(io.irontest.models.teststep.Teststep) HTTPStubMapping(io.irontest.models.HTTPStubMapping) HTTPStubsSetupTeststepProperties(io.irontest.models.teststep.HTTPStubsSetupTeststepProperties)

Aggregations

HTTPStubsSetupTeststepProperties (io.irontest.models.teststep.HTTPStubsSetupTeststepProperties)3 HTTPStubMapping (io.irontest.models.HTTPStubMapping)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 StubMapping (com.github.tomakehurst.wiremock.stubbing.StubMapping)1 Endpoint (io.irontest.models.endpoint.Endpoint)1 Teststep (io.irontest.models.teststep.Teststep)1 UUID (java.util.UUID)1