Java Code Examples for org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse#builder()
The following examples show how to use
org.springframework.cloud.servicebroker.model.instance.CreateServiceInstanceResponse#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: WorkflowServiceInstanceService.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
private Mono<CreateServiceInstanceResponse> invokeCreateResponseBuilders(CreateServiceInstanceRequest request) { AtomicReference<CreateServiceInstanceResponseBuilder> responseBuilder = new AtomicReference<>(CreateServiceInstanceResponse.builder()); return Flux.fromIterable(createServiceInstanceWorkflows) .filterWhen(workflow -> workflow.accept(request)) .flatMap(workflow -> workflow.buildResponse(request, responseBuilder.get()) .doOnNext(responseBuilder::set)) .last(responseBuilder.get()) .map(CreateServiceInstanceResponseBuilder::build); }
Example 2
Source File: WorkflowServiceInstanceServiceTest.java From spring-cloud-app-broker with Apache License 2.0 | 5 votes |
@Test void createServiceInstanceWithResponseError() { CreateServiceInstanceRequest request = CreateServiceInstanceRequest.builder() .serviceInstanceId("foo") .build(); CreateServiceInstanceResponseBuilder responseBuilder = CreateServiceInstanceResponse.builder(); given(createServiceInstanceWorkflow1.accept(request)) .willReturn(Mono.just(true)); given( createServiceInstanceWorkflow1 .buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class))) .willReturn(Mono.error(new ServiceBrokerException("create foo error"))); given(createServiceInstanceWorkflow2.accept(request)) .willReturn(Mono.just(true)); given( createServiceInstanceWorkflow2 .buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder)); StepVerifier.create(workflowServiceInstanceService.createServiceInstance(request)) .expectErrorSatisfies(e -> assertThat(e) .isInstanceOf(ServiceBrokerException.class) .hasMessage("create foo error")) .verify(); }
Example 3
Source File: WorkflowServiceInstanceServiceTest.java From spring-cloud-app-broker with Apache License 2.0 | 4 votes |
@Test void createServiceInstance() { given(serviceInstanceStateRepository.saveState(anyString(), any(OperationState.class), anyString())) .willReturn( Mono.just( new ServiceInstanceState(OperationState.IN_PROGRESS, "create service instance started", new Timestamp(Instant.now().minusSeconds(60).toEpochMilli())))) .willReturn( Mono.just( new ServiceInstanceState(OperationState.SUCCEEDED, "create service instance completed", new Timestamp(Instant.now().minusSeconds(300).toEpochMilli())))); CreateServiceInstanceRequest request = CreateServiceInstanceRequest.builder() .serviceInstanceId("foo") .build(); CreateServiceInstanceResponseBuilder responseBuilder = CreateServiceInstanceResponse.builder(); CreateServiceInstanceResponse builtResponse = CreateServiceInstanceResponse.builder() .async(true) .dashboardUrl("https://dashboard.example.local") .operation("working2") .build(); TestPublisher<Void> lowerOrderFlow = TestPublisher.create(); TestPublisher<Void> higherOrderFlow = TestPublisher.create(); given(createServiceInstanceWorkflow1.accept(request)) .willReturn(Mono.just(true)); given(createServiceInstanceWorkflow1.create(eq(request), eq(builtResponse))) .willReturn(lowerOrderFlow.mono()); given( createServiceInstanceWorkflow1 .buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder .async(true) .operation("working1"))); given(createServiceInstanceWorkflow2.accept(request)) .willReturn(Mono.just(true)); given(createServiceInstanceWorkflow2.create(eq(request), eq(builtResponse))) .willReturn(higherOrderFlow.mono()); given(createServiceInstanceWorkflow2 .buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder .dashboardUrl("https://dashboard.example.local") .operation("working2"))); StepVerifier.create(workflowServiceInstanceService.createServiceInstance(request)) .assertNext(response -> { InOrder repoOrder = inOrder(serviceInstanceStateRepository); repoOrder.verify(serviceInstanceStateRepository) .saveState(eq("foo"), eq(OperationState.IN_PROGRESS), eq("create service instance started")); repoOrder.verify(serviceInstanceStateRepository) .saveState(eq("foo"), eq(OperationState.SUCCEEDED), eq("create service instance completed")); repoOrder.verifyNoMoreInteractions(); lowerOrderFlow.complete(); lowerOrderFlow.assertWasNotRequested(); higherOrderFlow.complete(); lowerOrderFlow.assertWasRequested(); InOrder createOrder = inOrder(createServiceInstanceWorkflow1, createServiceInstanceWorkflow2); createOrder.verify(createServiceInstanceWorkflow2).buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class)); createOrder.verify(createServiceInstanceWorkflow1).buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class)); createOrder.verify(createServiceInstanceWorkflow2).create(request, responseBuilder.build()); createOrder.verify(createServiceInstanceWorkflow1).create(request, responseBuilder.build()); createOrder.verifyNoMoreInteractions(); assertThat(response).isNotNull(); assertThat(response.isAsync()).isTrue(); assertThat(response.getDashboardUrl()).isEqualTo("https://dashboard.example.local"); assertThat(response.getOperation()).isEqualTo("working2"); }) .verifyComplete(); }
Example 4
Source File: WorkflowServiceInstanceServiceTest.java From spring-cloud-app-broker with Apache License 2.0 | 4 votes |
@Test void createServiceInstanceWithAsyncError() { given(serviceInstanceStateRepository.saveState(anyString(), any(OperationState.class), anyString())) .willReturn( Mono.just( new ServiceInstanceState(OperationState.IN_PROGRESS, "create service instance started", new Timestamp(Instant.now().minusSeconds(60).toEpochMilli())))) .willReturn(Mono.just(new ServiceInstanceState(OperationState.FAILED, "create service instance failed", new Timestamp(Instant.now().minusSeconds(30).toEpochMilli())))); CreateServiceInstanceRequest request = CreateServiceInstanceRequest.builder() .serviceInstanceId("foo") .build(); CreateServiceInstanceResponseBuilder responseBuilder = CreateServiceInstanceResponse.builder(); given(createServiceInstanceWorkflow1.accept(request)) .willReturn(Mono.just(true)); given(createServiceInstanceWorkflow1.create(request, responseBuilder.build())) .willReturn(Mono.error(new RuntimeException("create foo error"))); given( createServiceInstanceWorkflow1 .buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder)); given(createServiceInstanceWorkflow2.accept(request)) .willReturn(Mono.just(true)); given(createServiceInstanceWorkflow2.create(request, responseBuilder.build())) .willReturn(Mono.empty()); given( createServiceInstanceWorkflow2 .buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class))) .willReturn(Mono.just(responseBuilder)); StepVerifier.create(workflowServiceInstanceService.createServiceInstance(request)) .assertNext(response -> { InOrder repoOrder = inOrder(serviceInstanceStateRepository); repoOrder.verify(serviceInstanceStateRepository) .saveState(eq("foo"), eq(OperationState.IN_PROGRESS), eq("create service instance started")); repoOrder.verify(serviceInstanceStateRepository) .saveState(eq("foo"), eq(OperationState.FAILED), eq("create foo error")); repoOrder.verifyNoMoreInteractions(); InOrder createOrder = inOrder(createServiceInstanceWorkflow1, createServiceInstanceWorkflow2); createOrder.verify(createServiceInstanceWorkflow2).buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class)); createOrder.verify(createServiceInstanceWorkflow1).buildResponse(eq(request), any(CreateServiceInstanceResponseBuilder.class)); createOrder.verify(createServiceInstanceWorkflow2).create(request, responseBuilder.build()); createOrder.verify(createServiceInstanceWorkflow1).create(request, responseBuilder.build()); createOrder.verifyNoMoreInteractions(); assertThat(response).isNotNull(); }) .verifyComplete(); }