Search in sources :

Example 1 with CreateServiceInstanceRequest

use of org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest 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 CreateServiceInstanceRequest

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

the class ServiceInstanceControllerRequestTest method createServiceInstanceWithInvalidServiceDefinitionIdThrowsException.

@Test
void createServiceInstanceWithInvalidServiceDefinitionIdThrowsException() {
    CreateServiceInstanceRequest createRequest = CreateServiceInstanceRequest.builder().serviceDefinitionId("unknown-service-definition-id").build();
    ServiceInstanceController controller = createControllerUnderTest();
    assertThrows(ServiceDefinitionDoesNotExistException.class, () -> controller.createServiceInstance(pathVariables, null, false, null, null, null, createRequest).block());
}
Also used : CreateServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest) Test(org.junit.jupiter.api.Test)

Example 3 with CreateServiceInstanceRequest

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

the class ServiceInstanceControllerIntegrationTest method createServiceInstanceWithoutAsyncAndHeadersSucceeds.

@Test
void createServiceInstanceWithoutAsyncAndHeadersSucceeds() {
    setupCatalogService();
    setupServiceInstanceService(CreateServiceInstanceResponse.builder().build());
    client.put().uri(buildCreateUpdateUrl()).contentType(MediaType.APPLICATION_JSON).bodyValue(createRequestBody).accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isCreated();
    CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance();
    assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
    assertHeaderValuesNotSet(actualRequest);
}
Also used : CreateServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest) AbstractServiceInstanceControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 4 with CreateServiceInstanceRequest

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

the class ServiceInstanceControllerIntegrationTest method createServiceInstanceWithAsyncOperationAndHeadersSucceeds.

@Test
void createServiceInstanceWithAsyncOperationAndHeadersSucceeds() throws Exception {
    setupCatalogService();
    // alternatively throw a ServiceBrokerCreateOperationInProgressException when a request is received for
    // an operation in progress. See test: createServiceInstanceWithAsyncAndHeadersOperationInProgress
    setupServiceInstanceService(CreateServiceInstanceResponse.builder().async(true).operation("task_10").dashboardUrl("https://dashboard.app.local").build());
    client.put().uri(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, true)).contentType(MediaType.APPLICATION_JSON).bodyValue(createRequestBody).header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION).header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()).accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isAccepted().expectBody().jsonPath("$.operation").isEqualTo("task_10").jsonPath("$.dashboard_url").isEqualTo("https://dashboard.app.local");
    CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance();
    assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true);
    assertHeaderValuesSet(actualRequest);
}
Also used : CreateServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest) AbstractServiceInstanceControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 5 with CreateServiceInstanceRequest

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

the class ServiceInstanceControllerIntegrationTest method createServiceInstanceWithAsyncAndHeadersSucceeds.

@Test
void createServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception {
    setupCatalogService();
    setupServiceInstanceService(CreateServiceInstanceResponse.builder().async(true).build());
    client.put().uri(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, true)).contentType(MediaType.APPLICATION_JSON).bodyValue(createRequestBody).header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION).header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()).accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isAccepted();
    CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance();
    assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true);
    assertHeaderValuesSet(actualRequest);
}
Also used : CreateServiceInstanceRequest(org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest) AbstractServiceInstanceControllerIntegrationTest(org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

CreateServiceInstanceRequest (org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceRequest)17 Test (org.junit.jupiter.api.Test)15 AbstractServiceInstanceControllerIntegrationTest (org.springframework.cloud.servicebroker.autoconfigure.web.AbstractServiceInstanceControllerIntegrationTest)12 MvcResult (org.springframework.test.web.servlet.MvcResult)6 StringContains.containsString (org.hamcrest.core.StringContains.containsString)2 ServiceBrokerCreateOperationInProgressException (org.springframework.cloud.servicebroker.exception.ServiceBrokerCreateOperationInProgressException)2 CreateServiceInstanceResponse (org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse)2 Theory (org.junit.experimental.theories.Theory)1