@Test public 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"); }
@Test public void createDuplicateServiceInstanceIdFails() { setupCatalogService(); setupServiceInstanceService(new ServiceInstanceExistsException(SERVICE_INSTANCE_ID, serviceDefinition.getId())); client.put().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().is4xxClientError() .expectStatus().isEqualTo(HttpStatus.CONFLICT) .expectBody() .jsonPath("$.description").isNotEmpty() .consumeWith(result -> assertDescriptionContains(result, String.format("serviceInstanceId=%s, serviceDefinitionId=%s", SERVICE_INSTANCE_ID, serviceDefinition.getId()))); }
@Test public void createDuplicateServiceInstanceIdFails() throws Exception { setupCatalogService(); setupServiceInstanceService(new ServiceInstanceExistsException(SERVICE_INSTANCE_ID, serviceDefinition.getId())); MvcResult mvcResult = mockMvc.perform(put(buildCreateUpdateUrl()) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isConflict()) .andExpect(jsonPath("$.description", containsString(SERVICE_INSTANCE_ID))); }