Search in sources :

Example 1 with VariableInstanceLogQueryBuilder

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);
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) VariableInstanceLogQueryBuilder(org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder) Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) AuditLogServiceTest(org.jbpm.process.audit.AuditLogServiceTest) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 2 with VariableInstanceLogQueryBuilder

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);
}
Also used : VariableInstanceLogQueryBuilder(org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder) BeforeClass(org.junit.BeforeClass) QueryBuilderCoverageTestUtil.afterClass(org.jbpm.query.QueryBuilderCoverageTestUtil.afterClass) AfterClass(org.junit.AfterClass) QueryBuilderCoverageTestUtil.beforeClass(org.jbpm.query.QueryBuilderCoverageTestUtil.beforeClass) QueryBuilderCoverageTestUtil.queryBuilderCoverageTest(org.jbpm.query.QueryBuilderCoverageTestUtil.queryBuilderCoverageTest) Test(org.junit.Test)

Example 3 with VariableInstanceLogQueryBuilder

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());
    }
}
Also used : VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) VariableInstanceLogQueryBuilder(org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder) Date(java.util.Date) AuditLogServiceTest(org.jbpm.process.audit.AuditLogServiceTest) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Example 4 with VariableInstanceLogQueryBuilder

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);
}
Also used : Calendar(java.util.Calendar) GregorianCalendar(java.util.GregorianCalendar) VariableInstanceLog(org.jbpm.process.audit.VariableInstanceLog) VariableInstanceLogQueryBuilder(org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder) AuditLogServiceTest(org.jbpm.process.audit.AuditLogServiceTest) Test(org.junit.Test) AbstractBaseTest(org.jbpm.test.util.AbstractBaseTest)

Aggregations

Test (org.junit.Test)4 VariableInstanceLogQueryBuilder (org.kie.internal.runtime.manager.audit.query.VariableInstanceLogQueryBuilder)4 AuditLogServiceTest (org.jbpm.process.audit.AuditLogServiceTest)3 VariableInstanceLog (org.jbpm.process.audit.VariableInstanceLog)3 AbstractBaseTest (org.jbpm.test.util.AbstractBaseTest)3 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 Date (java.util.Date)1 QueryBuilderCoverageTestUtil.afterClass (org.jbpm.query.QueryBuilderCoverageTestUtil.afterClass)1 QueryBuilderCoverageTestUtil.beforeClass (org.jbpm.query.QueryBuilderCoverageTestUtil.beforeClass)1 QueryBuilderCoverageTestUtil.queryBuilderCoverageTest (org.jbpm.query.QueryBuilderCoverageTestUtil.queryBuilderCoverageTest)1 AfterClass (org.junit.AfterClass)1 BeforeClass (org.junit.BeforeClass)1