Search in sources :

Example 26 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class QueryDataServiceIntegrationTest method testGetProcessInstancesWithQueryDataServiceUsingCustomMapper.

@Test
public void testGetProcessInstancesWithQueryDataServiceUsingCustomMapper() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    List<Long> processInstanceIds = createProcessInstances(parameters);
    QueryDefinition query = createQueryDefinition("CUSTOM");
    try {
        queryClient.registerQuery(query);
        List<ProcessInstance> instances = queryClient.query(query.getName(), "CustomMapper", 0, 10, ProcessInstance.class);
        assertNotNull(instances);
        assertEquals(5, instances.size());
        List<Long> found = collectInstances(instances);
        assertEquals(processInstanceIds, found);
        instances = queryClient.query(query.getName(), "CustomMapper", 0, 3, ProcessInstance.class);
        assertNotNull(instances);
        assertEquals(3, instances.size());
        instances = queryClient.query(query.getName(), "CustomMapper", "status", 1, 3, ProcessInstance.class);
        assertNotNull(instances);
        assertEquals(2, instances.size());
    } finally {
        abortProcessInstances(processInstanceIds);
        queryClient.unregisterQuery(query.getName());
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 27 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class QueryDataServiceIntegrationTest method testGetProcessInstancesWithQueryDataServiceUsingCustomQueryBuilderAndColumnMapping.

@Test
public void testGetProcessInstancesWithQueryDataServiceUsingCustomQueryBuilderAndColumnMapping() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    List<Long> processInstanceIds = createProcessInstances(parameters);
    QueryDefinition query = getProcessInstanceWithVariablesQueryDefinition();
    try {
        queryClient.registerQuery(query);
        Map<String, String> columnMapping = new HashMap<>();
        columnMapping.put("variableId", "String");
        columnMapping.put("value", "String");
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("min", processInstanceIds.get(4));
        params.put("max", processInstanceIds.get(0));
        params.put(KieServerConstants.QUERY_ORDER_BY, "processInstanceId");
        params.put(KieServerConstants.QUERY_ASCENDING, false);
        params.put(KieServerConstants.QUERY_COLUMN_MAPPING, columnMapping);
        List<ProcessInstance> instances = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_PI_WITH_CUSTOM_VARS, "test", params, 0, 10, ProcessInstance.class);
        assertNotNull(instances);
        assertEquals(2, instances.size());
        long pi1 = instances.get(0).getId();
        long pi2 = instances.get(1).getId();
        // since sort order is descending first should be instance id which is bigger then second
        assertTrue(pi1 > pi2);
        for (ProcessInstance instance : instances) {
            final Map<String, Object> variables = instance.getVariables();
            assertNotNull(variables);
            assertEquals(2, variables.size());
            assertTrue(variables.containsKey("variableId"));
            assertTrue(variables.containsKey("value"));
        }
    } finally {
        abortProcessInstances(processInstanceIds);
        queryClient.unregisterQuery(query.getName());
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 28 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class QueryDataServiceIntegrationTest method testQueryDataServiceUsingComplexCustomQueryBuilderFilterSpecWithOrderByClause.

@Test
public void testQueryDataServiceUsingComplexCustomQueryBuilderFilterSpecWithOrderByClause() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    List<Long> processInstanceIds = createProcessInstances(parameters);
    final QueryDefinition query = getProcessInstanceWithVariablesQueryDefinition();
    try {
        queryClient.registerQuery(query);
        QueryParam expression = or(equalsTo("PROCESSINSTANCEID", processInstanceIds.get(0)), equalsTo("PROCESSINSTANCEID", processInstanceIds.get(1)));
        QueryFilterSpec filterSpec = QueryFilterSpec.builder().where(expression).get();
        List<ProcessInstance> instances = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_PI_WITH_VARS, filterSpec, 0, 10, ProcessInstance.class);
        assertNotNull(instances);
        assertEquals(2, instances.size());
    } finally {
        abortProcessInstances(processInstanceIds);
        queryClient.unregisterQuery(query.getName());
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) QueryFilterSpec(org.kie.server.api.model.definition.QueryFilterSpec) HashMap(java.util.HashMap) QueryParam(org.kie.server.api.model.definition.QueryParam) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 29 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class QueryDataServiceIntegrationTest method testGetProcessInstancesWithOrderByClause.

