use of io.gravitee.repository.management.api.GroupRepository in project gravitee-management-rest-api by gravitee-io.
the class GroupService_UpdateTest method shouldUpdateGroup.
@Test
public void shouldUpdateGroup() throws Exception {
UpdateGroupEntity updatedGroupEntity = new UpdateGroupEntity();
updatedGroupEntity.setDisableMembershipNotifications(true);
updatedGroupEntity.setEmailInvitation(true);
updatedGroupEntity.setEventRules(null);
updatedGroupEntity.setLockApiRole(true);
updatedGroupEntity.setLockApplicationRole(true);
updatedGroupEntity.setMaxInvitation(100);
updatedGroupEntity.setName("my-group-name");
updatedGroupEntity.setRoles(Maps.<RoleScope, String>builder().put(RoleScope.API, "OWNER").build());
updatedGroupEntity.setSystemInvitation(false);
when(groupRepository.findById(GROUP_ID)).thenReturn(Optional.of(Mockito.mock(Group.class)));
when(permissionService.hasPermission(RolePermission.ENVIRONMENT_GROUP, "DEFAULT", CREATE, UPDATE, DELETE)).thenReturn(true);
when(membershipService.getRoles(any(), any(), any(), any())).thenReturn(Collections.emptySet());
groupService.update(GROUP_ID, updatedGroupEntity);
verify(groupRepository).update(argThat(group -> group.isDisableMembershipNotifications() && group.isEmailInvitation() && group.getEventRules() == null && group.isLockApiRole() && group.isLockApplicationRole() && group.getMaxInvitation() == 100 && group.getName().equals("my-group-name") && !group.isSystemInvitation()));
verify(membershipService).addRoleToMemberOnReference(argThat(membershipReference -> membershipReference.getType() == MembershipReferenceType.API && membershipReference.getId() == null), argThat(membershipMember -> membershipMember.getMemberId().equals(GROUP_ID) && membershipMember.getReference() == null && membershipMember.getMemberType() == MembershipMemberType.GROUP), argThat(membershipRole -> membershipRole.getScope() == RoleScope.API && membershipRole.getName().equals("OWNER")));
}
Aggregations