Search in sources :

Example 1 with AuditService

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

the class PerCaseRuntimeManagerTest method testEventSignalingBetweenProcessesWithPeristence.

@Test
public void testEventSignalingBetweenProcessesWithPeristence() {
    final Set<Long> ksessionUsed = new HashSet<Long>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("events/throw-an-event.bpmn"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("events/start-on-event.bpmn"), ResourceType.BPMN2).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public List<ProcessEventListener> getProcessEventListeners(RuntimeEngine runtime) {
            List<ProcessEventListener> listeners = super.getProcessEventListeners(runtime);
            listeners.add(new DefaultProcessEventListener() {

                @Override
                public void beforeProcessStarted(ProcessStartedEvent event) {
                    ksessionUsed.add(((KieSession) event.getKieRuntime()).getIdentifier());
                }
            });
            return listeners;
        }
    }).get();
    manager = RuntimeManagerFactory.Factory.get().newPerCaseRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime = manager.getRuntimeEngine(CaseContext.get("Case-1"));
    KieSession ksession = runtime.getKieSession();
    long ksession1Id = ksession.getIdentifier();
    assertNotNull(ksession);
    ksession.startProcess("com.sample.bpmn.hello");
    AuditService auditService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> throwProcessLogs = auditService.findProcessInstances("com.sample.bpmn.hello");
    List<? extends ProcessInstanceLog> catchProcessLogs = auditService.findProcessInstances("com.sample.bpmn.Second");
    assertNotNull(throwProcessLogs);
    assertEquals(1, throwProcessLogs.size());
    assertEquals(ProcessInstance.STATE_COMPLETED, throwProcessLogs.get(0).getStatus().intValue());
    assertNotNull(catchProcessLogs);
    assertEquals(1, catchProcessLogs.size());
    assertEquals(ProcessInstance.STATE_COMPLETED, catchProcessLogs.get(0).getStatus().intValue());
    assertEquals(1, ksessionUsed.size());
    assertEquals(ksession1Id, ksessionUsed.iterator().next().longValue());
    manager.disposeRuntimeEngine(runtime);
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) ProcessEventListener(org.kie.api.event.process.ProcessEventListener) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) NodeLeftCountDownProcessEventListener(org.jbpm.test.listener.NodeLeftCountDownProcessEventListener) ProcessStartedEvent(org.kie.api.event.process.ProcessStartedEvent) DefaultProcessEventListener(org.kie.api.event.process.DefaultProcessEventListener) KieSession(org.kie.api.runtime.KieSession) AuditService(org.kie.api.runtime.manager.audit.AuditService) HashSet(java.util.HashSet) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with AuditService

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

the class PerProcessInstanceRuntimeManagerTest method testCreationOfSessionWithPersistenceAndAuditService.

@Test
public void testCreationOfSessionWithPersistenceAndAuditService() {
    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);
    // 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);
    long ksession1Id = ksession.getIdentifier();
    assertTrue(ksession1Id == 2);
    AuditService auditService = runtime.getAuditService();
    assertNotNull(auditService);
    List<? extends ProcessInstanceLog> logs = auditService.findProcessInstances();
    assertNotNull(logs);
    assertEquals(0, logs.size());
    // ksession for process instance #2
    // since there is no process instance yet we need to get new session
    RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    long ksession2Id = ksession2.getIdentifier();
    assertTrue(ksession2Id == 3);
    ProcessInstance pi1 = ksession.startProcess("UserTask");
    logs = auditService.findProcessInstances();
    assertNotNull(logs);
    assertEquals(1, logs.size());
    ProcessInstance pi2 = ksession2.startProcess("UserTask");
    logs = auditService.findProcessInstances();
    assertNotNull(logs);
    assertEquals(2, logs.size());
    // both processes started
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2.getState());
    manager.disposeRuntimeEngine(runtime);
    runtime = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId()));
    ksession = runtime.getKieSession();
    assertEquals(ksession1Id, ksession.getIdentifier());
    ksession.getWorkItemManager().completeWorkItem(1, null);
    manager.disposeRuntimeEngine(runtime);
    // since process is completed now session should not be there any more
    try {
        manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi1.getId())).getKieSession();
        fail("Session for this (" + pi1.getId() + ") process instance is no more accessible");
    } catch (RuntimeException e) {
    }
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId()));
    ;
    ksession2 = runtime2.getKieSession();
    assertEquals(ksession2Id, ksession2.getIdentifier());
    ksession2.getWorkItemManager().completeWorkItem(2, null);
    auditService = runtime2.getAuditService();
    logs = auditService.findProcessInstances();
    assertNotNull(logs);
    assertEquals(2, logs.size());
    manager.disposeRuntimeEngine(runtime2);
    // since process is completed now session should not be there any more
    try {
        manager.getRuntimeEngine(ProcessInstanceIdContext.get(pi2.getId())).getKieSession();
        fail("Session for this (" + pi2.getId() + ") process instance is no more accessible");
    } 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) AuditService(org.kie.api.runtime.manager.audit.AuditService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 3 with AuditService

use of org.kie.api.runtime.manager.audit.AuditService 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 4 with AuditService

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

the class PerProcessInstanceRuntimeManagerTest method testSignalStartMultipleProcesses.

@Test
public void testSignalStartMultipleProcesses() {
    // independent = true
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2-SignalMultipleProcessesMain.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-SignalMultipleProcessesOne.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-SignalMultipleProcessesTwo.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);
    Map<String, Object> inputParams = new HashMap<String, Object>();
    inputParams.put("processInput", "MyCoolParam");
    ksession.startProcess("main-process", inputParams);
    AuditService auditService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> processInstanceLogs = auditService.findProcessInstances();
    assertEquals(3, processInstanceLogs.size());
    manager.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) RuntimeEnvironment(org.kie.api.runtime.manager.RuntimeEnvironment) HashMap(java.util.HashMap) KieSession(org.kie.api.runtime.KieSession) AuditService(org.kie.api.runtime.manager.audit.AuditService) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest) Test(org.junit.Test)

Example 5 with AuditService

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

the class PerRequestRuntimeManagerTest method testExecuteReusableSubprocess.

@Test
public void testExecuteReusableSubprocess() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addEnvironmentEntry("RuntimeEngineEagerInit", "true").addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivity.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-CallActivitySubProcess.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(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 == 1);
    ProcessInstance pi1 = ksession.startProcess("ParentProcess");
    assertEquals(ProcessInstance.STATE_ACTIVE, pi1.getState());
    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());
    logs = logService.findProcessInstances("SubProcess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    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) 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)

Aggregations

AuditService (org.kie.api.runtime.manager.audit.AuditService)29 Test (org.junit.Test)28 RuntimeEngine (org.kie.api.runtime.manager.RuntimeEngine)26 KieSession (org.kie.api.runtime.KieSession)25 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)21 RuntimeEnvironment (org.kie.api.runtime.manager.RuntimeEnvironment)20 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)19 HashMap (java.util.HashMap)7 TaskService (org.kie.api.task.TaskService)6 TaskSummary (org.kie.api.task.model.TaskSummary)6 ProcessInstanceLog (org.kie.api.runtime.manager.audit.ProcessInstanceLog)5 InternalTaskService (org.kie.internal.task.api.InternalTaskService)4 ArrayList (java.util.ArrayList)3 NodeLeftCountDownProcessEventListener (org.jbpm.test.listener.NodeLeftCountDownProcessEventListener)3 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)3 HashSet (java.util.HashSet)2 EntityManager (javax.persistence.EntityManager)2 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)2 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)2 TaskCleanUpProcessEventListener (org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener)2