use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class AsyncAuditLogProducerTest method testAsyncAuditLoggerCompleteWithVariables.
@Test
public void testAsyncAuditLoggerCompleteWithVariables() 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();
Map<String, Object> params = new HashMap<String, Object>();
params.put("s", "test value");
// 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)), 3000, 13);
// 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(6);
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).hasSize(2);
VariableInstanceLog var = variables.get(0);
// initial value from rule flow definition
Assertions.assertThat(var.getValue()).isEqualTo("InitialValue");
Assertions.assertThat(var.getOldValue()).isIn("", " ", null);
Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
Assertions.assertThat(var.getVariableId()).isEqualTo("s");
Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("s");
// value given at process start
var = variables.get(1);
// initial value from rule flow definition
Assertions.assertThat(var.getValue()).isEqualTo("test value");
Assertions.assertThat(var.getOldValue()).isEqualTo("InitialValue");
Assertions.assertThat(var.getProcessInstanceId().longValue()).isEqualTo(processInstance.getId());
Assertions.assertThat(var.getProcessId()).isEqualTo(processInstance.getProcessId());
Assertions.assertThat(var.getVariableId()).isEqualTo("s");
Assertions.assertThat(var.getVariableInstanceId()).isEqualTo("s");
logService.clear();
processInstances = logService.findProcessInstances("com.sample.ruleflow3");
logService.dispose();
Assertions.assertThat(processInstances).isNullOrEmpty();
}
use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class AuditDeleteTest method createTestVariableInstanceLogData.
private VariableInstanceLog[] createTestVariableInstanceLogData() {
StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
EntityManager em = jtaHelper.getEntityManager();
int numEntities = 8;
VariableInstanceLog[] testData = new VariableInstanceLog[numEntities];
ProcessInstanceLog[] testDataPI = new ProcessInstanceLog[numEntities];
Calendar cal = randomCal();
for (int i = 0; i < numEntities; ++i) {
VariableInstanceLog vil = new VariableInstanceLog();
vil.setProcessInstanceId(randomLong());
vil.setProcessId(randomString());
cal.add(Calendar.MINUTE, 1);
vil.setDate(cal.getTime());
vil.setVariableInstanceId(randomString());
vil.setVariableId(randomString());
vil.setValue(randomString());
vil.setOldValue(randomString());
vil.setExternalId(randomString());
testData[i] = vil;
ProcessInstanceLog pLog = buildCompletedProcessInstance(vil.getProcessInstanceId());
testDataPI[i] = pLog;
}
for (int i = 0; i < numEntities; ++i) {
switch(i) {
case 1:
testData[i - 1].setDate(testData[i].getDate());
break;
case 2:
testData[i - 1].setOldValue(testData[i].getOldValue());
break;
case 3:
testData[i - 1].setProcessId(testData[i].getProcessId());
break;
case 4:
testData[i - 1].setProcessInstanceId(testData[i].getProcessInstanceId());
break;
case 5:
testData[i - 1].setValue(testData[i].getValue());
break;
case 6:
testData[i - 1].setVariableId(testData[i].getVariableId());
break;
case 7:
testData[i - 1].setVariableInstanceId(testData[i].getVariableInstanceId());
break;
}
}
Object tx = jtaHelper.joinTransaction(em);
for (int i = 0; i < numEntities; ++i) {
em.persist(testDataPI[i]);
em.persist(testData[i]);
}
jtaHelper.leaveTransaction(em, tx);
return testData;
}
use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class AuditQueryDataUtil method createTestVariableInstanceLogData.
static VariableInstanceLog[] createTestVariableInstanceLogData(EntityManagerFactory emf) {
StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
EntityManager em = jtaHelper.getEntityManager();
int numEntities = 8;
VariableInstanceLog[] testData = new VariableInstanceLog[numEntities];
Calendar cal = randomCal();
for (int i = 0; i < numEntities; ++i) {
VariableInstanceLog vil = new VariableInstanceLog();
vil.setProcessInstanceId(randomLong());
vil.setProcessId(randomString());
cal.add(Calendar.MINUTE, 1);
vil.setDate(cal.getTime());
vil.setVariableInstanceId(randomString());
vil.setVariableId(randomString());
vil.setValue(randomString());
vil.setOldValue(randomString());
vil.setExternalId(randomString());
testData[i] = vil;
}
for (int i = 0; i < numEntities; ++i) {
switch(i) {
case 1:
testData[i - 1].setDate(testData[i].getDate());
break;
case 2:
testData[i - 1].setOldValue(testData[i].getOldValue());
break;
case 3:
testData[i - 1].setProcessId(testData[i].getProcessId());
break;
case 4:
testData[i - 1].setProcessInstanceId(testData[i].getProcessInstanceId());
break;
case 5:
testData[i - 1].setValue(testData[i].getValue());
break;
case 6:
testData[i - 1].setVariableId(testData[i].getVariableId());
break;
case 7:
testData[i - 1].setVariableInstanceId(testData[i].getVariableInstanceId());
break;
}
}
Object tx = jtaHelper.joinTransaction(em);
for (int i = 0; i < numEntities; ++i) {
em.persist(testData[i]);
}
jtaHelper.leaveTransaction(em, tx);
createdEntities.addAll(Arrays.asList(testData));
return testData;
}
use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class AuditQueryTest method variableValueTest.
@Test
public void variableValueTest() throws Exception {
int numLogs = 9;
VariableInstanceLog[] testData = new VariableInstanceLog[numLogs];
Calendar cal = GregorianCalendar.getInstance();
String processId = "org.variable.value";
for (int i = 0; i < testData.length; ++i) {
cal.roll(Calendar.SECOND, 1);
testData[i] = new VariableInstanceLog(randomLong(), processId, "varInstId", "var-" + i, "val-" + i, "oldVal-" + i);
}
persistEntities(testData);
VariableInstanceLogQueryBuilder queryBuilder;
ParametrizedQuery<org.kie.api.runtime.manager.audit.VariableInstanceLog> query;
List<org.kie.api.runtime.manager.audit.VariableInstanceLog> logs;
// check
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.processId(processId).build();
logs = query.getResultList();
assertEquals(numLogs + " logs expected", numLogs, logs.size());
// control: don't find any
queryBuilder = this.variableInstanceLogQuery().intersect().processId(processId);
query = queryBuilder.variableValue("var-1", "val-2").build();
logs = query.getResultList();
assertEquals("No logs expected", 0, logs.size());
// control: don't find any
queryBuilder = this.variableInstanceLogQuery().intersect().processId(processId);
query = queryBuilder.variableValue("var-1", "val-1").variableValue("var-2", "val-2").build();
logs = query.getResultList();
assertEquals("No logs expected", 0, logs.size());
// find 1
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.union().variableValue("var-1", "val-1").build();
logs = query.getResultList();
assertEquals("1 log expected", 1, logs.size());
assertEquals("Incorrect variable val", "val-1", logs.get(0).getValue());
assertEquals("Incorrect variable id", "var-1", logs.get(0).getVariableId());
// find 2
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.union().variableValue("var-2", "val-2").variableValue("var-4", "val-4").build();
logs = query.getResultList();
assertEquals("2 log expected", 2, logs.size());
for (org.kie.api.runtime.manager.audit.VariableInstanceLog varLog : logs) {
String id = varLog.getVariableId().substring("var-".length());
assertEquals("variable value", "val-" + id, varLog.getValue());
}
// regex: find 1
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.like().variableValue("var-2", "val-*").build();
logs = query.getResultList();
assertEquals("1 log expected", 1, logs.size());
assertEquals("Incorrect variable val", "val-2", logs.get(0).getValue());
assertEquals("Incorrect variable id", "var-2", logs.get(0).getVariableId());
// regex: find 2
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.regex().union().variableValue("var-2", "val-*").variableValue("var-3", "val-*").build();
logs = query.getResultList();
assertEquals("2 log expected", 2, logs.size());
for (org.kie.api.runtime.manager.audit.VariableInstanceLog varLog : logs) {
String id = varLog.getVariableId().substring("var-".length());
assertEquals("variable value", "val-" + id, varLog.getValue());
}
// regex: find 2 with last
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.newGroup().regex().union().variableValue("var-2", "val-*").variableValue("var-3", "val-*").endGroup().equals().intersect().last().build();
logs = query.getResultList();
assertEquals("2 log expected", 2, logs.size());
for (org.kie.api.runtime.manager.audit.VariableInstanceLog varLog : logs) {
String id = varLog.getVariableId().substring("var-".length());
assertEquals("variable value", "val-" + id, varLog.getValue());
}
removeEntities(testData);
}
use of org.jbpm.process.audit.VariableInstanceLog in project jbpm by kiegroup.
the class AuditQueryTest method removeEntities.
private void removeEntities(VariableInstanceLog[] testData) {
StandaloneJtaStrategy jtaHelper = new StandaloneJtaStrategy(emf);
EntityManager em = jtaHelper.getEntityManager();
int numLogs = testData.length;
Object tx = jtaHelper.joinTransaction(em);
for (int i = 0; i < numLogs; ++i) {
VariableInstanceLog mergedEntity = em.merge(testData[i]);
em.remove(mergedEntity);
}
jtaHelper.leaveTransaction(em, tx);
}
Aggregations