Search in sources :

Example 1 with RoleRepository

use of io.gravitee.am.repository.management.api.RoleRepository in project gravitee-access-management by gravitee-io.

the class RoleServiceTest method shouldUpdate_defaultRolePermissions.

@Test
public void shouldUpdate_defaultRolePermissions() {
    UpdateRole updateRole = new UpdateRole();
    updateRole.setName(DefaultRole.DOMAIN_USER.name());
    updateRole.setPermissions(Permission.flatten(Collections.singletonMap(Permission.DOMAIN, Collections.singleton(Acl.READ))));
    Role role = new Role();
    role.setName(DefaultRole.DOMAIN_USER.name());
    // should be able to update a default role.
    role.setDefaultRole(true);
    role.setReferenceType(ReferenceType.ORGANIZATION);
    role.setReferenceId(ORGANIZATION_ID);
    when(roleRepository.findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role")).thenReturn(Maybe.just(role));
    when(roleRepository.findAll(ReferenceType.ORGANIZATION, ORGANIZATION_ID)).thenReturn(Flowable.empty());
    when(roleRepository.update(argThat(r -> r.getPermissionAcls().equals(Permission.unflatten(updateRole.getPermissions()))))).thenReturn(Single.just(role));
    when(eventService.create(any())).thenReturn(Single.just(new Event()));
    TestObserver testObserver = roleService.update(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role", updateRole, null).test();
    testObserver.awaitTerminalEvent();
    testObserver.assertComplete();
    testObserver.assertNoErrors();
    verify(roleRepository, times(1)).findById(ReferenceType.ORGANIZATION, ORGANIZATION_ID, "my-role");
    verify(roleRepository, times(1)).findAll(ReferenceType.ORGANIZATION, ORGANIZATION_ID);
    verify(roleRepository, times(1)).update(any(Role.class));
}
Also used : Role(io.gravitee.am.model.Role) NewRole(io.gravitee.am.service.model.NewRole) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) UpdateRole(io.gravitee.am.service.model.UpdateRole) Arrays(java.util.Arrays) Mock(org.mockito.Mock) Completable(io.reactivex.Completable) Role(io.gravitee.am.model.Role) Permission(io.gravitee.am.model.permissions.Permission) Maybe(io.reactivex.Maybe) RunWith(org.junit.runner.RunWith) TechnicalException(io.gravitee.am.repository.exceptions.TechnicalException) Single(io.reactivex.Single) Event(io.gravitee.am.model.common.event.Event) Matchers.anyString(org.mockito.Matchers.anyString) io.gravitee.am.service.exception(io.gravitee.am.service.exception) Acl(io.gravitee.am.model.Acl) Flowable(io.reactivex.Flowable) NewRole(io.gravitee.am.service.model.NewRole) ReferenceType(io.gravitee.am.model.ReferenceType) RoleServiceImpl(io.gravitee.am.service.impl.RoleServiceImpl) InjectMocks(org.mockito.InjectMocks) Set(java.util.Set) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test) DefaultRole(io.gravitee.am.model.permissions.DefaultRole) RoleRepository(io.gravitee.am.repository.management.api.RoleRepository) UpdateRole(io.gravitee.am.service.model.UpdateRole) Mockito(org.mockito.Mockito) Matchers.anyList(org.mockito.Matchers.anyList) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) UpdateRole(io.gravitee.am.service.model.UpdateRole) Event(io.gravitee.am.model.common.event.Event) TestObserver(io.reactivex.observers.TestObserver) Test(org.junit.Test)

Aggregations

Acl (io.gravitee.am.model.Acl)1 ReferenceType (io.gravitee.am.model.ReferenceType)1 Role (io.gravitee.am.model.Role)1 Event (io.gravitee.am.model.common.event.Event)1 DefaultRole (io.gravitee.am.model.permissions.DefaultRole)1 Permission (io.gravitee.am.model.permissions.Permission)1 TechnicalException (io.gravitee.am.repository.exceptions.TechnicalException)1 RoleRepository (io.gravitee.am.repository.management.api.RoleRepository)1 io.gravitee.am.service.exception (io.gravitee.am.service.exception)1 RoleServiceImpl (io.gravitee.am.service.impl.RoleServiceImpl)1 NewRole (io.gravitee.am.service.model.NewRole)1 UpdateRole (io.gravitee.am.service.model.UpdateRole)1 Completable (io.reactivex.Completable)1 Flowable (io.reactivex.Flowable)1 Maybe (io.reactivex.Maybe)1 Single (io.reactivex.Single)1 TestObserver (io.reactivex.observers.TestObserver)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Set (java.util.Set)1