@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"); }
@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); }
.async(false) .instanceExisted(false) .dashboardUrl("https://dashboard.example.com") .build(), HttpStatus.CREATED
@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 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()); }