Search in sources :

Example 21 with TaskAssignment

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

the class RemoveTaskExecutableProblemFactChangeTest method removeTaskProblemFactChange.

private void removeTaskProblemFactChange(TaskAssigningSolution solution, List<String> taskIds) {
    List<ProgrammedProblemFactChange<RemoveTaskProblemFactChange>> programmedChanges = taskIds.stream().map(id -> findTaskAssignmentOrCreate(solution, id)).map(taskAssignment -> new ProgrammedProblemFactChange<>(new RemoveTaskProblemFactChange(taskAssignment))).collect(Collectors.toList());
    // each partial solution must have the change that was applied on it.
    executeSequentialChanges(solution, programmedChanges);
    programmedChanges.forEach(change -> assertRemoveTaskProblemFactChangeWasProduced(change.getChange(), change.getSolutionAfterChange()));
    // finally the last solution must have the result of all the changes.
    TaskAssigningSolution lastSolution = programmedChanges.get(programmedChanges.size() - 1).getSolutionAfterChange();
    programmedChanges.forEach(change -> assertRemoveTaskProblemFactChangeWasProduced(change.getChange(), lastSolution));
}
Also used : Arrays(java.util.Arrays) SET_OF_100TASKS_5USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_100TASKS_5USERS_SOLUTION) SET_OF_500TASKS_20USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_500TASKS_20USERS_SOLUTION) 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) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Task(org.kie.kogito.taskassigning.core.model.Task) List(java.util.List) SET_OF_50TASKS_5USERS_SOLUTION(org.kie.kogito.taskassigning.core.TestDataSet.SET_OF_50TASKS_5USERS_SOLUTION) TestConstants(org.kie.kogito.taskassigning.core.TestConstants) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) Tag(org.junit.jupiter.api.Tag) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution)

Example 22 with TaskAssignment

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

the class SolutionBuilderTest method assertThatTaskProcessorsWereApplied.

public static void assertThatTaskProcessorsWereApplied(TaskAssigningSolution solution, AttributesProcessorRegistry processorRegistry, String... taskIds) {
    for (String taskId : taskIds) {
        TaskAssignment taskAssignment = solution.getTaskAssignmentList().stream().filter(ta -> taskId.equals(ta.getId())).findFirst().orElseThrow(() -> new RuntimeException("Expected task was not found in solution, taskId:" + taskId));
        verify(processorRegistry).applyAttributesProcessor(eq(taskAssignment.getTask()), any());
    }
}
Also used : TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 23 with TaskAssignment

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

the class SolutionBuilderTest method assertThatTaskIsAssignedToUser.

private void assertThatTaskIsAssignedToUser(TaskAssigningSolution solution, String taskId, String userId) {
    TaskAssignment taskAssignment = solution.getTaskAssignmentList().stream().filter(ta -> taskId.equals(ta.getId())).findFirst().orElse(null);
    assertThat(taskAssignment).withFailMessage("Task %s is not present in solution.", taskId).isNotNull();
    User user = solution.getUserList().stream().filter(u -> userId.equals(u.getId())).findFirst().orElse(null);
    assertThat(user).withFailMessage("User %s is not present in solution.", userId).isNotNull();
    assertThat(taskAssignment.getUser()).withFailMessage("Task %s must be assigned to user %s but is assigned to nobody.", taskId, userId).isNotNull();
    assertThat(taskAssignment.getUser().getId()).withFailMessage("Task %s must be assigned to user %s.", taskId, userId).isEqualTo(userId);
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) TestUtil.mockExternalUser(org.kie.kogito.taskassigning.service.TestUtil.mockExternalUser) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment)

Example 24 with TaskAssignment

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

the class SolutionChangesBuilderTest method addReservedTaskChangeForSameUserButNotPinned.

@Test
void addReservedTaskChangeForSameUserButNotPinned() {
    TaskAssignment user1Assignment = new TaskAssignment(mockTask(TASK_1_ID));
    User user1 = TestUtil.mockUser(USER_1, Collections.singletonList(user1Assignment));
    user1Assignment.setPinned(false);
    TaskAssigningSolution solution = mockSolution(Collections.singletonList(user1), Collections.singletonList(user1Assignment));
    TaskData taskData = mockTaskData(TASK_1_ID, RESERVED.value(), USER_1, TASK_1_LAST_UPDATE);
    addReservedTaskChangeForAnotherUser(solution, taskData, user1);
    assertThatTaskProcessorsWhereNotApplied();
    assertThatUserProcessorsWereNotApplied();
}
Also used : User(org.kie.kogito.taskassigning.core.model.User) TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) TaskAssignment(org.kie.kogito.taskassigning.core.model.TaskAssignment) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData) TestUtil.mockTaskData(org.kie.kogito.taskassigning.service.TestUtil.mockTaskData) Test(org.junit.jupiter.api.Test)

Example 25 with TaskAssignment

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

the class SolutionChangesBuilderTest method addNewReadyTaskChange.

@Test
void addNewReadyTaskChange() {
    TaskData taskData = mockTaskData(TASK_1_ID, READY.value(), TASK_1_LAST_UPDATE);
    List<TaskData> taskDataList = mockTaskDataList(taskData);
    TaskAssigningSolution solution = mockSolution(Collections.emptyList(), Collections.emptyList());
    List<ProblemFactChange<TaskAssigningSolution>> result = SolutionChangesBuilder.create().withContext(context).withUserServiceConnector(userServiceConnector).withProcessors(processorRegistry).fromTasksData(taskDataList).forSolution(solution).build();
    AddTaskProblemFactChange expected = new AddTaskProblemFactChange(new TaskAssignment(fromTaskData(taskData)));
    assertChangeIsTheChangeSetId(result, 0);
    assertChange(result, 1, expected);
    assertTaskPublishStatus(taskData.getId(), false);
    assertThatTaskProcessorsWereApplied(TASK_1_ID);
    assertThatUserProcessorsWereNotApplied();
}
Also used : TaskAssigningSolution(org.kie.kogito.taskassigning.core.model.TaskAssigningSolution) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) RemoveUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange) ProblemFactChange(org.optaplanner.core.api.solver.ProblemFactChange) AssignTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange) DisableUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange) UserPropertyChangeProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange) AddUserProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddUserProblemFactChange) RemoveTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange) AddTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange) ReleaseTaskProblemFactChange(org.kie.kogito.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange) TaskUtil.fromTaskData(org.kie.kogito.taskassigning.service.util.TaskUtil.fromTaskData) TestUtil.mockTaskData(org.kie.kogito.taskassigning.service.TestUtil.mockTaskData) 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