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

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingRequest. 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: BookstoreServiceInstanceBindingServiceTests.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
public void getBindingWhenBindingExists() {
	HashMap<String, Object> parameters = new HashMap<>();
	ServiceBinding serviceBinding = new ServiceBinding(SERVICE_BINDING_ID, parameters, credentials);

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

	GetServiceInstanceBindingRequest request = GetServiceInstanceBindingRequest.builder()
			.bindingId(SERVICE_BINDING_ID)
			.build();

	StepVerifier.create(service.getServiceInstanceBinding(request))
			.consumeNextWith(response -> {
				assertThat(response).isInstanceOf(GetServiceInstanceAppBindingResponse.class);
				GetServiceInstanceAppBindingResponse appResponse = (GetServiceInstanceAppBindingResponse) response;
				assertThat(appResponse.getParameters()).isEqualTo(parameters);
				assertThat(appResponse.getCredentials()).isEqualTo(credentials);
			})
			.verifyComplete();

	verify(repository).findById(SERVICE_BINDING_ID);
	verifyNoMoreInteractions(repository);
}
 
Example #2
Source File: MailServiceInstanceBindingServiceUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenServiceBindingExists_whenGetServiceBinding_thenExistingBindingIsRetrieved() {
    // given service binding exists
    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 get service binding
    GetServiceInstanceBindingRequest request = GetServiceInstanceBindingRequest.builder()
        .serviceInstanceId(MAIL_SERVICE_INSTANCE_ID)
        .bindingId(MAIL_SERVICE_BINDING_ID)
        .build();

    // then the existing service binding is retrieved
    StepVerifier.create(mailServiceInstanceBindingService.getServiceInstanceBinding(request))
        .consumeNextWith(response -> {
            assertTrue(response instanceof GetServiceInstanceAppBindingResponse);
            GetServiceInstanceAppBindingResponse bindingResponse = (GetServiceInstanceAppBindingResponse) response;
            validateBindingCredentials(bindingResponse.getCredentials());
        })
        .verifyComplete();
}
 
Example #3
Source File: MailServiceInstanceBindingServiceUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenServiceBindingDoesNotExist_whenGetServiceBinding_thenException() {
    // given service binding does not exist
    when(mailService.getServiceBinding(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.empty());

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

    // then ServiceInstanceBindingDoesNotExistException is thrown
    StepVerifier.create(mailServiceInstanceBindingService.getServiceInstanceBinding(request))
        .expectErrorMatches(ex -> ex instanceof ServiceInstanceBindingDoesNotExistException)
        .verify();
}
 
Example #4
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
private void validateGetServiceBindingResponseStatus(GetServiceInstanceBindingResponse response,
		HttpStatus httpStatus) {
	Mono<GetServiceInstanceBindingResponse> responseMono;
	if (response == null) {
		responseMono = Mono.empty();
	}
	else {
		responseMono = Mono.just(response);
	}
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willReturn(responseMono);

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, null, null, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(httpStatus);
	assertThat(responseEntity.getBody()).isEqualTo(response);
}
 
Example #5
Source File: ServiceInstanceBindingControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void getServiceBindingParametersAreMappedToRequest() {
	GetServiceInstanceBindingRequest expectedRequest = GetServiceInstanceBindingRequest.builder()
			.serviceInstanceId("service-instance-id")
			.bindingId("binding-id")
			.platformInstanceId("platform-instance-id")
			.apiInfoLocation("api-info-location")
			.originatingIdentity(identityContext)
			.requestIdentity("request-id")
			.build();

	ServiceInstanceBindingController controller = createControllerUnderTest(expectedRequest);

	controller.getServiceInstanceBinding(pathVariables, "service-instance-id", "binding-id",
			"api-info-location", encodeOriginatingIdentity(identityContext), "request-id");
}
 
Example #6
Source File: ExampleServiceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	String serviceInstanceId = request.getServiceInstanceId();
	String bindingId = request.getBindingId();

	//
	// retrieve the details of the specified service binding
	//

	String url = new String(/* retrieved URL */);
	String bindingUsername = new String(/* retrieved user */);
	String bindingPassword = new String(/* retrieved password */);

	GetServiceInstanceBindingResponse response = GetServiceInstanceAppBindingResponse.builder()
			.credentials("username", bindingUsername)
			.credentials("password", bindingPassword)
			.credentials("url", url)
			.build();

	return Mono.just(response);
}
 
Example #7
Source File: BookstoreServiceInstanceBindingServiceTests.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
public void getBindingWhenBindingDoesNotExist() {
	when(repository.findById(SERVICE_BINDING_ID))
			.thenReturn(Mono.empty());

	GetServiceInstanceBindingRequest request = GetServiceInstanceBindingRequest.builder()
			.bindingId(SERVICE_BINDING_ID)
			.build();

	StepVerifier.create(service.getServiceInstanceBinding(request))
			.expectErrorMatches(e -> e instanceof ServiceInstanceBindingDoesNotExistException)
			.verify();

	verify(repository).findById(SERVICE_BINDING_ID);
	verifyNoMoreInteractions(repository);
}
 
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 getBindingToAppSucceeds() throws Exception {
	setupServiceInstanceBindingService(GetServiceInstanceAppBindingResponse.builder()
			.build());

	MvcResult mvcResult = mockMvc.perform(get(buildCreateUrl(PLATFORM_INSTANCE_ID, false))
			.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().isOk());

	GetServiceInstanceBindingRequest actualRequest = verifyGetBinding();
	assertHeaderValuesSet(actualRequest);
}
 
Example #9
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void getBindingToRouteSucceeds() throws Exception {
	setupServiceInstanceBindingService(GetServiceInstanceRouteBindingResponse.builder()
			.build());

	MvcResult mvcResult = mockMvc.perform(get(buildCreateUrl(PLATFORM_INSTANCE_ID, false))
			.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().isOk());

	GetServiceInstanceBindingRequest actualRequest = verifyGetBinding();
	assertHeaderValuesSet(actualRequest);
}
 
Example #10
Source File: AbstractServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
protected GetServiceInstanceBindingRequest verifyGetBinding() {
	ArgumentCaptor<GetServiceInstanceBindingRequest> argumentCaptor = ArgumentCaptor
			.forClass(GetServiceInstanceBindingRequest.class);
	then(serviceInstanceBindingService)
			.should()
			.getServiceInstanceBinding(argumentCaptor.capture());
	return argumentCaptor.getValue();
}
 
Example #11
Source File: BookStoreServiceInstanceBindingService.java    From bookstore-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	return Mono.just(request.getBindingId())
			.flatMap(bindingId -> bindingRepository.findById(bindingId)
					.flatMap(Mono::justOrEmpty)
					.switchIfEmpty(Mono.error(new ServiceInstanceBindingDoesNotExistException(bindingId)))
					.flatMap(serviceBinding -> Mono.just(GetServiceInstanceAppBindingResponse.builder()
							.parameters(serviceBinding.getParameters())
							.credentials(serviceBinding.getCredentials())
							.build())));
}
 
Example #12
Source File: MailServiceInstanceBindingService.java    From tutorials with MIT License 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
    return mailService.getServiceBinding(request.getServiceInstanceId(), request.getBindingId())
        .switchIfEmpty(Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId())))
        .flatMap(mailServiceBinding -> Mono.just(GetServiceInstanceAppBindingResponse.builder()
            .credentials(mailServiceBinding.getCredentials())
            .build()));
}
 
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<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	if (request.getBindingId() == null) {
		return Mono.error(new ServiceInstanceDoesNotExistException("service-instance-id"));
	}
	return Mono.just(GetServiceInstanceAppBindingResponse.builder().build());
}
 
Example #14
Source File: ServiceInstanceBindingEventServiceTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceInstanceBinding() {
	StepVerifier
			.create(serviceInstanceBindingEventService.getServiceInstanceBinding(
					GetServiceInstanceBindingRequest.builder()
							.serviceInstanceId("service-instance-id")
							.bindingId("service-binding-id")
							.build()))
			.expectNext(GetServiceInstanceAppBindingResponse.builder().build())
			.verifyComplete();
}
 
Example #15
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceBindingWithMissingServiceInstanceGivesExpectedStatus() {
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceDoesNotExistException("nonexistent-service-id"));

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, "nonexistent-service-id", "nonexistent-binding-id", null,
					null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
