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