Skip to content

Commit

Permalink
Merge branch 'release/0.4.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jangalinski committed Mar 16, 2023
2 parents b4d9cb8 + 5040021 commit 7a51d71
Show file tree
Hide file tree
Showing 24 changed files with 613 additions and 260 deletions.
9 changes: 9 additions & 0 deletions .codacy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
engines:
duplications:
exclude_paths:
- "**/src/test/kotlin/**"
exclude_paths:
- "README.md"
- ".github/**"
- "docs/**"
19 changes: 9 additions & 10 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,23 @@ jobs:
steps:

- name: Checkout code
uses: actions/checkout@v1

- name: Cache .m2
uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven
uses: actions/checkout@v3

- name: Set up JDK
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: ${{ matrix.jdk }}
distribution: zulu
cache: maven

- name: Prepare Maven Wrapper
run: chmod +x ./mvnw

- name: Build with Maven
run: ./mvnw clean verify -U -B -T4

# - name: Upload test coverage to Codacy
# if: github.event_name == 'push' && github.actor != 'dependabot[bot]'
# run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
# env:
# CODACY_PROJECT_TOKEN: "${{secrets.CODACY_PROJECT_TOKEN}}"
25 changes: 13 additions & 12 deletions .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,22 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v1

- name: Cache .m2
uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven
uses: actions/checkout@v3

# Get GPG private key into GPG
- name: Import GPG Owner Trust
run: echo ${{ secrets.GPG_OWNERTRUST }} | base64 --decode | gpg --import-ownertrust

- name: Import GPG key
run: echo ${{ secrets.GPG_SECRET_KEYS }} | base64 --decode | gpg --import --no-tty --batch --yes

# Setup JDK and Maven
- name: Set up JDK 11
uses: actions/setup-java@v1
uses: actions/setup-java@v3
with:
java-version: 11.0.5
distribution: zulu
cache: maven
server-id: ossrh
server-username: OSS_CENTRAL_USERNAME # env variable for Maven Central
server-password: OSS_CENTRAL_PASSWORD # env variable for Maven Central
Expand All @@ -44,5 +39,11 @@ jobs:
- name: Deploy a new version to central
run: ./mvnw clean deploy -B -DskipTests -DskipExamples -Prelease -Dgpg.keyname="${{secrets.GPG_KEYNAME}}" -Dgpg.passphrase="${{secrets.GPG_PASSPHRASE}}"
env:
OSS_CENTRAL_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
OSS_CENTRAL_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
OSS_CENTRAL_USERNAME: "${{ secrets.SONATYPE_USERNAME }}"
OSS_CENTRAL_PASSWORD: "${{ secrets.SONATYPE_PASSWORD }}"

# - name: Upload test coverage to Codacy
# if: github.event_name == 'push' && github.actor != 'dependabot[bot]'
# run: bash <(curl -Ls https://coverage.codacy.com/get.sh)
# env:
# CODACY_PROJECT_TOKEN: "${{secrets.CODACY_PROJECT_TOKEN}}"
19 changes: 18 additions & 1 deletion .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.4/apache-maven-3.5.4-bin.zip
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
38 changes: 34 additions & 4 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.2.0</version>
<version>0.4.0</version>
<scope>test</scope>
</dependency>
```
Expand All @@ -52,7 +52,7 @@ open class ApprovalProcessTest : ScenarioTest<ApprovalProcessActionStage, Approv
val camunda = rule.processEngine

@Test
internal fun `should automatically approve`() {
fun`should automatically approve`() {

val approvalRequestId = UUID.randomUUID().toString()

Expand All @@ -77,10 +77,40 @@ 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:

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

@get:Rule
val rule: ProcessEngineRule = processEngineRule

```

and add the following content into your `camunda.cfg.xml`:

```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>
```


### JUnit5

