use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testStartFromReservedWithIncorrectUser.
@Test
public void testStartFromReservedWithIncorrectUser() {
// 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 not change
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.Reserved, task2.getTaskData().getStatus());
assertEquals("Bobba Fet", task1.getTaskData().getActualOwner().getId());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testNominateWithIncorrectUser.
@Test
public void testNominateWithIncorrectUser() {
String str = "(with (new Task()) { priority = 55, taskData = (with( new TaskData()) { } ), ";
str += "peopleAssignments = (with ( new PeopleAssignments() ) { businessAdministrators = [ new User('Bobba Fet') ] } ),";
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();
try {
List<OrganizationalEntity> potentialOwners = new ArrayList<OrganizationalEntity>(1);
User user = createUser("Jabba Hutt");
potentialOwners.add(user);
taskService.nominate(taskId, "Darth Vader", potentialOwners);
fail("Shouldn't be successful");
} catch (RuntimeException e) {
// expected
// assertNotNull(nominateHandler.getError());
// assertNotNull(nominateHandler.getError().getMessage());
// assertTrue(nominateHandler.getError().getMessage().contains("Darth Vader"));
}
// shouldn't affect the assignments
Task task1 = taskService.getTaskById(taskId);
User user = createUser("Bobba Fet");
assertTrue(task1.getPeopleAssignments().getBusinessAdministrators().contains(user));
assertEquals(task1.getTaskData().getStatus(), Status.Created);
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testResumeFromCompleted.
@Test
public void testResumeFromCompleted() {
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();
taskService.claim(taskId, "Darth Vader");
Task task1 = taskService.getTaskById(taskId);
assertEquals(Status.Reserved, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
taskService.start(taskId, "Darth Vader");
task1 = taskService.getTaskById(taskId);
assertEquals(Status.InProgress, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
taskService.complete(taskId, "Darth Vader", null);
task1 = taskService.getTaskById(taskId);
assertEquals(Status.Completed, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
assertThatExceptionOfType(PermissionDeniedException.class).isThrownBy(() -> {
taskService.resume(taskId, "Darth Vader");
}).withMessageContaining("was unable to execute operation 'Resume' on task id");
task1 = taskService.getTaskById(taskId);
assertEquals(Status.Completed, task1.getTaskData().getStatus());
assertEquals("Darth Vader", task1.getTaskData().getActualOwner().getId());
}
use of org.kie.api.task.model.Task in project jbpm by kiegroup.
the class LifeCycleBaseTest method testReleaseWithIncorrectUser.
@Test
public void testReleaseWithIncorrectUser() {
// 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.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.release(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 testFail.
@Test
public void testFail() {
// 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());
// Check is Failed
taskService.fail(taskId, "Darth Vader", null);
Task task2 = taskService.getTaskById(taskId);
assertEquals(Status.Failed, task2.getTaskData().getStatus());
assertEquals("Darth Vader", task2.getTaskData().getActualOwner().getId());
}
Aggregations