private HttpStatus getCreateResponseCode(CreateServiceInstanceResponse response) { if (response != null) { if (response.isAsync()) { return HttpStatus.ACCEPTED; } else if (response.isInstanceExisted()) { return HttpStatus.OK; } } return HttpStatus.CREATED; }
/** * Construct a {@link CreateServiceInstanceResponse} from the provided values. * * @return the newly constructed {@literal CreateServiceInstanceResponse} */ public CreateServiceInstanceResponse build() { return new CreateServiceInstanceResponse(async, operation, dashboardUrl, instanceExisted); } }
@Override public final boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CreateServiceInstanceResponse)) return false; if (!super.equals(o)) return false; CreateServiceInstanceResponse that = (CreateServiceInstanceResponse) o; return that.canEqual(this) && instanceExisted == that.instanceExisted && Objects.equals(dashboardUrl, that.dashboardUrl); }
@Test public void responseWithAllValuesIsDeserialized() { CreateServiceInstanceResponse response = JsonUtils.readTestDataFile( "createResponse.json", CreateServiceInstanceResponse.class); assertThat(response.getOperation()).isEqualTo("in progress"); assertThat(response.getDashboardUrl()).isEqualTo("https://dashboard.local"); }
@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"); }
@Override public Mono<CreateServiceInstanceResponse> createServiceInstance( CreateServiceInstanceRequest request) { if (request.getServiceDefinitionId() == null) { return Mono.error(new ServiceBrokerInvalidParametersException("arrrr")); } return Mono.just(CreateServiceInstanceResponse.builder().build()); }
@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); }
@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(); }
private HttpStatus getCreateResponseCode(CreateServiceInstanceResponse response) { if (response != null) { if (response.isAsync()) { return HttpStatus.ACCEPTED; } else if (response.isInstanceExisted()) { return HttpStatus.OK; } } return HttpStatus.CREATED; }
/** * Construct a {@link CreateServiceInstanceResponse} from the provided values. * * @return the newly constructed {@literal CreateServiceInstanceResponse} */ public CreateServiceInstanceResponse build() { return new CreateServiceInstanceResponse(async, operation, dashboardUrl, instanceExisted); } }
@Override public final boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CreateServiceInstanceResponse)) return false; if (!super.equals(o)) return false; CreateServiceInstanceResponse that = (CreateServiceInstanceResponse) o; return that.canEqual(this) && instanceExisted == that.instanceExisted && Objects.equals(dashboardUrl, that.dashboardUrl); }
), new CreateResponseAndExpectedStatus( CreateServiceInstanceResponse.builder() .async(false) .instanceExisted(false) ), new CreateResponseAndExpectedStatus( CreateServiceInstanceResponse.builder() .async(false) .instanceExisted(true) ), new CreateResponseAndExpectedStatus( CreateServiceInstanceResponse.builder() .async(true) .instanceExisted(false) ), new CreateResponseAndExpectedStatus( CreateServiceInstanceResponse.builder() .async(true) .instanceExisted(true)
@Override public String toString() { String responseValue = response == null ? "null" : "{" + "async=" + response.isAsync() + ", instanceExisted=" + response.isInstanceExisted() + "}"; return "response=" + responseValue + ", expectedStatus=" + expectedStatus; }
@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 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 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 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(); }