use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithMergeOfResultsNoDataBeforeCompletion.
@Test
public void testCompleteWithMergeOfResultsNoDataBeforeCompletion() {
final Map<String, Object> outputsAfterCompletion = new HashMap<String, Object>();
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Bobba Fet'), new User('Darth Vader') ], businessAdministrators = [ new User('Administrator') ],}),";
str += "name = 'This is my task name' })";
((EventService<TaskLifeCycleEventListener>) taskService).registerTaskEventListener(new DefaultTaskEventListener() {
@Override
public void afterTaskCompletedEvent(TaskEvent event) {
outputsAfterCompletion.putAll(event.getTask().getTaskData().getTaskOutputVariables());
}
});
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
task1 = taskService.getTaskById(taskId);
Map<String, Object> outputs = getTaskOutput(task1);
assertEquals(0, outputs.size());
Map<String, Object> params = new HashMap<String, Object>();
params.put("response", "let's do it");
params.put("feedback", "ok");
taskService.complete(taskId, "Darth Vader", params);
task1 = taskService.getTaskById(taskId);
assertEquals(Status.Completed, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
outputs = getTaskOutput(task1);
assertEquals(2, outputs.size());
assertEquals("let's do it", outputs.get("response"));
assertEquals("ok", outputs.get("feedback"));
// now let's check what was actually given to listeners
assertEquals(2, outputsAfterCompletion.size());
assertEquals("let's do it", outputsAfterCompletion.get("response"));
assertEquals("ok", outputsAfterCompletion.get("feedback"));
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleLocalWithRuleServiceTest method testCreateTaskWithDisallowedCreationBasedOnContentByRule.
@Test
public void testCreateTaskWithDisallowedCreationBasedOnContentByRule() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('john')],businessAdministrators = [ new User('Administrator') ], }),";
str += "descriptions = [ new I18NText( 'en-UK', 'This is my description')], ";
str += "subjects = [ new I18NText( 'en-UK', 'This is my subject')], ";
str += "names = [ new I18NText( 'en-UK', 'This is my task name')] })";
Task task = (Task) TaskFactory.evalTask(new StringReader(str));
Map<String, Object> params = new HashMap<String, Object>();
params.put("manager", "John");
try {
taskService.addTask(task, params);
fail("Task should not be created due to rule violation");
} catch (CannotAddTaskException e) {
assertTrue(e.getMessage().indexOf("John (manager) does not work here any more") != -1);
}
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleLocalWithRuleServiceTest method testCompleteTaskWithCheckByRule.
@Test
public void testCompleteTaskWithCheckByRule() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('mary')],businessAdministrators = [ new User('Administrator') ], }),";
str += "description = 'This is my description', ";
str += "subject = 'This is my subject', ";
str += "name = 'This is my task name' })";
Task task = (Task) TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
List<TaskSummary> tasks = taskService.getTasksOwned("mary", "en-UK");
assertNotNull(tasks);
assertEquals(1, tasks.size());
long taskId = tasks.get(0).getId();
taskService.start(taskId, "mary");
Map<String, Object> data = new HashMap<String, Object>();
data.put("approved", "false");
try {
taskService.complete(taskId, "mary", data);
fail("Task should not be created due to rule violation");
} catch (PermissionDeniedException e) {
assertTrue(e.getMessage().indexOf("Mary is not allowed to complete task with approved false") != -1);
}
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleLocalWithRuleServiceTest method testCreateTaskWithExcludedActorByRule.
@Test
public void testCreateTaskWithExcludedActorByRule() {
// One potential owner, should go straight to state Reserved
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { workItemId = 1 } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('john')],businessAdministrators = [ new User('Administrator') ], }),";
str += "description = 'This is my description', ";
str += "subject = 'This is my subject', ";
str += "name = 'This is my task name' })";
Task task = (Task) TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
List<TaskSummary> tasks = taskService.getTasksOwned("john", "en-UK");
assertNotNull(tasks);
assertEquals(0, tasks.size());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class SubTasksBaseTest method noActionStrategy.
@Test
public void noActionStrategy() throws Exception {
// One potential owner, should go straight to state Reserved
String parentTaskstr = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
parentTaskstr += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('salaboy') ],businessAdministrators = [ new User('Administrator') ], }),";
parentTaskstr += "names = [ new I18NText( 'en-UK', 'This is my task Parent name')] })";
// By default the task will contain a SubTask SubTasksStrategy.NoAction
Task parentTask = TaskFactory.evalTask(new StringReader(parentTaskstr));
taskService.addTask(parentTask, new HashMap<String, Object>());
long taskParentId = parentTask.getId();
// Task should remain in Created state with no actual owner
Task parentTask1 = taskService.getTaskById(taskParentId);
assertEquals(parentTask1.getTaskData().getStatus(), Status.Reserved);
taskService.start(taskParentId, "salaboy");
String child1Taskstr = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { parentId= " + taskParentId + " } ), ";
child1Taskstr += "peopleAssignments = (with ( new PeopleAssignments() ) { potentialOwners = [new User('Darth Vader') ],businessAdministrators = [ new User('Administrator') ], }),";
child1Taskstr += "names = [ new I18NText( 'en-UK', 'This is my task Child 1 name')] })";
Task child1Task = TaskFactory.evalTask(new StringReader(child1Taskstr));
taskService.addTask(child1Task, new HashMap<String, Object>());
long child1TaskId = child1Task.getId();
// Test if the task is succesfully created
assertEquals(1, taskService.getPendingSubTasksByParent(taskParentId));
Task childTask1 = taskService.getTaskById(child1TaskId);
assertEquals(taskParentId, childTask1.getTaskData().getParentId());
taskService.start(child1TaskId, "Darth Vader");
taskService.complete(child1TaskId, "Darth Vader", null);
childTask1 = taskService.getTaskById(child1TaskId);
assertEquals(Status.Completed, childTask1.getTaskData().getStatus());
parentTask1 = taskService.getTaskById(taskParentId);
assertEquals(Status.InProgress, parentTask1.getTaskData().getStatus());
assertEquals(0, taskService.getPendingSubTasksByParent(taskParentId));
taskService.complete(taskParentId, "salaboy", null);
parentTask1 = taskService.getTaskById(taskParentId);
assertEquals(Status.Completed, parentTask1.getTaskData().getStatus());
}
Aggregations