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);
}
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));
}
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);
}
Aggregations