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

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.DeleteServiceInstanceBindingResponse. 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
private Mono<Void> delete(DeleteServiceInstanceBindingRequest request,
	DeleteServiceInstanceBindingResponse response) {
	return stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
		OperationState.IN_PROGRESS, "delete service instance binding started")
		.thenMany(invokeDeleteWorkflows(request, response)
			.doOnRequest(l -> {
				LOG.info("Deleting service instance binding");
				LOG.debug("request={}", request);
			})
			.doOnComplete(() -> {
				LOG.info("Finish deleting service instance binding");
				LOG.debug("request={}, response={}", request, response);
			})
			.doOnError(e -> LOG.error(String.format("Error deleting service instance binding. error=%s",
				e.getMessage()), e)))
		.thenEmpty(stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
			OperationState.SUCCEEDED, "delete service instance binding completed")
			.then())
		.onErrorResume(
			exception -> stateRepository.saveState(request.getServiceInstanceId(), request.getBindingId(),
				OperationState.FAILED, exception.getMessage())
				.then());
}
 
Example 2
@Test
void deleteCredentialsFromCredHubWhenNotFound() {
	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest
		.builder()
		.bindingId("foo-binding-id")
		.serviceInstanceId("foo-instance-id")
		.serviceDefinitionId("foo-definition-id")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder =
		DeleteServiceInstanceBindingResponse.builder();

	given(this.credHubOperations.credentials())
		.willReturn(credHubCredentialOperations);

	given(this.credHubCredentialOperations.findByName(any()))
		.willReturn(Flux.fromIterable(Collections.emptyList()));

	StepVerifier
		.create(this.workflow.buildResponse(request, responseBuilder))
		.expectNext(responseBuilder)
		.verifyComplete();

	verifyNoMoreInteractions(this.credHubCredentialOperations);
	verifyNoMoreInteractions(this.credHubPermissionOperations);
}
 
Example 3
@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 4
@Test
void deleteBindingWithoutAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.build());

	client.delete().uri(buildDeleteUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.exchange()
			.expectStatus().isOk()
			.expectBody()
			.json("{}");


	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
	assertHeaderValuesSet(actualRequest);
}
 
Example 5
@Test
void deleteBindingFiltersPlansSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.build());

	client.delete().uri(buildDeleteUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.exchange()
			.expectStatus().isOk()
			.expectBody()
			.json("{}");

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
	assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId());
	assertHeaderValuesSet(actualRequest);
}
 
Example 6
@Test
void deleteBindingWithAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.async(true)
			.operation("working")
			.build());

	client.delete().uri(buildDeleteUrl(PLATFORM_INSTANCE_ID, true))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.exchange()
			.expectStatus().isAccepted()
			.expectBody()
			.jsonPath("$.operation").isEqualTo("working");

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true);
	assertHeaderValuesSet(actualRequest);
}
 
Example 7
@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
private void validateDeleteServiceBindingWithResponseStatus(DeleteServiceInstanceBindingResponse response,
		HttpStatus expectedStatus) {
	Mono<DeleteServiceInstanceBindingResponse> responseMono;
	if (response == null) {
		responseMono = Mono.empty();
	}
	else {
		responseMono = Mono.just(response);
	}
	given(bindingService.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class)))
			.willReturn(responseMono);

	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(expectedStatus);
	assertThat(responseEntity.getBody()).isEqualTo(response);

	then(bindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));
}
 
Example 9
@Test
void deleteServiceInstanceBindingSucceeds() {
	prepareBindingFlows();

	StepVerifier
			.create(serviceInstanceBindingEventService.deleteServiceInstanceBinding(
					DeleteServiceInstanceBindingRequest.builder()
							.serviceInstanceId("service-instance-id")
							.bindingId("service-binding-id")
							.build()))
			.expectNext(DeleteServiceInstanceBindingResponse.builder().build())
			.verifyComplete();

	assertThat(this.results.getBeforeCreate()).isNullOrEmpty();
	assertThat(this.results.getAfterCreate()).isNullOrEmpty();
	assertThat(this.results.getErrorCreate()).isNullOrEmpty();
	assertThat(this.results.getBeforeDelete()).isEqualTo("before delete service-instance-id");
	assertThat(this.results.getAfterDelete()).isEqualTo("after delete service-instance-id");
	assertThat(this.results.getErrorDelete()).isNullOrEmpty();
}
 
Example 10
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
	DeleteServiceInstanceBindingRequest request) {
	return invokeDeleteResponseBuilders(request)
		.flatMap(response -> {
			if (response.isAsync()) {
				return Mono.just(response).publishOn(Schedulers.parallel())
					.doOnNext(r -> delete(request, r)
						.subscribe());
			}
			else {
				return delete(request, response).thenReturn(response);
			}
		});
}
 
