Search in sources :

Example 6 with AccountDO

use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.

the class AccountsServiceImplTest method grantPermissionsInvalidPermission.

@Test
void grantPermissionsInvalidPermission() {
    final AccountDO account = createAccountDO();
    Mockito.when(accountsRepository.getById(account.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(account)));
    final List<PermissionBO> permissions = Arrays.asList(RANDOM.nextObject(PermissionBO.class), RANDOM.nextObject(PermissionBO.class));
    assertThatThrownBy(() -> accountService.grantPermissions(account.getId(), permissions)).isInstanceOf(ServiceException.class);
}
Also used : AccountDO(com.nexblocks.authguard.dal.model.AccountDO) Test(org.junit.jupiter.api.Test)

Example 7 with AccountDO

use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.

the class AccountsServiceImplTest method grantPermissions.

@Test
void grantPermissions() {
    final AccountDO account = createAccountDO();
    Mockito.when(accountsRepository.getById(account.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(account)));
    Mockito.when(permissionsService.validate(any(), eq("main"))).thenAnswer(invocation -> invocation.getArgument(0, List.class));
    final List<PermissionBO> permissions = Arrays.asList(RANDOM.nextObject(PermissionBO.class), RANDOM.nextObject(PermissionBO.class));
    final AccountBO updated = accountService.grantPermissions(account.getId(), permissions);
    assertThat(updated).isNotEqualTo(account);
    assertThat(updated.getPermissions()).contains(permissions.toArray(new PermissionBO[0]));
}
Also used : AccountDO(com.nexblocks.authguard.dal.model.AccountDO) Test(org.junit.jupiter.api.Test)

Example 8 with AccountDO

use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.

the class AccountsServiceImplTest method createAccountDO.

private AccountDO createAccountDO() {
    final AccountDO account = RANDOM.nextObject(AccountDO.class);
    account.setDomain("main");
    return account;
}
Also used : AccountDO(com.nexblocks.authguard.dal.model.AccountDO)

Example 9 with AccountDO

use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.

the class AccountsServiceImplTest method getById.

@Test
void getById() {
    final AccountBO accountBO = createAccountBO();
    final AccountDO accountDO = serviceMapper.toDO(accountBO);
    Mockito.when(accountsRepository.getById(any())).thenReturn(CompletableFuture.completedFuture(Optional.of(accountDO)));
    final Optional<AccountBO> retrieved = accountService.getById("");
    final List<PermissionBO> expectedPermissions = accountBO.getPermissions().stream().map(permission -> permission.withEntityType(null)).collect(Collectors.toList());
    assertThat(retrieved).isPresent();
    assertThat(retrieved.get()).isEqualTo(accountBO.withPermissions(expectedPermissions));
}
Also used : ServiceMapper(com.nexblocks.authguard.service.mappers.ServiceMapper) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) MessageBus(com.nexblocks.authguard.emb.MessageBus) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException) ServiceMapperImpl(com.nexblocks.authguard.service.mappers.ServiceMapperImpl) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Message(com.nexblocks.authguard.emb.model.Message) IdempotencyService(com.nexblocks.authguard.service.IdempotencyService) RolesService(com.nexblocks.authguard.service.RolesService) EasyRandomParameters(org.jeasy.random.EasyRandomParameters) ImmutableMap(com.google.common.collect.ImmutableMap) EasyRandom(org.jeasy.random.EasyRandom) EventType(com.nexblocks.authguard.emb.model.EventType) com.nexblocks.authguard.service.model(com.nexblocks.authguard.service.model) PermissionsService(com.nexblocks.authguard.service.PermissionsService) Collectors(java.util.stream.Collectors) AccountConfig(com.nexblocks.authguard.service.config.AccountConfig) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) AccountsRepository(com.nexblocks.authguard.dal.persistence.AccountsRepository) AccountDO(com.nexblocks.authguard.dal.model.AccountDO) ConfigContext(com.nexblocks.authguard.config.ConfigContext) AccountDO(com.nexblocks.authguard.dal.model.AccountDO) Test(org.junit.jupiter.api.Test)

