public static void runTestLogger3(KieSession session, AuditLogService auditLogService) { session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); // record the initial count to compare to later List<ProcessInstanceLog> processInstances = auditLogService.findProcessInstances("com.sample.ruleflow"); int initialProcessInstanceSize = processInstances.size(); // start process instance long processInstanceId = session.startProcess("com.sample.ruleflow2").getId(); logger.debug("Checking process instances for process 'com.sample.ruleflow2'"); processInstances = auditLogService.findProcessInstances("com.sample.ruleflow2"); Assertions.assertThat(processInstances.size()).isEqualTo(initialProcessInstanceSize + 1); ProcessInstanceLog processInstance = processInstances.get(initialProcessInstanceSize); logger.debug("{} -> {} - {}", processInstance.toString(), processInstance.getStart(), processInstance.getEnd()); Assertions.assertThat(processInstance.getStart()).isNotNull(); Assertions.assertThat(processInstance.getEnd()).isNotNull().withFailMessage("ProcessInstanceLog does not contain end date."); Assertions.assertThat(processInstance.getProcessInstanceId().longValue()).isEqualTo(processInstanceId); Assertions.assertThat(processInstance.getProcessId()).isEqualTo("com.sample.ruleflow2"); List<NodeInstanceLog> nodeInstances = auditLogService.findNodeInstances(processInstanceId); for (NodeInstanceLog nodeInstance: nodeInstances) { logger.debug("{} -> {}", nodeInstance.toString(), nodeInstance.getDate()); Assertions.assertThat(processInstance.getProcessInstanceId().longValue()).isEqualTo(processInstanceId); Assertions.assertThat(processInstance.getProcessId()).isEqualTo("com.sample.ruleflow2"); Assertions.assertThat(nodeInstance.getDate()).isNotNull(); } Assertions.assertThat(nodeInstances.size()).isEqualTo(14); auditLogService.clear(); }
Assertions.assertThat(processInstances.size()).isEqualTo(initialProcessInstanceSize + 1); ProcessInstanceLog processInstance = processInstances.get(initialProcessInstanceSize); logger.debug("{} -> {} - {}", processInstance.toString(), processInstance.getStart(), processInstance.getEnd()); Assertions.assertThat(processInstance.getStart()).isNotNull(); Assertions.assertThat(processInstance.getEnd()).isNotNull(); Assertions.assertThat(processInstance.getProcessInstanceId().longValue()).isEqualTo(processInstanceId); Assertions.assertThat(processInstance.getProcessId()).isEqualTo("com.sample.ruleflow");
logger.debug( "{} -> {} - {}",processInstance.toString(), processInstance.getStart(), processInstance.getEnd()); Assertions.assertThat(processInstance.getEnd()).isNotNull().withFailMessage("ProcessInstanceLog does not contain end date."); Assertions.assertThat(processInstance.getProcessInstanceId().longValue()).isEqualTo(processInstanceId); Assertions.assertThat(processInstance.getProcessId()).isEqualTo("com.sample.ruleflow");
Assertions.assertThat(processInstances.size()).isEqualTo(expected).withFailMessage(String.format("Expected %d ProcessInstanceLog instances, not %d", expected, processInstances.size())); ProcessInstanceLog processInstance = processInstances.get(initialProcessInstanceSize); logger.debug("{} -> {} - {}",processInstance.toString(), processInstance.getStart(), processInstance.getEnd()); Assertions.assertThat(processInstance.getStart()).isNotNull(); Assertions.assertThat(processInstance.getEnd()).isNotNull().withFailMessage("ProcessInstanceLog does not contain end date."); Assertions.assertThat(processInstance.getProcessInstanceId().longValue()).isEqualTo(processInstanceId); Assertions.assertThat(processInstance.getProcessId()).isEqualTo("com.sample.ruleflow3");
public static void runTestLogger2(KieSession session, AuditLogService auditLogService) { session.getWorkItemManager().registerWorkItemHandler("Human Task", new SystemOutWorkItemHandler()); // record the initial count to compare to later List<ProcessInstanceLog> processInstances = auditLogService.findProcessInstances("com.sample.ruleflow"); int initialProcessInstanceSize = processInstances.size(); // start process instance session.startProcess("com.sample.ruleflow"); session.startProcess("com.sample.ruleflow"); logger.debug("Checking process instances for process 'com.sample.ruleflow'"); processInstances = auditLogService.findProcessInstances("com.sample.ruleflow"); Assertions.assertThat(processInstances.size()).isEqualTo(initialProcessInstanceSize + 2); for (ProcessInstanceLog processInstance: processInstances) { logger.debug("{} -> {} - {}", processInstance.toString(), processInstance.getStart(), processInstance.getEnd()); List<NodeInstanceLog> nodeInstances = auditLogService.findNodeInstances(processInstance.getProcessInstanceId()); for (NodeInstanceLog nodeInstance: nodeInstances) { logger.debug("{} -> {}",nodeInstance.toString(), nodeInstance.getDate()); } Assertions.assertThat(nodeInstances.size()).isEqualTo(6); } auditLogService.clear(); }
@Override public AuditEvent buildEvent(ProcessCompletedEvent pce, Object log) { ProcessInstanceImpl pi = (ProcessInstanceImpl) pce.getProcessInstance(); ProcessInstanceLog logEvent = null; if (log != null) { logEvent = (ProcessInstanceLog) log; } else { logEvent = new ProcessInstanceLog(pi.getId(), pi.getProcessId()); } logEvent.setOutcome(pi.getOutcome()); logEvent.setStatus(pi.getState()); logEvent.setEnd(pce.getEventDate()); logEvent.setDuration(logEvent.getEnd().getTime() - logEvent.getStart().getTime()); logEvent.setProcessInstanceDescription( pi.getDescription() ); logEvent.setSlaCompliance(pi.getSlaCompliance()); return logEvent; }
@Test public void testLogger2() { // start process instance startProcess("com.sample.ruleflow"); startProcess("com.sample.ruleflow"); logger.debug("Checking process instances for process 'com.sample.ruleflow'"); List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow"); assertEquals(2, processInstances.size()); for (ProcessInstanceLog processInstance: processInstances) { logger.debug("{}", processInstance); logger.debug(" -> {} - {}", processInstance.getStart(), processInstance.getEnd()); List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getProcessInstanceId()); for (NodeInstanceLog nodeInstance: nodeInstances) { logger.debug("{}", nodeInstance); logger.debug(" -> {}", nodeInstance.getDate()); } assertEquals(6, nodeInstances.size()); assertRuleFlowSampleLogsSorting(nodeInstances, processInstance.getProcessInstanceId()); } logService.clear(); }
@Test public void unionQueryBuilderTest() { ProcessInstanceLogQueryBuilder builder = this.processInstanceLogQuery(); builder.duration(pilTestData[4].getDuration()); List<org.kie.api.runtime.manager.audit.ProcessInstanceLog> resultList = builder.build().getResultList(); assertEquals( "duration result", 1, resultList.size()); builder.endDate(pilTestData[5].getEnd(), pilTestData[6].getEnd()); resultList = builder.build().getResultList(); assertEquals( "union: duration OR end result", 3, resultList.size()); builder.identity(pilTestData[7].getIdentity(), pilTestData[8].getIdentity()); resultList = builder.build().getResultList(); assertEquals( "union: duration OR end OR identity result", 5, resultList.size()); }
@Test public void testLogger3() { long processInstanceId = startProcess("com.sample.ruleflow2").getId(); logger.debug("Checking process instances for process 'com.sample.ruleflow2'"); List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow2"); assertEquals(1, processInstances.size()); ProcessInstanceLog processInstance = processInstances.get(0); logger.debug("{}", processInstance); logger.debug(" -> {} - {} ", processInstance.getStart(), processInstance.getEnd()); assertNotNull(processInstance.getStart()); assertNotNull(processInstance.getEnd()); assertEquals(processInstanceId, processInstance.getProcessInstanceId().longValue()); assertEquals("com.sample.ruleflow2", processInstance.getProcessId()); List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstanceId); for (NodeInstanceLog nodeInstance: nodeInstances) { logger.debug("{}", nodeInstance); logger.debug(" -> {}", nodeInstance.getDate()); assertEquals(processInstanceId, processInstance.getProcessInstanceId().longValue()); assertEquals("com.sample.ruleflow2", processInstance.getProcessId()); assertNotNull(nodeInstance.getDate()); } assertEquals(14, nodeInstances.size()); logService.clear(); }
@Test public void testDeleteProcessInstanceInfoLogByDate() { int p = 0; Date endDate = pilTestData[p++].getEnd(); ProcessInstanceLogDeleteBuilder updateBuilder = this.processInstanceLogDelete().endDate(endDate); int result = updateBuilder.build().execute(); assertEquals(1, result); }
@Test public void testDeleteProcessInstanceInfoLogByDateRangeStart() { Date endDate = pilTestData[8].getEnd(); ProcessInstanceLogDeleteBuilder updateBuilder = this.processInstanceLogDelete().endDateRangeStart(endDate); int result = updateBuilder.build().execute(); assertEquals(3, result); }
@Test public void testDeleteProcessInstanceInfoLogByDateRangeEnd() { Date endDate = pilTestData[4].getEnd(); ProcessInstanceLogDeleteBuilder updateBuilder = this.processInstanceLogDelete().endDateRangeEnd(endDate); int result = updateBuilder.build().execute(); assertEquals(5, result); }
@Test public void testDeleteProcessInstanceInfoLogByTimestamp() { int p = 0; Date endDate = pilTestData[p++].getEnd(); List<org.kie.api.runtime.manager.audit.ProcessInstanceLog> logs = this.processInstanceLogQuery().endDate(endDate).build().getResultList(); assertEquals(1, logs.size()); ProcessInstanceLogDeleteBuilder updateBuilder = this.processInstanceLogDelete().endDate(logs.get(0).getEnd()); int result = updateBuilder.build().execute(); assertEquals(1, result); }
ProcessInstanceLog processInstance = processInstances.get(initialProcessInstanceSize); logger.debug( "{} -> {} - {}",processInstance.toString(), processInstance.getStart(), processInstance.getEnd()); assertNotNull("ProcessInstanceLog does not contain end date.", processInstance.getEnd()); assertEquals(processInstanceId, processInstance.getProcessInstanceId().longValue()); assertEquals(PROCESS_ID, processInstance.getProcessId());
@Test public void testLogger1() { // start process instance long processInstanceId = startProcess("com.sample.ruleflow").getId(); logger.debug("Checking process instances for process 'com.sample.ruleflow'"); List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow"); assertEquals(1, processInstances.size()); ProcessInstanceLog processInstance = processInstances.get(0); logger.debug("{}", processInstance); assertNotNull(processInstance.getStart()); assertNotNull(processInstance.getEnd()); assertEquals(processInstanceId, processInstance.getProcessInstanceId().longValue()); assertEquals("com.sample.ruleflow", processInstance.getProcessId()); List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstanceId); assertEquals(6, nodeInstances.size()); for (NodeInstanceLog nodeInstance: nodeInstances) { logger.debug("{}", nodeInstance); assertEquals(processInstanceId, processInstance.getProcessInstanceId().longValue()); assertEquals("com.sample.ruleflow", processInstance.getProcessId()); assertNotNull(nodeInstance.getDate()); } assertRuleFlowSampleLogsSorting(nodeInstances, processInstanceId); logService.clear(); }
@Test public void intersectQueryBuilderTest() { ProcessInstanceLogQueryBuilder builder = this.processInstanceLogQuery(); builder.intersect(); builder.duration(pilTestData[4].getDuration()); List<org.kie.api.runtime.manager.audit.ProcessInstanceLog> resultList = builder.build().getResultList(); assertEquals( "duration result", 1, resultList.size()); builder.endDate(pilTestData[5].getEnd()); resultList = builder.build().getResultList(); assertEquals( "intersect: duration AND end result", 0, resultList.size()); builder.identity(pilTestData[6].getIdentity()); resultList = builder.build().getResultList(); assertEquals( "intersect: duration AND end AND identity result", 0, resultList.size()); }
@Test public void testDeleteProcessInstanceInfoLogByProcessIdAndDate() { int p = 0; String processId = pilTestData[p].getProcessId(); Date endDate = pilTestData[p].getEnd(); ProcessInstanceLogDeleteBuilder updateBuilder = this.processInstanceLogDelete().endDate(endDate).processId(processId); int result = updateBuilder.build().execute(); assertEquals(1, result); }
@Test public void testDeleteProcessInstanceInfoLogByProcessIdAndNotMatchingDate() { int p = 0; String processId = pilTestData[p++].getProcessId(); Date endDate = pilTestData[p++].getEnd(); ProcessInstanceLogDeleteBuilder updateBuilder = this.processInstanceLogDelete().endDate(endDate).processId(processId); int result = updateBuilder.build().execute(); assertEquals(0, result); }
@Test public void intersectUnionQueryBuilderTest() { ProcessInstanceLogQueryBuilder builder = this.processInstanceLogQuery(); builder.duration(pilTestData[0].getDuration(), pilTestData[2].getDuration()); List<org.kie.api.runtime.manager.audit.ProcessInstanceLog> resultList = builder.build().getResultList(); assertEquals( "duration result", 3, resultList.size()); builder.intersect().endDate(pilTestData[0].getEnd()); resultList = builder.build().getResultList(); assertEquals( "intersect: duration AND end result", 1, resultList.size()); builder.union().processId(pilTestData[10].getProcessId()); resultList = builder.build().getResultList(); assertEquals( "intersect/union: duration AND end OR processId result", 1 + 1, resultList.size()); }
@Test @RequirePersistence public void testScriptTaskWithHistoryLog() throws Exception { KieBase kbase = createKnowledgeBase("BPMN2-ScriptTask.bpmn2"); ksession = createKnowledgeSession(kbase); ProcessInstance processInstance = ksession.startProcess("ScriptTask"); assertProcessInstanceCompleted(processInstance); AuditLogService logService = new JPAAuditLogService(ksession.getEnvironment()); List<NodeInstanceLog> logs = logService.findNodeInstances(processInstance.getId()); assertNotNull(logs); assertEquals(6, logs.size()); for (NodeInstanceLog log : logs) { assertNotNull(log.getDate()); } ProcessInstanceLog pilog = logService.findProcessInstance(processInstance.getId()); assertNotNull(pilog); assertNotNull(pilog.getEnd()); List<ProcessInstanceLog> pilogs = logService.findActiveProcessInstances(processInstance.getProcessId()); assertNotNull(pilogs); assertEquals(0, pilogs.size()); logService.dispose(); }