Search in sources :

Example 1 with MembershipRepository

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);
}
Also used : SystemRole(io.gravitee.am.model.permissions.SystemRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) MembershipServiceImpl(io.gravitee.am.service.impl.MembershipServiceImpl) InjectMocks(org.mockito.InjectMocks) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) SystemRole(io.gravitee.am.model.permissions.SystemRole) MemberType(io.gravitee.am.model.membership.MemberType) Mock(org.mockito.Mock) Maybe(io.reactivex.Maybe) RunWith(org.junit.runner.RunWith) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) Single(io.reactivex.Single) DefaultUser(io.gravitee.am.identityprovider.api.DefaultUser) io.gravitee.am.model(io.gravitee.am.model) Event(io.gravitee.am.model.common.event.Event) io.gravitee.am.service.exception(io.gravitee.am.service.exception) MembershipRepository(io.gravitee.am.repository.management.api.MembershipRepository) Mockito(org.mockito.Mockito) Flowable(io.reactivex.Flowable) NewMembership(io.gravitee.am.service.model.NewMembership) MembershipCriteria(io.gravitee.am.repository.management.api.search.MembershipCriteria) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) NewMembership(io.gravitee.am.service.model.NewMembership) Test(org.junit.Test)

Aggregations

DefaultUser (io.gravitee.am.identityprovider.api.DefaultUser)1 io.gravitee.am.model (io.gravitee.am.model)1 Event (io.gravitee.am.model.common.event.Event)1 MemberType (io.gravitee.am.model.membership.MemberType)1 DefaultRole (io.gravitee.am.model.permissions.DefaultRole)1 SystemRole (io.gravitee.am.model.permissions.SystemRole)1 MembershipRepository (io.gravitee.am.repository.management.api.MembershipRepository)1 MembershipCriteria (io.gravitee.am.repository.management.api.search.MembershipCriteria)1 io.gravitee.am.service.exception (io.gravitee.am.service.exception)1 MembershipServiceImpl (io.gravitee.am.service.impl.MembershipServiceImpl)1 NewMembership (io.gravitee.am.service.model.NewMembership)1 Flowable (io.reactivex.Flowable)1 Maybe (io.reactivex.Maybe)1 Single (io.reactivex.Single)1 TestObserver (io.reactivex.observers.TestObserver)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 ArgumentMatchers.any (org.mockito.ArgumentMatchers.any)1 InjectMocks (org.mockito.InjectMocks)1