use of org.springframework.validation.FieldError in project spring-cloud-open-service-broker by spring-cloud.
the class ServiceBrokerWebFluxExceptionHandlerTest method webExchangeBindException.
@Test
void webExchangeBindException() throws NoSuchMethodException {
BindingResult bindingResult = new MapBindingResult(new HashMap<>(), "objectName");
bindingResult.addError(new FieldError("objectName", "field1", "message"));
bindingResult.addError(new FieldError("objectName", "field2", "message"));
Method method = this.getClass().getMethod("setUp", (Class<?>[]) null);
MethodParameter parameter = new MethodParameter(method, -1);
WebExchangeBindException exception = new WebExchangeBindException(parameter, bindingResult);
ErrorMessage errorMessage = exceptionHandler.handleException(exception);
assertThat(errorMessage.getError()).isNull();
assertThat(errorMessage.getMessage()).contains("field1");
assertThat(errorMessage.getMessage()).contains("field2");
}
use of org.springframework.validation.FieldError in project arch-playground by BeneStem.
the class BadRequestException method badRequest.
public static BadRequestException badRequest(final Object target, final String targetName, final String fieldName, final String message) {
final var error = new BeanPropertyBindingResult(target, targetName);
error.addError(new FieldError(targetName, fieldName, message));
return badRequest(error);
}
use of org.springframework.validation.FieldError in project alien4cloud by alien4cloud.
the class RestTechnicalExceptionHandler method processValidationError.
@ExceptionHandler(MethodArgumentNotValidException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public RestResponse<FieldErrorDTO[]> processValidationError(MethodArgumentNotValidException e) {
BindingResult result = e.getBindingResult();
List<FieldErrorDTO> errors = Lists.newArrayList();
for (FieldError fieldError : result.getFieldErrors()) {
errors.add(new FieldErrorDTO(fieldError.getField(), fieldError.getCode()));
}
return RestResponseBuilder.<FieldErrorDTO[]>builder().data(errors.toArray(new FieldErrorDTO[errors.size()])).error(RestErrorBuilder.builder(RestErrorCode.ILLEGAL_PARAMETER).message("Method argument is invalid " + e.getMessage()).build()).build();
}
use of org.springframework.validation.FieldError in project molgenis by molgenis.
the class RepositoryConstraintViolationExceptionTest method testGetFieldErrors.
@Test
void testGetFieldErrors() {
EntityErrors entityErrors = mock(EntityErrors.class);
List<FieldError> list = new ArrayList<>();
list.add(new FieldError("name1", "field1", "message1"));
list.add(new FieldError("name2", "field2", "message2"));
when(entityErrors.getFieldErrors("field")).thenReturn(list);
RepositoryConstraintViolationException exception = new RepositoryConstraintViolationException(entityErrors);
assertEquals(exception.getFieldErrors("field"), list);
}
use of org.springframework.validation.FieldError in project molgenis by molgenis.
the class RepositoryConstraintViolationExceptionTest method getFieldError.
@Test
void getFieldError() {
EntityErrors entityErrors = mock(EntityErrors.class);
FieldError fieldError = new FieldError("name1", "field", "message1");
when(entityErrors.getFieldError()).thenReturn(fieldError);
RepositoryConstraintViolationException exception = new RepositoryConstraintViolationException(entityErrors);
assertEquals(exception.getFieldError(), fieldError);
}
Aggregations