ServiceBrokerExceptionHandler { @ExceptionHandler(ServiceBrokerApiVersionException.class) @ResponseStatus(HttpStatus.PRECONDITION_FAILED) public ErrorMessage handleException(ServiceBrokerApiVersionException ex) { return getErrorResponse(ex); }  @ExceptionHandler(ServiceBrokerApiVersionException.class) @ResponseStatus(HttpStatus.PRECONDITION_FAILED) ErrorMessage handleException(ServiceBrokerApiVersionException ex); @ExceptionHandler(ServiceBrokerApiVersionMissingException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) ErrorMessage handleException(ServiceBrokerApiVersionMissingException ex); @ExceptionHandler(ServiceInstanceDoesNotExistException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) ErrorMessage handleException(ServiceInstanceDoesNotExistException ex); @ExceptionHandler(ServiceDefinitionDoesNotExistException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) ErrorMessage handleException(ServiceDefinitionDoesNotExistException ex); @ExceptionHandler(ServiceDefinitionPlanDoesNotExistException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) ErrorMessage handleException(ServiceDefinitionPlanDoesNotExistException ex); @ExceptionHandler(ServiceBrokerAsyncRequiredException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) ErrorMessage handleException(ServiceBrokerAsyncRequiredException ex); @ExceptionHandler(ServiceBrokerMaintenanceInfoConflictException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) ErrorMessage handleException(ServiceBrokerMaintenanceInfoConflictException ex); @ExceptionHandler(ServiceBrokerInvalidParametersException.class) @ResponseStatus(HttpStatus.BAD_REQUEST) ErrorMessage handleException(ServiceBrokerInvalidParametersException ex); @ExceptionHandler(ServiceBrokerOperationInProgressException.class) @ResponseStatus(HttpStatus.NOT_FOUND) ErrorMessage handleException(ServiceBrokerOperationInProgressException ex); @ExceptionHandler(ServiceBrokerCreateOperationInProgressException.class) @ResponseStatus(HttpStatus.ACCEPTED) OperationInProgressMessage handleException(ServiceBrokerCreateOperationInProgressException ex); @ExceptionHandler(ServiceBrokerUpdateOperationInProgressException.class) @ResponseStatus(HttpStatus.ACCEPTED) OperationInProgressMessage handleException(ServiceBrokerUpdateOperationInProgressException ex); @ExceptionHandler(ServiceBrokerDeleteOperationInProgressException.class) @ResponseStatus(HttpStatus.ACCEPTED) OperationInProgressMessage handleException(ServiceBrokerDeleteOperationInProgressException ex); @ExceptionHandler(ServiceBrokerUnavailableException.class) @ResponseStatus(HttpStatus.SERVICE_UNAVAILABLE) ErrorMessage handleException(ServiceBrokerUnavailableException ex); @ExceptionHandler(ServiceBrokerConcurrencyException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) ErrorMessage handleException(ServiceBrokerConcurrencyException ex); @ExceptionHandler(ServiceBrokerException.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) ErrorMessage handleException(ServiceBrokerException ex); @ExceptionHandler(ServiceBrokerInvalidOriginatingIdentityException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) ErrorMessage handleException(ServiceBrokerInvalidOriginatingIdentityException ex); @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) ErrorMessage handleException(Exception ex); @ExceptionHandler(ServiceInstanceExistsException.class) @ResponseStatus(HttpStatus.CONFLICT) ErrorMessage handleException(ServiceInstanceExistsException ex); @ExceptionHandler(ServiceInstanceUpdateNotSupportedException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) ErrorMessage handleException(ServiceInstanceUpdateNotSupportedException ex); @ExceptionHandler(ServiceInstanceBindingExistsException.class) @ResponseStatus(HttpStatus.CONFLICT) ErrorMessage handleException(ServiceInstanceBindingExistsException ex); @ExceptionHandler(ServiceInstanceBindingDoesNotExistException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) ErrorMessage handleException(ServiceInstanceBindingDoesNotExistException ex); @ExceptionHandler(ServiceBrokerBindingRequiresAppException.class) @ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY) ErrorMessage handleException(ServiceBrokerBindingRequiresAppException ex);  }
@Test void serviceInstanceUpdateNotSupportedException() { ServiceInstanceUpdateNotSupportedException exception = new ServiceInstanceUpdateNotSupportedException("test exception"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getMessage()).contains("test exception"); }
@Test void bindingExistsException() { ErrorMessage errorMessage = exceptionHandler .handleException(new ServiceInstanceBindingExistsException("service-instance-id", "binding-id")); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()) .contains("serviceInstanceId=service-instance-id") .contains("bindingId=binding-id"); }
@Test void bindingDoesNotExistException() { ErrorMessage errorMessage = exceptionHandler .handleException(new ServiceInstanceBindingDoesNotExistException("binding-id")); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()) .contains("id=binding-id"); }
@Test void appRequiredException() { ErrorMessage errorMessage = exceptionHandler .handleException(new ServiceBrokerBindingRequiresAppException("app GUID is required")); assertThat(errorMessage.getError()).isEqualTo(APP_REQUIRED_ERROR); assertThat(errorMessage.getMessage()).contains("app GUID is required"); }
@Test void serviceBrokerApiVersionException() { ServiceBrokerApiVersionException exception = new ServiceBrokerApiVersionException("expected-version", "actual-version"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("expected version=expected-version"); assertThat(errorMessage.getMessage()).contains("provided version=actual-version"); }
@Test void serviceInstanceDoesNotExistException() { ServiceInstanceDoesNotExistException exception = new ServiceInstanceDoesNotExistException("service-instance-id"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("id=service-instance-id"); }
@Test void serviceDefinitionDoesNotExistException() { ServiceDefinitionDoesNotExistException exception = new ServiceDefinitionDoesNotExistException("service-definition-id"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("id=service-definition-id"); }
@Test void serviceDefinitionPlanDoesNotExistException() { ServiceDefinitionPlanDoesNotExistException exception = new ServiceDefinitionPlanDoesNotExistException("service-definition-plan-id"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("Service Definition Plan does not exist: " + "id=service-definition-plan-id"); }
@Test void serviceDefinitionPlanDoesNotExistExceptionWithCustomCode() { final String errorCode = "error"; ServiceDefinitionPlanDoesNotExistException exception = new ServiceDefinitionPlanDoesNotExistException(errorCode, "service-definition-plan-id"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isEqualTo(errorCode); assertThat(errorMessage.getMessage()).contains("Service Definition Plan does not exist: " + "id=service-definition-plan-id"); }
@Test void serviceBrokerAsyncRequiredException() { ServiceBrokerAsyncRequiredException exception = new ServiceBrokerAsyncRequiredException("test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isEqualTo(ASYNC_REQUIRED_ERROR); assertThat(errorMessage.getMessage()).contains("test message"); }
@Test void serviceBrokerInvalidParametersException() { ServiceBrokerInvalidParametersException exception = new ServiceBrokerInvalidParametersException("test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("test message"); }
@Test void serviceBrokerInvalidOriginatingIdentityException() { ServiceBrokerInvalidOriginatingIdentityException exception = new ServiceBrokerInvalidOriginatingIdentityException("test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("test message"); }
@Test void operationInProgressException() { ServiceBrokerOperationInProgressException exception = new ServiceBrokerOperationInProgressException("task_10"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("task_10"); }
@Test void serviceBrokerUnavailableException() { ServiceBrokerUnavailableException exception = new ServiceBrokerUnavailableException("maintenance in progress"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("maintenance in progress"); }
@Test void serviceBrokerConcurrencyException() { ServiceBrokerConcurrencyException exception = new ServiceBrokerConcurrencyException("operation in progress"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isEqualTo(CONCURRENCY_ERROR); assertThat(errorMessage.getMessage()).contains("operation in progress"); }
@Test void serviceBrokerException() { ServiceBrokerException exception = new ServiceBrokerException("test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("test message"); }
@Test void serviceBrokerExceptionWithErrorCode() { ServiceBrokerException exception = new ServiceBrokerException("ErrorCode", "test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isEqualTo("ErrorCode"); assertThat(errorMessage.getMessage()).contains("test message"); }
@Test void unknownException() { Exception exception = new Exception("test message"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getError()).isNull(); assertThat(errorMessage.getMessage()).contains("test message"); }
@Test void serviceInstanceExistsException() { ServiceInstanceExistsException exception = new ServiceInstanceExistsException("service-instance-id", "service-definition-id"); ErrorMessage errorMessage = exceptionHandler.handleException(exception); assertThat(errorMessage.getMessage()).contains("serviceInstanceId=service-instance-id"); assertThat(errorMessage.getMessage()).contains("serviceDefinitionId=service-definition-id"); }