use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testTimerStartCron.
@Test(timeout = 15000)
public void testTimerStartCron() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 5);
KieBase kbase = createKnowledgeBase("BPMN2-TimerStartCron.bpmn2");
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void afterProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
// Timer in the process takes 1s, so after 5 seconds, there should be 5 process IDs in the list.
countDownListener.waitTillCompleted();
assertThat(getNumberOfProcessInstances("Minimal")).isEqualTo(5);
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class StartEventTest method testTimerStartDateISO.
@Test(timeout = 10000)
public void testTimerStartDateISO() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("StartProcess", 1);
byte[] content = IoUtils.readBytesFromInputStream(this.getClass().getResourceAsStream("/BPMN2-TimerStartDate.bpmn2"));
String processContent = new String(content, "UTF-8");
OffsetDateTime plusTwoSeconds = OffsetDateTime.now().plusSeconds(2);
processContent = processContent.replaceFirst("#\\{date\\}", plusTwoSeconds.toString());
Resource resource = ResourceFactory.newReaderResource(new StringReader(processContent));
resource.setSourcePath("/BPMN2-TimerStartDate.bpmn2");
resource.setTargetPath("/BPMN2-TimerStartDate.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(resource);
ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
assertThat(list.size()).isEqualTo(0);
countDownListener.waitTillCompleted();
assertThat(list.size()).isEqualTo(1);
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class DynamicProcessTest method testDynamicProcess.
@Test
public void testDynamicProcess() throws Exception {
RuleFlowProcessFactory factory = RuleFlowProcessFactory.createProcess("org.jbpm.HelloWorld");
factory.name("HelloWorldProcess").version("1.0").packageName("org.jbpm").startNode(1).name("Start").done().humanTaskNode(2).name("Task1").actorId("krisv").taskName("MyTask").done().endNode(3).name("End").done().connection(1, 2).connection(2, 3);
final RuleFlowProcess process = factory.validate().getProcess();
Resource resource = ResourceFactory.newByteArrayResource(XmlRuleFlowProcessDumper.INSTANCE.dump(process).getBytes());
// source path or target path must be set to be added into kbase
resource.setSourcePath("/tmp/dynamicProcess.bpmn2");
KieBase kbase = createKnowledgeBaseFromResources(resource);
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
TestWorkItemHandler testHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler("Human Task", testHandler);
ksession.addEventListener(new ProcessEventListener() {
public void beforeVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void beforeProcessStarted(ProcessStartedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeProcessCompleted(ProcessCompletedEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent arg0) {
logger.info("{}", arg0);
}
public void beforeNodeLeft(ProcessNodeLeftEvent arg0) {
logger.info("{}", arg0);
}
public void afterVariableChanged(ProcessVariableChangedEvent arg0) {
}
public void afterProcessStarted(ProcessStartedEvent arg0) {
}
public void afterProcessCompleted(ProcessCompletedEvent arg0) {
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent arg0) {
}
public void afterNodeLeft(ProcessNodeLeftEvent arg0) {
}
});
final ProcessInstanceImpl processInstance = (ProcessInstanceImpl) ksession.startProcess("org.jbpm.HelloWorld");
HumanTaskNode node = new HumanTaskNode();
node.setName("Task2");
node.setId(4);
insertNodeInBetween(process, 2, 3, node);
((CommandBasedStatefulKnowledgeSession) ksession).getRunner().execute(new ExecutableCommand<Void>() {
public Void execute(Context context) {
StatefulKnowledgeSession ksession = (StatefulKnowledgeSession) ((RegistryContext) context).lookup(KieSession.class);
((ProcessInstanceImpl) ksession.getProcessInstance(processInstance.getId())).updateProcess(process);
return null;
}
});
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceActive(processInstance);
ksession.getWorkItemManager().completeWorkItem(testHandler.getWorkItem().getId(), null);
assertProcessInstanceFinished(processInstance, ksession);
ksession.dispose();
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class TimerCycleOnBinaryPackageTest method testStartTimerCycleFromDisc.
@Test(timeout = 20000)
public void testStartTimerCycleFromDisc() throws Exception {
NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
KieBase kbase = createKnowledgeBaseFromDisc("BPMN2-StartTimerCycle.bpmn2");
try {
StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);
ksession.addEventListener(countDownListener);
assertEquals(0, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
long sessionId = ksession.getIdentifier();
Environment env = ksession.getEnvironment();
final List<Long> list = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
assertEquals(2, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
logger.info("dispose");
ksession.dispose();
countDownListener = new NodeLeftCountDownProcessEventListener("start", 2);
ksession = JPAKnowledgeService.loadStatefulKnowledgeSession(sessionId, kbase, null, env);
ksession.addEventListener(countDownListener);
AuditLoggerFactory.newInstance(Type.JPA, ksession, null);
final List<Long> list2 = new ArrayList<Long>();
ksession.addEventListener(new DefaultProcessEventListener() {
public void beforeProcessStarted(ProcessStartedEvent event) {
list2.add(event.getProcessInstance().getId());
}
});
((SingleSessionCommandService) ((CommandBasedStatefulKnowledgeSession) ksession).getRunner()).getKieSession().addEventListener(new TriggerRulesEventListener(ksession));
countDownListener.waitTillCompleted();
assertEquals(4, getNumberOfProcessInstances("defaultPackage.TimerProcess"));
abortProcessInstances(ksession);
ksession.dispose();
} finally {
ksession = createKnowledgeSession(kbase);
abortProcessInstances(ksession);
ksession.dispose();
}
}
use of org.kie.api.event.process.ProcessStartedEvent in project jbpm by kiegroup.
the class IdentityProviderAwareProcessListenerTest method testUserNotSet.
@Test
public void testUserNotSet() {
final WorkflowProcessInstance processInstance = mock(WorkflowProcessInstance.class);
final HashMap<String, Object> metaData = new HashMap<>();
when(processInstance.getMetaData()).thenReturn(metaData);
final ProcessStartedEvent event = new ProcessStartedEventImpl(processInstance, mock(KieRuntime.class));
listener.beforeProcessStarted(event);
assertTrue(metaData.isEmpty());
verify(processInstance, never()).setVariable(anyString(), anyString());
}
Aggregations