Search in sources :

Example 86 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithEmptyContext.

@Test
public void testCreationOfSessionWithEmptyContext() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultInMemoryBuilder().userGroupCallback(userGroupCallback).entityManagerFactory(emf).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    // ksession for process instance #1
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id == 1);
    // ksession for process instance #2
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime2 = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    long ksession2Id = ksession2.getIdentifier();
    assertTrue(ksession2Id == 2);
    ProcessInstance pi1 = ksession.startProcess("UserTask");
    ProcessInstance pi2 = ksession2.startProcess("UserTask");
    // both processes started
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
    manager.disposeRuntimeEngine(runtime);
    manager.disposeRuntimeEngine(runtime2);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
    ksession = runtime.getKieSession();
    assertEquals(ksession1Id, ksession.getIdentifier());
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
    ksession2 = runtime2.getKieSession();
    assertEquals(ksession2Id, ksession2.getIdentifier());
    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) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 87 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testErrorThrowOfChildProcessOnParent.

@Test
public void testErrorThrowOfChildProcessOnParent() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/ParentError.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("reusable-subprocess/ChildError.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    ksession.startProcess("ParentError");
    List<? extends ProcessInstanceLog> processInstanceLogs = runtime.getAuditService().findProcessInstances();
    assertEquals(2, processInstanceLogs.size());
    for (ProcessInstanceLog log : processInstanceLogs) {
        if (log.getProcessId().equals("ParentError")) {
            assertEquals(ProcessInstance.STATE_COMPLETED, log.getStatus().intValue());
        } else if (log.getProcessId().equals("ChildError")) {
            assertEquals(ProcessInstance.STATE_ABORTED, log.getStatus().intValue());
        }
    }
    manager.disposeRuntimeEngine(runtime);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 88 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionTaskServiceNotConfigured.

@Test
public void testCreationOfSessionTaskServiceNotConfigured() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newEmptyBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    // ksession for process instance #1
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    try {
        runtime.getTaskService();
        fail("Should fail as task service is not configured");
    } catch (UnsupportedOperationException e) {
        assertEquals("TaskService was not configured", e.getMessage());
    }
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) KieSession(org.kie.api.runtime.KieSession) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 89 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testExecuteReusableSubprocess.

@Test
public void testExecuteReusableSubprocess() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id == 2);
    ProcessInstance pi1 = ksession.startProcess("ParentProcess");
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    try {
        ksession.getWorkItemManager().completeWorkItem(1, null);
        fail("Invalid session was used for subprocess of (" + pi1.getId() + ") process instance");
    } catch (RuntimeException e) {
    }
    manager.disposeRuntimeEngine(runtime);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(2l));
    ksession = runtime.getKieSession();
    ksession.getWorkItemManager().completeWorkItem(1, null);
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findActiveProcessInstances("ParentProcess");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findActiveProcessInstances("SubProcess");
    assertNotNull(logs);
    assertEquals(0, logs.size());
    logs = logService.findProcessInstances("ParentProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    String externalId = logs.get(0).getExternalId();
    assertEquals(manager.getIdentifier(), externalId);
    logs = logService.findProcessInstances("SubProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    externalId = logs.get(0).getExternalId();
    assertEquals(manager.getIdentifier(), externalId);
    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) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 90 with RuntimeEngine

use of org.kie.api.runtime.manager.RuntimeEngine in project jbpm by kiegroup.

the class PerProcessInstanceRuntimeManagerTest method testStartTwoProcessIntancesOnSameSession.

@Test
public void testStartTwoProcessIntancesOnSameSession() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-ScriptTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-UserTask.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(environment);
    assertNotNull(manager);
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession = runtime.getKieSession();
    assertNotNull(ksession);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id == 2);
    ProcessInstance pi1 = ksession.startProcess("UserTask");
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    try {
        ProcessInstance pi2 = ksession.startProcess("UserTask");
        fail("Invalid session was used for (" + pi2.getId() + ") process instance");
    } catch (RuntimeException e) {
    }
    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) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Aggregations

RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)388 Test (org.junit.Test)269 KieSession (org.kie.api.runtime.KieSession)265 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)229 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)149 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)116 TaskService (org.kie.api.task.TaskService)111 HashMap (java.util.HashMap)110 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)105 TaskSummary (org.kie.api.task.model.TaskSummary)86 InternalRuntimeManager (org.kie.internal.runtime.manager.InternalRuntimeManager)82 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)67 ArrayList (java.util.ArrayList)59 InternalTaskService (org.kie.internal.task.api.InternalTaskService)59 ProcessEventListener (org.kie.api.event.process.ProcessEventListener)58 AbstractExecutorBaseTest (org.jbpm.test.util.AbstractExecutorBaseTest)49 DefaultRegisterableItemsFactory (org.jbpm.runtime.manager.impl.DefaultRegisterableItemsFactory)43 WorkItemHandler (org.kie.api.runtime.process.WorkItemHandler)40 UserTaskService (org.jbpm.services.api.UserTaskService)36 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)34