diff --git a/snippets/eventsubprocessresume/README.md b/snippets/eventsubprocessresume/README.md new file mode 100644 index 0000000000..29a557763b --- /dev/null +++ b/snippets/eventsubprocessresume/README.md @@ -0,0 +1,5 @@ +## How it works + +This example shows how you can resume the normal process flow after having it interrupted by an event based sub process. + +It uses Camunda's [process instance modification API](https://docs.camunda.org/manual/7.10/user-guide/process-engine/process-instance-modification/). \ No newline at end of file diff --git a/snippets/eventsubprocessresume/pom.xml b/snippets/eventsubprocessresume/pom.xml new file mode 100644 index 0000000000..afb0c7972a --- /dev/null +++ b/snippets/eventsubprocessresume/pom.xml @@ -0,0 +1,189 @@ + + + 4.0.0 + + com.camunda.demo + event-subprocess-resume + 1.0-SNAPSHOT + + Camunda Spring Boot Application + Spring Boot Application using [Camunda](http://docs.camunda.org). [The project has been generated by the Maven archetype 'camunda-archetype-spring-boot-7.10.0'] + + + 7.10.0-ee + + 3.2.0 + 2.1.1.RELEASE + + 1.8 + 1.8 + 1.8 + + UTF-8 + false + + + + + + org.camunda.bpm + camunda-bom + ${camunda.version} + import + pom + + + org.camunda.bpm.dmn + camunda-engine-dmn-bom + ${camunda.version} + pom + import + + + org.springframework.boot + spring-boot-dependencies + ${springBoot.version} + pom + import + + + + + + + org.camunda.bpm.springboot + camunda-bpm-spring-boot-starter-webapp-ee + + ${camundaSpringBoot.version} + + + + org.camunda.bpm.springboot + camunda-bpm-spring-boot-starter-rest + ${camundaSpringBoot.version} + + + + com.h2database + h2 + + + + + org.springframework.boot + spring-boot-starter-jdbc + + + + + org.camunda.spin + camunda-spin-dataformat-all + + + org.camunda.bpm + camunda-engine-plugin-spin + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.camunda.bpm.extension + camunda-bpm-assert + 1.2 + test + + + + org.assertj + assertj-core + 1.7.0 + test + + + org.camunda.bpm.extension + camunda-bpm-assert-scenario + 0.2 + test + + + + org.camunda.bpm.extension + camunda-bpm-process-test-coverage + 0.3.2 + test + + + + + org.slf4j + jul-to-slf4j + test + + + + + + org.springframework.boot + spring-boot-devtools + + + + + + + camunda-bpm-nexus + Camunda Maven Repository + https://app.camunda.com/nexus/content/groups/public + + + + + + ${project.artifactId} + + + org.springframework.boot + spring-boot-maven-plugin + ${springBoot.version} + + ZIP + + + + + repackage + + + + + + org.codehaus.mojo + exec-maven-plugin + 1.6.0 + + com.camunda.demo.CamundaApplication + + + + + + diff --git a/snippets/eventsubprocessresume/src/main/java/com/camunda/demo/CamundaApplication.java b/snippets/eventsubprocessresume/src/main/java/com/camunda/demo/CamundaApplication.java new file mode 100644 index 0000000000..e8ba045fd6 --- /dev/null +++ b/snippets/eventsubprocessresume/src/main/java/com/camunda/demo/CamundaApplication.java @@ -0,0 +1,13 @@ +package com.camunda.demo; + +import org.camunda.bpm.spring.boot.starter.annotation.EnableProcessApplication; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +@EnableProcessApplication("event-subprocess-resume") +public class CamundaApplication { + public static void main(String... args) { + SpringApplication.run(CamundaApplication.class, args); + } +} diff --git a/snippets/eventsubprocessresume/src/main/java/com/camunda/demo/ResumeInstanceDelegate.java b/snippets/eventsubprocessresume/src/main/java/com/camunda/demo/ResumeInstanceDelegate.java new file mode 100644 index 0000000000..06b4f3170d --- /dev/null +++ b/snippets/eventsubprocessresume/src/main/java/com/camunda/demo/ResumeInstanceDelegate.java @@ -0,0 +1,21 @@ +package com.camunda.demo; + +import org.camunda.bpm.engine.RuntimeService; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.springframework.stereotype.Component; + +@Component +public class ResumeInstanceDelegate implements JavaDelegate { + + @Override + public void execute(DelegateExecution execution) throws Exception { + + RuntimeService runtimeService = execution.getProcessEngineServices().getRuntimeService(); + + runtimeService.createProcessInstanceModification(execution.getProcessInstanceId()).startBeforeActivity("Task_DoThat").execute(); + + // The resume activity could also be resolved dynamically, based on a variable that could be set by a user. + + } +} diff --git a/snippets/eventsubprocessresume/src/main/resources/META-INF/processes.xml b/snippets/eventsubprocessresume/src/main/resources/META-INF/processes.xml new file mode 100644 index 0000000000..e69de29bb2 diff --git a/snippets/eventsubprocessresume/src/main/resources/application.yaml b/snippets/eventsubprocessresume/src/main/resources/application.yaml new file mode 100644 index 0000000000..8adff68a48 --- /dev/null +++ b/snippets/eventsubprocessresume/src/main/resources/application.yaml @@ -0,0 +1,15 @@ +spring.datasource: + url: jdbc:h2:./camunda-db;DB_CLOSE_DELAY=-1;MVCC=TRUE;DB_CLOSE_ON_EXIT=FALSE +#shareable h2 database: jdbc:h2:./camunda-db;DB_CLOSE_DELAY=-1;MVCC=TRUE;DB_CLOSE_ON_EXIT=FALSE;AUTO_SERVER=TRUE + username: sa + password: sa +spring.h2.console.enabled: true +camunda.bpm: + admin-user: + id: demo + password: demo + firstName: Demo + lastName: Demo + filter: + create: All Tasks +server.port: 8080 diff --git a/snippets/eventsubprocessresume/src/main/resources/process.bpmn b/snippets/eventsubprocessresume/src/main/resources/process.bpmn new file mode 100644 index 0000000000..44379a1885 --- /dev/null +++ b/snippets/eventsubprocessresume/src/main/resources/process.bpmn @@ -0,0 +1,159 @@ + + + + + SequenceFlow1 + + + SequenceFlow_1aerq1d + + + + + SequenceFlow1 + SequenceFlow_057pe5c + + + + SequenceFlow_057pe5c + SequenceFlow_1aerq1d + + + + SequenceFlow_0m3ur7d + + + + + SequenceFlow_1k2jypl + SequenceFlow_0dpfwn5 + SequenceFlow_0j6fv68 + + + + SequenceFlow_0dpfwn5 + + + ${cancel} + + + ${not cancel} + + + SequenceFlow_1tsi26q + + + + SequenceFlow_0j6fv68 + SequenceFlow_1tsi26q + + + + + + + + SequenceFlow_0m3ur7d + SequenceFlow_1k2jypl + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/snippets/eventsubprocessresume/src/test/java/com/camunda/demo/ProcessTest.java b/snippets/eventsubprocessresume/src/test/java/com/camunda/demo/ProcessTest.java new file mode 100644 index 0000000000..2fc7874419 --- /dev/null +++ b/snippets/eventsubprocessresume/src/test/java/com/camunda/demo/ProcessTest.java @@ -0,0 +1,77 @@ +package com.camunda.demo; + +import org.apache.ibatis.logging.LogFactory; +import org.camunda.bpm.engine.ProcessEngine; +import org.camunda.bpm.engine.runtime.ProcessInstance; +import org.camunda.bpm.engine.test.Deployment; +import org.camunda.bpm.engine.test.ProcessEngineRule; +import org.camunda.bpm.extension.process_test_coverage.junit.rules.TestCoverageProcessEngineRuleBuilder; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.*; +import static org.junit.Assert.*; + +import javax.annotation.PostConstruct; + +/** + * Test case starting an in-memory database-backed Process Engine. + */ +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.NONE) +public class ProcessTest { + + private static final String PROCESS_DEFINITION_KEY = "event-subprocess-resume"; + + @Autowired + private ProcessEngine processEngine; + + static { + LogFactory.useSlf4jLogging(); // MyBatis + } + + @Rule @ClassRule + public static ProcessEngineRule rule; + + @PostConstruct + void initRule() { + rule = TestCoverageProcessEngineRuleBuilder.create(processEngine).build(); + } + + @Before + public void setup() { + init(processEngine); + } + + @Test + @Deployment(resources="process.bpmn") + public void shouldDeploy(){} + + @Test + @Deployment(resources="process.bpmn") // only required for process test coverage + public void shouldRunHappyPath() { + + ProcessInstance processInstance = processEngine().getRuntimeService().startProcessInstanceByKey(PROCESS_DEFINITION_KEY); + + assertThat(processInstance).isWaitingAt("Task_DoThis"); + runtimeService().correlateMessage("cancel_instance"); + + assertThat(processInstance).isWaitingAt("Task_CheckCancellation"); + complete(task(),withVariables("cancel", false)); + + assertThat(processInstance).isWaitingAt("Task_DoThat").isWaitingAt("Task_ResumeProcessInstance"); + execute(job()); // async after + complete(task()); + + assertThat(processInstance).isEnded(); + + } + +} diff --git a/snippets/eventsubprocessresume/src/test/java/com/camunda/demo/ProcessTestCoverageProcessEnginePlugin.java b/snippets/eventsubprocessresume/src/test/java/com/camunda/demo/ProcessTestCoverageProcessEnginePlugin.java new file mode 100644 index 0000000000..8bf03d536a --- /dev/null +++ b/snippets/eventsubprocessresume/src/test/java/com/camunda/demo/ProcessTestCoverageProcessEnginePlugin.java @@ -0,0 +1,17 @@ +package com.camunda.demo; + +import org.camunda.bpm.engine.impl.cfg.AbstractProcessEnginePlugin; +import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; +import org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin; +import org.camunda.bpm.extension.process_test_coverage.junit.rules.ProcessCoverageConfigurator; +import org.springframework.stereotype.Component; + +@Component +public class ProcessTestCoverageProcessEnginePlugin extends AbstractProcessEnginePlugin implements ProcessEnginePlugin { + + @Override + public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) { + ProcessCoverageConfigurator.initializeProcessCoverageExtensions(processEngineConfiguration); + } + +} diff --git a/snippets/eventsubprocessresume/src/test/resources/application.yaml b/snippets/eventsubprocessresume/src/test/resources/application.yaml new file mode 100644 index 0000000000..96f10aacf9 --- /dev/null +++ b/snippets/eventsubprocessresume/src/test/resources/application.yaml @@ -0,0 +1,8 @@ +# Test configuration using spring-boot + +camunda.bpm: + job-execution.enabled: false + id-generator: simple + +spring.datasource: + url: jdbc:h2:mem:camunda-spring-boot-test;DB_CLOSE_ON_EXIT=false diff --git a/snippets/eventsubprocessresume/src/test/resources/logback-test.xml b/snippets/eventsubprocessresume/src/test/resources/logback-test.xml new file mode 100644 index 0000000000..a2484ac0eb --- /dev/null +++ b/snippets/eventsubprocessresume/src/test/resources/logback-test.xml @@ -0,0 +1,63 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + + + + + + + + + + + + + + + diff --git a/snippets/eventsubprocessresume/src/test/resources/logging.properties b/snippets/eventsubprocessresume/src/test/resources/logging.properties new file mode 100644 index 0000000000..4941c55971 --- /dev/null +++ b/snippets/eventsubprocessresume/src/test/resources/logging.properties @@ -0,0 +1,2 @@ +#register SLF4JBridgeHandler as handler for the j.u.l. root logger +handlers = org.slf4j.bridge.SLF4JBridgeHandler