```kotlin
@ExtendWith(ProcessEngineExtension::class)
@Deployment(resources = [ApprovalProcessBean.RESOURCE])
internal class ApprovalProcessTest :
ScenarioTest<ApprovalProcessActionStage, ApprovalProcessActionStage, ApprovalProcessThenStage>() {
Expand All @@ -92,7 +122,7 @@ internal class ApprovalProcessTest :
val camunda = extension.processEngine

@Test
internal fun `should automatically approve`() {
fun`should automatically approve`() {

val approvalRequestId = UUID.randomUUID().toString()

Expand Down
9 changes: 7 additions & 2 deletions examples/basic-junit5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>io.holunda.testing</groupId>
<artifactId>camunda-bpm-jgiven-examples</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</parent>

<artifactId>camunda-bpm-jgiven-examples-basic-junit5</artifactId>
Expand All @@ -21,6 +21,11 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.camunda.community.mockito</groupId>
<artifactId>camunda-platform-7-mockito</artifactId>
Expand Down Expand Up @@ -48,7 +53,7 @@
</dependency>
<dependency>
<groupId>org.camunda.community.process_test_coverage</groupId>
<artifactId>camunda-process-test-coverage-junit4-platform-7</artifactId>
<artifactId>camunda-process-test-coverage-junit5-platform-7</artifactId>
<version>${camunda-process-test-coverage.version}</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import org.camunda.bpm.engine.ProcessEngine
import org.camunda.bpm.engine.runtime.ProcessInstance
import java.util.function.Supplier

class ApprovalProcessBean(private val processEngine: ProcessEngine) : Supplier<ProcessInstance> {
/**
* Process backing bean.
*/
class ApprovalProcessBean(
private val processEngine: ProcessEngine
) : Supplier<ProcessInstance> {

companion object {
const val KEY = "approval"
Expand All @@ -15,6 +20,9 @@ class ApprovalProcessBean(private val processEngine: ProcessEngine) : Supplier<P

override fun get(): ProcessInstance = this.processInstance

/**
* BPMN elements.
*/
object Elements {
const val START = "start"
const val END_CANCELLED = "end_cancelled"
Expand All @@ -25,6 +33,9 @@ class ApprovalProcessBean(private val processEngine: ProcessEngine) : Supplier<P
const val SERVICE_AUTO_APPROVE = "service_auto_approve_request"
}

/**
* Process variables.
*/
object Variables {
const val APPROVAL_REQUEST_ID = "approvalRequestId"
const val APPROVAL_STRATEGY = "approvalStrategy"
Expand All @@ -33,30 +44,45 @@ class ApprovalProcessBean(private val processEngine: ProcessEngine) : Supplier<P
const val ORIGINATOR = "originator"
}

/**
* Expressions used in BPMN.
*/
object Expressions {
const val LOAD_APPROVAL_REQUEST = "loadApprovalRequest"
const val DETERMINE_APPROVAL_STRATEGY = "determineApprovalStrategy"
const val AUTOMATICALLY_APPROVE_REQUEST = "automaticallyApproveRequest"
const val AUTOMATIC_APPROVAL_FAILED = "automaticApprovalFailed"
const val APPROVE_REQUEST_TASK_LISTENER = "approveRequestTaskListener"

/**
* Values for approval strategy.
*/
object ApprovalStrategy {
const val AUTOMATIC = "AUTOMATIC"
const val MANUAL = "MANUAL"
}

/**
* Values for approval decision.
*/
object ApprovalDecision {
const val APPROVE = "APPROVE"
const val REJECT = "REJECT"
const val RETURN = "RETURN"
}

/**
* Values for amend decision.
*/
object AmendAction {
const val RESUBMIT = "RESUBMIT"
const val CANCEL = "CANCEL"
}
}

/**
* Starts the business process.
*/
fun start(approvalRequestId: String) {
this.processInstance = this.processEngine.runtimeService.startProcessInstanceByKey(
KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ import org.springframework.context.annotation.Bean
import java.time.temporal.ChronoUnit
import java.util.*

/**
* Starts the application.
*/
fun main(args: Array<String>) = runApplication<BasicProcessApplication>(*args).let { Unit }

/**
* Main application class.
*/
@EnableProcessApplication
class BasicProcessApplication {

/**
* Listener setting follow-up date.
*/
@Bean(APPROVE_REQUEST_TASK_LISTENER)
fun approveRequestTaskListener() = TaskListener {
it.followUpDate = Date.from(it.createTime.toInstant().plus(1, ChronoUnit.DAYS))
Expand Down
2 changes: 1 addition & 1 deletion examples/basic-junit5/src/main/resources/approval.bpmn
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,4 @@
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
</bpmn:definitions>
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,15 @@ import org.camunda.bpm.engine.variable.Variables.putValue
import org.camunda.community.mockito.DelegateExpressions.getJavaDelegateMock
import org.camunda.community.mockito.DelegateExpressions.registerJavaDelegateMock

/**
* Process stage.
*/
@JGivenProcessStage
class ApprovalProcessActionStage : ProcessStage<ApprovalProcessActionStage, ApprovalProcessBean>() {

/**
* mocks all expressions (delegates) of the process.
*/
@BeforeStage
fun mock_all_delegates() {
registerJavaDelegateMock(DETERMINE_APPROVAL_STRATEGY)
Expand All @@ -32,23 +38,38 @@ class ApprovalProcessActionStage : ProcessStage<ApprovalProcessActionStage, Appr
Mocks.register(APPROVE_REQUEST_TASK_LISTENER, BasicProcessApplication().approveRequestTaskListener())
}

/**
* Starts process.
*/
fun process_is_started_for_request(@Quoted approvalRequestId: String) = step {
processInstanceSupplier = ApprovalProcessBean(camunda)
processInstanceSupplier.start(approvalRequestId)
assertThat(processInstanceSupplier.processInstance).isNotNull
assertThat(processInstanceSupplier.processInstance).isStarted
}

/**
* Determines of the approval strategy can be applied.
*/
@As("\$approvalStrategy approval strategy can be applied")
fun approval_strategy_can_be_applied(@Quoted approvalStrategy: String) = step {
getJavaDelegateMock(DETERMINE_APPROVAL_STRATEGY).onExecutionSetVariables(Variables.putValue(APPROVAL_STRATEGY, approvalStrategy))
getJavaDelegateMock(DETERMINE_APPROVAL_STRATEGY).onExecutionSetVariables(putValue(APPROVAL_STRATEGY, approvalStrategy))
}

/**
* Preloads the automatic approval with result.
*/
fun automatic_approval_returns(approvalResult: String) = step {
external_task_is_completed(externalTask().topicName, putValue(APPROVAL_DECISION, approvalResult))
external_task_is_completed(
externalTask().topicName,
putValue(APPROVAL_DECISION, approvalResult),
)
}

}

/**
* Assert stage.
*/
@JGivenProcessStage
class ApprovalProcessThenStage : ProcessStage<ApprovalProcessThenStage, ApprovalProcessBean>()
Loading

0 comments on commit 7a51d71

Please sign in to comment.