Search in sources :

Example 76 with RuntimeEnvironment

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();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 77 with RuntimeEnvironment

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();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) RuleAwareProcessEventLister(org.jbpm.process.instance.event.listeners.RuleAwareProcessEventLister) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 78 with RuntimeEnvironment

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);
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) TaskService(org.kie.api.task.TaskService) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) TaskSummary(org.kie.api.task.model.TaskSummary) KieSession(org.kie.api.runtime.KieSession) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) BMScript(org.jboss.byteman.contrib.bmunit.BMScript)

Example 79 with RuntimeEnvironment

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");
}
Also used : RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) JBossUserGroupCallbackImpl(org.jbpm.services.task.identity.JBossUserGroupCallbackImpl) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) Properties(java.util.Properties) UserGroupCallback(org.kie.api.task.UserGroupCallback) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Example 80 with RuntimeEnvironment

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);
}
Also used : ObjectModel(org.kie.internal.runtime.conf.ObjectModel) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) InternalRuntimeManager(org.kie.internal.runtime.manager.InternalRuntimeManager) HashMap(java.util.HashMap) DeploymentDescriptor(org.kie.internal.runtime.conf.DeploymentDescriptor) DefaultSignalManagerFactory(org.jbpm.process.instance.event.DefaultSignalManagerFactory) ArrayList(java.util.ArrayList) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) RegisterableItemsFactory(org.kie.api.runtime.manager.RegisterableItemsFactory) KieServices(org.kie.api.KieServices) InternalRegisterableItemsFactory(org.kie.internal.runtime.manager.InternalRegisterableItemsFactory) KieSession(org.kie.api.runtime.KieSession) RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) TaskService(org.kie.api.task.TaskService) ReleaseId(org.kie.api.builder.ReleaseId) NamedObjectModel(org.kie.internal.runtime.conf.NamedObjectModel) BusinessCalendar(org.jbpm.process.core.timer.BusinessCalendar) TaskSummary(org.kie.api.task.model.TaskSummary) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule) Test(org.junit.Test)

Aggregations

RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)177 Test (org.junit.Test)163 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)148 KieSession (org.kie.api.runtime.KieSession)127 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)107 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)101 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)51 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)49 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)48 HashMap (java.util.HashMap)47 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)42 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)38 ArrayList (java.util.ArrayList)21 TaskSummary (org.kie.api.task.model.TaskSummary)21 NodeTriggeredCountDownProcessEventListener (org.jbpm.test.listener.NodeTriggeredCountDownProcessEventListener)20 AuditService (org.kie.api.runtime.manager.audit.AuditService)20 CountDownAsyncJobListener (org.jbpm.executor.test.CountDownAsyncJobListener)19 SystemOutWorkItemHandler (org.jbpm.process.instance.impl.demo.SystemOutWorkItemHandler)19 DefaultProcessEventListener (org.kie.api.event.process.DefaultProcessEventListener)19 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)17