Search in sources :

Example 11 with AuditService

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

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

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

the class AdminAPIsWithListenerTest method automaticCleanUpForSubProcessWithPerProcessInstanceStrategy.

@Test
public void automaticCleanUpForSubProcessWithPerProcessInstanceStrategy() throws Exception {
    TaskCleanUpProcessEventListener taskCleanUpProcessEventListener = new TaskCleanUpProcessEventListener(null);
    this.addProcessEventListener(taskCleanUpProcessEventListener);
    RuntimeManager manager = createRuntimeManager(Strategy.PROCESS_INSTANCE, "com.mycompany.sample", "org/jbpm/test/functional/task/ht-main.bpmn", "org/jbpm/test/functional/task/ht-sub.bpmn");
    RuntimeEngine runtime = getRuntimeEngine(ProcessInstanceIdContext.get());
    taskCleanUpProcessEventListener.setTaskService((InternalTaskService) runtime.getTaskService());
    KieSession ksession = runtime.getKieSession();
    // start a new process instance
    Map<String, Object> params = new HashMap<String, Object>();
    ProcessInstance pi = ksession.startProcess("com.mycompany.sample", params);
    // obtain the task service
    TaskService taskService = runtime.getTaskService();
    List<TaskSummary> tasks1 = taskService.getTasksAssignedAsPotentialOwner("john", "en-UK");
    assertFalse(tasks1.isEmpty());
    TaskSummary task1 = tasks1.get(0);
    System.out.println("Sales-rep executing task " + task1.getName() + "(" + task1.getId() + ": " + task1.getDescription() + ")");
    taskService.start(task1.getId(), "john");
    Map<String, Object> results = new HashMap<String, Object>();
    results.put("comment", "Agreed, existing laptop needs replacing");
    results.put("outcome", "Accept");
    // complete the human task of the main process
    taskService.complete(task1.getId(), "john", results);
    // abort the process instance
    ksession.abortProcessInstance(pi.getId());
    // main process instance shall be aborted
    assertProcessInstanceAborted(pi.getId());
    AuditService logService = runtime.getAuditService();
    List<? extends ProcessInstanceLog> logs = logService.findProcessInstances("com.mycompany.sample");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    assertEquals(ProcessInstance.STATE_ABORTED, logs.get(0).getStatus().intValue());
    logs = logService.findProcessInstances("com.mycompany.sample.subprocess");
    assertNotNull(logs);
    assertEquals(1, logs.size());
    assertEquals(ProcessInstance.STATE_ABORTED, logs.get(0).getStatus().intValue());
    manager.close();
    final EntityManager em = emfTasks.createEntityManager();
    assertEquals(0, em.createQuery("select t from TaskImpl t").getResultList().size());
    assertEquals(0, em.createQuery("select i from I18NTextImpl i").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_BAs").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_ExclOwners").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_PotOwners").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Recipients").getResultList().size());
    assertEquals(0, em.createNativeQuery("select * from PeopleAssignments_Stakeholders").getResultList().size());
    assertEquals(0, em.createQuery("select c from ContentImpl c").getResultList().size());
    em.close();
}
Also used : RuntimeEngine(org.kie.api.runtime.manager.RuntimeEngine) HashMap(java.util.HashMap) InternalTaskService(org.kie.internal.task.api.InternalTaskService) TaskService(org.kie.api.task.TaskService) RuntimeManager(org.kie.api.runtime.manager.RuntimeManager) TaskCleanUpProcessEventListener(org.jbpm.services.task.admin.listener.TaskCleanUpProcessEventListener) EntityManager(javax.persistence.EntityManager) 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) Test(org.junit.Test)

Example 14 with AuditService

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

the class BPMN2DataServicesReferencesTest method testCallActivity.

@Test
public void testCallActivity() throws IOException {
    Assume.assumeTrue("Skip call activity tests", loadCallActivityProcesses);
    String processId = PROC_ID_CALL_ACTIVITY;
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // run process (to verify that it works)
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    Long procId = startProcess(deploymentId, processId, params);
    ProcessInstance procInst = processService.getProcessInstance(procId);
    assertNull(procInst);
    AuditService auditService = deploymentService.getRuntimeManager(deploymentId).getRuntimeEngine(null).getAuditService();
    List<? extends VariableInstanceLog> logs = auditService.findVariableInstances(procId);
    boolean foundY = false;
    for (VariableInstanceLog log : logs) {
        if (log.getVariableId().equals("y") && log.getValue().equals("new value")) {
            foundY = true;
        }
    }
    assertTrue("Parent process did not call sub process", foundY);
    // check information about process
    Collection<String> refProcesses = bpmn2Service.getReusableSubProcesses(deploymentId, processId);
    assertNotNull("Null set of referenced processes", refProcesses);
    assertFalse("Empty set of referenced processes", refProcesses.isEmpty());
    assertEquals("Number referenced processes", 1, refProcesses.size());
    assertEquals("Imported class in processes", PROC_ID_ACTIVITY_CALLED, refProcesses.iterator().next());
}
Also used : VariableInstanceLog(org.kie.api.runtime.manager.audit.VariableInstanceLog) HashMap(java.util.HashMap) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 15 with AuditService

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

the class BPMN2DataServicesReferencesTest method testCallActivityByName.

@Test
public void testCallActivityByName() throws IOException {
    Assume.assumeTrue("Skip call activity tests", loadCallActivityProcesses);
    String processId = PROC_ID_CALL_ACTIVITY_BY_NAME;
    ProcessDefinition procDef = bpmn2Service.getProcessDefinition(deploymentId, processId);
    assertNotNull(procDef);
    // run process (to verify that it works)
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("x", "oldValue");
    Long procId = startProcess(deploymentId, processId, params);
    ProcessInstance procInst = processService.getProcessInstance(procId);
    assertNull(procInst);
    AuditService auditService = deploymentService.getRuntimeManager(deploymentId).getRuntimeEngine(null).getAuditService();
    List<? extends VariableInstanceLog> logs = auditService.findVariableInstances(procId);
    boolean foundY = false;
    for (VariableInstanceLog log : logs) {
        if (log.getVariableId().equals("y") && log.getValue().equals("new value")) {
            foundY = true;
        }
    }
    assertTrue("Parent process did not call sub process", foundY);
    // check information about process
    Collection<String> refProcesses = bpmn2Service.getReusableSubProcesses(deploymentId, processId);
    assertNotNull("Null set of referenced processes", refProcesses);
    assertFalse("Empty set of referenced processes", refProcesses.isEmpty());
    assertEquals("Number referenced processes", 1, refProcesses.size());
    assertEquals("Imported class in processes", PROC_ID_ACTIVITY_CALLED, refProcesses.iterator().next());
}
Also used : VariableInstanceLog(org.kie.api.runtime.manager.audit.VariableInstanceLog) HashMap(java.util.HashMap) ProcessDefinition(org.jbpm.services.api.model.ProcessDefinition) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) AuditService(org.kie.api.runtime.manager.audit.AuditService) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

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