Search in sources :

Example 71 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class RuntimeDataServiceImplTest method testGetProcessInstanceById.

@Test
public void testGetProcessInstanceById() {
    Collection<ProcessInstanceDesc> instances = runtimeDataService.getProcessInstances(new QueryContext());
    assertNotNull(instances);
    assertEquals(0, instances.size());
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstanceDesc instance = runtimeDataService.getProcessInstanceById(processInstanceId);
    assertNotNull(instance);
    assertEquals(1, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
    List<UserTaskInstanceDesc> tasks = instance.getActiveTasks();
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    UserTaskInstanceDesc activeTask = tasks.get(0);
    assertNotNull(activeTask);
    assertEquals(Status.Reserved.name(), activeTask.getStatus());
    assertEquals(instance.getId(), activeTask.getProcessInstanceId());
    assertEquals(instance.getProcessId(), activeTask.getProcessId());
    assertEquals("Write a Document", activeTask.getName());
    assertEquals("salaboy", activeTask.getActualOwner());
    assertEquals(deploymentUnit.getIdentifier(), activeTask.getDeploymentId());
    processService.abortProcessInstance(processInstanceId);
    instance = runtimeDataService.getProcessInstanceById(processInstanceId);
    processInstanceId = null;
    assertNotNull(instance);
    assertEquals(3, (int) instance.getState());
    assertEquals("org.jbpm.writedocument", instance.getProcessId());
}
Also used : ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) UserTaskInstanceDesc(org.jbpm.services.api.model.UserTaskInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 72 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class RuntimeDataServiceImplTest method testGetProcessInstancesByVariableAndValue.

@Test
public void testGetProcessInstancesByVariableAndValue() {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approval_document", "initial content");
    params.put("approval_reviewComment", "not yet reviewed");
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument", params);
    assertNotNull(processInstanceId);
    Collection<ProcessInstanceDesc> processInstanceLogs = runtimeDataService.getProcessInstancesByVariableAndValue("approval_document", "initial content", null, new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    processService.setProcessVariable(processInstanceId, "approval_document", "updated content");
    processInstanceLogs = runtimeDataService.getProcessInstancesByVariableAndValue("approval_document", "initial content", null, new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(0, processInstanceLogs.size());
    processInstanceLogs = runtimeDataService.getProcessInstancesByVariableAndValue("approval_document", "updated content", null, new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    processInstanceLogs = runtimeDataService.getProcessInstancesByVariableAndValue("approval_document", "updated%", null, new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    processInstanceLogs = runtimeDataService.getProcessInstancesByVariableAndValue("approval_reviewComment", "not yet%", null, new QueryContext());
    assertNotNull(processInstanceLogs);
    assertEquals(1, processInstanceLogs.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
}
Also used : HashMap(java.util.HashMap) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 73 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImplTest method testUpdateTimerRelative.

@Test(timeout = 10000)
public void testUpdateTimerRelative() throws Exception {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "IntermediateCatchEvent");
    assertNotNull(processInstanceId);
    long scheduleTime = System.currentTimeMillis();
    Collection<NodeInstanceDesc> activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstanceDesc active = activeNodes.iterator().next();
    assertEquals("timer", active.getName());
    Collection<TimerInstance> timers = processAdminService.getTimerInstances(processInstanceId);
    assertNotNull(timers);
    assertEquals(1, timers.size());
    TimerInstance timer = timers.iterator().next();
    assertNotNull(timer.getActivationTime());
    assertNotNull(timer.getDelay());
    assertNotNull(timer.getNextFireTime());
    assertNotNull(timer.getProcessInstanceId());
    assertNotNull(timer.getSessionId());
    assertNotNull(timer.getTimerId());
    assertNotNull(timer.getTimerName());
    // thread sleep to test the different in the time timer spent after upgrade
    // not to wait for any job to be done
    Thread.sleep(1000);
    processAdminService.updateTimerRelative(processInstanceId, timer.getTimerId(), 3, 0, 0);
    CountDownListenerFactory.getExisting("processAdminService").waitTillCompleted();
    long fireTime = System.currentTimeMillis();
    // since the update of timer was relative (to current time) then it must wait at least 3 secs
    long expirationTime = fireTime - scheduleTime;
    assertTrue(expirationTime > 3000);
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
    processInstanceId = null;
}
Also used : TimerInstance(org.jbpm.services.api.admin.TimerInstance) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 74 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class ProcessInstanceAdminServiceImplTest method testTrigerLastActionNode.

@Test
public void testTrigerLastActionNode() {
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    Collection<NodeInstanceDesc> activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    NodeInstanceDesc active = activeNodes.iterator().next();
    assertEquals("Write a Document", active.getName());
    List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(1, tasks.size());
    Collection<ProcessNode> processNodes = processAdminService.getProcessNodes(processInstanceId);
    ProcessNode writeDocNode = processNodes.stream().filter(pn -> pn.getNodeName().equals("Report")).findFirst().orElse(null);
    processAdminService.triggerNode(processInstanceId, writeDocNode.getNodeId());
    activeNodes = processAdminService.getActiveNodeInstances(processInstanceId);
    assertNotNull(activeNodes);
    assertEquals(0, activeNodes.size());
    tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("salaboy", new QueryFilter());
    assertEquals(0, tasks.size());
    ProcessInstanceDesc pi = runtimeDataService.getProcessInstanceById(processInstanceId);
    assertEquals(ProcessInstance.STATE_COMPLETED, pi.getState().intValue());
    processInstanceId = null;
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessNode(org.jbpm.services.api.admin.ProcessNode) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) KModuleDeploymentServiceTest(org.jbpm.kie.services.test.KModuleDeploymentServiceTest) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 75 with ProcessInstanceDesc

use of org.jbpm.services.api.model.ProcessInstanceDesc in project jbpm by kiegroup.

the class QueryServiceEJBIntegrationTest method testGetProcessInstancesByState.

@Test
public void testGetProcessInstancesByState() {
    query = new SqlQueryDefinition("getAllProcessInstances", "java:jboss/datasources/ExampleDS");
    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);
    // search for aborted only
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_STATUS, 3));
    assertNotNull(instances);
    assertEquals(0, instances.size());
    // aborted and active
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_STATUS, 3, 1));
    assertNotNull(instances);
    assertEquals(1, instances.size());
    processService.abortProcessInstance(processInstanceId);
    processInstanceId = null;
    // aborted only
    instances = queryService.query(query.getName(), ProcessInstanceQueryMapper.get(), new QueryContext(), QueryParam.equalsTo(COLUMN_STATUS, 3));
    assertNotNull(instances);
    assertEquals(1, instances.size());
    assertEquals(3, (int) instances.iterator().next().getState());
}
Also used : SqlQueryDefinition(org.jbpm.kie.services.impl.query.SqlQueryDefinition) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) QueryContext(org.kie.api.runtime.query.QueryContext) Test(org.junit.Test)

Aggregations

ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)198 Test (org.junit.Test)147 QueryContext (org.kie.api.runtime.query.QueryContext)123 ArrayList (java.util.ArrayList)75 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)57 HashMap (java.util.HashMap)32 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)25 TaskSummary (org.kie.api.task.model.TaskSummary)25 QueryFilter (org.kie.internal.query.QueryFilter)23 RemoteEjbTest (org.jbpm.remote.ejb.test.RemoteEjbTest)17 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)16 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)16 UserTaskInstanceDesc (org.jbpm.services.api.model.UserTaskInstanceDesc)15 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)12 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)12 NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)12 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)11 CorrelationKey (org.kie.internal.process.CorrelationKey)11 SqlQueryDefinition (org.jbpm.kie.services.impl.query.SqlQueryDefinition)9 List (java.util.List)7