Example 11
private Mono<DeleteServiceInstanceBindingResponse> invokeDeleteResponseBuilders(
	DeleteServiceInstanceBindingRequest request) {
	AtomicReference<DeleteServiceInstanceBindingResponseBuilder> responseBuilder =
		new AtomicReference<>(DeleteServiceInstanceBindingResponse.builder());

	return Flux.fromIterable(deleteServiceInstanceBindingWorkflows)
		.filterWhen(workflow -> workflow.accept(request))
		.flatMap(workflow -> workflow.buildResponse(request, responseBuilder.get())
			.doOnNext(responseBuilder::set))
		.last(responseBuilder.get())
		.map(DeleteServiceInstanceBindingResponseBuilder::build);
}
 
Example 12
@Test
void deleteServiceInstanceBindingsWithNoWorkflows() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(
			Mono.just(new ServiceInstanceState(OperationState.IN_PROGRESS, "delete service instance started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(
			Mono.just(new ServiceInstanceState(OperationState.SUCCEEDED, "delete service instance completed",
				new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	this.workflowServiceInstanceBindingService = new WorkflowServiceInstanceBindingService(
		this.stateRepository, null, null, null);

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.build();

	StepVerifier.create(workflowServiceInstanceBindingService.deleteServiceInstanceBinding(request))
		.assertNext(response -> {
			InOrder repoOrder = inOrder(stateRepository);
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.IN_PROGRESS),
					eq("delete service instance binding started"));
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.SUCCEEDED),
					eq("delete service instance binding completed"));
			repoOrder.verifyNoMoreInteractions();

			assertThat(response).isNotNull();
			assertThat(response).isInstanceOf(DeleteServiceInstanceBindingResponse.class);
		})
		.verifyComplete();
}
 
Example 13
@Test
void deleteServiceInstanceBindingWithResponseError() {
	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo")
		.bindingId("bar")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder = DeleteServiceInstanceBindingResponse.builder();

	given(deleteServiceInstanceBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow1
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.error(new ServiceBrokerException("delete foo binding error")));

	given(deleteServiceInstanceBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow2
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

	StepVerifier.create(workflowServiceInstanceBindingService.deleteServiceInstanceBinding(request))
		.expectErrorSatisfies(e -> assertThat(e)
			.isInstanceOf(ServiceBrokerException.class)
			.hasMessage("delete foo binding error"))
		.verify();
}
 
Example 14
@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 15
@Test
void deleteBindingWithoutAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.build());

	MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, false))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.contentType(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andExpect(status().isOk())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isOk())
			.andExpect(content().string("{}"));

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
	assertHeaderValuesSet(actualRequest);
}
 
Example 16
@Test
void deleteBindingWithAsyncAndHeadersSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse.builder()
			.async(true)
			.operation("working")
			.build());

	MvcResult mvcResult = mockMvc.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, true))
			.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
			.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
			.accept(MediaType.APPLICATION_JSON)
			.contentType(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andExpect(status().isOk())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isAccepted())
			.andExpect(jsonPath("$.operation", equalTo("working")));

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(true);
	assertHeaderValuesSet(actualRequest);
}
 
Example 17
@Test
void deleteBindingFiltersPlansSucceeds() throws Exception {
	setupCatalogService();

	setupServiceInstanceBindingService(DeleteServiceInstanceBindingResponse
			.builder()
			.build());

	MvcResult mvcResult = mockMvc
			.perform(delete(buildDeleteUrl(PLATFORM_INSTANCE_ID, false))
					.header(API_INFO_LOCATION_HEADER, API_INFO_LOCATION)
					.header(ORIGINATING_IDENTITY_HEADER, buildOriginatingIdentityHeader())
					.contentType(MediaType.APPLICATION_JSON))
			.andExpect(request().asyncStarted())
			.andExpect(status().isOk())
			.andReturn();

	mockMvc.perform(asyncDispatch(mvcResult))
			.andExpect(status().isOk())
			.andExpect(content().string("{}"));

	then(serviceInstanceBindingService)
			.should()
			.deleteServiceInstanceBinding(any(DeleteServiceInstanceBindingRequest.class));

	DeleteServiceInstanceBindingRequest actualRequest = verifyDeleteBinding();
	assertThat(actualRequest.isAsyncAccepted()).isEqualTo(false);
	assertThat(actualRequest.getPlan().getId()).isEqualTo(actualRequest.getPlanId());
	assertHeaderValuesSet(actualRequest);
}
 
Example 18
@Bean
public DeleteServiceInstanceBindingCompletionFlow createCompleteFlow() {
	return new DeleteServiceInstanceBindingCompletionFlow() {
		@Override
		public Mono<Void> complete(DeleteServiceInstanceBindingRequest request,
				DeleteServiceInstanceBindingResponse response) {
			return Mono.empty();
		}
	};
}
 
