Search in sources :

Example 1 with GroupRepository

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")));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) InjectMocks(org.mockito.InjectMocks) RolePermissionAction(io.gravitee.rest.api.model.permissions.RolePermissionAction) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) GroupRepository(io.gravitee.repository.management.api.GroupRepository) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) Group(io.gravitee.repository.management.model.Group) Test(org.junit.Test) RoleScope(io.gravitee.rest.api.model.permissions.RoleScope) Maps(io.gravitee.common.util.Maps) Mockito(org.mockito.Mockito) MembershipReferenceType(io.gravitee.rest.api.model.MembershipReferenceType) Optional(java.util.Optional) GroupServiceImpl(io.gravitee.rest.api.service.impl.GroupServiceImpl) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) MembershipMemberType(io.gravitee.rest.api.model.MembershipMemberType) UpdateGroupEntity(io.gravitee.rest.api.model.UpdateGroupEntity) RolePermission(io.gravitee.rest.api.model.permissions.RolePermission) UpdateGroupEntity(io.gravitee.rest.api.model.UpdateGroupEntity) Test(org.junit.Test)

Aggregations

Maps (io.gravitee.common.util.Maps)1 GroupRepository (io.gravitee.repository.management.api.GroupRepository)1 Group (io.gravitee.repository.management.model.Group)1 MembershipMemberType (io.gravitee.rest.api.model.MembershipMemberType)1 MembershipReferenceType (io.gravitee.rest.api.model.MembershipReferenceType)1 UpdateGroupEntity (io.gravitee.rest.api.model.UpdateGroupEntity)1 RolePermission (io.gravitee.rest.api.model.permissions.RolePermission)1 RolePermissionAction (io.gravitee.rest.api.model.permissions.RolePermissionAction)1 RoleScope (io.gravitee.rest.api.model.permissions.RoleScope)1 GroupServiceImpl (io.gravitee.rest.api.service.impl.GroupServiceImpl)1 Collections (java.util.Collections)1 Optional (java.util.Optional)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)1 InjectMocks (org.mockito.InjectMocks)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1 MockitoJUnitRunner (org.mockito.junit.MockitoJUnitRunner)1