From 352ebf3437c39f8ba51b5034293aa2790c53d459 Mon Sep 17 00:00:00 2001 From: Igor Dianov Date: Wed, 1 Apr 2020 02:06:27 -0700 Subject: [PATCH] feat(AAE-1291): add multi instance cloud connector and test error connector scenarios (#919) * feat(AAE-1291): add multi instance cloud connector test scenario * fix: add connector error propagation test scenario --- .../qa/story/ProcessInstanceConnectors.java | 71 +++++++++++++++++-- .../process-instance-connectors-actions.story | 22 +++++- 2 files changed, 86 insertions(+), 7 deletions(-) diff --git a/runtime-acceptance-tests/src/main/java/org/activiti/cloud/qa/story/ProcessInstanceConnectors.java b/runtime-acceptance-tests/src/main/java/org/activiti/cloud/qa/story/ProcessInstanceConnectors.java index 7f751d2c..10d445e3 100644 --- a/runtime-acceptance-tests/src/main/java/org/activiti/cloud/qa/story/ProcessInstanceConnectors.java +++ b/runtime-acceptance-tests/src/main/java/org/activiti/cloud/qa/story/ProcessInstanceConnectors.java @@ -16,24 +16,31 @@ package org.activiti.cloud.qa.story; +import static org.activiti.api.process.model.events.IntegrationEvent.IntegrationEvents.INTEGRATION_ERROR_RECEIVED; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.tuple; import static org.awaitility.Awaitility.await; import java.util.Collection; -import net.thucydides.core.annotations.Steps; +import org.activiti.cloud.acc.core.steps.audit.AuditSteps; +import org.activiti.cloud.acc.core.steps.query.ProcessQuerySteps; import org.activiti.cloud.acc.core.steps.runtime.ProcessRuntimeBundleSteps; import org.activiti.cloud.acc.core.steps.runtime.ProcessVariablesRuntimeBundleSteps; import org.activiti.cloud.acc.shared.steps.VariableBufferSteps; import org.activiti.cloud.api.model.shared.CloudVariableInstance; +import org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent; import org.activiti.cloud.api.process.model.CloudProcessInstance; +import org.activiti.cloud.api.process.model.events.CloudIntegrationErrorReceivedEvent; import org.activiti.cloud.api.task.model.CloudTask; import org.jbehave.core.annotations.Given; import org.jbehave.core.annotations.Then; import org.jbehave.core.annotations.When; import org.springframework.hateoas.Resources; +import net.serenitybdd.core.Serenity; +import net.thucydides.core.annotations.Steps; + public class ProcessInstanceConnectors { @Steps @@ -45,6 +52,12 @@ public class ProcessInstanceConnectors { @Steps private ProcessVariablesRuntimeBundleSteps processVariablesRuntimeBundleSteps; + @Steps + private ProcessQuerySteps processQuerySteps; + + @Steps + private AuditSteps auditSteps; + private CloudProcessInstance processInstance; @Given("the user provides a variable named $variableName with value $variableValue") @@ -54,20 +67,31 @@ public void givenVariable(String variableName, variableValue); } - + @Given("the user provides an integer variable named $variableName with value $variableValue") + public void givenVariable(String variableName, + Integer variableValue) { + variableBufferSteps.addVariable(variableName, + variableValue); + } + @When("the user starts an instance of process called $processDefinitionKey with the provided variables") public void startProcessWithAvailableVariables(String processDefinitionKey) { processInstance = processRuntimeBundleSteps.startProcessWithVariables(processDefinitionKey, variableBufferSteps.availableVariables()); + + Serenity.setSessionVariable("processInstanceId").to(processInstance.getId()); } @Then("the process instance has a task named $taskName") public void processHasTask(String taskName) { + + String processInstanceId = Serenity.sessionVariableCalled("processInstanceId"); + await().untilAsserted( () -> { assertThat(processInstance).isNotNull(); - Collection tasks = processRuntimeBundleSteps.getTaskByProcessInstanceId(processInstance.getId()); + Collection tasks = processRuntimeBundleSteps.getTaskByProcessInstanceId(processInstanceId); assertThat(tasks).isNotNull(); assertThat(tasks) .extracting(CloudTask::getName) @@ -79,9 +103,12 @@ public void processHasTask(String taskName) { @Then("the process instance has a variable named $variableName with value $variableValue") public void assertThatHasVariable(String variableName, String variableValue) { - assertThat(processInstance).isNotNull(); + + String processInstanceId = Serenity.sessionVariableCalled("processInstanceId"); + + assertThat(processInstanceId).isNotNull(); await().untilAsserted(() -> { - Resources processVariables = processVariablesRuntimeBundleSteps.getVariables(processInstance.getId()); + Resources processVariables = processVariablesRuntimeBundleSteps.getVariables(processInstanceId); assertThat(processVariables.getContent()).isNotNull(); assertThat(processVariables.getContent()) .extracting(CloudVariableInstance::getName, @@ -90,4 +117,38 @@ public void assertThatHasVariable(String variableName, variableValue)); }); } + + @Then("the query process instance has an integer variable named $variableName with value $variableValue") + public void assertThatQueryHasVariable(String variableName, + Integer variableValue) { + String processInstanceId = Serenity.sessionVariableCalled("processInstanceId"); + + processQuerySteps.checkProcessInstanceHasVariableValue(processInstanceId, + variableName, + variableValue); + } + + @Then("integration error event is emitted for the process") + public void verifyIntegrationEventsForProcesses() throws Exception { + + String processId = Serenity.sessionVariableCalled("processInstanceId"); + + await().untilAsserted(() -> { + Collection events = auditSteps.getEventsByProcessInstanceId(processId); + + assertThat(events) + .filteredOn(CloudIntegrationErrorReceivedEvent.class::isInstance) + .isNotEmpty() + .extracting("eventType", + "errorMessage", + "errorClassName" + ) + .containsExactly( + tuple(INTEGRATION_ERROR_RECEIVED, + "TestErrorConnector", + "java.lang.RuntimeException" + )); + }); + } + } diff --git a/runtime-acceptance-tests/src/main/resources/stories/runtime-bundle/process-instance-connectors-actions.story b/runtime-acceptance-tests/src/main/resources/stories/runtime-bundle/process-instance-connectors-actions.story index 152ef77f..081981b7 100644 --- a/runtime-acceptance-tests/src/main/resources/stories/runtime-bundle/process-instance-connectors-actions.story +++ b/runtime-acceptance-tests/src/main/resources/stories/runtime-bundle/process-instance-connectors-actions.story @@ -1,7 +1,7 @@ Meta: Narrative: As a user -I want to perform operations os processes containing connectors +I want to perform operations of processes containing connectors Scenario: Start a process containing cloud connector Given the user is authenticated as testuser @@ -9,4 +9,22 @@ And the user provides a variable named movieToRank with value The Lord of The Ri When the user starts an instance of process called RankMovieId with the provided variables Then the process instance has a variable named movieToRank with value The Lord of The Rings And the process instance has a variable named movieDesc with value The Lord of the Rings is an epic high fantasy novel written by English author and scholar J. R. R. Tolkien -And the process instance has a task named Add Rating \ No newline at end of file +And the process instance has a task named Add Rating + +Scenario: Complete a process containing multi-instance cloud connector +Given the user is authenticated as testuser +And the user provides an integer variable named instanceCount with value 3 +When the user starts an instance of process called miParallelCloudConnector with the provided variables +Then the query process instance has an integer variable named instanceCount with value 3 +And the query process instance has an integer variable named executionCount with value 3 +And the query process instance has an integer variable named nrOfInstances with value 3 +And the query process instance has an integer variable named nrOfCompletedInstances with value 3 +And the query process instance has an integer variable named nrOfActiveInstances with value 0 +And the query process instance has an integer variable named loopCounter with value 0 +And the status of the process is changed to completed + +Scenario: Propagate integration error for a process containing cloud connector to audit +Given the user is authenticated as testuser +And the user provides a variable named var with value test +When the user starts an instance of process called testErrorConnectorProcess with the provided variables +Then integration error event is emitted for the process