Search in sources :

Example 1 with PermissionBO

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));
}
Also used : CreatePermissionRequestDTO(com.nexblocks.authguard.api.dto.requests.CreatePermissionRequestDTO) PermissionBO(com.nexblocks.authguard.service.model.PermissionBO)

Example 2 with PermissionBO

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);
}
Also used : PermissionBO(com.nexblocks.authguard.service.model.PermissionBO) PermissionDO(com.nexblocks.authguard.dal.model.PermissionDO) Test(org.junit.jupiter.api.Test)

Example 3 with PermissionBO

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");
}
Also used : PermissionBO(com.nexblocks.authguard.service.model.PermissionBO) Test(org.junit.jupiter.api.Test)

Example 4 with PermissionBO

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());
}
Also used : ServiceMapper(com.nexblocks.authguard.service.mappers.ServiceMapper) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) MessageBus(com.nexblocks.authguard.emb.MessageBus) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceMapperImpl(com.nexblocks.authguard.service.mappers.ServiceMapperImpl) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) AccountsService(com.nexblocks.authguard.service.AccountsService) AppBO(com.nexblocks.authguard.service.model.AppBO) ApplicationsService(com.nexblocks.authguard.service.ApplicationsService) IdempotencyService(com.nexblocks.authguard.service.IdempotencyService) EasyRandomParameters(org.jeasy.random.EasyRandomParameters) AppDO(com.nexblocks.authguard.dal.model.AppDO) ApplicationsRepository(com.nexblocks.authguard.dal.persistence.ApplicationsRepository) EasyRandom(org.jeasy.random.EasyRandom) AccountBO(com.nexblocks.authguard.service.model.AccountBO) PermissionBO(com.nexblocks.authguard.service.model.PermissionBO) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) Optional(java.util.Optional) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) AppBO(com.nexblocks.authguard.service.model.AppBO) PermissionBO(com.nexblocks.authguard.service.model.PermissionBO) Test(org.junit.jupiter.api.Test)

Example 5 with PermissionBO

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");
}
Also used : ServiceMapper(com.nexblocks.authguard.service.mappers.ServiceMapper) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) MessageBus(com.nexblocks.authguard.emb.MessageBus) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ServiceMapperImpl(com.nexblocks.authguard.service.mappers.ServiceMapperImpl) CompletableFuture(java.util.concurrent.CompletableFuture) Supplier(java.util.function.Supplier) AccountsService(com.nexblocks.authguard.service.AccountsService) AppBO(com.nexblocks.authguard.service.model.AppBO) ApplicationsService(com.nexblocks.authguard.service.ApplicationsService) IdempotencyService(com.nexblocks.authguard.service.IdempotencyService) EasyRandomParameters(org.jeasy.random.EasyRandomParameters) AppDO(com.nexblocks.authguard.dal.model.AppDO) ApplicationsRepository(com.nexblocks.authguard.dal.persistence.ApplicationsRepository) EasyRandom(org.jeasy.random.EasyRandom) AccountBO(com.nexblocks.authguard.service.model.AccountBO) PermissionBO(com.nexblocks.authguard.service.model.PermissionBO) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) Optional(java.util.Optional) AppBO(com.nexblocks.authguard.service.model.AppBO) PermissionBO(com.nexblocks.authguard.service.model.PermissionBO) Test(org.junit.jupiter.api.Test)

Aggregations

PermissionBO (com.nexblocks.authguard.service.model.PermissionBO)7 Test (org.junit.jupiter.api.Test)6 PermissionDO (com.nexblocks.authguard.dal.model.PermissionDO)3 AppDO (com.nexblocks.authguard.dal.model.AppDO)2 ApplicationsRepository (com.nexblocks.authguard.dal.persistence.ApplicationsRepository)2 MessageBus (com.nexblocks.authguard.emb.MessageBus)2 AccountsService (com.nexblocks.authguard.service.AccountsService)2 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)2 IdempotencyService (com.nexblocks.authguard.service.IdempotencyService)2 ServiceMapper (com.nexblocks.authguard.service.mappers.ServiceMapper)2 ServiceMapperImpl (com.nexblocks.authguard.service.mappers.ServiceMapperImpl)2 AccountBO (com.nexblocks.authguard.service.model.AccountBO)2 AppBO (com.nexblocks.authguard.service.model.AppBO)2 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)2 List (java.util.List)2 Optional (java.util.Optional)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 Supplier (java.util.function.Supplier)2 Collectors (java.util.stream.Collectors)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2