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