org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse Java Examples

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorkflowServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 6 votes vote down vote up
private Flux<Void> invokeCreateWorkflows(CreateServiceInstanceBindingRequest request,
	CreateServiceInstanceBindingResponse response) {
	return Flux.defer(() -> {
		if (isAppBindingRequest(request)) {
			return Flux.fromIterable(createServiceInstanceAppBindingWorkflows)
				.filterWhen(workflow -> workflow.accept(request))
				.concatMap(workflow -> workflow.create(request,
					(CreateServiceInstanceAppBindingResponse) response));
		}
		else if (isRouteBindingRequest(request)) {
			return Flux.fromIterable(createServiceInstanceRouteBindingWorkflows)
				.filterWhen(workflow -> workflow.accept(request))
				.concatMap(workflow -> workflow.create(request,
					(CreateServiceInstanceRouteBindingResponse) response));
		}
		return Flux.empty();
	});
}
 
Example #2
Source File: ExampleServiceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void createBindingToAppWithExistingSucceeds() {
	setupCatalogService();

	setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder()
			.bindingExisted(true)
			.build());

	client.put().uri(buildCreateUrl())
			.contentType(MediaType.APPLICATION_JSON)
			.bodyValue(createRequestBody)
			.accept(MediaType.APPLICATION_JSON)
			.exchange()
			.expectStatus().isOk();

	CreateServiceInstanceBindingRequest actualRequest = verifyCreateBinding();
	assertHeaderValuesNotSet(actualRequest);
}
 
Example #4
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
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)
			.bodyValue(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);
}
 
Example #5
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void createBindingToAppFiltersPlansSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse
			.builder()
			.bindingExisted(false)
			.build());

	client.put().uri(buildCreateUrl(PLATFORM_INSTANCE_ID, false))
			.contentType(MediaType.APPLICATION_JSON)
			.bodyValue(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);
}
 
Example #6
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void createBindingToAppWithoutAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(CreateServiceInstanceAppBindingResponse.builder()
			.bindingExisted(false)
			.build());

	client.put().uri(buildCreateUrl(PLATFORM_INSTANCE_ID, false))
			.contentType(MediaType.APPLICATION_JSON)
			.bodyValue(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);
}
 
Example #7
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
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);
}
 
Example #8
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
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);
}
 
Example #9
Source File: BookStoreServiceInstanceBindingService.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	return Mono.just(CreateServiceInstanceAppBindingResponse.builder())
			.flatMap(responseBuilder -> bindingRepository.existsById(request.getBindingId())
					.flatMap(exists -> {
						if (exists) {
							return bindingRepository.findById(request.getBindingId())
									.flatMap(serviceBinding -> Mono.just(responseBuilder
											.bindingExisted(true)
											.credentials(serviceBinding.getCredentials())
											.build()));
						}
						else {
							return createUser(request)
									.flatMap(user -> buildCredentials(request.getServiceInstanceId(), user))
									.flatMap(credentials -> bindingRepository
											.save(new ServiceBinding(request.getBindingId(),
													request.getParameters(), credentials))
											.thenReturn(responseBuilder
													.bindingExisted(false)
													.credentials(credentials)
													.build()));
						}
					}));
}
 
Example #10
Source File: ServiceInstanceBindingEventServiceTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void createServiceInstanceBindingSucceeds() {
	prepareBindingFlows();

	StepVerifier
			.create(serviceInstanceBindingEventService.createServiceInstanceBinding(
					CreateServiceInstanceBindingRequest.builder()
							.serviceInstanceId("service-instance-id")
							.serviceDefinitionId("service-binding-id")
							.build()))
			.expectNext(CreateServiceInstanceAppBindingResponse.builder().build())
			.verifyComplete();

	assertThat(this.results.getBeforeCreate()).isEqualTo("before create service-instance-id");
	assertThat(this.results.getAfterCreate()).isEqualTo("after create service-instance-id");
	assertThat(this.results.getErrorCreate()).isNullOrEmpty();
	assertThat(this.results.getBeforeDelete()).isNullOrEmpty();
	assertThat(this.results.getAfterDelete()).isNullOrEmpty();
	assertThat(this.results.getErrorDelete()).isNullOrEmpty();
}
 
