use of org.springframework.validation.MapBindingResult in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method extractBindingResultErrorsExcludeMessageAndErrors.
@Test
void extractBindingResultErrorsExcludeMessageAndErrors() throws Exception {
Method method = getClass().getDeclaredMethod("method", String.class);
MethodParameter stringParam = new MethodParameter(method, 0);
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new WebExchangeBindException(stringParam, bindingResult);
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, ex), ErrorAttributeOptions.defaults());
assertThat(attributes).doesNotContainKey("message");
assertThat(attributes).doesNotContainKey("errors");
}
use of org.springframework.validation.MapBindingResult in project spring-boot by spring-projects.
the class DefaultErrorAttributesTests method extractBindingResultErrors.
@Test
void extractBindingResultErrors() throws Exception {
Method method = getClass().getDeclaredMethod("method", String.class);
MethodParameter stringParam = new MethodParameter(method, 0);
BindingResult bindingResult = new MapBindingResult(Collections.singletonMap("a", "b"), "objectName");
bindingResult.addError(new ObjectError("c", "d"));
Exception ex = new WebExchangeBindException(stringParam, bindingResult);
MockServerHttpRequest request = MockServerHttpRequest.get("/test").build();
Map<String, Object> attributes = this.errorAttributes.getErrorAttributes(buildServerRequest(request, ex), ErrorAttributeOptions.of(Include.MESSAGE, Include.BINDING_ERRORS));
assertThat(attributes.get("message")).asString().startsWith("Validation failed for argument at index 0 in method: " + "int org.springframework.boot.web.reactive.error.DefaultErrorAttributesTests" + ".method(java.lang.String), with 1 error(s)");
assertThat(attributes.get("errors")).isEqualTo(bindingResult.getAllErrors());
}
use of org.springframework.validation.MapBindingResult in project alf.io by alfio-event.
the class ValidatorTest method init.
@BeforeEach
void init() {
eventModification = mock(EventModification.class);
errors = new MapBindingResult(new HashMap<>(), "test");
ticketCategoryModification = mock(TicketCategoryModification.class);
when(ticketCategoryModification.getInception()).thenReturn(VALID_INCEPTION);
when(ticketCategoryModification.getExpiration()).thenReturn(VALID_EXPIRATION);
when(ticketCategoryModification.getName()).thenReturn("name");
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class DataObjectModelController method getDataObjectModel.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<DataModelDto>> getDataObjectModel(@PathVariable String dataModelId) {
logger.debug("Requested data object model -> {}", dataModelId);
MapBindingResult bindingResult = new MapBindingResult(new HashMap<>(), "dataModels");
int result = this.getDataObjectModelValidator().checkModelId(dataModelId, bindingResult);
if (bindingResult.hasErrors()) {
if (404 == result) {
throw new ResourceNotFoundException(DataObjectModelValidator.ERRCODE_DATAOBJECTMODEL_DOES_NOT_EXIST, "dataObjectModel", dataModelId);
} else {
throw new ValidationGenericException(bindingResult);
}
}
DataModelDto dataModelDto = this.getDataObjectModelService().getDataObjectModel(Long.parseLong(dataModelId));
return new ResponseEntity<>(new SimpleRestResponse<>(dataModelDto), HttpStatus.OK);
}
use of org.springframework.validation.MapBindingResult in project entando-core by entando.
the class DataObjectModelController method deleteDataObjectModel.
@RestAccessControl(permission = Permission.SUPERUSER)
@RequestMapping(value = "/{dataModelId}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<SimpleRestResponse<Map>> deleteDataObjectModel(@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 SimpleRestResponse<>(payload), HttpStatus.OK);
}
Aggregations