Search in sources :

Example 1 with RolesRequestDTO

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

the class RolesRequestValidatorTest method validateValid.

@Test
void validateValid() {
    final RolesRequestDTO request = RolesRequestDTO.builder().action(RolesRequest.Action.GRANT).addRoles("test").build();
    final Validator<RolesRequestDTO> validator = Validators.getForClass(RolesRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).isEmpty();
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) RolesRequestDTO(com.nexblocks.authguard.api.dto.requests.RolesRequestDTO) Test(org.junit.jupiter.api.Test)

Example 2 with RolesRequestDTO

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

the class RolesRequestDTOTest method parse.

@Test
void parse() {
    final ArrayNode roles = new ArrayNode(JsonNodeFactory.instance).add("test");
    final ObjectNode requestJson = new ObjectNode(JsonNodeFactory.instance).put("action", "GRANT").set("roles", roles);
    final ObjectMapper objectMapper = new ObjectMapper();
    final RolesRequestDTO expected = RolesRequestDTO.builder().action(RolesRequest.Action.GRANT).addRoles("test").build();
    final RolesRequestDTO actual = objectMapper.convertValue(requestJson, RolesRequestDTO.class);
    assertThat(actual).isEqualTo(expected);
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) RolesRequestDTO(com.nexblocks.authguard.api.dto.requests.RolesRequestDTO) Test(org.junit.jupiter.api.Test)

Example 3 with RolesRequestDTO

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

the class RolesRequestValidatorTest method validateNoFields.

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

Aggregations

RolesRequestDTO (com.nexblocks.authguard.api.dto.requests.RolesRequestDTO)3 Test (org.junit.jupiter.api.Test)3 Violation (com.nexblocks.authguard.api.dto.validation.violations.Violation)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1