CaseRolesPresenter extends AbstractCaseInstancePresenter<CaseRolesPresenter.CaseRolesView> { public void setCaseRoleAssignments(CaseRoleItemView caseRole, final int assignmentsListMaxWidth) { final CaseRoleAssignmentSummary caseRoleAssignmentSummary = caseRole.getValue(); if (!caseRoleAssignmentSummary.hasAssignment()) { caseRole.displayUnassigned(); return; } if (CASE_OWNER_ROLE.equals(caseRoleAssignmentSummary.getName())) { caseRole.displayOwnerAssignment(); } else { if (caseRoleAssignmentSummary.getUsers().size() == 0) { caseRole.hideUserAssignments(); } else { List<CaseAssignmentItem> itemsList = new ArrayList<>(); caseRoleAssignmentSummary.getUsers().forEach(user -> itemsList.add(new CaseAssignmentItem() { @Override public String label() { return user; } @Override public void execute() { caseRole.showRemoveUserAssignmentPopup(user); } })); caseRole.displayAssignmentsList(CaseRoleItemView.USERS_LINE_ID, assignmentsListMaxWidth, itemsList); } if (caseRoleAssignmentSummary.getGroups().size() == 0) { caseRole.hideGroupAssignments(); } else { List<CaseRolesPresenter.CaseAssignmentItem> itemsList = new ArrayList<>(); caseRoleAssignmentSummary.getGroups().forEach(group -> itemsList.add(new CaseAssignmentItem() { @Override public String label() { return group; } @Override public void execute() { caseRole.showRemoveGroupAssignmentPopup(group); } })); caseRole.displayAssignmentsList(CaseRoleItemView.GROUP_LINE_ID, assignmentsListMaxWidth, itemsList); } } }  @WorkbenchPartTitle String getTittle(); void filterCaseRoles(); void setCaseRoleActions(CaseRoleItemView caseRole); void setCaseRoleAssignments(CaseRoleItemView caseRole,
                                       final int assignmentsListMaxWidth); void storeRoleAssignments(final CaseRoleAssignmentSummary currentRoleAssignments,
                                     List<String> users,
                                     List<String> groups); static final String SCREEN_ID; static final String CASE_OWNER_ROLE; }
@Test public void testSetCaseRoleAssignments_ownerRole() { final int assignmentsListMaxWidth = 70; when(caseRole.getValue()).thenReturn(CaseRoleAssignmentSummary.builder() .name(CaseRolesPresenter.CASE_OWNER_ROLE) .users(singletonList(USER)) .build()); presenter.setCaseRoleAssignments(caseRole, assignmentsListMaxWidth); verify(caseRole).displayOwnerAssignment(); }
@Test public void testSetCaseRoleAssignments_roleWithoutAssignments() { final int assignmentsListMaxWidth = 70; when(caseRole.getValue()).thenReturn(CaseRoleAssignmentSummary.builder() .name(CASE_ROLE) .build()); presenter.setCaseRoleAssignments(caseRole, assignmentsListMaxWidth); verify(caseRole).displayUnassigned(); }
@Test public void testSetCaseRoleAssignments_roleWithUserAssignmentsOnly() { final int assignmentsListMaxWidth = 70; final CaseRoleAssignmentSummary caseRoleAssignmentSummary = CaseRoleAssignmentSummary.builder() .name(CASE_ROLE) .users(singletonList(USER)) .build(); when(caseRole.getValue()).thenReturn(caseRoleAssignmentSummary); presenter.setCaseRoleAssignments(caseRole, assignmentsListMaxWidth); verify(caseRole, never()).hideUserAssignments(); verify(caseRole).hideGroupAssignments(); final ArgumentCaptor<List> itemsList = ArgumentCaptor.forClass(List.class); verify(caseRole).displayAssignmentsList(eq(CaseRoleItemView.USERS_LINE_ID), eq(assignmentsListMaxWidth), itemsList.capture()); assertEquals(caseRoleAssignmentSummary.getUsers().size(), itemsList.getValue().size()); CaseRolesPresenter.CaseAssignmentItem assignmentItem = (CaseRolesPresenter.CaseAssignmentItem)itemsList.getValue().get(0); final String assignedUser = caseRoleAssignmentSummary.getUsers().get(0); assertEquals(assignedUser, assignmentItem.label()); assignmentItem.execute(); verify(caseRole).showRemoveUserAssignmentPopup(assignedUser); }
@Test public void testSetCaseRoleAssignments_roleWithGroupAssignmentsOnly() { final int assignmentsListMaxWidth = 70; final CaseRoleAssignmentSummary caseRoleAssignmentSummary = CaseRoleAssignmentSummary.builder() .name(CASE_ROLE) .groups(singletonList(GROUP)) .build(); when(caseRole.getValue()).thenReturn(caseRoleAssignmentSummary); presenter.setCaseRoleAssignments(caseRole, assignmentsListMaxWidth); verify(caseRole).hideUserAssignments(); verify(caseRole, never()).hideGroupAssignments(); final ArgumentCaptor<List> itemsList = ArgumentCaptor.forClass(List.class); verify(caseRole).displayAssignmentsList(eq(CaseRoleItemView.GROUP_LINE_ID), eq(assignmentsListMaxWidth), itemsList.capture()); assertEquals(caseRoleAssignmentSummary.getGroups().size(), itemsList.getValue().size()); CaseRolesPresenter.CaseAssignmentItem assignmentItem = (CaseRolesPresenter.CaseAssignmentItem)itemsList.getValue().get(0); final String assignedGroup = caseRoleAssignmentSummary.getGroups().get(0); assertEquals(assignedGroup, assignmentItem.label()); assignmentItem.execute(); verify(caseRole).showRemoveGroupAssignmentPopup(assignedGroup); }
@Test public void testSetCaseRoleAssignments_roleWithUserAndGroupAssignments() { final int assignmentsListMaxWidth = 70; final CaseRoleAssignmentSummary caseRoleAssignmentSummary = CaseRoleAssignmentSummary.builder() .name(CASE_ROLE) .users(singletonList(USER)) .groups(singletonList(GROUP)) .build(); when(caseRole.getValue()).thenReturn(caseRoleAssignmentSummary); presenter.setCaseRoleAssignments(caseRole, assignmentsListMaxWidth); verify(caseRole, never()).hideUserAssignments(); verify(caseRole, never()).hideGroupAssignments(); verify(caseRole, times(2)).displayAssignmentsList(anyString(), eq(assignmentsListMaxWidth), anyListOf(CaseRolesPresenter.CaseAssignmentItem.class)); }