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