Java Code Examples for org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingDoesNotExistException

The following examples show how to use org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingDoesNotExistException. 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
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	return Mono.just(request.getBindingId())
			.flatMap(bindingId -> bindingRepository.existsById(bindingId)
					.flatMap(exists -> {
						if (exists) {
							return bindingRepository.deleteById(bindingId)
									.then(userService.deleteUser(bindingId))
									.thenReturn(DeleteServiceInstanceBindingResponse.builder().build());
						}
						else {
							return Mono.error(new ServiceInstanceBindingDoesNotExistException(bindingId));
						}
					}));
}
 
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
public void deleteBindingWhenBindingDoesNotExist() {
	when(repository.existsById(SERVICE_BINDING_ID))
			.thenReturn(Mono.just(false));

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

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

	verify(repository).existsById(SERVICE_BINDING_ID);
	verifyNoMoreInteractions(repository);
}
 
Example 4
@Test
void deleteBindingWithUnknownBindingIdFails() throws Exception {
	setupCatalogService();

	doThrow(new ServiceInstanceBindingDoesNotExistException(SERVICE_INSTANCE_BINDING_ID))
			.when(serviceInstanceBindingService)
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl())
			.contentType(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isGone());
}
 
Example 5
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	if (IN_PROGRESS_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceBrokerDeleteOperationInProgressException("task_10"));
	}
	if (UNKNOWN_SERVICE_INSTANCE_ID.equals(request.getServiceInstanceId())) {
		return Mono.error(new ServiceInstanceDoesNotExistException(request.getServiceInstanceId()));
	}
	if (UNKNOWN_BINDING_ID.equals(request.getBindingId())) {
		return Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId()));
	}
	if (request.isAsyncAccepted()) {
		return Mono.just(DeleteServiceInstanceBindingResponse.builder()
				.async(true)
				.operation("working")
				.build());
	}
	else {
		return Mono.just(DeleteServiceInstanceBindingResponse.builder()
				.build());
	}
}
 
Example 6
@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 7
@Test
public void givenServiceBindingDoesNotExist_whenDeleteServiceBinding_thenException() {
    // given service binding does not exist
    when(mailService.serviceBindingExists(MAIL_SERVICE_INSTANCE_ID, MAIL_SERVICE_BINDING_ID)).thenReturn(Mono.just(false));

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

    // then ServiceInstanceBindingDoesNotExistException is thrown
    StepVerifier.create(mailServiceInstanceBindingService.deleteServiceInstanceBinding(request))
        .expectErrorMatches(ex -> ex instanceof ServiceInstanceBindingDoesNotExistException)
        .verify();
}
 
Example 8
@Override
public Mono<GetLastServiceBindingOperationResponse> getLastOperation(
	GetLastServiceBindingOperationRequest request) {
	return stateRepository.getState(request.getServiceInstanceId(), request.getBindingId())
		.doOnError(exception -> Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId())))
		.map(serviceInstanceState -> GetLastServiceBindingOperationResponse.builder()
			.operationState(serviceInstanceState.getOperationState())
			.description(serviceInstanceState.getDescription())
			.build());
}
 
Example 9
@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 10
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request)
        throws ServiceBrokerException {

    String bindingId = request.getBindingId();
    try {
        BindingWorkflow workflow = getWorkflow(request)
                .withDeleteRequest(request);

        LOG.info("looking up binding: " + bindingId);
        ServiceInstanceBinding binding = repository.find(bindingId);
        if (binding == null)
            throw new ServiceInstanceBindingDoesNotExistException(bindingId);
        LOG.info("binding found: " + bindingId);

        workflow.removeBinding(binding);

        LOG.info("deleting from repository" + bindingId);
        repository.delete(bindingId);
        return Mono.just(DeleteServiceInstanceBindingResponse.builder()
                .async(false)
                .build());
    } catch (Exception e) {
        LOG.error("Error deleting binding: " + e);
        throw new ServiceBrokerException(e);
    }
}
 
Example 11
private boolean isRemoteConnectBinding(DeleteServiceInstanceBindingRequest deleteRequest) throws IOException {
    String bindingId = deleteRequest.getBindingId();
    ServiceInstanceBinding binding = repository.find(bindingId);
    if (binding == null)
        throw new ServiceInstanceBindingDoesNotExistException(bindingId);
    return isRemoteConnectBinding(binding.getParameters());
}
 
Example 12
@Test
void deleteBindingWithUnknownBindingIdFails() {
	setupCatalogService();

	given(serviceInstanceBindingService
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceBindingDoesNotExistException(SERVICE_INSTANCE_BINDING_ID));

	client.delete().uri(buildDeleteUrl())
			.exchange()
			.expectStatus().is4xxClientError()
			.expectStatus().isEqualTo(HttpStatus.GONE);
}
 
