Search in sources :

Example 1 with CreateRoleRequestDTO

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

the class CreateRoleRequestValidatorTest method validateNoNameOrDomain.

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

Example 2 with CreateRoleRequestDTO

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

the class RolesRoute method create.

public void create(final Context context) {
    final CreateRoleRequestDTO role = createRoleRequestBodyHandler.getValidated(context);
    final RoleDTO created = Optional.of(role).map(restMapper::toBO).map(rolesService::create).map(restMapper::toDTO).orElseThrow();
    context.status(201).json(created);
}
Also used : RoleDTO(com.nexblocks.authguard.api.dto.entities.RoleDTO) CreateRoleRequestDTO(com.nexblocks.authguard.api.dto.requests.CreateRoleRequestDTO)

Example 3 with CreateRoleRequestDTO

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

the class CreateRoleRequestValidatorTest method validateValidRequest.

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

Aggregations

CreateRoleRequestDTO (com.nexblocks.authguard.api.dto.requests.CreateRoleRequestDTO)3 Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)2 Test (org.junit.jupiter.api.Test)2 RoleDTO (com.nexblocks.authguard.api.dto.entities.RoleDTO)1