Search in sources :

Example 11 with NodeInstanceDesc

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

the class ProcessServiceImplTest method testStartProcessAndGetWorkItems.

@Test
public void testStartProcessAndGetWorkItems() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertEquals("Write a Document", activeNodes.iterator().next().getName());
    List<WorkItem> wis = processService.getWorkItemByProcessInstance(processInstanceId);
    assertNotNull(wis);
    assertEquals(1, wis.size());
    assertEquals("Human Task", wis.get(0).getName());
    assertEquals("Write a Document", wis.get(0).getParameter("NodeName"));
    processService.abortProcessInstance(processInstanceId);
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) WorkItem(org.kie.api.runtime.process.WorkItem) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 12 with NodeInstanceDesc

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

the class ProcessServiceImplTest method testStartProcessAndCompleteWorkItem.

@Test
public void testStartProcessAndCompleteWorkItem() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertEquals("Write a Document", activeNodes.iterator().next().getName());
    Map<String, Object> outcome = new HashMap<String, Object>();
    outcome.put("Result", "here is my first document");
    processService.completeWorkItem(activeNodes.iterator().next().getWorkItemId(), outcome);
    activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(2, activeNodes.size());
    Object variableValue = processService.getProcessInstanceVariable(processInstanceId, "approval_document");
    assertNotNull(variableValue);
    assertTrue(variableValue instanceof String);
    assertEquals("here is my first document", variableValue);
    processService.abortProcessInstance(processInstanceId);
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
}
Also used : HashMap(java.util.HashMap) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 13 with NodeInstanceDesc

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

the class ProcessServiceImplTest method testStartProcessAndAbortWorkItem.

@Test
public void testStartProcessAndAbortWorkItem() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    boolean isDeployed = deploymentService.isDeployed(deploymentUnit.getIdentifier());
    assertTrue(isDeployed);
    assertNotNull(processService);
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "org.jbpm.writedocument");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    Collection<NodeInstanceDesc> activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(1, activeNodes.size());
    assertEquals("Write a Document", activeNodes.iterator().next().getName());
    processService.abortWorkItem(activeNodes.iterator().next().getWorkItemId());
    activeNodes = runtimeDataService.getProcessInstanceHistoryActive(processInstanceId, new QueryContext());
    assertNotNull(activeNodes);
    assertEquals(2, activeNodes.size());
    Object variableValue = processService.getProcessInstanceVariable(processInstanceId, "approval_document");
    assertNull(variableValue);
    processService.abortProcessInstance(processInstanceId);
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) QueryContext(org.kie.api.runtime.query.QueryContext) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) NodeInstanceDesc(org.jbpm.services.api.model.NodeInstanceDesc) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 14 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc 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 15 with NodeInstanceDesc

use of org.jbpm.services.api.model.NodeInstanceDesc 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)

Aggregations

NodeInstanceDesc (org.jbpm.services.api.model.NodeInstanceDesc)45 Test (org.junit.Test)40 QueryContext (org.kie.api.runtime.query.QueryContext)29 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)20 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)19 KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)15 HashMap (java.util.HashMap)14 ProcessInstanceDesc (org.jbpm.services.api.model.ProcessInstanceDesc)12 AbstractCaseServicesBaseTest (org.jbpm.casemgmt.impl.util.AbstractCaseServicesBaseTest)9 TaskSummary (org.kie.api.task.model.TaskSummary)9 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)8 WorkItem (org.kie.api.runtime.process.WorkItem)8 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)7 KModuleDeploymentServiceTest (org.jbpm.kie.services.test.KModuleDeploymentServiceTest)6 QueryFilter (org.kie.internal.query.QueryFilter)6 AdHocFragmentNotFoundException (org.jbpm.casemgmt.api.AdHocFragmentNotFoundException)4 CaseActiveException (org.jbpm.casemgmt.api.CaseActiveException)4 CaseCommentNotFoundException (org.jbpm.casemgmt.api.CaseCommentNotFoundException)4 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)4 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)4