@Override public Mono<UpdateServiceInstanceResponse> updateServiceInstance( UpdateServiceInstanceRequest request) { if (request.getServiceDefinitionId() == null) { return Mono.error(new ServiceBrokerInvalidParametersException("arrrr")); } return Mono.just(UpdateServiceInstanceResponse.builder().build()); }
@Test public void responseWithDefaultsIsBuilt() { UpdateServiceInstanceResponse response = UpdateServiceInstanceResponse.builder() .build(); assertThat(response.isAsync()).isEqualTo(false); assertThat(response.getOperation()).isNull(); DocumentContext json = JsonUtils.toJsonPath(response); assertThat(json).hasNoPath("$.operation"); }
@Test public void responseWithAllValuesIsBuilt() { UpdateServiceInstanceResponse response = UpdateServiceInstanceResponse.builder() .async(true) .dashboardUrl("https://dashboard.example.com") .operation("in progress") .build(); assertThat(response.isAsync()).isEqualTo(true); assertThat(response.getOperation()).isEqualTo("in progress"); DocumentContext json = JsonUtils.toJsonPath(response); assertThat(json).hasPath("$.operation").isEqualTo("in progress"); assertThat(json).hasPath("$.dashboard_url").isEqualTo("https://dashboard.example.com"); }
@DataPoints("updateResponsesWithExpectedStatus") public static List<UpdateResponseAndExpectedStatus> updateDataPoints() { return Arrays.asList( new UpdateResponseAndExpectedStatus( null, HttpStatus.OK ), new UpdateResponseAndExpectedStatus( UpdateServiceInstanceResponse.builder() .async(false) .build(), HttpStatus.OK ), new UpdateResponseAndExpectedStatus( UpdateServiceInstanceResponse.builder() .async(true) .operation("updating") .build(), HttpStatus.ACCEPTED ) ); }
@Test public void updateServiceInstanceSucceeds() { prepareUpdateEventFlows(); StepVerifier .create(serviceInstanceEventService.updateServiceInstance( UpdateServiceInstanceRequest.builder() .serviceInstanceId("foo") .serviceDefinitionId("bar") .build())) .expectNext(UpdateServiceInstanceResponse.builder().build()) .verifyComplete(); assertThat(this.results.getBeforeUpdate()).isEqualTo("before foo"); assertThat(this.results.getAfterUpdate()).isEqualTo("after foo"); assertThat(this.results.getErrorUpdate()).isNullOrEmpty(); }
@Override public Mono<UpdateServiceInstanceResponse> updateServiceInstance(UpdateServiceInstanceRequest request) { String serviceInstanceId = request.getServiceInstanceId(); String planId = request.getPlanId(); String previousPlan = request.getPreviousValues().getPlanId(); Map<String, Object> parameters = request.getParameters(); // // perform the steps necessary to initiate the asynchronous // updating of all necessary resources // UpdateServiceInstanceResponse response = UpdateServiceInstanceResponse.builder() .async(true) .build(); return Mono.just(response); }
@Test public void updateServiceInstanceFiltersPlansSucceeds() { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .build()); client.patch().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(updateRequestBodyWithPlan) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() .expectBody() .json("{}"); UpdateServiceInstanceRequest actualRequest = verifyUpdateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertThat(actualRequest.getPlan().getId()).isEqualTo("plan-three-id"); assertHeaderValuesNotSet(actualRequest); }
@Test public void updateServiceInstanceWithoutSyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .build()); MvcResult mvcResult = mockMvc.perform(patch(buildCreateUpdateUrl()) .content(updateRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().string("{}")); UpdateServiceInstanceRequest actualRequest = verifyUpdateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertThat(actualRequest.getServiceDefinition().getPlans().size()).isEqualTo(3); assertThat(actualRequest.getPlan()).isNull(); assertHeaderValuesNotSet(actualRequest); }
@Test public void updateServiceInstanceWithoutAsyncAndHeadersSucceeds() { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .build()); client.patch().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(updateRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() .expectBody() .json("{}"); UpdateServiceInstanceRequest actualRequest = verifyUpdateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertThat(actualRequest.getPlan()).isNull(); assertHeaderValuesNotSet(actualRequest); }
@Test public void updateServiceInstanceFiltersPlansSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse .builder() .build()); MvcResult mvcResult = mockMvc .perform(patch(buildCreateUpdateUrl()) .content(updateRequestBodyWithPlan) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()) .andExpect(content().string("{}")); UpdateServiceInstanceRequest actualRequest = verifyUpdateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId()); assertHeaderValuesNotSet(actualRequest); }
@Test public void updateServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .async(true) .operation("working") .dashboardUrl("https://dashboard.example.com") .build()); MvcResult mvcResult = mockMvc.perform(patch(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, true)) .content(updateRequestBody) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()) .andExpect(jsonPath("$.operation", equalTo("working"))) .andExpect(jsonPath("$.dashboard_url", equalTo("https://dashboard.example.com"))); UpdateServiceInstanceRequest actualRequest = verifyUpdateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void updateServiceInstanceWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .async(true) .operation("working") .dashboardUrl("https://dashboard.example.com") .build()); client.patch().uri(buildCreateUpdateUrl(PLATFORM_INSTANCE_ID, true)) .contentType(MediaType.APPLICATION_JSON) .syncBody(updateRequestBody) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isAccepted() .expectBody() .jsonPath("$.operation").isEqualTo("working") .jsonPath("$.dashboard_url").isEqualTo("https://dashboard.example.com"); UpdateServiceInstanceRequest actualRequest = verifyUpdateServiceInstance(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void updateServiceInstanceResponseShouldNotContainEmptyValuesWhenEmpty() { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .dashboardUrl("") .operation("") .build()); client.patch().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(updateRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() .expectBody() .jsonPath("$.dashboard_url").doesNotExist() .jsonPath("$.operation").doesNotExist(); }
@Test public void updateServiceInstanceResponseShouldNotContainEmptyValuesWhenNull() throws Exception { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .dashboardUrl(null) .operation(null) .build()); mockMvc.perform(patch(buildCreateUpdateUrl()) .content(updateRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.dashboard_url").doesNotExist()) .andExpect(jsonPath("$.operation").doesNotExist()); }
@Test public void updateServiceInstanceResponseShouldNotContainEmptyValuesWhenEmpty() throws Exception { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .dashboardUrl("") .operation("") .build()); mockMvc.perform(patch(buildCreateUpdateUrl()) .content(updateRequestBody) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(jsonPath("$.dashboard_url").doesNotExist()) .andExpect(jsonPath("$.operation").doesNotExist()); }
@Test public void updateServiceInstanceResponseShouldNotContainEmptyValuesWhenNull() { setupCatalogService(); setupServiceInstanceService(UpdateServiceInstanceResponse.builder() .dashboardUrl(null) .operation(null) .build()); client.patch().uri(buildCreateUpdateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(updateRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk() .expectBody() .jsonPath("$.dashboard_url").doesNotExist() .jsonPath("$.operation").doesNotExist(); }