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

The following examples show how to use org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingDoesNotExistException. 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: MailServiceInstanceBindingServiceUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@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 #2
Source File: BookStoreServiceInstanceBindingService.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@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 #3
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 #4
Source File: BookstoreServiceInstanceBindingServiceTests.java    From bookstore-service-broker with Apache License 2.0 6 votes vote down vote up
@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 #5
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 #6
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: TestServiceInstanceBindingService.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@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 #8
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 #9
Source File: MailServiceInstanceBindingService.java    From tutorials with 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 #10
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 #11
Source File: MongoServiceInstanceBindingServiceTest.java    From cloudfoundry-service-broker with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: MongoServiceInstanceBindingService.java    From cloudfoundry-service-broker with Apache License 2.0 5 votes vote down vote up
@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 #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<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	if (request.getBindingId() == null) {
		return Mono.error(new ServiceInstanceBindingDoesNotExistException("service-binding-id"));
	}
	return Mono.just(DeleteServiceInstanceBindingResponse.builder().build());
}
 
Example #14
Source File: ServiceBrokerExceptionHandlerTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void bindingDoesNotExistException() {
	ErrorMessage errorMessage = exceptionHandler
			.handleException(new ServiceInstanceBindingDoesNotExistException("binding-id"));

	assertThat(errorMessage.getError()).isNull();
	assertThat(errorMessage.getMessage())
			.contains("id=binding-id");
}
 
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 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
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: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@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 #19
Source File: EcsServiceInstanceBindingService.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
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 #20
Source File: EcsServiceInstanceBindingService.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@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 #21
Source File: WorkflowServiceInstanceBindingService.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@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 #22
Source File: ServiceInstanceBindingController.java    From spring-cloud-open-service-broker with Apache License 2.0 4 votes vote down vote up
/**
 * 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
Source File: ServiceBrokerExceptionHandler.java    From spring-cloud-open-service-broker with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}