Search in sources :

Example 1 with DeleteServiceInstanceRequest

use of org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest 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 DeleteServiceInstanceRequest

use of org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceControllerRequestTest method deleteServiceInstanceParametersAreMappedToRequest.

@Test
void deleteServiceInstanceParametersAreMappedToRequest() {
    DeleteServiceInstanceRequest expectedRequest = DeleteServiceInstanceRequest.builder().asyncAccepted(true).serviceInstanceId("service-instance-id").serviceDefinitionId("service-definition-id").planId("plan-id").platformInstanceId("platform-instance-id").apiInfoLocation("api-info-location").originatingIdentity(identityContext).requestIdentity("request-id").serviceDefinition(serviceDefinition).plan(plan).build();
    ServiceInstanceController controller = createControllerUnderTest(expectedRequest);
    controller.deleteServiceInstance(pathVariables, "service-instance-id", "service-definition-id", "plan-id", true, "api-info-location", encodeOriginatingIdentity(identityContext), "request-id").block();
}
Also used : DeleteServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest) Test(org.junit.jupiter.api.Test)

Example 3 with DeleteServiceInstanceRequest

use of org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceControllerRequestTest method deleteServiceInstanceWithInvalidServiceDefinitionIdThrowsException.

@Test
void deleteServiceInstanceWithInvalidServiceDefinitionIdThrowsException() {
    DeleteServiceInstanceRequest expectedRequest = DeleteServiceInstanceRequest.builder().asyncAccepted(true).serviceDefinitionId("service-definition-id").planId("plan-id").build();
    ServiceInstanceController controller = createControllerUnderTest(expectedRequest);
    assertThrows(ServiceDefinitionDoesNotExistException.class, () -> controller.deleteServiceInstance(pathVariables, null, "unknown-service-definition-id", null, true, null, encodeOriginatingIdentity(identityContext), "request-id").block());
}
Also used : DeleteServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest) Test(org.junit.jupiter.api.Test)

Example 4 with DeleteServiceInstanceRequest

use of org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceControllerIntegrationTest method deleteServiceInstanceWithAsyncAndHeadersSucceeds.

@Test
void deleteServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception {
    setupCatalogService();
    setupServiceInstanceService(DeleteServiceInstanceResponse.builder().async(true).operation("working").build());
    client.delete().uri(buildDeleteUrl(PLATFORM_INSTANCE_ID, true)).header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION).header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()).accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isAccepted().expectBody().jsonPath("$.operation").isEqualTo("working");
    DeleteServiceInstanceRequest actualRequest = verifyDeleteServiceInstance();
    assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true);
    assertHeaderValuesSet(actualRequest);
}
Also used : DeleteServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest) AbstractServiceInstanceControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with DeleteServiceInstanceRequest

use of org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceControllerIntegrationTest method deleteServiceInstanceWithoutAsyncAndHeadersSucceeds.

@Test
void deleteServiceInstanceWithoutAsyncAndHeadersSucceeds() {
    setupCatalogService();
    setupServiceInstanceService(DeleteServiceInstanceResponse.builder().build());
    client.delete().uri(buildDeleteUrl()).accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk().expectBody().json("{}");
    DeleteServiceInstanceRequest actualRequest = verifyDeleteServiceInstance();
    assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
    assertHeaderValuesNotSet(actualRequest);
}
Also used : DeleteServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest) AbstractServiceInstanceControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

DeleteServiceInstanceRequest (org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceRequest)10 Test (org.junit.jupiter.api.Test)9 AbstractServiceInstanceControllerIntegrationTest (org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest)6 MvcResult (org.springframework.test.web.servlet.MvcResult)3 ServiceInstanceDoesNotExistException (org.springframework.cloud.servicebroker.exception.ServiceInstanceDoesNotExistException)1 ServiceDefinition (org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition)1 DeleteServiceInstanceResponse (org.springframework.cloud.servicebroker.model.instance.DeleteServiceInstanceResponse)1 ResponseEntity (org.springframework.http.ResponseEntity)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1