use of io.gravitee.am.repository.management.api.MembershipRepository in project gravitee-access-management by gravitee-io.
the class MembershipServiceTest method shouldNotSetPlatformAdmin_alreadySet.
@Test
public void shouldNotSetPlatformAdmin_alreadySet() {
final String userId = "userId";
final Membership alreadyExisting = new Membership();
final Role platformAdminRole = new Role();
platformAdminRole.setId("platform-admin");
when(roleService.findSystemRole(SystemRole.PLATFORM_ADMIN, ReferenceType.PLATFORM)).thenReturn(Maybe.just(platformAdminRole));
when(membershipRepository.findByCriteria(eq(ReferenceType.PLATFORM), eq(Platform.DEFAULT), argThat(criteria -> criteria != null && criteria.getUserId().get().equals(userId)))).thenReturn(Flowable.just(alreadyExisting));
final TestObserver<Membership> obs = membershipService.setPlatformAdmin(userId).test();
obs.awaitTerminalEvent();
obs.assertComplete();
obs.assertValue(alreadyExisting);
verify(membershipRepository, times(0)).create(any(Membership.class));
verifyZeroInteractions(eventService);
verifyZeroInteractions(auditService);
}
Aggregations