@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"); }
@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 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); }
@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 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); }