@Test public void deleteServiceInstanceWithMissingInstanceGivesExpectedStatus() { when(serviceInstanceService.deleteServiceInstance(any(DeleteServiceInstanceRequest.class))) .thenReturn(Mono.error(new ServiceInstanceDoesNotExistException("instance does not exist"))); ResponseEntity<DeleteServiceInstanceResponse> responseEntity = controller .deleteServiceInstance(pathVariables, null, "service-definition-id", null, false, null, null) .block(); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.GONE); }
@Override public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) { if (request.getBindingId() == null) { return Mono.error(new ServiceInstanceDoesNotExistException("foo")); } return Mono.just(GetServiceInstanceAppBindingResponse.builder().build()); }
@Override public Mono<DeleteServiceInstanceResponse> deleteServiceInstance( DeleteServiceInstanceRequest request) { if (request.getServiceDefinitionId() == null) { return Mono.error(new ServiceInstanceDoesNotExistException("foo")); } return Mono.just(DeleteServiceInstanceResponse.builder().build()); }
@Test public 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 public void deleteBindingWithUnknownInstanceIdFails() throws Exception { setupCatalogService(); doThrow(new ServiceInstanceDoesNotExistException(SERVICE_INSTANCE_ID)) .when(serviceInstanceBindingService).deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class)); client.delete().uri(buildDeleteUrl()) .exchange() .expectStatus().is4xxClientError() .expectStatus().isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY) .expectBody() .jsonPath("$.description").isNotEmpty() .consumeWith(result -> assertDescriptionContains(result, SERVICE_INSTANCE_ID)); }
@Test public void createBindingWithUnknownServiceInstanceIdFails() throws Exception { setupCatalogService(); when(serviceInstanceBindingService.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class))) .thenThrow(new ServiceInstanceDoesNotExistException(SERVICE_INSTANCE_ID)); client.put().uri(buildCreateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().is4xxClientError() .expectStatus().isEqualTo(HttpStatus.UNPROCESSABLE_ENTITY) .expectBody() .jsonPath("$.description").isNotEmpty() .consumeWith(result -> assertDescriptionContains(result, String.format("id=%s", SERVICE_INSTANCE_ID))); }
@Test public void deleteBindingWithUnknownInstanceIdFails() throws Exception { setupCatalogService(); doThrow(new ServiceInstanceDoesNotExistException(SERVICE_INSTANCE_ID)) .when(serviceInstanceBindingService).deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class)); MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl()) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isUnprocessableEntity()) .andExpect(jsonPath("$.description", containsString(SERVICE_INSTANCE_ID))); }
@Test public void createBindingWithUnknownServiceInstanceIdFails() throws Exception { setupCatalogService(); when(serviceInstanceBindingService.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class))) .thenThrow(new ServiceInstanceDoesNotExistException(SERVICE_INSTANCE_ID)); MvcResult mvcResult = mockMvc.perform(put(buildCreateUrl()) .content(createRequestBody) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isUnprocessableEntity()) .andExpect(jsonPath("$.description", containsString(SERVICE_INSTANCE_ID))); }
@Test public void deleteServiceInstanceWithUnknownIdFails() { setupCatalogService(); setupServiceInstanceService(new ServiceInstanceDoesNotExistException(SERVICE_INSTANCE_ID)); client.delete().uri(buildDeleteUrl()) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().is4xxClientError() .expectStatus().isEqualTo(HttpStatus.GONE); }
@Test public void deleteServiceInstanceWithUnknownIdFails() throws Exception { setupCatalogService(); setupServiceInstanceService(new ServiceInstanceDoesNotExistException(SERVICE_INSTANCE_ID)); MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl()) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isGone()); }