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);
}
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]));
}
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;
}
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));
}
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();
}
Aggregations