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

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceBindingRequest. These examples are extracted from open source projects. 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
@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
@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 3
@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 4
@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 5
@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 6
@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 7
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 8
@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 9
@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 10
@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 11
protected GetServiceInstanceBindingRequest verifyGetBinding() {
	ArgumentCaptor<GetServiceInstanceBindingRequest> argumentCaptor = ArgumentCaptor
			.forClass(GetServiceInstanceBindingRequest.class);
	then(serviceInstanceBindingService)
			.should()
			.getServiceInstanceBinding(argumentCaptor.capture());
	return argumentCaptor.getValue();
}
 
Example 12
@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 13
@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 14
@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 15
@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 16
@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 17
/**
 * 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
@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 19
@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 20
@Test
void getServiceInstanceBinding() {
	StepVerifier
			.create(serviceInstanceBindingEventService.getServiceInstanceBinding(
					GetServiceInstanceBindingRequest.builder()
							.serviceInstanceId("service-instance-id")
							.bindingId("service-binding-id")
							.build()))
			.expectNext(GetServiceInstanceAppBindingResponse.builder().build())
			.verifyComplete();
}
 
Example 21
@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 22
Source Project: tutorials   Source File: MailServiceInstanceBindingService.java    License: 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 23
protected void setupServiceInstanceBindingService(GetServiceInstanceBindingResponse getResponse) {
	given(serviceInstanceBindingService.getServiceInstanceBinding(any(GetServiceInstanceBindingRequest.class)))
			.willReturn(Mono.just(getResponse));
}
 
Example 24
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(GetServiceInstanceBindingRequest request) {
	return service.getServiceInstanceBinding(request);
}
 
Example 25
@Override
public Mono<GetServiceInstanceBindingResponse> getServiceInstanceBinding(
		GetServiceInstanceBindingRequest request) {
	assertThat(request).isEqualTo(expectedRequest);
	return Mono.empty();
}
 
Example 26
/**
 * 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."));
}