Search in sources :

Example 1 with CreateServiceInstanceResponse

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

the class ServiceInstanceControllerResponseCodeTest method createServiceInstanceWithResponseGivesExpectedStatus.

@Theory
public void createServiceInstanceWithResponseGivesExpectedStatus(CreateResponseAndExpectedStatus data) {
    when(serviceInstanceService.createServiceInstance(any(CreateServiceInstanceRequest.class))).thenReturn(data.response);
    CreateServiceInstanceRequest createRequest = CreateServiceInstanceRequest.builder().serviceDefinitionId("service-definition-id").build();
    ResponseEntity<CreateServiceInstanceResponse> responseEntity = controller.createServiceInstance(pathVariables, null, false, null, null, createRequest);
    assertThat(responseEntity.getStatusCode()).isEqualTo(data.expectedStatus);
    assertThat(responseEntity.getBody()).isEqualTo(data.response);
}
Also used : CreateServiceInstanceResponse(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse) CreateServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest) Theory(org.junit.experimental.theories.Theory)

Example 2 with CreateServiceInstanceResponse

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

the class ServiceInstanceController method createServiceInstance.

@PutMapping(value = { "/{platformInstanceId}/v2/service_instances/{instanceId}", "/v2/service_instances/{instanceId}" })
public ResponseEntity<CreateServiceInstanceResponse> createServiceInstance(@PathVariable Map<String, String> pathVariables, @PathVariable(INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId, @RequestParam(value = ASYNC_REQUEST_PARAMETER, required = false) boolean acceptsIncomplete, @RequestHeader(value = API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation, @RequestHeader(value = ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString, @Valid @RequestBody CreateServiceInstanceRequest request) {
    ServiceDefinition serviceDefinition = getRequiredServiceDefinition(request.getServiceDefinitionId());
    request.setServiceInstanceId(serviceInstanceId);
    request.setServiceDefinition(serviceDefinition);
    setCommonRequestFields(request, pathVariables.get(PLATFORM_INSTANCE_ID_VARIABLE), apiInfoLocation, originatingIdentityString, acceptsIncomplete);
    LOGGER.debug("Creating a service instance: request={}", request);
    CreateServiceInstanceResponse response = service.createServiceInstance(request);
    LOGGER.debug("Creating a service instance succeeded: serviceInstanceId={}, response={}", serviceInstanceId, response);
    return new ResponseEntity<>(response, getCreateResponseCode(response));
}
Also used : CreateServiceInstanceResponse(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse) ResponseEntity(org.springframework.http.ResponseEntity) ServiceDefinition(org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 3 with CreateServiceInstanceResponse

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

the class ServiceInstanceControllerResponseCodeTest method validateCreateServiceInstanceWithResponseStatus.

private void validateCreateServiceInstanceWithResponseStatus(CreateServiceInstanceResponse response, HttpStatus expectedStatus) {
    Mono<CreateServiceInstanceResponse> responseMono;
    if (response == null) {
        responseMono = Mono.empty();
    } else {
        responseMono = Mono.just(response);
    }
    given(serviceInstanceService.createServiceInstance(any(CreateServiceInstanceRequest.class))).willReturn(responseMono);
    CreateServiceInstanceRequest createRequest = CreateServiceInstanceRequest.builder().serviceDefinitionId("service-definition-id").planId("service-definition-plan-id").build();
    ResponseEntity<CreateServiceInstanceResponse> responseEntity = controller.createServiceInstance(pathVariables, null, false, null, null, null, createRequest).block();
    then(serviceInstanceService).should().createServiceInstance(any(CreateServiceInstanceRequest.class));
    assertThat(responseEntity).isNotNull();
    assertThat(responseEntity.getStatusCode()).isEqualTo(expectedStatus);
    assertThat(responseEntity.getBody()).isEqualTo(response);
}
Also used : CreateServiceInstanceResponse(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse) CreateServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest)

Aggregations

CreateServiceInstanceResponse (org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse)3 CreateServiceInstanceRequest (org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest)2 Theory (org.junit.experimental.theories.Theory)1 ServiceDefinition (org.springframework.cloud.servicebroker.model.catalog.ServiceDefinition)1 ResponseEntity (org.springframework.http.ResponseEntity)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1