Search in sources :

Example 1 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class SolverHandlerTest method onUpdateSolutionSolverNotStarted.

@Test
public void onUpdateSolutionSolverNotStarted() {
    prepareStart();
    List<ProblemFactChange<TaskAssigningSolution>> changes = new ArrayList<>();
    changes.add(new TaskPropertyChangeProblemFactChange(new Task()));
    SolutionSynchronizer.Result result = SolutionSynchronizer.Result.forChanges(changes);
    doReturn(false).when(solverExecutor).isStarted();
    synchronizerConsumerCaptor.getValue().accept(result);
    verify(solverExecutor, never()).addProblemFactChanges(changes);
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) ArrayList(java.util.ArrayList) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) TaskPropertyChangeProblemFactChange(org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange) ProblemFactChange(org.optaplanner.core.impl.solver.ProblemFactChange) Test(org.junit.Test)

Example 2 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class SolutionSynchronizerTest method initSolverExecutor.

@Test(timeout = TEST_TIMEOUT)
@SuppressWarnings("unchecked")
public void initSolverExecutor() throws Exception {
    CompletableFuture future = startRunnableBase();
    LocalDateTime firstQueryTime = LocalDateTime.now();
    List<User> userList = mockUserList();
    List<TaskAssigningRuntimeDelegate.FindTasksResult> results = mockTasksQueryExecutions(firstQueryTime);
    LocalDateTime firstSuccessfulQueryTime = results.get(results.size() - 1).getQueryTime();
    queryExecutionsCountDown = new CountDownLatch(results.size());
    prepareQueryExecutionsWithOutEmptyStatus(results);
    when(emptySolution.getTaskList()).thenReturn(Collections.emptyList());
    when(generatedSolution.getTaskList()).thenReturn(Collections.singletonList(new Task()));
    when(solverExecutor.isStopped()).thenReturn(true);
    when(userSystemService.findAllUsers()).thenReturn(userList);
    runnableBase.initSolverExecutor();
    // wait for the query executions to happen
    queryExecutionsCountDown.await();
    verify(delegate, times(results.size())).findTasks(anyList(), eq(null), anyObject());
    verify(solverExecutor).start(solutionCaptor.capture());
    assertEquals(generatedSolution, solutionCaptor.getValue());
    LocalDateTime nextQueryTime = context.shiftQueryTime(firstSuccessfulQueryTime.withNano(0));
    LocalDateTime previousQueryTime = context.shiftQueryTime(nextQueryTime);
    assertEquals(previousQueryTime, context.getPreviousQueryTime());
    assertEquals(nextQueryTime, context.getNextQueryTime());
    runnableBase.destroy();
    future.get();
    assertTrue(runnableBase.isDestroyed());
}
Also used : LocalDateTime(java.time.LocalDateTime) CompletableFuture(java.util.concurrent.CompletableFuture) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.user.system.api.User) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class TaskUtilTest method fromTaskData.

private void fromTaskData(Map<String, Object> inputData, Set<Object> expectedSkills, Set<Object> expectedAffinities) {
    Set<OrganizationalEntity> potentialOwners = new HashSet<>();
    potentialOwners.add(OE_1);
    potentialOwners.add(OE_2);
    TaskData taskData = TaskData.builder().taskId(TASK_ID).processInstanceId(PROCESS_INSTANCE_ID).processId(PROCESS_ID).containerId(CONTAINER_ID).name(NAME).priority(PRIORITY).status(STATUS).inputData(inputData).potentialOwners(potentialOwners).build();
    Task task = TaskUtil.fromTaskData(taskData);
    assertEquals(TASK_ID, task.getId(), 0);
    assertEquals(PROCESS_INSTANCE_ID, task.getProcessInstanceId(), 0);
    assertEquals(PROCESS_ID, task.getProcessId());
    assertEquals(CONTAINER_ID, task.getContainerId());
    assertEquals(NAME, task.getName());
    assertEquals(PRIORITY, task.getPriority(), 0);
    assertEquals(STATUS, task.getStatus());
    assertEquals(inputData, task.getInputData());
    assertEquals(potentialOwners.size(), task.getPotentialOwners().size(), 2);
    User user = task.getPotentialOwners().stream().filter(u -> OE_1.getName().equals(u.getEntityId()) && u.isUser()).map(u -> (User) u).findFirst().orElse(null);
    assertNotNull(user);
    Group group = task.getPotentialOwners().stream().filter(g -> OE_2.getName().equals(g.getEntityId()) && !g.isUser()).map(g -> (Group) g).findFirst().orElse(null);
    assertNotNull(group);
    assertEquals(expectedSkills, task.getLabelValues(SKILLS.name()));
    assertEquals(expectedAffinities, task.getLabelValues(AFFINITIES.name()));
}
Also used : Arrays(java.util.Arrays) Group(org.kie.server.services.taskassigning.core.model.Group) Assert.assertNotNull(org.junit.Assert.assertNotNull) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) TaskData(org.kie.server.api.model.taskassigning.TaskData) HashSet(java.util.HashSet) User(org.kie.server.services.taskassigning.core.model.User) Map(java.util.Map) AFFINITIES(org.kie.server.services.taskassigning.core.model.DefaultLabels.AFFINITIES) Collections(java.util.Collections) UserType(org.kie.server.api.model.taskassigning.UserType) OrganizationalEntity(org.kie.server.api.model.taskassigning.OrganizationalEntity) Assert.assertEquals(org.junit.Assert.assertEquals) SKILLS(org.kie.server.services.taskassigning.core.model.DefaultLabels.SKILLS) Task(org.kie.server.services.taskassigning.core.model.Task) Group(org.kie.server.services.taskassigning.core.model.Group) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) OrganizationalEntity(org.kie.server.api.model.taskassigning.OrganizationalEntity) HashSet(java.util.HashSet) TaskData(org.kie.server.api.model.taskassigning.TaskData)

