use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method grantPermissionsFromDifferentDomain.
@Test
void grantPermissionsFromDifferentDomain() {
final AccountDO account = createAccountDO();
Mockito.when(accountsRepository.getById(account.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(account)));
Mockito.when(permissionsService.validate(any(), eq("other"))).thenAnswer(invocation -> invocation.getArgument(0, List.class));
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 patch.
@Test
void patch() {
final AccountBO accountBO = createAccountBO().withCreatedAt(OffsetDateTime.now()).withLastModified(OffsetDateTime.now());
final AccountBO update = AccountBO.builder().firstName("first_name").middleName("middle_name").lastName("last_name").phoneNumber(PhoneNumberBO.builder().number("new_number").build()).email(AccountEmailBO.builder().email("new_primary").build()).backupEmail(AccountEmailBO.builder().email("new_backup").build()).build();
final AccountDO accountDO = serviceMapper.toDO(accountBO);
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 Optional<AccountBO> updated = accountService.patch(accountDO.getId(), update);
final AccountBO expected = accountBO.withFirstName(update.getFirstName()).withMiddleName(update.getMiddleName()).withLastName(update.getLastName()).withPhoneNumber(update.getPhoneNumber()).withEmail(update.getEmail()).withBackupEmail(update.getBackupEmail());
final List<PermissionBO> expectedPermissions = accountBO.getPermissions().stream().map(permission -> permission.withEntityType(null)).collect(Collectors.toList());
assertThat(updated).isPresent();
assertThat(updated.get()).isEqualToIgnoringGivenFields(expected.withPermissions(expectedPermissions), "lastModified");
assertThat(updated.get().getLastModified()).isAfter(expected.getLastModified());
// need better assertion
Mockito.verify(messageBus, Mockito.times(1)).publish(eq("accounts"), any());
Mockito.verify(messageBus, Mockito.times(3)).publish(eq("verification"), any());
}
use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method grantRoles.
@Test
void grantRoles() {
final AccountDO account = createAccountDO();
Mockito.when(accountsRepository.getById(account.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(account)));
Mockito.when(accountsRepository.update(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(Optional.of(invocation.getArgument(0, AccountDO.class))));
final List<String> roles = Arrays.asList(RANDOM.nextObject(String.class), RANDOM.nextObject(String.class));
Mockito.when(rolesService.verifyRoles(roles, "main")).thenReturn(roles);
final AccountBO updated = accountService.grantRoles(account.getId(), roles);
assertThat(updated).isNotEqualTo(account);
assertThat(updated.getRoles()).contains(roles.toArray(new String[0]));
}
use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method activateAccount.
@Test
void activateAccount() {
final AccountBO accountBO = createAccountBO();
final AccountDO accountDO = serviceMapper.toDO(accountBO);
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.activate(accountDO.getId()).orElse(null);
final List<PermissionBO> expectedPermissions = accountBO.getPermissions().stream().map(permission -> permission.withEntityType(null)).collect(Collectors.toList());
assertThat(updated).isNotNull();
assertThat(updated).isEqualToIgnoringGivenFields(accountBO.withPermissions(expectedPermissions), "id", "createdAt", "lastModified", "active");
assertThat(updated.isActive()).isTrue();
}
use of com.nexblocks.authguard.dal.model.AccountDO in project AuthGuard by AuthGuard.
the class AccountsServiceImplTest method revokeRoles.
@Test
void revokeRoles() {
final AccountDO account = createAccountDO();
final List<String> currentRoles = new ArrayList<>(account.getRoles());
Mockito.when(accountsRepository.getById(account.getId())).thenReturn(CompletableFuture.completedFuture(Optional.of(account)));
Mockito.when(accountsRepository.update(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(Optional.of(invocation.getArgument(0, AccountDO.class))));
final List<String> rolesToRevoke = Arrays.asList(currentRoles.get(0), currentRoles.get(1));
final AccountBO updated = accountService.revokeRoles(account.getId(), rolesToRevoke);
assertThat(updated).isNotEqualTo(account);
assertThat(updated.getRoles()).doesNotContain(rolesToRevoke.toArray(new String[0]));
}
Aggregations