use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class AbstractCaseServicesBaseTest method assertCaseInstanceNotActive.
public void assertCaseInstanceNotActive(String caseId) {
try {
CaseInstance caseInstance = caseService.getCaseInstance(caseId);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getStatus()).isIn(CaseStatus.CLOSED.getId(), CaseStatus.CANCELLED.getId());
} catch (CaseNotFoundException ex) {
// in case it does not exist at all
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testAddSubprocessToEmptyCaseCheckCaseNodes.
@Test
public void testAddSubprocessToEmptyCaseCheckCaseNodes() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
Collection<NodeInstanceDesc> completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(0, completedNodes.size());
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicSubprocess(caseId, "UserTask", parameters);
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(2, activeNodes.size());
Map<String, NodeInstanceDesc> mappedNodes = mapNodeInstances(activeNodes);
assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(0, completedNodes.size());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertEquals(1, tasks.size());
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
activeNodes = caseRuntimeDataService.getActiveNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(activeNodes);
assertEquals(0, activeNodes.size());
completedNodes = caseRuntimeDataService.getCompletedNodesForCase(caseId, new QueryContext(0, 10));
assertNotNull(completedNodes);
assertEquals(2, completedNodes.size());
assertEquals("HumanTaskNode", mappedNodes.get("Hello").getNodeType());
assertEquals("SubProcessNode", mappedNodes.get("[Dynamic] Sub Process").getNodeType());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testUserTasksInCase.
@Test
public void testUserTasksInCase() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
String caseId2 = null;
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(0, tasks.size());
Map<String, Object> taskInput = new HashMap<>();
taskInput.put("ActorId", "john");
taskInput.put("Comment", "Need to provide data");
caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals("Missing data", task.getName());
assertEquals("Need to provide data", task.getSubject());
caseId2 = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
assertNotNull(caseId2);
assertEquals("CASE-0000000002", caseId2);
caseService.triggerAdHocFragment(caseId2, "Missing data", taskInput);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId2, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals("Missing data", task.getName());
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertEquals("Missing data", task.getName());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
if (caseId2 != null) {
caseService.cancelCase(caseId2);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testStartEmptyCaseWithCaseFile.
/*
* Case instance queries
*/
@Test
public void testStartEmptyCaseWithCaseFile() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId, true, false, false, false);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertNotNull(cInstance.getCaseFile());
assertEquals("my first case", cInstance.getCaseFile().getData("name"));
Collection<CaseInstance> instances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(instances);
assertEquals(1, instances.size());
CaseInstance instance = instances.iterator().next();
assertNotNull(instance);
assertEquals(FIRST_CASE_ID, instance.getCaseId());
assertEquals(EMPTY_CASE_P_ID, instance.getCaseDefinitionId());
assertEquals("my first case", instance.getCaseDescription());
assertEquals(USER, instance.getOwner());
assertEquals(ProcessInstance.STATE_ACTIVE, instance.getStatus().intValue());
assertEquals(deploymentUnit.getIdentifier(), instance.getDeploymentId());
assertNotNull(instance.getStartedAt());
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicTask(FIRST_CASE_ID, caseService.newHumanTaskSpec("First task", "test", "john", null, parameters));
Collection<NodeInstanceDesc> activeNodes = caseRuntimeDataService.getActiveNodesForCase(FIRST_CASE_ID, new QueryContext());
assertNotNull(activeNodes);
assertEquals(1, activeNodes.size());
NodeInstanceDesc activeNode = activeNodes.iterator().next();
assertNotNull(activeNodes);
assertEquals("[Dynamic] First task", activeNode.getName());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals("First task", task.getName());
assertEquals("test", task.getDescription());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseRuntimeDataServiceImplTest method testUserTasksInCaseWithSubprocess.
@Test
public void testUserTasksInCaseWithSubprocess() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl(USER));
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(FIRST_CASE_ID, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(0, tasks.size());
Map<String, Object> taskInput = new HashMap<>();
taskInput.put("ActorId", "john");
caseService.triggerAdHocFragment(caseId, "Missing data", taskInput);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertEquals("Missing data", task.getName());
caseService.addDynamicSubprocess(caseId, "UserTask", null);
tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(caseId, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(2, tasks.size());
task = tasks.get(0);
assertEquals("Hello", task.getName());
task = tasks.get(1);
assertEquals("Missing data", task.getName());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations