@SuppressWarnings("unchecked") @Test void testDelete() { String groupName = "group"; Package pack = mock(Package.class); when(pack.getId()).thenReturn(groupName); Group group = mock(Group.class); when(group.getName()).thenReturn(groupName); Role role1 = mock(Role.class); when(role1.getId()).thenReturn("role1"); Role role2 = mock(Role.class); when(role2.getId()).thenReturn("role2"); List<Role> roles = Arrays.asList(role1, role2); when(group.getRoles()).thenReturn(roles); RoleMembership member1 = mock(RoleMembership.class); RoleMembership member2 = mock(RoleMembership.class); List<RoleMembership> members = Arrays.asList(member1, member2); Query<Group> groupQuery = mock(Query.class, RETURNS_SELF); when(dataService.query(GROUP, Group.class)).thenReturn(groupQuery); when(groupQuery.eq(GroupMetadata.ROOT_PACKAGE, groupName).findOne()).thenReturn(group); Query<RoleMembership> membershipQuery = mock(Query.class, Mockito.RETURNS_SELF); when(dataService.query(RoleMembershipMetadata.ROLE_MEMBERSHIP, RoleMembership.class)) .thenReturn(membershipQuery); Query<RoleMembership> role1Query = mock(Query.class); when(role1Query.findAll()).thenReturn(members.stream()); doReturn(role1Query).when(membershipQuery).eq(RoleMembershipMetadata.ROLE, "role1"); Query<RoleMembership> role2Query = mock(Query.class); when(role2Query.findAll()).thenReturn(Stream.empty()); doReturn(role2Query).when(membershipQuery).eq(RoleMembershipMetadata.ROLE, "role2"); Query<Role> includesRoleQuery1 = mock(Query.class, RETURNS_SELF); when(dataService.query(ROLE, Role.class)).thenReturn(includesRoleQuery1); groupPackageService.deleteGroup(pack); verify(dataService, times(2)) .delete(eq(RoleMembershipMetadata.ROLE_MEMBERSHIP), memberCaptor.capture()); List<Stream<RoleMembership>> values = memberCaptor.getAllValues(); assertEquals(emptyList(), values.get(1).collect(toList())); assertEquals(asList(member1, member2), values.get(0).collect(toList())); verify(dataService).delete(eq(ROLE), roleCaptor.capture()); assertEquals(asList(role1, role2), roleCaptor.getValue().collect(toList())); verify(dataService).delete(GROUP, group); verify(mutableAclService).deleteAcl(new GroupIdentity(groupName), true); }
@Override public void deleteGroup(Package rootPackage) { Group group = getGroup(rootPackage); if (group != null) { deleteRoles(group); dataService.delete(GROUP, group); mutableAclService.deleteAcl(new GroupIdentity(group.getName()), true); } }
GroupPackageServiceImpl implements GroupPackageService { @Override public void deleteGroup(Package rootPackage) { Group group = getGroup(rootPackage); if (group != null) { deleteRoles(group); dataService.delete(GROUP, group); mutableAclService.deleteAcl(new GroupIdentity(group.getName()), true); } } }
GroupPackageServiceImpl implements GroupPackageService { @Override public void deleteGroup(Package rootPackage) { Group group = getGroup(rootPackage); if (group != null) { deleteRoles(group); dataService.delete(GROUP, group); mutableAclService.deleteAcl(new GroupIdentity(group.getName()), true); } } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); }
GroupPackageServiceImpl implements GroupPackageService { @Override public void deleteGroup(Package rootPackage) { Group group = getGroup(rootPackage); if (group != null) { deleteRoles(group); dataService.delete(GROUP, group); mutableAclService.deleteAcl(new GroupIdentity(group.getName()), true); } } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); @Override void createGroup(Package rootPackage); @Override void createGroups(List<Package> packages); @Override void deleteGroup(Package rootPackage); }
GroupPackageServiceImpl implements GroupPackageService { @Override public void deleteGroup(Package rootPackage) { Group group = getGroup(rootPackage); if (group != null) { deleteRoles(group); dataService.delete(GROUP, group); mutableAclService.deleteAcl(new GroupIdentity(group.getName()), true); } } GroupPackageServiceImpl(
      GroupValueFactory groupValueFactory,
      RoleMembershipService roleMembershipService,
      RoleFactory roleFactory,
      DataService dataService,
      GroupFactory groupFactory,
      MutableAclService mutableAclService,
      GroupService groupService); @Override void createGroup(Package rootPackage); @Override void createGroups(List<Package> packages); @Override void deleteGroup(Package rootPackage);  }