flowable / flowable/flowable-engine
Fluent assertions
- Lingua principale
- Java
- Stelle
- 9.5k
- Fork
- 2.9k
- Merge medio
- 7h 8m
- PR unite (30g)
- 2
Descrizione
**Is your feature request related to a problem? Please describe.**
Assertions are not readable. Instead of:
```
@Test
void followHappyPath(RuntimeService runtimeService, TaskService taskService, HistoryService historyService) {
ProcessInstance helloWorldProcess = runtimeService.createProcessInstanceBuilder().processDefinitionKey("P001-helloWorld").start();
assertThat(helloWorldProcess).isNotNull();
List path = new ArrayList<>(List.of("theStart", "theStart-theSayHelloUserTask", "theSayHelloUserTask"));
assertThat(runtimeService.createActivityInstanceQuery()
.processInstanceId(helloWorldProcess.getId()).orderByActivityInstanceStartTime().asc().list())
.as("The hello world process has to go directly through theStart -> theSayHelloUserTask")
.extracting(ActivityInstance::getActivityId)
.containsExactlyInAnyOrderElementsOf(path);
assertThat(runtimeService.createVariableInstanceQuery().processInstanceId(helloWorldProcess.getId()).list())
.extracting("name", "value")
.containsExactly(Tuple.tuple("initiator", null));
Task userTask = taskService.createTaskQuery().processInstanceId(helloWorldProcess.getId()).singleResult();
assertThat(userTask).extracting(Task::getName).isEqualTo("Say hello world");
assertThat(userTask).extracting(Task::getTaskDefinitionKey).isEqualTo("theSayHelloUserTask");
taskService.complete(userTask.getId(), Map.of("greeting", "Hello World!"));
assertThat(runtimeService.createActivityInstanceQuery().processInstanceId(helloWorldProcess.getId()).singleResult())
.as("The hello world process is finished, no instance is present in the runtime.")
.isNull();
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(helloWorldProcess.getId()).singleResult();
assertThat(historicProcessInstance)
.as("The hello world process must be present in the history")
.isNotNull();
assertThat(historicProcessInstance.getEndTime())
.as("The hello world process must be finished")
.isNotNull();
assertThat(historyService.createHistoricVariableInstanceQuery().processInstanceId(helloWorldProcess.getId()).list())
.as("All variables must be present in the history")
.extracting("name", "value")
.containsExactlyInAnyOrder(Tuple.tuple("initiator", null), Tuple.tuple("greeting", "Hello World!"));
path.addAll(List.of("theSayHelloUserTask-theEnd", "theEnd"));
assertThat(historyService.createHistoricActivityInstanceQuery().processInstanceId(helloWorldProcess.getId()).orderByHistoricActivityInstanceStartTime().asc().list())
.as("The hello world process must pass through all activities")
.extracting(HistoricActivityInstance::getActivityId)
.containsExactlyInAnyOrderElementsOf(path);
}
```
Use:
```
@Test
void followHappyPathWithFluentAssertions(RuntimeService runtimeService, TaskService taskService) {
ProcessInstance helloWorldProcess = runtimeService.createProcessInstanceBuilder().processDefinitionKey("P001-helloWorld").start();
List path = new ArrayList<>(List.of("theStart", "theStart-theSayHelloUserTask", "theSayHelloUserTask"));
assertThat(helloWorldProcess)
.isRunning()
.hasVariableWithValue("initiator", null)
.activities()
.extracting(ActivityInstance::getActivityId)
.containsExactlyInAnyOrderElementsOf(path);
assertThat(helloWorldProcess)
.userTasks()
.extracting("name", "taskDefinitionKey")
.containsExactly(Tuple.tuple("Say hello world", "theSayHelloUserTask"));
Task userTask = taskService.createTaskQuery().processInstanceId(helloWorldProcess.getId()).singleResult();
taskService.complete(userTask.getId(), Map.of("greeting", "Hello World!"));
assertThat(helloWorldProcess)
.as("The hello world process is finished, no instance is present in the runtime.")
.doesNotExist()
.inHistory()
.as("The hello world process must be present in the history and finished")
.isFinished()
.variables()
.as("All variables must be present in the history")
.extracting("name", "value")
.containsExactlyInAnyOrder(Tuple.tuple("initiator", null), Tuple.tuple("greeting", "Hello World!"));
path.addAll(List.of("theSayHelloUserTask-theEnd", "theEnd"));
assertThat(helloWorldProcess).inHistory()
.as("The hello world process must pass through all activities")
.activities()
.extracting(HistoricActivityInstance::getActivityId)
.containsExactlyInAnyOrderElementsOf(path);
}
```
The code can be even more readable in groovy.
https://github.com/crystal-processes/crp-flowable-springboot-sample/blob/main/docs/01_sample/02-helloWorld.md#partly_sunny-what-to-do-next---tests
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Start with the issue's before-and-after followHappyPath examples and the linked helloWorld.md sample. Identify the existing test assertion entry points for process state, activities, user tasks, history, and variables. Done means the fluent chains shown in the requested example are supported and the corresponding sample test can use them successfully.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- java
- Ambito
- testing
- Tipo di issue
- Funzionalità
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100