Example #16
Source File: ServiceInstanceBindingControllerResponseCodeTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getServiceBindingWithMissingBindingGivesExpectedStatus() {
	given(bindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceBindingDoesNotExistException("binding-id"));

	ResponseEntity<GetServiceInstanceBindingResponse> responseEntity = controller
			.getServiceInstanceBinding(pathVariables, null, null, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
}
 
Example #17
Source File: ServiceInstanceBindingController.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * REST controller for getting a service instance binding
 *
 * @param pathVariables the path variables
 * @param serviceInstanceId the service instance ID
 * @param bindingId the service binding ID
 * @param apiInfoLocation location of the API info endpoint of the platform instance
 * @param originatingIdentityString identity of the user that initiated the request from the platform
 * @param requestIdentity identity of the request sent from the platform
 * @return the response
 */
@GetMapping({PLATFORM_PATH_MAPPING, PATH_MAPPING})
public Mono<ResponseEntity<GetServiceInstanceBindingResponse>> getServiceInstanceBinding(
		@PathVariable Map<String, String> pathVariables,
		@PathVariable(ServiceBrokerRequest.INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId,
		@PathVariable(ServiceBrokerRequest.BINDING_ID_PATH_VARIABLE) String bindingId,
		@RequestHeader(value = ServiceBrokerRequest.API_INFO_LOCATION_HEADER, required = false) String apiInfoLocation,
		@RequestHeader(value = ServiceBrokerRequest.ORIGINATING_IDENTITY_HEADER, required = false) String originatingIdentityString,
		@RequestHeader(value = ServiceBrokerRequest.REQUEST_IDENTITY_HEADER, required = false) String requestIdentity) {
	return Mono.just(GetServiceInstanceBindingRequest.builder()
			.serviceInstanceId(serviceInstanceId)
			.bindingId(bindingId)
			.platformInstanceId(pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE))
			.apiInfoLocation(apiInfoLocation)
			.originatingIdentity(parseOriginatingIdentity(originatingIdentityString))
			.requestIdentity(requestIdentity)
			.build())
			.flatMap(req -> service.getServiceInstanceBinding(req)
					.doOnRequest(v -> {
						LOG.info("Getting a service instance binding");
						LOG.debug(DEBUG_REQUEST, req);
					})
					.doOnSuccess(response -> {
						LOG.info("Getting a service instance binding succeeded");
						LOG.debug("bindingId={}", bindingId);
					})
					.doOnError(e -> LOG.error("Error getting service instance binding. error=" +
							e.getMessage(), e)))
			.map(response -> new ResponseEntity<>(response, HttpStatus.OK))
			.switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK)))
			.onErrorResume(e -> {
				if (e instanceof ServiceInstanceBindingDoesNotExistException ||
						e instanceof ServiceInstanceDoesNotExistException) {
					return Mono.just(new ResponseEntity<>(HttpStatus.NOT_FOUND));
				}
				else {
					return Mono.error(e);
				}
			});
}
 
Example #18
Source File: TestServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	if (IN_PROGRESS_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceBrokerOperationInProgressException("task_10"));
	}
	return Mono.just(GetServiceInstanceAppBindingResponse.builder()
			.build());
}
 
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 getBindingWithOperationInProgressFails() {
	given(serviceInstanceBindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceBrokerOperationInProgressException("task_10"));

	client.get().uri(buildCreateUrl())
			.accept(MediaType.APPLICATION_JSON)
			.exchange()
			.expectStatus().isNotFound();
}
 
Example #20
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getBindingToRouteSucceeds() throws Exception {
	setupServiceInstanceBindingService(GetServiceInstanceRouteBindingResponse.builder()
			.build());

	client.get().uri(buildCreateUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.accept(MediaType.APPLICATION_JSON)
			.exchange()
			.expectStatus().isOk();

	GetServiceInstanceBindingRequest actualRequest = verifyGetBinding();
	assertHeaderValuesSet(actualRequest);
}
 
Example #21
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getBindingToAppSucceeds() throws Exception {
	setupServiceInstanceBindingService(GetServiceInstanceAppBindingResponse.builder()
			.build());

	client.get().uri(buildCreateUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.accept(MediaType.APPLICATION_JSON)
			.exchange()
			.expectStatus().isOk();

	GetServiceInstanceBindingRequest actualRequest = verifyGetBinding();
	assertHeaderValuesSet(actualRequest);
}
 
Example #22
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void getBindingWithOperationInProgressFails() throws Exception {
	given(serviceInstanceBindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceBrokerOperationInProgressException("task_10"));

	MvcResult mvcResult = mockMvc.perform(get(buildCreateUrl())
			.accept(MediaType.APPLICATION_JSON)
			.contentType(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isNotFound());
}
 
Example #23
Source File: ServiceInstanceBindingEventService.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	return service.getServiceInstanceBinding(request);
}
 
Example #24
Source File: ServiceInstanceBindingControllerRequestTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example #25
Source File: AbstractServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
protected void setupServiceInstanceBindingService(GetServiceInstanceBindingResponse getResponse) {
	given(serviceInstanceBindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willReturn(Mono.just(getResponse));
}
 
Example #26
Source File: ServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 3 votes vote down vote up
/**
 * Get the details of a binding to a service instance.
 *
 * @param request containing the details of the request
 * @return a {@link GetServiceInstanceBindingResponse} on successful processing of the request
 * @throws ServiceInstanceDoesNotExistException if a service instance with the given ID is not known to the
 * 		broker
 * @throws ServiceInstanceBindingDoesNotExistException if a binding with the given ID is not known to the broker
 * @throws ServiceBrokerOperationInProgressException if a an operation is in progress for the service binding
 */
default Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	return Mono.error(new UnsupportedOperationException(
			"This service broker does not support retrieving service bindings. " +
					"The service broker should set 'bindings_retrievable:false' in the service catalog, " +
					"or provide an implementation of the fetch binding API."));
}