Skip to content
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

#3835 fluent assertions #3837

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions modules/flowable-assertions/flowable-process-assertions/pom.xml
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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.flowable.assertions.process;
martin-grofcik marked this conversation as resolved.
Show resolved Hide resolved

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);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.flowable.assertions.process;

import static org.assertj.core.api.Assertions.assertThat;
import static org.flowable.assertions.process.Utils.getProcessDescription;
import static org.flowable.assertions.process.Utils.getProcessEngine;

import org.assertj.core.api.AbstractAssert;
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;

/**
* @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.");
}

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);
}

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();
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.");
}
}

}
Loading
Loading