Search in sources :

Example 6 with AuditService

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

the class PerRequestRuntimeManagerTest method testSignalEventViaRuntimeManager.

@Test
public void testSignalEventViaRuntimeManager() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2IntermediateThrowEventScope.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newPerRequestRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ProcessInstance processInstance = ksession1.startProcess("intermediate-event-scope");
    manager.disposeRuntimeEngine(runtime1);
    RuntimeEngine runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    ProcessInstance processInstance2 = ksession2.startProcess("intermediate-event-scope");
    manager.disposeRuntimeEngine(runtime2);
    runtime1 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance.getId()));
    List<Long> tasks1 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance2.getId()));
    List<Long> tasks2 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance2.getId());
    assertNotNull(tasks2);
    assertEquals(1, tasks2.size());
    Object data = "some data";
    runtime1.getTaskService().claim(tasks1.get(0), "john");
    runtime1.getTaskService().start(tasks1.get(0), "john");
    runtime1.getTaskService().complete(tasks1.get(0), "john", Collections.singletonMap("_output", data));
    manager.disposeRuntimeEngine(runtime1);
    manager.disposeRuntimeEngine(runtime2);
    runtime2 = manager.getRuntimeEngine(ProcessInstanceIdContext.get(processInstance2.getId()));
    AuditService auditService = runtime2.getAuditService();
    ProcessInstanceLog pi1Log = auditService.findProcessInstance(processInstance.getId());
    assertNotNull(pi1Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi1Log.getStatus().intValue());
    ProcessInstanceLog pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2Log.getStatus().intValue());
    List<? extends NodeInstanceLog> nLogs = auditService.findNodeInstances(processInstance2.getId(), "_527AF0A7-D741-4062-9953-A05E51479C80");
    assertNotNull(nLogs);
    assertEquals(2, nLogs.size());
    auditService.dispose();
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime1);
    manager.disposeRuntimeEngine(runtime2);
    // 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) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 7 with AuditService

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

the class SingletonRuntimeManagerTest method testSignalEventViaRuntimeManager.

@Test
public void testSignalEventViaRuntimeManager() {
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().userGroupCallback(userGroupCallback).addAsset(ResourceFactory.newClassPathResource("BPMN2IntermediateThrowEventScope.bpmn2"), ResourceType.BPMN2).get();
    manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
    assertNotNull(manager);
    RuntimeEngine runtime1 = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession1 = runtime1.getKieSession();
    assertNotNull(ksession1);
    ProcessInstance processInstance = ksession1.startProcess("intermediate-event-scope");
    RuntimeEngine runtime2 = manager.getRuntimeEngine(EmptyContext.get());
    KieSession ksession2 = runtime2.getKieSession();
    assertNotNull(ksession2);
    ProcessInstance processInstance2 = ksession2.startProcess("intermediate-event-scope");
    List<Long> tasks1 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance.getId());
    assertNotNull(tasks1);
    assertEquals(1, tasks1.size());
    List<Long> tasks2 = runtime1.getTaskService().getTasksByProcessInstanceId(processInstance2.getId());
    assertNotNull(tasks2);
    assertEquals(1, tasks2.size());
    Object data = "some data";
    runtime1.getTaskService().claim(tasks1.get(0), "john");
    runtime1.getTaskService().start(tasks1.get(0), "john");
    runtime1.getTaskService().complete(tasks1.get(0), "john", Collections.singletonMap("_output", data));
    AuditService auditService = runtime1.getAuditService();
    ProcessInstanceLog pi1Log = auditService.findProcessInstance(processInstance.getId());
    assertNotNull(pi1Log);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi1Log.getStatus().intValue());
    ProcessInstanceLog pi2Log = auditService.findProcessInstance(processInstance2.getId());
    assertNotNull(pi2Log);
    assertEquals(ProcessInstance.STATE_ACTIVE, pi2Log.getStatus().intValue());
    List<? extends NodeInstanceLog> nLogs = auditService.findNodeInstances(processInstance2.getId(), "_527AF0A7-D741-4062-9953-A05E51479C80");
    assertNotNull(nLogs);
    assertEquals(2, nLogs.size());
    auditService.dispose();
    // dispose session that should not have affect on the session at all
    manager.disposeRuntimeEngine(runtime1);
    manager.disposeRuntimeEngine(runtime2);
    // 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) ProcessInstanceLog(org.kie.api.runtime.manager.audit.ProcessInstanceLog) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 8 with AuditService

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

the class SingletonRuntimeManagerTest 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().newSingletonRuntimeManager(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)

Example 9 with AuditService

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

the class SingletonRuntimeManagerTest method testBusinessRuleTaskWithGlobal.

@Test
public void testBusinessRuleTaskWithGlobal() {
    final List<String> list = new ArrayList<String>();
    RuntimeEnvironment environment = RuntimeEnvironmentBuilder.Factory.get().newDefaultBuilder().addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTask.bpmn2"), ResourceType.BPMN2).addAsset(ResourceFactory.newClassPathResource("BPMN2-BusinessRuleTaskWithGlobal.drl"), ResourceType.DRL).registerableItemsFactory(new DefaultRegisterableItemsFactory() {

        @Override
        public Map<String, Object> getGlobals(RuntimeEngine runtime) {
            Map<String, Object> globals = super.getGlobals(runtime);
            globals.put("list", list);
            return globals;
        }
    }).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()));
    assertEquals(1, list.size());
    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) ArrayList(java.util.ArrayList) 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 10 with AuditService

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

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