use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testSuspendFromReservedWithIncorrectUser.
@Test
public void testSuspendFromReservedWithIncorrectUser() {
// 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' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// Check is Reserved
taskService.claim(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Check is not changed
PermissionDeniedException denied = null;
try {
taskService.suspend(taskId, "Bobba Fet");
} catch (PermissionDeniedException e) {
denied = e;
}
assertNotNull("Should get permissed denied exception", denied);
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task2.getTaskData().getStatus());
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithContentAndVarListener.
protected void testCompleteWithContentAndVarListener(TaskLifeCycleEventListener listener) {
// 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(listener);
Map<String, Object> params = new HashMap<String, Object>();
params.put("input", "simple input");
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, params);
long taskId = task.getId();
// start task
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// complete task with output
params = new HashMap<String, Object>();
params.put("content", "content");
taskService.complete(taskId, "Darth Vader", params);
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testActivate.
@Test
public void testActivate() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { ";
str += "businessAdministrators = [ new User('Darth Vader') ] } ),";
str += "name = 'This is my task name' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
taskService.activate(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(task1.getTaskData().getStatus(), Status.Ready);
// When we are not using remoting the object is the same
// assertTrue(task1.equals(task));
// When we use remoting this will be false
// assertFalse(task1.equals(task));
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testResumeFromReserved.
@Test
public void testResumeFromReserved() {
// 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' })";
Task task = TaskFactory.evalTask(new StringReader(str));
taskService.addTask(task, new HashMap<String, Object>());
long taskId = task.getId();
// Check is Reserved
taskService.claim(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Check is suspended
taskService.suspend(taskId, "Darth Vader");
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task2.getTaskData().getPreviousStatus());
assertEquals(Status.Suspended, task2.getTaskData().getStatus());
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
// Check is Resumed
taskService.resume(taskId, "Darth Vader");
Task task3 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task3.getTaskData().getStatus());
assertEquals(Status.Suspended, task3.getTaskData().getPreviousStatus());
assertEquals("Darth Vader", task3.getTaskData().getActualOwner().getId());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testCompleteWithMergeOfResults.
@Test
public void testCompleteWithMergeOfResults() {
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) {
Map<String, Object> outs = event.getTask().getTaskData().getTaskOutputVariables();
if (outs != null) {
outputsAfterCompletion.putAll(outs);
}
}
});
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());
taskService.complete(taskId, "Darth Vader", null);
task1 = taskService.getTaskById(taskId);
assertEquals(Status.Completed, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
outputs = getTaskOutput(task1);
assertEquals(0, outputs.size());
// now let's check what was actually given to listeners
assertEquals(0, outputsAfterCompletion.size());
}
Aggregations