use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class QueryClientIntegrationTest method testFindProcessInstancesByContainerId.
@Test
public void testFindProcessInstancesByContainerId() {
final Long processInstanceId = startProcess(CONTAINER_ID, PROCESS_WITH_SIGNAL_ID);
final List<Integer> statuses = Arrays.asList(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
final Map<String, Object> parameters = new HashMap<>();
parameters.put("containerId", CONTAINER_ID);
parameters.put("page", "0");
parameters.put("pageSize", "10");
parameters.put("status", statuses);
final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
executionServerCommand.setClient("query");
executionServerCommand.setOperation("findProcessInstancesByContainerId");
executionServerCommand.setParameters(parameters);
final Object response = runOnExecutionServer(executionServerCommand);
Assertions.assertThat(response).isNotNull();
Assertions.assertThat(response).isInstanceOf(List.class);
final List<ProcessInstance> processInstances = (List<ProcessInstance>) response;
Assertions.assertThat(processInstances).isNotEmpty();
final List<Long> processInstancesIds = processInstances.stream().map(p -> p.getId()).collect(Collectors.toList());
Assertions.assertThat(processInstancesIds).contains(processInstanceId);
sendSignalToProcessInstance(CONTAINER_ID, processInstanceId, SIGNAL_NAME);
}
use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class QueryClientIntegrationTest method testFindProcessInstanceByInitiator.
@Test
public void testFindProcessInstanceByInitiator() {
final Long processInstanceId = startProcess(CONTAINER_ID, PROCESS_WITH_SIGNAL_ID);
final List<Integer> statuses = Arrays.asList(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE);
final Map<String, Object> parameters = new HashMap<>();
parameters.put("initiator", INITIATOR);
parameters.put("status", statuses);
parameters.put("page", "0");
parameters.put("pageSize", "10");
final ExecutionServerCommand executionServerCommand = new ExecutionServerCommand();
executionServerCommand.setClient("query");
executionServerCommand.setOperation("findProcessInstancesByInitiator");
executionServerCommand.setParameters(parameters);
final Object response = runOnExecutionServer(executionServerCommand);
Assertions.assertThat(response).isNotNull();
Assertions.assertThat(response).isInstanceOf(List.class);
final List<ProcessInstance> processInstances = (List<ProcessInstance>) response;
Assertions.assertThat(processInstances).isNotEmpty();
final List<Long> processInstancesIds = processInstances.stream().map(p -> p.getId()).collect(Collectors.toList());
Assertions.assertThat(processInstancesIds).contains(processInstanceId);
sendSignalToProcessInstance(CONTAINER_ID, processInstanceId, SIGNAL_NAME);
}
use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class RuntimeDataServiceIntegrationTest method testGetProcessInstanceByCorrelationKeyPaging.
@Test
public void testGetProcessInstanceByCorrelationKeyPaging() throws Exception {
CorrelationKeyFactory correlationKeyFactory = KieInternalServices.Factory.get().newCorrelationKeyFactory();
String businessKey = "simple-key";
CorrelationKey key = correlationKeyFactory.newCorrelationKey(businessKey);
// Start and abort 2 processes to be sure that there are processes to be returned.
Map<String, Object> parameters = new HashMap<String, Object>();
Long processInstanceId1 = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, key, parameters);
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId1);
Long processInstanceId2 = processClient.startProcess(CONTAINER_ID, PROCESS_ID_EVALUATION, key, parameters);
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId2);
List<ProcessInstance> processInstancesPage0 = queryClient.findProcessInstancesByCorrelationKey(key, 0, 1);
List<ProcessInstance> processInstancesPage1 = queryClient.findProcessInstancesByCorrelationKey(key, 1, 1);
assertEquals(1, processInstancesPage0.size());
assertEquals(1, processInstancesPage1.size());
assertNotEquals("Process instances are same! Paging doesn't work.", processInstancesPage0.get(0).getId(), processInstancesPage1.get(0).getId());
}
use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class RuntimeDataServiceIntegrationTest method testGetProcessInstancesByInitiatorSortedByName.
@Test
public void testGetProcessInstancesByInitiatorSortedByName() 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);
try {
List<ProcessInstance> instances = queryClient.findProcessInstancesByInitiator(USER_YODA, null, 0, 3, SORT_BY_PROCESS_ID, true);
assertNotNull(instances);
assertEquals(3, instances.size());
for (ProcessInstance instance : instances) {
assertTrue(processInstanceIds.contains(instance.getId()));
assertEquals(PROCESS_ID_SIGNAL_PROCESS, instance.getProcessId());
}
instances = queryClient.findProcessInstancesByInitiator(USER_YODA, null, 1, 3, SORT_BY_PROCESS_ID, true);
assertNotNull(instances);
assertEquals(2, instances.size());
for (ProcessInstance instance : instances) {
assertTrue(processInstanceIds.contains(instance.getId()));
assertEquals(PROCESS_ID_USERTASK, instance.getProcessId());
}
instances = queryClient.findProcessInstancesByInitiator(USER_YODA, null, 0, 10, SORT_BY_PROCESS_ID, false);
assertNotNull(instances);
assertEquals(5, instances.size());
for (int i = 0; i < instances.size(); i++) {
if (i < 2) {
assertEquals(PROCESS_ID_USERTASK, instances.get(i).getProcessId());
} else {
assertEquals(PROCESS_ID_SIGNAL_PROCESS, instances.get(i).getProcessId());
}
}
} finally {
abortProcessInstances(processInstanceIds);
}
}
use of org.kie.server.api.model.instance.ProcessInstance in project droolsjbpm-integration by kiegroup.
the class RuntimeDataServiceIntegrationTest method testGetProcessInstanceWithVariables.
@Test
public void testGetProcessInstanceWithVariables() throws Exception {
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("stringData", "waiting for signal");
Object person = createPersonInstance(USER_JOHN);
parameters.put("personData", person);
Long processInstanceId = processClient.startProcess(CONTAINER_ID, PROCESS_ID_SIGNAL_PROCESS, parameters);
assertNotNull(processInstanceId);
assertTrue(processInstanceId.longValue() > 0);
try {
ProcessInstance processInstance = queryClient.findProcessInstanceById(processInstanceId, true);
assertNotNull(processInstance);
assertEquals(processInstanceId, processInstance.getId());
assertEquals(org.kie.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.getState().intValue());
assertEquals(PROCESS_ID_SIGNAL_PROCESS, processInstance.getProcessId());
assertEquals("signalprocess", processInstance.getProcessName());
assertEquals("1.0", processInstance.getProcessVersion());
assertEquals(CONTAINER_ID, processInstance.getContainerId());
assertEquals("signalprocess", processInstance.getProcessInstanceDescription());
assertEquals(TestConfig.getUsername(), processInstance.getInitiator());
assertEquals(-1l, processInstance.getParentId().longValue());
assertNotNull(processInstance.getCorrelationKey());
assertNotNull(processInstance.getDate());
Map<String, Object> variables = processInstance.getVariables();
assertNotNull(variables);
assertEquals(4, variables.size());
assertTrue(variables.containsKey("stringData"));
assertTrue(variables.containsKey("personData"));
assertTrue(variables.containsKey("initiator"));
assertTrue(variables.containsKey("nullAccepted"));
String stringVar = (String) variables.get("stringData");
Object personVar = variables.get("personData");
String initiator = (String) variables.get("initiator");
assertNotNull(personVar);
assertEquals(person.toString(), personVar);
assertNotNull(stringVar);
assertEquals("waiting for signal", stringVar);
assertNotNull(initiator);
assertEquals(TestConfig.getUsername(), initiator);
} finally {
processClient.abortProcessInstance(CONTAINER_ID, processInstanceId);
}
}
Aggregations