Example 10 with AccountDO

use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.

the class AccountsServiceImplTest method deactivateAccount.

@Test
void deactivateAccount() {
    final AccountBO accountBO = createAccountBO();
    final AccountDO accountDO = serviceMapper.toDO(accountBO);
    final List<PermissionBO> expectedPermissions = accountBO.getPermissions().stream().map(permission -> permission.withEntityType(null)).collect(Collectors.toList());
    Mockito.when(accountsRepository.getById(accountDO.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(accountDO)));
    Mockito.when(accountsRepository.update(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(Optional.of(invocation.getArgument(0, AccountDO.class))));
    final AccountBO updated = accountService.deactivate(accountDO.getId()).orElse(null);
    assertThat(updated).isNotNull();
    assertThat(updated).isEqualToIgnoringGivenFields(accountBO.withPermissions(expectedPermissions), "id", "createdAt", "lastModified", "active");
    assertThat(updated.isActive()).isFalse();
}
Also used : ServiceMapper(com.nexblocks.authguard.service.mappers.ServiceMapper) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) MessageBus(com.nexblocks.authguard.emb.MessageBus) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceException(com.nexblocks.authguard.service.exceptions.ServiceException) ServiceMapperImpl(com.nexblocks.authguard.service.mappers.ServiceMapperImpl) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) ArgumentCaptor(org.mockito.ArgumentCaptor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Message(com.nexblocks.authguard.emb.model.Message) IdempotencyService(com.nexblocks.authguard.service.IdempotencyService) RolesService(com.nexblocks.authguard.service.RolesService) EasyRandomParameters(org.jeasy.random.EasyRandomParameters) ImmutableMap(com.google.common.collect.ImmutableMap) EasyRandom(org.jeasy.random.EasyRandom) EventType(com.nexblocks.authguard.emb.model.EventType) com.nexblocks.authguard.service.model(com.nexblocks.authguard.service.model) PermissionsService(com.nexblocks.authguard.service.PermissionsService) Collectors(java.util.stream.Collectors) AccountConfig(com.nexblocks.authguard.service.config.AccountConfig) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) OffsetDateTime(java.time.OffsetDateTime) AccountsRepository(com.nexblocks.authguard.dal.persistence.AccountsRepository) AccountDO(com.nexblocks.authguard.dal.model.AccountDO) ConfigContext(com.nexblocks.authguard.config.ConfigContext) AccountDO(com.nexblocks.authguard.dal.model.AccountDO) Test(org.junit.jupiter.api.Test)

Aggregations

AccountDO (com.nexblocks.authguard.dal.model.AccountDO)14 Test (org.junit.jupiter.api.Test)13 ImmutableMap (com.google.common.collect.ImmutableMap)6 ConfigContext (com.nexblocks.authguard.config.ConfigContext)6 AccountsRepository (com.nexblocks.authguard.dal.persistence.AccountsRepository)6 MessageBus (com.nexblocks.authguard.emb.MessageBus)6 EventType (com.nexblocks.authguard.emb.model.EventType)6 Message (com.nexblocks.authguard.emb.model.Message)6 IdempotencyService (com.nexblocks.authguard.service.IdempotencyService)6 PermissionsService (com.nexblocks.authguard.service.PermissionsService)6 RolesService (com.nexblocks.authguard.service.RolesService)6 AccountConfig (com.nexblocks.authguard.service.config.AccountConfig)6 ServiceException (com.nexblocks.authguard.service.exceptions.ServiceException)6 ServiceMapper (com.nexblocks.authguard.service.mappers.ServiceMapper)6 ServiceMapperImpl (com.nexblocks.authguard.service.mappers.ServiceMapperImpl)6 com.nexblocks.authguard.service.model (com.nexblocks.authguard.service.model)6 OffsetDateTime (java.time.OffsetDateTime)6 java.util (java.util)6 CompletableFuture (java.util.concurrent.CompletableFuture)6 Supplier (java.util.function.Supplier)6