} catch (ServiceInstanceDoesNotExistException e) { logger.debug("Service instance does not exist: ", e); return new ResponseEntity<>(DeleteServiceInstanceResponse.builder().build(), HttpStatus.GONE);
@Test public void responseWithAllValuesIsBuilt() { DeleteServiceInstanceResponse response = DeleteServiceInstanceResponse.builder() .async(true) .operation("in progress") .build(); assertThat(response.isAsync()).isEqualTo(true); assertThat(response.getOperation()).isEqualTo("in progress"); }
@Test public void responseWithDefaultsIsBuilt() { DeleteServiceInstanceResponse response = DeleteServiceInstanceResponse.builder() .build(); assertThat(response.isAsync()).isEqualTo(false); assertThat(response.getOperation()).isNull(); }
@DataPoints("deleteResponsesWithExpectedStatus") public static List<DeleteResponseAndExpectedStatus> deleteDataPoints() { return Arrays.asList( new DeleteResponseAndExpectedStatus( null, HttpStatus.OK ), new DeleteResponseAndExpectedStatus( DeleteServiceInstanceResponse.builder() .async(false) .build(), HttpStatus.OK ), new DeleteResponseAndExpectedStatus( DeleteServiceInstanceResponse.builder() .async(true) .operation("deleting") .build(), HttpStatus.ACCEPTED ) ); }
@Test public void deleteServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(DeleteServiceInstanceResponse.builder() .async(true) .operation("working") .build()); MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, true)) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()) .andExpect(jsonPath("$.operation", equalTo("working"))); DeleteServiceInstanceRequest actualRequest = verifyDeleteServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void deleteServiceInstanceFiltersPlansSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(DeleteServiceInstanceResponse .builder() .build()); MvcResult mvcResult = mockMvc .perform(delete(buildDeleteUrl()) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().string("{}")); DeleteServiceInstanceRequest actualRequest = verifyDeleteServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId()); assertHeaderValuesNotSet(actualRequest); }
@Test public 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); }
@Test public void deleteServiceInstanceFiltersPlansSucceeds() { 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); assertThat(actualRequest.getPlan().getId()).isEqualTo("plan-three-id"); assertHeaderValuesNotSet(actualRequest); }
@Test public void deleteServiceInstanceWithoutAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(DeleteServiceInstanceResponse.builder() .build()); MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl()) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().string("{}")); DeleteServiceInstanceRequest actualRequest = verifyDeleteServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertHeaderValuesNotSet(actualRequest); }
@Test public void deleteServiceInstanceSucceeds() { prepareDeleteEventFlows(); StepVerifier .create(serviceInstanceEventService.deleteServiceInstance( DeleteServiceInstanceRequest.builder() .serviceInstanceId("foo") .serviceDefinitionId("bar") .build())) .expectNext(DeleteServiceInstanceResponse.builder().build()) .verifyComplete(); assertThat(this.results.getBeforeDelete()).isEqualTo("before foo"); assertThat(this.results.getAfterDelete()).isEqualTo("after foo"); assertThat(this.results.getErrorDelete()).isNullOrEmpty(); }
@Test public 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); }
@Override public Mono<DeleteServiceInstanceResponse> deleteServiceInstance(DeleteServiceInstanceRequest request) { String serviceInstanceId = request.getServiceInstanceId(); String planId = request.getPlanId(); // // perform the steps necessary to initiate the asynchronous // deletion of all provisioned resources // DeleteServiceInstanceResponse response = DeleteServiceInstanceResponse.builder() .async(true) .build(); return Mono.just(response); }
@Override public Mono<DeleteServiceInstanceResponse> deleteServiceInstance( DeleteServiceInstanceRequest request) { if (request.getServiceDefinitionId() == null) { return Mono.error(new ServiceInstanceDoesNotExistException("foo")); } return Mono.just(DeleteServiceInstanceResponse.builder().build()); }