-
Notifications
You must be signed in to change notification settings - Fork 2.8k
#3835 fluent assertions #3837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
martin-grofcik
wants to merge
13
commits into
flowable:main
Choose a base branch
from
martin-grofcik:#3835_fluent_assertions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
#3835 fluent assertions #3837
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0942eb0
#3835 initial implementation for processes
martin-grofcik 289b708
#3835 test clean up
martin-grofcik dde9a98
#3835 test clean up
martin-grofcik 2b59e75
#3835 adding modules into pom
martin-grofcik e2e01c4
#3835 formatting
martin-grofcik 1f431cc
#3835 license
martin-grofcik 537de3a
Update modules/flowable-assertions/flowable-process-assertions/src/ma…
martin-grofcik e3a3f49
Update modules/flowable-assertions/flowable-process-assertions/src/ma…
martin-grofcik 363f215
Update modules/flowable-assertions/flowable-process-assertions/src/ma…
martin-grofcik c14a452
#3835 imports
martin-grofcik ee24b3c
Merge remote-tracking branch 'downstream/#3835_fluent_assertions' int…
martin-grofcik c4bbe51
#3835 module change flowable-assertions -> flowable-assertj
martin-grofcik 86f9192
#3835 package change org.flowable.assertions -> org.flowable.assertj
martin-grofcik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
modules/flowable-assertions/flowable-process-assertions/pom.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
| <parent> | ||
| <groupId>org.flowable</groupId> | ||
| <artifactId>flowable-assertions</artifactId> | ||
| <version>7.1.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <artifactId>flowable-process-assertions</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>org.assertj</groupId> | ||
| <artifactId>assertj-core</artifactId> | ||
| <scope>compile</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.flowable</groupId> | ||
| <artifactId>flowable-engine</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.zaxxer</groupId> | ||
| <artifactId>HikariCP</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>com.h2database</groupId> | ||
| <artifactId>h2</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.junit.jupiter</groupId> | ||
| <artifactId>junit-jupiter</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
19 changes: 19 additions & 0 deletions
19
...s-assertions/src/main/java/org/flowable/assertions/process/FlowableProcessAssertions.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package org.flowable.assertions.process; | ||
|
|
||
| import org.assertj.core.api.Assertions; | ||
| import org.flowable.engine.history.HistoricProcessInstance; | ||
| import org.flowable.engine.runtime.ProcessInstance; | ||
|
|
||
| /** | ||
| * @author martin.grofcik | ||
| */ | ||
| public class FlowableProcessAssertions extends Assertions { | ||
|
|
||
| public static ProcessInstanceAssert assertThat(ProcessInstance processInstance) { | ||
| return new ProcessInstanceAssert(processInstance); | ||
| } | ||
| public static HistoricProcessInstanceAssert assertThat(HistoricProcessInstance historicProcessInstance) { | ||
| return new HistoricProcessInstanceAssert(historicProcessInstance); | ||
| } | ||
|
|
||
| } | ||
150 changes: 150 additions & 0 deletions
150
...sertions/src/main/java/org/flowable/assertions/process/HistoricProcessInstanceAssert.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| package org.flowable.assertions.process; | ||
|
|
||
| import org.assertj.core.api.AbstractAssert; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.assertj.core.api.ListAssert; | ||
| import org.flowable.engine.ProcessEngine; | ||
| import org.flowable.engine.history.HistoricActivityInstance; | ||
| import org.flowable.engine.history.HistoricProcessInstance; | ||
| import org.flowable.identitylink.api.IdentityLink; | ||
| import org.flowable.identitylink.api.history.HistoricIdentityLink; | ||
| import org.flowable.task.api.history.HistoricTaskInstance; | ||
| import org.flowable.variable.api.history.HistoricVariableInstance; | ||
|
|
||
| import static org.flowable.assertions.process.FlowableProcessAssertions.assertThat; | ||
martin-grofcik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| import static org.flowable.assertions.process.Utils.*; | ||
martin-grofcik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * @author martin.grofcik | ||
| */ | ||
|
|
||
| public class HistoricProcessInstanceAssert extends AbstractAssert<HistoricProcessInstanceAssert, HistoricProcessInstance> { | ||
|
|
||
| protected final ProcessServicesProvider processServicesProvider; | ||
|
|
||
| protected HistoricProcessInstanceAssert(ProcessEngine processEngine, HistoricProcessInstance historicProcessInstance) { | ||
| super(historicProcessInstance, HistoricProcessInstanceAssert.class); | ||
| processServicesProvider = ProcessServicesProvider.of(processEngine); | ||
| } | ||
|
|
||
| protected HistoricProcessInstanceAssert(HistoricProcessInstance historicProcessInstance) { | ||
| this(getProcessEngine(), historicProcessInstance); | ||
| } | ||
|
|
||
| /** | ||
| * Assert <b>historic</b> activities ordered by activity instance start time. | ||
| * | ||
| * @return Assertion of {@link HistoricActivityInstance} list. | ||
| */ | ||
| public ListAssert<HistoricActivityInstance> activities() { | ||
| processExistsInHistory(); | ||
|
|
||
| return assertThat(processServicesProvider.getHistoryService().createHistoricActivityInstanceQuery().processInstanceId(actual.getId()) | ||
| .orderByHistoricActivityInstanceStartTime().desc().list()); | ||
| } | ||
|
|
||
| /** | ||
| * Assert <b>historic</b> process instance exists in the history and is finished. | ||
| * | ||
| * @return Historic process instance assertion. | ||
| */ | ||
| public HistoricProcessInstanceAssert isFinished() { | ||
| processExistsInHistory(); | ||
|
|
||
| if (processServicesProvider.getHistoryService().createHistoricProcessInstanceQuery().finished().processInstanceId(actual.getId()).count() != 1) { | ||
| failWithMessage(getProcessDescription(actual)+" to be finished, but is running in history."); | ||
martin-grofcik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| public ListAssert<HistoricVariableInstance> variables() { | ||
| processExistsInHistory(); | ||
|
|
||
| return assertThat(processServicesProvider.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(actual.getId()).orderByVariableName().asc().list()); | ||
| } | ||
|
|
||
| /** | ||
| * Assert that process instance has variable in <b>history</b>. | ||
| * | ||
| * @param variableName variable to check. | ||
| * @return Historic process instance assertion | ||
| */ | ||
|
|
||
| public HistoricProcessInstanceAssert hasVariable(String variableName) { | ||
| processExistsInHistory(); | ||
|
|
||
| if (processServicesProvider.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(actual.getId()).variableExists(variableName).count() != 1) { | ||
| failWithMessage(getProcessDescription(actual)+" has variable <%s> but variable does not exist in history.", variableName); | ||
martin-grofcik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Assert that process instance does not have variable in <b>history</b>. | ||
| * @param variableName variable to check | ||
| * @return Historic process instance assertion | ||
| */ | ||
| public HistoricProcessInstanceAssert doesNotHaveVariable(String variableName) { | ||
| processExistsInHistory(); | ||
|
|
||
| if (processServicesProvider.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(actual.getId()).variableExists(variableName).count() != 0) { | ||
| failWithMessage(getProcessDescription(actual)+" does not have variable <%s> but variable exists in history.", variableName); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Assert that process instance has variable in <b>history</b> with value equals to expectedValue. | ||
| * | ||
| * @param variableName variable to check. | ||
| * @param expectedValue expected variable value. | ||
| * @return Historic process instance assertion | ||
| */ | ||
| public HistoricProcessInstanceAssert hasVariableWithValue(String variableName, Object expectedValue) { | ||
| processExistsInHistory(); | ||
| hasVariable(variableName); | ||
|
|
||
| HistoricVariableInstance actualVariable = processServicesProvider.getHistoryService().createHistoricVariableInstanceQuery().processInstanceId(actual.getId()).variableName(variableName).singleResult(); | ||
| Assertions.assertThat(actualVariable.getValue()).isEqualTo(expectedValue); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Assert list of <b>historic</b> identity links without ordering. | ||
| * | ||
| * @return Assertion of #{@link IdentityLink} list. | ||
| */ | ||
| public ListAssert<HistoricIdentityLink> identityLinks() { | ||
| processExistsInHistory(); | ||
|
|
||
| return assertThat(processServicesProvider.getHistoryService().getHistoricIdentityLinksForProcessInstance(actual.getId())); | ||
| } | ||
|
|
||
| /** | ||
| * Assert list of user tasks in the <b>history</b> ordered by the task name ascending. | ||
| * Process, Task variables and identityLinks are included. | ||
| * | ||
| * @return Assertion of {@link HistoricTaskInstance} list. | ||
| */ | ||
| public ListAssert<HistoricTaskInstance> userTasks() { | ||
| processExistsInHistory(); | ||
|
|
||
| return assertThat(processServicesProvider.getHistoryService().createHistoricTaskInstanceQuery().processInstanceId(actual.getId()).orderByTaskName().asc() | ||
| .includeProcessVariables().includeIdentityLinks().includeTaskLocalVariables().list()); | ||
| } | ||
|
|
||
| private void processExistsInHistory() { | ||
| isNotNull(); | ||
| isInHistory(); | ||
| } | ||
|
|
||
| private void isInHistory() { | ||
| if (processServicesProvider.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(actual.getId()).count() != 1) { | ||
| failWithMessage(getProcessDescription(actual)+"> exists in history but process instance not found."); | ||
| } | ||
| } | ||
|
|
||
| } | ||
182 changes: 182 additions & 0 deletions
182
...ocess-assertions/src/main/java/org/flowable/assertions/process/ProcessInstanceAssert.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,182 @@ | ||
| package org.flowable.assertions.process; | ||
|
|
||
| import org.assertj.core.api.AbstractAssert; | ||
| import org.assertj.core.api.Assertions; | ||
| import org.assertj.core.api.ListAssert; | ||
| import org.flowable.engine.ProcessEngine; | ||
| import org.flowable.engine.runtime.ActivityInstance; | ||
| import org.flowable.engine.runtime.Execution; | ||
| import org.flowable.engine.runtime.ProcessInstance; | ||
| import org.flowable.eventsubscription.api.EventSubscription; | ||
| import org.flowable.identitylink.api.IdentityLink; | ||
| import org.flowable.task.api.Task; | ||
| import org.flowable.variable.api.persistence.entity.VariableInstance; | ||
|
|
||
| import static org.flowable.assertions.process.FlowableProcessAssertions.assertThat; | ||
| import static org.flowable.assertions.process.Utils.*; | ||
| /** | ||
| * @author martin.grofcik | ||
| */ | ||
| public class ProcessInstanceAssert extends AbstractAssert<ProcessInstanceAssert, ProcessInstance> { | ||
| protected final ProcessServicesProvider processServicesProvider; | ||
|
|
||
| protected ProcessInstanceAssert(ProcessEngine processEngine, ProcessInstance processInstance) { | ||
| super(processInstance, ProcessInstanceAssert.class); | ||
| processServicesProvider = ProcessServicesProvider.of(processEngine); | ||
| } | ||
|
|
||
| protected ProcessInstanceAssert(ProcessInstance processInstance) { | ||
| this(getProcessEngine(), processInstance); | ||
| } | ||
|
|
||
| /** | ||
| * Assert that process instance exists in <b>runtime</b>. | ||
| * | ||
| * @return Process instance assert. | ||
| */ | ||
| public ProcessInstanceAssert isRunning() { | ||
| isNotNull(); | ||
|
|
||
| if (processServicesProvider.getRuntimeService().createProcessInstanceQuery().processInstanceId(actual.getId()).count() < 1) { | ||
| failWithMessage(getProcessDescription(actual)+" to be running but is not.", actual.getId()); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Assert that process instance has variable in <b>runtime</b>. | ||
| * | ||
| * @param variableName variable to check. | ||
| * @return Process instance assertion | ||
| */ | ||
| public ProcessInstanceAssert hasVariable(String variableName) { | ||
| isNotNull(); | ||
|
|
||
| if (processServicesProvider.getRuntimeService().createProcessInstanceQuery().processInstanceId(actual.getId()).variableExists(variableName).count() != 1) { | ||
| failWithMessage(getProcessDescription(actual)+" has variable <%s> but variable does not exist.", variableName); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Assert that process instance has variable in <b>runtime</b> with value equals to expectedValue. | ||
| * | ||
| * @param variableName variable to check. | ||
| * @param expectedValue expected variable value. | ||
| * @return Process instance assertion | ||
| */ | ||
| public ProcessInstanceAssert hasVariableWithValue(String variableName, Object expectedValue) { | ||
| isNotNull(); | ||
| hasVariable(variableName); | ||
|
|
||
| VariableInstance actualVariable = processServicesProvider.getRuntimeService().createVariableInstanceQuery().processInstanceId(actual.getId()).variableName(variableName).singleResult(); | ||
| Assertions.assertThat(actualVariable.getValue()).isEqualTo(expectedValue); | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Assert that process instance does not have variable in <b>runtime</b>. | ||
| * @param variableName variable to check | ||
| * @return Process instance assertion | ||
| */ | ||
| public ProcessInstanceAssert doesNotHaveVariable(String variableName) { | ||
| isNotNull(); | ||
|
|
||
| if (processServicesProvider.getRuntimeService().createProcessInstanceQuery().processInstanceId(actual.getId()).variableExists(variableName).count() != 0) { | ||
| failWithMessage(getProcessDescription(actual)+" does not have variable <%s> but variable exists.", variableName); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Assert that process instance does on exist in <b>runtime</b>. | ||
martin-grofcik marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| * | ||
| * @return Process instance assertion | ||
| */ | ||
| public ProcessInstanceAssert doesNotExist() { | ||
| isNotNull(); | ||
|
|
||
| if (processServicesProvider.getRuntimeService().createProcessInstanceQuery().processInstanceId(actual.getId()).count() != 0) { | ||
| failWithMessage(getProcessDescription(actual)+" is finished but instance exists in runtime."); | ||
| } | ||
|
|
||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * @return Historic process instance assertion | ||
| */ | ||
| public HistoricProcessInstanceAssert inHistory() { | ||
| return assertThat(processServicesProvider.getHistoryService().createHistoricProcessInstanceQuery().processInstanceId(actual.getId()).singleResult()); | ||
| } | ||
|
|
||
| /** | ||
| * Assert list of <b>runtime</b> process instance activities ordered by activity start time. | ||
| * | ||
| * @return Assertion of #{@link ActivityInstance} list. | ||
| */ | ||
| public ListAssert<ActivityInstance> activities() { | ||
| isNotNull(); | ||
|
|
||
| return assertThat(processServicesProvider.getRuntimeService().createActivityInstanceQuery().processInstanceId(actual.getId()).orderByActivityInstanceStartTime().asc().list()); | ||
| } | ||
|
|
||
| /** | ||
| * Assert list of <b>runtime</b> execution instances without ordering. | ||
| * | ||
| * @return Assertion of #{@link Execution} list. | ||
| */ | ||
| public ListAssert<Execution> executions() { | ||
| isNotNull(); | ||
|
|
||
| return assertThat(processServicesProvider.getRuntimeService().createExecutionQuery().processInstanceId(actual.getId()).list()); | ||
| } | ||
|
|
||
| /** | ||
| * Assert list of <b>runtime</b> variable instances ordered by variable name ascending. | ||
| * | ||
| * @return Assertion of #{@link VariableInstance} list. | ||
| */ | ||
| public ListAssert<VariableInstance> variables() { | ||
| isNotNull(); | ||
|
|
||
| return assertThat(processServicesProvider.getRuntimeService().createVariableInstanceQuery().processInstanceId(actual.getId()).orderByVariableName().asc().list()); | ||
| } | ||
|
|
||
| /** | ||
| * Assert list of <b>runtime</b> identity links without ordering. | ||
| * | ||
| * @return Assertion of #{@link IdentityLink} list. | ||
| */ | ||
| public ListAssert<IdentityLink> identityLinks() { | ||
| isNotNull(); | ||
|
|
||
| return assertThat(processServicesProvider.getRuntimeService().getIdentityLinksForProcessInstance(actual.getId())); | ||
| } | ||
|
|
||
| /** | ||
| * Assert list of user tasks in the <b>runtime</b> ordered by the task name ascending. | ||
| * | ||
| * @return Assertion of {@link Task} list. | ||
| */ | ||
| public ListAssert<Task> userTasks() { | ||
| isNotNull(); | ||
|
|
||
| return assertThat(getTaskService().createTaskQuery().processInstanceId(actual.getId()).orderByTaskName().asc() | ||
| .includeProcessVariables().includeIdentityLinks().includeTaskLocalVariables().list()); | ||
| } | ||
|
|
||
| /** | ||
| * Assert list of event subscriptions in the <b>runtime</b> ordered by the event name ascending. | ||
| * | ||
| * @return Assertion of {@link EventSubscription} list. | ||
| */ | ||
|
|
||
| public ListAssert<EventSubscription> eventSubscription() { | ||
| isNotNull(); | ||
|
|
||
| return assertThat(processServicesProvider.getRuntimeService().createEventSubscriptionQuery().processInstanceId(actual.getId()).orderByEventName().asc().list()); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.