Example 19
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(DeleteServiceInstanceBindingRequest request) {
	String serviceInstanceId = request.getServiceInstanceId();
	String bindingId = request.getBindingId();

	//
	// delete any binding-specific credentials
	//

	return Mono.just(DeleteServiceInstanceBindingResponse.builder()
			.async(true)
			.build());
}
 
Example 20
@Bean
public DeleteServiceInstanceBindingCompletionFlow deleteServiceInstanceBindingCompletionFlow() {
	return new DeleteServiceInstanceBindingCompletionFlow() {
		@Override
		public Mono<Void> complete(DeleteServiceInstanceBindingRequest request,
				DeleteServiceInstanceBindingResponse response) {
			//
			// do something after the service instance binding is deleted
			//
			return Mono.empty();
		}
	};
}
 
Example 21
@Override
public Mono<DeleteServiceInstanceBindingResponse> deleteServiceInstanceBinding(
		DeleteServiceInstanceBindingRequest request) {
	return flows.getDeleteInstanceBindingRegistry().getInitializationFlows(request)
			.then(service.deleteServiceInstanceBinding(request))
			.onErrorResume(e -> flows.getDeleteInstanceBindingRegistry().getErrorFlows(request, e)
					.then(Mono.error(e)))
			.flatMap(response -> flows.getDeleteInstanceBindingRegistry().getCompletionFlows(request, response)
					.then(Mono.just(response)));
}
 
Example 22
@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 23
@Test
void equalsAndHashCode() {
	EqualsVerifier
			.forClass(AsyncServiceBrokerResponse.class)
			.withRedefinedSubclass(CreateServiceInstanceResponse.class)
			.withRedefinedSubclass(UpdateServiceInstanceResponse.class)
			.withRedefinedSubclass(CreateServiceInstanceBindingResponse.class)
			.withRedefinedSubclass(DeleteServiceInstanceBindingResponse.class)
			.verify();
}
 
Example 24
@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 25
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 26
private Flux<Void> invokeDeleteWorkflows(DeleteServiceInstanceBindingRequest request,
	DeleteServiceInstanceBindingResponse response) {
	return Flux.fromIterable(deleteServiceInstanceBindingWorkflows)
		.filterWhen(workflow -> workflow.accept(request))
		.concatMap(workflow -> workflow.delete(request, response));
}
 
Example 27
default Mono<Void> delete(DeleteServiceInstanceBindingRequest request,
	DeleteServiceInstanceBindingResponse response) {
	return Mono.empty();
}
 
Example 28
@Test
void deleteServiceInstanceBinding() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.IN_PROGRESS, "delete service instance binding started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.SUCCEEDED, "delete service instance binding completed",
				new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder = DeleteServiceInstanceBindingResponse.builder();
	DeleteServiceInstanceBindingResponse builtResponse = DeleteServiceInstanceBindingResponse.builder()
		.async(true)
		.operation("working2")
		.build();

	TestPublisher<Void> lowerOrderFlow = TestPublisher.create();
	TestPublisher<Void> higherOrderFlow = TestPublisher.create();

	given(deleteServiceInstanceBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow1.delete(eq(request), eq(builtResponse)))
		.willReturn(lowerOrderFlow.mono());
	given(deleteServiceInstanceBindingWorkflow1
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder
			.async(true)
			.operation("working1")));

	given(deleteServiceInstanceBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow2.delete(eq(request), eq(builtResponse)))
		.willReturn(higherOrderFlow.mono());
	given(deleteServiceInstanceBindingWorkflow2
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder
			.operation("working2")));

	StepVerifier.create(workflowServiceInstanceBindingService.deleteServiceInstanceBinding(request))
		.assertNext(response -> {
			InOrder repoOrder = inOrder(stateRepository);
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.IN_PROGRESS),
					eq("delete service instance binding started"));
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.SUCCEEDED),
					eq("delete service instance binding completed"));
			repoOrder.verifyNoMoreInteractions();

			lowerOrderFlow.complete();
			lowerOrderFlow.assertWasNotRequested();

			higherOrderFlow.complete();
			lowerOrderFlow.assertWasRequested();

			InOrder deleteOrder = inOrder(deleteServiceInstanceBindingWorkflow1,
				deleteServiceInstanceBindingWorkflow2);
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow2).buildResponse(eq(request),
				any(DeleteServiceInstanceBindingResponseBuilder.class));
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow1).buildResponse(eq(request),
				any(DeleteServiceInstanceBindingResponseBuilder.class));
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow2).delete(request, responseBuilder.build());
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow1).delete(request, responseBuilder.build());
			deleteOrder.verifyNoMoreInteractions();

			assertThat(response).isNotNull();
			assertThat(response.isAsync()).isTrue();
			assertThat(response.getOperation()).isEqualTo("working2");
		})
		.verifyComplete();
}
 