Example #11
Source File: MailServiceInstanceBindingServiceUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenServiceBindingExists_whenCreateServiceBinding_thenExistingBindingIsRetrieved() {
    // given service binding exists
    when(mailService.serviceBindingExists(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.just(true));

    Map<String, Object> credentials = generateCredentials();
    MailServiceBinding serviceBinding = new MailServiceBinding(MAIL_SERVICE_BINDING_ID, credentials);
    when(mailService.getServiceBinding(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID))
        .thenReturn(Mono.just(serviceBinding));

    // when create service binding
    CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
        .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID)
        .bindingId(MAIL_SERVICE_BINDING_ID)
        .build();

    // then a new service binding is provisioned
    StepVerifier.create(mailServiceInstanceBindingService.createServiceInstanceBinding(request))
        .consumeNextWith(response -> {
            assertTrue(response instanceof CreateServiceInstanceAppBindingResponse);
            CreateServiceInstanceAppBindingResponse bindingResponse = (CreateServiceInstanceAppBindingResponse) response;
            assertTrue(bindingResponse.isBindingExisted());
            validateBindingCredentials(bindingResponse.getCredentials());
        })
        .verifyComplete();
}
 
Example #12
Source File: MailServiceInstanceBindingServiceUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenServiceBindingDoesNotExist_whenCreateServiceBinding_thenNewBindingIsCreated() {
    // given service binding does not exist
    when(mailService.serviceBindingExists(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.just(false));

    Map<String, Object> credentials = generateCredentials();
    MailServiceBinding serviceBinding = new MailServiceBinding(MAIL_SERVICE_BINDING_ID, credentials);
    when(mailService.createServiceBinding(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID))
        .thenReturn(Mono.just(serviceBinding));

    // when create service binding
    CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
        .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID)
        .bindingId(MAIL_SERVICE_BINDING_ID)
        .build();

    // then a new service binding is provisioned
    StepVerifier.create(mailServiceInstanceBindingService.createServiceInstanceBinding(request))
        .consumeNextWith(response -> {
            assertTrue(response instanceof CreateServiceInstanceAppBindingResponse);
            CreateServiceInstanceAppBindingResponse bindingResponse = (CreateServiceInstanceAppBindingResponse) response;
            assertFalse(bindingResponse.isBindingExisted());
            validateBindingCredentials(bindingResponse.getCredentials());
        })
        .verifyComplete();
}
 
Example #13
Source File: ServiceInstanceBindingEventServiceTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	if (request.getServiceDefinitionId() == null) {
		return Mono.error(new ServiceInstanceBindingExistsException("service-instance-id", "arrrr"));
	}
	return Mono.just(CreateServiceInstanceAppBindingResponse.builder().build());
}
 
Example #14
Source File: TestServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	if (IN_PROGRESS_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceBrokerCreateOperationInProgressException("task_10"));
	}
	if (EXISTING_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.just(CreateServiceInstanceAppBindingResponse.builder()
				.bindingExisted(true)
				.build());
	}
	if (UNKNOWN_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceInstanceDoesNotExistException(request.getServiceInstanceId()));
	}
	if (request.isAsyncAccepted()) {
		return Mono.just(CreateServiceInstanceAppBindingResponse.builder()
				.async(true)
				.operation("working")
				.bindingExisted(false)
				.build());
	}
	else {
		return Mono.just(CreateServiceInstanceAppBindingResponse.builder()
				.bindingExisted(false)
				.build());
	}
}
 
Example #15
Source File: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void createServiceInstanceAppBindingWithNoWorkflows() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.IN_PROGRESS, "create service instance binding started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.SUCCEEDED, "create service instance binding completed",
				new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	this.workflowServiceInstanceBindingService = new WorkflowServiceInstanceBindingService(
		this.stateRepository, null, null, null);

	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.bindResource(BindResource.builder()
			.appGuid("foo-guid")
			.build())
		.build();

	StepVerifier.create(workflowServiceInstanceBindingService.createServiceInstanceBinding(request))
		.assertNext(response -> {
			InOrder repoOrder = inOrder(stateRepository);
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.IN_PROGRESS),
					eq("create service instance binding started"));
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.SUCCEEDED),
					eq("create service instance binding completed"));
			repoOrder.verifyNoMoreInteractions();

			assertThat(response).isNotNull();
			assertThat(response).isInstanceOf(CreateServiceInstanceAppBindingResponse.class);
		})
		.verifyComplete();
}
 
Example #16
Source File: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void createServiceInstanceAppBindingWithResponseError() {
	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-id")
		.bindResource(BindResource.builder()
			.appGuid("foo-guid")
			.build())
		.build();

	CreateServiceInstanceAppBindingResponseBuilder responseBuilder = CreateServiceInstanceAppBindingResponse
		.builder();

	given(createServiceInstanceAppBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(createServiceInstanceAppBindingWorkflow1
		.buildResponse(eq(request), any(CreateServiceInstanceAppBindingResponseBuilder.class)))
		.willReturn(Mono.error(new ServiceBrokerException("create foo error")));

	given(createServiceInstanceAppBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(createServiceInstanceAppBindingWorkflow2
		.buildResponse(eq(request), any(CreateServiceInstanceAppBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

	StepVerifier.create(workflowServiceInstanceBindingService.createServiceInstanceBinding(request))
		.expectErrorSatisfies(e -> assertThat(e)
			.isInstanceOf(ServiceBrokerException.class)
			.hasMessage("create foo error"))
		.verify();
}
 
Example #17
Source File: MailServiceInstanceBindingService.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
    CreateServiceInstanceBindingRequest request) {
    return Mono.just(CreateServiceInstanceAppBindingResponse.builder())
        .flatMap(responseBuilder -> mailService.serviceBindingExists(
            request.getServiceInstanceId(), request.getBindingId())
            .flatMap(exists -> {
                if (exists) {
                    return mailService.getServiceBinding(
                        request.getServiceInstanceId(), request.getBindingId())
                        .flatMap(serviceBinding -> Mono.just(responseBuilder
                            .bindingExisted(true)
                            .credentials(serviceBinding.getCredentials())
                            .build()));
                } else {
                    return mailService.createServiceBinding(
                        request.getServiceInstanceId(), request.getBindingId())
                        .switchIfEmpty(Mono.error(
                            new ServiceInstanceDoesNotExistException(
                                request.getServiceInstanceId())))
                        .flatMap(mailServiceBinding -> Mono.just(responseBuilder
                            .bindingExisted(false)
                            .credentials(mailServiceBinding.getCredentials())
                            .build()));
                }
            }));
}
 
Example #18
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
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);
}
 
Example #19
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
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);
}
 
Example #20
Source File: CredHubPersistingCreateServiceInstanceAppBindingWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private Mono<CreateServiceInstanceAppBindingResponseBuilder> persistBindingCredentials(
	CreateServiceInstanceBindingRequest request, CreateServiceInstanceAppBindingResponse response,
	CredentialName credentialName) {
	return writeCredential(response, credentialName)
		.then(writePermissions(request, credentialName))
		.thenReturn(buildReplacementBindingResponse(response, credentialName));
}
 
Example #21
Source File: NamespaceBindingWorkflow.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public CreateServiceInstanceAppBindingResponse getResponse(Map<String, Object> credentials) {
    // TODO add bindingExisted, & endpoints?yy
    return CreateServiceInstanceAppBindingResponse.builder()
            .credentials(credentials)
            .build();
}
 
Example #22
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void createServiceBindingWithNoExistingBindingResponseGivesExpectedStatus() {
	CreateServiceInstanceBindingResponse response = CreateServiceInstanceAppBindingResponse.builder()
			.bindingExisted(false)
			.build();
	validateCreateServiceBindingResponseStatus(response, HttpStatus.CREATED);
}
 
Example #23
Source File: BucketBindingWorkflow.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public CreateServiceInstanceAppBindingResponse getResponse(Map<String, Object> credentials) {
    CreateServiceInstanceAppBindingResponse.CreateServiceInstanceAppBindingResponseBuilder builder = CreateServiceInstanceAppBindingResponse.builder()
            .credentials(credentials);

    if (volumeMounts != null) {
            builder.volumeMounts(volumeMounts);
    }

    return builder.build();
}
 
Example #24
Source File: BindingWorkflowImpl.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
public CreateServiceInstanceAppBindingResponse getResponse(Map<String, Object> credentials) {
    // TODO add bindingExisted, & endpoints
    return CreateServiceInstanceAppBindingResponse.builder()
            .async(false)
            .credentials(credentials)
            .build();
}
 
