use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class AssignTaskProblemFactChangeTest method doChangeForExistingUserAndTaskAssignmentThatBelongsToAnotherUser.
@Test
void doChangeForExistingUserAndTaskAssignmentThatBelongsToAnotherUser() {
// Initial assignments:
// User1 <- TASK_0 <- TASK_1 <- TASK_2 <- TASK_3 <- TASK_4
// User2 <- USER2_TASK_0 <- USER2_TASK_1 <- USER2_TASK_2
List<TaskAssignment> user1Tasks = buildUserTasks();
User user1 = buildUser(user1Tasks);
List<TaskAssignment> user2Tasks = Arrays.asList(mockTaskAssignment(USER2_TASK_0, false), mockTaskAssignment(USER2_TASK_1, false), mockTaskAssignment(USER2_TASK_2, false));
User user2 = mockUser("USER_2", user2Tasks);
TaskAssignment taskAssignment = mockTaskAssignment(USER2_TASK_1, false);
TaskAssignment workingTaskAssignment = user2Tasks.get(1);
ChainElement originalPreviousElement = workingTaskAssignment.getPreviousElement();
TaskAssignment expectedPreviousElement = user1Tasks.get(1);
when(scoreDirector.lookUpWorkingObjectOrReturnNull(user1)).thenReturn(user1);
when(scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment)).thenReturn(workingTaskAssignment);
change = new AssignTaskProblemFactChange(taskAssignment, user1);
change.doChange(scoreDirector);
assertPinning(workingTaskAssignment);
assertThat(workingTaskAssignment.getPreviousElement()).isSameAs(expectedPreviousElement);
assertThat(user2Tasks.get(2).getPreviousElement()).isSameAs(originalPreviousElement);
verify(scoreDirector, never()).beforeEntityAdded(any());
verify(scoreDirector, never()).afterEntityAdded(any());
verify(scoreDirector).triggerVariableListeners();
// Expected assignments:
// User1 <- TASK_0 <- TASK_1 <- USER2_TASK_1 <- TASK_2 <- TASK_3 <- TASK_4
// User2 <- USER2_TASK_0 <- USER2_TASK_2
assertTaskPositions(user1, user1Tasks.get(0), user1Tasks.get(1), workingTaskAssignment, user1Tasks.get(2), user1Tasks.get(3), user1Tasks.get(4));
assertTaskPositions(user2, user2Tasks.get(0), user2Tasks.get(2));
}
use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class AssignTaskProblemFactChangeTest method doChangeForExistingTaskAssignmentThatBelongsToSameUserWithoutPositionChange.
@Test
void doChangeForExistingTaskAssignmentThatBelongsToSameUserWithoutPositionChange() {
// Initial assignments:
// User <- TASK_0 <- TASK_1 <- TASK_2 <- TASK_3 <- TASK_4
List<TaskAssignment> userTasks = buildUserTasks();
User user = buildUser(userTasks);
TaskAssignment taskAssignment = mockTaskAssignment(TASK_2, false);
TaskAssignment originalPreviousElement = userTasks.get(1);
TaskAssignment workingTaskAssignment = userTasks.get(2);
// Expected assignments:
// User <- TASK_0 <- TASK_1 <- TASK_2 <- TASK_3 <- TASK_4
doChangeForExistingTaskAssignmentThatBelongsToSameUser(user, taskAssignment, workingTaskAssignment, originalPreviousElement, Arrays.asList(userTasks.get(0), userTasks.get(1), workingTaskAssignment, userTasks.get(3), userTasks.get(4)));
}
use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class AssignTaskProblemFactChangeTest method getUser.
@Test
void getUser() {
User user = new User();
change = new AssignTaskProblemFactChange(new TaskAssignment(), user);
assertThat(change.getUser()).isSameAs(user);
}
use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class AssignTaskExecutableProblemFactChangeTest method assertAssignTaskProblemFactChangeWasProduced.
/**
* Given an AssignTaskProblemFactChange and a solution that was produced as the result of applying the change,
* asserts that the assignment defined by the change is not violated (exists in) by the solution.
* The assignment defined in the change must also be pinned in the produced solution as well as any other
* previous assignment for the given user.
*
* @param change The change that was executed for producing the solution.
* @param solution The produced solution.
*/
private void assertAssignTaskProblemFactChangeWasProduced(AssignTaskProblemFactChange change, TaskAssigningSolution solution) throws Exception {
User internalUser = solution.getUserList().stream().filter(user -> Objects.equals(user.getId(), change.getUser().getId())).findFirst().orElseThrow(() -> new Exception("User: " + change.getUser() + " was not found in solution."));
TaskAssignment internalTaskAssignment = solution.getTaskAssignmentList().stream().filter(taskAssignment -> Objects.equals(taskAssignment.getId(), change.getTaskAssignment().getId())).findFirst().orElseThrow(() -> new Exception("TaskAssignment: " + change + " was not found in solution."));
assertThat(internalTaskAssignment.getUser()).isEqualTo(internalUser);
assertThat(internalTaskAssignment.isPinned()).isTrue();
// all the previous tasks must be pinned by construction and be assigned to the user
ChainElement previousElement = internalTaskAssignment.getPreviousElement();
while (previousElement != null) {
if (previousElement.isTaskAssignment()) {
TaskAssignment previousTaskAssignment = (TaskAssignment) previousElement;
assertThat(previousTaskAssignment.isPinned()).isTrue();
assertThat(previousTaskAssignment.getUser()).isEqualTo(internalUser);
previousElement = previousTaskAssignment.getPreviousElement();
} else {
assertThat(previousElement).isEqualTo(internalUser);
previousElement = null;
}
}
// all the next tasks must to the user.
TaskAssignment nextTaskAssignment = internalTaskAssignment.getNextElement();
while (nextTaskAssignment != null) {
assertThat(nextTaskAssignment.getUser()).isEqualTo(internalUser);
nextTaskAssignment = nextTaskAssignment.getNextElement();
}
}
use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.
the class AssignTaskExecutableProblemFactChangeTest method assignTaskProblemFactChangeFixedChangeSet.
private void assignTaskProblemFactChangeFixedChangeSet(String solutionResource) throws Exception {
TaskAssigningSolution solution = readTaskAssigningSolution(solutionResource);
solution.getUserList().add(PLANNING_USER);
// prepare the list of changes to program
List<ProgrammedAssignTaskProblemFactChange> programmedChanges = new ArrayList<>();
// assign Task_0 to User_0
TaskAssignment taskAssignment = solution.getTaskAssignmentList().get(0);
User user = solution.getUserList().get(0);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign Task_10 to User_0
taskAssignment = solution.getTaskAssignmentList().get(10);
user = solution.getUserList().get(0);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign Task_15 to User_2
taskAssignment = solution.getTaskAssignmentList().get(15);
user = solution.getUserList().get(2);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign Task_13 to User_3
taskAssignment = solution.getTaskAssignmentList().get(13);
user = solution.getUserList().get(3);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign Task_13 to User_4
taskAssignment = solution.getTaskAssignmentList().get(13);
user = solution.getUserList().get(4);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign Task_13 to User_5
taskAssignment = solution.getTaskAssignmentList().get(13);
user = solution.getUserList().get(5);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign Task_15 to User_5
taskAssignment = solution.getTaskAssignmentList().get(15);
user = solution.getUserList().get(5);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign Task_16 to User_5
taskAssignment = solution.getTaskAssignmentList().get(16);
user = solution.getUserList().get(5);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign Task_17 to User_5
taskAssignment = solution.getTaskAssignmentList().get(17);
user = solution.getUserList().get(5);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// repeat assign Task_17 to User_5
taskAssignment = solution.getTaskAssignmentList().get(17);
user = solution.getUserList().get(5);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// repeat assign Task_15 to User_5
taskAssignment = solution.getTaskAssignmentList().get(15);
user = solution.getUserList().get(5);
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
String nextTaskId = NEW_TASK + 1;
// assign a brand new task "NewTask_x and assign to User_0
user = solution.getUserList().get(0);
taskAssignment = new TaskAssignment(Task.newBuilder().id(nextTaskId).name(nextTaskId).build());
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign a brand new task "NewTask_x and assign to User_2
nextTaskId = NEW_TASK + 2;
user = solution.getUserList().get(2);
taskAssignment = new TaskAssignment(Task.newBuilder().id(nextTaskId).name(nextTaskId).build());
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
// assign a brand new task "NewTask_x and assign to User_5
nextTaskId = NEW_TASK + 3;
user = solution.getUserList().get(5);
taskAssignment = new TaskAssignment(Task.newBuilder().id(nextTaskId).name(nextTaskId).build());
programmedChanges.add(new ProgrammedAssignTaskProblemFactChange(taskAssignment, user));
assignTaskProblemFactChange(solution, solutionResource, FIXED_TEST, programmedChanges);
}
Aggregations