/*
     * JBPM-5468 Client requests with 'sortBy' request parameter can now use full ORDER BY clause syntax.
     */
@Test
public void testGetProcessInstancesWithOrderByClause() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    List<Long> processInstanceIds = createProcessInstances(parameters);
    QueryDefinition query = createQueryDefinition("CUSTOM");
    try {
        queryClient.registerQuery(query);
        List<ProcessInstance> instances = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_PI, "processId asc, processInstanceId desc", 0, 10, ProcessInstance.class);
        assertNotNull(instances);
        assertEquals(5, instances.size());
        List<Long> found = collectInstances(instances);
        assertEquals(processInstanceIds, found);
        long pi1 = instances.get(0).getId();
        long pi2 = instances.get(1).getId();
        // since sort order is descending first should be instance id which is bigger then second
        assertTrue(pi1 + " not greater than " + pi2, pi1 > pi2);
    } finally {
        abortProcessInstances(processInstanceIds);
        queryClient.unregisterQuery(query.getName());
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Example 30 with ProcessInstance

use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.

the class QueryDataServiceIntegrationTest method testGetProcessInstancesWithVariablesQueryDataService.

@Test
public void testGetProcessInstancesWithVariablesQueryDataService() throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("stringData", "waiting for signal");
    parameters.put("personData", createPersonInstance(USER_JOHN));
    parameters.put("nullAccepted", true);
    List<Long> processInstanceIds = createProcessInstances(parameters);
    final QueryDefinition query = getProcessInstanceWithVariablesQueryDefinition();
    try {
        queryClient.registerQuery(query);
        final List<ProcessInstance> instances = queryClient.query(query.getName(), QueryServicesClient.QUERY_MAP_PI_WITH_VARS, 0, 20, ProcessInstance.class);
        assertNotNull(instances);
        final List<Long> found = collectInstances(instances);
        assertEquals(processInstanceIds, found);
        for (ProcessInstance instance : instances) {
            final Map<String, Object> variables = instance.getVariables();
            assertNotNull(variables);
            assertEquals(4, variables.size());
            assertEquals(TestConfig.getUsername(), variables.get("initiator"));
            assertEquals("waiting for signal", variables.get("stringData"));
            assertEquals("Person{name='john'}", variables.get("personData"));
            assertEquals("true", variables.get("nullAccepted"));
        }
    } finally {
        abortProcessInstances(processInstanceIds);
        queryClient.unregisterQuery(query.getName());
    }
}
Also used : QueryDefinition(org.kie.server.api.model.definition.QueryDefinition) HashMap(java.util.HashMap) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) Test(org.junit.Test)

Aggregations

ProcessInstance (org.kie.server.api.model.instance.ProcessInstance)125 Test (org.junit.Test)97 HashMap (java.util.HashMap)75 TaskSummary (org.kie.server.api.model.instance.TaskSummary)31 ArrayList (java.util.ArrayList)24 QueryDefinition (org.kie.server.api.model.definition.QueryDefinition)22 KieServicesException (org.kie.server.api.exception.KieServicesException)17 ProcessDefinition (org.kie.server.api.model.definition.ProcessDefinition)11 List (java.util.List)9 QueryServicesClient (org.kie.server.client.QueryServicesClient)9 JbpmKieServerBaseIntegrationTest (org.kie.server.integrationtests.jbpm.JbpmKieServerBaseIntegrationTest)9 Category (org.junit.experimental.categories.Category)7 CorrelationKey (org.kie.internal.process.CorrelationKey)7 CorrelationKeyFactory (org.kie.internal.process.CorrelationKeyFactory)7 ProcessServicesClient (org.kie.server.client.ProcessServicesClient)7 Arrays (java.util.Arrays)6 Map (java.util.Map)6 Assertions (org.assertj.core.api.Assertions)6 After (org.junit.After)6 TaskInstance (org.kie.server.api.model.instance.TaskInstance)6