use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.
the class CaseServiceImplTest method testAddUserTaskToEmptyCase.
@Test
public void testAddUserTaskToEmptyCase() {
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<>();
parameters.put("variable", "#{name}");
caseService.addDynamicTask(FIRST_CASE_ID, caseService.newHumanTaskSpec("First task", "test", "john", null, parameters));
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
TaskSummary task = tasks.get(0);
assertTask(task, "john", "First task", Status.Reserved);
assertEquals("test", task.getDescription());
Map<String, Object> inputs = userTaskService.getTaskInputContentByTaskId(task.getId());
assertNotNull(inputs);
assertEquals("my first case", inputs.get("variable"));
String nameVar = (String) processService.getProcessInstanceVariable(task.getProcessInstanceId(), "name");
assertNotNull(nameVar);
assertEquals("my first case", nameVar);
userTaskService.start(task.getId(), "john");
Map<String, Object> outcome = new HashMap<>();
outcome.put("name", "updated by dynamic task");
userTaskService.complete(task.getId(), "john", outcome);
nameVar = (String) processService.getProcessInstanceVariable(task.getProcessInstanceId(), "name");
assertNotNull(nameVar);
assertEquals("updated by dynamic task", nameVar);
// second task add by process instance id
Collection<ProcessInstanceDesc> caseProcessInstances = caseRuntimeDataService.getProcessInstancesForCase(caseId, new QueryContext());
assertNotNull(caseProcessInstances);
assertEquals(1, caseProcessInstances.size());
ProcessInstanceDesc casePI = caseProcessInstances.iterator().next();
assertNotNull(casePI);
assertEquals(FIRST_CASE_ID, casePI.getCorrelationKey());
caseService.addDynamicTask(casePI.getId(), caseService.newHumanTaskSpec("Second task", "another test", "mary", null, parameters));
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("mary", new QueryFilter());
assertNotNull(tasks);
assertEquals(1, tasks.size());
task = tasks.get(0);
assertTask(task, "mary", "Second task", Status.Reserved);
assertEquals("another test", task.getDescription());
// User john cannot work with task assigned to mary
try {
userTaskService.start(task.getId(), "john");
} catch (TaskNotFoundException e) {
// expected
}
userTaskService.start(task.getId(), "mary");
userTaskService.complete(task.getId(), "mary", null);
Collection<NodeInstanceDesc> nodes = runtimeDataService.getProcessInstanceHistoryCompleted(casePI.getId(), new QueryContext());
assertNotNull(nodes);
assertEquals(4, 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] First task"));
assertTrue(nodesByName.containsKey("[Dynamic] Second task"));
assertEquals("StartNode", nodesByName.get("StartProcess"));
assertEquals("EndNode", nodesByName.get("EndProcess"));
assertEquals("Human Task", nodesByName.get("[Dynamic] First task"));
assertEquals("Human Task", nodesByName.get("[Dynamic] Second task"));
} 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.kie.internal.query.QueryFilter in project jbpm by kiegroup.
the class CaseServiceImplTest method testCaseWithStageAutoStartNodes.
@Test
public void testCaseWithStageAutoStartNodes() {
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_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());
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner("john", new QueryFilter());
assertNotNull(tasks);
assertEquals(2, tasks.size());
assertTask(tasks.get(0), "john", "Ask for input", Status.Reserved);
assertTask(tasks.get(1), "john", "Missing data", Status.Reserved);
} 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.kie.internal.query.QueryFilter in project jbpm by kiegroup.
the class StageCompletionConditionTest method testAutoCompleteDynamicSubProcess.
@Test
public void testAutoCompleteDynamicSubProcess() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_AUTOCOMPLETE);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
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.addDynamicSubprocessToStage(caseId, stageId, USER_TASK_PROCESS, Collections.emptyMap());
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceActive(caseId);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary dynamicTask = tasks.get(0);
assertThat(dynamicTask.getName()).isEqualTo(HELLO_TASK);
userTaskService.completeAutoProgress(dynamicTask.getId(), USER, null);
assertCaseInstanceNotActive(caseId);
}
use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.
the class StageCompletionConditionTest method testCaseFileVariableWithoutPrefix.
@Test
public void testCaseFileVariableWithoutPrefix() {
Map<String, Object> data = new HashMap<>();
data.put("continue", false);
CaseFileInstance caseFile = caseService.newCaseFileInstance(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_VARIABLE_NO_PREFIX, data, Collections.emptyMap());
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_CASE_FILE_VARIABLE_NO_PREFIX, caseFile);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
caseService.addDataToCaseFile(caseId, "continue", true);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceNotActive(caseId);
}
use of org.kie.internal.query.QueryFilter in project jbpm by kiegroup.
the class StageCompletionConditionTest method testAutoCompleteNoAutoStartTask.
@Test
public void testAutoCompleteNoAutoStartTask() {
String caseId = caseService.startCase(deploymentUnit.getIdentifier(), STAGE_WITH_TASK_NO_AUTOSTART);
assertThat(caseId).isNotNull().isEqualTo(FIRST_CASE_ID);
assertCaseInstanceActive(caseId);
List<TaskSummary> tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).isEmpty();
caseService.triggerAdHocFragment(caseId, INSIDE_TASK, null);
assertCaseInstanceActive(caseId);
tasks = runtimeDataService.getTasksAssignedAsPotentialOwner(USER, new QueryFilter());
assertThat(tasks).hasSize(1);
TaskSummary insideTask = tasks.get(0);
assertThat(insideTask.getName()).isEqualTo(INSIDE_TASK);
userTaskService.completeAutoProgress(insideTask.getId(), USER, null);
assertCaseInstanceNotActive(caseId);
}
Aggregations