use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesWithRawMapperMultipleRows.
@Test
public void testGetProcessInstancesWithRawMapperMultipleRows() {
query = new SqlQueryDefinition("getAllProcessInstances", dataSourceJNDIname);
query.setExpression("select * from processinstancelog");
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryDefinition registeredQuery = queries.get(0);
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
registeredQuery = queryService.getQuery(query.getName());
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
List<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext());
assertNotNull(instances);
assertEquals(0, instances.size());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
Long processInstanceId2 = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId2);
instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext());
assertNotNull(instances);
assertEquals(2, instances.size());
List<Object> firstRow = instances.get(0);
assertNotNull(firstRow);
assertEquals(18, firstRow.size());
List<Object> secondRow = instances.get(1);
assertNotNull(secondRow);
assertEquals(18, secondRow.size());
Assert.assertNotEquals(firstRow, secondRow);
processService.abortProcessInstance(processInstanceId2);
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesWithQueryParamBuilder.
@Test
public void testGetProcessInstancesWithQueryParamBuilder() {
query = new SqlQueryDefinition("getAllProcessInstances", dataSourceJNDIname);
query.setExpression("select * from processinstancelog");
queryService.registerQuery(query);
Collection<ProcessInstanceDesc> instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext());
assertNotNull(instances);
assertEquals(0, instances.size());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
QueryParamBuilderFactory qbFactory = new TestQueryParamBuilderFactory();
assertTrue(qbFactory.accept("test"));
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("min", processInstanceId);
parameters.put("max", processInstanceId + 2);
QueryParamBuilder<?> paramBuilder = qbFactory.newInstance(parameters);
instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), paramBuilder);
assertNotNull(instances);
assertEquals(1, instances.size());
parameters = new HashMap<String, Object>();
parameters.put("min", processInstanceId + 2);
parameters.put("max", 0l);
paramBuilder = qbFactory.newInstance(parameters);
instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), paramBuilder);
assertNotNull(instances);
assertEquals(0, instances.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetTaskInstancesAsPotOwners.
@Test
public void testGetTaskInstancesAsPotOwners() {
query = new SqlQueryDefinition("getMyTaskInstances", dataSourceJNDIname, Target.PO_TASK);
query.setExpression(PO_TASK_QUERY);
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
QueryDefinition registeredQuery = queries.get(0);
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
registeredQuery = queryService.getQuery(query.getName());
assertNotNull(registeredQuery);
assertEquals(query.getName(), registeredQuery.getName());
assertEquals(query.getSource(), registeredQuery.getSource());
assertEquals(query.getExpression(), registeredQuery.getExpression());
assertEquals(query.getTarget(), registeredQuery.getTarget());
Map<String, Object> params = new HashMap<String, Object>();
params.put("approval_document", "initial content");
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
assertNotNull(processInstanceId);
identityProvider.setName("notvalid");
List<UserTaskInstanceDesc> taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(0, taskInstanceLogs.size());
identityProvider.setName("salaboy");
taskInstanceLogs = queryService.query(query.getName(), UserTaskInstanceQueryMapper.get(), new QueryContext());
assertNotNull(taskInstanceLogs);
assertEquals(1, taskInstanceLogs.size());
List<TaskSummary> taskSummaries = queryService.query(query.getName(), TaskSummaryQueryMapper.get(), new QueryContext());
assertNotNull(taskSummaries);
assertEquals(1, taskSummaries.size());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesCount.
@Test
public void testGetProcessInstancesCount() {
query = new SqlQueryDefinition("getAllProcessInstances", dataSourceJNDIname);
query.setExpression("select * from processinstancelog");
queryService.registerQuery(query);
List<QueryDefinition> queries = queryService.getQueries(new QueryContext());
assertNotNull(queries);
assertEquals(1, queries.size());
Collection<List<Object>> instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), QueryParam.count(COLUMN_PROCESSINSTANCEID));
assertNotNull(instances);
assertEquals(1, instances.size());
List<Object> result = instances.iterator().next();
assertNotNull(result);
assertEquals(1, result.size());
assertTrue(result.get(0) instanceof Number);
assertEquals(0, ((Number) result.get(0)).intValue());
processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
assertNotNull(processInstanceId);
instances = queryService.query(query.getName(), RawListQueryMapper.get(), new QueryContext(), QueryParam.count(COLUMN_PROCESSINSTANCEID));
assertNotNull(instances);
assertEquals(1, instances.size());
result = instances.iterator().next();
assertNotNull(result);
assertEquals(1, result.size());
assertTrue(result.get(0) instanceof Number);
assertEquals(1, ((Number) result.get(0)).intValue());
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
use of org.jbpm.kie.services.impl.query.SqlQueryDefinition in project jbpm by kiegroup.
the class QueryServiceImplTest method testGetProcessInstancesWithCustomVariables.
@Test
public void testGetProcessInstancesWithCustomVariables() throws Exception {
deploymentService.deploy(deploymentUnitJPA);
units.add(deploymentUnitJPA);
query = new SqlQueryDefinition("getAllProcessInstancesWithCustomVariables", dataSourceJNDIname);
query.setExpression("select pi.*, c.firstname, c.lastname, c.age, c.customerId from ProcessInstanceLog pi " + "inner join (select mv.map_var_id, mv.processInstanceId from MappedVariable mv) mv " + "on (mv.processInstanceId = pi.processinstanceId) " + "inner join Customer c " + "on (c.id = mv.map_var_id)");
queryService.registerQuery(query);
RuntimeManager manager = deploymentService.getRuntimeManager(deploymentUnitJPA.getIdentifier());
assertNotNull(manager);
Class<?> clazz = Class.forName("org.jbpm.test.Customer", true, ((InternalRuntimeManager) manager).getEnvironment().getClassLoader());
Object cinstance = clazz.newInstance();
// set fields
setFieldValue(cinstance, "firstName", "john");
setFieldValue(cinstance, "lastName", "doe");
setFieldValue(cinstance, "age", new Integer(45));
setFieldValue(cinstance, "customerId", new Long(1234));
Map<String, Object> params = new HashMap<String, Object>();
params.put("customer", cinstance);
processInstanceId = processService.startProcess(deploymentUnitJPA.getIdentifier(), "persistence-test.customer-evaluation", params);
assertNotNull(processInstanceId);
Map<String, String> variableMap = new HashMap<String, String>();
variableMap.put("FIRSTNAME", "string");
variableMap.put("LASTNAME", "string");
variableMap.put("AGE", "integer");
variableMap.put("CUSTOMERID", "long");
List<ProcessInstanceWithVarsDesc> processInstanceLogs = queryService.query(query.getName(), ProcessInstanceWithCustomVarsQueryMapper.get(variableMap), new QueryContext());
assertNotNull(processInstanceLogs);
assertEquals(1, processInstanceLogs.size());
ProcessInstanceWithVarsDesc instance = processInstanceLogs.get(0);
assertEquals(4, instance.getVariables().size());
assertTrue(instance.getVariables().containsKey("FIRSTNAME"));
assertTrue(instance.getVariables().containsKey("LASTNAME"));
assertTrue(instance.getVariables().containsKey("AGE"));
assertTrue(instance.getVariables().containsKey("CUSTOMERID"));
assertEquals("john", instance.getVariables().get("FIRSTNAME"));
assertEquals("doe", instance.getVariables().get("LASTNAME"));
assertEquals(45, instance.getVariables().get("AGE"));
assertEquals(1234l, instance.getVariables().get("CUSTOMERID"));
processService.abortProcessInstance(processInstanceId);
processInstanceId = null;
}
Aggregations