use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseCommentNotificationTest method testCommentsNotificationWithTemplate.
@Test
public void testCommentsNotificationWithTemplate() {
Map<String, OrganizationalEntity> roleAssignments = new HashMap<>();
roleAssignments.put("owner", new UserImpl("john"));
TestNotificationPublisher publisher = new TestNotificationPublisher(false);
CommentNotificationEventListener listener = CommentNotificationEventListenerFactory.get("test");
listener.addPublisher(publisher);
Map<String, Object> data = new HashMap<>();
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_CASE_P_ID, data, roleAssignments);
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), USER_TASK_STAGE_AUTO_START_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<CommentInstance> caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(0, caseComments.size());
caseService.addCaseComment(FIRST_CASE_ID, "poul", "just a tiny comment refering to @owner");
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
CommentInstance comment = caseComments.iterator().next();
assertComment(comment, "poul", "just a tiny comment refering to @owner");
String expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with template mentioned-in-comment";
List<String> published = publisher.get();
assertThat(published).hasSize(1);
assertThat(published.get(0)).isEqualTo(expectedNotification);
caseService.updateCaseComment(FIRST_CASE_ID, comment.getId(), comment.getAuthor(), "Updated " + comment.getComment());
caseComments = caseService.getCaseComments(FIRST_CASE_ID, new QueryContext());
assertNotNull(caseComments);
assertEquals(1, caseComments.size());
comment = caseComments.iterator().next();
assertComment(comment, "poul", "Updated just a tiny comment refering to @owner");
expectedNotification = "Publishing notification from cases@jbpm.org, with subject You have been mentioned in case (CASE-0000000001) comment to [[UserImpl:'john']] with template mentioned-in-comment";
published = publisher.get();
assertThat(published).hasSize(1);
assertThat(published.get(0)).isEqualTo(expectedNotification);
} 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 CaseDynamicNodesTest method testAddDynamicUserTaskToEmptyStage.
@Test
public void testAddDynamicUserTaskToEmptyStage() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(DYNAMIC_TASK);
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).isEmpty();
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseDynamicNodesTest method testAddDynamicSubprocessWithNotExistingProcessId.
@Test
public void testAddDynamicSubprocessWithNotExistingProcessId() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_P_ID);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
CaseStatus initialStatus = CaseStatus.fromId(caseInstance.getStatus());
assertThatThrownBy(() -> caseService.addDynamicSubprocess(caseId, NOT_EXISTING_SUBPROCESS, Collections.emptyMap())).isInstanceOf(ProcessDefinitionNotFoundException.class);
// case instance status should not have changed
caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
CaseStatus afterStatus = CaseStatus.fromId(caseInstance.getStatus());
assertThat(initialStatus).isEqualTo(afterStatus);
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class CaseDynamicNodesTest method testAddMultipleDynamicTasksToStage.
@Test
public void testAddMultipleDynamicTasksToStage() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), EMPTY_CASE_STAGE, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
CaseInstance caseInstance = caseService.getCaseInstance(caseId, false, false, false, true);
assertThat(caseInstance).isNotNull();
assertThat(caseInstance.getCaseStages()).hasSize(1);
String stageId = caseInstance.getCaseStages().iterator().next().getId();
caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
caseService.addDynamicTaskToStage(caseId, stageId, createUserTask());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(2);
TaskSummary userTask1 = tasks.get(0);
assertThat(userTask1.getName()).isEqualTo(DYNAMIC_TASK);
userTaskService.completeAutoProgress(userTask1.getId(), USER, null);
TaskSummary userTask2 = tasks.get(1);
assertThat(userTask2.getName()).isEqualTo(DYNAMIC_TASK);
userTaskService.completeAutoProgress(userTask2.getId(), USER, null);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).isEmpty();
}
use of org.jbpm.casemgmt.api.model.instance.CaseInstance in project jbpm by kiegroup.
the class SubCaseServiceImplTest method testStartCaseWithIndependentDynamicSubCase.
private void testStartCaseWithIndependentDynamicSubCase(String idependent, Consumer<String> finishCase) {
Map<String, Object> data = new HashMap<>();
data.put("name", "John Doe");
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(deploymentUnit.getIdentifier(), cInstance.getDeploymentId());
Map<String, Object> parameters = new HashMap<>();
parameters.put("CaseDefinitionId", "UserTaskCase");
parameters.put("DeploymentId", deploymentUnit.getIdentifier());
parameters.put("UserRole_owner", "john");
parameters.put("Data_s", "#{name}");
parameters.put("Independent", idependent);
TaskSpecification taskSpecification = caseService.newTaskSpec("StartCaseInstance", "Sub Case", parameters);
caseService.addDynamicTask(caseId, taskSpecification);
Collection<CaseInstance> caseInstances = caseRuntimeDataService.getCaseInstances(new QueryContext());
assertNotNull(caseInstances);
assertEquals(2, caseInstances.size());
Map<String, CaseInstance> byCaseId = caseInstances.stream().collect(toMap(CaseInstance::getCaseId, c -> c));
assertTrue(byCaseId.containsKey(FIRST_CASE_ID));
assertTrue(byCaseId.containsKey(HR_CASE_ID));
List<TaskSummary> tasks = caseRuntimeDataService.getCaseTasksAssignedAsPotentialOwner(HR_CASE_ID, "john", null, new QueryContext());
assertNotNull(tasks);
assertEquals(1, tasks.size());
assertEquals("Hello1", tasks.get(0).getName());
CaseFileInstance mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertEquals(HR_CASE_ID, mainCaseFile.getData("CaseId"));
assertEquals("John Doe", mainCaseFile.getData("s"));
finishCase.accept(HR_CASE_ID);
mainCaseFile = caseService.getCaseFileInstance(caseId);
assertNotNull(mainCaseFile);
assertEquals(HR_CASE_ID, mainCaseFile.getData("CaseId"));
assertEquals("John Doe", mainCaseFile.getData("s"));
} catch (Exception e) {
logger.error("Unexpected error {}", e.getMessage(), e);
fail("Unexpected exception " + e.getMessage());
} finally {
if (caseId != null) {
caseService.cancelCase(caseId);
}
}
}
Aggregations