Java Code Examples for org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse#builder()

The following examples show how to use org.springframework.cloud.servicebroker.model.binding.CreateServiceInstanceAppBindingResponse#builder() . 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: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 5 votes vote down vote up
@Test
void createServiceInstanceAppBindingWithResponseError() {
	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-id")
		.bindResource(BindResource.builder()
			.appGuid("foo-guid")
			.build())
		.build();

	CreateServiceInstanceAppBindingResponseBuilder responseBuilder = CreateServiceInstanceAppBindingResponse
		.builder();

	given(createServiceInstanceAppBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(createServiceInstanceAppBindingWorkflow1
		.buildResponse(eq(request), any(CreateServiceInstanceAppBindingResponseBuilder.class)))
		.willReturn(Mono.error(new ServiceBrokerException("create foo error")));

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

	StepVerifier.create(workflowServiceInstanceBindingService.createServiceInstanceBinding(request))
		.expectErrorSatisfies(e -> assertThat(e)
			.isInstanceOf(ServiceBrokerException.class)
			.hasMessage("create foo error"))
		.verify();
}
 
Example 2
Source File: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void createServiceInstanceAppBinding() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.IN_PROGRESS, "create service instance binding started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.SUCCEEDED, "create service instance binding completed",
				new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.bindResource(BindResource.builder()
			.appGuid("foo-guid")
			.build())
		.build();

	CreateServiceInstanceAppBindingResponseBuilder responseBuilder = CreateServiceInstanceAppBindingResponse
		.builder();
	CreateServiceInstanceAppBindingResponse builtResponse = CreateServiceInstanceAppBindingResponse.builder()
		.async(true)
		.credentials("foo", "bar")
		.operation("working2")
		.build();

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

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

	given(createServiceInstanceAppBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(createServiceInstanceAppBindingWorkflow2.create(eq(request), eq(builtResponse)))
		.willReturn(higherOrderFlow.mono());
	given(createServiceInstanceAppBindingWorkflow2
		.buildResponse(eq(request), any(CreateServiceInstanceAppBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder
			.credentials("foo", "bar")
			.operation("working2")));

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

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

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

			InOrder createOrder = inOrder(createServiceInstanceAppBindingWorkflow1,
				createServiceInstanceAppBindingWorkflow2);
			createOrder.verify(createServiceInstanceAppBindingWorkflow2).buildResponse(eq(request),
				any(CreateServiceInstanceAppBindingResponseBuilder.class));
			createOrder.verify(createServiceInstanceAppBindingWorkflow1).buildResponse(eq(request),
				any(CreateServiceInstanceAppBindingResponseBuilder.class));
			createOrder.verify(createServiceInstanceAppBindingWorkflow2).create(request, responseBuilder.build());
			createOrder.verify(createServiceInstanceAppBindingWorkflow1).create(request, responseBuilder.build());
			createOrder.verifyNoMoreInteractions();

			CreateServiceInstanceAppBindingResponse r = (CreateServiceInstanceAppBindingResponse) response;

			assertThat(r).isNotNull();
			assertThat(r.getCredentials()).containsOnly(entry("foo", "bar"));
			assertThat(r.isAsync()).isTrue();
			assertThat(r.getOperation()).isEqualTo("working2");
		})
		.verifyComplete();
}
 
Example 3
Source File: WorkflowServiceInstanceBindingServiceTest.java    From spring-cloud-app-broker with Apache License 2.0 4 votes vote down vote up
@Test
void createServiceInstanceAppBindingWithAsyncError() {
	given(stateRepository.saveState(anyString(), anyString(), any(OperationState.class), anyString()))
		.willReturn(Mono.just(
			new ServiceInstanceState(OperationState.IN_PROGRESS, "create service instance binding started",
				new Timestamp(Instant.now().minusSeconds(60).toEpochMilli()))))
		.willReturn(
			Mono.just(new ServiceInstanceState(OperationState.FAILED, "create service instance binding failed",
				new Timestamp(Instant.now().minusSeconds(30).toEpochMilli()))));

	CreateServiceInstanceBindingRequest request = CreateServiceInstanceBindingRequest.builder()
		.serviceInstanceId("foo-service")
		.bindingId("foo-binding")
		.bindResource(BindResource.builder()
			.appGuid("foo-guid")
			.build())
		.build();

	CreateServiceInstanceAppBindingResponseBuilder responseBuilder = CreateServiceInstanceAppBindingResponse
		.builder();

	given(createServiceInstanceAppBindingWorkflow1.accept(request))
		.willReturn(Mono.just(true));
	given(createServiceInstanceAppBindingWorkflow1.create(request, responseBuilder.build()))
		.willReturn(Mono.error(new RuntimeException("create foo error")));
	given(createServiceInstanceAppBindingWorkflow1
		.buildResponse(eq(request), any(CreateServiceInstanceAppBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

	given(createServiceInstanceAppBindingWorkflow2.accept(request))
		.willReturn(Mono.just(true));
	given(createServiceInstanceAppBindingWorkflow2.create(request, responseBuilder.build()))
		.willReturn(Mono.empty());
	given(createServiceInstanceAppBindingWorkflow2
		.buildResponse(eq(request), any(CreateServiceInstanceAppBindingResponseBuilder.class)))
		.willReturn(Mono.just(responseBuilder));

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

			InOrder createOrder = inOrder(createServiceInstanceAppBindingWorkflow1,
				createServiceInstanceAppBindingWorkflow2);
			createOrder.verify(createServiceInstanceAppBindingWorkflow2).buildResponse(eq(request),
				any(CreateServiceInstanceAppBindingResponseBuilder.class));
			createOrder.verify(createServiceInstanceAppBindingWorkflow1).buildResponse(eq(request),
				any(CreateServiceInstanceAppBindingResponseBuilder.class));
			createOrder.verify(createServiceInstanceAppBindingWorkflow2).create(request, responseBuilder.build());
			createOrder.verify(createServiceInstanceAppBindingWorkflow1).create(request, responseBuilder.build());
			createOrder.verifyNoMoreInteractions();

			assertThat(response).isNotNull();
			assertThat(response).isInstanceOf(CreateServiceInstanceAppBindingResponse.class);
		})
		.verifyComplete();
}