-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
485 additions
and
97 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
90 changes: 90 additions & 0 deletions
90
impl-8/src/main/java/org/camunda/community/bpmndt/api/CustomMultiInstanceHandler.java
This file contains 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,90 @@ | ||
package org.camunda.community.bpmndt.api; | ||
|
||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
|
||
import org.camunda.community.bpmndt.api.TestCaseInstanceElement.MultiInstanceElement; | ||
|
||
import io.camunda.zeebe.process.test.assertions.BpmnAssert; | ||
import io.camunda.zeebe.process.test.assertions.ProcessInstanceAssert; | ||
|
||
/** | ||
* Fluent API to handle multi instances and multi instance scopes, using custom code. | ||
*/ | ||
public class CustomMultiInstanceHandler { | ||
|
||
private final MultiInstanceElement element; | ||
|
||
private Consumer<ProcessInstanceAssert> verifier; | ||
private BiConsumer<TestCaseInstance, Long> action; | ||
|
||
private Boolean expectedSequential; | ||
|
||
public CustomMultiInstanceHandler(MultiInstanceElement element) { | ||
this.element = element; | ||
} | ||
|
||
void apply(TestCaseInstance instance, long processInstanceKey) { | ||
if (verifier != null) { | ||
verifier.accept(new ProcessInstanceAssert(processInstanceKey, BpmnAssert.getRecordStream())); | ||
} | ||
|
||
if (expectedSequential != null && expectedSequential != element.sequential) { | ||
var message = "expected multi instance %s to be %s, but was %s"; | ||
throw new AssertionError(String.format(message, element.id, getText(expectedSequential), getText(element.sequential))); | ||
} | ||
|
||
if (action != null) { | ||
action.accept(instance, processInstanceKey); | ||
} | ||
} | ||
|
||
/** | ||
* Executes a custom action that handles the multi instance or the multi instance scope. | ||
* | ||
* @param action A specific action that accepts a {@link TestCaseInstance} and the related process instance key. | ||
*/ | ||
public void execute(BiConsumer<TestCaseInstance, Long> action) { | ||
if (action == null) { | ||
throw new IllegalArgumentException("action is null"); | ||
} | ||
this.action = action; | ||
} | ||
|
||
/** | ||
* Verifies the multi instance state. | ||
* <p> | ||
* <b>Please note</b>: An application specific job worker may have already completed the related job and updated some variables. | ||
* | ||
* @param verifier Verifier that accepts an {@link ProcessInstanceAssert} instance. | ||
* @return The handler. | ||
*/ | ||
public CustomMultiInstanceHandler verify(Consumer<ProcessInstanceAssert> verifier) { | ||
this.verifier = verifier; | ||
return this; | ||
} | ||
|
||
/** | ||
* Verifies that the multi instance loop execution is done in parallel. | ||
* | ||
* @return The handler. | ||
*/ | ||
public CustomMultiInstanceHandler verifyParallel() { | ||
this.expectedSequential = Boolean.FALSE; | ||
return this; | ||
} | ||
|
||
/** | ||
* Verifies that the multi instance loop is sequentially executed. | ||
* | ||
* @return The handler. | ||
*/ | ||
public CustomMultiInstanceHandler verifySequential() { | ||
this.expectedSequential = Boolean.TRUE; | ||
return this; | ||
} | ||
|
||
private String getText(boolean sequential) { | ||
return sequential ? "sequential" : "parallel"; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.