use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testTriggerNotExistingAdHocFragment.
@Test
public void testTriggerNotExistingAdHocFragment() {
String expectedCaseId = "UniqueID-0000000001";
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("patient", new UserImpl("john"));
Map<String, Object> data = new HashMap<>();
data.put("s", "description");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), "CaseWithRolesDefinition", data, roleAssignments);
identityProvider.setName("mary");
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), "CaseWithRolesDefinition", caseFile);
assertNotNull(caseId);
assertEquals(expectedCaseId, caseId);
try {
CaseInstance cInstance = caseService.getCaseInstance(caseId);
assertNotNull(cInstance);
assertEquals(expectedCaseId, cInstance.getCaseId());
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
identityProvider.setName("john");
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(expectedCaseId, "john", Arrays.asList(Status.Reserved), new QueryContext());
assertEquals(1, tasks.size());
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
identityProvider.setName("mary");
try {
caseService.triggerAdHocFragment(expectedCaseId, "not existing", null);
fail("There is no ad hoc fragment with name 'not existing'");
} catch (AdHocFragmentNotFoundException e) {
// expected
}
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
identityProvider.setName("mary");
caseService.cancelCase(caseId);
}
}
}
use of org.jbpm.casemgmt.api.model.instance.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddSubprocessToEmptyCase.
@Test
public void testAddSubprocessToEmptyCase() {
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());
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicSubprocess(FIRST_CASE_ID, SUBPROCESS_P_ID, parameters);
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
Collection<NodeInstanceDesc> nodes = runtimeDataService.getProcessInstanceHistoryCompleted(casePI.getId(), new QueryContext());
assertNotNull(nodes);
assertEquals(3, nodes.size());
Map<String, String> nodesByName = nodes.stream().collect(toMap(NodeInstanceDesc::getName, NodeInstanceDesc::getNodeType));
assertTrue(nodesByName.containsKey("StartProcess"));
assertTrue(nodesByName.containsKey("EndProcess"));
assertTrue(nodesByName.containsKey("[Dynamic] Sub Process"));
assertEquals("StartNode", nodesByName.get("StartProcess"));
assertEquals("EndNode", nodesByName.get("EndProcess"));
assertEquals("SubProcessNode", nodesByName.get("[Dynamic] Sub Process"));
caseService.addDynamicSubprocess(casePI.getId(), SUBPROCESS_P_ID, parameters);
// let's verify that there are three process instances related to this case
caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(3, caseProcessInstances.size());
} 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.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddSubprocessToCaseWithStage.
@Test
public void testAddSubprocessToCaseWithStage() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
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());
CaseDefinition caseDef = caseRuntimeDataService.getCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_CASE_P_ID);
assertNotNull(caseDef);
assertEquals(1, caseDef.getCaseStages().size());
assertEquals(deploymentUnit.getIdentifier(), caseDef.getDeploymentId());
CaseStage stage = caseDef.getCaseStages().iterator().next();
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicSubprocessToStage(FIRST_CASE_ID, stage.getId(), SUBPROCESS_P_ID, parameters);
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
caseService.addDynamicSubprocessToStage(casePI.getId(), stage.getId(), SUBPROCESS_P_ID, parameters);
// let's verify that there are three process instances related to this case
caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(3, caseProcessInstances.size());
} 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.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddSubprocessToEmptyCaseAndClose.
@Test
public void testAddSubprocessToEmptyCaseAndClose() {
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());
// add dynamic user task to empty case instance - first by case id
Map<String, Object> parameters = new HashMap<>();
caseService.addDynamicSubprocess(FIRST_CASE_ID, SUBPROCESS_P_ID, parameters);
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
caseService.closeCase(caseId, "not needed any more");
cInstance = caseRuntimeDataService.getCaseInstanceById(caseId);
assertNotNull(cInstance);
assertEquals(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
assertEquals("not needed any more", cInstance.getCompletionMessage());
caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, Arrays.asList(2), new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(2, caseProcessInstances.size());
caseId = null;
} 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.CaseFileInstance in project jbpm by kiegroup.
the class CaseServiceImplTest method testStartCaseWithStageAndAdHocFragments.
@Test
public void testStartCaseWithStageAndAdHocFragments() {
Map<String, Object> data = new HashMap<>();
data.put("name", "my first case");
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_ADHOC_CASE_P_ID, data);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_ADHOC_CASE_P_ID, caseFile);
assertNotNull(caseId);
assertEquals(FIRST_CASE_ID, caseId);
try {
assertCaseInstance(caseId, "my first case");
Collection<AdHocFragment> availableFragments = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
assertEquals(2, availableFragments.size());
Map<String, AdHocFragment> mapped = mapAdHocFragments(availableFragments);
assertEquals("HumanTaskNode", mapped.get("Adhoc 1").getType());
assertEquals("HumanTaskNode", mapped.get("Adhoc 2").getType());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertTask(tasks.get(0), "john", "Initial step", Status.Reserved);
userTaskService.completeAutoProgress(tasks.get(0).getId(), "john", null);
availableFragments = caseRuntimeDataService.getAdHocFragmentsForCase(caseId);
assertEquals(4, availableFragments.size());
mapped = mapAdHocFragments(availableFragments);
assertEquals("HumanTaskNode", mapped.get("Adhoc 1").getType());
assertEquals("HumanTaskNode", mapped.get("Adhoc 2").getType());
assertEquals("HumanTaskNode", mapped.get("First").getType());
assertEquals("HumanTaskNode", mapped.get("Second").getType());
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations