/** * Construct a {@link CreateServiceInstanceAppBindingResponse} from the provided values. * * @return the newly constructed {@literal CreateServiceInstanceAppBindingResponse} */ public CreateServiceInstanceAppBindingResponse build() { return new CreateServiceInstanceAppBindingResponse(async, operation, bindingExisted, credentials, syslogDrainUrl, volumeMounts); } }
@Override public final boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CreateServiceInstanceAppBindingResponse)) return false; if (!super.equals(o)) return false; CreateServiceInstanceAppBindingResponse that = (CreateServiceInstanceAppBindingResponse) o; return that.canEqual(this) && Objects.equals(credentials, that.credentials) && Objects.equals(syslogDrainUrl, that.syslogDrainUrl) && Objects.equals(volumeMounts, that.volumeMounts); }
@Override public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(CreateServiceInstanceBindingRequest request) { if (request.getServiceDefinitionId() == null) { return Mono.error(new ServiceInstanceBindingExistsException("foo", "arrrr")); } return Mono.just(CreateServiceInstanceAppBindingResponse.builder().build()); }
@Test public void responseWithDefaultsIsBuilt() { CreateServiceInstanceAppBindingResponse response = CreateServiceInstanceAppBindingResponse.builder() .build(); assertThat(response.isBindingExisted()).isEqualTo(false); assertThat(response.getCredentials()).hasSize(0); assertThat(response.getSyslogDrainUrl()).isNull(); assertThat(response.getVolumeMounts()).hasSize(0); DocumentContext json = JsonUtils.toJsonPath(response); assertThat(json).hasNoPath("$.credentials"); assertThat(json).hasNoPath("$.syslog_drain_url"); assertThat(json).hasNoPath("$.volume_mounts"); }
@Test public void responseWithValuesIsDeserialized() { CreateServiceInstanceAppBindingResponse response = JsonUtils.readTestDataFile( "createAppBindingResponse.json", CreateServiceInstanceAppBindingResponse.class); assertThat(response.getCredentials()).containsOnly(entry("cred1", "foo"), entry("cred2", "bar")); assertThat(response.getSyslogDrainUrl()).isEqualTo("https://logs.hello.local"); assertThat(response.getVolumeMounts()).hasSize(1); VolumeMount volumeMount = response.getVolumeMounts().get(0); assertThat(volumeMount.getDriver()).isEqualTo("driver-1"); assertThat(volumeMount.getContainerDir()).isEqualTo("container-dir-1"); assertThat(volumeMount.getMode()).isEqualTo(VolumeMount.Mode.READ_ONLY); assertThat(volumeMount.getDeviceType()).isEqualTo(VolumeMount.DeviceType.SHARED); SharedVolumeDevice sharedVolumeDevice = ((SharedVolumeDevice)volumeMount.getDevice()); assertThat(sharedVolumeDevice.getVolumeId()).isEqualTo("volume-id"); assertThat(sharedVolumeDevice.getMountConfig()) .containsOnly(entry("field1", "mount-config-1"), entry("field2", "mount-config-2")); }
@Override public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(CreateServiceInstanceBindingRequest request) { String serviceInstanceId = request.getServiceInstanceId(); String bindingId = request.getBindingId(); // // create credentials and store for later retrieval // String url = new String(/* build a URL to access the service instance */); String bindingUsername = new String(/* create a user */); String bindingPassword = new String(/* create a password */); CreateServiceInstanceBindingResponse response = CreateServiceInstanceAppBindingResponse.builder() .credentials("url", url) .credentials("username", bindingUsername) .credentials("password", bindingPassword) .bindingExisted(false) .async(true) .build(); return Mono.just(response); }
); CreateServiceInstanceAppBindingResponse response = CreateServiceInstanceAppBindingResponse.builder() .bindingExisted(true) .credentials("credential1", "value1") .build(); assertThat(response.isBindingExisted()).isEqualTo(true); assertThat(response.getCredentials()).hasSize(5); assertThat(response.getCredentials().get("credential1")).isEqualTo("value1"); assertThat(response.getCredentials().get("credential2")).isEqualTo(2); assertThat(response.getCredentials().get("credential3")).isEqualTo(true); assertThat(response.getCredentials().get("credential4")).isEqualTo("value4"); assertThat(response.getCredentials().get("credential5")).isEqualTo("value5"); assertThat(response.getSyslogDrainUrl()).isEqualTo("https://logs.example.com"); assertThat(response.getVolumeMounts()).hasSize(4);
@DataPoints("createResponsesWithExpectedStatus") public static List<CreateResponseAndExpectedStatus> createDataPoints() { return Arrays.asList( new CreateResponseAndExpectedStatus( null, HttpStatus.CREATED ), new CreateResponseAndExpectedStatus( CreateServiceInstanceAppBindingResponse.builder() .bindingExisted(false) .build(), HttpStatus.CREATED ), new CreateResponseAndExpectedStatus( CreateServiceInstanceAppBindingResponse.builder() .bindingExisted(true) .build(), HttpStatus.OK ) ); }
@Override public final boolean equals(Object o) { if (this == o) return true; if (!(o instanceof CreateServiceInstanceAppBindingResponse)) return false; if (!super.equals(o)) return false; CreateServiceInstanceAppBindingResponse that = (CreateServiceInstanceAppBindingResponse) o; return that.canEqual(this) && Objects.equals(credentials, that.credentials) && Objects.equals(syslogDrainUrl, that.syslogDrainUrl) && Objects.equals(volumeMounts, that.volumeMounts); }
/** * Construct a {@link CreateServiceInstanceAppBindingResponse} from the provided values. * * @return the newly constructed {@literal CreateServiceInstanceAppBindingResponse} */ public CreateServiceInstanceAppBindingResponse build() { return new CreateServiceInstanceAppBindingResponse(async, operation, bindingExisted, credentials, syslogDrainUrl, volumeMounts); } }
@Test public void createServiceInstanceBindingSucceeds() { prepareBindingFlows(); StepVerifier .create(serviceInstanceBindingEventService.createServiceInstanceBinding( CreateServiceInstanceBindingRequest.builder() .serviceInstanceId("foo") .serviceDefinitionId("bar") .build())) .expectNext(CreateServiceInstanceAppBindingResponse.builder().build()) .verifyComplete(); assertThat(this.results.getBeforeCreate()).isEqualTo("before create foo"); assertThat(this.results.getAfterCreate()).isEqualTo("after create foo"); assertThat(this.results.getErrorCreate()).isNullOrEmpty(); assertThat(this.results.getBeforeDelete()).isNullOrEmpty(); assertThat(this.results.getAfterDelete()).isNullOrEmpty(); assertThat(this.results.getErrorDelete()).isNullOrEmpty(); }
@Test public void createBindingToAppFiltersPlansSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse .builder() .bindingExisted(false) .build()); MvcResult mvcResult = mockMvc .perform(put(buildCreateUrl(PLATFORM_INSTANCE_ID, false)) .content(createRequestBody) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isCreated()); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId()); assertHeaderValuesSet(actualRequest); }
@Test public void createBindingToAppFiltersPlansSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse .builder() .bindingExisted(false) .build()); client.put().uri(buildCreateUrl(PLATFORM_INSTANCE_ID, false)) .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().isCreated(); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId()); assertHeaderValuesSet(actualRequest); }
@Test public void createBindingToAppWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder() .async(true) .operation("working") .bindingExisted(false) .build()); client.put().uri(buildCreateUrl(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() .expectBody() .jsonPath("$.operation").isEqualTo("working"); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void createBindingToAppWithoutAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder() .bindingExisted(false) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUrl(PLATFORM_INSTANCE_ID, false)) .content(createRequestBody) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isCreated()); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false); assertHeaderValuesSet(actualRequest); }
@Test public void createBindingToAppWithExistingSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder() .bindingExisted(true) .build()); client.put().uri(buildCreateUrl()) .contentType(MediaType.APPLICATION_JSON) .syncBody(createRequestBody) .accept(MediaType.APPLICATION_JSON) .exchange() .expectStatus().isOk(); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertHeaderValuesNotSet(actualRequest); }
@Test public void createBindingToAppWithAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder() .async(true) .operation("working") .bindingExisted(false) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUrl(PLATFORM_INSTANCE_ID, true)) .content(createRequestBody) .header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION) .header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader()) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andExpect(status().isOk()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isAccepted()) .andExpect(jsonPath("$.operation", equalTo("working"))); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true); assertHeaderValuesSet(actualRequest); }
@Test public void createBindingToAppWithoutAsyncAndHeadersSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder() .bindingExisted(false) .build()); client.put().uri(buildCreateUrl(PLATFORM_INSTANCE_ID, false)) .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().isCreated(); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertHeaderValuesSet(actualRequest); }
@Test public void createBindingToAppWithExistingSucceeds() throws Exception { setupCatalogService(); setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder() .bindingExisted(true) .build()); MvcResult mvcResult = mockMvc.perform(put(buildCreateUrl()) .content(createRequestBody) .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(request().asyncStarted()) .andExpect(status().isOk()) .andReturn(); mockMvc.perform(asyncDispatch(mvcResult)) .andExpect(status().isOk()); CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding(); assertHeaderValuesNotSet(actualRequest); }