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

The following examples show how to use org.springframework.cloud.servicebroker.exception.ServiceInstanceBindingExistsException. 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: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void createBindingWithDuplicateIdFails() throws Exception {
	setupCatalogService();

	given(serviceInstanceBindingService
			.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceBindingExistsException(SERVICE_INSTANCE_ID, SERVICE_INSTANCE_BINDING_ID));

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

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isConflict())
			.andExpect(jsonPath("$.description", containsString(SERVICE_INSTANCE_ID)))
			.andExpect(jsonPath("$.description", containsString(SERVICE_INSTANCE_BINDING_ID)));
}
 
Example #2
Source File: ServiceInstanceBindingControllerIntegrationTest.java    From spring-cloud-open-service-broker with Apache License 2.0 6 votes vote down vote up
@Test
void createBindingWithDuplicateIdFails() {
	setupCatalogService();

	given(serviceInstanceBindingService
			.createServiceInstanceBinding(any(CreateServiceInstanceBindingRequest.class)))
			.willThrow(new ServiceInstanceBindingExistsException(SERVICE_INSTANCE_ID, SERVICE_INSTANCE_BINDING_ID));

	client.put().uri(buildCreateUrl())
			.contentType(MediaType.APPLICATION_JSON)
			.bodyValue(createRequestBody)
			.accept(MediaType.APPLICATION_JSON)
			.exchange()
			.expectStatus().is4xxClientError()
			.expectStatus().isEqualTo(HttpStatus.CONFLICT)
			.expectBody()
			.jsonPath("$.description").isNotEmpty()
			.consumeWith(result -> assertDescriptionContains(result,
					String.format("serviceInstanceId=%s, bindingId=%s", SERVICE_INSTANCE_ID,
							SERVICE_INSTANCE_BINDING_ID)));
}
 
Example #3
Source File: RemoteConnectBindingWorkflow.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public void checkIfUserExists() throws EcsManagementClientException, IOException {
    ServiceInstance instance = instanceRepository.find(instanceId);
    if (instance == null)
        throw new ServiceInstanceDoesNotExistException(instanceId);
    if (instance.remoteConnectionKeyExists(bindingId))
        throw new ServiceInstanceBindingExistsException(instanceId, bindingId);
}
 
Example #4
Source File: EcsServiceInstanceBindingServiceTest.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * If the binding-service attempts to create a namespace user that already
 * exists, the service will throw an error.
 */
@Test(expected = ServiceInstanceBindingExistsException.class)
public void testCreateExistingNamespaceUserFails() {
    when(ecs.lookupServiceDefinition(NAMESPACE_SERVICE_ID))
            .thenReturn(namespaceServiceFixture());
    when(ecs.userExists(BINDING_ID)).thenReturn(true);

    bindSvc.createServiceInstanceBinding(namespaceBindingRequestFixture());
}
 
Example #5
Source File: EcsServiceInstanceBindingServiceTest.java    From ecs-cf-service-broker with Apache License 2.0 5 votes vote down vote up
/**
 * If the binding-service attempts to create a bucket user that already
 * exists, the service will throw an error.
 */
@Test(expected = ServiceInstanceBindingExistsException.class)
public void testCreateExistingBucketUserFails() {
    when(ecs.lookupServiceDefinition(BUCKET_SERVICE_ID)).thenReturn(bucketServiceFixture());
    when(ecs.userExists(BINDING_ID)).thenReturn(true);

    bindSvc.createServiceInstanceBinding(
            bucketBindingPermissionRequestFixture());
}
 
Example #6
Source File: ServiceBrokerExceptionHandlerTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Test
void bindingExistsException() {
	ErrorMessage errorMessage = exceptionHandler
			.handleException(new ServiceInstanceBindingExistsException("service-instance-id", "binding-id"));

	assertThat(errorMessage.getError()).isNull();
	assertThat(errorMessage.getMessage())
			.contains("serviceInstanceId=service-instance-id")
			.contains("bindingId=binding-id");
}
 
Example #7
Source File: ServiceInstanceBindingEventServiceTest.java    From spring-cloud-open-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public Mono<CreateServiceInstanceBindingResponse> createServiceInstanceBinding(
		CreateServiceInstanceBindingRequest request) {
	if (request.getServiceDefinitionId() == null) {
		return Mono.error(new ServiceInstanceBindingExistsException("service-instance-id", "arrrr"));
	}
	return Mono.just(CreateServiceInstanceAppBindingResponse.builder().build());
}
 
Example #8
Source File: MongoServiceInstanceBindingService.java    From cloudfoundry-service-broker with Apache License 2.0 5 votes vote down vote up
@Override
public CreateServiceInstanceBindingResponse createServiceInstanceBinding(CreateServiceInstanceBindingRequest request) {

	String bindingId = request.getBindingId();
	String serviceInstanceId = request.getServiceInstanceId();

	ServiceInstanceBinding binding = bindingRepository.findOne(bindingId);
	if (binding != null) {
		throw new ServiceInstanceBindingExistsException(serviceInstanceId, bindingId);
	}

	String database = serviceInstanceId;
	String username = bindingId;
	String password = RandomStringUtils.randomAlphanumeric(25);
	
	// TODO check if user already exists in the DB

	mongo.createUser(database, username, password);
	
	Map<String, Object> credentials =
			Collections.singletonMap("uri", (Object) mongo.getConnectionString(database, username, password));

	binding = new ServiceInstanceBinding(bindingId, serviceInstanceId, credentials, null, request.getBoundAppGuid());
	bindingRepository.save(binding);
	
	return new CreateServiceInstanceAppBindingResponse().withCredentials(credentials);
}
 
Example #9
Source File: MongoServiceInstanceBindingServiceTest.java    From cloudfoundry-service-broker with Apache License 2.0 5 votes vote down vote up
@Test(expected = ServiceInstanceBindingExistsException.class)
public void serviceInstanceCreationFailsWithExistingInstance() throws Exception {

	when(repository.findOne(any(String.class)))
			.thenReturn(ServiceInstanceBindingFixture.getServiceInstanceBinding());

	service.createServiceInstanceBinding(buildCreateRequest());
}
 
Example #10
Source File: BucketBindingWorkflow.java    From ecs-cf-service-broker with Apache License 2.0 4 votes vote down vote up
public void checkIfUserExists() throws EcsManagementClientException, IOException {
    if (ecs.userExists(bindingId))
        throw new ServiceInstanceBindingExistsException(instanceId, bindingId);
}
 
Example #11
Source File: NamespaceBindingWorkflow.java    From ecs-cf-service-broker with Apache License 2.0 4 votes vote down vote up
public void checkIfUserExists() {
    if (ecs.userExists(bindingId))
        throw new ServiceInstanceBindingExistsException(instanceId, bindingId);
}
 
Example #12
Source File: ServiceBrokerExceptionHandler.java    From spring-cloud-open-service-broker with Apache License 2.0 2 votes vote down vote up
/**
 * Handle a {@link ServiceInstanceBindingExistsException}
 *
 * @param ex the exception
 * @return an error message
 */
@ExceptionHandler(ServiceInstanceBindingExistsException.class)
@ResponseStatus(HttpStatus.CONFLICT)
public ErrorMessage handleException(ServiceInstanceBindingExistsException ex) {
	return getErrorResponse(ex);
}