@Test public void responseWithAllValuesIsBuilt() { CreateServiceInstanceResponse response = CreateServiceInstanceResponse.builder() .async(true) .operation("in progress") .instanceExisted(true) .dashboardUrl("http://dashboard.example.com") .build(); assertThat(response.isAsync()).isEqualTo(true); assertThat(response.getOperation()).isEqualTo("in progress"); assertThat(response.isInstanceExisted()).isEqualTo(true); assertThat(response.getDashboardUrl()).isEqualTo("http://dashboard.example.com"); DocumentContext json = JsonUtils.toJsonPath(response); assertThat(json).hasPath("$.operation").isEqualTo("in progress"); assertThat(json).hasPath("$.dashboard_url").isEqualTo("http://dashboard.example.com"); }
new CreateResponseAndExpectedStatus( CreateServiceInstanceResponse.builder() .async(false) .instanceExisted(false) .dashboardUrl("https://dashboard.example.com") .build(), HttpStatus.CREATED ), new CreateResponseAndExpectedStatus( CreateServiceInstanceResponse.builder() .async(false) .instanceExisted(true) .build(), HttpStatus.OK ), new CreateResponseAndExpectedStatus( CreateServiceInstanceResponse.builder() .async(true) .instanceExisted(false) .operation("creating") .build(), HttpStatus.ACCEPTED ), new CreateResponseAndExpectedStatus( CreateServiceInstanceResponse.builder() .async(true) .instanceExisted(true) .build(), HttpStatus.ACCEPTED
@Test public void createServiceInstanceFiltersPlansSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse .builder() .build()); MvcResult mvcResult = mockMvc .perform(put(buildCreateUpdateUrl()) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isCreated()); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId()); assertHeaderValuesNotSet(actualRequest); }
@Test public void createServiceInstanceWithEmptyPlatformInstanceIdSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .async(true) .build()); // force a condition where the platformInstanceId segment is present but empty // e.g. http://test.example.com//v2/service_instances/[guid] String url = "http://test.example.com/" + buildCreateUpdateUrl(); MvcResult mvcResult = mockMvc.perform(put(url) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertHeaderValuesNotSet(actualRequest); }
@Test public void createServiceInstanceWithEmptyPlatformInstanceIdSucceeds() { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .async(true) .build()); // force a condition where the platformInstanceId segment is present but empty // e.g. http://test.example.com//v2/service_instances/[guid] String url = "http://test.example.com/" + buildCreateUpdateUrl(); client.put().uri(url) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isAccepted(); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertHeaderValuesNotSet(actualRequest); }
@Test public void createServiceInstanceResponseShouldNotContainEmptyValuesWhenNull() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .operation(null) .dashboardUrl(null) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUpdateUrl()) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isCreated()) .andExpect(jsonPath("$.dashboard_url").doesNotExist()) .andExpect(jsonPath("$.operation").doesNotExist()); }
@Test public void createServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .async(true) .build()); client.put().uri(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, true)) .contentType(MediaType.APPLICATION_JSON) .syncBody(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); }
@Test public void createServiceInstanceWithoutAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUpdateUrl()) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isCreated()); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertHeaderValuesNotSet(actualRequest); }
@Test public void createServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .async(true) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, true)) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void createServiceInstanceResponseShouldNotContainEmptyValuesWhenEmpty() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .operation("") .dashboardUrl("") .build()); client.put().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isCreated() .expectBody() .jsonPath("$.dashboard_url").doesNotExist() .jsonPath("$.operation").doesNotExist(); }
@Test public void createServiceInstanceResponseShouldNotContainEmptyValuesWhenNull() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .operation(null) .dashboardUrl(null) .build()); client.put().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isCreated() .expectBody() .jsonPath("$.dashboard_url").doesNotExist() .jsonPath("$.operation").doesNotExist(); }
@Test public void createServiceInstanceResponseShouldNotContainEmptyValuesWhenEmpty() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .operation("") .dashboardUrl("") .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUpdateUrl()) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isCreated()) .andExpect(jsonPath("$.dashboard_url").doesNotExist()) .andExpect(jsonPath("$.operation").doesNotExist()); }
@Test public void createServiceInstanceFiltersPlanSucceeds() { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse .builder() .build()); client.put().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isCreated(); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertThat(actualRequest.getPlan().getId()).isEqualTo("plan-one-id"); assertHeaderValuesNotSet(actualRequest); }
@Test public void createServiceInstanceWithoutAsyncAndHeadersSucceeds() { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .build()); client.put().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isCreated(); CreateServiceInstanceRequest actualRequest = verifyCreateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertHeaderValuesNotSet(actualRequest); }
@Test public void createServiceInstanceSucceeds() { prepareCreateEventFlows(); StepVerifier .create(serviceInstanceEventService.createServiceInstance( CreateServiceInstanceRequest.builder() .serviceInstanceId("foo") .serviceDefinitionId("bar") .build())) .expectNext(CreateServiceInstanceResponse.builder().build()) .verifyComplete(); assertThat(this.results.getBeforeCreate()).isEqualTo("before foo"); assertThat(this.results.getAfterCreate()).isEqualTo("after foo"); assertThat(this.results.getErrorCreate()).isNullOrEmpty(); }
@Override public Mono<CreateServiceInstanceResponse> createServiceInstance(CreateServiceInstanceRequest request) { String serviceInstanceId = request.getServiceInstanceId(); String planId = request.getPlanId(); Map<String, Object> parameters = request.getParameters(); // // perform the steps necessary to initiate the asynchronous // provisioning of all necessary resources // String dashboardUrl = new String(/* construct a dashboard URL */); CreateServiceInstanceResponse response = CreateServiceInstanceResponse.builder() .dashboardUrl(dashboardUrl) .async(true) .build(); return Mono.just(response); }
@Test public void createServiceInstanceWithExistingInstanceSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .instanceExisted(true) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUpdateUrl()) .content(createRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()); }
@Test public void createServiceInstanceWithExistingInstanceSucceeds() { setupCatalogService(); setupServiceInstanceService(CreateServiceInstanceResponse.builder() .instanceExisted(true) .build()); client.put().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk(); }
@Test public void responseWithDefaultsIsBuilt() { CreateServiceInstanceResponse response = CreateServiceInstanceResponse.builder() .build(); assertThat(response.isAsync()).isEqualTo(false); assertThat(response.getOperation()).isNull(); assertThat(response.isInstanceExisted()).isEqualTo(false); assertThat(response.getDashboardUrl()).isNull(); DocumentContext json = JsonUtils.toJsonPath(response); assertThat(json).hasNoPath("$.operation"); assertThat(json).hasNoPath("$.dashboard_url"); }
/** * Create a builder that provides a fluent API for constructing a {@literal CreateServiceInstanceResponse}. * * @return the builder */ public static CreateServiceInstanceResponseBuilder builder() { return new CreateServiceInstanceResponseBuilder(); }