Search in sources :

Example 1 with CreateAppRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO in project AuthGuard by AuthGuard.

the class CreateAppRequestValidatorTest method validateMissingNameAndDomain.

@Test
void validateMissingNameAndDomain() {
    final CreateAppRequestDTO request = CreateAppRequestDTO.builder().build();
    final Validator<CreateAppRequestDTO> validator = Validators.getForClass(CreateAppRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).containsExactlyInAnyOrder(new Violation("name", ViolationType.MISSING_REQUIRED_VALUE), new Violation("domain", ViolationType.MISSING_REQUIRED_VALUE));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) CreateAppRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO) Test(org.junit.jupiter.api.Test)

Example 2 with CreateAppRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO in project AuthGuard by AuthGuard.

the class RestMapperTest method createAppRequestToAccountBO.

@Test
void createAppRequestToAccountBO() {
    final CreateAppRequestDTO requestDTO = easyRandom.nextObject(CreateAppRequestDTO.class);
    final AppDTO appDTO = AppDTO.builder().externalId(requestDTO.getExternalId()).name(requestDTO.getName()).accountId(requestDTO.getAccountId()).permissions(requestDTO.getPermissions()).roles(requestDTO.getRoles()).active(requestDTO.isActive()).domain(requestDTO.getDomain()).build();
    // verified in another test case
    final AppBO expected = restMapper.toBO(appDTO);
    final AppBO actual = restMapper.toBO(requestDTO);
    assertThat(actual).isEqualTo(expected);
}
Also used : CreateAppRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO) Test(org.junit.jupiter.api.Test)

Example 3 with CreateAppRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO in project AuthGuard by AuthGuard.

the class ApplicationsRoute method create.

public void create(final Context context) {
    final String idempotentKey = IdempotencyHeader.getKeyOrFail(context);
    final CreateAppRequestDTO request = appRequestRequestBodyHandler.getValidated(context);
    final RequestContextBO requestContext = RequestContextBO.builder().idempotentKey(idempotentKey).source(context.ip()).build();
    final Optional<Object> created = Optional.of(restMapper.toBO(request)).map(appBO -> applicationsService.create(appBO, requestContext)).map(restMapper::toDTO);
    if (created.isPresent()) {
        context.status(201).json(created.get());
    } else {
        context.status(400).json(new Error("400", "Failed to create application"));
    }
}
Also used : ApiKeysService(com.nexblocks.authguard.service.ApiKeysService) AppDTO(com.nexblocks.authguard.api.dto.entities.AppDTO) ApplicationsApi(com.nexblocks.authguard.api.routes.ApplicationsApi) ApiKeyDTO(com.nexblocks.authguard.api.dto.entities.ApiKeyDTO) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) Inject(com.google.inject.Inject) Collectors(java.util.stream.Collectors) List(java.util.List) BodyHandler(com.nexblocks.authguard.rest.util.BodyHandler) Error(com.nexblocks.authguard.api.dto.entities.Error) RestJsonMapper(com.nexblocks.authguard.rest.mappers.RestJsonMapper) RestMapper(com.nexblocks.authguard.rest.mappers.RestMapper) Context(io.javalin.http.Context) Optional(java.util.Optional) CreateAppRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO) IdempotencyHeader(com.nexblocks.authguard.rest.util.IdempotencyHeader) ApplicationsService(com.nexblocks.authguard.service.ApplicationsService) CreateAppRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO) RequestContextBO(com.nexblocks.authguard.service.model.RequestContextBO) Error(com.nexblocks.authguard.api.dto.entities.Error)

Example 4 with CreateAppRequestDTO

use of com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO in project AuthGuard by AuthGuard.

the class CreateAppRequestValidatorTest method validateValid.

@Test
void validateValid() {
    final CreateAppRequestDTO request = CreateAppRequestDTO.builder().name("app").domain("main").build();
    final Validator<CreateAppRequestDTO> validator = Validators.getForClass(CreateAppRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).isEmpty();
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) CreateAppRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO) Test(org.junit.jupiter.api.Test)

Aggregations

CreateAppRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateAppRequestDTO)4 Test (org.junit.jupiter.api.Test)3 Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)2 Inject (com.google.inject.Inject)1 ApiKeyDTO (com.nexblocks.authguard.api.dto.entities.ApiKeyDTO)1 AppDTO (com.nexblocks.authguard.api.dto.entities.AppDTO)1 Error (com.nexblocks.authguard.api.dto.entities.Error)1 ApplicationsApi (com.nexblocks.authguard.api.routes.ApplicationsApi)1 RestJsonMapper (com.nexblocks.authguard.rest.mappers.RestJsonMapper)1 RestMapper (com.nexblocks.authguard.rest.mappers.RestMapper)1 BodyHandler (com.nexblocks.authguard.rest.util.BodyHandler)1 IdempotencyHeader (com.nexblocks.authguard.rest.util.IdempotencyHeader)1 ApiKeysService (com.nexblocks.authguard.service.ApiKeysService)1 ApplicationsService (com.nexblocks.authguard.service.ApplicationsService)1 RequestContextBO (com.nexblocks.authguard.service.model.RequestContextBO)1 Context (io.javalin.http.Context)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1