<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>mtitek.jbpm.junit.samples</groupId> <artifactId>mtitek-jbpm-junit-samples</artifactId> <version>1.0.0-SNAPSHOT</version> <dependencies> <dependency> <groupId>org.jbpm</groupId> <artifactId>jbpm-test</artifactId> <version>7.28.0.Final</version> <scope>test</scope> </dependency> <dependency> <groupId>org.kie</groupId> <artifactId>kie-api</artifactId> <version>7.28.0.Final</version> <scope>test</scope> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>1.7.28</version> <scope>test</scope> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>1.2.3</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.1</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> </project>
src/test/resources/mtitek/jbpm/junit/samples/sample.bpmn
<?xml version="1.0" encoding="UTF-8"?> <definitions id="Definition" targetNamespace="http://www.jboss.org/drools" typeLanguage="http://www.java.com/javaTypes" expressionLanguage="http://www.mvel.org/2.0" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xmlns:di="http://www.omg.org/spec/DD/20100524/DI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd"> <process id="mtitek.jbpm.junit.samples.hello" name="Hello jBPM World" processType="Private" isExecutable="true"> <startEvent id="startEventId" /> <scriptTask id="scriptTaskId" name="Hello"> <script>System.out.println("Hello jBPM World!!!");</script> </scriptTask> <endEvent id="endEventId"> <terminateEventDefinition /> </endEvent> <sequenceFlow id="startEvent-scriptTask" sourceRef="startEventId" targetRef="scriptTaskId" /> <sequenceFlow id="scriptTask-endEvent" sourceRef="scriptTaskId" targetRef="endEventId" /> </process> <bpmndi:BPMNDiagram> <bpmndi:BPMNPlane bpmnElement="mtitek.jbpm.junit.samples.hello"> <bpmndi:BPMNShape bpmnElement="scriptTaskId"> <dc:Bounds x="96" y="16" width="80" height="48" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="startEventId"> <dc:Bounds x="30" y="22" width="36" height="36" /> </bpmndi:BPMNShape> <bpmndi:BPMNShape bpmnElement="endEventId"> <dc:Bounds x="210" y="22" width="36" height="36" /> </bpmndi:BPMNShape> <bpmndi:BPMNEdge bpmnElement="startEvent-scriptTask"> <di:waypoint x="66" y="40" /> <di:waypoint x="96" y="40" /> </bpmndi:BPMNEdge> <bpmndi:BPMNEdge bpmnElement="scriptTask-endEvent"> <di:waypoint x="176" y="40" /> <di:waypoint x="210" y="40" /> </bpmndi:BPMNEdge> </bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
src/test/resources/META-INF/kmodule.xml
<kmodule xmlns="http://www.drools.org/xsd/kmodule"> <kbase name="kbase" packages="mtitek.jbpm.junit.samples" /> </kmodule>
src/test/resources/logback-test.xml
<configuration> <appender name="console" class="ch.qos.logback.core.ConsoleAppender"> <target>System.out</target> <encoder> <pattern>[%d{HH:mm:ss,SSS}] %p [%c: %L] %m%n</pattern> </encoder> </appender> <logger name="mtitek.jbpm.junit.samples" level="debug" /> <root level="debug"> <appender-ref ref="console" /> </root> </configuration>
src/test/java/mtitek/jbpm/junit/samples/ProcessTest.java
package mtitek.jbpm.junit.samples; import org.jbpm.test.JbpmJUnitBaseTestCase; import org.junit.Test; import org.kie.api.runtime.KieSession; import org.kie.api.runtime.manager.RuntimeEngine; import org.kie.api.runtime.manager.RuntimeManager; import org.kie.api.runtime.process.ProcessInstance; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class ProcessTest extends JbpmJUnitBaseTestCase { private static final Logger LOG = LoggerFactory.getLogger(ProcessTest.class); @Test public void test() { ProcessTest.LOG.debug("jBPM unit test sample"); final RuntimeManager runtimeManager = createRuntimeManager("mtitek/jbpm/junit/samples/sample.bpmn"); final RuntimeEngine runtimeEngine = getRuntimeEngine(null); final KieSession kieSession = runtimeEngine.getKieSession(); final ProcessInstance processInstance = kieSession.startProcess("mtitek.jbpm.junit.samples.hello"); assertProcessInstanceNotActive(processInstance.getId(), kieSession); assertNodeTriggered(processInstance.getId(), "Hello"); runtimeManager.disposeRuntimeEngine(runtimeEngine); runtimeManager.close(); } }