use of org.springframework.validation.MapBindingResult in project spring-cloud-open-service-broker by spring-cloud.
the class BaseControllerTest method methodArgumentNotValidExceptionGivesExpectedStatus.
@Test
public void methodArgumentNotValidExceptionGivesExpectedStatus() 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);
MethodArgumentNotValidException exception = new MethodArgumentNotValidException(parameter, bindingResult);
ResponseEntity<ErrorMessage> responseEntity = controller.handleException(exception);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
assertThat(responseEntity.getBody().getError()).isNull();
assertThat(responseEntity.getBody().getMessage()).contains("field1");
assertThat(responseEntity.getBody().getMessage()).contains("field2");
}
use of org.springframework.validation.MapBindingResult in project spring-cloud-open-service-broker by spring-cloud.
the class BaseControllerTest method webExchangeBindExceptionGivesExpectedStatus.
@Test
public void webExchangeBindExceptionGivesExpectedStatus() 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);
ResponseEntity<ErrorMessage> responseEntity = controller.handleException(exception);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
assertThat(responseEntity.getBody().getError()).isNull();
assertThat(responseEntity.getBody().getMessage()).contains("field1");
assertThat(responseEntity.getBody().getMessage()).contains("field2");
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class DataObjectModelController method deleteGroup.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<RestResponse> deleteGroup(@PathVariable String dataModelId) throws ApsSystemException {
logger.info("deleting data object model -> {}", dataModelId);
MapBindingResult bindingResult = new MapBindingResult(new HashMap<>(), "dataModels");
Long dataId = this.getDataObjectModelValidator().checkValidModelId(dataModelId, bindingResult);
if (null == dataId) {
throw new ValidationGenericException(bindingResult);
}
this.getDataObjectModelService().removeDataObjectModel(Long.parseLong(dataModelId));
Map<String, String> payload = new HashMap<>();
payload.put("modelId", dataModelId);
return new ResponseEntity<>(new RestResponse(payload), HttpStatus.OK);
}
use of org.springframework.validation.MapBindingResult in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method withBindingErrors.
@Test
void withBindingErrors() {
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new BindException(bindingResult);
testBindingResult(bindingResult, ex, ErrorAttributeOptions.of(Include.MESSAGE, Include.BINDING_ERRORS));
}
use of org.springframework.validation.MapBindingResult in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method withMethodArgumentNotValidExceptionBindingErrors.
@Test
void withMethodArgumentNotValidExceptionBindingErrors() {
Method method = ReflectionUtils.findMethod(String.class, "substring", int.class);
MethodParameter parameter = new MethodParameter(method, 0);
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new MethodArgumentNotValidException(parameter, bindingResult);
testBindingResult(bindingResult, ex, ErrorAttributeOptions.of(Include.MESSAGE, Include.BINDING_ERRORS));
}
Aggregations