Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zambrovski committed Oct 9, 2023
1 parent f6966a1 commit d083856
Showing 1 changed file with 60 additions and 65 deletions.
125 changes: 60 additions & 65 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Add the following dependency to your Maven pom:
<dependency>
<groupId>io.holunda.testing</groupId>
<artifactId>camunda-bpm-jgiven</artifactId>
<version>0.4.0</version>
<version>1.20.0</version>
<scope>test</scope>
</dependency>
```
Expand All @@ -39,17 +39,18 @@ Stages contain assert and action methods and may be subclassed. This library pro
`ProcessStage` for building your process testing stages. Here is how the test then looks like
(written in Kotlin):

### JUnit4
### JUnit5

```kotlin
@Deployment(resources = [ApprovalProcessBean.RESOURCE])
open class ApprovalProcessTest : ScenarioTest<ApprovalProcessActionStage, ApprovalProcessActionStage, ApprovalProcessThenStage>() {
internal class ApprovalProcessTest :
ScenarioTest<ApprovalProcessActionStage, ApprovalProcessActionStage, ApprovalProcessThenStage>() {

@get: Rule
val rule: ProcessEngineRule = StandaloneInMemoryTestConfiguration().rule()
@RegisterExtension
val extension = TestProcessEngine.DEFAULT

@ScenarioState
val camunda = rule.processEngine
val camunda = extension.processEngine

@Test
fun`should automatically approve`() {
Expand Down Expand Up @@ -77,49 +78,46 @@ open class ApprovalProcessTest : ScenarioTest<ApprovalProcessActionStage, Approv
}
```

If you want to collect process test coverage during the test run, make sure to replace your rule declaration by the following:
Here is the corresponding stage, providing the steps used in the test:

```kotlin
companion object {
@get: ClassRule
@JvmStatic
val processEngineRule: ProcessEngineRule = TestCoverageProcessEngineRuleBuilder.create().build()
}

@get:Rule
val rule: ProcessEngineRule = processEngineRule

```
class ApprovalProcessActionStage : ProcessStage<ApprovalProcessActionStage, ApprovalProcessBean>() {

and add the following content into your `camunda.cfg.xml`:
@BeforeStage
fun `automock all delegates`() {
CamundaMockito.registerJavaDelegateMock(DETERMINE_APPROVAL_STRATEGY)
CamundaMockito.registerJavaDelegateMock(AUTOMATICALLY_APPROVE_REQUEST)
CamundaMockito.registerJavaDelegateMock(ApprovalProcessBean.Expressions.LOAD_APPROVAL_REQUEST)
}

```xml
<?xml version="1.0" encoding="UTF-8"?>
fun process_is_started_for_request(approvalRequestId: String) = step {
processInstanceSupplier = ApprovalProcessBean(camunda.processEngine)
processInstanceSupplier.start(approvalRequestId)
assertThat(processInstanceSupplier.processInstance).isNotNull
assertThat(processInstanceSupplier.processInstance).isStarted
}

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
fun approval_strategy_can_be_applied(approvalStrategy: String) = step {
getJavaDelegateMock(DETERMINE_APPROVAL_STRATEGY).onExecutionSetVariables(Variables.putValue(APPROVAL_STRATEGY, approvalStrategy))
}

<bean id="processEngineConfiguration"
class="org.camunda.community.process_test_coverage.engine.platform7.ProcessCoverageInMemProcessEngineConfiguration">
<property name="history" value="full"/>
</bean>
</beans>
fun automatic_approval_returns(approvalDecision: String) = step {
getJavaDelegateMock(AUTOMATICALLY_APPROVE_REQUEST).onExecutionSetVariables(Variables.putValue(APPROVAL_DECISION, approvalDecision))
}
}
```


### JUnit5
### JUnit4

```kotlin
@Deployment(resources = [ApprovalProcessBean.RESOURCE])
internal class ApprovalProcessTest :
ScenarioTest<ApprovalProcessActionStage, ApprovalProcessActionStage, ApprovalProcessThenStage>() {
open class ApprovalProcessTest : ScenarioTest<ApprovalProcessActionStage, ApprovalProcessActionStage, ApprovalProcessThenStage>() {

@RegisterExtension
val extension = TestProcessEngine.DEFAULT
@get: Rule
val rule: ProcessEngineRule = StandaloneInMemoryTestConfiguration().rule()

@ScenarioState
val camunda = extension.processEngine
val camunda = rule.processEngine

@Test
fun`should automatically approve`() {
Expand Down Expand Up @@ -147,35 +145,37 @@ internal class ApprovalProcessTest :
}
```

Here is the corresponding stage, providing the steps used in the test:
If you want to collect process test coverage during the test run, make sure to replace your rule declaration by the following:

```kotlin
class ApprovalProcessActionStage : ProcessStage<ApprovalProcessActionStage, ApprovalProcessBean>() {
companion object {
@get: ClassRule
@JvmStatic
val processEngineRule: ProcessEngineRule = TestCoverageProcessEngineRuleBuilder.create().build()
}

@BeforeStage
fun `automock all delegates`() {
CamundaMockito.registerJavaDelegateMock(DETERMINE_APPROVAL_STRATEGY)
CamundaMockito.registerJavaDelegateMock(AUTOMATICALLY_APPROVE_REQUEST)
CamundaMockito.registerJavaDelegateMock(ApprovalProcessBean.Expressions.LOAD_APPROVAL_REQUEST)
}
@get:Rule
val rule: ProcessEngineRule = processEngineRule

fun process_is_started_for_request(approvalRequestId: String) = step {
processInstanceSupplier = ApprovalProcessBean(camunda.processEngine)
processInstanceSupplier.start(approvalRequestId)
assertThat(processInstanceSupplier.processInstance).isNotNull
assertThat(processInstanceSupplier.processInstance).isStarted
}
```

fun approval_strategy_can_be_applied(approvalStrategy: String) = step {
getJavaDelegateMock(DETERMINE_APPROVAL_STRATEGY).onExecutionSetVariables(Variables.putValue(APPROVAL_STRATEGY, approvalStrategy))
}
and add the following content into your `camunda.cfg.xml`:

fun automatic_approval_returns(approvalDecision: String) = step {
getJavaDelegateMock(AUTOMATICALLY_APPROVE_REQUEST).onExecutionSetVariables(Variables.putValue(APPROVAL_DECISION, approvalDecision))
}
}
```xml
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

<bean id="processEngineConfiguration"
class="org.camunda.community.process_test_coverage.engine.platform7.ProcessCoverageInMemProcessEngineConfiguration">
<property name="history" value="full"/>
</bean>
</beans>
```


The resulting report:

![JGiven Process Report](docs/report.png)
Expand All @@ -185,7 +185,10 @@ Interested? Check out the examples.

## License

APACHE 2.0
This library is developed under

[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](/LICENSE)


## Contribution

Expand All @@ -201,11 +204,3 @@ If you have permissions to release, make sure all branches are fetched and run:
from cli. This will update the poms of `develop` and `master` branches
and start GitHub actions producing a new release.


### Current maintainers

* [Simon Zambrovski](https://github.com/zambrovski)
* [Simon Sprünker](https://github.com/srsp)
* [Jan Galinski](https://github.com/jangalinski)
* [Andre Hegerath](https://github.com/a-hegerath)
* [Stefan Zilske](https://github.com/stefanzilske)

0 comments on commit d083856

Please sign in to comment.