Search in sources :

Example 1 with ServiceInstanceDoesNotExistException

use of org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceController method deleteServiceInstance.

@DeleteMapping(value = { "/{platformInstanceId}/v2/service_instances/{instanceId}", "/v2/service_instances/{instanceId}" })
public ResponseEntity<DeleteServiceInstanceResponse> deleteServiceInstance(@PathVariable Map<String, String> pathVariables, @PathVariable(INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId, @RequestParam(SERVICE_ID_PARAMETER) String serviceDefinitionId, @RequestParam(PLAN_ID_PARAMETER) String planId, @RequestParam(value = ASYNC_REQUEST_PARAMETER, required = false) boolean acceptsIncomplete, @RequestHeader(value = API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation, @RequestHeader(value = ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString) {
    ServiceDefinition serviceDefinition = getRequiredServiceDefinition(serviceDefinitionId);
    DeleteServiceInstanceRequest request = DeleteServiceInstanceRequest.builder().serviceInstanceId(serviceInstanceId).serviceDefinitionId(serviceDefinitionId).planId(planId).serviceDefinition(serviceDefinition).asyncAccepted(acceptsIncomplete).platformInstanceId(pathVariables.get(PLATFORM_INSTANCE_ID_VARIABLE)).apiInfoLocation(apiInfoLocation).originatingIdentity(parseOriginatingIdentity(originatingIdentityString)).build();
    LOGGER.debug("Deleting a service instance: request={}", request);
    try {
        DeleteServiceInstanceResponse response = service.deleteServiceInstance(request);
        LOGGER.debug("Deleting a service instance succeeded: serviceInstanceId={}, response={}", serviceInstanceId, response);
        return new ResponseEntity<>(response, getAsyncResponseCode(response));
    } catch (ServiceInstanceDoesNotExistException e) {
        LOGGER.debug("Service instance does not exist: ", e);
        return new ResponseEntity<>(DeleteServiceInstanceResponse.builder().build(), HttpStatus.GONE);
    }
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ServiceInstanceDoesNotExistException(org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException) DeleteServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest) ServiceDefinition(org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition) DeleteServiceInstanceResponse(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 2 with ServiceInstanceDoesNotExistException

use of org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException in project spring-cloud-open-service-broker by spring-cloud.

the class BaseControllerTest method serviceInstanceDoesNotExistExceptionGivesExpectedStatus.

@Test
public void serviceInstanceDoesNotExistExceptionGivesExpectedStatus() {
    ServiceInstanceDoesNotExistException exception = new ServiceInstanceDoesNotExistException("service-instance-id");
    ResponseEntity<ErrorMessage> responseEntity = controller.handleException(exception);
    assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY);
    assertThat(responseEntity.getBody().getError()).isNull();
    assertThat(responseEntity.getBody().getMessage()).contains("id=service-instance-id");
}
Also used : ServiceInstanceDoesNotExistException(org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException) ErrorMessage(org.springframework.cloud.servicebroker.model.error.ErrorMessage) Test(org.junit.Test)

Example 3 with ServiceInstanceDoesNotExistException

use of org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceControllerResponseCodeTest method deleteServiceInstanceWithMissingInstanceGivesExpectedStatus.

@Test
public void deleteServiceInstanceWithMissingInstanceGivesExpectedStatus() {
    when(serviceInstanceService.deleteServiceInstance(any(DeleteServiceInstanceRequest.class))).thenThrow(new ServiceInstanceDoesNotExistException("instance does not exist"));
    ResponseEntity<DeleteServiceInstanceResponse> responseEntity = controller.deleteServiceInstance(pathVariables, null, "service-definition-id", null, false, null, null);
    assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.GONE);
    assertThat(responseEntity.getBody()).isEqualTo(DeleteServiceInstanceResponse.builder().build());
}
Also used : ServiceInstanceDoesNotExistException(org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException) DeleteServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest) DeleteServiceInstanceResponse(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse) Test(org.junit.Test)

Example 4 with ServiceInstanceDoesNotExistException

use of org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceBindingControllerResponseCodeTest method getServiceBindingWithMissingServiceInstanceGivesExpectedStatus.

@Test
void getServiceBindingWithMissingServiceInstanceGivesExpectedStatus() {
    given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class))).willThrow(new ServiceInstanceDoesNotExistException("nonexistent-service-id"));
    ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller.getServiceInstanceBinding(pathVariables, "nonexistent-service-id", "nonexistent-binding-id", null, null, null, null, null).block();
    assertThat(responseEntity).isNotNull();
    assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
Also used : ServiceInstanceDoesNotExistException(org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException) GetServiceInstanceBindingRequest(org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingRequest) GetServiceInstanceBindingResponse(org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingResponse) Test(org.junit.jupiter.api.Test)

Example 5 with ServiceInstanceDoesNotExistException

use of org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceControllerIntegrationTest method deleteServiceInstanceWithUnknownIdFails.

@Test
void deleteServiceInstanceWithUnknownIdFails() {
    setupCatalogService();
    setupServiceInstanceService(new ServiceInstanceDoesNotExistException(SERVICE_INSTANCE_ID));
    client.delete().uri(buildDeleteUrl()).accept(MediaType.APPLICATION_JSON).exchange().expectStatus().is4xxClientError().expectStatus().isEqualTo(HttpStatus.GONE);
}
Also used : ServiceInstanceDoesNotExistException(org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException) AbstractServiceInstanceControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceInstanceDoesNotExistException (org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException)13 Test (org.junit.jupiter.api.Test)10 AbstractServiceInstanceBindingControllerIntegrationTest (org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceBindingControllerIntegrationTest)4 AbstractServiceInstanceControllerIntegrationTest (org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 Test (org.junit.Test)2 CreateServiceInstanceBindingRequest (org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest)2 DeleteServiceInstanceBindingRequest (org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingRequest)2 ErrorMessage (org.springframework.cloud.servicebroker.model.error.ErrorMessage)2 DeleteServiceInstanceRequest (org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest)2 DeleteServiceInstanceResponse (org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse)2 GetServiceInstanceBindingRequest (org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingRequest)1 GetServiceInstanceBindingResponse (org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingResponse)1 ServiceDefinition (org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition)1 ResponseEntity (org.springframework.http.ResponseEntity)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1