Search in sources :

Example 1 with ServiceInstanceExistsException

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

the class ServiceInstanceControllerIntegrationTest method createDuplicateServiceInstanceIdFails.

@Test
void createDuplicateServiceInstanceIdFails() {
    setupCatalogService();
    setupServiceInstanceService(new ServiceInstanceExistsException(SERVICE_INSTANCE_ID, serviceDefinition.getId()));
    client.put().uri(buildCreateUpdateUrl()).contentType(MediaType.APPLICATION_JSON).bodyValue(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())));
}
Also used : ServiceInstanceExistsException(org.springframework.cloud.servicebroker.exception.ServiceInstanceExistsException) AbstractServiceInstanceControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with ServiceInstanceExistsException

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

the class ServiceInstanceControllerIntegrationTest method createDuplicateServiceInstanceIdFails.

@Test
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)));
}
Also used : ServiceInstanceExistsException(org.springframework.cloud.servicebroker.exception.ServiceInstanceExistsException) MvcResult(org.springframework.test.web.servlet.MvcResult) AbstractServiceInstanceControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceInstanceExistsException

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

the class ServiceInstanceControllerResponseCodeTest method serviceInstanceExistsExceptionGivesExpectedStatus.

@Test
public void serviceInstanceExistsExceptionGivesExpectedStatus() {
    ServiceInstanceExistsException exception = new ServiceInstanceExistsException("service-instance-id", "service-definition-id");
    ResponseEntity<ErrorMessage> responseEntity = controller.handleException(exception);
    assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.CONFLICT);
    assertThat(responseEntity.getBody().getMessage()).contains("serviceInstanceId=service-instance-id");
    assertThat(responseEntity.getBody().getMessage()).contains("serviceDefinitionId=service-definition-id");
}
Also used : ServiceInstanceExistsException(org.springframework.cloud.servicebroker.exception.ServiceInstanceExistsException) ErrorMessage(org.springframework.cloud.servicebroker.model.error.ErrorMessage) Test(org.junit.Test)

Example 4 with ServiceInstanceExistsException

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

the class ServiceBrokerExceptionHandlerTest method serviceInstanceExistsException.

@Test
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");
}
Also used : ServiceInstanceExistsException(org.springframework.cloud.servicebroker.exception.ServiceInstanceExistsException) ErrorMessage(org.springframework.cloud.servicebroker.model.error.ErrorMessage) Test(org.junit.jupiter.api.Test)

Aggregations

ServiceInstanceExistsException (org.springframework.cloud.servicebroker.exception.ServiceInstanceExistsException)4 Test (org.junit.jupiter.api.Test)3 AbstractServiceInstanceControllerIntegrationTest (org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest)2 ErrorMessage (org.springframework.cloud.servicebroker.model.error.ErrorMessage)2 Test (org.junit.Test)1 MvcResult (org.springframework.test.web.servlet.MvcResult)1