Example 13
/**
 * 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 14
@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 15
@Test
void deleteServiceBindingWithMissingBindingGivesExpectedStatus() {
	given(bindingService.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceBindingDoesNotExistException("binding-id"));

	ResponseEntity<DeleteServiceInstanceBindingResponse> responseEntity = controller
			.deleteServiceInstanceBinding(pathVariables, null, null, "service-definition-id",
					"service-definition-plan-id", false, null, null, null)
			.block();

	assertThat(responseEntity).isNotNull();
	assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.GONE);
}
 
Example 16
@Test
void bindingDoesNotExistException() {
	ErrorMessage errorMessage = exceptionHandler
			.handleException(new ServiceInstanceBindingDoesNotExistException("binding-id"));

	assertThat(errorMessage.getError()).isNull();
	assertThat(errorMessage.getMessage())
			.contains("id=binding-id");
}
 
Example 17
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	if (request.getBindingId() == null) {
		return Mono.error(new ServiceInstanceBindingDoesNotExistException("service-binding-id"));
	}
	return Mono.just(DeleteServiceInstanceBindingResponse.builder().build());
}
 
Example 18
@Override
public void deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request) {
	String bindingId = request.getBindingId();
	ServiceInstanceBinding binding = getServiceInstanceBinding(bindingId);

	if (binding == null) {
		throw new ServiceInstanceBindingDoesNotExistException(bindingId);
	}

	mongo.deleteUser(binding.getServiceInstanceId(), bindingId);
	bindingRepository.delete(bindingId);
}
 
Example 19
@Test(expected = ServiceInstanceBindingDoesNotExistException.class)
public void unknownServiceInstanceDeleteCallSuccessful() throws Exception {
	ServiceInstanceBinding binding = ServiceInstanceBindingFixture.getServiceInstanceBinding();

	when(repository.findOne(any(String.class))).thenReturn(null);

	service.deleteServiceInstanceBinding(buildDeleteRequest());

	verify(mongo, never()).deleteUser(binding.getServiceInstanceId(), binding.getId());
	verify(repository, never()).delete(binding.getId());
}
 
Example 20
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 21
Source Project: tutorials   Source File: MailServiceInstanceBindingService.java    License: MIT License 5 votes vote down vote up
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
    DeleteServiceInstanceBindingRequest request) {
    return mailService.serviceBindingExists(request.getServiceInstanceId(), request.getBindingId())
        .flatMap(exists -> {
            if (exists) {
                return mailService.deleteServiceBinding(request.getServiceInstanceId())
                    .thenReturn(DeleteServiceInstanceBindingResponse.builder().build());
            } else {
                return Mono.error(new ServiceInstanceBindingDoesNotExistException(request.getBindingId()));
            }
        });
}
 
Example 22
/**
 * REST controller for deleting a service instance binding
 *
 * @param pathVariables the path variables
 * @param serviceInstanceId the service instance ID
 * @param bindingId the service binding ID
 * @param serviceDefinitionId the service definition ID
 * @param planId the plan ID
 * @param acceptsIncomplete indicates an asynchronous request
 * @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
 */
@DeleteMapping({PLATFORM_PATH_MAPPING, PATH_MAPPING})
public Mono<ResponseEntity<DeleteServiceInstanceBindingResponse>> deleteServiceInstanceBinding(
		@PathVariable Map<String, String> pathVariables,
		@PathVariable(ServiceBrokerRequest.INSTANCE_ID_PATH_VARIABLE) String serviceInstanceId,
		@PathVariable(ServiceBrokerRequest.BINDING_ID_PATH_VARIABLE) String bindingId,
		@RequestParam(ServiceBrokerRequest.SERVICE_ID_PARAMETER) String serviceDefinitionId,
		@RequestParam(ServiceBrokerRequest.PLAN_ID_PARAMETER) String planId,
		@RequestParam(value = AsyncServiceBrokerRequest.ASYNC_REQUEST_PARAMETER, required = false) boolean acceptsIncomplete,
		@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 getRequiredServiceDefinition(serviceDefinitionId)
			.switchIfEmpty(Mono.just(ServiceDefinition.builder().build()))
			.flatMap(serviceDefinition -> getRequiredServiceDefinitionPlan(serviceDefinition, planId)
					.map(DeleteServiceInstanceBindingRequest.builder()::plan)
					.switchIfEmpty(Mono.just(DeleteServiceInstanceBindingRequest.builder()))
					.map(builder -> builder
							.serviceInstanceId(serviceInstanceId)
							.bindingId(bindingId)
							.serviceDefinitionId(serviceDefinitionId)
							.planId(planId)
							.serviceDefinition(serviceDefinition)
							.asyncAccepted(acceptsIncomplete)
							.platformInstanceId(
									pathVariables.get(ServiceBrokerRequest.PLATFORM_INSTANCE_ID_VARIABLE))
							.apiInfoLocation(apiInfoLocation)
							.originatingIdentity(parseOriginatingIdentity(originatingIdentityString))
							.requestIdentity(requestIdentity)
							.build()))
			.flatMap(req -> service.deleteServiceInstanceBinding(req)
					.doOnRequest(v -> {
						LOG.info("Deleting a service instance binding");
						LOG.debug(DEBUG_REQUEST, req);
					})
					.doOnSuccess(aVoid -> {
						LOG.info("Deleting a service instance binding succeeded");
						LOG.debug("bindingId={}", bindingId);
					})
					.doOnError(e -> LOG.error("Error deleting a service instance binding. error=" +
							e.getMessage(), e)))
			.map(response -> new ResponseEntity<>(response, getAsyncResponseCode(response)))
			.switchIfEmpty(Mono.just(new ResponseEntity<>(HttpStatus.OK)))
			.onErrorResume(e -> {
				if (e instanceof ServiceInstanceBindingDoesNotExistException) {
					return Mono.just(new ResponseEntity<>(HttpStatus.GONE));
				}
				else {
					return Mono.error(e);
				}
			});
}
 
Example 23
/**
 * Handle a {@link ServiceInstanceBindingDoesNotExistException}
 *
 * @param ex the exception
 * @return an error message
 */
@ExceptionHandler(ServiceInstanceBindingDoesNotExistException.class)
@ResponseStatus(HttpStatus.UNPROCESSABLE_ENTITY)
public ErrorMessage handleException(ServiceInstanceBindingDoesNotExistException ex) {
	return getErrorResponse(ex);
}