use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class SingletonRuntimeManagerTest method testBusinessRuleTask.
@Test
public void testBusinessRuleTask() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.drl"), ResourceType.DRL).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long sessionId = ksession.getIdentifier();
assertTrue(sessionId == 1);
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
assertEquals(sessionId, ksession.getIdentifier());
// start process
ProcessInstance pi = ksession.createProcessInstance("BPMN2-BusinessRuleTask", null);
ksession.insert(pi);
ksession.startProcessInstance(pi.getId());
assertNull(ksession.getProcessInstance(pi.getId()));
AuditService logService = runtime.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("BPMN2-BusinessRuleTask");
assertNotNull(logs);
assertEquals(0, logs.size());
logs = logService.findProcessInstances("BPMN2-BusinessRuleTask");
assertNotNull(logs);
assertEquals(1, logs.size());
// dispose session that should not have affect on the session at all
manager.disposeRuntimeEngine(runtime);
// close manager which will close session maintained by the manager
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class SingletonRuntimeManagerTest method testBusinessRuleTaskWithRuleAwareListener.
@Test
public void testBusinessRuleTaskWithRuleAwareListener() {
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.drl"), ResourceType.DRL).get();
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession ksession = runtime.getKieSession();
assertNotNull(ksession);
long sessionId = ksession.getIdentifier();
assertTrue(sessionId == 1);
runtime = manager.getRuntimeEngine(EmptyContext.get());
ksession = runtime.getKieSession();
assertEquals(sessionId, ksession.getIdentifier());
// start process
ksession.addEventListener(new RuleAwareProcessEventLister());
ProcessInstance pi = ksession.startProcess("BPMN2-BusinessRuleTask");
assertNull(ksession.getProcessInstance(pi.getId()));
AuditService logService = runtime.getAuditService();
List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("BPMN2-BusinessRuleTask");
assertNotNull(logs);
assertEquals(0, logs.size());
logs = logService.findProcessInstances("BPMN2-BusinessRuleTask");
assertNotNull(logs);
assertEquals(1, logs.size());
// dispose session that should not have affect on the session at all
manager.disposeRuntimeEngine(runtime);
// close manager which will close session maintained by the manager
manager.close();
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class TimerInitFailureRuntimeManagerTest method testPerCaseRuntimeManager.
@Test(timeout = 10000)
@BMScript(value = "byteman-scripts/failOnRuntimeManagerInitRules.btm")
public void testPerCaseRuntimeManager() throws Exception {
final NodeLeftCountDownProcessEventListener countDownListener = new NodeLeftCountDownProcessEventListener("Intermediate Catch Event 1", 1);
RuntimeEnvironment environment = createEnvironment(countDownListener);
manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment, "first");
assertNotNull(manager);
RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
KieSession ksession = runtime.getKieSession();
// start a new process instance
Map<String, Object> params = new HashMap<>();
ProcessInstance pi = ksession.startProcess("TimerInitFailure", params);
assertEquals(ProcessInstance.STATE_ACTIVE, pi.getState());
manager.disposeRuntimeEngine(runtime);
countDownListener.waitTillCompleted();
// User access
runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
runtime.getKieSession();
TaskService taskService = runtime.getTaskService();
List<TaskSummary> list = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
assertEquals(1, list.size());
long taskId = list.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
manager.disposeRuntimeEngine(runtime);
runtime = manager.getRuntimeEngine(CaseContext.get("CASE-001"));
AuditService auditService = runtime.getAuditService();
ProcessInstanceLog log = auditService.findProcessInstance(pi.getId());
assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
auditService.dispose();
manager.disposeRuntimeEngine(runtime);
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class MvelResolverDeploymentDescriptorManagerTest method testDeploymentDescriptorFromKieContainer.
@Test
public void testDeploymentDescriptorFromKieContainer() throws IOException {
Map<String, String> resources = new HashMap<String, String>();
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId(GROUP_ID, ARTIFACT_ID, VERSION);
String kmoduleString = IOUtils.toString(this.getClass().getResourceAsStream("/kmodule-custom-wih.xml"), "UTF-8");
resources.put("src/main/resources/META-INF/kmodule.xml", kmoduleString);
String processString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CustomTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CustomTask.bpmn2", processString);
InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
installKjar(releaseId, kJar1);
Properties properties = new Properties();
UserGroupCallback userGroupCallback = new JBossUserGroupCallbackImpl(properties);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
manager.getRuntimeEngine(ProcessInstanceIdContext.get()).getKieSession().startProcess("customtask");
}
use of org.kie.api.runtime.manager.RuntimeEnvironment in project jbpm by kiegroup.
the class RuntimeManagerWithDescriptorTest method testDeployWithFullCustomDeploymentDescriptor.
@Test
public void testDeployWithFullCustomDeploymentDescriptor() throws Exception {
Map<String, String> resources = new HashMap<String, String>();
String scriptString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ScriptTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ScriptTask.bpmn2", scriptString);
String manualString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-ManualTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-ManualTask.bpmn2", manualString);
String userString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-UserTask.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-UserTask.bpmn2", userString);
String callString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivity.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivity.bpmn2", callString);
String subProcessString = IOUtils.toString(this.getClass().getResourceAsStream("/BPMN2-CallActivitySubProcess.bpmn2"), "UTF-8");
resources.put("src/main/resources/BPMN2-CallActivitySubProcess.bpmn2", subProcessString);
DeploymentDescriptor customDescriptor = new DeploymentDescriptorImpl("org.jbpm.persistence.jpa");
customDescriptor.getBuilder().runtimeStrategy(RuntimeStrategy.PER_PROCESS_INSTANCE).addMarshalingStrategy(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestMarshallingStrategy")).addConfiguration(new NamedObjectModel("drools.processSignalManagerFactory", "java.lang.String", new Object[] { DefaultSignalManagerFactory.class.getName() })).addEnvironmentEntry(new NamedObjectModel("jbpm.business.calendar", "org.jbpm.runtime.manager.impl.deploy.RuntimeManagerWithDescriptorTest$TestBusinessCalendar")).addEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestProcessEventListener")).addGlobal(new NamedObjectModel("service", "java.util.ArrayList")).addTaskEventListener(new ObjectModel("org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestTaskEventListener")).addWorkItemHandler(new NamedObjectModel("Manual Task", "org.jbpm.runtime.manager.impl.deploy" + ".RuntimeManagerWithDescriptorTest$TestWorkItemHandler"));
resources.put("src/main/resources/" + DeploymentDescriptor.META_INF_LOCATION, customDescriptor.toXml());
String drl = "package org.jbpm; global java.util.List service; " + " rule \"Start Hello1\"" + " when" + " then" + " System.out.println(\"Hello\");" + " end";
resources.put("src/main/resources/simple.drl", drl);
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.jbpm.test.dd", "-kjar-with-dd", "1.0.0");
InternalKieModule kJar1 = createKieJar(ks, releaseId, resources);
installKjar(releaseId, kJar1);
RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder(releaseId).userGroupCallback(userGroupCallback).get();
manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
assertNotNull(manager);
InternalRuntimeManager internalManager = (InternalRuntimeManager) manager;
RegisterableItemsFactory factory = internalManager.getEnvironment().getRegisterableItemsFactory();
assertNotNull(factory);
assertTrue(factory instanceof InternalRegisterableItemsFactory);
assertNotNull(((InternalRegisterableItemsFactory) factory).getRuntimeManager());
DeploymentDescriptor descriptor = internalManager.getDeploymentDescriptor();
assertNotNull(descriptor);
assertEquals("org.jbpm.persistence.jpa", descriptor.getPersistenceUnit());
assertEquals("org.jbpm.persistence.jpa", descriptor.getAuditPersistenceUnit());
assertEquals(AuditMode.JPA, descriptor.getAuditMode());
assertEquals(PersistenceMode.JPA, descriptor.getPersistenceMode());
assertEquals(RuntimeStrategy.PER_PROCESS_INSTANCE, descriptor.getRuntimeStrategy());
assertEquals(1, descriptor.getMarshallingStrategies().size());
// assertEquals(1, descriptor.getConfiguration().size());
assertEquals(1, descriptor.getEnvironmentEntries().size());
assertEquals(1, descriptor.getEventListeners().size());
assertEquals(1, descriptor.getGlobals().size());
assertEquals(1, descriptor.getTaskEventListeners().size());
assertEquals(1, descriptor.getWorkItemHandlers().size());
assertEquals(0, descriptor.getRequiredRoles().size());
RuntimeEngine engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
assertNotNull(engine);
KieSession kieSession = engine.getKieSession();
// configuration
assertEquals(((SessionConfiguration) kieSession.getSessionConfiguration()).getSignalManagerFactory(), DefaultSignalManagerFactory.class.getName());
BusinessCalendar bc = (BusinessCalendar) kieSession.getEnvironment().get("jbpm.business.calendar");
assertNotNull(bc);
assertTrue(bc instanceof TestBusinessCalendar);
// globals
Object service = kieSession.getGlobal("service");
assertNotNull(service);
assertTrue(service instanceof ArrayList);
// work item handler
ProcessInstance processInstance = kieSession.startProcess("ManualTask");
long processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
kieSession.getWorkItemManager().completeWorkItem(TestWorkItemHandler.getWorkItem().getId(), null);
assertNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// process event listener
assertArrayEquals(new String[] { "beforeProcessStarted", "afterProcessStarted", "beforeProcessCompleted", "afterProcessCompleted" }, processEvents.toArray());
processEvents.clear();
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// task event listener
processInstance = kieSession.startProcess("UserTask");
processInstanceId = processInstance.getId();
assertNotNull(kieSession.getProcessInstance(processInstanceId));
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstanceId));
TaskService taskService = engine.getTaskService();
List<TaskSummary> tasks = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
long taskId = tasks.get(0).getId();
taskService.start(taskId, "john");
taskService.complete(taskId, "john", null);
assertArrayEquals(new String[] { "beforeTaskAddedEvent", "afterTaskAddedEvent", "beforeTaskStartedEvent", "afterTaskStartedEvent", "beforeTaskCompletedEvent", "afterTaskCompletedEvent" }, taskEvents.toArray());
manager.disposeRuntimeEngine(engine);
engine = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
kieSession = engine.getKieSession();
// marshalling strategy
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "marshal");
processInstance = kieSession.startProcess("ParentProcess", params);
processInstanceId = processInstance.getId();
ProcessInstance pi = kieSession.getProcessInstance(processInstanceId);
assertNotNull(pi);
String varX = (String) ((WorkflowProcessInstance) pi).getVariable("x");
assertEquals(TestMarshallingStrategy.ALWAYS_RESPOND_WITH, varX);
manager.disposeRuntimeEngine(engine);
}
Aggregations