use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteDirectCreation.
@Test
public void testAsyncAuditLoggerCompleteDirectCreation() throws Exception {
Environment env = createEnvironment(context);
// load the process
KieBase kbase = createKnowledgeBase();
// create a new session
KieSession session = createSession(kbase, env);
AbstractAuditLogger logger = AuditLoggerFactory.newJMSInstance(true, factory, queue);
Assertions.assertThat(logger).isNotNull();
Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
session.addEventListener(logger);
// start process instance
ProcessInstance processInstance = session.startProcess("com.sample.ruleflow");
MessageReceiver receiver = new MessageReceiver();
receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 6000, 11);
// validate if everything is stored in db
AuditLogService logService = new JPAAuditLogService(env);
List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow");
Assertions.assertThat(processInstances.size()).isEqualTo(1);
List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
Assertions.assertThat(nodeInstances.size()).isEqualTo(6);
for (NodeInstanceLog nodeInstance : nodeInstances) {
Assertions.assertThat(nodeInstance.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow");
Assertions.assertThat(nodeInstance.getDate()).isNotNull();
}
logService.clear();
processInstances = logService.findProcessInstances("com.sample.ruleflow");
logService.dispose();
Assertions.assertThat(processInstances).isEmpty();
}
use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteWithVariablesCustomIndexer.
@Test
public void testAsyncAuditLoggerCompleteWithVariablesCustomIndexer() throws Exception {
Environment env = createEnvironment(context);
// load the process
KieBase kbase = createKnowledgeBase();
// create a new session
KieSession session = createSession(kbase, env);
Map<String, Object> jmsProps = new HashMap<String, Object>();
jmsProps.put("jbpm.audit.jms.transacted", false);
jmsProps.put("jbpm.audit.jms.connection.factory", factory);
jmsProps.put("jbpm.audit.jms.queue", queue);
AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
Assertions.assertThat(logger).isNotNull();
Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
List<String> names = new LinkedList<String>();
names.add("john");
names.add("mary");
names.add("peter");
Map<String, Object> params = new HashMap<String, Object>();
params.put("list", names);
// start process instance
ProcessInstance processInstance = session.startProcess("com.sample.ruleflow3", params);
MessageReceiver receiver = new MessageReceiver();
receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 6000, 28);
// validate if everything is stored in db
AuditLogService logService = new JPAAuditLogService(env);
List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow3");
Assertions.assertThat(processInstances.size()).isEqualTo(1);
List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
Assertions.assertThat(nodeInstances.size()).isEqualTo(12);
for (NodeInstanceLog nodeInstance : nodeInstances) {
Assertions.assertThat(nodeInstance.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow3");
Assertions.assertThat(nodeInstance.getDate()).isNotNull();
}
// verify variables
List<VariableInstanceLog> variables = logService.findVariableInstances(processInstance.getId());
Assertions.assertThat(variables).isNotNull();
Assertions.assertThat(variables.size()).isEqualTo(8);
List<VariableInstanceLog> listVariables = new ArrayList<VariableInstanceLog>();
// collect only those that are related to list process variable
for (VariableInstanceLog v : variables) {
if (v.getVariableInstanceId().equals("list")) {
listVariables.add(v);
}
}
Assertions.assertThat(listVariables.size()).isEqualTo(3);
List<String> variableValues = new ArrayList<String>();
List<String> variableIds = new ArrayList<String>();
for (VariableInstanceLog var : listVariables) {
variableValues.add(var.getValue());
variableIds.add(var.getVariableId());
Assertions.assertThat(var.getOldValue()).isIn("", " ", null);
Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("list");
}
Assertions.assertThat(variableValues).contains("john", "mary", "peter");
Assertions.assertThat(variableIds).contains("list[0]", "list[1]", "list[2]");
logService.clear();
processInstances = logService.findProcessInstances("com.sample.ruleflow3");
logService.dispose();
Assertions.assertThat(processInstances).isNullOrEmpty();
}
use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class JbpmJUnitBaseTestCase method clearHistory.
protected void clearHistory() {
if (sessionPersistence && logService != null) {
// RuntimeManager manager = createRuntimeManager();
// RuntimeEngine engine = manager.getRuntimeEngine(null);
// engine.getAuditService().clear();
// manager.disposeRuntimeEngine(engine);
// manager.close();
JPAAuditLogService service = new JPAAuditLogService(emf);
service.clear();
service.dispose();
} else if (inMemoryLogger != null) {
inMemoryLogger.clear();
}
}
use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class JbpmJUnitTestCase method createKnowledgeSession.
protected KieSession createKnowledgeSession() {
manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);
RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());
KieSession result = runtime.getKieSession();
if (sessionPersistence) {
logService = new JPAAuditLogService(environment.getEnvironment());
} else {
logger = new WorkingMemoryInMemoryLogger((StatefulKnowledgeSession) result);
}
// knowledgeSessionSetLocal.get().add(result);
return result;
}
use of org.jbpm.process.audit.JPAAuditLogService in project jbpm by kiegroup.
the class AsyncAuditLogProducerTest method testAsyncAuditLoggerComplete.
@Test
public void testAsyncAuditLoggerComplete() throws Exception {
Environment env = createEnvironment(context);
// load the process
KieBase kbase = createKnowledgeBase();
// create a new session
KieSession session = createSession(kbase, env);
Map<String, Object> jmsProps = new HashMap<String, Object>();
jmsProps.put("jbpm.audit.jms.transacted", false);
jmsProps.put("jbpm.audit.jms.connection.factory", factory);
jmsProps.put("jbpm.audit.jms.queue", queue);
AbstractAuditLogger logger = AuditLoggerFactory.newInstance(Type.JMS, session, jmsProps);
Assertions.assertThat(logger).isNotNull();
Assertions.assertThat((logger instanceof AsyncAuditLogProducer)).isTrue();
// start process instance
ProcessInstance processInstance = session.startProcess("com.sample.ruleflow");
MessageReceiver receiver = new MessageReceiver();
receiver.receiveAndProcess(queue, ((EntityManagerFactory) env.get(EnvironmentName.ENTITY_MANAGER_FACTORY)), 2000, 11);
// validate if everything is stored in db
AuditLogService logService = new JPAAuditLogService(env);
List<ProcessInstanceLog> processInstances = logService.findProcessInstances("com.sample.ruleflow");
Assertions.assertThat(processInstances.size()).isEqualTo(1);
List<NodeInstanceLog> nodeInstances = logService.findNodeInstances(processInstance.getId());
Assertions.assertThat(nodeInstances.size()).isEqualTo(6);
for (NodeInstanceLog nodeInstance : nodeInstances) {
Assertions.assertThat(processInstance.getId()).isEqualTo(nodeInstance.getProcessInstanceId().longValue());
Assertions.assertThat(nodeInstance.getProcessId()).isEqualTo("com.sample.ruleflow");
Assertions.assertThat(nodeInstance.getDate()).isNotNull();
}
logService.clear();
processInstances = logService.findProcessInstances("com.sample.ruleflow");
logService.dispose();
Assertions.assertThat(processInstances).isEmpty();
}
Aggregations