Search in sources :

Example 1 with CreateServiceInstanceBindingResponse

use of org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceBindingController method createServiceInstanceBinding.

@PutMapping(value = { "/{platformInstanceId}/v2/service_instances/{instanceId}/service_bindings/{bindingId}", "/v2/service_instances/{instanceId}/service_bindings/{bindingId}" })
public ResponseEntity<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(@PathVariable Map<String, String> pathVariables, @PathVariable(INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId, @PathVariable(BINDING_ID_PATH_VARIABLE) String bindingId, @RequestHeader(value = API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation, @RequestHeader(value = ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString, @Valid @RequestBody CreateServiceInstanceBindingRequest request) {
    request.setServiceInstanceId(serviceInstanceId);
    request.setBindingId(bindingId);
    request.setServiceDefinition(getRequiredServiceDefinition(request.getServiceDefinitionId()));
    setCommonRequestFields(request, pathVariables.get(PLATFORM_INSTANCE_ID_VARIABLE), apiInfoLocation, originatingIdentityString);
    LOGGER.debug("Creating a service instance binding: request={}", request);
    CreateServiceInstanceBindingResponse response = serviceInstanceBindingService.createServiceInstanceBinding(request);
    LOGGER.debug("Creating a service instance binding succeeded: serviceInstanceId={}, bindingId={}, response={}", serviceInstanceId, bindingId, response);
    return new ResponseEntity<>(response, getCreateResponseCode(response));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) CreateServiceInstanceBindingResponse(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 2 with CreateServiceInstanceBindingResponse

use of org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceBindingControllerResponseCodeTest method createServiceBindingWithResponseGivesExpectedStatus.

@Theory
public void createServiceBindingWithResponseGivesExpectedStatus(CreateResponseAndExpectedStatus data) {
    when(bindingService.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class))).thenReturn(data.response);
    CreateServiceInstanceBindingRequest createRequest = CreateServiceInstanceBindingRequest.builder().serviceDefinitionId("service-definition-id").build();
    ResponseEntity<CreateServiceInstanceBindingResponse> responseEntity = controller.createServiceInstanceBinding(pathVariables, null, null, null, null, createRequest);
    assertThat(responseEntity.getStatusCode()).isEqualTo(data.expectedStatus);
    assertThat(responseEntity.getBody()).isEqualTo(data.response);
}
Also used : CreateServiceInstanceBindingRequest(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest) CreateServiceInstanceBindingResponse(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse) Theory(org.junit.experimental.theories.Theory)

Example 3 with CreateServiceInstanceBindingResponse

use of org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceBindingControllerResponseCodeTest method createServiceBindingWithExistingBindingResponseGivesExpectedStatus.

@Test
void createServiceBindingWithExistingBindingResponseGivesExpectedStatus() {
    CreateServiceInstanceBindingResponse response = CreateServiceInstanceAppBindingResponse.builder().bindingExisted(true).build();
    validateCreateServiceBindingResponseStatus(response, HttpStatus.OK);
}
Also used : CreateServiceInstanceBindingResponse(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse) Test(org.junit.jupiter.api.Test)

Example 4 with CreateServiceInstanceBindingResponse

use of org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceBindingControllerResponseCodeTest method createServiceBindingWithNoExistingBindingResponseGivesExpectedStatus.

@Test
void createServiceBindingWithNoExistingBindingResponseGivesExpectedStatus() {
    CreateServiceInstanceBindingResponse response = CreateServiceInstanceAppBindingResponse.builder().bindingExisted(false).build();
    validateCreateServiceBindingResponseStatus(response, HttpStatus.CREATED);
}
Also used : CreateServiceInstanceBindingResponse(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse) Test(org.junit.jupiter.api.Test)

Example 5 with CreateServiceInstanceBindingResponse

use of org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse in project spring-cloud-open-service-broker by spring-cloud.

the class ServiceInstanceBindingControllerResponseCodeTest method validateCreateServiceBindingResponseStatus.

private void validateCreateServiceBindingResponseStatus(CreateServiceInstanceBindingResponse response, HttpStatus httpStatus) {
    Mono<CreateServiceInstanceBindingResponse> responseMono;
    if (response == null) {
        responseMono = Mono.empty();
    } else {
        responseMono = Mono.just(response);
    }
    given(bindingService.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class))).willReturn(responseMono);
    CreateServiceInstanceBindingRequest createRequest = CreateServiceInstanceBindingRequest.builder().serviceDefinitionId("service-definition-id").planId("service-definition-plan-id").build();
    ResponseEntity<CreateServiceInstanceBindingResponse> responseEntity = controller.createServiceInstanceBinding(pathVariables, null, null, false, null, null, null, createRequest).block();
    assertThat(responseEntity).isNotNull();
    assertThat(responseEntity.getStatusCode()).isEqualTo(httpStatus);
    assertThat(responseEntity.getBody()).isEqualTo(response);
}
Also used : CreateServiceInstanceBindingRequest(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest) CreateServiceInstanceBindingResponse(org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse)

Aggregations

CreateServiceInstanceBindingResponse (org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingResponse)6 Test (org.junit.jupiter.api.Test)2 CreateServiceInstanceBindingRequest (org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceBindingRequest)2 Theory (org.junit.experimental.theories.Theory)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1