Search in sources :

Example 76 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ProcessServiceEJBIntegrationTest method testStartAndSignalProcess.

@Test
public void testStartAndSignalProcess() {
    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(), "signal");
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(processInstanceId);
    assertNotNull(pi);
    Collection<String> signals = processService.getAvailableSignals(processInstanceId);
    assertNotNull(signals);
    assertEquals(1, signals.size());
    assertTrue(signals.contains("MySignal"));
    processService.signalProcessInstance(processInstanceId, "MySignal", null);
    pi = processService.getProcessInstance(processInstanceId);
    assertNull(pi);
}
Also used : ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) Test(org.junit.Test)

Example 77 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ProcessServiceEJBIntegrationTest 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) Test(org.junit.Test)

Example 78 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ProcessServiceEJBIntegrationTest method testStartProcessWithParmsWithCorrelationKey.

@Test
public void testStartProcessWithParmsWithCorrelationKey() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", "test");
    CorrelationKey key = KieInternalServices.Factory.get().newCorrelationKeyFactory().newCorrelationKey("my business key");
    long processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "customtask", key, params);
    assertNotNull(processInstanceId);
    ProcessInstance pi = processService.getProcessInstance(key);
    assertNull(pi);
}
Also used : HashMap(java.util.HashMap) CorrelationKey(org.kie.internal.process.CorrelationKey) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) Test(org.junit.Test)

Example 79 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ClientProcessServiceWithCustomDataEJBTest method testStartProcessWithCustomData.

@Test
public void testStartProcessWithCustomData() {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    Map<String, Object> parameters = new RemoteMap();
    Object person = getInstance("org.jbpm.test.Person", new Object[] { "john", 25, true });
    parameters.put("person", person);
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "custom-data-project.work-on-custom-data", parameters);
    assertNotNull(processInstanceId);
    List<TaskSummary> taskSummaries = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter(0, 10));
    assertNotNull(taskSummaries);
    assertEquals(1, taskSummaries.size());
    List<Long> tasks = runtimeDataService.getTasksByProcessInstanceId(processInstanceId);
    assertNotNull(tasks);
    assertEquals(1, tasks.size());
    Long taskId = tasks.get(0);
    userTaskService.start(taskId, "john");
    Map<String, Object> data = userTaskService.getTaskInputContentByTaskId(taskId);
    assertNotNull(data);
    Object fromTaskPerson = data.get("_person");
    assertNotNull(fromTaskPerson);
    assertEquals("john", getFieldValue(fromTaskPerson, "name"));
    setFieldValue(fromTaskPerson, "name", "John Doe");
    RemoteMap outcome = new RemoteMap();
    outcome.put("person_", fromTaskPerson);
    userTaskService.complete(taskId, "john", outcome);
    ProcessInstanceDesc desc = runtimeDataService.getProcessInstanceById(processInstanceId);
    assertNotNull(desc);
    assertEquals(2, (int) desc.getState());
    processInstanceId = null;
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) RemoteMap(org.jbpm.services.ejb.remote.api.RemoteMap) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Example 80 with KModuleDeploymentUnit

use of org.jbpm.kie.services.impl.KModuleDeploymentUnit in project jbpm by kiegroup.

the class ClientEjbTimerServiceTest method testStartProcessWithHTDeadline.

@Test
public void testStartProcessWithHTDeadline() throws InterruptedException {
    assertNotNull(deploymentService);
    KModuleDeploymentUnit deploymentUnit = new KModuleDeploymentUnit(GROUP_ID, ARTIFACT_ID, VERSION);
    deploymentService.deploy(deploymentUnit);
    units.add(deploymentUnit);
    assertNotNull(processService);
    processInstanceId = processService.startProcess(deploymentUnit.getIdentifier(), "htdeadlinetest");
    List<TaskSummary> krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(1, krisTasks.size());
    List<TaskSummary> johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(0, johnTasks.size());
    List<TaskSummary> maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());
    // now wait for 2 seconds for first reassignment
    Thread.sleep(3000);
    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(1, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());
    userTaskService.start(johnTasks.get(0).getId(), "john");
    // now wait for 2 more seconds for second reassignment
    Thread.sleep(2000);
    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(1, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(0, maryTasks.size());
    // now wait for 1 seconds to make sure that reassignment did not happen any more since task was already started
    Thread.sleep(3000);
    krisTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("krisv", new QueryFilter());
    assertEquals(0, krisTasks.size());
    johnTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
    assertEquals(0, johnTasks.size());
    maryTasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
    assertEquals(1, maryTasks.size());
    userTaskService.start(maryTasks.get(0).getId(), "mary");
    userTaskService.complete(maryTasks.get(0).getId(), "mary", null);
    // now wait for 2 seconds to make sure that reassignment did not happen any more since task was completed
    Thread.sleep(2000);
    ProcessInstance processInstance = processService.getProcessInstance(processInstanceId);
    assertNull(processInstance);
    processInstanceId = null;
}
Also used : QueryFilter(org.kie.internal.query.QueryFilter) TaskSummary(org.kie.api.task.model.TaskSummary) ProcessInstance(org.kie.api.runtime.process.ProcessInstance) KModuleDeploymentUnit(org.jbpm.kie.services.impl.KModuleDeploymentUnit) AbstractKieServicesBaseTest(org.jbpm.kie.test.util.AbstractKieServicesBaseTest) Test(org.junit.Test)

Aggregations

KModuleDeploymentUnit (org.jbpm.kie.services.impl.KModuleDeploymentUnit)170 Test (org.junit.Test)131 AbstractKieServicesBaseTest (org.jbpm.kie.test.util.AbstractKieServicesBaseTest)97 ProcessInstance (org.kie.api.runtime.process.ProcessInstance)83 DeploymentUnit (org.jbpm.services.api.model.DeploymentUnit)55 HashMap (java.util.HashMap)46 DeployedUnit (org.jbpm.services.api.model.DeployedUnit)42 ArrayList (java.util.ArrayList)34 QueryContext (org.kie.api.runtime.query.QueryContext)34 ReleaseId (org.kie.api.builder.ReleaseId)29 KieServices (org.kie.api.KieServices)26 File (java.io.File)22 ProcessDefinition (org.jbpm.services.api.model.ProcessDefinition)22 DeploymentDescriptor (org.kie.internal.runtime.conf.DeploymentDescriptor)21 DeploymentDescriptorImpl (org.jbpm.runtime.manager.impl.deploy.DeploymentDescriptorImpl)19 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)19 RuntimeManager (org.kie.api.runtime.manager.RuntimeManager)19 Before (org.junit.Before)18 FileOutputStream (java.io.FileOutputStream)17 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)17