TaskAssignmentsPresenter extends AbstractTaskPresenter { public void onTaskSelectionEvent(@Observes final TaskSelectionEvent event) { if (!event.isForLog()) { setSelectedTask(event); view.setHelpText(""); view.clearUserOrGroupInput(); refreshTaskPotentialOwners(); } } @Inject  TaskAssignmentsPresenter(TaskAssignmentsView view,
                                    Caller<TaskService> taskService,
                                    Event<TaskRefreshedEvent> taskRefreshed); @PostConstruct void init(); IsWidget getView(); void delegateTask(String entity); void refreshTaskPotentialOwners(); void onTaskSelectionEvent(@Observes final TaskSelectionEvent event); void onTaskRefreshedEvent(@Observes final TaskRefreshedEvent event);  }
@Test public void delegationDisabled_whenCompletedTaskSelected() { final long COMPLETED_TASK_ID = 1; final TaskAssignmentSummary task = new TaskAssignmentSummary(); task.setTaskId(COMPLETED_TASK_ID); task.setStatus(TASK_STATUS_COMPLETED.getIdentifier()); task.setPotOwnersString(Arrays.asList(CURRENT_USER)); when(taskService.getTaskAssignmentDetails(anyString(), anyString(), eq(COMPLETED_TASK_ID))).thenReturn(task); task.setDelegationAllowed(false); boolean isForLog = false; TaskSelectionEvent event = new TaskSelectionEvent("serverTemplateId", "containerId", COMPLETED_TASK_ID, "task", true, isForLog, "description", new Date(), "Completed", "actualOwner", 2, 1L, "processId"); presenter.onTaskSelectionEvent(event); verify(viewMock, times(2)).enableDelegateButton(false); verify(viewMock, times(2)).enableUserOrGroupInput(false); verify(viewMock, never()).enableDelegateButton(true); verify(viewMock, never()).enableUserOrGroupInput(true); }
@Test public void delegationDisabled_whenTaskNotOwnedByCurrentUserSelected() { final long TASK_OWNED_BY_SOMEONE_ELSE_ID = 2; final TaskAssignmentSummary task = new TaskAssignmentSummary(); task.setTaskId(TASK_OWNED_BY_SOMEONE_ELSE_ID); task.setStatus(TASK_STATUS_READY.getIdentifier()); task.setActualOwner(OTHER_USER); task.setPotOwnersString(Arrays.asList(OTHER_USER)); task.setDelegationAllowed(false); when(taskService.getTaskAssignmentDetails(anyString(), anyString(), eq(TASK_OWNED_BY_SOMEONE_ELSE_ID))).thenReturn(task); boolean isForLog = false; TaskSelectionEvent event = new TaskSelectionEvent("serverTemplateId", "containerId", TASK_OWNED_BY_SOMEONE_ELSE_ID, "task", true, isForLog, "description", new Date(), "Completed", "actualOwner", 2, 1L, "processId"); presenter.onTaskSelectionEvent(event); verify(viewMock, times(2)).enableDelegateButton(false); verify(viewMock, times(2)).enableUserOrGroupInput(false); verify(viewMock, never()).enableDelegateButton(true); verify(viewMock, never()).enableUserOrGroupInput(true); }
@Test public void delegationEnabled_whenTaskOwnedByCurrentUserSelected() { final long TASK_OWNED_BY_CURRENT_USER = 3; final TaskAssignmentSummary task = new TaskAssignmentSummary(); task.setTaskId(TASK_OWNED_BY_CURRENT_USER); task.setStatus(TASK_STATUS_READY.getIdentifier()); task.setActualOwner(CURRENT_USER); task.setPotOwnersString(Arrays.asList(CURRENT_USER)); task.setDelegationAllowed(true); when(taskService.getTaskAssignmentDetails(anyString(), anyString(), eq(TASK_OWNED_BY_CURRENT_USER))).thenReturn(task); boolean isForLog = false; TaskSelectionEvent event = new TaskSelectionEvent("serverTemplateId", "containerId", TASK_OWNED_BY_CURRENT_USER, "task", true, isForLog, "description", new Date(), "Completed", "actualOwner", 2, 1L, "processId"); presenter.onTaskSelectionEvent(event); final InOrder inOrder = inOrder(viewMock); inOrder.verify(viewMock).enableDelegateButton(false); inOrder.verify(viewMock).enableUserOrGroupInput(false); inOrder.verify(viewMock).enableDelegateButton(true); inOrder.verify(viewMock).enableUserOrGroupInput(true); }
@Test public void taskSelectionEventIsForLogTask() { String serverTemplateId = "serverTemplateId"; String containerId = "containerId"; Long taskId = 1L; boolean isForLog = true; TaskSelectionEvent event = new TaskSelectionEvent(serverTemplateId, containerId, taskId, "task", true, isForLog); TaskAssignmentSummary ts = new TaskAssignmentSummary(); ts.setPotOwnersString(Arrays.asList("owner1", "owner2")); when(taskService.getTaskAssignmentDetails(eq(serverTemplateId), eq(containerId), eq(taskId))).thenReturn(ts); presenter.onTaskSelectionEvent(event); verifyNoMoreInteractions(taskService); }
@Test public void taskSelectionEventNotIsForLogTask() { String serverTemplateId = "serverTemplateId"; String containerId = "containerId"; Long taskId = 1L; boolean isForLog = false; TaskSelectionEvent event = new TaskSelectionEvent(serverTemplateId, containerId, taskId, "task", true, isForLog); presenter.onTaskSelectionEvent(event); verify(taskService).getTaskAssignmentDetails(serverTemplateId, containerId, taskId); }