Example 29
@Test
void deleteServiceInstanceBindingWithAsyncError() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(
			Mono.just(new ServiceInstanceState(OperationState.IN_PROGRESS, "delete service instance started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(Mono.just(new ServiceInstanceState(OperationState.FAILED, "delete service instance failed",
			new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder = DeleteServiceInstanceBindingResponse.builder();

	given(deleteServiceInstanceBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow1.delete(request, responseBuilder.build()))
		.willReturn(Mono.error(new RuntimeException("delete foo binding error")));
	given(deleteServiceInstanceBindingWorkflow1
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

	given(deleteServiceInstanceBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(deleteServiceInstanceBindingWorkflow2.delete(request, responseBuilder.build()))
		.willReturn(Mono.empty());
	given(deleteServiceInstanceBindingWorkflow2
		.buildResponse(eq(request), any(DeleteServiceInstanceBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

	StepVerifier.create(workflowServiceInstanceBindingService.deleteServiceInstanceBinding(request))
		.assertNext(response -> {
			InOrder repoOrder = inOrder(stateRepository);
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.IN_PROGRESS),
					eq("delete service instance binding started"));
			repoOrder.verify(stateRepository)
				.saveState(eq("foo-service"), eq("foo-binding"), eq(OperationState.FAILED),
					eq("delete foo binding error"));
			repoOrder.verifyNoMoreInteractions();

			InOrder deleteOrder = inOrder(deleteServiceInstanceBindingWorkflow1,
				deleteServiceInstanceBindingWorkflow2);
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow2).buildResponse(eq(request),
				any(DeleteServiceInstanceBindingResponseBuilder.class));
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow1).buildResponse(eq(request),
				any(DeleteServiceInstanceBindingResponseBuilder.class));
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow2).delete(request, responseBuilder.build());
			deleteOrder.verify(deleteServiceInstanceBindingWorkflow1).delete(request, responseBuilder.build());
			deleteOrder.verifyNoMoreInteractions();

			assertThat(response).isNotNull();
		})
		.verifyComplete();
}
 
Example 30
@Test
void deleteCredentialsFromCredHubWhenFound() {
	CredentialName credentialName = ServiceInstanceCredentialName.builder()
		.serviceBrokerName("test-app-name")
		.serviceOfferingName("foo-definition-id")
		.serviceBindingId("foo-binding-id")
		.credentialName("credentials-json")
		.build();

	DeleteServiceInstanceBindingRequest request = DeleteServiceInstanceBindingRequest
		.builder()
		.bindingId("foo-binding-id")
		.serviceInstanceId("foo-instance-id")
		.serviceDefinitionId("foo-definition-id")
		.build();

	DeleteServiceInstanceBindingResponseBuilder responseBuilder =
		DeleteServiceInstanceBindingResponse.builder();

	given(this.credHubOperations.credentials())
		.willReturn(credHubCredentialOperations);

	given(this.credHubOperations.permissionsV2())
		.willReturn(credHubPermissionV2Operations);

	given(this.credHubOperations.permissions())
		.willReturn(credHubPermissionOperations);

	given(this.credHubCredentialOperations.findByName(credentialName))
		.willReturn(Flux.fromIterable(Collections.singletonList(new CredentialSummary(credentialName))));

	CredentialPermission credentialPermission = new CredentialPermission(credentialName,
		Permission.builder().app("app-id").operation(Operation.READ).build());
	ReflectionTestUtils.setField(credentialPermission, "uuid", "permission-uuid");

	given(this.credHubPermissionV2Operations.getPermissionsByPathAndActor(any(), any()))
		.willReturn(Mono.just(credentialPermission));

	given(this.credHubPermissionV2Operations.deletePermission("permission-uuid"))
		.willReturn(Mono.empty());

	Permission permission = Permission.builder().operation(Operation.READ).client("client-id").build();
	given(this.credHubPermissionOperations.getPermissions(any()))
		.willReturn(Flux.just(permission));

	given(this.credHubCredentialOperations.deleteByName(any()))
		.willReturn(Mono.empty());

	StepVerifier
		.create(this.workflow.buildResponse(request, responseBuilder))
		.expectNext(responseBuilder)
		.verifyComplete();

	verify(this.credHubCredentialOperations, times(1))
		.deleteByName(eq(credentialName));
	verify(this.credHubPermissionV2Operations, times(1))
		.getPermissionsByPathAndActor(eq(credentialName), eq(Actor.client("client-id")));
	verify(this.credHubPermissionV2Operations, times(1))
		.deletePermission(eq("permission-uuid"));

	verifyNoMoreInteractions(this.credHubCredentialOperations);
	verifyNoMoreInteractions(this.credHubPermissionOperations);
	verifyNoMoreInteractions(this.credHubPermissionV2Operations);
}