use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testSuspendFromReserved.
@Test
public void testSuspendFromReserved() {
// 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());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testSkipFromReady.
@Test
public void testSkipFromReady() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { skipable = true} ), ";
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 Complete
taskService.skip(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Obsolete, task1.getTaskData().getStatus());
assertNull(task1.getTaskData().getActualOwner());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testStartFromReadyStateWithIncorrectPotentialOwner.
@Test
public void testStartFromReadyStateWithIncorrectPotentialOwner() {
// 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();
// A Task with multiple potential owners moves to "Ready" state until someone claims it.
List<TaskSummary> tasksAssignedAsPotentialOwner = taskService.getTasksAssignedAsPotentialOwner("Bobba Fet", "en-UK");
assertEquals(1, tasksAssignedAsPotentialOwner.size());
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Ready, task1.getTaskData().getStatus());
// State should not change as user isn't potential owner
PermissionDeniedException denied = null;
try {
taskService.start(taskId, "Tony Stark");
} catch (PermissionDeniedException e) {
denied = e;
}
assertNotNull("Should get permissed denied exception", denied);
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Ready, task2.getTaskData().getStatus());
assertNull(task2.getTaskData().getActualOwner());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testFailWithIncorrectUser.
@Test
public void testFailWithIncorrectUser() {
// 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();
// Go straight from Ready to Inprogress
taskService.start(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
// Should not fail as wrong user
PermissionDeniedException denied = null;
try {
taskService.fail(taskId, "Bobba Fet", null);
} catch (PermissionDeniedException e) {
denied = e;
}
assertNotNull("Should get permissed denied exception", denied);
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, 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 testStartFromReserved.
@Test
public void testStartFromReserved() throws Exception {
// 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') ], 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();
// Task should be assigned to the single potential owner and state set to Reserved
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task1.getTaskData().getStatus());
assertEquals("Bobba Fet", task1.getTaskData().getActualOwner().getId());
// Should change to InProgress
taskService.start(taskId, "Bobba Fet");
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task2.getTaskData().getStatus());
assertEquals("Bobba Fet", task1.getTaskData().getActualOwner().getId());
}
Aggregations