Example #25
Source File: BookstoreServiceInstanceBindingServiceTests.java    From bookstore-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
public void createBindingWhenBindingExists() {
	ServiceBinding binding = new ServiceBinding(SERVICE_BINDING_ID, null, credentials);

	when(repository.existsById(SERVICE_BINDING_ID))
			.thenReturn(Mono.just(true));

	when(repository.findById(SERVICE_BINDING_ID))
			.thenReturn(Mono.just(binding));

	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
			.serviceInstanceId(SERVICE_INSTANCE_ID)
			.bindingId(SERVICE_BINDING_ID)
			.build();

	StepVerifier.create(service.createServiceInstanceBinding(request))
			.consumeNextWith(response -> {
				assertThat(response).isInstanceOf(CreateServiceInstanceAppBindingResponse.class);
				CreateServiceInstanceAppBindingResponse appResponse = (CreateServiceInstanceAppBindingResponse) response;
				assertThat(appResponse.isBindingExisted()).isTrue();
				assertThat(credentials).isEqualTo(appResponse.getCredentials());
			})
			.verifyComplete();

	verify(repository).existsById(SERVICE_BINDING_ID);
	verify(repository).findById(SERVICE_BINDING_ID);
	verifyNoMoreInteractions(repository);
}
 
Example #26
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void createServiceBindingWithExistingBindingResponseGivesExpectedStatus() {
	CreateServiceInstanceBindingResponse response = CreateServiceInstanceAppBindingResponse.builder()
			.bindingExisted(true)
			.build();
	validateCreateServiceBindingResponseStatus(response, HttpStatus.OK);
}
 
Example #27
Source File: CredHubPersistingCreateServiceInstanceAppBindingWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private Mono<Void> writeCredential(CreateServiceInstanceAppBindingResponse response,
	CredentialName credentialName) {
	return credHubOperations.credentials()
			.write(JsonCredentialRequest.builder()
				.name(credentialName)
				.value(response.getCredentials())
				.build())
		.then();
}
 
Example #28
Source File: CredHubPersistingCreateServiceInstanceAppBindingWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
private CreateServiceInstanceAppBindingResponseBuilder buildReplacementBindingResponse(
	CreateServiceInstanceAppBindingResponse response, CredentialName credentialName) {
	return CreateServiceInstanceAppBindingResponse.builder()
		.async(response.isAsync())
		.bindingExisted(response.isBindingExisted())
		.credentials(CREDHUB_REF_KEY, credentialName.getName())
		.operation(response.getOperation())
		.syslogDrainUrl(response.getSyslogDrainUrl())
		.volumeMounts(response.getVolumeMounts());
}
 
Example #29
Source File: CredHubPersistingCreateServiceInstanceAppBindingWorkflowTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void noBindingCredentials() {
	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest
		.builder()
		.bindingId("foo-binding-id")
		.serviceInstanceId("foo-instance-id")
		.serviceDefinitionId("foo-definition-id")
		.build();

	CreateServiceInstanceAppBindingResponseBuilder responseBuilder = CreateServiceInstanceAppBindingResponse
		.builder()
		.bindingExisted(true)
		.syslogDrainUrl("https://logs.example.local")
		.volumeMounts(VolumeMount.builder().build())
		.volumeMounts(VolumeMount.builder().build())
		.volumeMounts(Arrays.asList(
			VolumeMount.builder().build(),
			VolumeMount.builder().build()
		));

	StepVerifier
		.create(this.workflow.buildResponse(request, responseBuilder))
		.assertNext(createServiceInstanceAppBindingResponseBuilder -> {
			CreateServiceInstanceAppBindingResponse response = createServiceInstanceAppBindingResponseBuilder
				.build();
			assertThat(response.isBindingExisted()).isEqualTo(true);
			assertThat(response.getCredentials()).hasSize(0);
			assertThat(response.getSyslogDrainUrl()).isEqualTo("https://logs.example.local");
			assertThat(response.getVolumeMounts()).hasSize(4);

		})
		.verifyComplete();

	verifyNoInteractions(this.credHubCredentialOperations);
}
 
Example #30
Source File: CreateServiceInstanceAppBindingWorkflow.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
default Mono<Void> create(CreateServiceInstanceBindingRequest request,
	CreateServiceInstanceAppBindingResponse response) {
	return Mono.empty();
}