Example 4 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class TestUtil method initializeUser.

public static User initializeUser(User user, List<Task> tasks) {
    TaskOrUser previous = user;
    for (Task task : tasks) {
        previous.setNextTask(task);
        task.setPreviousTaskOrUser(previous);
        task.setUser(user);
        previous = task;
    }
    return user;
}
Also used : Task(org.kie.server.services.taskassigning.core.model.Task) TaskOrUser(org.kie.server.services.taskassigning.core.model.TaskOrUser)

Example 5 with Task

use of org.kie.server.services.taskassigning.core.model.Task in project droolsjbpm-integration by kiegroup.

the class RemoveUserProblemFactChangeTest method doChange.

@Test
public void doChange() {
    List<Task> workingUserTasks = Arrays.asList(mockTask(TASK_ID1, true), mockTask(TASK_ID2, true), mockTask(TASK_ID3, false), mockTask(TASK_ID4, false));
    User workingUser = mockUser(USER_ID_1, workingUserTasks);
    workingUser.setEnabled(true);
    workingSolution.getUserList().add(workingUser);
    int originalUsersSize = workingSolution.getUserList().size();
    when(scoreDirector.lookUpWorkingObjectOrReturnNull(user)).thenReturn(workingUser);
    change.doChange(scoreDirector);
    verify(scoreDirector).beforeProblemPropertyChanged(workingUser);
    verify(scoreDirector).afterProblemPropertyChanged(workingUser);
    verify(scoreDirector).triggerVariableListeners();
    assertThat(workingUser.isEnabled()).isFalse();
    workingUserTasks.forEach(task -> assertTaskWasReleased(task, scoreDirector));
    verify(scoreDirector).beforeProblemFactRemoved(workingUser);
    verify(scoreDirector).afterProblemFactRemoved(workingUser);
    assertThat(workingSolution.getUserList().size()).isEqualTo(originalUsersSize - 1);
    assertThat(workingSolution.getUserList()).contains(user2, user3);
    assertThat(workingSolution.getUserList()).doesNotContain(workingUser);
}
Also used : TestUtil.mockTask(org.kie.server.services.taskassigning.core.model.TestUtil.mockTask) Task(org.kie.server.services.taskassigning.core.model.Task) User(org.kie.server.services.taskassigning.core.model.User) TestUtil.mockUser(org.kie.server.services.taskassigning.core.model.TestUtil.mockUser) Test(org.junit.Test)

Aggregations

Task (org.kie.server.services.taskassigning.core.model.Task)63 User (org.kie.server.services.taskassigning.core.model.User)32 Test (org.junit.Test)26 TaskAssigningSolution (org.kie.server.services.taskassigning.core.model.TaskAssigningSolution)23 TaskOrUser (org.kie.server.services.taskassigning.core.model.TaskOrUser)21 PlanningTask (org.kie.server.api.model.taskassigning.PlanningTask)15 ArrayList (java.util.ArrayList)14 TaskPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.TaskPropertyChangeProblemFactChange)12 ProblemFactChange (org.optaplanner.core.impl.solver.ProblemFactChange)12 AddTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddTaskProblemFactChange)11 AssignTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AssignTaskProblemFactChange)11 TaskData (org.kie.server.api.model.taskassigning.TaskData)10 AddUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.AddUserProblemFactChange)10 DisableUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.DisableUserProblemFactChange)10 ReleaseTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.ReleaseTaskProblemFactChange)10 RemoveTaskProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveTaskProblemFactChange)10 RemoveUserProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.RemoveUserProblemFactChange)10 UserPropertyChangeProblemFactChange (org.kie.server.services.taskassigning.core.model.solver.realtime.UserPropertyChangeProblemFactChange)10 TaskUtil.fromTaskData (org.kie.server.services.taskassigning.planning.util.TaskUtil.fromTaskData)8 UserUtil.fromExternalUser (org.kie.server.services.taskassigning.planning.util.UserUtil.fromExternalUser)8