Search in sources :

Example 1 with ServiceInstanceBindingExistsException

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

the class ServiceInstanceBindingControllerIntegrationTest method createBindingWithDuplicateIdFails.

@Test
void createBindingWithDuplicateIdFails() {
    setupCatalogService();
    given(serviceInstanceBindingService.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class))).willThrow(new ServiceInstanceBindingExistsException(SERVICE_INSTANCE_ID, SERVICE_INSTANCE_BINDING_ID));
    client.put().uri(buildCreateUrl()).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, bindingId=%s", SERVICE_INSTANCE_ID, SERVICE_INSTANCE_BINDING_ID)));
}
Also used : CreateServiceInstanceBindingRequest(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest) ServiceInstanceBindingExistsException(org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingExistsException) AbstractServiceInstanceBindingControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceBindingControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 2 with ServiceInstanceBindingExistsException

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

the class ServiceInstanceBindingControllerIntegrationTest method createBindingWithDuplicateIdFails.

@Test
void createBindingWithDuplicateIdFails() throws Exception {
    setupCatalogService();
    given(serviceInstanceBindingService.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class))).willThrow(new ServiceInstanceBindingExistsException(SERVICE_INSTANCE_ID, SERVICE_INSTANCE_BINDING_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().isConflict()).andExpect(jsonPath("$.description", containsString(SERVICE_INSTANCE_ID))).andExpect(jsonPath("$.description", containsString(SERVICE_INSTANCE_BINDING_ID)));
}
Also used : CreateServiceInstanceBindingRequest(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest) ServiceInstanceBindingExistsException(org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingExistsException) MvcResult(org.springframework.test.web.servlet.MvcResult) AbstractServiceInstanceBindingControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceBindingControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 3 with ServiceInstanceBindingExistsException

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

the class ServiceInstanceBindingControllerResponseCodeTest method bindingExistsGivesExpectedStatus.

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

Example 4 with ServiceInstanceBindingExistsException

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

the class ServiceBrokerExceptionHandlerTest method bindingExistsException.

@Test
void bindingExistsException() {
    ErrorMessage errorMessage = exceptionHandler.handleException(new ServiceInstanceBindingExistsException("service-instance-id", "binding-id"));
    assertThat(errorMessage.getError()).isNull();
    assertThat(errorMessage.getMessage()).contains("serviceInstanceId=service-instance-id").contains("bindingId=binding-id");
}
Also used : ServiceInstanceBindingExistsException(org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingExistsException) ErrorMessage(org.springframework.cloud.servicebroker.model.error.ErrorMessage) Test(org.junit.jupiter.api.Test)

Aggregations

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