Java源码示例:org.springframework.cloud.servicebroker.model.binding.GetServiceInstanceAppBindingResponse

示例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);
}
 
示例2
@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);
}
 
示例3
@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);
}
 
示例4
@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();
}
 
示例5
@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())));
}
 
示例6
@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);
}
 
示例7
@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());
}
 
示例8
@Test
void getServiceInstanceBinding() {
	StepVerifier
			.create(serviceInstanceBindingEventService.getServiceInstanceBinding(
					GetServiceInstanceBindingRequest.builder()
							.serviceInstanceId("service-instance-id")
							.bindingId("service-binding-id")
							.build()))
			.expectNext(GetServiceInstanceAppBindingResponse.builder().build())
			.verifyComplete();
}
 
示例9
@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());
}
 
示例10
@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()));
}
 
示例11
@Test
void getServiceBindingWithResponseGivesExpectedStatus2() {
	GetServiceInstanceBindingResponse response = GetServiceInstanceAppBindingResponse.builder()
			.build();
	validateGetServiceBindingResponseStatus(response, HttpStatus.OK);
}