Search in sources :

Example 1 with AbstractTestAction

use of com.consol.citrus.actions.AbstractTestAction in project apim-cli by Axway-API-Management-Plus.

the class APIImportInitializationTestIT method beforeSuite.

@Override
public void beforeSuite(TestDesigner designer) {
    designer.createVariable("orgNumber2", RandomNumberFunction.getRandomNumber(4, true));
    designer.createVariable("orgNumber3", RandomNumberFunction.getRandomNumber(4, true));
    designer.createVariable("orgName2", "API Test-Org 2 ${orgNumber2}");
    designer.createVariable("orgName3", "API Test-Org 3 ${orgNumber2}");
    designer.echo("####### Create Test Org 2: '${orgName2}' with Non-Development flag #######");
    designer.http().client("apiManager").send().post("/organizations").name("orgCreatedRequest").header("Content-Type", "application/json").payload("{\"name\": \"${orgName2}\", \"description\": \"Non-Dev Org ${orgNumber2}\", \"enabled\": true, \"development\": false }");
    designer.echo("####### Validating Non-Development Test-Organisation 2: 'API Test-Org ${orgNumber2}' has been created #######");
    designer.http().client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON).validate("$.name", "${orgName2}").extractFromPayload("$.id", "orgId2");
    designer.echo("####### Extracted Non-Dev organization id: ${orgId2} as attribute: orgId2 #######");
    designer.echo("####### Create Test Org 3: '${orgName3}' with Development flag #######");
    designer.http().client("apiManager").send().post("/organizations").name("orgCreatedRequest").header("Content-Type", "application/json").payload("{\"name\": \"${orgName3}\", \"description\": \"Dev Org ${orgNumber3}\", \"enabled\": true, \"development\": true }");
    designer.echo("####### Validating Development Test-Organisation3 : 'API Test-Org ${orgNumber3}' has been created #######");
    designer.http().client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON).validate("$.name", "${orgName3}").extractFromPayload("$.id", "orgId3");
    designer.echo("####### Extracted Non-Dev organization id: ${orgId3} as attribute: orgId3 #######");
    designer.action(new AbstractTestAction() {

        @Override
        public void doExecute(TestContext testContext) {
            testContext.getGlobalVariables().put("orgId2", testContext.getVariable("orgId2"));
            testContext.getGlobalVariables().put("orgId3", testContext.getVariable("orgId3"));
            testContext.getGlobalVariables().put("orgNumber2", testContext.getVariable("orgNumber2"));
            testContext.getGlobalVariables().put("orgNumber3", testContext.getVariable("orgNumber3"));
            testContext.getGlobalVariables().put("orgName2", testContext.getVariable("orgName2"));
            testContext.getGlobalVariables().put("orgName3", testContext.getVariable("orgName3"));
        }
    });
}
Also used : AbstractTestAction(com.consol.citrus.actions.AbstractTestAction) TestContext(com.consol.citrus.context.TestContext)

Example 2 with AbstractTestAction

use of com.consol.citrus.actions.AbstractTestAction in project apim-cli by Axway-API-Management-Plus.

the class CoreInitializationTestIT method beforeSuite.

@Override
public void beforeSuite(TestDesigner designer) {
    designer.echo("Do a quick healthcheck");
    designer.http().client("gatewayPlain").send().get("/healthcheck");
    designer.http().client("gatewayPlain").receive().response(HttpStatus.OK).payload("<status>ok</status>");
    designer.createVariable("orgNumber", RandomNumberFunction.getRandomNumber(4, true));
    designer.createVariable("orgName", "API Development ${orgNumber}");
    designer.echo("####### Setup Test Org: 'API Development ${orgNumber}' #######");
    designer.http().client("apiManager").send().post("/organizations").name("orgCreatedRequest").header("Content-Type", "application/json").payload("{\"name\": \"${orgName}\", \"description\": \"Test Org ${orgNumber}\", \"enabled\": true, \"development\": true }");
    designer.echo("####### Validate Test-Organisation: ${orgName} has been created #######");
    designer.http().client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON).validate("$.name", "${orgName}").extractFromPayload("$.id", "orgId");
    designer.echo("####### Extracted organization id: ${orgId} as attribute: orgId #######");
    designer.echo("####### Create an Org-Admin-User #######");
    designer.createVariable("oadminUsername1", "orgadmin-${orgNumber}");
    designer.createVariable("oadminPassword1", "orgadmin-${orgNumber}");
    designer.http().client("apiManager").send().post("/users").header("Content-Type", "application/json").payload("{\"enabled\":true,\"loginName\":\"${oadminUsername1}\",\"name\":\"Anna Owen ${orgNumber}\",\"email\":\"anna-${orgNumber}@axway.com\",\"role\":\"oadmin\",\"organizationId\":\"${orgId}\"}");
    designer.http().client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON).extractFromPayload("$.id", "oadminUserId1").extractFromPayload("$.loginName", "oadminUsername1");
    designer.http().client("apiManager").send().post("/users/${oadminUserId1}/changepassword/").header("Content-Type", "application/x-www-form-urlencoded").payload("newPassword=${oadminPassword1}");
    designer.http().client("apiManager").receive().response(HttpStatus.NO_CONTENT);
    designer.echo("####### Created a Org-Admin user: '${oadminUsername1}' ID: '${oadminUserId1}' #######");
    designer.echo("####### Create a test application #######");
    designer.http().client("apiManager").send().post("/applications").name("orgCreatedRequest").header("Content-Type", "application/json").payload("{\"name\":\"Test App ${orgNumber}\",\"apis\":[],\"organizationId\":\"${orgId}\"}");
    designer.http().client("apiManager").receive().response(HttpStatus.CREATED).messageType(MessageType.JSON).extractFromPayload("$.id", "testAppId").extractFromPayload("$.name", "testAppName");
    designer.echo("####### Created a application: '${testAppName}' ID: '${testAppId}' (testAppName/testAppId) #######");
    // Adjusting the API-Manager config in preparation to run integration tests
    designer.echo("Turn off changePasswordOnFirstLogin and passwordExpiryEnabled validation to run integration tests");
    designer.http().client("apiManager").send().put("/config").header("Content-Type", "application/json").payload(new ClassPathResource("/apimanager/config/apimanager-test-config.json"));
    designer.action(new AbstractTestAction() {

        @Override
        public void doExecute(TestContext testContext) {
            testContext.getGlobalVariables().put("orgId", testContext.getVariable("orgId"));
            testContext.getGlobalVariables().put("orgNumber", testContext.getVariable("orgNumber"));
            testContext.getGlobalVariables().put("orgName", testContext.getVariable("orgName"));
            testContext.getGlobalVariables().put("oadminUserId1", testContext.getVariable("oadminUserId1"));
            testContext.getGlobalVariables().put("oadminUsername1", testContext.getVariable("oadminUsername1"));
            testContext.getGlobalVariables().put("oadminPassword1", testContext.getVariable("oadminPassword1"));
            testContext.getGlobalVariables().put("testAppId", testContext.getVariable("testAppId"));
            testContext.getGlobalVariables().put("testAppName", testContext.getVariable("testAppName"));
        }
    });
}
Also used : AbstractTestAction(com.consol.citrus.actions.AbstractTestAction) TestContext(com.consol.citrus.context.TestContext) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 3 with AbstractTestAction

