Search in sources :

Example 11 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class DefaultTaskAssigningConstraintProviderTest method prepareTaskAssignment.

private static TaskAssignment prepareTaskAssignment(User user, Task task, int endTimeInMinutes) {
    TaskAssignment taskAssignment = prepareTaskAssignment(user, task);
    taskAssignment.setEndTimeInMinutes(endTimeInMinutes);
    return taskAssignment;
}
Also used : TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 12 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class SolverTest method assertAssignment.

private void assertAssignment(User user, TaskAssignment taskAssignment, List<User> availableUsers) {
    assertThat(taskAssignment.getUser()).isNotNull();
    assertThat(taskAssignment.getUser().getId()).as("TaskAssignment: %s is not assigned to expected user: %s ", taskAssignment, user).isEqualTo(user.getId());
    Task task = taskAssignment.getTask();
    if (task.getPotentialUsers().isEmpty() && task.getPotentialGroups().isEmpty()) {
        assertThat(user.getId()).as("TaskAssignment: %s without potentialOwners can only be assigned to the PLANNING_USER", taskAssignment).isEqualTo(PLANNING_USER.getId());
    } else if (PLANNING_USER.getId().equals(user.getId())) {
        availableUsers.forEach(availableUser -> assertThat(isPotentialOwner(taskAssignment.getTask(), user)).as(String.format("PLANNING_USER user was assigned but another potential owner was found, user: %s taskAssignment: %s", user, taskAssignment)).isFalse());
    } else {
        assertThat(isPotentialOwner(taskAssignment.getTask(), user)).as(String.format("User: %s is not a potential owner for the taskAssignment: %s", user, taskAssignment)).isTrue();
    }
}
Also used : Solver(org.optaplanner.core.api.solver.Solver) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) SET_OF_24TASKS_8USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_24TASKS_8USERS_SOLUTION) TaskHelper.isPotentialOwner(org.kie.kogito.taskassigning.core.model.solver.TaskHelper.isPotentialOwner) AbstractTaskAssigningCoreTest(org.kie.kogito.taskassigning.core.AbstractTaskAssigningCoreTest) User(org.kie.kogito.taskassigning.core.model.User) Test(org.junit.jupiter.api.Test) Task(org.kie.kogito.taskassigning.core.model.Task) List(java.util.List) Assertions.fail(org.assertj.core.api.Assertions.fail) PLANNING_USER(org.kie.kogito.taskassigning.core.model.ModelConstants.PLANNING_USER) TaskHelper.extractTaskAssignments(org.kie.kogito.taskassigning.core.model.solver.TaskHelper.extractTaskAssignments) Timeout(org.junit.jupiter.api.Timeout) Task(org.kie.kogito.taskassigning.core.model.Task)

Example 13 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class TaskHelperTest method filterNonDummyAssignments.

@Test
void filterNonDummyAssignments() {
    List<TaskAssignment> taskAssignments = Arrays.asList(new TaskAssignment(Task.newBuilder().id(TASK_ID_1).build()), new TaskAssignment(Task.newBuilder().id(DUMMY_TASK_ASSIGNMENT.getId()).build()), new TaskAssignment(Task.newBuilder().id(TASK_ID_2).build()), new TaskAssignment(Task.newBuilder().id(DUMMY_TASK_ASSIGNMENT_PLANNER_1738.getId()).build()));
    List<TaskAssignment> result = TaskHelper.filterNonDummyAssignments(taskAssignments);
    assertThat(result).hasSize(2);
    assertThat(result.get(0)).isSameAs(taskAssignments.get(0));
    assertThat(result.get(1)).isSameAs(taskAssignments.get(2));
}
Also used : TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 14 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class AssignTaskProblemFactChangeTest method doChangeForNonExistingUserAndNotAddIt.

@Test
void doChangeForNonExistingUserAndNotAddIt() {
    User user = new User();
    when(scoreDirector.lookUpWorkingObjectOrReturnNull(user)).thenReturn(null);
    change = new AssignTaskProblemFactChange(new TaskAssignment(), user, false);
    assertThatThrownBy(() -> change.doChange(scoreDirector)).hasMessage("Expected user: %s was not found in current working solution", user);
    assertThat(solution.getUserList()).isEmpty();
}
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 15 with TaskAssignment

use of org.kie.kogito.taskassigning.core.model.TaskAssignment in project kogito-apps by kiegroup.

the class AssignTaskProblemFactChangeTest method doChangeForNewTaskAssignment.

@Test
void doChangeForNewTaskAssignment() {
    // Initial assignments:
    // User <- TASK_0 <- TASK_1 <- TASK_2 <- TASK_3 <- TASK_4
    List<TaskAssignment> userTasks = buildUserTasks();
    User user = buildUser(userTasks);
    TaskAssignment taskAssignment = mockTaskAssignment(NEW_TASK_ID, false);
    when(scoreDirector.lookUpWorkingObjectOrReturnNull(user)).thenReturn(user);
    when(scoreDirector.lookUpWorkingObjectOrReturnNull(taskAssignment)).thenReturn(null);
    change = new AssignTaskProblemFactChange(taskAssignment, user);
    change.doChange(scoreDirector);
    assertThat(solution.getTaskAssignmentList()).contains(taskAssignment);
    assertPinning(taskAssignment);
    verify(scoreDirector).beforeEntityAdded(taskAssignment);
    verify(scoreDirector).afterEntityAdded(taskAssignment);
    verify(scoreDirector).triggerVariableListeners();
    // Expected assignments:
    // User <- TASK_0 <- TASK_1 <- TASK_2 <- NEW_TASK_ID <- TASK_3 <- TASK_4
    assertTaskPositions(user, userTasks.get(0), userTasks.get(1), taskAssignment, userTasks.get(2), 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)

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