Search in sources :

Example 1 with PermissionsRequestDTO

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

the class PermissionsRequestValidatorTest method validateValid.

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

Example 2 with PermissionsRequestDTO

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

the class PermissionsRequestValidatorTest method validateInvalidPermission.

@Test
void validateInvalidPermission() {
    final PermissionsRequestDTO request = PermissionsRequestDTO.builder().action(PermissionsRequest.Action.GRANT).addPermissions(PermissionDTO.builder().build()).build();
    final Validator<PermissionsRequestDTO> validator = Validators.getForClass(PermissionsRequestDTO.class);
    final List<Violation> violations = validator.validate(request);
    assertThat(violations).containsExactlyInAnyOrder(new Violation("group", ViolationType.MISSING_REQUIRED_VALUE), new Violation("name", ViolationType.MISSING_REQUIRED_VALUE));
}
Also used : Violation(com.nexblocks.authguard.api.dto.validation.violations.Violation) PermissionsRequestDTO(com.nexblocks.authguard.api.dto.requests.PermissionsRequestDTO) Test(org.junit.jupiter.api.Test)

Example 3 with PermissionsRequestDTO

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

the class PermissionsRequestDTOTest method parse.

@Test
void parse() {
    final ArrayNode permissions = new ArrayNode(JsonNodeFactory.instance).add(new ObjectNode(JsonNodeFactory.instance).put("group", "tests").put("name", "read"));
    final ObjectNode requestJson = new ObjectNode(JsonNodeFactory.instance).set("permissions", permissions);
    final ObjectMapper objectMapper = new ObjectMapper();
    final PermissionsRequestDTO expected = PermissionsRequestDTO.builder().addPermissions(PermissionDTO.builder().group("tests").name("read").build()).build();
    final PermissionsRequestDTO actual = objectMapper.convertValue(requestJson, PermissionsRequestDTO.class);
    assertThat(actual).isEqualTo(expected);
}
Also used : PermissionsRequestDTO(com.nexblocks.authguard.api.dto.requests.PermissionsRequestDTO) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 4 with PermissionsRequestDTO

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

the class PermissionsRequestValidatorTest method validateNoFields.

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

Aggregations

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