JBPM 6 - 2.0.1 - Eclipse Overview
Jump to navigation
Jump to search
JBPM 6 - 2.0.1 - Eclipse Overview
Sample jBPM Project
- Start eclipse using ant
$ ant start.eclipse
- Create new jBPM project, include sample project
ProcesTest.java file:
public class ProcessTest extends JbpmJUnitBaseTestCase {
@Test
public void testProcess() {
RuntimeManager manager = createRuntimeManager("sample.bpmn");
RuntimeEngine engine = getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
ProcessInstance processInstance = ksession.startProcess("com.sample.bpmn.hello");
// check whether the process instance has completed successfully
assertProcessInstanceCompleted(processInstance.getId(), ksession);
assertNodeTriggered(processInstance.getId(), "Hello");
manager.disposeRuntimeEngine(engine);
manager.close();
}
}
Sample.bpmn file:
- Run the project (Menu: Run / Run or Ctrl-F11) and check Console and JUnit windows
More Advanced jBPM Project
Scenario: A salesman will get a bonus if his sales is over 1000.
BPMN file
- Create new jBPM project (or open 04.1.2_exercise project)
- Change diagram file name to Bonus.bpmn2
- Add sales variable
- Properties Window/Data Items/Variable List for Process/Add
- Add conditions
- sales>1000
- else - default flow
- Define script tasks
- Congratulation!
System.out.println("You are the best!");
- Try harder!
System.out.println("Maybe next time.");
ProcessTest.java file
- Write Unit Test - add code to ProcessTest class
- Import Man and HashMap (import java.util.HashMap;, import java.util.Map;)
- Run project and check what happens if sales is 20000. Is bonus assigned? Check JUnit Window.
Map<String, Object> params = new HashMap<String, Object>();
params.put("sales", 20000);
ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
assertNodeTriggered(processInstance.getId(),"Bonus Assigned");
assertProcessInstanceCompleted(processInstance.getId(), ksession);
- The final code
public class ProcessTest extends JbpmJUnitBaseTestCase {
@Test
public void testProcess() throws Exception {
createRuntimeManager("Bonus.bpmn2");
RuntimeEngine engine = getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
Map<String, Object> params = new HashMap<String, Object>();
params.put("sales", 20000);
ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
assertNodeTriggered(processInstance.getId(),"Bonus Assigned");
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
}
- Add another test
Solution
/**
* Copyright NobleProg Ltd
* Author: Filip Stachecki (filip@nobleprog.pl)
* more info: http://www.nobleprog.co.uk
*/
package com.nobleprog;
import java.util.HashMap;
import java.util.Map;
import org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler;
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.process.ProcessInstance;
import org.kie.internal.KnowledgeBase;
import org.kie.internal.runtime.StatefulKnowledgeSession;
public class ProcessTest extends JbpmJUnitBaseTestCase {
@Test
public void testProcess() throws Exception {
createRuntimeManager("Bonus.bpmn2");
RuntimeEngine engine = getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
Map<String, Object> params = new HashMap<String, Object>();
params.put("sales", 20000);
ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
assertNodeTriggered(processInstance.getId(),"Bonus Assigned");
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
@Test
public void testProcessNoBonus() throws Exception {
createRuntimeManager("Bonus.bpmn2");
RuntimeEngine engine = getRuntimeEngine(null);
KieSession ksession = engine.getKieSession();
Map<String, Object> params = new HashMap<String, Object>();
params.put("sales", 500);
ProcessInstance processInstance = ksession.startProcess("com.sample.test", params);
assertNodeTriggered(processInstance.getId(),"No Bonus");
assertProcessInstanceCompleted(processInstance.getId(), ksession);
}
}
Exercises
- 04.1_exclusive_gateway
- 04.1.2_exercise
- 04.2_inclusive_gateway
- 04.2.1_exercise
- Parallel gateway
- 04.3_parallel_exercise
- 05_timer_delay
- 05.1_timer_delay
- 05.1.1_exercise_timer_delay