use of org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder in project jbpm by kiegroup.
the class AuditQueryTest method lastVariableTest.
@Test
public void lastVariableTest() throws Exception {
int numLogs = 10;
VariableInstanceLog[] testData = new VariableInstanceLog[numLogs];
Calendar cal = GregorianCalendar.getInstance();
for (int i = 0; i < 5; ++i) {
cal.roll(Calendar.SECOND, 1);
testData[i] = new VariableInstanceLog(23L, "org.lots.of.vars", "inst", "first-var", "val-a", "oldVal-" + i);
testData[i + 5] = new VariableInstanceLog(23L, "org.lots.of.vars", "inst", "second-var", "val-b", "oldVal-" + i);
testData[i].setDate(cal.getTime());
testData[i + 5].setDate(cal.getTime());
}
persistEntities(testData);
VariableInstanceLogQueryBuilder queryBuilder;
ParametrizedQuery<org.kie.api.runtime.manager.audit.VariableInstanceLog> query;
List<org.kie.api.runtime.manager.audit.VariableInstanceLog> logs;
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.last().intersect().processInstanceId(23L).build();
logs = query.getResultList();
assertEquals("2 logs", 2, logs.size());
queryBuilder = this.variableInstanceLogQuery();
query = queryBuilder.value("val-a").intersect().last().build();
logs = query.getResultList();
assertEquals("Only 1 log expected", 1, logs.size());
assertEquals("Incorrect variable val", "val-a", logs.get(0).getValue());
assertEquals("Incorrect variable old val", "oldVal-4", logs.get(0).getOldValue());
removeEntities(testData);
}
use of org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder in project jbpm by kiegroup.
the class AuditQueryCoverageTest method variableInstanceLogQueryBuilderCoverageTest.
@Test
public void variableInstanceLogQueryBuilderCoverageTest() {
VariableInstanceLogQueryBuilder queryBuilder = this.variableInstanceLogQuery();
Class builderClass = VariableInstanceLogQueryBuilder.class;
queryBuilderCoverageTest(queryBuilder, builderClass, inputFiller);
}
use of org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder in project jbpm by kiegroup.
the class AuditQueryTest method simpleVariableInstanceLogQueryBuilderTest.
@Test
public void simpleVariableInstanceLogQueryBuilderTest() {
int p = 0;
Date date = vilTestData[p++].getDate();
VariableInstanceLogQueryBuilder builder = this.variableInstanceLogQuery().date(date);
List<org.kie.api.runtime.manager.audit.VariableInstanceLog> resultList = builder.build().getResultList();
assertEquals("date query result", 2, resultList.size());
{
String oldValue = vilTestData[p++].getOldValue();
builder = this.variableInstanceLogQuery().oldValue(oldValue);
resultList = builder.build().getResultList();
assertEquals("old value query result", 2, resultList.size());
}
{
String processId = vilTestData[p++].getProcessId();
builder = this.variableInstanceLogQuery().processId(processId);
resultList = builder.build().getResultList();
assertEquals("process id query result", 2, resultList.size());
}
{
long processInstanceId = vilTestData[p++].getProcessInstanceId();
builder = this.variableInstanceLogQuery().processInstanceId(processInstanceId);
resultList = builder.build().getResultList();
assertEquals("process instance id query result", 2, resultList.size());
}
{
String value = vilTestData[p++].getValue();
builder = this.variableInstanceLogQuery().value(value);
resultList = builder.build().getResultList();
assertEquals("value query result", 2, resultList.size());
}
{
String variableId = vilTestData[p++].getVariableId();
builder = this.variableInstanceLogQuery().variableId(variableId);
resultList = builder.build().getResultList();
assertEquals("variable id query result", 2, resultList.size());
}
{
String varInstId = vilTestData[p++].getVariableInstanceId();
builder = this.variableInstanceLogQuery().variableInstanceId(varInstId);
resultList = builder.build().getResultList();
assertEquals("variable instance id query result", 2, resultList.size());
}
}
use of org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder 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);
}
Aggregations