use of com.consol.citrus.actions.AbstractTestAction in project camelinaction2 by camelinaction.

the class CitrusIT method stopAndWaitForGracefulShutdown.

/**
 * Stop and wait for graceful shutdown of Camel context before closing the test.
 */
private void stopAndWaitForGracefulShutdown() {
    // stop the Camel context with custom test action.
    action(new AbstractTestAction() {

        @Override
        public void doExecute(TestContext context) {
            try {
                orderService.stop();
            } catch (Exception e) {
                throw new CitrusRuntimeException("Failed to stop Camel context");
            }
        }
    });
    waitFor().condition(new AbstractCondition() {

        @Override
        public boolean isSatisfied(TestContext context) {
            return orderService.isStopped();
        }

        @Override
        public String getSuccessMessage(TestContext context) {
            return "Successfully stopped Camel context";
        }

        @Override
        public String getErrorMessage(TestContext context) {
            return "Failed to stop Camel context";
        }
    });
}
Also used : AbstractTestAction(com.consol.citrus.actions.AbstractTestAction) TestContext(com.consol.citrus.context.TestContext) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException) AbstractCondition(com.consol.citrus.condition.AbstractCondition) CitrusRuntimeException(com.consol.citrus.exceptions.CitrusRuntimeException)

Example 4 with AbstractTestAction

use of com.consol.citrus.actions.AbstractTestAction in project allure-java by allure-framework.

the class AllureCitrusTest method shouldAddAllureSteps.

@AllureFeatures.Steps
@Test
void shouldAddAllureSteps() {
    final DefaultTestDesigner designer = new DefaultTestDesigner();
    designer.name("Simple test");
    designer.action(new AbstractTestAction() {

        @Override
        public void doExecute(final TestContext context) {
            Allure.step("a");
            Allure.step("b");
            Allure.step("c");
        }
    });
    final AllureResults results = run(designer);
    assertThat(results.getTestResults()).flatExtracting(TestResult::getSteps).flatExtracting(StepResult::getSteps).extracting(StepResult::getName).containsExactly("a", "b", "c");
}
Also used : AbstractTestAction(com.consol.citrus.actions.AbstractTestAction) DefaultTestDesigner(com.consol.citrus.dsl.design.DefaultTestDesigner) TestContext(com.consol.citrus.context.TestContext) AllureResults(io.qameta.allure.test.AllureResults) StepResult(io.qameta.allure.model.StepResult) Test(org.junit.jupiter.api.Test)

Example 5 with AbstractTestAction

use of com.consol.citrus.actions.AbstractTestAction in project allure-java by allure-framework.

the class AllureCitrusTest method shouldSetFailedStatus.

@AllureFeatures.FailedTests
@Test
void shouldSetFailedStatus() {
    final DefaultTestDesigner designer = new DefaultTestDesigner();
    designer.name("Simple test");
    designer.action(new AbstractTestAction() {

        @Override
        public void doExecute(final TestContext context) {
            assertThat(true).isFalse();
        }
    });
    final AllureResults results = run(designer);
    assertThat(results.getTestResults()).extracting(TestResult::getStatus).containsExactly(Status.FAILED);
}
Also used : AbstractTestAction(com.consol.citrus.actions.AbstractTestAction) DefaultTestDesigner(com.consol.citrus.dsl.design.DefaultTestDesigner) TestContext(com.consol.citrus.context.TestContext) AllureResults(io.qameta.allure.test.AllureResults) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractTestAction (com.consol.citrus.actions.AbstractTestAction)5 TestContext (com.consol.citrus.context.TestContext)5 DefaultTestDesigner (com.consol.citrus.dsl.design.DefaultTestDesigner)2 AllureResults (io.qameta.allure.test.AllureResults)2 Test (org.junit.jupiter.api.Test)2 AbstractCondition (com.consol.citrus.condition.AbstractCondition)1 CitrusRuntimeException (com.consol.citrus.exceptions.CitrusRuntimeException)1 StepResult (io.qameta.allure.model.StepResult)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1