From 289b7081f0a0685e95befeff7cd2bab7ac4f7313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Grof=C4=8D=C3=ADk?= Date: Fri, 2 Feb 2024 19:12:33 +0100 Subject: [PATCH] #3835 test clean up --- .../HistoricProcessInstanceAssertTest.java | 24 ++++--- .../process/ProcessInstanceAssertTest.java | 63 ++++++++++--------- .../boot/OneTaskProcessGroovyTest.groovy | 27 -------- .../spring/boot/OneTaskProcessSpec.groovy | 42 ------------- .../test/spring/boot/OneTaskProcessTest.java | 29 --------- 5 files changed, 49 insertions(+), 136 deletions(-) delete mode 100644 modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessGroovyTest.groovy delete mode 100644 modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessSpec.groovy delete mode 100644 modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessTest.java diff --git a/modules/flowable-assertions/flowable-process-assertions/src/test/java/org/flowable/assertions/process/HistoricProcessInstanceAssertTest.java b/modules/flowable-assertions/flowable-process-assertions/src/test/java/org/flowable/assertions/process/HistoricProcessInstanceAssertTest.java index adfec97b4e1..0af5e616c8b 100644 --- a/modules/flowable-assertions/flowable-process-assertions/src/test/java/org/flowable/assertions/process/HistoricProcessInstanceAssertTest.java +++ b/modules/flowable-assertions/flowable-process-assertions/src/test/java/org/flowable/assertions/process/HistoricProcessInstanceAssertTest.java @@ -26,13 +26,14 @@ class HistoricProcessInstanceAssertTest { void isFinishedForFinishedProcessInstance(RuntimeService runtimeService, TaskService taskService, HistoryService historyService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); - FlowableProcessAssertions.assertThat(oneTaskProcess).inHistory().activities().extracting(HistoricActivityInstance::getActivityId).contains( + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.inHistory().activities().extracting(HistoricActivityInstance::getActivityId).contains( "theStart", "theStart-theTask", "theTask" ); taskService.complete(taskService.createTaskQuery().processInstanceId(oneTaskProcess.getId()).singleResult().getId()); - FlowableProcessAssertions.assertThat(oneTaskProcess).inHistory().isFinished() + assertThatOneTaskProcess.inHistory().isFinished() .activities().extracting(HistoricActivityInstance::getActivityId).contains( "theStart", "theStart-theTask", "theTask", "theTask-theEnd", "theEnd" ); @@ -49,12 +50,13 @@ void isFinishedForFinishedProcessInstance(RuntimeService runtimeService, TaskSer void variables(RuntimeService runtimeService, TaskService taskService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("No variable exists in the process scope.") + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.as("No variable exists in the process scope.") .inHistory().variables().isEmpty(); runtimeService.setVariable(oneTaskProcess.getId(), "testVariable", "variableValue"); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Variable exists in the process scope, the variable must be present in the history.") + assertThatOneTaskProcess.as("Variable exists in the process scope, the variable must be present in the history.") .inHistory() .hasVariable("testVariable") .hasVariableWithValue("testVariable", "variableValue") @@ -64,7 +66,7 @@ void variables(RuntimeService runtimeService, TaskService taskService) { Task task = taskService.createTaskQuery().processInstanceId(oneTaskProcess.getId()).singleResult(); taskService.complete(task.getId()); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Variable exists in the process scope, the variable must be present in the history.") + assertThatOneTaskProcess.as("Variable exists in the process scope, the variable must be present in the history.") .doesNotExist() .inHistory() .isFinished() @@ -79,12 +81,13 @@ void variables(RuntimeService runtimeService, TaskService taskService) { void hasVariable(RuntimeService runtimeService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("No variable exists in the process scope.") + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.as("No variable exists in the process scope.") .inHistory().variables().isEmpty(); runtimeService.setVariable(oneTaskProcess.getId(), "testVariable", "variableValue"); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Variable exists in the process scope, the variable must be present in the history.") + assertThatOneTaskProcess.as("Variable exists in the process scope, the variable must be present in the history.") .inHistory().variables().hasSize(1).extracting("name", "value"). containsExactly(Tuple.tuple("testVariable", "variableValue")); } @@ -94,16 +97,17 @@ void hasVariable(RuntimeService runtimeService) { void doesNotHaveVariable(RuntimeService runtimeService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("No variable exists in the process scope.") + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.as("No variable exists in the process scope.") .inHistory().doesNotHaveVariable("nonExistingVariable"); runtimeService.setVariable(oneTaskProcess.getId(), "testVariable", "variableValue"); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Variable exists in the process scope, the variable must be present in the history.") + assertThatOneTaskProcess.as("Variable exists in the process scope, the variable must be present in the history.") .inHistory().doesNotHaveVariable("nonExistingVariable") .hasVariable("testVariable"); - assertThatThrownBy(() -> FlowableProcessAssertions.assertThat(oneTaskProcess).inHistory().doesNotHaveVariable("testVariable")) + assertThatThrownBy(() -> assertThatOneTaskProcess.inHistory().doesNotHaveVariable("testVariable")) .isInstanceOf(AssertionError.class) .hasMessage("Expected process instance does not have variable but variable exists in history."); } diff --git a/modules/flowable-assertions/flowable-process-assertions/src/test/java/org/flowable/assertions/process/ProcessInstanceAssertTest.java b/modules/flowable-assertions/flowable-process-assertions/src/test/java/org/flowable/assertions/process/ProcessInstanceAssertTest.java index 1e27cf330bc..02ae9888374 100644 --- a/modules/flowable-assertions/flowable-process-assertions/src/test/java/org/flowable/assertions/process/ProcessInstanceAssertTest.java +++ b/modules/flowable-assertions/flowable-process-assertions/src/test/java/org/flowable/assertions/process/ProcessInstanceAssertTest.java @@ -60,10 +60,11 @@ void hasVariable(RuntimeService runtimeService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); runtimeService.setVariable(oneTaskProcess.getId(), "variableName", "variableValue"); - FlowableProcessAssertions.assertThat(oneTaskProcess).hasVariable("variableName"); - FlowableProcessAssertions.assertThat(oneTaskProcess).hasVariable("variableName").isRunning(); - FlowableProcessAssertions.assertThat(oneTaskProcess).isRunning().hasVariable("variableName"); - assertThatThrownBy(() -> FlowableProcessAssertions.assertThat(oneTaskProcess).hasVariable("nonExistingVariable")) + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.hasVariable("variableName"); + assertThatOneTaskProcess.hasVariable("variableName").isRunning(); + assertThatOneTaskProcess.isRunning().hasVariable("variableName"); + assertThatThrownBy(() -> assertThatOneTaskProcess.hasVariable("nonExistingVariable")) .isInstanceOf(AssertionError.class) .hasMessage("Expected process instance has variable but variable does not exist."); } @@ -96,9 +97,10 @@ void doesNotHaveVariable(RuntimeService runtimeService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); runtimeService.setVariable(oneTaskProcess.getId(), "variableName", "variableValue"); - FlowableProcessAssertions.assertThat(oneTaskProcess).doesNotHaveVariable("NonExistingVariableName"); - FlowableProcessAssertions.assertThat(oneTaskProcess).doesNotHaveVariable("NonExistingVariableName").isRunning(); - assertThatThrownBy(() -> FlowableProcessAssertions.assertThat(oneTaskProcess).doesNotHaveVariable("variableName")) + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.doesNotHaveVariable("NonExistingVariableName"); + assertThatOneTaskProcess.doesNotHaveVariable("NonExistingVariableName").isRunning(); + assertThatThrownBy(() -> assertThatOneTaskProcess.doesNotHaveVariable("variableName")) .isInstanceOf(AssertionError.class) .hasMessage("Expected process instance does not have variable but variable exists."); } @@ -110,8 +112,9 @@ void doesNotHaveVariableForNonRunningProcess(RuntimeService runtimeService, Task runtimeService.setVariable(oneTaskProcess.getId(), "variableName", "variableValue"); taskService.complete(taskService.createTaskQuery().processInstanceId(oneTaskProcess.getId()).singleResult().getId()); - FlowableProcessAssertions.assertThat(oneTaskProcess).doesNotHaveVariable("variableName"); - FlowableProcessAssertions.assertThat(oneTaskProcess).doesNotHaveVariable("nonExistingVariable"); + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.doesNotHaveVariable("variableName"); + assertThatOneTaskProcess.doesNotHaveVariable("nonExistingVariable"); } @Test @@ -170,14 +173,15 @@ void activitiesForNonRunningProcess(RuntimeService runtimeService, TaskService t void executions(RuntimeService runtimeService, TaskService taskService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Running process has at least 2 active executions." + + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.as("Running process has at least 2 active executions." + "(ProcessInstance + Child)") .executions().extracting(Execution::getId).contains(oneTaskProcess.getId()) .hasSize(2); taskService.complete(taskService.createTaskQuery().processInstanceId(oneTaskProcess.getId()).singleResult().getId()); - FlowableProcessAssertions.assertThat(oneTaskProcess).doesNotExist().as("There must be no execution for the finished process.") + assertThatOneTaskProcess.doesNotExist().as("There must be no execution for the finished process.") .executions().hasSize(0); } @@ -186,23 +190,24 @@ void executions(RuntimeService runtimeService, TaskService taskService) { void variables(RuntimeService runtimeService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); - FlowableProcessAssertions.assertThat(oneTaskProcess).variables().isEmpty(); - assertThatThrownBy(() -> FlowableProcessAssertions.assertThat(oneTaskProcess).hasVariableWithValue("nonExistingVar", "anyValue")) + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.variables().isEmpty(); + assertThatThrownBy(() -> assertThatOneTaskProcess.hasVariableWithValue("nonExistingVar", "anyValue")) .isInstanceOf(AssertionError.class).hasMessage("Expected process instance has variable but variable does not exist."); runtimeService.setVariable(oneTaskProcess.getId(), "testVariable", "initialValue"); - FlowableProcessAssertions.assertThat(oneTaskProcess).variables().extracting("name", "value").contains(Tuple.tuple("testVariable", "initialValue")); - FlowableProcessAssertions.assertThat(oneTaskProcess).hasVariableWithValue("testVariable", "initialValue"); + assertThatOneTaskProcess.variables().extracting("name", "value").contains(Tuple.tuple("testVariable", "initialValue")); + assertThatOneTaskProcess.hasVariableWithValue("testVariable", "initialValue"); runtimeService.setVariable(oneTaskProcess.getId(), "testVariable", "updatedValue"); - FlowableProcessAssertions.assertThat(oneTaskProcess).variables().extracting("name", "value").contains(Tuple.tuple("testVariable", "updatedValue")); - FlowableProcessAssertions.assertThat(oneTaskProcess).hasVariableWithValue("testVariable", "updatedValue").isRunning(); + assertThatOneTaskProcess.variables().extracting("name", "value").contains(Tuple.tuple("testVariable", "updatedValue")); + assertThatOneTaskProcess.hasVariableWithValue("testVariable", "updatedValue").isRunning(); runtimeService.setVariable(oneTaskProcess.getId(), "firstVariable", "initialValue"); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Variables are ordered by names ascending.") + assertThatOneTaskProcess.as("Variables are ordered by names ascending.") .variables().extracting("name") .containsExactly("firstVariable", "testVariable"); @@ -213,17 +218,18 @@ void variables(RuntimeService runtimeService) { void identityLinks(RuntimeService runtimeService) { ProcessInstance oneTaskProcess = createOneTaskProcess(runtimeService); - FlowableProcessAssertions.assertThat(oneTaskProcess).identityLinks().isEmpty(); - FlowableProcessAssertions.assertThat(oneTaskProcess).inHistory().identityLinks().isEmpty(); + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.identityLinks().isEmpty(); + assertThatOneTaskProcess.inHistory().identityLinks().isEmpty(); runtimeService.addUserIdentityLink(oneTaskProcess.getId(), "testUser", IdentityLinkType.ASSIGNEE); runtimeService.addGroupIdentityLink(oneTaskProcess.getId(), "testGroup", IdentityLinkType.CANDIDATE); - FlowableProcessAssertions.assertThat(oneTaskProcess).identityLinks().hasSize(2) + assertThatOneTaskProcess.identityLinks().hasSize(2) .extracting(IdentityLink::getUserId, IdentityLink::getGroupId, IdentityLink::getType) .containsExactlyInAnyOrder(Tuple.tuple("testUser", null, IdentityLinkType.ASSIGNEE), Tuple.tuple(null, "testGroup", IdentityLinkType.CANDIDATE)); - FlowableProcessAssertions.assertThat(oneTaskProcess).inHistory().identityLinks().hasSize(2) + assertThatOneTaskProcess.inHistory().identityLinks().hasSize(2) .extracting(HistoricIdentityLink::getUserId, HistoricIdentityLink::getGroupId, HistoricIdentityLink::getType) .containsExactlyInAnyOrder(Tuple.tuple("testUser", null, IdentityLinkType.ASSIGNEE), Tuple.tuple(null, "testGroup", IdentityLinkType.CANDIDATE)); @@ -236,25 +242,26 @@ void userTasks(RuntimeService runtimeService, ManagementService managementServic TaskService taskService, ProcessEngineConfiguration processEngineConfiguration) { ProcessInstance oneTaskProcess = runtimeService.createProcessInstanceBuilder().processDefinitionKey("oneTaskProcess").startAsync(); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Process instance is started asynchronously and did not reach userTask") + ProcessInstanceAssert assertThatOneTaskProcess = FlowableProcessAssertions.assertThat(oneTaskProcess); + assertThatOneTaskProcess.as("Process instance is started asynchronously and did not reach userTask") .userTasks().isEmpty(); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Process instance is started asynchronously and did not reach userTask in history") + assertThatOneTaskProcess.as("Process instance is started asynchronously and did not reach userTask in history") .inHistory().userTasks().isEmpty(); JobTestHelper.waitForJobExecutorToProcessAllJobs(processEngineConfiguration, managementService, 10_000, 500); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Async executions executed and userTask reached.") + assertThatOneTaskProcess.as("Async executions executed and userTask reached.") .userTasks().hasSize(1).extracting(Task::getTaskDefinitionKey).containsExactly("theTask"); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("Async executions executed and userTask reached in history.") + assertThatOneTaskProcess.as("Async executions executed and userTask reached in history.") .inHistory().userTasks().hasSize(1).extracting(HistoricTaskInstance::getTaskDefinitionKey) .containsExactly("theTask"); Task task = taskService.createTaskQuery().processInstanceId(oneTaskProcess.getId()).singleResult(); taskService.complete(task.getId()); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("User tasks are empty for non existing process").doesNotExist() + assertThatOneTaskProcess.as("User tasks are empty for non existing process").doesNotExist() .userTasks().isEmpty(); - FlowableProcessAssertions.assertThat(oneTaskProcess).as("The userTask is completed, but must exist in history.") + assertThatOneTaskProcess.as("The userTask is completed, but must exist in history.") .inHistory().isFinished() .userTasks().hasSize(1).extracting(HistoricTaskInstance::getTaskDefinitionKey) .containsExactly("theTask"); diff --git a/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessGroovyTest.groovy b/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessGroovyTest.groovy deleted file mode 100644 index 66ffcc96116..00000000000 --- a/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessGroovyTest.groovy +++ /dev/null @@ -1,27 +0,0 @@ -package org.flowable.test.spring.boot - -import flowable.Application -import org.flowable.engine.RuntimeService -import org.flowable.engine.runtime.ProcessInstance -import org.junit.jupiter.api.Test -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest - -import static org.crp.flowable.assertions.CrpFlowableAssertions.assertThat - -@SpringBootTest(classes = Application.class) -class OneTaskProcessGroovyTest { - @Autowired - RuntimeService runtimeService; - - @Test - void "happy path"() { - ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("oneTaskProcess").start() - - assertThat(processInstance).isRunning() - .doesNotHaveVariable('nonExistingVariable') - .activities().extracting('activityId') - .contains('theStart', 'theStart-theTask', 'theTask') - - } -} diff --git a/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessSpec.groovy b/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessSpec.groovy deleted file mode 100644 index 9d1ed52fbf1..00000000000 --- a/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessSpec.groovy +++ /dev/null @@ -1,42 +0,0 @@ -package org.flowable.test.spring.boot - -import flowable.Application -import org.flowable.engine.RuntimeService -import org.flowable.engine.TaskService -import org.flowable.engine.runtime.ProcessInstance -import org.junit.jupiter.api.Test -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.boot.test.context.SpringBootTest -import org.springframework.test.context.ContextConfiguration -import spock.lang.Specification - -import static org.crp.flowable.assertions.CrpFlowableAssertions.assertThat - -@SpringBootTest(classes = Application.class) -@ContextConfiguration -class OneTaskProcessSpec extends Specification { - @Autowired - RuntimeService runtimeService - @Autowired - TaskService taskService - - def 'happy path'() { - given: - path = [] - - when: - ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("oneTaskProcess").start() - - then: - assertThat(processInstance).isRunning() - .doesNotHaveVariable('nonExistingVariable') - .activities().extracting('activityId') - .contains(path << ['theStart', 'theStart-theTask', 'theTask']) - - when: - - cleanup: - runtimeService.deleteProcessInstance(processInstance.id, 'removing test process instance') - } - -} diff --git a/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessTest.java b/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessTest.java deleted file mode 100644 index 3ee8dd88c73..00000000000 --- a/modules/flowable-spring-boot/flowable-spring-boot-samples/flowable-spring-boot-sample-rest-api/src/test/java/org/flowable/test/spring/boot/OneTaskProcessTest.java +++ /dev/null @@ -1,29 +0,0 @@ -package org.flowable.test.spring.boot; - -import flowable.Application; -import org.flowable.engine.RuntimeService; -import org.flowable.engine.runtime.ActivityInstance; -import org.flowable.engine.runtime.ProcessInstance; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import static org.crp.flowable.assertions.CrpFlowableAssertions.assertThat; - -@SpringBootTest(classes = Application.class) -public class OneTaskProcessTest { - @Autowired - RuntimeService runtimeService; - - @Test - void happyPath() { - ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder().processDefinitionKey("oneTaskProcess").start(); - - assertThat(processInstance) - .isRunning() - .doesNotHaveVariable("nonExistingVariable") - .activities().extracting(ActivityInstance::getActivityId).contains( - "theStart", "theStart-theTask", "theTask" - ); - } -}