use of org.springframework.cloud.servicebroker.model.error.ErrorMessage 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.cloud.servicebroker.model.error.ErrorMessage 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.cloud.servicebroker.model.error.ErrorMessage in project spring-cloud-open-service-broker by spring-cloud.
the class BaseControllerTest method httpMessageNotReadableExceptionGivesExpectedStatus.
@Test
public void httpMessageNotReadableExceptionGivesExpectedStatus() {
HttpMessageNotReadableException exception = new HttpMessageNotReadableException("test message");
ResponseEntity<ErrorMessage> responseEntity = controller.handleException(exception);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
assertThat(responseEntity.getBody().getError()).isNull();
assertThat(responseEntity.getBody().getMessage()).contains("test message");
}
use of org.springframework.cloud.servicebroker.model.error.ErrorMessage in project spring-cloud-open-service-broker by spring-cloud.
the class BaseControllerTest method serviceBrokerUnavailableExceptionGivesExpectedStatus.
@Test
public void serviceBrokerUnavailableExceptionGivesExpectedStatus() {
ServiceBrokerUnavailableException exception = new ServiceBrokerUnavailableException("maintenance in progress");
ResponseEntity<ErrorMessage> responseEntity = controller.handleException(exception);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.SERVICE_UNAVAILABLE);
assertThat(responseEntity.getBody().getError()).isNull();
assertThat(responseEntity.getBody().getMessage()).contains("maintenance in progress");
}
use of org.springframework.cloud.servicebroker.model.error.ErrorMessage in project spring-cloud-open-service-broker by spring-cloud.
the class BaseControllerTest method serviceBrokerExceptionGivesExpectedStatus.
@Test
public void serviceBrokerExceptionGivesExpectedStatus() {
ServiceBrokerException exception = new ServiceBrokerException("test message");
ResponseEntity<ErrorMessage> responseEntity = controller.handleException(exception);
assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertThat(responseEntity.getBody().getError()).isNull();
assertThat(responseEntity.getBody().getMessage()).contains("test message");
}
Aggregations