Search in sources :

Example 16 with TaskAssignment

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));
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) User(org.kie.kogito.taskassigning.core.model.User) TestUtil.mockUser(org.kie.kogito.taskassigning.core.model.TestUtil.mockUser) TestUtil.mockTaskAssignment(org.kie.kogito.taskassigning.core.model.TestUtil.mockTaskAssignment) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) Test(org.junit.jupiter.api.Test)

Example 17 with TaskAssignment

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)));
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) TestUtil.mockUser(org.kie.kogito.taskassigning.core.model.TestUtil.mockUser) TestUtil.mockTaskAssignment(org.kie.kogito.taskassigning.core.model.TestUtil.mockTaskAssignment) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) Test(org.junit.jupiter.api.Test)

Example 18 with TaskAssignment

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);
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) TestUtil.mockUser(org.kie.kogito.taskassigning.core.model.TestUtil.mockUser) TestUtil.mockTaskAssignment(org.kie.kogito.taskassigning.core.model.TestUtil.mockTaskAssignment) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) Test(org.junit.jupiter.api.Test)

Example 19 with TaskAssignment

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();
    }
}
Also used : ChainElement(org.kie.kogito.taskassigning.core.model.ChainElement) User(org.kie.kogito.taskassigning.core.model.User) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 20 with TaskAssignment

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);
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) ArrayList(java.util.ArrayList) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Aggregations

TaskAssignment (org.kie.kogito.taskassigning.core.model.TaskAssignment)72 User (org.kie.kogito.taskassigning.core.model.User)39 Test (org.junit.jupiter.api.Test)27 TaskAssigningSolution (org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)23 ChainElement (org.kie.kogito.taskassigning.core.model.ChainElement)14 ArrayList (java.util.ArrayList)12 TestUtil.mockTaskAssignment (org.kie.kogito.taskassigning.core.model.TestUtil.mockTaskAssignment)12 TestUtil.mockUser (org.kie.kogito.taskassigning.core.model.TestUtil.mockUser)11 TaskUtil.fromTaskData (org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData)10 Task (org.kie.kogito.taskassigning.core.model.Task)8 AddTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)8 AssignTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)8 TestUtil.mockTaskData (org.kie.kogito.taskassigning.service.TestUtil.mockTaskData)8 RemoveTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)6 List (java.util.List)5 AddUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)5 ProblemFactChange (org.optaplanner.core.api.solver.ProblemFactChange)5 DisableUserProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)4 ProblemFactChangeUtil.unlinkTaskAssignment (org.kie.kogito.taskassigning.core.model.solver.realtime.ProblemFactChangeUtil.unlinkTaskAssignment)4 ReleaseTaskProblemFactChange (org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)4