use of com.nexblocks.authguard.service.model.PermissionBO in project AuthGuard by AuthGuard.
the class PermissionsRoute method create.
public void create(final Context context) {
final CreatePermissionRequestDTO permission = createPermissionRequestBodyHandler.getValidated(context);
final PermissionBO created = permissionsService.create(restMapper.toBO(permission));
context.status(201).json(restMapper.toDTO(created));
}
use of com.nexblocks.authguard.service.model.PermissionBO in project AuthGuard by AuthGuard.
the class PermissionsServiceImplTest method createDuplicate.
@Test
void createDuplicate() {
final PermissionDO permission = PermissionDO.builder().build();
final PermissionBO request = PermissionBO.builder().group("test").name("read").domain("main").build();
Mockito.when(permissionsRepository.search(request.getGroup(), request.getName(), "main")).thenReturn(CompletableFuture.completedFuture(Optional.of(permission)));
Mockito.when(permissionsRepository.save(Mockito.any())).thenAnswer(invocation -> CompletableFuture.completedFuture(invocation.getArgument(0, PermissionDO.class)));
assertThatThrownBy(() -> permissionsService.create(request)).isInstanceOf(ServiceConflictException.class);
}
use of com.nexblocks.authguard.service.model.PermissionBO in project AuthGuard by AuthGuard.
the class PermissionsServiceImplTest method create.
@Test
void create() {
final PermissionBO request = PermissionBO.builder().group("test").name("read").domain("main").build();
Mockito.when(permissionsRepository.search(request.getGroup(), request.getName(), "main")).thenReturn(CompletableFuture.completedFuture(Optional.empty()));
Mockito.when(permissionsRepository.save(Mockito.any())).thenAnswer(invocation -> CompletableFuture.completedFuture(invocation.getArgument(0, PermissionDO.class)));
final PermissionBO actual = permissionsService.create(request);
assertThat(actual).isEqualToIgnoringGivenFields(request, "id", "createdAt", "lastModified");
}
use of com.nexblocks.authguard.service.model.PermissionBO in project AuthGuard by AuthGuard.
the class ApplicationsServiceImplTest method create.
@Test
void create() {
final AppBO app = random.nextObject(AppBO.class);
final String idempotentKey = "idempotent-key";
final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).build();
Mockito.when(accountsService.getById(app.getParentAccountId())).thenReturn(Optional.of(random.nextObject(AccountBO.class)));
Mockito.when(applicationsRepository.save(any())).thenAnswer(invocation -> CompletableFuture.completedFuture(invocation.getArgument(0, AppDO.class)));
Mockito.when(idempotencyService.performOperation(Mockito.any(), Mockito.eq(idempotentKey), Mockito.eq(app.getEntityType()))).thenAnswer(invocation -> {
return CompletableFuture.completedFuture(invocation.getArgument(0, Supplier.class).get());
});
final AppBO created = applicationsService.create(app, requestContext);
final List<PermissionBO> expectedPermissions = app.getPermissions().stream().map(permission -> permission.withEntityType(null)).collect(Collectors.toList());
assertThat(created).isEqualToIgnoringGivenFields(app.withPermissions(expectedPermissions), "id", "createdAt", "lastModified", "entityType");
Mockito.verify(messageBus, Mockito.times(1)).publish(eq("apps"), any());
}
use of com.nexblocks.authguard.service.model.PermissionBO in project AuthGuard by AuthGuard.
the class ApplicationsServiceImplTest method getById.
@Test
void getById() {
final AppBO app = random.nextObject(AppBO.class).withDeleted(false);
Mockito.when(applicationsRepository.getById(any())).thenReturn(CompletableFuture.completedFuture(Optional.of(serviceMapper.toDO(app))));
final Optional<AppBO> retrieved = applicationsService.getById("");
final List<PermissionBO> expectedPermissions = app.getPermissions().stream().map(permission -> permission.withEntityType(null)).collect(Collectors.toList());
assertThat(retrieved).isPresent();
assertThat(retrieved.get()).isEqualToIgnoringGivenFields(app.withPermissions(expectedPermissions), "permissions", "entityType");
}
Aggregations