diff --git a/.github/workflows/ci-java-8-and-11.yml b/.github/workflows/ci-java-8-and-11.yml index 27082a618ad..468a54178ab 100644 --- a/.github/workflows/ci-java-8-and-11.yml +++ b/.github/workflows/ci-java-8-and-11.yml @@ -33,7 +33,9 @@ jobs: restore-keys: ${{ runner.os }}-m2 - name: Build with Maven run: ./mvnw clean package -Dgpg.skip + - name: Compile integration tests + run: ./mvnw -Pintegration-test test-compile compile - if: ${{ matrix.java != 8 }} name: Check style with Spotless - run: ./mvnw spotless:check + run: ./mvnw spotless:check -Pintegration-test diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index 3817c35541d..00000000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -cloudfoundry-java-client \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml deleted file mode 100644 index f4ec93d14cd..00000000000 --- a/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,449 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml deleted file mode 100644 index 79ee123c2b2..00000000000 --- a/.idea/codeStyles/codeStyleConfig.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 1d6ce3c640e..00000000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/Apache_License__Version_2_0.xml b/.idea/copyright/Apache_License__Version_2_0.xml deleted file mode 100644 index 893ada61a7c..00000000000 --- a/.idea/copyright/Apache_License__Version_2_0.xml +++ /dev/null @@ -1,9 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index 2fca47b2b32..00000000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/.idea/dictionaries/bhale.xml b/.idea/dictionaries/bhale.xml deleted file mode 100644 index f5368121b65..00000000000 --- a/.idea/dictionaries/bhale.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - deserialized - dropsonde - evictor - gibi - keepalive - kibi - mibi - mibibyte - relativize - scim - tcproutes - timespan - unshare - upsert - yhoo - - - \ No newline at end of file diff --git a/.idea/dictionaries/project.xml b/.idea/dictionaries/project.xml deleted file mode 100644 index 2e81ec68354..00000000000 --- a/.idea/dictionaries/project.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - acfbae - actee - actees - adff - backoff - bufs - buildpacks - cflinuxfs - codec - containermetrics - ctxt - datas - diegos - firehose - gradle - guids - metadatas - micropcf - mkactivity - mkcalendar - mkredirectref - mkworkspace - okhttp - orderpatch - procfile - recentlogs - restage - showmethod - spacejump - springapps - staticfile - textsearch - truster - truststore - uncheckout - unmap - updateredirectref - uptime - whatuuid - - - diff --git a/.idea/encodings.xml b/.idea/encodings.xml deleted file mode 100644 index f939b983d38..00000000000 --- a/.idea/encodings.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/google-java-format.xml b/.idea/google-java-format.xml deleted file mode 100644 index 2aa056da349..00000000000 --- a/.idea/google-java-format.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index 212e4222738..00000000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index 3b312839bf2..00000000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 1c24f9a8de4..00000000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index a1043f84492..00000000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 797acea53eb..00000000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/TestServiceBroker.xml b/.idea/runConfigurations/TestServiceBroker.xml deleted file mode 100644 index de50e7e26f1..00000000000 --- a/.idea/runConfigurations/TestServiceBroker.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/cloudfoundry_client.xml b/.idea/runConfigurations/cloudfoundry_client.xml deleted file mode 100644 index 00e5b6ea595..00000000000 --- a/.idea/runConfigurations/cloudfoundry_client.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/cloudfoundry_client_reactor.xml b/.idea/runConfigurations/cloudfoundry_client_reactor.xml deleted file mode 100644 index de82ed2bbc0..00000000000 --- a/.idea/runConfigurations/cloudfoundry_client_reactor.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/cloudfoundry_operations.xml b/.idea/runConfigurations/cloudfoundry_operations.xml deleted file mode 100644 index 03d3cad96d4..00000000000 --- a/.idea/runConfigurations/cloudfoundry_operations.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/cloudfoundry_util.xml b/.idea/runConfigurations/cloudfoundry_util.xml deleted file mode 100644 index 7a32364ae65..00000000000 --- a/.idea/runConfigurations/cloudfoundry_util.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/integration_test.xml b/.idea/runConfigurations/integration_test.xml deleted file mode 100644 index d8fd72e7b89..00000000000 --- a/.idea/runConfigurations/integration_test.xml +++ /dev/null @@ -1,26 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations/test_service_broker__package_.xml b/.idea/runConfigurations/test_service_broker__package_.xml deleted file mode 100644 index b1d3fbf9241..00000000000 --- a/.idea/runConfigurations/test_service_broker__package_.xml +++ /dev/null @@ -1,29 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml deleted file mode 100644 index e96534fb27b..00000000000 --- a/.idea/uiDesigner.xml +++ /dev/null @@ -1,124 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 590a612f67c..00000000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/ci/integration-test.sh b/ci/integration-test.sh index 789f612213d..4091ca6c7ca 100755 --- a/ci/integration-test.sh +++ b/ci/integration-test.sh @@ -35,4 +35,4 @@ TEST_ADMIN_CLIENTSECRET=$(jq -n -r --argjson credentials "${UAA_CREDS}" '$creden export TEST_ADMIN_CLIENTSECRET cd cf-java-client -./mvnw -q -P integration-test test +./mvnw -P integration-test test diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java index 29d208aad47..319a1bcfd6f 100644 --- a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/_ReactorCloudFoundryClient.java @@ -34,6 +34,7 @@ import org.cloudfoundry.client.v2.routemappings.RouteMappings; import org.cloudfoundry.client.v2.routes.Routes; import org.cloudfoundry.client.v2.securitygroups.SecurityGroups; +import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3; import org.cloudfoundry.client.v2.servicebindings.ServiceBindingsV2; import org.cloudfoundry.client.v2.servicebrokers.ServiceBrokers; import org.cloudfoundry.client.v2.serviceinstances.ServiceInstances; @@ -91,6 +92,7 @@ import org.cloudfoundry.reactor.client.v2.routemappings.ReactorRouteMappings; import org.cloudfoundry.reactor.client.v2.routes.ReactorRoutes; import org.cloudfoundry.reactor.client.v2.securitygroups.ReactorSecurityGroups; +import org.cloudfoundry.reactor.client.v3.securitygroups.ReactorSecurityGroupsV3; import org.cloudfoundry.reactor.client.v2.servicebindings.ReactorServiceBindingsV2; import org.cloudfoundry.reactor.client.v2.servicebrokers.ReactorServiceBrokers; import org.cloudfoundry.reactor.client.v2.serviceinstances.ReactorServiceInstances; @@ -151,7 +153,8 @@ public AdminV3 adminV3() { @Override @Value.Derived public ApplicationUsageEvents applicationUsageEvents() { - return new ReactorApplicationUsageEvents(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorApplicationUsageEvents(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -228,7 +231,8 @@ public Droplets droplets() { @Override @Value.Derived public EnvironmentVariableGroups environmentVariableGroups() { - return new ReactorEnvironmentVariableGroups(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorEnvironmentVariableGroups(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -270,7 +274,8 @@ public JobsV3 jobsV3() { @Override @Value.Derived public OrganizationQuotaDefinitions organizationQuotaDefinitions() { - return new ReactorOrganizationQuotaDefinitions(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorOrganizationQuotaDefinitions(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -345,6 +350,12 @@ public SecurityGroups securityGroups() { return new ReactorSecurityGroups(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); } + @Override + @Value.Derived + public SecurityGroupsV3 securityGroupsV3() { + return new ReactorSecurityGroupsV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags()); + } + @Override @Value.Derived public ServiceBindingsV2 serviceBindingsV2() { @@ -366,7 +377,7 @@ public ServiceBrokers serviceBrokers() { @Override @Value.Derived public ServiceBrokersV3 serviceBrokersV3() { - return new ReactorServiceBrokersV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags()); + return new ReactorServiceBrokersV3(getConnectionContext(), getRootV3(), getTokenProvider(), getRequestTags()); } @Override @@ -396,7 +407,8 @@ public ServiceOfferingsV3 serviceOfferingsV3() { @Override @Value.Derived public ServicePlanVisibilities servicePlanVisibilities() { - return new ReactorServicePlanVisibilities(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorServicePlanVisibilities(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -432,7 +444,8 @@ public SharedDomains sharedDomains() { @Override @Value.Derived public SpaceQuotaDefinitions spaceQuotaDefinitions() { - return new ReactorSpaceQuotaDefinitions(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorSpaceQuotaDefinitions(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -468,7 +481,8 @@ public Tasks tasks() { @Override @Value.Derived public UserProvidedServiceInstances userProvidedServiceInstances() { - return new ReactorUserProvidedServiceInstances(getConnectionContext(), getRootV2(), getTokenProvider(), getRequestTags()); + return new ReactorUserProvidedServiceInstances(getConnectionContext(), getRootV2(), getTokenProvider(), + getRequestTags()); } @Override @@ -483,7 +497,8 @@ public Users users() { abstract ConnectionContext getConnectionContext(); /** - * Map of http header name and value which will be added to every request to the controller + * Map of http header name and value which will be added to every request to the + * controller */ @Value.Default Map getRequestTags() { diff --git a/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java new file mode 100644 index 00000000000..adea2b5f86a --- /dev/null +++ b/cloudfoundry-client-reactor/src/main/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3.java @@ -0,0 +1,201 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.reactor.client.v3.securitygroups; + +import java.util.Map; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3; +import org.cloudfoundry.client.v3.securitygroups.UnbindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UnbindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse; +import org.cloudfoundry.client.v3.servicebindings.ServiceBindingsV3; +import org.cloudfoundry.reactor.ConnectionContext; +import org.cloudfoundry.reactor.TokenProvider; +import org.cloudfoundry.reactor.client.v3.AbstractClientV3Operations; +import reactor.core.publisher.Mono; + +/** + * The Reactor-based implementation of {@link ServiceBindingsV3} + */ +public final class ReactorSecurityGroupsV3 extends AbstractClientV3Operations + implements SecurityGroupsV3 { + + /** + * Creates an instance + * + * @param connectionContext the {@link ConnectionContext} to use when communicating with the + * server + * @param root the root URI of the server. Typically something like + * {@code https://api.run.pivotal.io}. + * @param tokenProvider the {@link TokenProvider} to use when communicating with the server + * @param requestTags map with custom http headers which will be added to web request + */ + public ReactorSecurityGroupsV3( + ConnectionContext connectionContext, + Mono root, + TokenProvider tokenProvider, + Map requestTags) { + super(connectionContext, root, tokenProvider, requestTags); + } + + @Override + public Mono create(CreateSecurityGroupRequest request) { + return post( + request, + CreateSecurityGroupResponse.class, + builder -> builder.pathSegment("security_groups")) + .checkpoint(); + } + + @Override + public Mono get(GetSecurityGroupRequest request) { + return get( + request, + GetSecurityGroupResponse.class, + builder -> + builder.pathSegment( + "security_groups", request.getSecurityGroupId())) + .checkpoint(); + } + + @Override + public Mono list(ListSecurityGroupsRequest request) { + return get( + request, + ListSecurityGroupsResponse.class, + builder -> builder.pathSegment("security_groups")) + .checkpoint(); + } + + @Override + public Mono update(UpdateSecurityGroupRequest request) { + return patch( + request, + UpdateSecurityGroupResponse.class, + builder -> + builder.pathSegment( + "security_groups", request.getSecurityGroupId())) + .checkpoint(); + } + + @Override + public Mono delete(DeleteSecurityGroupRequest request) { + return delete( + request, + builder -> + builder.pathSegment( + "security_groups", request.getSecurityGroupId())) + .checkpoint(); + } + + @Override + public Mono bindRunningSecurityGroup( + BindRunningSecurityGroupRequest request) { + return post( + request, + BindRunningSecurityGroupResponse.class, + builder -> + builder.pathSegment( + "security_groups", + request.getSecurityGroupId(), + "relationships", + "running_spaces")) + .checkpoint(); + } + + @Override + public Mono bindStagingSecurityGroup( + BindStagingSecurityGroupRequest request) { + return post( + request, + BindStagingSecurityGroupResponse.class, + builder -> + builder.pathSegment( + "security_groups", + request.getSecurityGroupId(), + "relationships", + "staging_spaces")) + .checkpoint(); + } + + @Override + public Mono unbindStagingSecurityGroup(UnbindStagingSecurityGroupRequest request) { + return delete( + request, + Void.class, + builder -> + builder.pathSegment( + "security_groups", + request.getSecurityGroupId(), + "relationships", + "staging_spaces", + request.getSpaceId())) + .checkpoint(); + } + + @Override + public Mono unbindRunningSecurityGroup(UnbindRunningSecurityGroupRequest request) { + return delete( + request, + Void.class, + builder -> + builder.pathSegment( + "security_groups", + request.getSecurityGroupId(), + "relationships", + "running_spaces", + request.getSpaceId())) + .checkpoint(); + } + + @Override + public Mono listRunning( + ListRunningSecurityGroupsRequest request) { + return get( + request, + ListRunningSecurityGroupsResponse.class, + builder -> + builder.pathSegment( + "spaces", request.getSpaceId(), "running_security_groups")) + .checkpoint(); + } + + @Override + public Mono listStaging( + ListStagingSecurityGroupsRequest request) { + return get( + request, + ListStagingSecurityGroupsResponse.class, + builder -> + builder.pathSegment( + "spaces", request.getSpaceId(), "staging_security_groups")) + .checkpoint(); + } +} diff --git a/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java new file mode 100644 index 00000000000..7ffeece9ffc --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/java/org/cloudfoundry/reactor/client/v3/securitygroups/ReactorSecurityGroupsV3Test.java @@ -0,0 +1,885 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.reactor.client.v3.securitygroups; + +import static io.netty.handler.codec.http.HttpMethod.DELETE; +import static io.netty.handler.codec.http.HttpMethod.GET; +import static io.netty.handler.codec.http.HttpMethod.PATCH; +import static io.netty.handler.codec.http.HttpMethod.POST; +import static io.netty.handler.codec.http.HttpResponseStatus.ACCEPTED; +import static io.netty.handler.codec.http.HttpResponseStatus.CREATED; +import static io.netty.handler.codec.http.HttpResponseStatus.NO_CONTENT; +import static io.netty.handler.codec.http.HttpResponseStatus.OK; + +import java.time.Duration; +import java.util.Collections; +import org.cloudfoundry.client.v3.Link; +import org.cloudfoundry.client.v3.Pagination; +import org.cloudfoundry.client.v3.Relationship; +import org.cloudfoundry.client.v3.ToManyRelationship; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.GloballyEnabled; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsResponse; +import org.cloudfoundry.client.v3.securitygroups.Protocol; +import org.cloudfoundry.client.v3.securitygroups.Relationships; +import org.cloudfoundry.client.v3.securitygroups.Rule; +import org.cloudfoundry.client.v3.securitygroups.SecurityGroupResource; +import org.cloudfoundry.client.v3.securitygroups.UnbindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UnbindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupResponse; +import org.cloudfoundry.reactor.InteractionContext; +import org.cloudfoundry.reactor.TestRequest; +import org.cloudfoundry.reactor.TestResponse; +import org.cloudfoundry.reactor.client.AbstractClientApiTest; +import org.junit.jupiter.api.Test; +import reactor.test.StepVerifier; + +public final class ReactorSecurityGroupsV3Test extends AbstractClientApiTest { + + private final ReactorSecurityGroupsV3 securityGroups = + new ReactorSecurityGroupsV3( + CONNECTION_CONTEXT, this.root, TOKEN_PROVIDER, Collections.emptyMap()); + + @Test + public void create() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(POST) + .path("/security_groups") + .payload( + "fixtures/client/v3/security_groups/POST_request.json") + .build()) + .response( + TestResponse.builder() + .status(CREATED) + .payload( + "fixtures/client/v3/security_groups/POST_response.json") + .build()) + .build()); + this.securityGroups + .create( + CreateSecurityGroupRequest.builder() + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .name("my-group0") + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description( + "Allow ping requests to private services") + .type(8) + .code(0) + .build()) + .build()) + .as(StepVerifier::create) + .expectNext( + CreateSecurityGroupResponse.builder() + .name("my-group0") + .id("b85a788e-671f-4549-814d-e34cdb2f539a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .globallyEnabled( + GloballyEnabled.builder() + .staging(false) + .running(true) + .build()) + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description( + "Allow ping requests to private services") + .type(8) + .code(0) + .build()) + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .data( + Relationship.builder() + .id("space-guid-1") + .build()) + .data( + Relationship.builder() + .id("space-guid-2") + .build()) + .build()) + .runningSpaces(ToManyRelationship.builder().build()) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void get() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(GET) + .path( + "/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/security_groups/GET_{id}_response.json") + .build()) + .build()); + this.securityGroups + .get( + GetSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .as(StepVerifier::create) + .expectNext( + GetSecurityGroupResponse.builder() + .name("my-group0") + .id("b85a788e-671f-4549-814d-e34cdb2f539a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .globallyEnabled( + GloballyEnabled.builder() + .staging(false) + .running(true) + .build()) + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description( + "Allow ping requests to private services") + .type(8) + .code(0) + .build()) + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .data( + Relationship.builder() + .id("space-guid-1") + .build()) + .data( + Relationship.builder() + .id("space-guid-2") + .build()) + .build()) + .runningSpaces(ToManyRelationship.builder().build()) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void list() { + mockRequest( + InteractionContext.builder() + .request(TestRequest.builder().method(GET).path("/security_groups").build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/security_groups/GET_response.json") + .build()) + .build()); + + this.securityGroups + .list(ListSecurityGroupsRequest.builder().build()) + .as(StepVerifier::create) + .expectNext( + ListSecurityGroupsResponse.builder() + .pagination( + Pagination.builder() + .totalResults(1) + .totalPages(1) + .first( + Link.builder() + .href( + "https://api.example.org/v3/security_groups?page=1&per_page=50") + .build()) + .last( + Link.builder() + .href( + "https://api.example.org/v3/security_groups?page=1&per_page=50") + .build()) + .build()) + .resource( + SecurityGroupResource.builder() + .name("my-group0") + .id("b85a788e-671f-4549-814d-e34cdb2f539a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .globallyEnabled( + GloballyEnabled.builder() + .staging(false) + .running(true) + .build()) + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description( + "Allow ping requests to" + + " private services") + .type(8) + .code(0) + .build()) + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .data( + Relationship + .builder() + .id( + "space-guid-1") + .build()) + .data( + Relationship + .builder() + .id( + "space-guid-2") + .build()) + .build()) + .runningSpaces( + ToManyRelationship.builder() + .build()) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()) + .resource( + SecurityGroupResource.builder() + .name("my-group1") + .id("a89a788e-671f-4549-814d-e34c1b2f533a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .build()) + .runningSpaces( + ToManyRelationship.builder() + .build()) + .build()) + .globallyEnabled( + GloballyEnabled.builder() + .staging(true) + .running(true) + .build()) + .globallyEnabled( + GloballyEnabled.builder() + .staging(true) + .running(true) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a") + .build()) + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void update() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(PATCH) + .path( + "/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .payload( + "fixtures/client/v3/security_groups/PATCH_{id}_request.json") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/security_groups/PATCH_{id}_response.json") + .build()) + .build()); + this.securityGroups + .update( + UpdateSecurityGroupRequest.builder() + .name("my-group0") + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .globallyEnabled(GloballyEnabled.builder().running(true).build()) + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description( + "Allow ping requests to private services") + .type(8) + .code(0) + .build()) + .build()) + .as(StepVerifier::create) + .expectNext( + UpdateSecurityGroupResponse.builder() + .name("my-group0") + .id("b85a788e-671f-4549-814d-e34cdb2f539a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .globallyEnabled( + GloballyEnabled.builder() + .staging(false) + .running(true) + .build()) + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description( + "Allow ping requests to private services") + .type(8) + .code(0) + .build()) + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .data( + Relationship.builder() + .id("space-guid-1") + .build()) + .data( + Relationship.builder() + .id("space-guid-2") + .build()) + .build()) + .runningSpaces(ToManyRelationship.builder().build()) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void delete() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(DELETE) + .path( + "/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .response( + TestResponse.builder() + .status(ACCEPTED) + .header( + "Location", + "https://api.example.org/v3/jobs/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()); + + this.securityGroups + .delete( + DeleteSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .as(StepVerifier::create) + .expectNext("b85a788e-671f-4549-814d-e34cdb2f539a") + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void bindStagingSecurityGroup() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(POST) + .path( + "/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces") + .payload( + "fixtures/client/v3/security_groups/bind_staging/POST_request.json") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/security_groups/bind_staging/POST_response.json") + .build()) + .build()); + this.securityGroups + .bindStagingSecurityGroup( + BindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .boundSpaces(Relationship.builder().id("space-guid1").build()) + .boundSpaces(Relationship.builder().id("space-guid2").build()) + .build()) + .as(StepVerifier::create) + .expectNext( + BindStagingSecurityGroupResponse.builder() + .boundSpaces(Relationship.builder().id("space-guid1").build()) + .boundSpaces(Relationship.builder().id("space-guid2").build()) + .boundSpaces( + Relationship.builder().id("previous-space-guid").build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces") + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void bindRunningSecurityGroup() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(POST) + .path( + "/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces") + .payload( + "fixtures/client/v3/security_groups/bind_running/POST_request.json") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/security_groups/bind_running/POST_response.json") + .build()) + .build()); + this.securityGroups + .bindRunningSecurityGroup( + BindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .boundSpaces(Relationship.builder().id("space-guid1").build()) + .boundSpaces(Relationship.builder().id("space-guid2").build()) + .build()) + .as(StepVerifier::create) + .expectNext( + BindRunningSecurityGroupResponse.builder() + .boundSpaces(Relationship.builder().id("space-guid1").build()) + .boundSpaces(Relationship.builder().id("space-guid2").build()) + .boundSpaces( + Relationship.builder().id("previous-space-guid").build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces") + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void unbindStagingSecurityGroup() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(DELETE) + .path( + "/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces/space-guid-1") + .build()) + .response(TestResponse.builder().status(NO_CONTENT).build()) + .build()); + this.securityGroups + .unbindStagingSecurityGroup( + UnbindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .spaceId("space-guid-1") + .build()) + .as(StepVerifier::create) + .expectNextCount(0) + .verifyComplete(); + } + + @Test + public void unbindRunningSecurityGroup() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(DELETE) + .path( + "/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces/space-guid-1") + .build()) + .response(TestResponse.builder().status(NO_CONTENT).build()) + .build()); + this.securityGroups + .unbindRunningSecurityGroup( + UnbindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .spaceId("space-guid-1") + .build()) + .as(StepVerifier::create) + .expectNextCount(0) + .verifyComplete(); + } + + @Test + public void listRunning() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(GET) + .path( + "/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/security_groups/GET_running_{id}_response.json") + .build()) + .build()); + + this.securityGroups + .listRunning( + ListRunningSecurityGroupsRequest.builder() + .spaceId("c5048979-53b9-4d2a-9fca-78e6bc07c041") + .build()) + .as(StepVerifier::create) + .expectNext( + ListRunningSecurityGroupsResponse.builder() + .pagination( + Pagination.builder() + .totalResults(1) + .totalPages(1) + .first( + Link.builder() + .href( + "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups?page=1&per_page=50") + .build()) + .last( + Link.builder() + .href( + "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups?page=1&per_page=50") + .build()) + .build()) + .resource( + SecurityGroupResource.builder() + .name("my-group0") + .id("b85a788e-671f-4549-814d-e34cdb2f539a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .globallyEnabled( + GloballyEnabled.builder() + .staging(false) + .running(true) + .build()) + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description( + "Allow ping requests to" + + " private services") + .type(8) + .code(0) + .build()) + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .build()) + .runningSpaces( + ToManyRelationship.builder() + .data( + Relationship + .builder() + .id( + "space-guid-1") + .build()) + .data( + Relationship + .builder() + .id( + "space-guid-2") + .build()) + .build()) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()) + .resource( + SecurityGroupResource.builder() + .name("my-group1") + .id("a89a788e-671f-4549-814d-e34c1b2f533a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .build()) + .runningSpaces( + ToManyRelationship.builder() + .build()) + .build()) + .globallyEnabled( + GloballyEnabled.builder() + .staging(true) + .running(true) + .build()) + .globallyEnabled( + GloballyEnabled.builder() + .staging(true) + .running(true) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a") + .build()) + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } + + @Test + public void listStaging() { + mockRequest( + InteractionContext.builder() + .request( + TestRequest.builder() + .method(GET) + .path( + "/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups") + .build()) + .response( + TestResponse.builder() + .status(OK) + .payload( + "fixtures/client/v3/security_groups/GET_staging_{id}_response.json") + .build()) + .build()); + + this.securityGroups + .listStaging( + ListStagingSecurityGroupsRequest.builder() + .spaceId("c5048979-53b9-4d2a-9fca-78e6bc07c041") + .build()) + .as(StepVerifier::create) + .expectNext( + ListStagingSecurityGroupsResponse.builder() + .pagination( + Pagination.builder() + .totalResults(1) + .totalPages(1) + .first( + Link.builder() + .href( + "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups?page=1&per_page=50") + .build()) + .last( + Link.builder() + .href( + "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups?page=1&per_page=50") + .build()) + .build()) + .resource( + SecurityGroupResource.builder() + .name("my-group0") + .id("b85a788e-671f-4549-814d-e34cdb2f539a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .globallyEnabled( + GloballyEnabled.builder() + .staging(true) + .running(false) + .build()) + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description( + "Allow ping requests to" + + " private services") + .type(8) + .code(0) + .build()) + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .data( + Relationship + .builder() + .id( + "space-guid-1") + .build()) + .data( + Relationship + .builder() + .id( + "space-guid-2") + .build()) + .build()) + .runningSpaces( + ToManyRelationship.builder() + .build()) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a") + .build()) + .build()) + .resource( + SecurityGroupResource.builder() + .name("my-group1") + .id("a89a788e-671f-4549-814d-e34c1b2f533a") + .createdAt("2020-02-20T17:42:08Z") + .updatedAt("2020-02-20T17:42:08Z") + .relationships( + Relationships.builder() + .stagingSpaces( + ToManyRelationship.builder() + .build()) + .runningSpaces( + ToManyRelationship.builder() + .build()) + .build()) + .globallyEnabled( + GloballyEnabled.builder() + .staging(true) + .running(true) + .build()) + .globallyEnabled( + GloballyEnabled.builder() + .staging(true) + .running(true) + .build()) + .link( + "self", + Link.builder() + .href( + "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a") + .build()) + .build()) + .build()) + .expectComplete() + .verify(Duration.ofSeconds(5)); + } +} diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_response.json new file mode 100644 index 00000000000..9e39d26c2a1 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_response.json @@ -0,0 +1,84 @@ +{ + "pagination": { + "total_results": 1, + "total_pages": 1, + "first": { + "href": "https://api.example.org/v3/security_groups?page=1&per_page=50" + }, + "last": { + "href": "https://api.example.org/v3/security_groups?page=1&per_page=50" + }, + "next": null, + "previous": null + }, + "resources": [ + { + "guid": "b85a788e-671f-4549-814d-e34cdb2f539a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group0", + "globally_enabled": { + "running": true, + "staging": false + }, + "rules": [ + { + "protocol": "tcp", + "destination": "10.10.10.0/24", + "ports": "443,80,8080" + }, + { + "protocol": "icmp", + "destination": "10.10.10.0/24", + "type": 8, + "code": 0, + "description": "Allow ping requests to private services" + } + ], + "relationships": { + "staging_spaces": { + "data": [ + { + "guid": "space-guid-1" + }, + { + "guid": "space-guid-2" + } + ] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a" + } + } + }, + { + "guid": "a89a788e-671f-4549-814d-e34c1b2f533a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group1", + "globally_enabled": { + "running": true, + "staging": true + }, + "rules": [], + "relationships": { + "staging_spaces": { + "data": [] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a" + } + } + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_running_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_running_{id}_response.json new file mode 100644 index 00000000000..c02b6b95267 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_running_{id}_response.json @@ -0,0 +1,84 @@ +{ + "pagination": { + "total_results": 1, + "total_pages": 1, + "first": { + "href": "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups?page=1&per_page=50" + }, + "last": { + "href": "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/running_security_groups?page=1&per_page=50" + }, + "next": null, + "previous": null + }, + "resources": [ + { + "guid": "b85a788e-671f-4549-814d-e34cdb2f539a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group0", + "globally_enabled": { + "running": true, + "staging": false + }, + "rules": [ + { + "protocol": "tcp", + "destination": "10.10.10.0/24", + "ports": "443,80,8080" + }, + { + "protocol": "icmp", + "destination": "10.10.10.0/24", + "type": 8, + "code": 0, + "description": "Allow ping requests to private services" + } + ], + "relationships": { + "staging_spaces": { + "data": [] + }, + "running_spaces": { + "data": [ + { + "guid": "space-guid-1" + }, + { + "guid": "space-guid-2" + } + ] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a" + } + } + }, + { + "guid": "a89a788e-671f-4549-814d-e34c1b2f533a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group1", + "globally_enabled": { + "running": true, + "staging": true + }, + "rules": [], + "relationships": { + "staging_spaces": { + "data": [] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a" + } + } + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_staging_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_staging_{id}_response.json new file mode 100644 index 00000000000..b9dede15381 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_staging_{id}_response.json @@ -0,0 +1,84 @@ +{ + "pagination": { + "total_results": 1, + "total_pages": 1, + "first": { + "href": "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups?page=1&per_page=50" + }, + "last": { + "href": "https://api.example.org/v3/spaces/c5048979-53b9-4d2a-9fca-78e6bc07c041/staging_security_groups?page=1&per_page=50" + }, + "next": null, + "previous": null + }, + "resources": [ + { + "guid": "b85a788e-671f-4549-814d-e34cdb2f539a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group0", + "globally_enabled": { + "running": false, + "staging": true + }, + "rules": [ + { + "protocol": "tcp", + "destination": "10.10.10.0/24", + "ports": "443,80,8080" + }, + { + "protocol": "icmp", + "destination": "10.10.10.0/24", + "type": 8, + "code": 0, + "description": "Allow ping requests to private services" + } + ], + "relationships": { + "staging_spaces": { + "data": [ + { + "guid": "space-guid-1" + }, + { + "guid": "space-guid-2" + } + ] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a" + } + } + }, + { + "guid": "a89a788e-671f-4549-814d-e34c1b2f533a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group1", + "globally_enabled": { + "running": true, + "staging": true + }, + "rules": [], + "relationships": { + "staging_spaces": { + "data": [] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/a89a788e-671f-4549-814d-e34c1b2f533a" + } + } + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_{id}_response.json new file mode 100644 index 00000000000..5c1290a8e35 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/GET_{id}_response.json @@ -0,0 +1,44 @@ +{ + "guid": "b85a788e-671f-4549-814d-e34cdb2f539a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group0", + "globally_enabled": { + "running": true, + "staging": false + }, + "rules": [ + { + "protocol": "tcp", + "destination": "10.10.10.0/24", + "ports": "443,80,8080" + }, + { + "protocol": "icmp", + "destination": "10.10.10.0/24", + "type": 8, + "code": 0, + "description": "Allow ping requests to private services" + } + ], + "relationships": { + "staging_spaces": { + "data": [ + { + "guid": "space-guid-1" + }, + { + "guid": "space-guid-2" + } + ] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_request.json new file mode 100644 index 00000000000..7b146d9a9b5 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_request.json @@ -0,0 +1,20 @@ +{ + "name": "my-group0", + "globally_enabled": { + "running": true + }, + "rules": [ + { + "protocol": "tcp", + "destination": "10.10.10.0/24", + "ports": "443,80,8080" + }, + { + "protocol": "icmp", + "destination": "10.10.10.0/24", + "type": 8, + "code": 0, + "description": "Allow ping requests to private services" + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_response.json new file mode 100644 index 00000000000..5c1290a8e35 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/PATCH_{id}_response.json @@ -0,0 +1,44 @@ +{ + "guid": "b85a788e-671f-4549-814d-e34cdb2f539a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group0", + "globally_enabled": { + "running": true, + "staging": false + }, + "rules": [ + { + "protocol": "tcp", + "destination": "10.10.10.0/24", + "ports": "443,80,8080" + }, + { + "protocol": "icmp", + "destination": "10.10.10.0/24", + "type": 8, + "code": 0, + "description": "Allow ping requests to private services" + } + ], + "relationships": { + "staging_spaces": { + "data": [ + { + "guid": "space-guid-1" + }, + { + "guid": "space-guid-2" + } + ] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_request.json new file mode 100644 index 00000000000..35e74431db8 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_request.json @@ -0,0 +1,17 @@ +{ + "name": "my-group0", + "rules": [ + { + "protocol": "tcp", + "destination": "10.10.10.0/24", + "ports": "443,80,8080" + }, + { + "protocol": "icmp", + "destination": "10.10.10.0/24", + "type": 8, + "code": 0, + "description": "Allow ping requests to private services" + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_response.json new file mode 100644 index 00000000000..5c1290a8e35 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/POST_response.json @@ -0,0 +1,44 @@ +{ + "guid": "b85a788e-671f-4549-814d-e34cdb2f539a", + "created_at": "2020-02-20T17:42:08Z", + "updated_at": "2020-02-20T17:42:08Z", + "name": "my-group0", + "globally_enabled": { + "running": true, + "staging": false + }, + "rules": [ + { + "protocol": "tcp", + "destination": "10.10.10.0/24", + "ports": "443,80,8080" + }, + { + "protocol": "icmp", + "destination": "10.10.10.0/24", + "type": 8, + "code": 0, + "description": "Allow ping requests to private services" + } + ], + "relationships": { + "staging_spaces": { + "data": [ + { + "guid": "space-guid-1" + }, + { + "guid": "space-guid-2" + } + ] + }, + "running_spaces": { + "data": [] + } + }, + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_request.json new file mode 100644 index 00000000000..eaa31060cad --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_request.json @@ -0,0 +1,10 @@ +{ + "data": [ + { + "guid": "space-guid1" + }, + { + "guid": "space-guid2" + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_response.json new file mode 100644 index 00000000000..35ce11babff --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_running/POST_response.json @@ -0,0 +1,18 @@ +{ + "data": [ + { + "guid": "space-guid1" + }, + { + "guid": "space-guid2" + }, + { + "guid": "previous-space-guid" + } + ], + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/running_spaces" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_request.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_request.json new file mode 100644 index 00000000000..eaa31060cad --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_request.json @@ -0,0 +1,10 @@ +{ + "data": [ + { + "guid": "space-guid1" + }, + { + "guid": "space-guid2" + } + ] +} \ No newline at end of file diff --git a/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_response.json b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_response.json new file mode 100644 index 00000000000..06b4b5914d5 --- /dev/null +++ b/cloudfoundry-client-reactor/src/test/resources/fixtures/client/v3/security_groups/bind_staging/POST_response.json @@ -0,0 +1,18 @@ +{ + "data": [ + { + "guid": "space-guid1" + }, + { + "guid": "space-guid2" + }, + { + "guid": "previous-space-guid" + } + ], + "links": { + "self": { + "href": "https://api.example.org/v3/security_groups/b85a788e-671f-4549-814d-e34cdb2f539a/relationships/staging_spaces" + } + } +} \ No newline at end of file diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java index 5e487ed3769..446319cf4b3 100644 --- a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/CloudFoundryClient.java @@ -63,6 +63,7 @@ import org.cloudfoundry.client.v3.resourcematch.ResourceMatchV3; import org.cloudfoundry.client.v3.roles.RolesV3; import org.cloudfoundry.client.v3.routes.RoutesV3; +import org.cloudfoundry.client.v3.securitygroups.SecurityGroupsV3; import org.cloudfoundry.client.v3.servicebindings.ServiceBindingsV3; import org.cloudfoundry.client.v3.servicebrokers.ServiceBrokersV3; import org.cloudfoundry.client.v3.serviceinstances.ServiceInstancesV3; @@ -247,6 +248,11 @@ public interface CloudFoundryClient { */ SecurityGroups securityGroups(); + /** + * Main entry point to the Cloud Foundry Security Groups V3 Client API + */ + SecurityGroupsV3 securityGroupsV3(); + /** * Main entry point to the Cloud Foundry Service Bindings V2 Client API */ @@ -348,7 +354,8 @@ public interface CloudFoundryClient { Tasks tasks(); /** - * Main entry point to the Cloud Foundry User Provided Service Instances Client API + * Main entry point to the Cloud Foundry User Provided Service Instances Client + * API */ UserProvidedServiceInstances userProvidedServiceInstances(); diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupRequest.java new file mode 100644 index 00000000000..daef64716e7 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupRequest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import java.util.List; +import org.cloudfoundry.client.v3.Relationship; + +@JsonSerialize +public abstract class AbstractBindSecurityGroupRequest { + + /** + * The Security Group id + */ + @JsonIgnore + abstract String getSecurityGroupId(); + + /** + * A relationship to the spaces where the security_group is applied to + * applications during runtime + */ + @JsonProperty("data") + abstract List getBoundSpaces(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupResponse.java new file mode 100644 index 00000000000..65838436474 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractBindSecurityGroupResponse.java @@ -0,0 +1,41 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.List; +import java.util.Map; +import org.cloudfoundry.AllowNulls; +import org.cloudfoundry.client.v3.Link; +import org.cloudfoundry.client.v3.Relationship; + +@JsonDeserialize +public abstract class AbstractBindSecurityGroupResponse { + + /** + * A relationship to the spaces where the security_group is applied to applications during + * runtime + */ + @JsonProperty("data") + abstract List getBoundSpaces(); + + /** + * The links + */ + @AllowNulls + @JsonProperty("links") + public abstract Map getLinks(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractListSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractListSecurityGroupRequest.java new file mode 100644 index 00000000000..1a29e8e83cb --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractListSecurityGroupRequest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.util.List; +import org.cloudfoundry.Nullable; +import org.cloudfoundry.client.v2.PaginatedRequest; +import org.cloudfoundry.client.v3.FilterParameter; + +public abstract class AbstractListSecurityGroupRequest extends PaginatedRequest { + + /** + * The Space id + */ + @JsonIgnore + abstract String getSpaceId(); + + /** + * The security group ids filter + */ + @FilterParameter("guids") + @Nullable + abstract List getSecurityGroupIds(); + + /** + * The security group names filter + */ + @FilterParameter("names") + @Nullable + abstract List getNames(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractUnbindSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractUnbindSecurityGroupRequest.java new file mode 100644 index 00000000000..7903a2bdacf --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/AbstractUnbindSecurityGroupRequest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonIgnore; + +public abstract class AbstractUnbindSecurityGroupRequest { + + /** + * The Security Group id + */ + @JsonIgnore + abstract String getSecurityGroupId(); + + /** + * The Space id + */ + @JsonIgnore + abstract String getSpaceId(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/Protocol.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/Protocol.java new file mode 100644 index 00000000000..7bd2e1eb0e3 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/Protocol.java @@ -0,0 +1,76 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * The protocol of a Security Group + */ +public enum Protocol { + + /** + * All protocols + */ + ALL("all"), + + /** + * ICMP protocol + */ + ICMP("icmp"), + + /** + * TCP protocol + */ + TCP("tcp"), + + /** + * UDP protocol + */ + UDP("udp"); + + private final String value; + + Protocol(String value) { + this.value = value; + } + + @JsonCreator + public static Protocol from(String s) { + switch (s.toLowerCase()) { + case "all": + return ALL; + case "icmp": + return ICMP; + case "tcp": + return TCP; + case "udp": + return UDP; + default: + throw new IllegalArgumentException(String.format("Unknown protocol: %s", s)); + } + } + + @JsonValue + public String getValue() { + return this.value; + } + + @Override + public String toString() { + return getValue(); + } +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroup.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroup.java new file mode 100644 index 00000000000..0ac31fc985f --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroup.java @@ -0,0 +1,51 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.util.List; +import org.cloudfoundry.client.v3.Resource; + +/** + * The entity response payload for the Security Group resource + */ +@JsonDeserialize +public abstract class SecurityGroup extends Resource { + + /** + * The name + */ + @JsonProperty("name") + abstract String getName(); + + /** + * The globally enabled + */ + @JsonProperty("globally_enabled") + abstract GloballyEnabled getGloballyEnabled(); + + /** + * The rules + */ + @JsonProperty("rules") + abstract List getRules(); + + /** + * The space relationships + */ + @JsonProperty("relationships") + abstract Relationships getRelationships(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroupsV3.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroupsV3.java new file mode 100644 index 00000000000..88e5e6d743c --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/SecurityGroupsV3.java @@ -0,0 +1,136 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import reactor.core.publisher.Mono; + +public interface SecurityGroupsV3 { + + /** + * Makes the Creating + * a Security Group request. + * + * @param request the Create Security Group request + * @return the response from the Create Security Group request + */ + Mono create(CreateSecurityGroupRequest request); + + /** + * Makes the Get + * a Security Group request. + * + * @param request the Get Security Group request + * @return the response from the Get Security Group request + */ + Mono get(GetSecurityGroupRequest request); + + /** + * Makes the List + * Security Groups request + * + * @param request the List Security Group request + * @return the response from the List Security Group request + */ + Mono list(ListSecurityGroupsRequest request); + + /** + * Makes the Update + * Security Groups request + * + * @param request the Update Security Group request + * @return the response from the Update Security Group request + */ + Mono update(UpdateSecurityGroupRequest request); + + /** + * Makes the Delete + * Security Groups request + * + * @param request the Delete Security Group request + * @return the response from the Delete Security Group request + */ + Mono delete(DeleteSecurityGroupRequest request); + + /** + * Makes the Bind + * Staging Security Group request + * + * @param request the Bind Staging Security Group request + * @return the response from the Bind Staging Security Group request + */ + Mono bindStagingSecurityGroup( + BindStagingSecurityGroupRequest request); + + /** + * Makes the Bind + * Running Security Group request + * + * @param request the Bind Running Security Group request + * @return the response from the Bind Running Security Group request + */ + Mono bindRunningSecurityGroup( + BindRunningSecurityGroupRequest request); + + /** + * Makes the Unbind + * Staging + * Security Group request + * + * @param request the Unbind Staging Security Group request + * @return the response from the Unbind staging Security Group request + */ + Mono unbindStagingSecurityGroup(UnbindStagingSecurityGroupRequest request); + + /** + * Makes the Unbind + * Running + * Security Groups request + * + * @param request the Unbind Staging Running Security Group request + * @return the response from the Unbind Running Security Group request + */ + Mono unbindRunningSecurityGroup(UnbindRunningSecurityGroupRequest request); + + /** + * Makes the List + * Running Security Groups request + * + * @param request the List Staging Security Group request + * @return the response from the List Staging Security Group request + */ + Mono listStaging(ListStagingSecurityGroupsRequest request); + + /** + * Makes the List + * Running Security Groups request + * + * @param request the List Staging Security Group request + * @return the response from the List Running Security Group request + */ + Mono listRunning(ListRunningSecurityGroupsRequest request); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupRequest.java new file mode 100644 index 00000000000..0e14195fc77 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupRequest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize +@Value.Immutable +abstract class _BindRunningSecurityGroupRequest extends AbstractBindSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupResponse.java new file mode 100644 index 00000000000..e299671f9af --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindRunningSecurityGroupResponse.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize +@Value.Immutable +public abstract class _BindRunningSecurityGroupResponse extends AbstractBindSecurityGroupResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupRequest.java new file mode 100644 index 00000000000..36ce1fcadae --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupRequest.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +@JsonSerialize +@Value.Immutable +abstract class _BindStagingSecurityGroupRequest extends AbstractBindSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupResponse.java new file mode 100644 index 00000000000..920c3eee7d4 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_BindStagingSecurityGroupResponse.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +@JsonDeserialize +@Value.Immutable +public abstract class _BindStagingSecurityGroupResponse extends AbstractBindSecurityGroupResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupRequest.java new file mode 100644 index 00000000000..e2d6b4f6c02 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupRequest.java @@ -0,0 +1,60 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +import java.util.List; + +/** + * The request payload for the Create a Security Group operation + */ +@JsonSerialize +@Value.Immutable +abstract class _CreateSecurityGroupRequest { + + /** + * The security group name + */ + @JsonProperty("name") + abstract String getName(); + + /** + * the security group glbally enabled field + */ + @JsonProperty("globally_enabled") + @Nullable + abstract GloballyEnabled getGloballyEnabled(); + + /** + * The security group rules + */ + @JsonProperty("rules") + @Nullable + abstract List getRules(); + + /** + * The security group relationships + */ + @JsonProperty("relationships") + @Nullable + abstract Relationships getRelationships(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupResponse.java new file mode 100644 index 00000000000..5b7f6f8ccd9 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_CreateSecurityGroupResponse.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Creating a Security Group operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _CreateSecurityGroupResponse extends SecurityGroup { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_DeleteSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_DeleteSecurityGroupRequest.java new file mode 100644 index 00000000000..48b0e7d20e2 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_DeleteSecurityGroupRequest.java @@ -0,0 +1,32 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Delete Security Group operation + */ +@Value.Immutable +abstract class _DeleteSecurityGroupRequest { + + /** + * The Security Group id + */ + @JsonIgnore + abstract String getSecurityGroupId(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupRequest.java new file mode 100644 index 00000000000..e001a6dbf9c --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupRequest.java @@ -0,0 +1,34 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.annotation.JsonIgnore; +import org.immutables.value.Value; + +/** + * The request payload for the Get Security Group operation + */ +@JsonSerialize +@Value.Immutable +abstract class _GetSecurityGroupRequest { + + /** + * The Security Group id + */ + @JsonIgnore + abstract String getSecurityGroupId(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupResponse.java new file mode 100644 index 00000000000..aab7d9d91ed --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GetSecurityGroupResponse.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the get Security Group operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _GetSecurityGroupResponse extends SecurityGroup { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GloballyEnabled.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GloballyEnabled.java new file mode 100644 index 00000000000..bf89201cbb2 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_GloballyEnabled.java @@ -0,0 +1,43 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * Controls if the group is applied globally to the lifecycle of all applications + */ +@JsonDeserialize +@Value.Immutable +abstract class _GloballyEnabled { + + /** + * Specifies whether the group should be applied globally to all running applications + */ + @JsonProperty("running") + @Nullable + abstract Boolean getRunning(); + + /** + * Specifies whether the group should be applied globally to all staging applications + */ + @JsonProperty("staging") + @Nullable + abstract Boolean getStaging(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsRequest.java new file mode 100644 index 00000000000..45e37d9a8f9 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsRequest.java @@ -0,0 +1,27 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + + +/** + * The request payload for the List running Security Group operation + */ + +@Value.Immutable +abstract class _ListRunningSecurityGroupsRequest extends AbstractListSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsResponse.java new file mode 100644 index 00000000000..0a6ec345a27 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListRunningSecurityGroupsResponse.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + +import org.cloudfoundry.client.v3.PaginatedResponse; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * The response payload for the List Security Groups operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListRunningSecurityGroupsResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsRequest.java new file mode 100644 index 00000000000..2ec1c16369e --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsRequest.java @@ -0,0 +1,70 @@ +/* + * Copyright 2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.cloudfoundry.client.v2.PaginatedRequest; +import org.immutables.value.Value; +import org.cloudfoundry.client.v3.FilterParameter; +import org.cloudfoundry.Nullable; +import java.util.List; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; + +/** + * The request payload for the List Security Group operation + */ +@JsonSerialize +@Value.Immutable +abstract class _ListSecurityGroupsRequest extends PaginatedRequest { + + /** + * The security group ids filter + */ + @FilterParameter("guids") + abstract List getSecurityGroupIds(); + + /** + * The security group names filter + */ + @FilterParameter("names") + abstract List getNames(); + + /** + * the security group globally enabled running filter + */ + @FilterParameter("globally_enabled_running") + @Nullable + abstract Boolean getGloballyEnabledRunning(); + + /** + * the security group globally enabled staging filter + */ + @FilterParameter("globally_enabled_staging") + @Nullable + abstract Boolean getGloballyEnabledStagingBoolean(); + + /** + * the security group running_space_guids filter + */ + @FilterParameter("running_space_guids") + @Nullable + abstract List getRunningSpaceIds(); + + /** + * the security group staging_space_guids filter + */ + @FilterParameter("staging_space_guids") + @Nullable + abstract List getStagingSpaceIds(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsResponse.java new file mode 100644 index 00000000000..f19bfc76136 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListSecurityGroupsResponse.java @@ -0,0 +1,31 @@ +/* + * Copyright 2013-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + +import org.cloudfoundry.client.v3.PaginatedResponse; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * The response payload for the List Security Groups operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListSecurityGroupsResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsRequest.java new file mode 100644 index 00000000000..d85b8c9c01c --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsRequest.java @@ -0,0 +1,28 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + + +/** + * The request payload for the List staging Security Group operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListStagingSecurityGroupsRequest extends AbstractListSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsResponse.java new file mode 100644 index 00000000000..1109b7a60a7 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_ListStagingSecurityGroupsResponse.java @@ -0,0 +1,29 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + +import org.cloudfoundry.client.v3.PaginatedResponse; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +/** + * The response payload for the List Security Groups operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _ListStagingSecurityGroupsResponse extends PaginatedResponse { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Relationships.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Relationships.java new file mode 100644 index 00000000000..e9d782cbac7 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Relationships.java @@ -0,0 +1,44 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.client.v3.ToManyRelationship; +import org.immutables.value.Value; + +/** + * Holds relationships to running/staging spaces where security groups is + * applied + */ +@JsonDeserialize +@Value.Immutable +abstract class _Relationships { + + /** + * A relationship to the spaces where the security_group is applied to + * applications during runtime + */ + @JsonProperty("running_spaces") + abstract ToManyRelationship getRunningSpaces(); + + /** + * A relationship to the spaces where the security_group is applied to + * applications during runtime + */ + @JsonProperty("staging_spaces") + abstract ToManyRelationship getStagingSpaces(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Rule.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Rule.java new file mode 100644 index 00000000000..b24119e0f89 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_Rule.java @@ -0,0 +1,78 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.cloudfoundry.Nullable; +import org.immutables.value.Value; + +/** + * A security group rule + */ +@JsonDeserialize +@Value.Immutable +abstract class _Rule { + + /** + * The code control signal for icmp + */ + @JsonProperty("code") + @Nullable + abstract Integer getCode(); + + /** + * The description of the rule + */ + @JsonProperty("description") + @Nullable + abstract String getDescription(); + + /** + * The destination + */ + @JsonProperty("destination") + @Nullable + abstract String getDestination(); + + /** + * Enables logging for the egress rule + */ + @JsonProperty("log") + @Nullable + abstract Boolean getLog(); + + /** + * The ports + */ + @JsonProperty("ports") + @Nullable + abstract String getPorts(); + + /** + * The protocol + */ + @JsonProperty("protocol") + @Nullable + abstract Protocol getProtocol(); + + /** + * The type control signal for icmp + */ + @JsonProperty("type") + @Nullable + abstract Integer getType(); + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_SecurityGroupResource.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_SecurityGroupResource.java new file mode 100644 index 00000000000..339559f111f --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_SecurityGroupResource.java @@ -0,0 +1,30 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + + +/** + * The Resource response payload for the List SecurityGroups operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _SecurityGroupResource extends SecurityGroup { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindRunningSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindRunningSecurityGroupRequest.java new file mode 100644 index 00000000000..b9666f90422 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindRunningSecurityGroupRequest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + +/** + * The request payload for the Unbind Running Security Group operation + */ +@Value.Immutable +abstract class _UnbindRunningSecurityGroupRequest extends AbstractUnbindSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindStagingSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindStagingSecurityGroupRequest.java new file mode 100644 index 00000000000..7c0f3a34b88 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UnbindStagingSecurityGroupRequest.java @@ -0,0 +1,25 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + +/** + * The request payload for the Unbind Staging Security Group operation + */ +@Value.Immutable +abstract class _UnbindStagingSecurityGroupRequest extends AbstractUnbindSecurityGroupRequest { + +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupRequest.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupRequest.java new file mode 100644 index 00000000000..a5ce3eed999 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupRequest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import org.immutables.value.Value; + +import java.util.List; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonIgnore; + +/** + * The request payload for the Create a Security Group operation + */ +@JsonSerialize +@Value.Immutable +abstract class _UpdateSecurityGroupRequest { + + /** + * Id of the security group + */ + @JsonIgnore + abstract String getSecurityGroupId(); + + /** + * Name of the security group + */ + @JsonProperty("name") + abstract String getName(); + + /** + * Object that controls if the group is applied globally to the lifecycle of all applications + */ + @JsonProperty("globally_enabled") + abstract GloballyEnabled getGloballyEnabled(); + + /** + * Rules that will be applied by this security group + */ + @JsonProperty("rules") + abstract List getRules(); +} diff --git a/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupResponse.java b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupResponse.java new file mode 100644 index 00000000000..42f5dfa05e7 --- /dev/null +++ b/cloudfoundry-client/src/main/java/org/cloudfoundry/client/v3/securitygroups/_UpdateSecurityGroupResponse.java @@ -0,0 +1,26 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.immutables.value.Value; + +/** + * The response payload for the Update a Security Group operation + */ +@JsonDeserialize +@Value.Immutable +abstract class _UpdateSecurityGroupResponse extends SecurityGroup { + +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindRunningSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindRunningSecurityGroupRequestTest.java new file mode 100644 index 00000000000..8c3e12640e7 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindRunningSecurityGroupRequestTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.cloudfoundry.client.v3.Relationship; +import org.junit.jupiter.api.Test; + +public class BindRunningSecurityGroupRequestTest { + + @Test + public void noSecurityGroupId() { + assertThrows( + IllegalStateException.class, + () -> { + BindRunningSecurityGroupRequest.builder().build(); + }); + } + + @Test + public void valid() { + BindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .boundSpaces(Relationship.builder().id("space-guid-1").build()) + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindStagingSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindStagingSecurityGroupRequestTest.java new file mode 100644 index 00000000000..ff5a4f3ba96 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/BindStagingSecurityGroupRequestTest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.cloudfoundry.client.v3.Relationship; +import org.junit.jupiter.api.Test; + +public class BindStagingSecurityGroupRequestTest { + + @Test + public void noSecurityGroupId() { + assertThrows( + IllegalStateException.class, + () -> { + BindStagingSecurityGroupRequest.builder().build(); + }); + } + + @Test + public void valid() { + BindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .boundSpaces(Relationship.builder().id("space-guid-1").build()) + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/CreateSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/CreateSecurityGroupRequestTest.java new file mode 100644 index 00000000000..292cec1b67d --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/CreateSecurityGroupRequestTest.java @@ -0,0 +1,31 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class CreateSecurityGroupRequestTest { + + @Test + public void noName() { + assertThrows( + IllegalStateException.class, + () -> { + CreateSecurityGroupRequest.builder().rule(Rule.builder().build()).build(); + }); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/DeleteSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/DeleteSecurityGroupRequestTest.java new file mode 100644 index 00000000000..d3fb5b8bec9 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/DeleteSecurityGroupRequestTest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class DeleteSecurityGroupRequestTest { + + @Test + public void noSecurityGroupId() { + assertThrows( + IllegalStateException.class, + () -> { + DeleteSecurityGroupRequest.builder().build(); + }); + } + + @Test + public void valid() { + DeleteSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/GetSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/GetSecurityGroupRequestTest.java new file mode 100644 index 00000000000..435873e76a8 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/GetSecurityGroupRequestTest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class GetSecurityGroupRequestTest { + + @Test + public void noSecurityGroupId() { + assertThrows( + IllegalStateException.class, + () -> { + GetSecurityGroupRequest.builder().build(); + }); + } + + @Test + public void valid() { + GetSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListRunningSecurityGroupsRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListRunningSecurityGroupsRequestTest.java new file mode 100644 index 00000000000..3f60cfc93f1 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListRunningSecurityGroupsRequestTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class ListRunningSecurityGroupsRequestTest { + + @Test + public void noSpaceID() { + assertThrows( + IllegalStateException.class, + () -> { + ListRunningSecurityGroupsRequest.builder().build(); + }); + } + + @Test + public void valid() { + ListRunningSecurityGroupsRequest.builder().spaceId("space-giud1").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListSecurityGroupsRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListSecurityGroupsRequestTest.java new file mode 100644 index 00000000000..9d8ccd1f696 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListSecurityGroupsRequestTest.java @@ -0,0 +1,24 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import org.junit.jupiter.api.Test; + +public class ListSecurityGroupsRequestTest { + + @Test + public void valid() { + ListSecurityGroupsRequest.builder().build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListStagingSecurityGroupsRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListStagingSecurityGroupsRequestTest.java new file mode 100644 index 00000000000..9ffde0a435f --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/ListStagingSecurityGroupsRequestTest.java @@ -0,0 +1,35 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class ListStagingSecurityGroupsRequestTest { + + @Test + public void noSpaceID() { + assertThrows( + IllegalStateException.class, + () -> { + ListStagingSecurityGroupsRequest.builder().build(); + }); + } + + @Test + public void valid() { + ListStagingSecurityGroupsRequest.builder().spaceId("space-giud1").build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindRunningSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindRunningSecurityGroupRequestTest.java new file mode 100644 index 00000000000..6bacd1e034e --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindRunningSecurityGroupRequestTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class UnbindRunningSecurityGroupRequestTest { + + @Test + public void noSecurityGroupId() { + assertThrows( + IllegalStateException.class, + () -> { + UnbindRunningSecurityGroupRequest.builder().build(); + }); + } + + @Test + public void noSpaceId() { + assertThrows( + IllegalStateException.class, + () -> { + UnbindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build(); + }); + } + + @Test + public void valid() { + UnbindRunningSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .spaceId("space-guid2") + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindStagingSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindStagingSecurityGroupRequestTest.java new file mode 100644 index 00000000000..9ab1c7fa1d4 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UnbindStagingSecurityGroupRequestTest.java @@ -0,0 +1,49 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class UnbindStagingSecurityGroupRequestTest { + + @Test + public void noSecurityGroupId() { + assertThrows( + IllegalStateException.class, + () -> { + UnbindStagingSecurityGroupRequest.builder().build(); + }); + } + + @Test + public void noSpaceId() { + assertThrows( + IllegalStateException.class, + () -> { + UnbindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .build(); + }); + } + + @Test + public void valid() { + UnbindStagingSecurityGroupRequest.builder() + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .spaceId("space-guid2") + .build(); + } +} diff --git a/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UpdateSecurityGroupRequestTest.java b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UpdateSecurityGroupRequestTest.java new file mode 100644 index 00000000000..d0b18172b85 --- /dev/null +++ b/cloudfoundry-client/src/test/java/org/cloudfoundry/client/v3/securitygroups/UpdateSecurityGroupRequestTest.java @@ -0,0 +1,53 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.cloudfoundry.client.v3.securitygroups; + +import static org.junit.jupiter.api.Assertions.assertThrows; + +import org.junit.jupiter.api.Test; + +public class UpdateSecurityGroupRequestTest { + + @Test + public void noName() { + assertThrows( + IllegalStateException.class, + () -> { + UpdateSecurityGroupRequest.builder().build(); + }); + } + + @Test + public void valid() { + UpdateSecurityGroupRequest.builder() + .name("my-group0") + .securityGroupId("b85a788e-671f-4549-814d-e34cdb2f539a") + .globallyEnabled(GloballyEnabled.builder().running(true).build()) + .rules( + Rule.builder() + .protocol(Protocol.TCP) + .destination("10.10.10.0/24") + .ports("443,80,8080") + .build()) + .rules( + Rule.builder() + .protocol(Protocol.ICMP) + .destination("10.10.10.0/24") + .description("Allow ping requests to private services") + .type(8) + .code(0) + .build()) + .build(); + } +} diff --git a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/_DefaultCloudFoundryOperations.java b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/_DefaultCloudFoundryOperations.java index 35d76a3fb0f..299b4bf5e41 100644 --- a/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/_DefaultCloudFoundryOperations.java +++ b/cloudfoundry-operations/src/main/java/org/cloudfoundry/operations/_DefaultCloudFoundryOperations.java @@ -18,10 +18,10 @@ import org.cloudfoundry.Nullable; import org.cloudfoundry.client.CloudFoundryClient; -import org.cloudfoundry.client.v2.organizations.ListOrganizationsRequest; -import org.cloudfoundry.client.v2.organizations.OrganizationResource; -import org.cloudfoundry.client.v2.spaces.ListSpacesRequest; -import org.cloudfoundry.client.v2.spaces.SpaceResource; +import org.cloudfoundry.client.v3.organizations.ListOrganizationsRequest; +import org.cloudfoundry.client.v3.organizations.OrganizationResource; +import org.cloudfoundry.client.v3.spaces.ListSpacesRequest; +import org.cloudfoundry.client.v3.spaces.SpaceResource; import org.cloudfoundry.doppler.DopplerClient; import org.cloudfoundry.networking.NetworkingClient; import org.cloudfoundry.operations.advanced.Advanced; @@ -56,7 +56,6 @@ import org.cloudfoundry.uaa.UaaClient; import org.cloudfoundry.util.ExceptionUtils; import org.cloudfoundry.util.PaginationUtils; -import org.cloudfoundry.util.ResourceUtils; import org.immutables.value.Value; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -211,7 +210,7 @@ Mono getOrganizationId() { if (hasText(organization)) { Mono cached = getOrganization(getCloudFoundryClientPublisher(), organization) - .map(ResourceUtils::getId); + .map(OrganizationResource::getId); return getCacheDuration() .map(cached::cache) @@ -247,7 +246,7 @@ Mono getSpaceId() { if (hasText(getSpace())) { Mono cached = getOrganizationId() .flatMap(organizationId -> getSpace(getCloudFoundryClientPublisher(), organizationId, space)) - .map(ResourceUtils::getId); + .map(SpaceResource::getId); return getCacheDuration() .map(cached::cache) @@ -308,7 +307,7 @@ private static boolean hasText(CharSequence str) { private static Flux requestOrganizations(Mono cloudFoundryClientPublisher, String organization) { return cloudFoundryClientPublisher .flatMapMany(cloudFoundryClient -> PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.organizations() + .requestClientV3Resources(page -> cloudFoundryClient.organizationsV3() .list(ListOrganizationsRequest.builder() .name(organization) .page(page) @@ -318,7 +317,7 @@ private static Flux requestOrganizations(Mono requestSpaces(Mono cloudFoundryClientPublisher, String organizationId, String space) { return cloudFoundryClientPublisher .flatMapMany(cloudFoundryClient -> PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() + .requestClientV3Resources(page -> cloudFoundryClient.spacesV3() .list(ListSpacesRequest.builder() .organizationId(organizationId) .name(space) diff --git a/integration-test/pom.xml b/integration-test/pom.xml index e1b541e1502..c7f8e86a6e5 100644 --- a/integration-test/pom.xml +++ b/integration-test/pom.xml @@ -76,6 +76,18 @@ ${project.version} test + + org.hamcrest + hamcrest-junit + 2.0.0.0 + test + + + junit + junit + + + org.immutables value @@ -91,11 +103,6 @@ spring-boot-starter-test test - - org.junit.vintage - junit-vintage-engine - test - diff --git a/integration-test/src/test/java/org/cloudfoundry/AbstractIntegrationTest.java b/integration-test/src/test/java/org/cloudfoundry/AbstractIntegrationTest.java index b84496bff21..c677804e71e 100644 --- a/integration-test/src/test/java/org/cloudfoundry/AbstractIntegrationTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/AbstractIntegrationTest.java @@ -16,57 +16,57 @@ package org.cloudfoundry; -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.rules.TestName; -import org.junit.runner.RunWith; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; -import reactor.core.publisher.Mono; -import reactor.util.function.Tuple2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; +import java.lang.reflect.Method; +import java.util.Optional; import java.util.function.Consumer; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.TestInfo; +import org.junit.jupiter.api.extension.RegisterExtension; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import reactor.core.publisher.Mono; +import reactor.util.function.Tuple2; -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; - -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = IntegrationTestConfiguration.class) +@SpringJUnitConfig(classes = IntegrationTestConfiguration.class) public abstract class AbstractIntegrationTest { private final Logger logger = LoggerFactory.getLogger("cloudfoundry-client.test"); - @Rule - public final TestName testName = new TestName(); + public String testName; - @Autowired - @Rule - public CloudFoundryVersionConditionalRule cloudFoundryVersion; + @Autowired protected NameFactory nameFactory; - @Autowired - protected NameFactory nameFactory; + @Autowired @RegisterExtension + public CloudFoundryVersionConditionalRule cloudFoundryVersionConditionalRule; - @Before - public void testEntry() { + @BeforeEach + public void testEntry(TestInfo testInfo) { + Optional testMethod = testInfo.getTestMethod(); + if (testMethod.isPresent()) { + this.testName = testMethod.get().getName(); + } this.logger.debug(">> {} <<", getTestName()); } - @After + @AfterEach public final void testExit() { this.logger.debug("<< {} >>", getTestName()); } protected static Mono getBytes(String path) { - try (InputStream in = new FileInputStream(new File("src/test/resources", path)); ByteArrayOutputStream out = new ByteArrayOutputStream()) { + try (InputStream in = new FileInputStream(new File("src/test/resources", path)); + ByteArrayOutputStream out = new ByteArrayOutputStream()) { byte[] buffer = new byte[8192]; int len; @@ -85,7 +85,6 @@ protected static Consumer> tupleEquality() { } private String getTestName() { - return String.format("%s.%s", this.getClass().getSimpleName(), this.testName.getMethodName()); + return String.format("%s.%s", this.getClass().getSimpleName(), this.testName); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/ApplicationUtils.java b/integration-test/src/test/java/org/cloudfoundry/ApplicationUtils.java index a3817e55cf6..0efd69a03ff 100644 --- a/integration-test/src/test/java/org/cloudfoundry/ApplicationUtils.java +++ b/integration-test/src/test/java/org/cloudfoundry/ApplicationUtils.java @@ -16,6 +16,15 @@ package org.cloudfoundry; +import static org.cloudfoundry.util.DelayUtils.exponentialBackOff; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.nio.file.Path; +import java.time.Duration; +import java.util.Collection; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.ApplicationInstanceInfo; import org.cloudfoundry.client.v2.applications.ApplicationInstancesRequest; @@ -41,151 +50,246 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.nio.file.Path; -import java.time.Duration; -import java.util.Collection; -import java.util.Map; -import java.util.Optional; -import java.util.stream.Collectors; - -import static org.cloudfoundry.util.DelayUtils.exponentialBackOff; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public class ApplicationUtils { - static Mono pushApplication(CloudFoundryClient cloudFoundryClient, Path applicationBits, String applicationName, Collection boundServices, - Map env, String hostName, String spaceId) { + static Mono pushApplication( + CloudFoundryClient cloudFoundryClient, + Path applicationBits, + String applicationName, + Collection boundServices, + Map env, + String hostName, + String spaceId) { return getSharedDomain(cloudFoundryClient) - .flatMap(domain -> Mono - .zip(createApplicationId(cloudFoundryClient, spaceId, applicationName), - createRouteId(cloudFoundryClient, ResourceUtils.getId(domain), spaceId, hostName)) - .flatMap(function((applicationId, routeId) -> Mono - .zip(requestAssociateApplicationRoute(cloudFoundryClient, applicationId, routeId), - bindServices(cloudFoundryClient, applicationId, boundServices)) - .thenReturn(applicationId))) - .flatMap(applicationId -> createRunningApplication(cloudFoundryClient, applicationBits, applicationId, env) - .map(ignore -> new ApplicationUtils.ApplicationMetadata(applicationId, spaceId, String.format("https://%s.%s", hostName, ResourceUtils.getEntity(domain).getName()))))); - - } - - private static Mono bindServices(CloudFoundryClient cloudFoundryClient, String applicationId, Collection boundServices) { - return Mono - .zip(boundServices.stream() - .map(serviceInstanceId -> cloudFoundryClient - .serviceBindingsV2() - .create(CreateServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(serviceInstanceId) - .build())) - .collect(Collectors.toList()), a -> Mono.just(applicationId)) - .thenReturn(applicationId); - } - - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + .flatMap( + domain -> + Mono.zip( + createApplicationId( + cloudFoundryClient, + spaceId, + applicationName), + createRouteId( + cloudFoundryClient, + ResourceUtils.getId(domain), + spaceId, + hostName)) + .flatMap( + function( + (applicationId, routeId) -> + Mono.zip( + requestAssociateApplicationRoute( + cloudFoundryClient, + applicationId, + routeId), + bindServices( + cloudFoundryClient, + applicationId, + boundServices)) + .thenReturn(applicationId))) + .flatMap( + applicationId -> + createRunningApplication( + cloudFoundryClient, + applicationBits, + applicationId, + env) + .map( + ignore -> + new ApplicationUtils + .ApplicationMetadata( + applicationId, + spaceId, + String + .format( + "https://%s.%s", + hostName, + ResourceUtils + .getEntity( + domain) + .getName()))))); + } + + private static Mono bindServices( + CloudFoundryClient cloudFoundryClient, + String applicationId, + Collection boundServices) { + return Mono.zip( + boundServices.stream() + .map( + serviceInstanceId -> + cloudFoundryClient + .serviceBindingsV2() + .create( + CreateServiceBindingRequest + .builder() + .applicationId( + applicationId) + .serviceInstanceId( + serviceInstanceId) + .build())) + .collect(Collectors.toList()), + a -> Mono.just(applicationId)) + .thenReturn(applicationId); + } + + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String spaceId, String hostName) { + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, + String domainId, + String spaceId, + String hostName) { return requestCreateRoute(cloudFoundryClient, domainId, spaceId, hostName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createRunningApplication(CloudFoundryClient cloudFoundryClient, Path applicationBits, String applicationId, Map env) { - return ApplicationUtils.requestUploadApplication(cloudFoundryClient, applicationId, applicationBits) - .flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .then(requestUpdateApplication(cloudFoundryClient, applicationId, env, "STARTED")) - .then(getApplicationPackageState(cloudFoundryClient, applicationId) - .filter(state -> "STAGED".equals(state) || "FAILED".equals(state)) - .repeatWhenEmpty(exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), Duration.ofMinutes(5)))) - .then(getApplicationInstanceState(cloudFoundryClient, applicationId) - .filter("RUNNING"::equals) - .repeatWhenEmpty(exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), Duration.ofMinutes(5)))); + private static Mono createRunningApplication( + CloudFoundryClient cloudFoundryClient, + Path applicationBits, + String applicationId, + Map env) { + return ApplicationUtils.requestUploadApplication( + cloudFoundryClient, applicationId, applicationBits) + .flatMap( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, Duration.ofMinutes(5), job)) + .then(requestUpdateApplication(cloudFoundryClient, applicationId, env, "STARTED")) + .then( + getApplicationPackageState(cloudFoundryClient, applicationId) + .filter(state -> "STAGED".equals(state) || "FAILED".equals(state)) + .repeatWhenEmpty( + exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5)))) + .then( + getApplicationInstanceState(cloudFoundryClient, applicationId) + .filter("RUNNING"::equals) + .repeatWhenEmpty( + exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5)))); } - private static Mono getApplicationPackageState(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono getApplicationPackageState( + CloudFoundryClient cloudFoundryClient, String applicationId) { return requestGetApplication(cloudFoundryClient, applicationId) - .map(response -> ResourceUtils.getEntity(response).getPackageState()); + .map(response -> ResourceUtils.getEntity(response).getPackageState()); } - private static Mono getApplicationInstanceState(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono getApplicationInstanceState( + CloudFoundryClient cloudFoundryClient, String applicationId) { return requestApplicationInstances(cloudFoundryClient, applicationId) - .flatMapMany(response -> Flux.fromIterable(response.getInstances().values())) - .single() - .map(ApplicationInstanceInfo::getState); + .flatMapMany(response -> Flux.fromIterable(response.getInstances().values())) + .single() + .map(ApplicationInstanceInfo::getState); } - private static Mono getSharedDomain(CloudFoundryClient cloudFoundryClient) { + private static Mono getSharedDomain( + CloudFoundryClient cloudFoundryClient) { return requestListSharedDomains(cloudFoundryClient) - .filter(resource -> !Optional.ofNullable(ResourceUtils.getEntity(resource).getInternal()).orElse(false)) - .next(); + .filter( + resource -> + !Optional.ofNullable( + ResourceUtils.getEntity(resource).getInternal()) + .orElse(false)) + .next(); } - private static Mono requestApplicationInstances(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV2() - .instances(ApplicationInstancesRequest.builder() - .applicationId(applicationId) - .build()); + private static Mono requestApplicationInstances( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV2() + .instances( + ApplicationInstancesRequest.builder().applicationId(applicationId).build()); } - private static Mono requestAssociateApplicationRoute(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { - return cloudFoundryClient.applicationsV2() - .associateRoute(AssociateApplicationRouteRequest.builder() - .applicationId(applicationId) - .routeId(routeId) - .build()); + private static Mono requestAssociateApplicationRoute( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + return cloudFoundryClient + .applicationsV2() + .associateRoute( + AssociateApplicationRouteRequest.builder() + .applicationId(applicationId) + .routeId(routeId) + .build()); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .buildpack("https://github.com/cloudfoundry/java-buildpack.git") - .memory(768) - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .buildpack("https://github.com/cloudfoundry/java-buildpack.git") + .memory(768) + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String spaceId, String hostName) { - return cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .host(hostName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, + String domainId, + String spaceId, + String hostName) { + return cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .domainId(domainId) + .host(hostName) + .spaceId(spaceId) + .build()); } - private static Mono requestGetApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV2() - .get(GetApplicationRequest.builder() - .applicationId(applicationId) - .build()); + private static Mono requestGetApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV2() + .get(GetApplicationRequest.builder().applicationId(applicationId).build()); } - private static Flux requestListSharedDomains(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.sharedDomains() - .list(ListSharedDomainsRequest.builder() - .page(page) - .build())); + private static Flux requestListSharedDomains( + CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .sharedDomains() + .list(ListSharedDomainsRequest.builder().page(page).build())); } - private static Mono requestUpdateApplication(CloudFoundryClient cloudFoundryClient, String applicationId, Map env, String state) { - return cloudFoundryClient.applicationsV2() - .update(UpdateApplicationRequest.builder() - .applicationId(applicationId) - .environmentJsons(env) - .state(state) - .build()); + private static Mono requestUpdateApplication( + CloudFoundryClient cloudFoundryClient, + String applicationId, + Map env, + String state) { + return cloudFoundryClient + .applicationsV2() + .update( + UpdateApplicationRequest.builder() + .applicationId(applicationId) + .environmentJsons(env) + .state(state) + .build()); } - private static Mono requestUploadApplication(CloudFoundryClient cloudFoundryClient, String applicationId, Path application) { - return cloudFoundryClient.applicationsV2() - .upload(UploadApplicationRequest.builder() - .application(application) - .applicationId(applicationId) - .async(true) - .build()); + private static Mono requestUploadApplication( + CloudFoundryClient cloudFoundryClient, String applicationId, Path application) { + return cloudFoundryClient + .applicationsV2() + .upload( + UploadApplicationRequest.builder() + .application(application) + .applicationId(applicationId) + .async(true) + .build()); } public static final class ApplicationMetadata { @@ -201,8 +305,5 @@ private ApplicationMetadata(String applicationId, String spaceId, String uri) { this.spaceId = spaceId; this.uri = uri; } - } - - } diff --git a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryCleaner.java b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryCleaner.java index 3d97095f77d..c4fb056ad2a 100644 --- a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryCleaner.java +++ b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryCleaner.java @@ -16,7 +16,17 @@ package org.cloudfoundry; +import static org.cloudfoundry.CloudFoundryVersion.PCF_1_12; +import static org.cloudfoundry.CloudFoundryVersion.PCF_2_1; +import static org.cloudfoundry.util.tuple.TupleUtils.function; +import static org.cloudfoundry.util.tuple.TupleUtils.predicate; + import com.github.zafarkhaja.semver.Version; +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Supplier; +import javax.net.ssl.SSLException; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest; import org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest; @@ -111,33 +121,23 @@ import reactor.util.function.Tuples; import reactor.util.retry.Retry; -import javax.net.ssl.SSLException; -import java.time.Duration; -import java.util.HashMap; -import java.util.Map; -import java.util.function.Supplier; - -import static org.cloudfoundry.CloudFoundryVersion.PCF_1_12; -import static org.cloudfoundry.CloudFoundryVersion.PCF_2_1; -import static org.cloudfoundry.util.tuple.TupleUtils.function; -import static org.cloudfoundry.util.tuple.TupleUtils.predicate; - final class CloudFoundryCleaner { private static final Logger LOGGER = LoggerFactory.getLogger("cloudfoundry-client.test"); - private static final Map STANDARD_FEATURE_FLAGS = FluentMap.builder() - .entry("app_bits_upload", true) - .entry("app_scaling", true) - .entry("diego_docker", true) - .entry("private_domain_creation", true) - .entry("route_creation", true) - .entry("service_instance_creation", true) - .entry("service_instance_sharing", true) - .entry("set_roles_by_username", true) - .entry("unset_roles_by_username", true) - .entry("user_org_creation", false) - .build(); + private static final Map STANDARD_FEATURE_FLAGS = + FluentMap.builder() + .entry("app_bits_upload", true) + .entry("app_scaling", true) + .entry("diego_docker", true) + .entry("private_domain_creation", true) + .entry("route_creation", true) + .entry("service_instance_creation", true) + .entry("service_instance_sharing", true) + .entry("set_roles_by_username", true) + .entry("unset_roles_by_username", true) + .entry("user_org_creation", false) + .build(); private final CloudFoundryClient cloudFoundryClient; @@ -149,7 +149,12 @@ final class CloudFoundryCleaner { private final UaaClient uaaClient; - CloudFoundryCleaner(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, NetworkingClient networkingClient, Version serverVersion, UaaClient uaaClient) { + CloudFoundryCleaner( + CloudFoundryClient cloudFoundryClient, + NameFactory nameFactory, + NetworkingClient networkingClient, + Version serverVersion, + UaaClient uaaClient) { this.cloudFoundryClient = cloudFoundryClient; this.nameFactory = nameFactory; this.networkingClient = networkingClient; @@ -159,598 +164,1282 @@ final class CloudFoundryCleaner { void clean() { Flux.empty() - .thenMany(Mono.when( // Before Routes - cleanServiceInstances(this.cloudFoundryClient, this.nameFactory, this.serverVersion), - cleanUserProvidedServiceInstances(this.cloudFoundryClient, this.nameFactory) - )) - .thenMany(Mono.when( // No prerequisites - cleanBuildpacks(this.cloudFoundryClient, this.nameFactory), - cleanClients(this.uaaClient, this.nameFactory), - cleanFeatureFlags(this.cloudFoundryClient), - cleanGroups(this.uaaClient, this.nameFactory), - cleanIdentityProviders(this.uaaClient, this.nameFactory), - cleanIdentityZones(this.uaaClient, this.nameFactory), - cleanNetworkingPolicies(this.networkingClient, this.nameFactory, this.serverVersion), - cleanRoutes(this.cloudFoundryClient, this.nameFactory), - cleanSecurityGroups(this.cloudFoundryClient, this.nameFactory), - cleanServiceBrokers(this.cloudFoundryClient, this.nameFactory), - cleanSpaceQuotaDefinitions(this.cloudFoundryClient, this.nameFactory), - cleanStacks(this.cloudFoundryClient, this.nameFactory), - cleanUsers(this.cloudFoundryClient, this.nameFactory) - )) - .thenMany(Mono.when( - cleanApplicationsV3(this.cloudFoundryClient, this.nameFactory), // After Routes, cannot run with other cleanApps - cleanUsers(this.uaaClient, this.nameFactory) // After CF Users - )) - .thenMany(Mono.when( // After Routes/Applications - cleanPrivateDomains(this.cloudFoundryClient, this.nameFactory), - cleanSharedDomains(this.cloudFoundryClient, this.nameFactory), - cleanSpaces(this.cloudFoundryClient, this.nameFactory) - )) - .thenMany(cleanOrganizations(this.cloudFoundryClient, this.nameFactory)) // After Spaces - .thenMany(cleanOrganizationQuotaDefinitions(this.cloudFoundryClient, this.nameFactory)) // After Organizations - .retryWhen(Retry.max(5).filter(SSLException.class::isInstance)) - .doOnSubscribe(s -> LOGGER.debug(">> CLEANUP <<")) - .doOnComplete(() -> LOGGER.debug("<< CLEANUP >>")) - .then() - .block(Duration.ofMinutes(30)); - } - - private static Flux cleanApplicationsV3(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV3Resources(page -> cloudFoundryClient.applicationsV3() - .list(ListApplicationsRequest.builder() - .page(page) - .build())) - .filter(application -> nameFactory.isApplicationName(application.getName())) - .delayUntil(application -> removeApplicationServiceBindings(cloudFoundryClient, application)) - .flatMap(application -> cloudFoundryClient.applicationsV3() - .delete(DeleteApplicationRequest.builder() - .applicationId(application.getId()) - .build()) + .thenMany( + Mono.when( // Before Routes + cleanServiceInstances( + this.cloudFoundryClient, + this.nameFactory, + this.serverVersion), + cleanUserProvidedServiceInstances( + this.cloudFoundryClient, this.nameFactory))) + .thenMany( + Mono.when( // No prerequisites + cleanBuildpacks(this.cloudFoundryClient, this.nameFactory), + cleanClients(this.uaaClient, this.nameFactory), + cleanFeatureFlags(this.cloudFoundryClient), + cleanGroups(this.uaaClient, this.nameFactory), + cleanIdentityProviders(this.uaaClient, this.nameFactory), + cleanIdentityZones(this.uaaClient, this.nameFactory), + cleanNetworkingPolicies( + this.networkingClient, + this.nameFactory, + this.serverVersion), + cleanRoutes(this.cloudFoundryClient, this.nameFactory), + cleanSecurityGroups(this.cloudFoundryClient, this.nameFactory), + cleanServiceBrokers(this.cloudFoundryClient, this.nameFactory), + cleanSpaceQuotaDefinitions( + this.cloudFoundryClient, this.nameFactory), + cleanStacks(this.cloudFoundryClient, this.nameFactory), + cleanUsers(this.cloudFoundryClient, this.nameFactory))) + .thenMany( + Mono.when( + cleanApplicationsV3( + this.cloudFoundryClient, + this.nameFactory), // After Routes, cannot run with + // other cleanApps + cleanUsers(this.uaaClient, this.nameFactory) // After CF Users + )) + .thenMany( + Mono.when( // After Routes/Applications + cleanPrivateDomains(this.cloudFoundryClient, this.nameFactory), + cleanSharedDomains(this.cloudFoundryClient, this.nameFactory), + cleanSpaces(this.cloudFoundryClient, this.nameFactory))) + .thenMany( + cleanOrganizations( + this.cloudFoundryClient, this.nameFactory)) // After Spaces + .thenMany( + cleanOrganizationQuotaDefinitions( + this.cloudFoundryClient, this.nameFactory)) // After Organizations + .retryWhen(Retry.max(5).filter(SSLException.class::isInstance)) + .doOnSubscribe(s -> LOGGER.debug(">> CLEANUP <<")) + .doOnComplete(() -> LOGGER.debug("<< CLEANUP >>")) .then() - .doOnError(t -> LOGGER.error("Unable to delete V3 application {}", application.getName(), t))); + .block(Duration.ofMinutes(30)); + } + + private static Flux cleanApplicationsV3( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .applicationsV3() + .list(ListApplicationsRequest.builder().page(page).build())) + .filter(application -> nameFactory.isApplicationName(application.getName())) + .delayUntil( + application -> + removeApplicationServiceBindings(cloudFoundryClient, application)) + .flatMap( + application -> + cloudFoundryClient + .applicationsV3() + .delete( + DeleteApplicationRequest.builder() + .applicationId(application.getId()) + .build()) + .then() + .doOnError( + t -> + LOGGER.error( + "Unable to delete V3 application" + + " {}", + application.getName(), + t))); } - private static Flux cleanBuildpacks(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.buildpacks() - .list(ListBuildpacksRequest.builder() - .page(page) - .build())) - .filter(buildpack -> nameFactory.isBuildpackName(ResourceUtils.getEntity(buildpack).getName())) - .flatMap(buildpack -> cloudFoundryClient.buildpacks() - .delete(DeleteBuildpackRequest.builder() - .async(true) - .buildpackId(ResourceUtils.getId(buildpack)) - .build()) - .doOnError(t -> LOGGER.error("Unable to delete buildpack {}", ResourceUtils.getEntity(buildpack).getName(), t))) - .flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)); + private static Flux cleanBuildpacks( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .buildpacks() + .list(ListBuildpacksRequest.builder().page(page).build())) + .filter( + buildpack -> + nameFactory.isBuildpackName( + ResourceUtils.getEntity(buildpack).getName())) + .flatMap( + buildpack -> + cloudFoundryClient + .buildpacks() + .delete( + DeleteBuildpackRequest.builder() + .async(true) + .buildpackId(ResourceUtils.getId(buildpack)) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete buildpack {}", + ResourceUtils.getEntity(buildpack) + .getName(), + t))) + .flatMap( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, Duration.ofMinutes(5), job)); } private static Flux cleanClients(UaaClient uaaClient, NameFactory nameFactory) { - return PaginationUtils - .requestUaaResources(startIndex -> uaaClient.clients() - .list(ListClientsRequest.builder() - .startIndex(startIndex) - .build())) - .filter(client -> nameFactory.isClientId(client.getClientId())) - .flatMap(client -> uaaClient.clients() - .delete(DeleteClientRequest.builder() - .clientId(client.getClientId()) - .build()) - .doOnError(t -> LOGGER.error("Unable to delete client {}", client.getName(), t)) - .then()); + return PaginationUtils.requestUaaResources( + startIndex -> + uaaClient + .clients() + .list( + ListClientsRequest.builder() + .startIndex(startIndex) + .build())) + .filter(client -> nameFactory.isClientId(client.getClientId())) + .flatMap( + client -> + uaaClient + .clients() + .delete( + DeleteClientRequest.builder() + .clientId(client.getClientId()) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete client {}", + client.getName(), + t)) + .then()); } private static Flux cleanFeatureFlags(CloudFoundryClient cloudFoundryClient) { - return cloudFoundryClient.featureFlags() - .list(ListFeatureFlagsRequest.builder() - .build()) - .flatMapIterable(ListFeatureFlagsResponse::getFeatureFlags) - .filter(featureFlag -> STANDARD_FEATURE_FLAGS.containsKey(featureFlag.getName())) - .filter(featureFlag -> STANDARD_FEATURE_FLAGS.get(featureFlag.getName()) != featureFlag.getEnabled()) - .flatMap(featureFlag -> cloudFoundryClient.featureFlags() - .set(SetFeatureFlagRequest.builder() - .name(featureFlag.getName()) - .enabled(STANDARD_FEATURE_FLAGS.get(featureFlag.getName())) - .build()) - .doOnError(t -> LOGGER.error("Unable to set feature flag {} to {}", featureFlag.getName(), STANDARD_FEATURE_FLAGS.get(featureFlag.getName()), t)) - .then()); + return cloudFoundryClient + .featureFlags() + .list(ListFeatureFlagsRequest.builder().build()) + .flatMapIterable(ListFeatureFlagsResponse::getFeatureFlags) + .filter(featureFlag -> STANDARD_FEATURE_FLAGS.containsKey(featureFlag.getName())) + .filter( + featureFlag -> + STANDARD_FEATURE_FLAGS.get(featureFlag.getName()) + != featureFlag.getEnabled()) + .flatMap( + featureFlag -> + cloudFoundryClient + .featureFlags() + .set( + SetFeatureFlagRequest.builder() + .name(featureFlag.getName()) + .enabled( + STANDARD_FEATURE_FLAGS.get( + featureFlag.getName())) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to set feature flag {} to" + + " {}", + featureFlag.getName(), + STANDARD_FEATURE_FLAGS.get( + featureFlag.getName()), + t)) + .then()); } private static Flux cleanGroups(UaaClient uaaClient, NameFactory nameFactory) { - return PaginationUtils - .requestUaaResources(startIndex -> uaaClient.groups() - .list(ListGroupsRequest.builder() - .startIndex(startIndex) - .build())) - .filter(group -> nameFactory.isGroupName(group.getDisplayName())) - .sort((group1, group2) -> { - if (containsMember(group1, group2)) { - return -1; - } else if (containsMember(group2, group1)) { - return 1; - } else { - return 0; - } - }) - .concatMap(group -> uaaClient.groups() - .delete(DeleteGroupRequest.builder() - .groupId(group.getId()) - .version("*") - .build()) - .doOnError(t -> LOGGER.error("Unable to delete group {}", group.getDisplayName(), t)) - .then()); + return PaginationUtils.requestUaaResources( + startIndex -> + uaaClient + .groups() + .list( + ListGroupsRequest.builder() + .startIndex(startIndex) + .build())) + .filter(group -> nameFactory.isGroupName(group.getDisplayName())) + .sort( + (group1, group2) -> { + if (containsMember(group1, group2)) { + return -1; + } else if (containsMember(group2, group1)) { + return 1; + } else { + return 0; + } + }) + .concatMap( + group -> + uaaClient + .groups() + .delete( + DeleteGroupRequest.builder() + .groupId(group.getId()) + .version("*") + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete group {}", + group.getDisplayName(), + t)) + .then()); } private static Flux cleanIdentityProviders(UaaClient uaaClient, NameFactory nameFactory) { - return uaaClient.identityProviders() - .list(ListIdentityProvidersRequest.builder() - .build()) - .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) - .filter(provider -> nameFactory.isIdentityProviderName(provider.getName())) - .flatMap(provider -> uaaClient.identityProviders() - .delete(DeleteIdentityProviderRequest.builder() - .identityProviderId(provider.getId()) - .build()) - .doOnError(t -> LOGGER.error("Unable to delete identity provider {}", provider.getName(), t)) - .then()); + return uaaClient + .identityProviders() + .list(ListIdentityProvidersRequest.builder().build()) + .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) + .filter(provider -> nameFactory.isIdentityProviderName(provider.getName())) + .flatMap( + provider -> + uaaClient + .identityProviders() + .delete( + DeleteIdentityProviderRequest.builder() + .identityProviderId(provider.getId()) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete identity provider" + + " {}", + provider.getName(), + t)) + .then()); } private static Flux cleanIdentityZones(UaaClient uaaClient, NameFactory nameFactory) { - return uaaClient.identityZones() - .list(ListIdentityZonesRequest.builder() - .build()) - .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) - .filter(zone -> nameFactory.isIdentityZoneName(zone.getName())) - .flatMap(zone -> uaaClient.identityZones() - .delete(DeleteIdentityZoneRequest.builder() - .identityZoneId(zone.getId()) - .build()) - .doOnError(t -> LOGGER.error("Unable to delete identity zone {}", zone.getName(), t)) - .then()); - } - - private static Flux cleanNetworkingPolicies(NetworkingClient networkingClient, NameFactory nameFactory, Version serverVersion) { - return ifCfVersion(PCF_1_12, serverVersion, () -> networkingClient.policies() - .list(ListPoliciesRequest.builder() - .build()) - .flatMapIterable(ListPoliciesResponse::getPolicies) - .filter(policy -> nameFactory.isPort(policy.getDestination().getPorts().getStart())) - .filter(policy -> nameFactory.isPort(policy.getDestination().getPorts().getEnd())) - .flatMap(policy -> networkingClient.policies() - .delete(DeletePoliciesRequest.builder() - .policy(Policy.builder() - .destination(Destination.builder() - .id(policy.getDestination().getId()) - .ports(Ports.builder() - .end(policy.getDestination().getPorts().getEnd()) - .start(policy.getDestination().getPorts().getStart()) - .build()) - .protocol(policy.getDestination().getProtocol()) - .build()) - .source(Source.builder() - .id(policy.getSource().getId()) - .build()) - .build()) - .build()) - .doOnError(t -> LOGGER.error("Unable to delete networking policy between {} and {}", policy.getSource().getId(), policy.getDestination().getId(), t)) - .then())); - } - - private static Flux cleanOrganizationQuotaDefinitions(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.organizationQuotaDefinitions() - .list(ListOrganizationQuotaDefinitionsRequest.builder() - .page(page) - .build())) - .filter(domain -> nameFactory.isQuotaDefinitionName(ResourceUtils.getEntity(domain).getName())) - .flatMap(organizationQuotaDefinition -> cloudFoundryClient.organizationQuotaDefinitions() - .delete(DeleteOrganizationQuotaDefinitionRequest.builder() - .async(true) - .organizationQuotaDefinitionId(ResourceUtils.getId(organizationQuotaDefinition)) - .build()) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> LOGGER.error("Unable to delete organization quota definition {}", ResourceUtils.getEntity(organizationQuotaDefinition).getName(), t))); - } - - private static Flux cleanOrganizations(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.organizations() - .list(ListOrganizationsRequest.builder() - .page(page) - .build())) - .filter(organization -> nameFactory.isOrganizationName(ResourceUtils.getEntity(organization).getName())) - .flatMap(organization -> cloudFoundryClient.organizations() - .delete(DeleteOrganizationRequest.builder() - .async(true) - .organizationId(ResourceUtils.getId(organization)) - .build()) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> LOGGER.error("Unable to delete organization {}", ResourceUtils.getEntity(organization).getName(), t))); - } - - private static Flux cleanPrivateDomains(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.privateDomains() - .list(ListPrivateDomainsRequest.builder() - .page(page) - .build())) - .filter(domain -> nameFactory.isDomainName(ResourceUtils.getEntity(domain).getName())) - .flatMap(privateDomain -> cloudFoundryClient.privateDomains() - .delete(DeletePrivateDomainRequest.builder() - .async(true) - .privateDomainId(ResourceUtils.getId(privateDomain)) - .build()) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> LOGGER.error("Unable to delete private domain {}", ResourceUtils.getEntity(privateDomain).getName(), t))); - } - - private static Flux cleanRoutes(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return uaaClient + .identityZones() + .list(ListIdentityZonesRequest.builder().build()) + .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) + .filter(zone -> nameFactory.isIdentityZoneName(zone.getName())) + .flatMap( + zone -> + uaaClient + .identityZones() + .delete( + DeleteIdentityZoneRequest.builder() + .identityZoneId(zone.getId()) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete identity zone {}", + zone.getName(), + t)) + .then()); + } + + private static Flux cleanNetworkingPolicies( + NetworkingClient networkingClient, NameFactory nameFactory, Version serverVersion) { + return ifCfVersion( + PCF_1_12, + serverVersion, + () -> + networkingClient + .policies() + .list(ListPoliciesRequest.builder().build()) + .flatMapIterable(ListPoliciesResponse::getPolicies) + .filter( + policy -> + nameFactory.isPort( + policy.getDestination() + .getPorts() + .getStart())) + .filter( + policy -> + nameFactory.isPort( + policy.getDestination() + .getPorts() + .getEnd())) + .flatMap( + policy -> + networkingClient + .policies() + .delete( + DeletePoliciesRequest.builder() + .policy( + Policy.builder() + .destination( + Destination + .builder() + .id( + policy.getDestination() + .getId()) + .ports( + Ports + .builder() + .end( + policy.getDestination() + .getPorts() + .getEnd()) + .start( + policy.getDestination() + .getPorts() + .getStart()) + .build()) + .protocol( + policy.getDestination() + .getProtocol()) + .build()) + .source( + Source + .builder() + .id( + policy.getSource() + .getId()) + .build()) + .build()) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete" + + " networking" + + " policy" + + " between {}" + + " and {}", + policy.getSource() + .getId(), + policy.getDestination() + .getId(), + t)) + .then())); + } + + private static Flux cleanOrganizationQuotaDefinitions( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizationQuotaDefinitions() + .list( + ListOrganizationQuotaDefinitionsRequest.builder() + .page(page) + .build())) + .filter( + domain -> + nameFactory.isQuotaDefinitionName( + ResourceUtils.getEntity(domain).getName())) + .flatMap( + organizationQuotaDefinition -> + cloudFoundryClient + .organizationQuotaDefinitions() + .delete( + DeleteOrganizationQuotaDefinitionRequest.builder() + .async(true) + .organizationQuotaDefinitionId( + ResourceUtils.getId( + organizationQuotaDefinition)) + .build()) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> + LOGGER.error( + "Unable to delete organization" + + " quota definition {}", + ResourceUtils.getEntity( + organizationQuotaDefinition) + .getName(), + t))); + } + + private static Flux cleanOrganizations( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .list( + ListOrganizationsRequest.builder() + .page(page) + .build())) + .filter( + organization -> + nameFactory.isOrganizationName( + ResourceUtils.getEntity(organization).getName())) + .flatMap( + organization -> + cloudFoundryClient + .organizations() + .delete( + DeleteOrganizationRequest.builder() + .async(true) + .organizationId( + ResourceUtils.getId(organization)) + .build()) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> + LOGGER.error( + "Unable to delete organization {}", + ResourceUtils.getEntity( + organization) + .getName(), + t))); + } + + private static Flux cleanPrivateDomains( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .privateDomains() + .list( + ListPrivateDomainsRequest.builder() + .page(page) + .build())) + .filter( + domain -> + nameFactory.isDomainName(ResourceUtils.getEntity(domain).getName())) + .flatMap( + privateDomain -> + cloudFoundryClient + .privateDomains() + .delete( + DeletePrivateDomainRequest.builder() + .async(true) + .privateDomainId( + ResourceUtils.getId(privateDomain)) + .build()) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> + LOGGER.error( + "Unable to delete private domain" + + " {}", + ResourceUtils.getEntity( + privateDomain) + .getName(), + t))); + } + + private static Flux cleanRoutes( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { return getAllDomains(cloudFoundryClient) - .flatMapMany(domains -> PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.routes() - .list(ListRoutesRequest.builder() - .page(page) - .build())) - .map(resource -> Tuples.of(domains, resource))) - .filter(predicate((domains, route) -> nameFactory.isDomainName(domains.get(ResourceUtils.getEntity(route).getDomainId())) || - nameFactory.isApplicationName(ResourceUtils.getEntity(route).getHost()) || - nameFactory.isHostName(ResourceUtils.getEntity(route).getHost()))) - .flatMap(function((domains, route) -> cloudFoundryClient.routes() - .delete(DeleteRouteRequest.builder() - .async(true) - .routeId(ResourceUtils.getId(route)) - .build()) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> { - RouteEntity entity = ResourceUtils.getEntity(route); - LOGGER.error("Unable to delete route {}.{}:{}{}", entity.getHost(), domains.get(entity.getDomainId()), entity.getPort(), entity.getPath(), t); - }))); - } - - private static Flux cleanSecurityGroups(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.securityGroups() - .list(ListSecurityGroupsRequest.builder() - .page(page) - .build())) - .filter(securityGroup -> nameFactory.isSecurityGroupName(ResourceUtils.getEntity(securityGroup).getName())) - .flatMap(securityGroup -> cloudFoundryClient.securityGroups() - .delete(DeleteSecurityGroupRequest.builder() - .securityGroupId(ResourceUtils.getId(securityGroup)) - .build()) - .doOnError(t -> LOGGER.error("Unable to delete security group {}", ResourceUtils.getEntity(securityGroup).getName(), t)) - .then()); - } - - private static Flux cleanServiceBrokers(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceBrokers() - .list(ListServiceBrokersRequest.builder() - .page(page) - .build())) - .filter(serviceBroker -> nameFactory.isServiceBrokerName(ResourceUtils.getEntity(serviceBroker).getName())) - .flatMap(serviceBroker -> cloudFoundryClient.serviceBrokers() - .delete(DeleteServiceBrokerRequest.builder() - .serviceBrokerId(ResourceUtils.getId(serviceBroker)) - .build()) - .doOnError(t -> LOGGER.error("Unable to delete service broker {}", ResourceUtils.getEntity(serviceBroker).getName(), t))); - } - - private static Flux cleanServiceInstances(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, Version serverVersion) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .page(page) - .build())) - .filter(serviceInstance -> nameFactory.isServiceInstanceName(ResourceUtils.getEntity(serviceInstance).getName())) - .delayUntil(serviceInstance -> removeRouteAssociations(cloudFoundryClient, serviceInstance)) - .delayUntil(serviceInstance -> removeServiceInstanceServiceBindings(cloudFoundryClient, serviceInstance)) - .delayUntil(serviceInstance -> removeServiceKeys(cloudFoundryClient, serviceInstance)) - .delayUntil(serviceInstance -> removeServiceShares(cloudFoundryClient, serviceInstance, serverVersion)) - .flatMap(serviceInstance -> cloudFoundryClient.serviceInstances() - .delete(DeleteServiceInstanceRequest.builder() - .async(true) - .serviceInstanceId(ResourceUtils.getId(serviceInstance)) - .build()) - .flatMap(response -> { - Object entity = response.getEntity(); - if (entity instanceof JobEntity) { - return JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), (JobEntity) response.getEntity()); - } else { - return LastOperationUtils - .waitForCompletion(Duration.ofMinutes(5), () -> cloudFoundryClient.serviceInstances() - .get(GetServiceInstanceRequest.builder() - .serviceInstanceId(ResourceUtils.getId(serviceInstance)) - .build()) - .map(r -> ResourceUtils.getEntity(r).getLastOperation())); - } - }) - .doOnError(t -> LOGGER.error("Unable to delete service instance {}", ResourceUtils.getEntity(serviceInstance).getName(), t))); - } - - private static Flux cleanSharedDomains(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.sharedDomains() - .list(ListSharedDomainsRequest.builder() - .page(page) - .build())) - .filter(domain -> nameFactory.isDomainName(ResourceUtils.getEntity(domain).getName())) - .flatMap(domain -> cloudFoundryClient.sharedDomains() - .delete(DeleteSharedDomainRequest.builder() - .async(true) - .sharedDomainId(ResourceUtils.getId(domain)) - .build()) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> LOGGER.error("Unable to delete domain {}", ResourceUtils.getEntity(domain).getName(), t))); - } - - private static Flux cleanSpaceQuotaDefinitions(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaceQuotaDefinitions() - .list(ListSpaceQuotaDefinitionsRequest.builder() - .page(page) - .build())) - .filter(quota -> nameFactory.isQuotaDefinitionName(ResourceUtils.getEntity(quota).getName())) - .flatMap(quota -> cloudFoundryClient.spaceQuotaDefinitions() - .delete((DeleteSpaceQuotaDefinitionRequest.builder() - .async(true) - .spaceQuotaDefinitionId(ResourceUtils.getId(quota)) - .build())) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> LOGGER.error("Unable to delete space quota definition {}", ResourceUtils.getEntity(quota).getName(), t))); - } - - private static Flux cleanSpaces(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .list(ListSpacesRequest.builder() - .page(page) - .build())) - .filter(space -> nameFactory.isSpaceName(ResourceUtils.getEntity(space).getName())) - .delayUntil(space -> removeSpaceMetadata(cloudFoundryClient, space)) //TODO: Remove once the delete spaces endpoint handles spaces with metadata - .flatMap(space -> cloudFoundryClient.spaces() - .delete(DeleteSpaceRequest.builder() - .async(true) - .recursive(true) - .spaceId(ResourceUtils.getId(space)) - .build()) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> LOGGER.error("Unable to delete space {}", ResourceUtils.getEntity(space).getName(), t))); - } - - private static Flux cleanStacks(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.stacks() - .list(ListStacksRequest.builder() - .page(page) - .build())) - .filter(stack -> nameFactory.isStackName(ResourceUtils.getEntity(stack).getName())) - .flatMap(stack -> cloudFoundryClient.stacks() - .delete((DeleteStackRequest.builder() - .async(true) - .stackId(ResourceUtils.getId(stack)) - .build())) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> LOGGER.error("Unable to delete stack {}", ResourceUtils.getEntity(stack).getName(), t))); - } - - private static Flux cleanUserProvidedServiceInstances(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.userProvidedServiceInstances() - .list(ListUserProvidedServiceInstancesRequest.builder() - .page(page) - .build())) - .filter(userProvidedServiceInstance -> nameFactory.isServiceInstanceName(ResourceUtils.getEntity(userProvidedServiceInstance).getName())) - .delayUntil(userProvidedServiceInstance -> removeRouteAssociations(cloudFoundryClient, userProvidedServiceInstance)) - .delayUntil(userProvidedServiceInstance -> removeUserProvidedServiceInstanceServiceBindings(cloudFoundryClient, userProvidedServiceInstance)) - .flatMap(userProvidedServiceInstance -> cloudFoundryClient.userProvidedServiceInstances() - .delete(DeleteUserProvidedServiceInstanceRequest.builder() - .userProvidedServiceInstanceId(ResourceUtils.getId(userProvidedServiceInstance)) - .build()) - .doOnError(t -> LOGGER.error("Unable to delete user provided service instance {}", ResourceUtils.getEntity(userProvidedServiceInstance).getName(), t))); - } - - private static Flux cleanUsers(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.users() - .list(org.cloudfoundry.client.v2.users.ListUsersRequest.builder() - .page(page) - .build())) - .filter(resource -> isCleanable(nameFactory, resource)) - .map(resource -> resource.getMetadata().getId()) - .flatMap(userId -> cloudFoundryClient.users() - .delete(org.cloudfoundry.client.v2.users.DeleteUserRequest.builder() - .async(true) - .userId(userId) - .build()) - .flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)) - .doOnError(t -> LOGGER.error("Unable to delete user {}", userId, t))); + .flatMapMany( + domains -> + PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .routes() + .list( + ListRoutesRequest.builder() + .page(page) + .build())) + .map(resource -> Tuples.of(domains, resource))) + .filter( + predicate( + (domains, route) -> + nameFactory.isDomainName( + domains.get( + ResourceUtils.getEntity(route) + .getDomainId())) + || nameFactory.isApplicationName( + ResourceUtils.getEntity(route).getHost()) + || nameFactory.isHostName( + ResourceUtils.getEntity(route).getHost()))) + .flatMap( + function( + (domains, route) -> + cloudFoundryClient + .routes() + .delete( + DeleteRouteRequest.builder() + .async(true) + .routeId(ResourceUtils.getId(route)) + .build()) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> { + RouteEntity entity = + ResourceUtils.getEntity(route); + LOGGER.error( + "Unable to delete route" + + " {}.{}:{}{}", + entity.getHost(), + domains.get( + entity.getDomainId()), + entity.getPort(), + entity.getPath(), + t); + }))); + } + + private static Flux cleanSecurityGroups( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .securityGroups() + .list( + ListSecurityGroupsRequest.builder() + .page(page) + .build())) + .filter( + securityGroup -> + nameFactory.isSecurityGroupName( + ResourceUtils.getEntity(securityGroup).getName())) + .flatMap( + securityGroup -> + cloudFoundryClient + .securityGroups() + .delete( + DeleteSecurityGroupRequest.builder() + .securityGroupId( + ResourceUtils.getId(securityGroup)) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete security group" + + " {}", + ResourceUtils.getEntity( + securityGroup) + .getName(), + t)) + .then()); + } + + private static Flux cleanServiceBrokers( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceBrokers() + .list( + ListServiceBrokersRequest.builder() + .page(page) + .build())) + .filter( + serviceBroker -> + nameFactory.isServiceBrokerName( + ResourceUtils.getEntity(serviceBroker).getName())) + .flatMap( + serviceBroker -> + cloudFoundryClient + .serviceBrokers() + .delete( + DeleteServiceBrokerRequest.builder() + .serviceBrokerId( + ResourceUtils.getId(serviceBroker)) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete service broker" + + " {}", + ResourceUtils.getEntity( + serviceBroker) + .getName(), + t))); + } + + private static Flux cleanServiceInstances( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, Version serverVersion) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest.builder() + .page(page) + .build())) + .filter( + serviceInstance -> + nameFactory.isServiceInstanceName( + ResourceUtils.getEntity(serviceInstance).getName())) + .delayUntil( + serviceInstance -> + removeRouteAssociations(cloudFoundryClient, serviceInstance)) + .delayUntil( + serviceInstance -> + removeServiceInstanceServiceBindings( + cloudFoundryClient, serviceInstance)) + .delayUntil( + serviceInstance -> removeServiceKeys(cloudFoundryClient, serviceInstance)) + .delayUntil( + serviceInstance -> + removeServiceShares( + cloudFoundryClient, serviceInstance, serverVersion)) + .flatMap( + serviceInstance -> + cloudFoundryClient + .serviceInstances() + .delete( + DeleteServiceInstanceRequest.builder() + .async(true) + .serviceInstanceId( + ResourceUtils.getId( + serviceInstance)) + .build()) + .flatMap( + response -> { + Object entity = response.getEntity(); + if (entity instanceof JobEntity) { + return JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + (JobEntity) response.getEntity()); + } else { + return LastOperationUtils.waitForCompletion( + Duration.ofMinutes(5), + () -> + cloudFoundryClient + .serviceInstances() + .get( + GetServiceInstanceRequest + .builder() + .serviceInstanceId( + ResourceUtils + .getId( + serviceInstance)) + .build()) + .map( + r -> + ResourceUtils + .getEntity( + r) + .getLastOperation())); + } + }) + .doOnError( + t -> + LOGGER.error( + "Unable to delete service instance" + + " {}", + ResourceUtils.getEntity( + serviceInstance) + .getName(), + t))); + } + + private static Flux cleanSharedDomains( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .sharedDomains() + .list( + ListSharedDomainsRequest.builder() + .page(page) + .build())) + .filter( + domain -> + nameFactory.isDomainName(ResourceUtils.getEntity(domain).getName())) + .flatMap( + domain -> + cloudFoundryClient + .sharedDomains() + .delete( + DeleteSharedDomainRequest.builder() + .async(true) + .sharedDomainId(ResourceUtils.getId(domain)) + .build()) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> + LOGGER.error( + "Unable to delete domain {}", + ResourceUtils.getEntity(domain) + .getName(), + t))); + } + + private static Flux cleanSpaceQuotaDefinitions( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaceQuotaDefinitions() + .list( + ListSpaceQuotaDefinitionsRequest.builder() + .page(page) + .build())) + .filter( + quota -> + nameFactory.isQuotaDefinitionName( + ResourceUtils.getEntity(quota).getName())) + .flatMap( + quota -> + cloudFoundryClient + .spaceQuotaDefinitions() + .delete( + (DeleteSpaceQuotaDefinitionRequest.builder() + .async(true) + .spaceQuotaDefinitionId( + ResourceUtils.getId(quota)) + .build())) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> + LOGGER.error( + "Unable to delete space quota" + + " definition {}", + ResourceUtils.getEntity(quota) + .getName(), + t))); + } + + private static Flux cleanSpaces( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .list(ListSpacesRequest.builder().page(page).build())) + .filter(space -> nameFactory.isSpaceName(ResourceUtils.getEntity(space).getName())) + .delayUntil( + space -> + removeSpaceMetadata( + cloudFoundryClient, + space)) // TODO: Remove once the delete spaces endpoint + // handles spaces with metadata + .flatMap( + space -> + cloudFoundryClient + .spaces() + .delete( + DeleteSpaceRequest.builder() + .async(true) + .recursive(true) + .spaceId(ResourceUtils.getId(space)) + .build()) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> + LOGGER.error( + "Unable to delete space {}", + ResourceUtils.getEntity(space) + .getName(), + t))); + } + + private static Flux cleanStacks( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .stacks() + .list(ListStacksRequest.builder().page(page).build())) + .filter(stack -> nameFactory.isStackName(ResourceUtils.getEntity(stack).getName())) + .flatMap( + stack -> + cloudFoundryClient + .stacks() + .delete( + (DeleteStackRequest.builder() + .async(true) + .stackId(ResourceUtils.getId(stack)) + .build())) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> + LOGGER.error( + "Unable to delete stack {}", + ResourceUtils.getEntity(stack) + .getName(), + t))); + } + + private static Flux cleanUserProvidedServiceInstances( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .userProvidedServiceInstances() + .list( + ListUserProvidedServiceInstancesRequest.builder() + .page(page) + .build())) + .filter( + userProvidedServiceInstance -> + nameFactory.isServiceInstanceName( + ResourceUtils.getEntity(userProvidedServiceInstance) + .getName())) + .delayUntil( + userProvidedServiceInstance -> + removeRouteAssociations( + cloudFoundryClient, userProvidedServiceInstance)) + .delayUntil( + userProvidedServiceInstance -> + removeUserProvidedServiceInstanceServiceBindings( + cloudFoundryClient, userProvidedServiceInstance)) + .flatMap( + userProvidedServiceInstance -> + cloudFoundryClient + .userProvidedServiceInstances() + .delete( + DeleteUserProvidedServiceInstanceRequest.builder() + .userProvidedServiceInstanceId( + ResourceUtils.getId( + userProvidedServiceInstance)) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete user provided" + + " service instance {}", + ResourceUtils.getEntity( + userProvidedServiceInstance) + .getName(), + t))); + } + + private static Flux cleanUsers( + CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .users() + .list( + org.cloudfoundry.client.v2.users.ListUsersRequest + .builder() + .page(page) + .build())) + .filter(resource -> isCleanable(nameFactory, resource)) + .map(resource -> resource.getMetadata().getId()) + .flatMap( + userId -> + cloudFoundryClient + .users() + .delete( + org.cloudfoundry.client.v2.users.DeleteUserRequest + .builder() + .async(true) + .userId(userId) + .build()) + .flatMapMany( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .doOnError( + t -> + LOGGER.error( + "Unable to delete user {}", + userId, + t))); } private static Flux cleanUsers(UaaClient uaaClient, NameFactory nameFactory) { - return PaginationUtils - .requestUaaResources(startIndex -> uaaClient.users() - .list(ListUsersRequest.builder() - .startIndex(startIndex) - .build())) - .filter(user -> nameFactory.isUserName(user.getUserName())) - .flatMap(user -> uaaClient.users() - .delete(DeleteUserRequest.builder() - .userId(user.getId()) - .version("*") - .build()) - .doOnError(t -> LOGGER.error("Unable to delete user {}", user.getName(), t)) - .then()); + return PaginationUtils.requestUaaResources( + startIndex -> + uaaClient + .users() + .list( + ListUsersRequest.builder() + .startIndex(startIndex) + .build())) + .filter(user -> nameFactory.isUserName(user.getUserName())) + .flatMap( + user -> + uaaClient + .users() + .delete( + DeleteUserRequest.builder() + .userId(user.getId()) + .version("*") + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to delete user {}", + user.getName(), + t)) + .then()); } private static boolean containsMember(Group group, Group candidate) { return group.getMembers().stream() - .map(MemberSummary::getMemberId) - .anyMatch(id -> candidate.getId().equals(id)); + .map(MemberSummary::getMemberId) + .anyMatch(id -> candidate.getId().equals(id)); } private static Mono> getAllDomains(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.privateDomains() - .list(ListPrivateDomainsRequest.builder() - .page(page) - .build())) - .map(response -> Tuples.of(ResourceUtils.getId(response), ResourceUtils.getEntity(response).getName())) - .mergeWith(PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.sharedDomains() - .list(ListSharedDomainsRequest.builder() - .page(page) - .build())) - .map(response -> Tuples.of(ResourceUtils.getId(response), ResourceUtils.getEntity(response).getName()))) - .collectMap(function((id, name) -> id), function((id, name) -> name)); - } - - private static Flux ifCfVersion(CloudFoundryVersion expectedVersion, Version serverVersion, Supplier> supplier) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .privateDomains() + .list( + ListPrivateDomainsRequest.builder() + .page(page) + .build())) + .map( + response -> + Tuples.of( + ResourceUtils.getId(response), + ResourceUtils.getEntity(response).getName())) + .mergeWith( + PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .sharedDomains() + .list( + ListSharedDomainsRequest.builder() + .page(page) + .build())) + .map( + response -> + Tuples.of( + ResourceUtils.getId(response), + ResourceUtils.getEntity(response) + .getName()))) + .collectMap(function((id, name) -> id), function((id, name) -> name)); + } + + private static Flux ifCfVersion( + CloudFoundryVersion expectedVersion, + Version serverVersion, + Supplier> supplier) { return serverVersion.lessThan(expectedVersion.getVersion()) ? Flux.empty() : supplier.get(); } private static boolean isCleanable(NameFactory nameFactory, UserResource resource) { - return nameFactory.isUserId(ResourceUtils.getId(resource)) || nameFactory.isUserName(ResourceUtils.getEntity(resource).getUsername()); - } - - private static Flux removeApplicationServiceBindings(CloudFoundryClient cloudFoundryClient, Application application) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.applicationsV2() - .listServiceBindings(ListApplicationServiceBindingsRequest.builder() - .page(page) - .applicationId(application.getId()) - .build())) - .flatMap(serviceBinding -> requestRemoveServiceBinding(cloudFoundryClient, application.getId(), ResourceUtils.getId(serviceBinding)) - .doOnError(t -> LOGGER.error("Unable to remove service binding from {}", application.getName(), t))); - } - - private static Flux removeRouteAssociations(CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceInstances() - .listRoutes(ListServiceInstanceRoutesRequest.builder() - .page(page) - .serviceInstanceId(ResourceUtils.getId(serviceInstance)) - .build())) - .flatMap(route -> cloudFoundryClient.serviceInstances() - .unbindRoute(UnbindServiceInstanceRouteRequest.builder() - .routeId(ResourceUtils.getId(route)) - .serviceInstanceId(ResourceUtils.getId(serviceInstance)) - .build()) - .doOnError(t -> LOGGER.error("Unable to remove route binding from {}", ResourceUtils.getEntity(serviceInstance).getName(), t))); - } - - private static Flux removeRouteAssociations(CloudFoundryClient cloudFoundryClient, UserProvidedServiceInstanceResource serviceInstance) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.userProvidedServiceInstances() - .listRoutes(ListUserProvidedServiceInstanceRoutesRequest.builder() - .page(page) - .userProvidedServiceInstanceId(ResourceUtils.getId(serviceInstance)) - .build())) - .flatMap(route -> cloudFoundryClient.userProvidedServiceInstances() - .removeRoute(RemoveUserProvidedServiceInstanceRouteRequest.builder() - .routeId(ResourceUtils.getId(route)) - .userProvidedServiceInstanceId(ResourceUtils.getId(serviceInstance)) - .build()) - .doOnError(t -> LOGGER.error("Unable to remove route binding from {}", ResourceUtils.getEntity(serviceInstance).getName(), t))); - } - - private static Flux removeServiceInstanceServiceBindings(CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceInstances() - .listServiceBindings(ListServiceInstanceServiceBindingsRequest.builder() - .page(page) - .serviceInstanceId(ResourceUtils.getId(serviceInstance)) - .build())) - .flatMap(serviceBinding -> requestRemoveServiceBinding(cloudFoundryClient, ResourceUtils.getEntity(serviceBinding).getApplicationId(), ResourceUtils.getId(serviceBinding)) - .doOnError(t -> LOGGER.error("Unable to remove service binding from {}", ResourceUtils.getEntity(serviceInstance).getName(), t))); - } - - private static Flux removeServiceKeys(CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceInstances() - .listServiceKeys(ListServiceInstanceServiceKeysRequest.builder() - .page(page) - .serviceInstanceId(ResourceUtils.getId(serviceInstance)) - .build())) - .flatMap(serviceKey -> cloudFoundryClient.serviceKeys() - .delete(DeleteServiceKeyRequest.builder() - .serviceKeyId(ResourceUtils.getId(serviceKey)) - .build()) - .doOnError(t -> LOGGER.error("Unable to remove service binding from {}", ResourceUtils.getEntity(serviceKey).getName(), t))); - } - - private static Flux removeServiceShares(CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance, Version serverVersion) { - return ifCfVersion(PCF_2_1, serverVersion, () -> cloudFoundryClient.serviceInstancesV3() - .listSharedSpacesRelationship(ListSharedSpacesRelationshipRequest.builder() - .serviceInstanceId(ResourceUtils.getId(serviceInstance)) - .build()) - .flatMapIterable(ListSharedSpacesRelationshipResponse::getData) - .map(Relationship::getId) - .flatMap(spaceId -> requestUnshareServiceInstance(cloudFoundryClient, serviceInstance, spaceId) - .doOnError(t -> LOGGER.error("Unable to remove service share from {}", ResourceUtils.getEntity(serviceInstance).getName(), t)))); - } - - private static Mono removeSpaceMetadata(CloudFoundryClient cloudFoundryClient, SpaceResource space) { - return cloudFoundryClient.spacesV3() - .get(GetSpaceRequest.builder() - .spaceId(ResourceUtils.getId(space)) - .build()) - .map(GetSpaceResponse::getMetadata) - .flatMap(metadata -> { - if (metadata.getAnnotations().isEmpty() && metadata.getLabels().isEmpty()) { - return Mono.empty(); - } - - Map annotations = new HashMap<>(metadata.getAnnotations()); - Map labels = new HashMap<>(metadata.getLabels()); - - annotations.replaceAll((k, v) -> null); - labels.replaceAll((k, v) -> null); - - return requestUpdateSpace(cloudFoundryClient, annotations, labels, ResourceUtils.getId(space)) - .doOnError(t -> LOGGER.error("Unable to remove metadata from {}", ResourceUtils.getEntity(space).getName())); - }); - } - - private static Flux removeUserProvidedServiceInstanceServiceBindings(CloudFoundryClient cloudFoundryClient, UserProvidedServiceInstanceResource serviceInstance) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.userProvidedServiceInstances() - .listServiceBindings(ListUserProvidedServiceInstanceServiceBindingsRequest.builder() - .page(page) - .userProvidedServiceInstanceId(ResourceUtils.getId(serviceInstance)) - .build())) - .flatMap(serviceBinding -> requestRemoveServiceBinding(cloudFoundryClient, ResourceUtils.getEntity(serviceBinding).getApplicationId(), ResourceUtils.getId(serviceBinding)) - .doOnError(t -> LOGGER.error("Unable to remove service binding from {}", ResourceUtils.getEntity(serviceInstance).getName(), t))); - } - - private static Mono requestRemoveServiceBinding(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceBindingId) { - return cloudFoundryClient.applicationsV2() - .removeServiceBinding(RemoveApplicationServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceBindingId(serviceBindingId) - .build()); - } - - private static Mono requestUnshareServiceInstance(CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance, String spaceId) { - return cloudFoundryClient.serviceInstancesV3() - .unshare(UnshareServiceInstanceRequest.builder() - .serviceInstanceId(ResourceUtils.getId(serviceInstance)) - .spaceId(spaceId) - .build()); - } - - private static Mono requestUpdateSpace(CloudFoundryClient cloudFoundryClient, Map annotations, Map labels, String spaceId) { - return cloudFoundryClient.spacesV3() - .update(UpdateSpaceRequest.builder() - .metadata(Metadata.builder() - .annotations(annotations) - .labels(labels) - .build()) - .spaceId(spaceId) - .build()); + return nameFactory.isUserId(ResourceUtils.getId(resource)) + || nameFactory.isUserName(ResourceUtils.getEntity(resource).getUsername()); + } + + private static Flux removeApplicationServiceBindings( + CloudFoundryClient cloudFoundryClient, Application application) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .applicationsV2() + .listServiceBindings( + ListApplicationServiceBindingsRequest.builder() + .page(page) + .applicationId(application.getId()) + .build())) + .flatMap( + serviceBinding -> + requestRemoveServiceBinding( + cloudFoundryClient, + application.getId(), + ResourceUtils.getId(serviceBinding)) + .doOnError( + t -> + LOGGER.error( + "Unable to remove service binding" + + " from {}", + application.getName(), + t))); + } + + private static Flux removeRouteAssociations( + CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceInstances() + .listRoutes( + ListServiceInstanceRoutesRequest.builder() + .page(page) + .serviceInstanceId( + ResourceUtils.getId( + serviceInstance)) + .build())) + .flatMap( + route -> + cloudFoundryClient + .serviceInstances() + .unbindRoute( + UnbindServiceInstanceRouteRequest.builder() + .routeId(ResourceUtils.getId(route)) + .serviceInstanceId( + ResourceUtils.getId( + serviceInstance)) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to remove route binding" + + " from {}", + ResourceUtils.getEntity( + serviceInstance) + .getName(), + t))); + } + + private static Flux removeRouteAssociations( + CloudFoundryClient cloudFoundryClient, + UserProvidedServiceInstanceResource serviceInstance) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .userProvidedServiceInstances() + .listRoutes( + ListUserProvidedServiceInstanceRoutesRequest + .builder() + .page(page) + .userProvidedServiceInstanceId( + ResourceUtils.getId( + serviceInstance)) + .build())) + .flatMap( + route -> + cloudFoundryClient + .userProvidedServiceInstances() + .removeRoute( + RemoveUserProvidedServiceInstanceRouteRequest + .builder() + .routeId(ResourceUtils.getId(route)) + .userProvidedServiceInstanceId( + ResourceUtils.getId( + serviceInstance)) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to remove route binding" + + " from {}", + ResourceUtils.getEntity( + serviceInstance) + .getName(), + t))); + } + + private static Flux removeServiceInstanceServiceBindings( + CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceInstances() + .listServiceBindings( + ListServiceInstanceServiceBindingsRequest.builder() + .page(page) + .serviceInstanceId( + ResourceUtils.getId( + serviceInstance)) + .build())) + .flatMap( + serviceBinding -> + requestRemoveServiceBinding( + cloudFoundryClient, + ResourceUtils.getEntity(serviceBinding) + .getApplicationId(), + ResourceUtils.getId(serviceBinding)) + .doOnError( + t -> + LOGGER.error( + "Unable to remove service binding" + + " from {}", + ResourceUtils.getEntity( + serviceInstance) + .getName(), + t))); + } + + private static Flux removeServiceKeys( + CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceInstances() + .listServiceKeys( + ListServiceInstanceServiceKeysRequest.builder() + .page(page) + .serviceInstanceId( + ResourceUtils.getId( + serviceInstance)) + .build())) + .flatMap( + serviceKey -> + cloudFoundryClient + .serviceKeys() + .delete( + DeleteServiceKeyRequest.builder() + .serviceKeyId( + ResourceUtils.getId(serviceKey)) + .build()) + .doOnError( + t -> + LOGGER.error( + "Unable to remove service binding" + + " from {}", + ResourceUtils.getEntity(serviceKey) + .getName(), + t))); } + private static Flux removeServiceShares( + CloudFoundryClient cloudFoundryClient, + ServiceInstanceResource serviceInstance, + Version serverVersion) { + return ifCfVersion( + PCF_2_1, + serverVersion, + () -> + cloudFoundryClient + .serviceInstancesV3() + .listSharedSpacesRelationship( + ListSharedSpacesRelationshipRequest.builder() + .serviceInstanceId( + ResourceUtils.getId(serviceInstance)) + .build()) + .flatMapIterable(ListSharedSpacesRelationshipResponse::getData) + .map(Relationship::getId) + .flatMap( + spaceId -> + requestUnshareServiceInstance( + cloudFoundryClient, + serviceInstance, + spaceId) + .doOnError( + t -> + LOGGER.error( + "Unable to remove" + + " service" + + " share from" + + " {}", + ResourceUtils + .getEntity( + serviceInstance) + .getName(), + t)))); + } + + private static Mono removeSpaceMetadata( + CloudFoundryClient cloudFoundryClient, SpaceResource space) { + return cloudFoundryClient + .spacesV3() + .get(GetSpaceRequest.builder().spaceId(ResourceUtils.getId(space)).build()) + .map(GetSpaceResponse::getMetadata) + .flatMap( + metadata -> { + if (metadata.getAnnotations().isEmpty() + && metadata.getLabels().isEmpty()) { + return Mono.empty(); + } + + Map annotations = + new HashMap<>(metadata.getAnnotations()); + Map labels = new HashMap<>(metadata.getLabels()); + + annotations.replaceAll((k, v) -> null); + labels.replaceAll((k, v) -> null); + + return requestUpdateSpace( + cloudFoundryClient, + annotations, + labels, + ResourceUtils.getId(space)) + .doOnError( + t -> + LOGGER.error( + "Unable to remove metadata from {}", + ResourceUtils.getEntity(space) + .getName())); + }); + } + + private static Flux removeUserProvidedServiceInstanceServiceBindings( + CloudFoundryClient cloudFoundryClient, + UserProvidedServiceInstanceResource serviceInstance) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .userProvidedServiceInstances() + .listServiceBindings( + ListUserProvidedServiceInstanceServiceBindingsRequest + .builder() + .page(page) + .userProvidedServiceInstanceId( + ResourceUtils.getId( + serviceInstance)) + .build())) + .flatMap( + serviceBinding -> + requestRemoveServiceBinding( + cloudFoundryClient, + ResourceUtils.getEntity(serviceBinding) + .getApplicationId(), + ResourceUtils.getId(serviceBinding)) + .doOnError( + t -> + LOGGER.error( + "Unable to remove service binding" + + " from {}", + ResourceUtils.getEntity( + serviceInstance) + .getName(), + t))); + } + + private static Mono requestRemoveServiceBinding( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceBindingId) { + return cloudFoundryClient + .applicationsV2() + .removeServiceBinding( + RemoveApplicationServiceBindingRequest.builder() + .applicationId(applicationId) + .serviceBindingId(serviceBindingId) + .build()); + } + + private static Mono requestUnshareServiceInstance( + CloudFoundryClient cloudFoundryClient, + ServiceInstanceResource serviceInstance, + String spaceId) { + return cloudFoundryClient + .serviceInstancesV3() + .unshare( + UnshareServiceInstanceRequest.builder() + .serviceInstanceId(ResourceUtils.getId(serviceInstance)) + .spaceId(spaceId) + .build()); + } + + private static Mono requestUpdateSpace( + CloudFoundryClient cloudFoundryClient, + Map annotations, + Map labels, + String spaceId) { + return cloudFoundryClient + .spacesV3() + .update( + UpdateSpaceRequest.builder() + .metadata( + Metadata.builder() + .annotations(annotations) + .labels(labels) + .build()) + .spaceId(spaceId) + .build()); + } } diff --git a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersion.java b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersion.java index 0fabb86744a..1f88cc6055d 100644 --- a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersion.java +++ b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersion.java @@ -19,7 +19,6 @@ import com.github.zafarkhaja.semver.Version; public enum CloudFoundryVersion { - PCF_1_9(Version.forIntegers(2, 65, 0)), PCF_1_10(Version.forIntegers(2, 75, 0)), @@ -67,5 +66,4 @@ public enum CloudFoundryVersion { Version getVersion() { return this.version; } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersionConditionalRule.java b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersionConditionalRule.java index 173b68bbe8d..7fb0089dfd9 100644 --- a/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersionConditionalRule.java +++ b/integration-test/src/test/java/org/cloudfoundry/CloudFoundryVersionConditionalRule.java @@ -16,18 +16,17 @@ package org.cloudfoundry; -import com.github.zafarkhaja.semver.Version; -import org.junit.Assume; -import org.junit.rules.MethodRule; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.Statement; -import org.springframework.core.annotation.AnnotationUtils; +import static org.cloudfoundry.CloudFoundryVersion.UNSPECIFIED; +import com.github.zafarkhaja.semver.Version; +import java.lang.reflect.AnnotatedElement; import java.util.Optional; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.springframework.core.annotation.AnnotationUtils; -import static org.cloudfoundry.CloudFoundryVersion.UNSPECIFIED; - -final class CloudFoundryVersionConditionalRule implements MethodRule { +final class CloudFoundryVersionConditionalRule implements ExecutionCondition { private final Version server; @@ -36,23 +35,24 @@ final class CloudFoundryVersionConditionalRule implements MethodRule { } @Override - public Statement apply(Statement base, FrameworkMethod method, Object target) { - return new Statement() { - - @Override - public void evaluate() throws Throwable { - IfCloudFoundryVersion annotation = Optional.ofNullable(AnnotationUtils.findAnnotation(method.getMethod(), IfCloudFoundryVersion.class)) - .orElse(AnnotationUtils.findAnnotation(method.getDeclaringClass(), IfCloudFoundryVersion.class)); - - boolean enabled = Optional.ofNullable(annotation) - .map(c -> isTestEnabled(c, CloudFoundryVersionConditionalRule.this.server)) - .orElse(true); - - Assume.assumeTrue(String.format("Cloud Foundry version required by @IfCloudFoundryVersion is not valid for test method [%s].", method.getMethod()), enabled); - - base.evaluate(); - } - }; + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + AnnotatedElement element = context.getElement().orElse(null); + + IfCloudFoundryVersion annotation = + AnnotationUtils.findAnnotation(element, IfCloudFoundryVersion.class); + + boolean enabled = + Optional.ofNullable(annotation) + .map(c -> isTestEnabled(c, CloudFoundryVersionConditionalRule.this.server)) + .orElse(true); + + return enabled + ? ConditionEvaluationResult.enabled("Test enabled") + : ConditionEvaluationResult.disabled( + String.format( + "Cloud Foundry version required by @IfCloudFoundryVersion is not" + + " valid for test method [%s].", + element)); } private static boolean isTestEnabled(IfCloudFoundryVersion condition, Version server) { @@ -63,7 +63,8 @@ private static boolean isTestEnabled(IfCloudFoundryVersion condition, Version se } if (condition.lessThanOrEqualTo() != UNSPECIFIED) { - enabled = enabled && server.lessThanOrEqualTo(condition.lessThanOrEqualTo().getVersion()); + enabled = + enabled && server.lessThanOrEqualTo(condition.lessThanOrEqualTo().getVersion()); } if (condition.equalTo() != UNSPECIFIED) { @@ -71,7 +72,10 @@ private static boolean isTestEnabled(IfCloudFoundryVersion condition, Version se } if (condition.greaterThanOrEqualTo() != UNSPECIFIED) { - enabled = enabled && server.greaterThanOrEqualTo(condition.greaterThanOrEqualTo().getVersion()); + enabled = + enabled + && server.greaterThanOrEqualTo( + condition.greaterThanOrEqualTo().getVersion()); } if (condition.greaterThan() != UNSPECIFIED) { @@ -80,5 +84,4 @@ private static boolean isTestEnabled(IfCloudFoundryVersion condition, Version se return enabled; } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/ExampleConfiguration.java b/integration-test/src/test/java/org/cloudfoundry/ExampleConfiguration.java index 399308081ec..fef0e018e1c 100644 --- a/integration-test/src/test/java/org/cloudfoundry/ExampleConfiguration.java +++ b/integration-test/src/test/java/org/cloudfoundry/ExampleConfiguration.java @@ -62,78 +62,78 @@ public class ExampleConfiguration { @Bean @Lazy - ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { + ReactorCloudFoundryClient cloudFoundryClient( + ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorCloudFoundryClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean @Lazy - DefaultCloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient, - DopplerClient dopplerClient, - RoutingClient routingClient, - UaaClient uaaClient, - @Value("${example.organization}") String organization, - @Value("${example.space}") String space) { + DefaultCloudFoundryOperations cloudFoundryOperations( + CloudFoundryClient cloudFoundryClient, + DopplerClient dopplerClient, + RoutingClient routingClient, + UaaClient uaaClient, + @Value("${example.organization}") String organization, + @Value("${example.space}") String space) { return DefaultCloudFoundryOperations.builder() - .cloudFoundryClient(cloudFoundryClient) - .dopplerClient(dopplerClient) - .routingClient(routingClient) - .uaaClient(uaaClient) - .organization(organization) - .space(space) - .build(); + .cloudFoundryClient(cloudFoundryClient) + .dopplerClient(dopplerClient) + .routingClient(routingClient) + .uaaClient(uaaClient) + .organization(organization) + .space(space) + .build(); } @Bean @Lazy - DefaultConnectionContext connectionContext(@Value("${example.apiHost}") String apiHost, - @Value("${example.skipSslValidation:false}") Boolean skipSslValidation) { + DefaultConnectionContext connectionContext( + @Value("${example.apiHost}") String apiHost, + @Value("${example.skipSslValidation:false}") Boolean skipSslValidation) { return DefaultConnectionContext.builder() - .apiHost(apiHost) - .skipSslValidation(skipSslValidation) - .build(); + .apiHost(apiHost) + .skipSslValidation(skipSslValidation) + .build(); } @Bean @Lazy DopplerClient dopplerClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorDopplerClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean @Lazy RoutingClient routingClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorRoutingClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean @Lazy - PasswordGrantTokenProvider tokenProvider(@Value("${example.password}") String password, - @Value("${example.username}") String username) { + PasswordGrantTokenProvider tokenProvider( + @Value("${example.password}") String password, + @Value("${example.username}") String username) { - return PasswordGrantTokenProvider.builder() - .password(password) - .username(username) - .build(); + return PasswordGrantTokenProvider.builder().password(password).username(username).build(); } @Bean @Lazy ReactorUaaClient uaaClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorUaaClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/IfCloudFoundryVersion.java b/integration-test/src/test/java/org/cloudfoundry/IfCloudFoundryVersion.java index 3d199081299..cbe64e5eb9d 100644 --- a/integration-test/src/test/java/org/cloudfoundry/IfCloudFoundryVersion.java +++ b/integration-test/src/test/java/org/cloudfoundry/IfCloudFoundryVersion.java @@ -16,6 +16,8 @@ package org.cloudfoundry; +import static org.cloudfoundry.CloudFoundryVersion.UNSPECIFIED; + import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; @@ -23,8 +25,6 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import static org.cloudfoundry.CloudFoundryVersion.UNSPECIFIED; - @Target({ElementType.METHOD, ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @@ -40,5 +40,4 @@ CloudFoundryVersion lessThan() default UNSPECIFIED; CloudFoundryVersion lessThanOrEqualTo() default UNSPECIFIED; - } diff --git a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java index 0263c1003da..2ed638c1450 100644 --- a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java +++ b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java @@ -16,11 +16,27 @@ package org.cloudfoundry; +import static org.assertj.core.api.Assertions.fail; +import static org.cloudfoundry.uaa.tokens.GrantType.AUTHORIZATION_CODE; +import static org.cloudfoundry.uaa.tokens.GrantType.CLIENT_CREDENTIALS; +import static org.cloudfoundry.uaa.tokens.GrantType.PASSWORD; +import static org.cloudfoundry.uaa.tokens.GrantType.REFRESH_TOKEN; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.deser.DeserializationProblemHandler; import com.github.zafarkhaja.semver.Version; +import java.io.IOException; +import java.nio.file.Path; +import java.security.SecureRandom; +import java.time.Duration; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Random; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.info.GetInfoRequest; import org.cloudfoundry.client.v2.organizationquotadefinitions.CreateOrganizationQuotaDefinitionRequest; @@ -76,126 +92,131 @@ import reactor.util.function.Tuple2; import reactor.util.function.Tuples; -import java.io.IOException; -import java.nio.file.Path; -import java.security.SecureRandom; -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Random; - -import static org.assertj.core.api.Assertions.fail; -import static org.cloudfoundry.uaa.tokens.GrantType.AUTHORIZATION_CODE; -import static org.cloudfoundry.uaa.tokens.GrantType.CLIENT_CREDENTIALS; -import static org.cloudfoundry.uaa.tokens.GrantType.PASSWORD; -import static org.cloudfoundry.uaa.tokens.GrantType.REFRESH_TOKEN; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @Configuration @EnableAutoConfiguration public class IntegrationTestConfiguration { - private static final List GROUPS = Arrays.asList( - "clients.admin", - "clients.secret", - "cloud_controller.admin", - "idps.write", - "network.admin", - "routing.router_groups.read", - "routing.router_groups.write", - "routing.routes.read", - "routing.routes.write", - "scim.create", - "scim.invite", - "scim.read", - "scim.userids", - "scim.write", - "scim.zones", - "uaa.admin", - "zones.read", - "zones.write"); - - private static final List SCOPES = Arrays.asList( - "clients.admin", - "clients.secret", - "cloud_controller.admin", - "cloud_controller.read", - "cloud_controller.write", - "idps.write", - "network.admin", - "openid", - "password.write", - "routing.router_groups.read", - "routing.router_groups.write", - "routing.routes.read", - "routing.routes.write", - "scim.create", - "scim.invite", - "scim.read", - "scim.userids", - "scim.write", - "scim.zones", - "uaa.admin", - "uaa.user", - "zones.read", - "zones.write"); + private static final List GROUPS = + Arrays.asList( + "clients.admin", + "clients.secret", + "cloud_controller.admin", + "idps.write", + "network.admin", + "routing.router_groups.read", + "routing.router_groups.write", + "routing.routes.read", + "routing.routes.write", + "scim.create", + "scim.invite", + "scim.read", + "scim.userids", + "scim.write", + "scim.zones", + "uaa.admin", + "zones.read", + "zones.write"); + + private static final List SCOPES = + Arrays.asList( + "clients.admin", + "clients.secret", + "cloud_controller.admin", + "cloud_controller.read", + "cloud_controller.write", + "idps.write", + "network.admin", + "openid", + "password.write", + "routing.router_groups.read", + "routing.router_groups.write", + "routing.routes.read", + "routing.routes.write", + "scim.create", + "scim.invite", + "scim.read", + "scim.userids", + "scim.write", + "scim.zones", + "uaa.admin", + "uaa.user", + "zones.read", + "zones.write"); private final Logger logger = LoggerFactory.getLogger("cloudfoundry-client.test"); @Bean @Qualifier("admin") - ReactorCloudFoundryClient adminCloudFoundryClient(ConnectionContext connectionContext, @Value("${test.admin.password}") String password, @Value("${test.admin.username}") String username) { + ReactorCloudFoundryClient adminCloudFoundryClient( + ConnectionContext connectionContext, + @Value("${test.admin.password}") String password, + @Value("${test.admin.username}") String username) { return ReactorCloudFoundryClient.builder() - .connectionContext(connectionContext) - .tokenProvider(PasswordGrantTokenProvider.builder() - .password(password) - .username(username) - .build()) - .build(); + .connectionContext(connectionContext) + .tokenProvider( + PasswordGrantTokenProvider.builder() + .password(password) + .username(username) + .build()) + .build(); } @Bean @Qualifier("admin") - NetworkingClient adminNetworkingClient(ConnectionContext connectionContext, @Value("${test.admin.password}") String password, @Value("${test.admin.username}") String username) { + NetworkingClient adminNetworkingClient( + ConnectionContext connectionContext, + @Value("${test.admin.password}") String password, + @Value("${test.admin.username}") String username) { return ReactorNetworkingClient.builder() - .connectionContext(connectionContext) - .tokenProvider(PasswordGrantTokenProvider.builder() - .password(password) - .username(username) - .build()) - .build(); + .connectionContext(connectionContext) + .tokenProvider( + PasswordGrantTokenProvider.builder() + .password(password) + .username(username) + .build()) + .build(); } @Bean @Qualifier("admin") - ReactorUaaClient adminUaaClient(ConnectionContext connectionContext, @Value("${test.admin.clientId}") String clientId, @Value("${test.admin.clientSecret}") String clientSecret) { + ReactorUaaClient adminUaaClient( + ConnectionContext connectionContext, + @Value("${test.admin.clientId}") String clientId, + @Value("${test.admin.clientSecret}") String clientSecret) { return ReactorUaaClient.builder() - .connectionContext(connectionContext) - .tokenProvider(ClientCredentialsGrantTokenProvider.builder() - .clientId(clientId) - .clientSecret(clientSecret) - .build()) - .build(); + .connectionContext(connectionContext) + .tokenProvider( + ClientCredentialsGrantTokenProvider.builder() + .clientId(clientId) + .clientSecret(clientSecret) + .build()) + .build(); } @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") - Mono> client(@Qualifier("admin") UaaClient uaaClient, String clientId, String clientSecret) { - return uaaClient.clients() - .create(CreateClientRequest.builder() - .authorizedGrantTypes(AUTHORIZATION_CODE, CLIENT_CREDENTIALS, PASSWORD, REFRESH_TOKEN) - .autoApprove(String.valueOf(true)) - .clientId(clientId) - .clientSecret(clientSecret) - .redirectUriPattern("https://test.com/login") - .scopes(SCOPES) - .build()) - .thenReturn(Tuples.of(clientId, clientSecret)) - .doOnSubscribe(s -> this.logger.debug(">> CLIENT ({}/{}) <<", clientId, clientSecret)) - .doOnError(Throwable::printStackTrace) - .doOnSuccess(r -> this.logger.debug("<< CLIENT ({})>>", clientId)); + Mono> client( + @Qualifier("admin") UaaClient uaaClient, String clientId, String clientSecret) { + return uaaClient + .clients() + .create( + CreateClientRequest.builder() + .authorizedGrantTypes( + AUTHORIZATION_CODE, + CLIENT_CREDENTIALS, + PASSWORD, + REFRESH_TOKEN) + .autoApprove(String.valueOf(true)) + .clientId(clientId) + .clientSecret(clientSecret) + .redirectUriPattern("https://test.com/login") + .scopes(SCOPES) + .build()) + .thenReturn(Tuples.of(clientId, clientSecret)) + .doOnSubscribe( + s -> this.logger.debug(">> CLIENT ({}/{}) <<", clientId, clientSecret)) + .doOnError(Throwable::printStackTrace) + .doOnSuccess(r -> this.logger.debug("<< CLIENT ({})>>", clientId)); } @Bean @@ -209,32 +230,44 @@ String clientSecret(NameFactory nameFactory) { } @Bean(initMethod = "clean", destroyMethod = "clean") - CloudFoundryCleaner cloudFoundryCleaner(@Qualifier("admin") CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, @Qualifier("admin") NetworkingClient networkingClient, - Version serverVersion, @Qualifier("admin") UaaClient uaaClient) { + CloudFoundryCleaner cloudFoundryCleaner( + @Qualifier("admin") CloudFoundryClient cloudFoundryClient, + NameFactory nameFactory, + @Qualifier("admin") NetworkingClient networkingClient, + Version serverVersion, + @Qualifier("admin") UaaClient uaaClient) { - return new CloudFoundryCleaner(cloudFoundryClient, nameFactory, networkingClient, serverVersion, uaaClient); + return new CloudFoundryCleaner( + cloudFoundryClient, nameFactory, networkingClient, serverVersion, uaaClient); } @Bean - ReactorCloudFoundryClient cloudFoundryClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { + ReactorCloudFoundryClient cloudFoundryClient( + ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorCloudFoundryClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean - DefaultCloudFoundryOperations cloudFoundryOperations(CloudFoundryClient cloudFoundryClient, DopplerClient dopplerClient, NetworkingClient networkingClient, RoutingClient routingClient, - UaaClient uaaClient, String organizationName, String spaceName) { + DefaultCloudFoundryOperations cloudFoundryOperations( + CloudFoundryClient cloudFoundryClient, + DopplerClient dopplerClient, + NetworkingClient networkingClient, + RoutingClient routingClient, + UaaClient uaaClient, + String organizationName, + String spaceName) { return DefaultCloudFoundryOperations.builder() - .cloudFoundryClient(cloudFoundryClient) - .dopplerClient(dopplerClient) - .networkingClient(networkingClient) - .routingClient(routingClient) - .uaaClient(uaaClient) - .organization(organizationName) - .space(spaceName) - .build(); + .cloudFoundryClient(cloudFoundryClient) + .dopplerClient(dopplerClient) + .networkingClient(networkingClient) + .routingClient(routingClient) + .uaaClient(uaaClient) + .organization(organizationName) + .space(spaceName) + .build(); } @Bean @@ -243,28 +276,29 @@ CloudFoundryVersionConditionalRule cloudFoundryVersionConditionalRule(Version se } @Bean - DefaultConnectionContext connectionContext(@Value("${test.apiHost}") String apiHost, - @Value("${test.proxy.host:}") String proxyHost, - @Value("${test.proxy.password:}") String proxyPassword, - @Value("${test.proxy.port:8080}") Integer proxyPort, - @Value("${test.proxy.username:}") String proxyUsername, - @Value("${test.skipSslValidation:false}") Boolean skipSslValidation) { - - DefaultConnectionContext.Builder connectionContext = DefaultConnectionContext.builder() - .apiHost(apiHost) - .problemHandler(new FailingDeserializationProblemHandler()) // Test-only problem handler - .skipSslValidation(skipSslValidation) - .sslHandshakeTimeout(Duration.ofSeconds(30)); + DefaultConnectionContext connectionContext( + @Value("${test.apiHost}") String apiHost, + @Value("${test.proxy.host:}") String proxyHost, + @Value("${test.proxy.password:}") String proxyPassword, + @Value("${test.proxy.port:8080}") Integer proxyPort, + @Value("${test.proxy.username:}") String proxyUsername, + @Value("${test.skipSslValidation:false}") Boolean skipSslValidation) { + + DefaultConnectionContext.Builder connectionContext = + DefaultConnectionContext.builder() + .apiHost(apiHost) + .problemHandler( + new FailingDeserializationProblemHandler()) // Test-only problem + // handler + .skipSslValidation(skipSslValidation) + .sslHandshakeTimeout(Duration.ofSeconds(30)); if (StringUtils.hasText(proxyHost)) { - ProxyConfiguration.Builder proxyConfiguration = ProxyConfiguration.builder() - .host(proxyHost) - .port(proxyPort); + ProxyConfiguration.Builder proxyConfiguration = + ProxyConfiguration.builder().host(proxyHost).port(proxyPort); if (StringUtils.hasText(proxyUsername)) { - proxyConfiguration - .password(proxyPassword) - .username(proxyUsername); + proxyConfiguration.password(proxyPassword).username(proxyUsername); } connectionContext.proxyConfiguration(proxyConfiguration.build()); @@ -276,17 +310,18 @@ DefaultConnectionContext connectionContext(@Value("${test.apiHost}") String apiH @Bean DopplerClient dopplerClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorDopplerClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean - ReactorLogCacheClient logCacheClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { + ReactorLogCacheClient logCacheClient( + ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorLogCacheClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean @@ -296,63 +331,86 @@ RandomNameFactory nameFactory(Random random) { @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") - Mono metricRegistrarServiceInstance(CloudFoundryClient cloudFoundryClient, Mono spaceId, NameFactory nameFactory) { - return spaceId - .flatMap(spaceIdValue ->cloudFoundryClient.userProvidedServiceInstances() - .create(CreateUserProvidedServiceInstanceRequest.builder() - .name(nameFactory.getServiceInstanceName()) - .spaceId(spaceIdValue) - .syslogDrainUrl("structured-format://json") - .build())) - .map(ResourceUtils::getId) - .cache(); + Mono metricRegistrarServiceInstance( + CloudFoundryClient cloudFoundryClient, Mono spaceId, NameFactory nameFactory) { + return spaceId.flatMap( + spaceIdValue -> + cloudFoundryClient + .userProvidedServiceInstances() + .create( + CreateUserProvidedServiceInstanceRequest.builder() + .name(nameFactory.getServiceInstanceName()) + .spaceId(spaceIdValue) + .syslogDrainUrl("structured-format://json") + .build())) + .map(ResourceUtils::getId) + .cache(); } @Bean - NetworkingClient networkingClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { + NetworkingClient networkingClient( + ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorNetworkingClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") - Mono organizationId(CloudFoundryClient cloudFoundryClient, String organizationName, String organizationQuotaName, Mono userId) { - return userId - .flatMap(userId1 -> cloudFoundryClient.organizationQuotaDefinitions() - .create(CreateOrganizationQuotaDefinitionRequest.builder() - .applicationInstanceLimit(-1) - .applicationTaskLimit(-1) - .instanceMemoryLimit(-1) - .memoryLimit(8192) - .name(organizationQuotaName) - .nonBasicServicesAllowed(true) - .totalPrivateDomains(-1) - .totalReservedRoutePorts(-1) - .totalRoutes(-1) - .totalServiceKeys(-1) - .totalServices(-1) - .build()) - .map(ResourceUtils::getId) - .zipWith(Mono.just(userId1))) - .flatMap(function((quotaId, userId1) -> cloudFoundryClient.organizations() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .quotaDefinitionId(quotaId) - .build()) - .map(ResourceUtils::getId) - .zipWith(Mono.just(userId1)))) - .flatMap(function((organizationId, userId1) -> cloudFoundryClient.organizations() - .associateManager(AssociateOrganizationManagerRequest.builder() - .organizationId(organizationId) - .managerId(userId1) - .build()) - .thenReturn(organizationId))) - .doOnSubscribe(s -> this.logger.debug(">> ORGANIZATION ({}) <<", organizationName)) - .doOnError(Throwable::printStackTrace) - .doOnSuccess(id -> this.logger.debug("<< ORGANIZATION ({}) >>", id)) - .cache(); + Mono organizationId( + CloudFoundryClient cloudFoundryClient, + String organizationName, + String organizationQuotaName, + Mono userId) { + return userId.flatMap( + userId1 -> + cloudFoundryClient + .organizationQuotaDefinitions() + .create( + CreateOrganizationQuotaDefinitionRequest.builder() + .applicationInstanceLimit(-1) + .applicationTaskLimit(-1) + .instanceMemoryLimit(-1) + .memoryLimit(8192) + .name(organizationQuotaName) + .nonBasicServicesAllowed(true) + .totalPrivateDomains(-1) + .totalReservedRoutePorts(-1) + .totalRoutes(-1) + .totalServiceKeys(-1) + .totalServices(-1) + .build()) + .map(ResourceUtils::getId) + .zipWith(Mono.just(userId1))) + .flatMap( + function( + (quotaId, userId1) -> + cloudFoundryClient + .organizations() + .create( + CreateOrganizationRequest.builder() + .name(organizationName) + .quotaDefinitionId(quotaId) + .build()) + .map(ResourceUtils::getId) + .zipWith(Mono.just(userId1)))) + .flatMap( + function( + (organizationId, userId1) -> + cloudFoundryClient + .organizations() + .associateManager( + AssociateOrganizationManagerRequest + .builder() + .organizationId(organizationId) + .managerId(userId1) + .build()) + .thenReturn(organizationId))) + .doOnSubscribe(s -> this.logger.debug(">> ORGANIZATION ({}) <<", organizationName)) + .doOnError(Throwable::printStackTrace) + .doOnSuccess(id -> this.logger.debug("<< ORGANIZATION ({}) >>", id)) + .cache(); } @Bean @@ -383,32 +441,52 @@ SecureRandom random() { @Bean RoutingClient routingClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorRoutingClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean Version serverVersion(@Qualifier("admin") CloudFoundryClient cloudFoundryClient) { - return cloudFoundryClient.info() - .get(GetInfoRequest.builder() - .build()) - .map(response -> Version.valueOf(response.getApiVersion())) - .doOnSubscribe(s -> this.logger.debug(">> CLOUD FOUNDRY VERSION <<")) - .doOnSuccess(r -> this.logger.debug("<< CLOUD FOUNDRY VERSION >>")) - .block(); + return cloudFoundryClient + .info() + .get(GetInfoRequest.builder().build()) + .map(response -> Version.valueOf(response.getApiVersion())) + .doOnSubscribe(s -> this.logger.debug(">> CLOUD FOUNDRY VERSION <<")) + .doOnSuccess(r -> this.logger.debug("<< CLOUD FOUNDRY VERSION >>")) + .block(); } @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") - Mono serviceBrokerId(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, String planName, String serviceBrokerName, String serviceName, Mono spaceId) { - return spaceId - .flatMap(spaceId1 -> ServiceBrokerUtils.createServiceBroker(cloudFoundryClient, nameFactory, planName, serviceBrokerName, serviceName, spaceId1, false) - .map(response -> response.serviceBrokerId)) - .doOnSubscribe(s -> this.logger.debug(">> SERVICE BROKER ({} {}/{}) <<", serviceBrokerName, serviceName, planName)) - .doOnError(Throwable::printStackTrace) - .doOnSuccess(id -> this.logger.debug("<< SERVICE_BROKER ({})>>", id)) - .cache(); + Mono serviceBrokerId( + CloudFoundryClient cloudFoundryClient, + NameFactory nameFactory, + String planName, + String serviceBrokerName, + String serviceName, + Mono spaceId) { + return spaceId.flatMap( + spaceId1 -> + ServiceBrokerUtils.createServiceBroker( + cloudFoundryClient, + nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId1, + false) + .map(response -> response.serviceBrokerId)) + .doOnSubscribe( + s -> + this.logger.debug( + ">> SERVICE BROKER ({} {}/{}) <<", + serviceBrokerName, + serviceName, + planName)) + .doOnError(Throwable::printStackTrace) + .doOnSuccess(id -> this.logger.debug("<< SERVICE_BROKER ({})>>", id)) + .cache(); } @Bean @@ -423,18 +501,23 @@ String serviceName(NameFactory nameFactory) { @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") - Mono spaceId(CloudFoundryClient cloudFoundryClient, Mono organizationId, String spaceName) { + Mono spaceId( + CloudFoundryClient cloudFoundryClient, Mono organizationId, String spaceName) { return organizationId - .flatMap(orgId -> cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organizationId(orgId) - .build())) - .map(ResourceUtils::getId) - .doOnSubscribe(s -> this.logger.debug(">> SPACE ({}) <<", spaceName)) - .doOnError(Throwable::printStackTrace) - .doOnSuccess(id -> this.logger.debug("<< SPACE ({}) >>", id)) - .cache(); + .flatMap( + orgId -> + cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organizationId(orgId) + .build())) + .map(ResourceUtils::getId) + .doOnSubscribe(s -> this.logger.debug(">> SPACE ({}) <<", spaceName)) + .doOnError(Throwable::printStackTrace) + .doOnSuccess(id -> this.logger.debug("<< SPACE ({}) >>", id)) + .cache(); } @Bean @@ -445,18 +528,21 @@ String spaceName(NameFactory nameFactory) { @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") Mono stackId(CloudFoundryClient cloudFoundryClient, String stackName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.stacks() - .list(ListStacksRequest.builder() - .name(stackName) - .page(page) - .build())) - .single() - .map(ResourceUtils::getId) - .doOnSubscribe(s -> this.logger.debug(">> STACK ({}) <<", stackName)) - .doOnError(Throwable::printStackTrace) - .doOnSuccess(id -> this.logger.debug("<< STACK ({})>>", id)) - .cache(); + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .stacks() + .list( + ListStacksRequest.builder() + .name(stackName) + .page(page) + .build())) + .single() + .map(ResourceUtils::getId) + .doOnSubscribe(s -> this.logger.debug(">> STACK ({}) <<", stackName)) + .doOnError(Throwable::printStackTrace) + .doOnSuccess(id -> this.logger.debug("<< STACK ({})>>", id)) + .cache(); } @Bean @@ -466,14 +552,28 @@ String stackName() { @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") - Mono testLogCacheApp(CloudFoundryClient cloudFoundryClient, Mono spaceId, Mono metricRegistrarServiceInstance, String testLogCacheAppName, - String testLogCacheHostName, Path testLogCacheAppbits) { + Mono testLogCacheApp( + CloudFoundryClient cloudFoundryClient, + Mono spaceId, + Mono metricRegistrarServiceInstance, + String testLogCacheAppName, + String testLogCacheHostName, + Path testLogCacheAppbits) { return metricRegistrarServiceInstance - .zipWith(spaceId) - .flatMap(function((metricsRegistrarServiceInstanceId, spaceIdValue) -> ApplicationUtils - .pushApplication(cloudFoundryClient, testLogCacheAppbits, testLogCacheAppName, Collections.singleton(metricsRegistrarServiceInstanceId), new HashMap<>(), testLogCacheHostName, - spaceIdValue))) - .cache(); + .zipWith(spaceId) + .flatMap( + function( + (metricsRegistrarServiceInstanceId, spaceIdValue) -> + ApplicationUtils.pushApplication( + cloudFoundryClient, + testLogCacheAppbits, + testLogCacheAppName, + Collections.singleton( + metricsRegistrarServiceInstanceId), + new HashMap<>(), + testLogCacheHostName, + spaceIdValue))) + .cache(); } @Bean @@ -487,9 +587,13 @@ String testLogCacheAppName(NameFactory nameFactory) { } @Bean - TestLogCacheEndpoints testLogCacheEndpoints(ConnectionContext connectionContext, TokenProvider tokenProvider, Mono testLogCacheApp) { + TestLogCacheEndpoints testLogCacheEndpoints( + ConnectionContext connectionContext, + TokenProvider tokenProvider, + Mono testLogCacheApp) { - return new TestLogCacheEndpoints(connectionContext, testLogCacheApp.map(app -> app.uri), tokenProvider); + return new TestLogCacheEndpoints( + connectionContext, testLogCacheApp.map(app -> app.uri), tokenProvider); } @Bean @@ -499,64 +603,97 @@ String testLogCacheHostName(NameFactory nameFactory) { @Bean @DependsOn({"client", "userId"}) - PasswordGrantTokenProvider tokenProvider(String clientId, String clientSecret, String password, String username) { + PasswordGrantTokenProvider tokenProvider( + String clientId, String clientSecret, String password, String username) { return PasswordGrantTokenProvider.builder() - .clientId(clientId) - .clientSecret(clientSecret) - .password(password) - .username(username) - .build(); + .clientId(clientId) + .clientSecret(clientSecret) + .password(password) + .username(username) + .build(); } @Bean ReactorUaaClient uaaClient(ConnectionContext connectionContext, TokenProvider tokenProvider) { return ReactorUaaClient.builder() - .connectionContext(connectionContext) - .tokenProvider(tokenProvider) - .build(); + .connectionContext(connectionContext) + .tokenProvider(tokenProvider) + .build(); } @Bean(initMethod = "block") @DependsOn("cloudFoundryCleaner") Mono userId(@Qualifier("admin") UaaClient uaaClient, String password, String username) { - return uaaClient.users() - .create(CreateUserRequest.builder() - .email(Email.builder() - .primary(true) - .value(String.format("%s@%s.com", username, username)) - .build()) - .name(Name.builder() - .givenName("Test") - .familyName("User") - .build()) - .password(password) - .userName(username) - .build()) - .map(CreateUserResponse::getId) - .delayUntil(userId -> Flux.fromIterable(GROUPS) - .flatMap(group -> uaaClient.groups() - .list(ListGroupsRequest.builder() - .filter(String.format("displayName eq \"%s\"", group)) - .build()) - .flatMapIterable(ListGroupsResponse::getResources) - .singleOrEmpty() - .map(Group::getId) - .switchIfEmpty(uaaClient.groups() - .create(CreateGroupRequest.builder() - .displayName(group) - .build()) - .map(CreateGroupResponse::getId)) - .flatMap(groupId -> uaaClient.groups() - .addMember(AddMemberRequest.builder() - .groupId(groupId) - .memberId(userId) - .origin("uaa") - .type(MemberType.USER) - .build())))) - .doOnSubscribe(s -> this.logger.debug(">> USER ({}/{}) <<", username, password)) - .doOnError(Throwable::printStackTrace) - .doOnSuccess(id -> this.logger.debug("<< USER ({})>>", id)) - .cache(); + return uaaClient + .users() + .create( + CreateUserRequest.builder() + .email( + Email.builder() + .primary(true) + .value( + String.format( + "%s@%s.com", username, username)) + .build()) + .name(Name.builder().givenName("Test").familyName("User").build()) + .password(password) + .userName(username) + .build()) + .map(CreateUserResponse::getId) + .delayUntil( + userId -> + Flux.fromIterable(GROUPS) + .flatMap( + group -> + uaaClient + .groups() + .list( + ListGroupsRequest.builder() + .filter( + String + .format( + "displayName" + + " eq \"%s\"", + group)) + .build()) + .flatMapIterable( + ListGroupsResponse + ::getResources) + .singleOrEmpty() + .map(Group::getId) + .switchIfEmpty( + uaaClient + .groups() + .create( + CreateGroupRequest + .builder() + .displayName( + group) + .build()) + .map( + CreateGroupResponse + ::getId)) + .flatMap( + groupId -> + uaaClient + .groups() + .addMember( + AddMemberRequest + .builder() + .groupId( + groupId) + .memberId( + userId) + .origin( + "uaa") + .type( + MemberType + .USER) + .build())))) + .doOnSubscribe(s -> this.logger.debug(">> USER ({}/{}) <<", username, password)) + .doOnError(Throwable::printStackTrace) + .doOnSuccess(id -> this.logger.debug("<< USER ({})>>", id)) + .cache(); } @Bean @@ -564,14 +701,21 @@ String username(NameFactory nameFactory) { return nameFactory.getUserName(); } - private static final class FailingDeserializationProblemHandler extends DeserializationProblemHandler { + private static final class FailingDeserializationProblemHandler + extends DeserializationProblemHandler { @Override - public boolean handleUnknownProperty(DeserializationContext ctxt, JsonParser jp, JsonDeserializer deserializer, Object beanOrClass, String propertyName) { - fail(String.format("Found unexpected property %s in payload for %s", propertyName, beanOrClass.getClass().getName())); + public boolean handleUnknownProperty( + DeserializationContext ctxt, + JsonParser jp, + JsonDeserializer deserializer, + Object beanOrClass, + String propertyName) { + fail( + String.format( + "Found unexpected property %s in payload for %s", + propertyName, beanOrClass.getClass().getName())); return false; } - } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/NameFactory.java b/integration-test/src/test/java/org/cloudfoundry/NameFactory.java index 944193e5623..7432672263f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/NameFactory.java +++ b/integration-test/src/test/java/org/cloudfoundry/NameFactory.java @@ -634,5 +634,4 @@ default boolean isVariableName(String candidate) { default boolean isVariableValue(String candidate) { return isName(VARIABLE_VALUE_PREFIX, candidate); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/RandomNameFactory.java b/integration-test/src/test/java/org/cloudfoundry/RandomNameFactory.java index 055dbf596d8..5443f15780e 100644 --- a/integration-test/src/test/java/org/cloudfoundry/RandomNameFactory.java +++ b/integration-test/src/test/java/org/cloudfoundry/RandomNameFactory.java @@ -16,13 +16,12 @@ package org.cloudfoundry; -import reactor.core.Exceptions; - import java.math.BigInteger; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; +import reactor.core.Exceptions; final class RandomNameFactory implements NameFactory { @@ -41,7 +40,11 @@ final class RandomNameFactory implements NameFactory { @Override public String getIpAddress() { try { - return InetAddress.getByName(String.format("169.254.%d.%d", 1 + this.random.nextInt(254), this.random.nextInt(256))).getHostAddress(); + return InetAddress.getByName( + String.format( + "169.254.%d.%d", + 1 + this.random.nextInt(254), this.random.nextInt(256))) + .getHostAddress(); } catch (UnknownHostException e) { throw Exceptions.propagate(e); } @@ -81,5 +84,4 @@ public boolean isName(String prefix, String candidate) { public boolean isPort(int candidate) { return candidate >= PORT_MINIMUM && candidate <= PORT_MAXIMUM; } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/ServiceBrokerUtils.java b/integration-test/src/test/java/org/cloudfoundry/ServiceBrokerUtils.java index 9e1e1fca2e6..f921df6d7f1 100644 --- a/integration-test/src/test/java/org/cloudfoundry/ServiceBrokerUtils.java +++ b/integration-test/src/test/java/org/cloudfoundry/ServiceBrokerUtils.java @@ -16,6 +16,11 @@ package org.cloudfoundry; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.DeleteApplicationRequest; import org.cloudfoundry.client.v2.servicebrokers.CreateServiceBrokerRequest; @@ -33,17 +38,17 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.io.IOException; -import java.nio.file.Path; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - public final class ServiceBrokerUtils { @SuppressWarnings("BlockingMethodInNonBlockingContext") - public static Mono createServiceBroker(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, String planName, String serviceBrokerName, - String serviceName, String spaceId, Boolean spaceScoped) { + public static Mono createServiceBroker( + CloudFoundryClient cloudFoundryClient, + NameFactory nameFactory, + String planName, + String serviceBrokerName, + String serviceName, + String spaceId, + Boolean spaceScoped) { Path application; try { application = new ClassPathResource("test-service-broker.jar").getFile().toPath(); @@ -51,24 +56,52 @@ public static Mono createServiceBroker throw Exceptions.propagate(e); } - return pushServiceBrokerApplication(cloudFoundryClient, application, nameFactory, planName, serviceName, spaceId) - .flatMap(applicationMetadata -> requestCreateServiceBroker(cloudFoundryClient, applicationMetadata, serviceBrokerName, spaceScoped) - .delayUntil(response -> Mono.zip( - makeServicePlanPubliclyVisible(cloudFoundryClient, serviceName, spaceScoped), - makeServicePlanPubliclyVisible(cloudFoundryClient, serviceName + "-shareable", spaceScoped) - )) - .map(response -> new ServiceBrokerMetadata(applicationMetadata, ResourceUtils.getId(response)))); + return pushServiceBrokerApplication( + cloudFoundryClient, + application, + nameFactory, + planName, + serviceName, + spaceId) + .flatMap( + applicationMetadata -> + requestCreateServiceBroker( + cloudFoundryClient, + applicationMetadata, + serviceBrokerName, + spaceScoped) + .delayUntil( + response -> + Mono.zip( + makeServicePlanPubliclyVisible( + cloudFoundryClient, + serviceName, + spaceScoped), + makeServicePlanPubliclyVisible( + cloudFoundryClient, + serviceName + "-shareable", + spaceScoped))) + .map( + response -> + new ServiceBrokerMetadata( + applicationMetadata, + ResourceUtils.getId(response)))); } - public static Mono deleteServiceBroker(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV2() - .delete(DeleteApplicationRequest.builder() - .applicationId(applicationId) - .build()); + public static Mono deleteServiceBroker( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV2() + .delete(DeleteApplicationRequest.builder().applicationId(applicationId).build()); } - public static Mono pushServiceBrokerApplication(CloudFoundryClient cloudFoundryClient, Path application, NameFactory nameFactory, String planName, - String serviceName, String spaceId) { + public static Mono pushServiceBrokerApplication( + CloudFoundryClient cloudFoundryClient, + Path application, + NameFactory nameFactory, + String planName, + String serviceName, + String spaceId) { String applicationName = nameFactory.getApplicationName(); String hostName = nameFactory.getHostName(); @@ -76,67 +109,89 @@ public static Mono pushServiceBrokerApplic env.put("SERVICE_NAME", serviceName); env.put("PLAN_NAME", planName); - return ApplicationUtils.pushApplication(cloudFoundryClient, application,applicationName, Collections.emptyList(), env, hostName, spaceId); + return ApplicationUtils.pushApplication( + cloudFoundryClient, + application, + applicationName, + Collections.emptyList(), + env, + hostName, + spaceId); } - private static Mono getServiceId(CloudFoundryClient cloudFoundryClient, String serviceName) { + private static Mono getServiceId( + CloudFoundryClient cloudFoundryClient, String serviceName) { return requestListServices(cloudFoundryClient, serviceName) - .single() - .map(ResourceUtils::getId); - + .single() + .map(ResourceUtils::getId); } - private static Mono getServicePlanId(CloudFoundryClient cloudFoundryClient, String serviceId) { + private static Mono getServicePlanId( + CloudFoundryClient cloudFoundryClient, String serviceId) { return requestListServicePlans(cloudFoundryClient, serviceId) - .single() - .map(ResourceUtils::getId); + .single() + .map(ResourceUtils::getId); } - private static Mono makeServicePlanPubliclyVisible(CloudFoundryClient cloudFoundryClient, String serviceName, Boolean spaceScoped) { + private static Mono makeServicePlanPubliclyVisible( + CloudFoundryClient cloudFoundryClient, String serviceName, Boolean spaceScoped) { if (spaceScoped) { return Mono.empty(); } return getServiceId(cloudFoundryClient, serviceName) - .flatMap(serviceId -> getServicePlanId(cloudFoundryClient, serviceId)) - .flatMap(planId -> requestUpdateServicePlan(cloudFoundryClient, planId, true)); + .flatMap(serviceId -> getServicePlanId(cloudFoundryClient, serviceId)) + .flatMap(planId -> requestUpdateServicePlan(cloudFoundryClient, planId, true)); } - private static Mono requestCreateServiceBroker(CloudFoundryClient cloudFoundryClient, ApplicationUtils.ApplicationMetadata applicationMetadata, - String serviceBrokerName, Boolean spaceScoped) { - return cloudFoundryClient.serviceBrokers() - .create(CreateServiceBrokerRequest.builder() - .authenticationPassword("test-authentication-password") - .authenticationUsername("test-authentication-username") - .brokerUrl(applicationMetadata.uri) - .name(serviceBrokerName) - .spaceId(spaceScoped ? applicationMetadata.spaceId : null) - .build()); + private static Mono requestCreateServiceBroker( + CloudFoundryClient cloudFoundryClient, + ApplicationUtils.ApplicationMetadata applicationMetadata, + String serviceBrokerName, + Boolean spaceScoped) { + return cloudFoundryClient + .serviceBrokers() + .create( + CreateServiceBrokerRequest.builder() + .authenticationPassword("test-authentication-password") + .authenticationUsername("test-authentication-username") + .brokerUrl(applicationMetadata.uri) + .name(serviceBrokerName) + .spaceId(spaceScoped ? applicationMetadata.spaceId : null) + .build()); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .serviceId(serviceId) - .page(page) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .serviceId(serviceId) + .page(page) + .build())); } - private static Flux requestListServices(CloudFoundryClient cloudFoundryClient, String serviceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .label(serviceName) - .build())); + private static Flux requestListServices( + CloudFoundryClient cloudFoundryClient, String serviceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .list(ListServicesRequest.builder().label(serviceName).build())); } - private static Mono requestUpdateServicePlan(CloudFoundryClient cloudFoundryClient, String planId, Boolean visibility) { - return cloudFoundryClient.servicePlans() - .update(UpdateServicePlanRequest.builder() - .servicePlanId(planId) - .publiclyVisible(visibility) - .build()); + private static Mono requestUpdateServicePlan( + CloudFoundryClient cloudFoundryClient, String planId, Boolean visibility) { + return cloudFoundryClient + .servicePlans() + .update( + UpdateServicePlanRequest.builder() + .servicePlanId(planId) + .publiclyVisible(visibility) + .build()); } public static final class ServiceBrokerMetadata { @@ -145,11 +200,10 @@ public static final class ServiceBrokerMetadata { public final String serviceBrokerId; - private ServiceBrokerMetadata(ApplicationUtils.ApplicationMetadata applicationMetadata, String serviceBrokerId) { + private ServiceBrokerMetadata( + ApplicationUtils.ApplicationMetadata applicationMetadata, String serviceBrokerId) { this.applicationMetadata = applicationMetadata; this.serviceBrokerId = serviceBrokerId; } - } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/ZipExpectations.java b/integration-test/src/test/java/org/cloudfoundry/client/ZipExpectations.java index 9659754221b..09d9c0f4aca 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/ZipExpectations.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/ZipExpectations.java @@ -16,8 +16,8 @@ package org.cloudfoundry.client; -import reactor.core.Exceptions; -import reactor.util.function.Tuple2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -29,32 +29,35 @@ import java.util.function.Consumer; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import reactor.core.Exceptions; +import reactor.util.function.Tuple2; public final class ZipExpectations { public static Consumer> zipEquality() { - return consumer((expected, actual) -> { - List expectedEntries = entries(expected); - List actualEntries = entries(expected); + return consumer( + (expected, actual) -> { + List expectedEntries = entries(expected); + List actualEntries = entries(expected); - assertThat(expectedEntries).hasSameSizeAs(actualEntries); + assertThat(expectedEntries).hasSameSizeAs(actualEntries); - Iterator expectedIterator = expectedEntries.iterator(); + Iterator expectedIterator = expectedEntries.iterator(); - for (Entry actualEntry : actualEntries) { - assertThat(actualEntry).usingRecursiveComparison().isEqualTo(expectedIterator.next()); - } - }); + for (Entry actualEntry : actualEntries) { + assertThat(actualEntry) + .usingRecursiveComparison() + .isEqualTo(expectedIterator.next()); + } + }); } private static byte[] content(InputStream in, int length) throws IOException { byte[] content = new byte[length]; int read = in.read(content, 0, length); if (read != length) { - throw new IllegalStateException(String.format("expected read: %d; actual read: %d", length, read)); + throw new IllegalStateException( + String.format("expected read: %d; actual read: %d", length, read)); } return content; } @@ -65,7 +68,14 @@ private static List entries(byte[] bytes) { try (ZipInputStream in = new ZipInputStream(new ByteArrayInputStream(bytes))) { ZipEntry entry; while ((entry = in.getNextEntry()) != null) { - entries.add(new Entry(entry.getCompressedSize(), content(in, (int) entry.getSize()), entry.getCrc(), entry.isDirectory(), entry.getName(), entry.getSize())); + entries.add( + new Entry( + entry.getCompressedSize(), + content(in, (int) entry.getSize()), + entry.getCrc(), + entry.isDirectory(), + entry.getName(), + entry.getSize())); in.closeEntry(); } } catch (IOException e) { @@ -90,7 +100,13 @@ private static final class Entry implements Comparable { private final long size; - private Entry(long compressedSize, byte[] contents, long crc, boolean directory, String name, long size) { + private Entry( + long compressedSize, + byte[] contents, + long crc, + boolean directory, + String name, + long size) { this.compressedSize = compressedSize; this.contents = contents; this.crc = crc; @@ -103,6 +119,5 @@ private Entry(long compressedSize, byte[] contents, long crc, boolean directory, public int compareTo(Entry o) { return this.name.compareTo(o.name); } - } } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ApplicationsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ApplicationsTest.java index 32e273c10e4..6cfbab97d8f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ApplicationsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ApplicationsTest.java @@ -16,6 +16,23 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.client.ZipExpectations.zipEquality; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.function.Consumer; +import java.util.zip.GZIPInputStream; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.archivers.tar.TarArchiveInputStream; import org.cloudfoundry.AbstractIntegrationTest; @@ -69,6 +86,7 @@ import org.cloudfoundry.util.OperationUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.util.Assert; @@ -78,59 +96,54 @@ import reactor.test.StepVerifier; import reactor.util.function.Tuple2; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Map; -import java.util.Optional; -import java.util.Set; -import java.util.function.Consumer; -import java.util.zip.GZIPInputStream; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.client.ZipExpectations.zipEquality; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ApplicationsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; - @Autowired - private Mono stackId; + @Autowired private Mono stackId; @Test public void associateRoute() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createRouteWithDomain(this.cloudFoundryClient, organizationId, spaceId, domainName, "test-host", "/test/path") - .map(ResourceUtils::getId) - ))) - .delayUntil(function((applicationId, routeId) -> requestAssociateRoute(this.cloudFoundryClient, applicationId, routeId))) - .flatMap(function((applicationId, routeId) -> Mono.zip( - getSingleRouteId(this.cloudFoundryClient, applicationId), - Mono.just(routeId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName), + createRouteWithDomain( + this.cloudFoundryClient, + organizationId, + spaceId, + domainName, + "test-host", + "/test/path") + .map(ResourceUtils::getId)))) + .delayUntil( + function( + (applicationId, routeId) -> + requestAssociateRoute( + this.cloudFoundryClient, applicationId, routeId))) + .flatMap( + function( + (applicationId, routeId) -> + Mono.zip( + getSingleRouteId( + this.cloudFoundryClient, applicationId), + Mono.just(routeId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -139,27 +152,51 @@ public void copy() { String copyApplicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - .delayUntil(applicationId -> uploadApplication(this.cloudFoundryClient, applicationId)), - requestCreateApplication(this.cloudFoundryClient, spaceId, copyApplicationName) - .map(ResourceUtils::getId) - )) - .delayUntil(function((sourceId, targetId) -> this.cloudFoundryClient.applicationsV2() - .copy(CopyApplicationRequest.builder() - .applicationId(targetId) - .sourceApplicationId(sourceId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - )) - .flatMap(function((sourceId, targetId) -> Mono.zip( - downloadApplication(this.cloudFoundryClient, sourceId), - downloadApplication(this.cloudFoundryClient, targetId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName) + .delayUntil( + applicationId -> + uploadApplication( + this.cloudFoundryClient, + applicationId)), + requestCreateApplication( + this.cloudFoundryClient, + spaceId, + copyApplicationName) + .map(ResourceUtils::getId))) + .delayUntil( + function( + (sourceId, targetId) -> + this.cloudFoundryClient + .applicationsV2() + .copy( + CopyApplicationRequest.builder() + .applicationId(targetId) + .sourceApplicationId(sourceId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job)))) + .flatMap( + function( + (sourceId, targetId) -> + Mono.zip( + downloadApplication( + this.cloudFoundryClient, sourceId), + downloadApplication( + this.cloudFoundryClient, targetId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -167,18 +204,24 @@ public void create() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - requestCreateApplication(this.cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getEntity) - )) - .as(StepVerifier::create) - .consumeNextWith(consumer((spaceId, entity) -> { - assertThat(entity.getSpaceId()).isEqualTo(spaceId); - assertThat(entity.getName()).isEqualTo(applicationName); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + requestCreateApplication( + this.cloudFoundryClient, + spaceId, + applicationName) + .map(ResourceUtils::getEntity))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (spaceId, entity) -> { + assertThat(entity.getSpaceId()).isEqualTo(spaceId); + assertThat(entity.getName()).isEqualTo(applicationName); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -186,23 +229,29 @@ public void createDocker() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - this.cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .dockerImage("cloudfoundry/test-app") - .name(applicationName) - .spaceId(spaceId) - .build()) - .map(ResourceUtils::getEntity) - )) - .as(StepVerifier::create) - .consumeNextWith(consumer((spaceId, entity) -> { - assertThat(entity.getSpaceId()).isEqualTo(spaceId); - assertThat(entity.getName()).isEqualTo(applicationName); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + this.cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .dockerImage( + "cloudfoundry/test-app") + .name(applicationName) + .spaceId(spaceId) + .build()) + .map(ResourceUtils::getEntity))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (spaceId, entity) -> { + assertThat(entity.getSpaceId()).isEqualTo(spaceId); + assertThat(entity.getName()).isEqualTo(applicationName); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -210,15 +259,30 @@ public void delete() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .delayUntil(applicationId -> this.cloudFoundryClient.applicationsV2() - .delete(DeleteApplicationRequest.builder() - .applicationId(applicationId) - .build())) - .flatMap(applicationId -> requestGetApplication(this.cloudFoundryClient, applicationId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-AppNotFound\\([0-9]+\\): The app could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .delayUntil( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .delete( + DeleteApplicationRequest.builder() + .applicationId(applicationId) + .build())) + .flatMap( + applicationId -> + requestGetApplication(this.cloudFoundryClient, applicationId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-AppNotFound\\([0-9]+\\): The app could not be" + + " found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -226,17 +290,26 @@ public void downloadDroplet() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .delayUntil(applicationId -> uploadAndStartApplication(this.cloudFoundryClient, applicationId)) - .flatMapMany(applicationId -> this.cloudFoundryClient.applicationsV2() - .downloadDroplet(DownloadApplicationDropletRequest.builder() - .applicationId(applicationId) - .build()) - .as(OperationUtils::collectByteArray)) - .as(StepVerifier::create) - .consumeNextWith(isTestApplicationDroplet()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .delayUntil( + applicationId -> + uploadAndStartApplication(this.cloudFoundryClient, applicationId)) + .flatMapMany( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .downloadDroplet( + DownloadApplicationDropletRequest.builder() + .applicationId(applicationId) + .build()) + .as(OperationUtils::collectByteArray)) + .as(StepVerifier::create) + .consumeNextWith(isTestApplicationDroplet()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -244,19 +317,31 @@ public void environment() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - this.cloudFoundryClient.applicationsV2() - .environment(ApplicationEnvironmentRequest.builder() - .applicationId(applicationId) - .build()) - .map(response -> getStringApplicationEnvValue(response.getApplicationEnvironmentJsons(), "VCAP_APPLICATION", "application_id")) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + this.cloudFoundryClient + .applicationsV2() + .environment( + ApplicationEnvironmentRequest.builder() + .applicationId(applicationId) + .build()) + .map( + response -> + getStringApplicationEnvValue( + response + .getApplicationEnvironmentJsons(), + "VCAP_APPLICATION", + "application_id")))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -264,15 +349,20 @@ public void get() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - requestGetApplication(this.cloudFoundryClient, applicationId) - )) - .as(StepVerifier::create) - .consumeNextWith(applicationIdAndNameEquality(applicationName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + requestGetApplication( + this.cloudFoundryClient, applicationId))) + .as(StepVerifier::create) + .consumeNextWith(applicationIdAndNameEquality(applicationName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_9) @@ -281,18 +371,26 @@ public void getPermissions() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV2() - .getPermissions(GetApplicationPermissionsRequest.builder() - .applicationId(applicationId) - .build())) - .as(StepVerifier::create) - .expectNext(GetApplicationPermissionsResponse.builder() - .readBasicData(true) - .readSensitiveData(true) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .getPermissions( + GetApplicationPermissionsRequest.builder() + .applicationId(applicationId) + .build())) + .as(StepVerifier::create) + .expectNext( + GetApplicationPermissionsResponse.builder() + .readBasicData(true) + .readSensitiveData(true) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -300,17 +398,26 @@ public void instances() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .delayUntil(applicationId -> uploadAndStartApplication(this.cloudFoundryClient, applicationId)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV2() - .instances(ApplicationInstancesRequest.builder() - .applicationId(applicationId) - .build())) - .map(ApplicationInstancesResponse::getInstances) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .delayUntil( + applicationId -> + uploadAndStartApplication(this.cloudFoundryClient, applicationId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .instances( + ApplicationInstancesRequest.builder() + .applicationId(applicationId) + .build())) + .map(ApplicationInstancesResponse::getInstances) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -318,22 +425,33 @@ public void list() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .list(ListApplicationsRequest.builder() - .page(page) - .build())) - .filter(resource -> ResourceUtils.getId(resource).equals(applicationId)) - .single() - .cast(AbstractApplicationResource.class) - )) - .as(StepVerifier::create) - .consumeNextWith(applicationIdAndNameEquality(applicationName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .list( + ListApplicationsRequest + .builder() + .page(page) + .build())) + .filter( + resource -> + ResourceUtils.getId(resource) + .equals(applicationId)) + .single() + .cast(AbstractApplicationResource.class))) + .as(StepVerifier::create) + .consumeNextWith(applicationIdAndNameEquality(applicationName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -341,23 +459,34 @@ public void listFilterByDiego() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .list(ListApplicationsRequest.builder() - .diego(true) - .page(page) - .build())) - .filter(resource -> ResourceUtils.getId(resource).equals(applicationId)) - .single() - .cast(AbstractApplicationResource.class) - )) - .as(StepVerifier::create) - .consumeNextWith(applicationIdAndNameEquality(applicationName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .list( + ListApplicationsRequest + .builder() + .diego(true) + .page(page) + .build())) + .filter( + resource -> + ResourceUtils.getId(resource) + .equals(applicationId)) + .single() + .cast(AbstractApplicationResource.class))) + .as(StepVerifier::create) + .consumeNextWith(applicationIdAndNameEquality(applicationName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -365,51 +494,76 @@ public void listFilterByName() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .list(ListApplicationsRequest.builder() - .name(applicationName) - .page(page) - .build())) - .filter(resource -> ResourceUtils.getId(resource).equals(applicationId)) - .single() - .cast(AbstractApplicationResource.class) - )) - .as(StepVerifier::create) - .consumeNextWith(applicationIdAndNameEquality(applicationName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .list( + ListApplicationsRequest + .builder() + .name( + applicationName) + .page(page) + .build())) + .filter( + resource -> + ResourceUtils.getId(resource) + .equals(applicationId)) + .single() + .cast(AbstractApplicationResource.class))) + .as(StepVerifier::create) + .consumeNextWith(applicationIdAndNameEquality(applicationName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByOrganizationId() { String applicationName = this.nameFactory.getApplicationName(); - Mono - .zip( - this.organizationId, - this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - ) - .flatMap(function((organizationId, applicationId) -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .list(ListApplicationsRequest.builder() - .organizationId(organizationId) - .page(page) - .build())) - .filter(resource -> ResourceUtils.getId(resource).equals(applicationId)) - .single() - .cast(AbstractApplicationResource.class) - ))) - .as(StepVerifier::create) - .consumeNextWith(applicationIdAndNameEquality(applicationName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId, + this.spaceId.flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName))) + .flatMap( + function( + (organizationId, applicationId) -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .list( + ListApplicationsRequest + .builder() + .organizationId( + organizationId) + .page( + page) + .build())) + .filter( + resource -> + ResourceUtils.getId( + resource) + .equals( + applicationId)) + .single() + .cast(AbstractApplicationResource.class)))) + .as(StepVerifier::create) + .consumeNextWith(applicationIdAndNameEquality(applicationName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -417,26 +571,41 @@ public void listFilterBySpaceId() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - )) - .flatMap(function((spaceId, applicationId) -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .list(ListApplicationsRequest.builder() - .spaceId(spaceId) - .page(page) - .build())) - .filter(resource -> ResourceUtils.getId(resource).equals(applicationId)) - .single() - .cast(AbstractApplicationResource.class) - ))) - .as(StepVerifier::create) - .consumeNextWith(applicationIdAndNameEquality(applicationName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName))) + .flatMap( + function( + (spaceId, applicationId) -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .list( + ListApplicationsRequest + .builder() + .spaceId( + spaceId) + .page( + page) + .build())) + .filter( + resource -> + ResourceUtils.getId( + resource) + .equals( + applicationId)) + .single() + .cast(AbstractApplicationResource.class)))) + .as(StepVerifier::create) + .consumeNextWith(applicationIdAndNameEquality(applicationName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -444,25 +613,45 @@ public void listFilterByStackId() { String applicationName = this.nameFactory.getApplicationName(); Mono.zip(this.spaceId, this.stackId) - .flatMap(function((spaceId, stackId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, stackId), - Mono.just(stackId)))) - .flatMap(function((applicationId, stackId) -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .list(ListApplicationsRequest.builder() - .stackId(stackId) - .page(page) - .build())) - .filter(resource -> ResourceUtils.getId(resource).equals(applicationId)) - .single() - .cast(AbstractApplicationResource.class) - ))) - .as(StepVerifier::create) - .consumeNextWith(applicationIdAndNameEquality(applicationName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (spaceId, stackId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + stackId), + Mono.just(stackId)))) + .flatMap( + function( + (applicationId, stackId) -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .list( + ListApplicationsRequest + .builder() + .stackId( + stackId) + .page( + page) + .build())) + .filter( + resource -> + ResourceUtils.getId( + resource) + .equals( + applicationId)) + .single() + .cast(AbstractApplicationResource.class)))) + .as(StepVerifier::create) + .consumeNextWith(applicationIdAndNameEquality(applicationName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -470,32 +659,51 @@ public void listRoutes() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - ))) - .flatMap(function((organizationId, spaceId, applicationId) -> Mono.zip( - Mono.just(applicationId), - createApplicationRoute(this.cloudFoundryClient, organizationId, spaceId, domainName, applicationId) - ))) - .flatMap(function((applicationId, routeResponse) -> Mono.zip( - Mono.just(ResourceUtils.getId(routeResponse)), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .page(page) - .build())) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName)))) + .flatMap( + function( + (organizationId, spaceId, applicationId) -> + Mono.zip( + Mono.just(applicationId), + createApplicationRoute( + this.cloudFoundryClient, + organizationId, + spaceId, + domainName, + applicationId)))) + .flatMap( + function( + (applicationId, routeResponse) -> + Mono.zip( + Mono.just(ResourceUtils.getId(routeResponse)), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .page( + page) + .build())) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -503,33 +711,56 @@ public void listRoutesFilterByDomainId() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - ))) - .flatMap(function((organizationId, spaceId, applicationId) -> Mono.zip( - Mono.just(applicationId), - createApplicationRoute(this.cloudFoundryClient, organizationId, spaceId, domainName, applicationId) - ))) - .flatMap(function((applicationId, routeResponse) -> Mono.zip( - Mono.just(ResourceUtils.getId(routeResponse)), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .domainId(ResourceUtils.getEntity(routeResponse).getDomainId()) - .page(page) - .build())) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName)))) + .flatMap( + function( + (organizationId, spaceId, applicationId) -> + Mono.zip( + Mono.just(applicationId), + createApplicationRoute( + this.cloudFoundryClient, + organizationId, + spaceId, + domainName, + applicationId)))) + .flatMap( + function( + (applicationId, routeResponse) -> + Mono.zip( + Mono.just(ResourceUtils.getId(routeResponse)), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .domainId( + ResourceUtils + .getEntity( + routeResponse) + .getDomainId()) + .page( + page) + .build())) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -537,33 +768,56 @@ public void listRoutesFilterByHost() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - ))) - .flatMap(function((organizationId, spaceId, applicationId) -> Mono.zip( - Mono.just(applicationId), - createApplicationRoute(this.cloudFoundryClient, organizationId, spaceId, domainName, applicationId) - ))) - .flatMap(function((applicationId, routeResponse) -> Mono.zip( - Mono.just(ResourceUtils.getId(routeResponse)), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .host(ResourceUtils.getEntity(routeResponse).getHost()) - .page(page) - .build())) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName)))) + .flatMap( + function( + (organizationId, spaceId, applicationId) -> + Mono.zip( + Mono.just(applicationId), + createApplicationRoute( + this.cloudFoundryClient, + organizationId, + spaceId, + domainName, + applicationId)))) + .flatMap( + function( + (applicationId, routeResponse) -> + Mono.zip( + Mono.just(ResourceUtils.getId(routeResponse)), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .host( + ResourceUtils + .getEntity( + routeResponse) + .getHost()) + .page( + page) + .build())) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -571,33 +825,56 @@ public void listRoutesFilterByPath() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - ))) - .flatMap(function((organizationId, spaceId, applicationId) -> Mono.zip( - Mono.just(applicationId), - createApplicationRoute(this.cloudFoundryClient, organizationId, spaceId, domainName, applicationId) - ))) - .flatMap(function((applicationId, routeResponse) -> Mono.zip( - Mono.just(ResourceUtils.getId(routeResponse)), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .path(ResourceUtils.getEntity(routeResponse).getPath()) - .page(page) - .build())) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName)))) + .flatMap( + function( + (organizationId, spaceId, applicationId) -> + Mono.zip( + Mono.just(applicationId), + createApplicationRoute( + this.cloudFoundryClient, + organizationId, + spaceId, + domainName, + applicationId)))) + .flatMap( + function( + (applicationId, routeResponse) -> + Mono.zip( + Mono.just(ResourceUtils.getId(routeResponse)), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .path( + ResourceUtils + .getEntity( + routeResponse) + .getPath()) + .page( + page) + .build())) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -606,19 +883,33 @@ public void listServiceBindings() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createUserServiceInstanceId(this.cloudFoundryClient, spaceId, serviceInstanceName) - )) - .delayUntil(function((applicationId, serviceInstanceId) -> createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId))) - .flatMap(function((applicationId, serviceInstanceId) -> Mono.zip( - Mono.just(serviceInstanceId), - getSingleServiceBindingInstanceId(this.cloudFoundryClient, applicationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName), + createUserServiceInstanceId( + this.cloudFoundryClient, + spaceId, + serviceInstanceName))) + .delayUntil( + function( + (applicationId, serviceInstanceId) -> + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId))) + .flatMap( + function( + (applicationId, serviceInstanceId) -> + Mono.zip( + Mono.just(serviceInstanceId), + getSingleServiceBindingInstanceId( + this.cloudFoundryClient, applicationId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -627,31 +918,50 @@ public void listServiceBindingsFilterByServiceInstanceId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createUserServiceInstanceId(this.cloudFoundryClient, spaceId, serviceInstanceName) - )) - .flatMap(function((applicationId, serviceInstanceId) -> Mono.zip( - Mono.just(applicationId), - Mono.just(serviceInstanceId), - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId) - ))) - .flatMap(function((applicationId, serviceInstanceId, serviceBindingId) -> Mono.zip( - Mono.just(serviceBindingId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.applicationsV2() - .listServiceBindings(ListApplicationServiceBindingsRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(serviceInstanceId) - .page(page) - .build())) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName), + createUserServiceInstanceId( + this.cloudFoundryClient, + spaceId, + serviceInstanceName))) + .flatMap( + function( + (applicationId, serviceInstanceId) -> + Mono.zip( + Mono.just(applicationId), + Mono.just(serviceInstanceId), + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId)))) + .flatMap( + function( + (applicationId, serviceInstanceId, serviceBindingId) -> + Mono.zip( + Mono.just(serviceBindingId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .applicationsV2() + .listServiceBindings( + ListApplicationServiceBindingsRequest + .builder() + .applicationId( + applicationId) + .serviceInstanceId( + serviceInstanceId) + .page( + page) + .build())) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -659,26 +969,47 @@ public void removeRoute() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - ))) - .flatMap(function((organizationId, spaceId, applicationId) -> Mono.zip( - Mono.just(applicationId), - createApplicationRoute(this.cloudFoundryClient, organizationId, spaceId, domainName, applicationId) - ))) - .delayUntil(function((applicationId, routeResponse) -> this.cloudFoundryClient.applicationsV2() - .removeRoute(RemoveApplicationRouteRequest.builder() - .applicationId(applicationId) - .routeId(ResourceUtils.getId(routeResponse)) - .build()))) - .flatMapMany(function((applicationId, routeResponse) -> requestRoutes(this.cloudFoundryClient, applicationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName)))) + .flatMap( + function( + (organizationId, spaceId, applicationId) -> + Mono.zip( + Mono.just(applicationId), + createApplicationRoute( + this.cloudFoundryClient, + organizationId, + spaceId, + domainName, + applicationId)))) + .delayUntil( + function( + (applicationId, routeResponse) -> + this.cloudFoundryClient + .applicationsV2() + .removeRoute( + RemoveApplicationRouteRequest.builder() + .applicationId(applicationId) + .routeId( + ResourceUtils.getId( + routeResponse)) + .build()))) + .flatMapMany( + function( + (applicationId, routeResponse) -> + requestRoutes(this.cloudFoundryClient, applicationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -687,23 +1018,43 @@ public void removeServiceBinding() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createUserServiceInstanceId(this.cloudFoundryClient, spaceId, serviceInstanceName) - )) - .flatMap(function((applicationId, serviceInstanceId) -> Mono.zip( - Mono.just(applicationId), - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId) - ))) - .delayUntil(function((applicationId, serviceBindingId) -> this.cloudFoundryClient.applicationsV2() - .removeServiceBinding(RemoveApplicationServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceBindingId(serviceBindingId) - .build()))) - .flatMapMany(function((applicationId, serviceBindingId) -> requestServiceBindings(this.cloudFoundryClient, applicationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName), + createUserServiceInstanceId( + this.cloudFoundryClient, + spaceId, + serviceInstanceName))) + .flatMap( + function( + (applicationId, serviceInstanceId) -> + Mono.zip( + Mono.just(applicationId), + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId)))) + .delayUntil( + function( + (applicationId, serviceBindingId) -> + this.cloudFoundryClient + .applicationsV2() + .removeServiceBinding( + RemoveApplicationServiceBindingRequest + .builder() + .applicationId(applicationId) + .serviceBindingId(serviceBindingId) + .build()))) + .flatMapMany( + function( + (applicationId, serviceBindingId) -> + requestServiceBindings( + this.cloudFoundryClient, applicationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -711,18 +1062,29 @@ public void restage() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .delayUntil(applicationId -> uploadAndStartApplication(this.cloudFoundryClient, applicationId)) - .delayUntil(applicationId -> this.cloudFoundryClient.applicationsV2() - .restage(RestageApplicationRequest.builder() - .applicationId(applicationId) - .build())) - .flatMap(applicationId -> waitForStagingApplication(this.cloudFoundryClient, applicationId)) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .delayUntil( + applicationId -> + uploadAndStartApplication(this.cloudFoundryClient, applicationId)) + .delayUntil( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .restage( + RestageApplicationRequest.builder() + .applicationId(applicationId) + .build())) + .flatMap( + applicationId -> + waitForStagingApplication(this.cloudFoundryClient, applicationId)) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -730,17 +1092,32 @@ public void statistics() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .delayUntil(applicationId -> uploadAndStartApplication(this.cloudFoundryClient, applicationId)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV2() - .statistics(ApplicationStatisticsRequest.builder() - .applicationId(applicationId) - .build()) - .map(instanceStatistics -> instanceStatistics.getInstances().get("0").getStatistics().getName())) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .delayUntil( + applicationId -> + uploadAndStartApplication(this.cloudFoundryClient, applicationId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .statistics( + ApplicationStatisticsRequest.builder() + .applicationId(applicationId) + .build()) + .map( + instanceStatistics -> + instanceStatistics + .getInstances() + .get("0") + .getStatistics() + .getName())) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -748,17 +1125,24 @@ public void summary() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV2() - .summary(SummaryApplicationRequest.builder() - .applicationId(applicationId) - .build()) - .map(SummaryApplicationResponse::getId) - .zipWith(Mono.just(applicationId))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .summary( + SummaryApplicationRequest.builder() + .applicationId(applicationId) + .build()) + .map(SummaryApplicationResponse::getId) + .zipWith(Mono.just(applicationId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -766,23 +1150,42 @@ public void terminateInstance() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .delayUntil(applicationId -> uploadAndStartApplication(this.cloudFoundryClient, applicationId)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getInstanceInfo(this.cloudFoundryClient, applicationId, "0") - .map(info -> Optional.ofNullable(info.getSince())) - )) - .delayUntil(function((applicationId, optionalSince) -> this.cloudFoundryClient.applicationsV2() - .terminateInstance(TerminateApplicationInstanceRequest.builder() - .applicationId(applicationId) - .index("0") - .build()))) - .flatMap(function((applicationId, optionalSince) -> waitForInstanceRestart(this.cloudFoundryClient, applicationId, "0", optionalSince))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .delayUntil( + applicationId -> + uploadAndStartApplication(this.cloudFoundryClient, applicationId)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getInstanceInfo(this.cloudFoundryClient, applicationId, "0") + .map(info -> Optional.ofNullable(info.getSince())))) + .delayUntil( + function( + (applicationId, optionalSince) -> + this.cloudFoundryClient + .applicationsV2() + .terminateInstance( + TerminateApplicationInstanceRequest + .builder() + .applicationId(applicationId) + .index("0") + .build()))) + .flatMap( + function( + (applicationId, optionalSince) -> + waitForInstanceRestart( + this.cloudFoundryClient, + applicationId, + "0", + optionalSince))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -791,39 +1194,66 @@ public void update() { String applicationName2 = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV2() - .update(UpdateApplicationRequest.builder() - .applicationId(applicationId) - .environmentJson("test-var", "test-value") - .name(applicationName2) - .ports(60606, 60607) - .build()) - .map(ResourceUtils::getId)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - requestGetApplication(this.cloudFoundryClient, applicationId) - .map(ResourceUtils::getEntity) - )) - .flatMap(function((applicationId, entity1) -> Mono.zip( - Mono.just(entity1), - this.cloudFoundryClient.applicationsV2() - .update(UpdateApplicationRequest.builder() - .applicationId(applicationId) - .environmentJsons(Collections.emptyMap()) - .build()) - .then(requestGetApplication(this.cloudFoundryClient, applicationId) - .map(ResourceUtils::getEntity)) - ))) - .as(StepVerifier::create) - .consumeNextWith(consumer((entity1, entity2) -> { - assertThat(entity1.getName()).isEqualTo(applicationName2); - assertThat(entity1.getPorts().containsAll(Arrays.asList(60606, 60607))); - assertThat(entity1.getEnvironmentJsons()).containsEntry("test-var", "test-value"); - assertThat(entity2.getEnvironmentJsons()).isEmpty(); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .update( + UpdateApplicationRequest.builder() + .applicationId(applicationId) + .environmentJson("test-var", "test-value") + .name(applicationName2) + .ports(60606, 60607) + .build()) + .map(ResourceUtils::getId)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + requestGetApplication( + this.cloudFoundryClient, applicationId) + .map(ResourceUtils::getEntity))) + .flatMap( + function( + (applicationId, entity1) -> + Mono.zip( + Mono.just(entity1), + this.cloudFoundryClient + .applicationsV2() + .update( + UpdateApplicationRequest.builder() + .applicationId( + applicationId) + .environmentJsons( + Collections + .emptyMap()) + .build()) + .then( + requestGetApplication( + this + .cloudFoundryClient, + applicationId) + .map( + ResourceUtils + ::getEntity))))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (entity1, entity2) -> { + assertThat(entity1.getName()).isEqualTo(applicationName2); + assertThat( + entity1.getPorts() + .containsAll(Arrays.asList(60606, 60607))); + assertThat(entity1.getEnvironmentJsons()) + .containsEntry("test-var", "test-value"); + assertThat(entity2.getEnvironmentJsons()).isEmpty(); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -831,16 +1261,21 @@ public void uploadAndDownload() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .delayUntil(applicationId -> uploadApplication(this.cloudFoundryClient, applicationId)) - .flatMap(applicationId -> Mono.zip( - downloadApplication(this.cloudFoundryClient, applicationId), - getBytes("test-application.zip") - )) - .as(StepVerifier::create) - .consumeNextWith(zipEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .delayUntil( + applicationId -> uploadApplication(this.cloudFoundryClient, applicationId)) + .flatMap( + applicationId -> + Mono.zip( + downloadApplication(this.cloudFoundryClient, applicationId), + getBytes("test-application.zip"))) + .as(StepVerifier::create) + .consumeNextWith(zipEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -848,16 +1283,22 @@ public void uploadAndDownloadAsyncFalse() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .delayUntil(applicationId -> uploadApplicationAsyncFalse(this.cloudFoundryClient, applicationId)) - .flatMap(applicationId -> Mono.zip( - downloadApplication(this.cloudFoundryClient, applicationId), - getBytes("test-application.zip") - )) - .as(StepVerifier::create) - .consumeNextWith(zipEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .delayUntil( + applicationId -> + uploadApplicationAsyncFalse(this.cloudFoundryClient, applicationId)) + .flatMap( + applicationId -> + Mono.zip( + downloadApplication(this.cloudFoundryClient, applicationId), + getBytes("test-application.zip"))) + .as(StepVerifier::create) + .consumeNextWith(zipEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -866,17 +1307,29 @@ public void uploadDirectory() throws IOException { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV2() - .upload(UploadApplicationRequest.builder() - .application(application) - .async(true) - .applicationId(applicationId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .upload( + UploadApplicationRequest.builder() + .application(application) + .async(true) + .applicationId(applicationId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_9) @@ -886,90 +1339,156 @@ public void uploadDroplet() throws IOException { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV2() - .uploadDroplet(UploadApplicationDropletRequest.builder() - .applicationId(applicationId) - .droplet(droplet) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Consumer> applicationIdAndNameEquality(String name) { + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV2() + .uploadDroplet( + UploadApplicationDropletRequest.builder() + .applicationId(applicationId) + .droplet(droplet) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Consumer> + applicationIdAndNameEquality(String name) { Assert.notNull(name, "name must not be null"); - return consumer((applicationId, resource) -> { - assertThat(ResourceUtils.getId(resource)).isEqualTo(applicationId); - assertThat(ResourceUtils.getEntity(resource).getName()).isEqualTo(name); - }); - } - - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return requestCreateApplication(cloudFoundryClient, spaceId, applicationName, "staticfile_buildpack", true, 512, 64, null) - .map(ResourceUtils::getId); - } - - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName, String stackId) { - return requestCreateApplication(cloudFoundryClient, spaceId, applicationName, "staticfile_buildpack", true, 512, 64, stackId) - .map(ResourceUtils::getId); - } - - private static Mono createApplicationRoute(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceId, String domainName, String applicationId) { - return createRouteWithDomain(cloudFoundryClient, organizationId, spaceId, domainName, "test-host", "/test-path") - .flatMap(createRouteResponse -> requestAssociateRoute(cloudFoundryClient, applicationId, createRouteResponse.getMetadata().getId()) - .map(response -> createRouteResponse)); - } - - private static Mono createPrivateDomainId(CloudFoundryClient cloudFoundryClient, String name, String organizationId) { + return consumer( + (applicationId, resource) -> { + assertThat(ResourceUtils.getId(resource)).isEqualTo(applicationId); + assertThat(ResourceUtils.getEntity(resource).getName()).isEqualTo(name); + }); + } + + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return requestCreateApplication( + cloudFoundryClient, + spaceId, + applicationName, + "staticfile_buildpack", + true, + 512, + 64, + null) + .map(ResourceUtils::getId); + } + + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String applicationName, + String stackId) { + return requestCreateApplication( + cloudFoundryClient, + spaceId, + applicationName, + "staticfile_buildpack", + true, + 512, + 64, + stackId) + .map(ResourceUtils::getId); + } + + private static Mono createApplicationRoute( + CloudFoundryClient cloudFoundryClient, + String organizationId, + String spaceId, + String domainName, + String applicationId) { + return createRouteWithDomain( + cloudFoundryClient, + organizationId, + spaceId, + domainName, + "test-host", + "/test-path") + .flatMap( + createRouteResponse -> + requestAssociateRoute( + cloudFoundryClient, + applicationId, + createRouteResponse.getMetadata().getId()) + .map(response -> createRouteResponse)); + } + + private static Mono createPrivateDomainId( + CloudFoundryClient cloudFoundryClient, String name, String organizationId) { return requestCreatePrivateDomain(cloudFoundryClient, name, organizationId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createRouteWithDomain(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceId, String domainName, String host, String path) { + private static Mono createRouteWithDomain( + CloudFoundryClient cloudFoundryClient, + String organizationId, + String spaceId, + String domainName, + String host, + String path) { return createPrivateDomainId(cloudFoundryClient, domainName, organizationId) - .flatMap(domainId -> cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .host(host) - .path(path) - .spaceId(spaceId) - .build())); - } - - private static Mono createServiceBindingId(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + .flatMap( + domainId -> + cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .domainId(domainId) + .host(host) + .path(path) + .spaceId(spaceId) + .build())); + } + + private static Mono createServiceBindingId( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { return requestCreateServiceBinding(cloudFoundryClient, applicationId, serviceInstanceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createUserServiceInstanceId(CloudFoundryClient cloudFoundryClient, String spaceId, String serviceInstanceName) { + private static Mono createUserServiceInstanceId( + CloudFoundryClient cloudFoundryClient, String spaceId, String serviceInstanceName) { return requestCreateUserServiceInstance(cloudFoundryClient, spaceId, serviceInstanceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getInstanceInfo(CloudFoundryClient cloudFoundryClient, String applicationId, String instanceName) { + private static Mono getInstanceInfo( + CloudFoundryClient cloudFoundryClient, String applicationId, String instanceName) { return requestInstances(cloudFoundryClient, applicationId) - .filter(response -> response.getInstances().containsKey(instanceName)) - .map(response -> response.getInstances().get(instanceName)); + .filter(response -> response.getInstances().containsKey(instanceName)) + .map(response -> response.getInstances().get(instanceName)); } - private static Mono getSingleRouteId(CloudFoundryClient cloudFoundryClient, String applicationId) { - return requestRoutes(cloudFoundryClient, applicationId) - .single() - .map(ResourceUtils::getId); + private static Mono getSingleRouteId( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return requestRoutes(cloudFoundryClient, applicationId).single().map(ResourceUtils::getId); } - private static Mono getSingleServiceBindingInstanceId(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono getSingleServiceBindingInstanceId( + CloudFoundryClient cloudFoundryClient, String applicationId) { return requestServiceBindings(cloudFoundryClient, applicationId) - .single() - .map(ResourceUtils::getEntity) - .map(ServiceBindingEntity::getServiceInstanceId); + .single() + .map(ResourceUtils::getEntity) + .map(ServiceBindingEntity::getServiceInstanceId); } @SuppressWarnings("unchecked") - private static String getStringApplicationEnvValue(Map environment, String... keys) { + private static String getStringApplicationEnvValue( + Map environment, String... keys) { for (int i = 0; i < keys.length - 1; ++i) { environment = (Map) environment.get(keys[i]); } @@ -984,7 +1503,9 @@ private static Consumer isTestApplicationDroplet() { return bytes -> { Set names = new HashSet<>(); - try (TarArchiveInputStream in = new TarArchiveInputStream(new GZIPInputStream(new ByteArrayInputStream(bytes)))) { + try (TarArchiveInputStream in = + new TarArchiveInputStream( + new GZIPInputStream(new ByteArrayInputStream(bytes)))) { TarArchiveEntry entry; while ((entry = in.getNextTarEntry()) != null) { names.add(entry.getName()); @@ -997,164 +1518,235 @@ private static Consumer isTestApplicationDroplet() { }; } - private static Mono requestAssociateRoute(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { - return cloudFoundryClient.applicationsV2() - .associateRoute(AssociateApplicationRouteRequest.builder() - .applicationId(applicationId) - .routeId(routeId) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return requestCreateApplication(cloudFoundryClient, spaceId, applicationName, null, null, null, null, null); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName, String buildpack, Boolean diego, - Integer diskQuota, Integer memory, String stackId) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .buildpack(buildpack) - .diego(diego) - .diskQuota(diskQuota) - .memory(memory) - .name(applicationName) - .spaceId(spaceId) - .stackId(stackId) - .build()); - } - - private static Mono requestCreatePrivateDomain(CloudFoundryClient cloudFoundryClient, String name, String organizationId) { - return cloudFoundryClient.privateDomains() - .create(CreatePrivateDomainRequest.builder() - .name(name) - .owningOrganizationId(organizationId) - .build()); - } - - private static Mono requestCreateServiceBinding(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { - return cloudFoundryClient.serviceBindingsV2() - .create(CreateServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(serviceInstanceId) - .build()); - } - - private static Mono requestCreateUserServiceInstance(CloudFoundryClient cloudFoundryClient, String spaceId, String name) { - return cloudFoundryClient.userProvidedServiceInstances() - .create(CreateUserProvidedServiceInstanceRequest.builder() - .name(name) - .spaceId(spaceId) - .build()); - } - - private static Mono requestGetApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV2() - .get(GetApplicationRequest.builder() - .applicationId(applicationId) - .build()) - .cast(AbstractApplicationResource.class); - } - - private static Mono requestInstances(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV2() - .instances(ApplicationInstancesRequest.builder() - .applicationId(applicationId) - .build()); - } - - private static Flux requestRoutes(CloudFoundryClient cloudFoundryClient, String applicationId) { - return PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.applicationsV2() - .listRoutes(ListApplicationRoutesRequest.builder() - .page(page) - .applicationId(applicationId) - .build())); - } - - private static Flux requestServiceBindings(CloudFoundryClient cloudFoundryClient, String applicationId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.applicationsV2() - .listServiceBindings(ListApplicationServiceBindingsRequest.builder() - .applicationId(applicationId) - .page(page) - .build())); - } - - private static Mono requestUpdateApplicationState(CloudFoundryClient cloudFoundryClient, String applicationId, String state) { - return cloudFoundryClient.applicationsV2() - .update(UpdateApplicationRequest.builder() - .applicationId(applicationId) - .state(state) - .build()); - } - - private static Mono startApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono requestAssociateRoute( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + return cloudFoundryClient + .applicationsV2() + .associateRoute( + AssociateApplicationRouteRequest.builder() + .applicationId(applicationId) + .routeId(routeId) + .build()); + } + + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return requestCreateApplication( + cloudFoundryClient, spaceId, applicationName, null, null, null, null, null); + } + + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String applicationName, + String buildpack, + Boolean diego, + Integer diskQuota, + Integer memory, + String stackId) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .buildpack(buildpack) + .diego(diego) + .diskQuota(diskQuota) + .memory(memory) + .name(applicationName) + .spaceId(spaceId) + .stackId(stackId) + .build()); + } + + private static Mono requestCreatePrivateDomain( + CloudFoundryClient cloudFoundryClient, String name, String organizationId) { + return cloudFoundryClient + .privateDomains() + .create( + CreatePrivateDomainRequest.builder() + .name(name) + .owningOrganizationId(organizationId) + .build()); + } + + private static Mono requestCreateServiceBinding( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + return cloudFoundryClient + .serviceBindingsV2() + .create( + CreateServiceBindingRequest.builder() + .applicationId(applicationId) + .serviceInstanceId(serviceInstanceId) + .build()); + } + + private static Mono requestCreateUserServiceInstance( + CloudFoundryClient cloudFoundryClient, String spaceId, String name) { + return cloudFoundryClient + .userProvidedServiceInstances() + .create( + CreateUserProvidedServiceInstanceRequest.builder() + .name(name) + .spaceId(spaceId) + .build()); + } + + private static Mono requestGetApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV2() + .get(GetApplicationRequest.builder().applicationId(applicationId).build()) + .cast(AbstractApplicationResource.class); + } + + private static Mono requestInstances( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV2() + .instances( + ApplicationInstancesRequest.builder().applicationId(applicationId).build()); + } + + private static Flux requestRoutes( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .applicationsV2() + .listRoutes( + ListApplicationRoutesRequest.builder() + .page(page) + .applicationId(applicationId) + .build())); + } + + private static Flux requestServiceBindings( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .applicationsV2() + .listServiceBindings( + ListApplicationServiceBindingsRequest.builder() + .applicationId(applicationId) + .page(page) + .build())); + } + + private static Mono requestUpdateApplicationState( + CloudFoundryClient cloudFoundryClient, String applicationId, String state) { + return cloudFoundryClient + .applicationsV2() + .update( + UpdateApplicationRequest.builder() + .applicationId(applicationId) + .state(state) + .build()); + } + + private static Mono startApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { return requestUpdateApplicationState(cloudFoundryClient, applicationId, "STARTED") - .then(waitForStagingApplication(cloudFoundryClient, applicationId)) - .then(waitForStartingInstanceInfo(cloudFoundryClient, applicationId)); + .then(waitForStagingApplication(cloudFoundryClient, applicationId)) + .then(waitForStartingInstanceInfo(cloudFoundryClient, applicationId)); } - private static Mono uploadAndStartApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono uploadAndStartApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { return uploadApplication(cloudFoundryClient, applicationId) - .then(startApplication(cloudFoundryClient, applicationId)); + .then(startApplication(cloudFoundryClient, applicationId)); } - private static Mono uploadApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono uploadApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { try { - return cloudFoundryClient.applicationsV2() - .upload(UploadApplicationRequest.builder() - .application(new ClassPathResource("test-application.zip").getFile().toPath()) - .async(true) - .applicationId(applicationId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)); + return cloudFoundryClient + .applicationsV2() + .upload( + UploadApplicationRequest.builder() + .application( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .async(true) + .applicationId(applicationId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, Duration.ofMinutes(5), job)); } catch (IOException e) { throw new RuntimeException(e); } } - private static Mono uploadApplicationAsyncFalse(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono uploadApplicationAsyncFalse( + CloudFoundryClient cloudFoundryClient, String applicationId) { try { - return cloudFoundryClient.applicationsV2() - .upload(UploadApplicationRequest.builder() - .application(new ClassPathResource("test-application.zip").getFile().toPath()) - .async(false) - .applicationId(applicationId) - .build()); + return cloudFoundryClient + .applicationsV2() + .upload( + UploadApplicationRequest.builder() + .application( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .async(false) + .applicationId(applicationId) + .build()); } catch (IOException e) { throw new RuntimeException(e); } } - private static Mono waitForInstanceRestart(CloudFoundryClient cloudFoundryClient, String applicationId, String instanceName, Optional optionalSince) { + private static Mono waitForInstanceRestart( + CloudFoundryClient cloudFoundryClient, + String applicationId, + String instanceName, + Optional optionalSince) { return getInstanceInfo(cloudFoundryClient, applicationId, instanceName) - .filter(info -> !isIdentical(info.getSince(), optionalSince.orElse(null))) - .repeatWhenEmpty(DelayUtils.exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), Duration.ofMinutes(5))); + .filter(info -> !isIdentical(info.getSince(), optionalSince.orElse(null))) + .repeatWhenEmpty( + DelayUtils.exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5))); } - private static Mono waitForStagingApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono waitForStagingApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { return requestGetApplication(cloudFoundryClient, applicationId) - .filter(response -> "STAGED".equals(response.getEntity().getPackageState())) - .repeatWhenEmpty(DelayUtils.exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), Duration.ofMinutes(5))); - } - - private static Mono waitForStartingInstanceInfo(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV2() - .instances(ApplicationInstancesRequest.builder() - .applicationId(applicationId) - .build()) - .flatMapMany(response -> Flux.fromIterable(response.getInstances().values())) - .filter(applicationInstanceInfo -> "RUNNING".equals(applicationInstanceInfo.getState())) - .next() - .repeatWhenEmpty(DelayUtils.exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), Duration.ofMinutes(5))); + .filter(response -> "STAGED".equals(response.getEntity().getPackageState())) + .repeatWhenEmpty( + DelayUtils.exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5))); + } + + private static Mono waitForStartingInstanceInfo( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV2() + .instances( + ApplicationInstancesRequest.builder().applicationId(applicationId).build()) + .flatMapMany(response -> Flux.fromIterable(response.getInstances().values())) + .filter( + applicationInstanceInfo -> + "RUNNING".equals(applicationInstanceInfo.getState())) + .next() + .repeatWhenEmpty( + DelayUtils.exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5))); + } + + private Mono downloadApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV2() + .download(DownloadApplicationRequest.builder().applicationId(applicationId).build()) + .as(OperationUtils::collectByteArray); } - - private Mono downloadApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV2() - .download(DownloadApplicationRequest.builder() - .applicationId(applicationId) - .build()) - .as(OperationUtils::collectByteArray); - } - - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java index 444433cf9be..ea0855e0048 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/BlobstoresTest.java @@ -16,29 +16,30 @@ package org.cloudfoundry.client.v2; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.blobstores.DeleteBlobstoreBuildpackCachesRequest; import org.cloudfoundry.util.JobUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.test.StepVerifier; -import java.time.Duration; - public final class BlobstoresTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void delete() { - this.cloudFoundryClient.blobstores() - .deleteBuildpackCaches(DeleteBlobstoreBuildpackCachesRequest.builder() - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .blobstores() + .deleteBuildpackCaches(DeleteBlobstoreBuildpackCachesRequest.builder().build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/BuildpacksTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/BuildpacksTest.java index 947fa424e89..9a4cf77b118 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/BuildpacksTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/BuildpacksTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v2; +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.buildpacks.BuildpackEntity; @@ -30,42 +33,41 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; - public final class BuildpacksTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void create() { String buildpackName = this.nameFactory.getBuildpackName(); - this.cloudFoundryClient.buildpacks() - .create(CreateBuildpackRequest.builder() - .enabled(false) - .locked(true) - .name(buildpackName) - .position(2) - .build()) - .map(ResourceUtils::getEntity) - .as(StepVerifier::create) - .expectNext(BuildpackEntity.builder() - .enabled(false) - .locked(true) - .name(buildpackName) - .position(2) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .buildpacks() + .create( + CreateBuildpackRequest.builder() + .enabled(false) + .locked(true) + .name(buildpackName) + .position(2) + .build()) + .map(ResourceUtils::getEntity) + .as(StepVerifier::create) + .expectNext( + BuildpackEntity.builder() + .enabled(false) + .locked(true) + .name(buildpackName) + .position(2) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -73,15 +75,19 @@ public void delete() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacks() - .delete(DeleteBuildpackRequest.builder() - .async(false) - .buildpackId(buildpackId) - .build())) - .then(getBuildpackEntity(this.cloudFoundryClient, buildpackName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacks() + .delete( + DeleteBuildpackRequest.builder() + .async(false) + .buildpackId(buildpackId) + .build())) + .then(getBuildpackEntity(this.cloudFoundryClient, buildpackName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -89,16 +95,23 @@ public void deleteAsync() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacks() - .delete(DeleteBuildpackRequest.builder() - .async(true) - .buildpackId(buildpackId) - .build())) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .then(getBuildpackEntity(this.cloudFoundryClient, buildpackName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacks() + .delete( + DeleteBuildpackRequest.builder() + .async(true) + .buildpackId(buildpackId) + .build())) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .then(getBuildpackEntity(this.cloudFoundryClient, buildpackName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -106,20 +119,25 @@ public void get() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacks() - .get(GetBuildpackRequest.builder() - .buildpackId(buildpackId) - .build())) - .map(ResourceUtils::getEntity) - .as(StepVerifier::create) - .expectNext(BuildpackEntity.builder() - .enabled(false) - .locked(false) - .name(buildpackName) - .position(3) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacks() + .get( + GetBuildpackRequest.builder() + .buildpackId(buildpackId) + .build())) + .map(ResourceUtils::getEntity) + .as(StepVerifier::create) + .expectNext( + BuildpackEntity.builder() + .enabled(false) + .locked(false) + .name(buildpackName) + .position(3) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -127,21 +145,28 @@ public void list() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMapMany(buildpackId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.buildpacks() - .list(ListBuildpacksRequest.builder() - .build())) - .map(ResourceUtils::getEntity) - .filter(entity -> buildpackName.equals(entity.getName()))) - .as(StepVerifier::create) - .expectNext(BuildpackEntity.builder() - .enabled(false) - .locked(false) - .name(buildpackName) - .position(3) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + buildpackId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .buildpacks() + .list( + ListBuildpacksRequest + .builder() + .build())) + .map(ResourceUtils::getEntity) + .filter(entity -> buildpackName.equals(entity.getName()))) + .as(StepVerifier::create) + .expectNext( + BuildpackEntity.builder() + .enabled(false) + .locked(false) + .name(buildpackName) + .position(3) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -149,21 +174,28 @@ public void listFilterByName() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMapMany(buildpackId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.buildpacks() - .list(ListBuildpacksRequest.builder() - .name(buildpackName) - .build())) - .map(ResourceUtils::getEntity)) - .as(StepVerifier::create) - .expectNext(BuildpackEntity.builder() - .enabled(false) - .locked(false) - .name(buildpackName) - .position(3) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + buildpackId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .buildpacks() + .list( + ListBuildpacksRequest + .builder() + .name(buildpackName) + .build())) + .map(ResourceUtils::getEntity)) + .as(StepVerifier::create) + .expectNext( + BuildpackEntity.builder() + .enabled(false) + .locked(false) + .name(buildpackName) + .position(3) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -171,23 +203,28 @@ public void update() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacks() - .update(UpdateBuildpackRequest.builder() - .buildpackId(buildpackId) - .enabled(true) - .locked(true) - .position(2) - .build())) - .map(ResourceUtils::getEntity) - .as(StepVerifier::create) - .expectNext(BuildpackEntity.builder() - .enabled(true) - .locked(true) - .name(buildpackName) - .position(2) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacks() + .update( + UpdateBuildpackRequest.builder() + .buildpackId(buildpackId) + .enabled(true) + .locked(true) + .position(2) + .build())) + .map(ResourceUtils::getEntity) + .as(StepVerifier::create) + .expectNext( + BuildpackEntity.builder() + .enabled(true) + .locked(true) + .name(buildpackName) + .position(2) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -197,23 +234,28 @@ public void upload() throws IOException { String filename = buildpack.getFileName().toString(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacks() - .upload(UploadBuildpackRequest.builder() - .buildpack(buildpack) - .buildpackId(buildpackId) - .filename(filename) - .build())) - .map(ResourceUtils::getEntity) - .as(StepVerifier::create) - .expectNext(BuildpackEntity.builder() - .enabled(false) - .filename(filename) - .locked(false) - .name(buildpackName) - .position(3) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacks() + .upload( + UploadBuildpackRequest.builder() + .buildpack(buildpack) + .buildpackId(buildpackId) + .filename(filename) + .build())) + .map(ResourceUtils::getEntity) + .as(StepVerifier::create) + .expectNext( + BuildpackEntity.builder() + .enabled(false) + .filename(filename) + .locked(false) + .name(buildpackName) + .position(3) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -223,52 +265,61 @@ public void uploadDirectory() throws IOException { String filename = buildpack.getFileName().toString(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacks() - .upload(UploadBuildpackRequest.builder() - .buildpack(buildpack) - .buildpackId(buildpackId) - .filename(filename) - .build())) - .map(ResourceUtils::getEntity) - .as(StepVerifier::create) - .expectNext(BuildpackEntity.builder() - .enabled(false) - .filename(filename + ".zip") - .locked(false) - .name(buildpackName) - .position(3) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacks() + .upload( + UploadBuildpackRequest.builder() + .buildpack(buildpack) + .buildpackId(buildpackId) + .filename(filename) + .build())) + .map(ResourceUtils::getEntity) + .as(StepVerifier::create) + .expectNext( + BuildpackEntity.builder() + .enabled(false) + .filename(filename + ".zip") + .locked(false) + .name(buildpackName) + .position(3) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createBuildpackId(CloudFoundryClient cloudFoundryClient, String buildpackName) { - return requestCreateBuildpack(cloudFoundryClient, buildpackName) - .map(ResourceUtils::getId); + private static Mono createBuildpackId( + CloudFoundryClient cloudFoundryClient, String buildpackName) { + return requestCreateBuildpack(cloudFoundryClient, buildpackName).map(ResourceUtils::getId); } - private static Mono getBuildpackEntity(CloudFoundryClient cloudFoundryClient, String buildpackName) { + private static Mono getBuildpackEntity( + CloudFoundryClient cloudFoundryClient, String buildpackName) { return requestListBuildpacks(cloudFoundryClient, buildpackName) - .map(ResourceUtils::getEntity) - .singleOrEmpty(); + .map(ResourceUtils::getEntity) + .singleOrEmpty(); } - private static Mono requestCreateBuildpack(CloudFoundryClient cloudFoundryClient, String buildpackName) { - return cloudFoundryClient.buildpacks() - .create(CreateBuildpackRequest.builder() - .enabled(false) - .locked(false) - .name(buildpackName) - .position(3) - .build()); + private static Mono requestCreateBuildpack( + CloudFoundryClient cloudFoundryClient, String buildpackName) { + return cloudFoundryClient + .buildpacks() + .create( + CreateBuildpackRequest.builder() + .enabled(false) + .locked(false) + .name(buildpackName) + .position(3) + .build()); } - private static Flux requestListBuildpacks(CloudFoundryClient cloudFoundryClient, String buildpackName) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.buildpacks() - .list(ListBuildpacksRequest.builder() - .name(buildpackName) - .build())); + private static Flux requestListBuildpacks( + CloudFoundryClient cloudFoundryClient, String buildpackName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .buildpacks() + .list(ListBuildpacksRequest.builder().name(buildpackName).build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/DomainsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/DomainsTest.java index 90428642163..676d130484f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/DomainsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/DomainsTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.function.Consumer; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; @@ -45,47 +51,41 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuple2; -import java.time.Duration; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @SuppressWarnings("deprecation") public final class DomainsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; - @Autowired - private Mono userId; + @Autowired private Mono userId; @Test public void create() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainEntity(this.cloudFoundryClient, organizationId, domainName), - Mono.just(organizationId) - )) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainEntity( + this.cloudFoundryClient, + organizationId, + domainName), + Mono.just(organizationId))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -93,13 +93,28 @@ public void delete() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> createDomainId(this.cloudFoundryClient, domainName, organizationId)) - .delayUntil(domainId -> requestDeleteDomain(this.cloudFoundryClient, domainId) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMap(domainId -> requestGetDomain(this.cloudFoundryClient, domainId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-DomainNotFound\\([0-9]+\\): The domain could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createDomainId(this.cloudFoundryClient, domainName, organizationId)) + .delayUntil( + domainId -> + requestDeleteDomain(this.cloudFoundryClient, domainId) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMap(domainId -> requestGetDomain(this.cloudFoundryClient, domainId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-DomainNotFound\\([0-9]+\\): The domain could" + + " not be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -107,12 +122,22 @@ public void deleteNotAsync() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> createDomainId(this.cloudFoundryClient, domainName, organizationId)) - .delayUntil(domainId -> requestDeleteDomainAsyncFalse(this.cloudFoundryClient, domainId)) - .flatMap(domainId -> requestGetDomain(this.cloudFoundryClient, domainId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-DomainNotFound\\([0-9]+\\): The domain could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createDomainId(this.cloudFoundryClient, domainName, organizationId)) + .delayUntil( + domainId -> + requestDeleteDomainAsyncFalse(this.cloudFoundryClient, domainId)) + .flatMap(domainId -> requestGetDomain(this.cloudFoundryClient, domainId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-DomainNotFound\\([0-9]+\\): The domain could" + + " not be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -120,18 +145,24 @@ public void get() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createDomainId(this.cloudFoundryClient, domainName, organizationId) - )) - .flatMap(function((organizationId, domainId) -> Mono.zip( - getDomainEntity(this.cloudFoundryClient, domainId), - Mono.just(organizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId))) + .flatMap( + function( + (organizationId, domainId) -> + Mono.zip( + getDomainEntity(this.cloudFoundryClient, domainId), + Mono.just(organizationId)))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -139,21 +170,31 @@ public void list() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createDomainId(this.cloudFoundryClient, domainName, organizationId) - )) - .flatMap(function((organizationId, domainId) -> Mono.zip( - requestListDomains(this.cloudFoundryClient) - .filter(resource -> domainId.equals(ResourceUtils.getId(resource))) - .single() - .map(ResourceUtils::getEntity), - Mono.just(organizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId))) + .flatMap( + function( + (organizationId, domainId) -> + Mono.zip( + requestListDomains(this.cloudFoundryClient) + .filter( + resource -> + domainId.equals( + ResourceUtils.getId( + resource))) + .single() + .map(ResourceUtils::getEntity), + Mono.just(organizationId)))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -161,21 +202,33 @@ public void listDomainSpaces() { String domainName = this.nameFactory.getDomainName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - Mono.just(spaceId) - ))) - .flatMap(function((domainId, spaceId) -> Mono.zip( - requestListDomainSpaces(this.cloudFoundryClient, domainId) - .filter(resource -> spaceId.equals(ResourceUtils.getId(resource))) - .single() - .map(ResourceUtils::getId), - Mono.just(spaceId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + Mono.just(spaceId)))) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + requestListDomainSpaces( + this.cloudFoundryClient, domainId) + .filter( + resource -> + spaceId.equals( + ResourceUtils.getId( + resource))) + .single() + .map(ResourceUtils::getId), + Mono.just(spaceId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -184,26 +237,49 @@ public void listDomainSpacesFilterByApplicationId() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> createDomainId(this.cloudFoundryClient, domainName, organizationId)) - .zipWith(this.spaceId) - .flatMap(function((domainId, spaceId) -> Mono.zip( - Mono.just(domainId), - Mono.just(spaceId), - getApplicationId(this.cloudFoundryClient, applicationName, spaceId), - getRouteId(this.cloudFoundryClient, domainId, spaceId) - ))) - .delayUntil(function((domainId, spaceId, applicationId, routeId) -> requestAssociateRouteApplication(this.cloudFoundryClient, applicationId, routeId))) - .flatMap(function((domainId, spaceId, applicationId, routeId) -> Mono.zip( - requestListDomainSpacesByApplicationId(this.cloudFoundryClient, applicationId, domainId) - .filter(resource -> spaceId.equals(ResourceUtils.getId(resource))) - .single() - .map(ResourceUtils::getId), - Mono.just(spaceId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createDomainId(this.cloudFoundryClient, domainName, organizationId)) + .zipWith(this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + Mono.just(domainId), + Mono.just(spaceId), + getApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + getRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .delayUntil( + function( + (domainId, spaceId, applicationId, routeId) -> + requestAssociateRouteApplication( + this.cloudFoundryClient, applicationId, routeId))) + .flatMap( + function( + (domainId, spaceId, applicationId, routeId) -> + Mono.zip( + requestListDomainSpacesByApplicationId( + this.cloudFoundryClient, + applicationId, + domainId) + .filter( + resource -> + spaceId.equals( + ResourceUtils.getId( + resource))) + .single() + .map(ResourceUtils::getId), + Mono.just(spaceId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -211,22 +287,42 @@ public void listDomainSpacesFilterByDeveloperId() { String domainName = this.nameFactory.getDomainName(); Mono.zip(this.spaceId, this.organizationId, this.userId) - .flatMap(function((spaceId, organizationId, userId) -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - requestAssociateOrganizationUser(this.cloudFoundryClient, organizationId, userId), - Mono.just(spaceId), - Mono.just(userId) - ))) - .delayUntil(function((domainId, response, spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((domainId, response, spaceId, userId) -> requestListSpaceDevelopers(this.cloudFoundryClient, domainId, userId) - .filter(resource -> spaceId.equals(ResourceUtils.getId(resource))) - .single() - .map(ResourceUtils::getId) - .zipWith(Mono.just(spaceId)))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (spaceId, organizationId, userId) -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + requestAssociateOrganizationUser( + this.cloudFoundryClient, + organizationId, + userId), + Mono.just(spaceId), + Mono.just(userId)))) + .delayUntil( + function( + (domainId, response, spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (domainId, response, spaceId, userId) -> + requestListSpaceDevelopers( + this.cloudFoundryClient, domainId, userId) + .filter( + resource -> + spaceId.equals( + ResourceUtils.getId( + resource))) + .single() + .map(ResourceUtils::getId) + .zipWith(Mono.just(spaceId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -234,22 +330,36 @@ public void listDomainSpacesFilterByName() { String domainName = this.nameFactory.getDomainName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(spaceId), - getSpaceName(this.cloudFoundryClient, spaceId), - createDomainId(this.cloudFoundryClient, domainName, organizationId) - ))) - .flatMap(function((spaceId, spaceName, domainId) -> Mono.zip( - requestListDomainSpacesBySpaceName(this.cloudFoundryClient, domainId, spaceName) - .filter(resource -> spaceId.equals(ResourceUtils.getId(resource))) - .single() - .map(ResourceUtils::getId), - Mono.just(spaceId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(spaceId), + getSpaceName(this.cloudFoundryClient, spaceId), + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId)))) + .flatMap( + function( + (spaceId, spaceName, domainId) -> + Mono.zip( + requestListDomainSpacesBySpaceName( + this.cloudFoundryClient, + domainId, + spaceName) + .filter( + resource -> + spaceId.equals( + ResourceUtils.getId( + resource))) + .single() + .map(ResourceUtils::getId), + Mono.just(spaceId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -257,22 +367,36 @@ public void listDomainSpacesFilterByOrganizationId() { String domainName = this.nameFactory.getDomainName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - Mono.just(organizationId), - Mono.just(spaceId) - ))) - .flatMap(function((domainId, organizationId, spaceId) -> Mono.zip( - requestListDomainSpacesByOrganizationId(this.cloudFoundryClient, domainId, organizationId) - .filter(resource -> spaceId.equals(ResourceUtils.getId(resource))) - .single() - .map(ResourceUtils::getId), - Mono.just(spaceId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + Mono.just(organizationId), + Mono.just(spaceId)))) + .flatMap( + function( + (domainId, organizationId, spaceId) -> + Mono.zip( + requestListDomainSpacesByOrganizationId( + this.cloudFoundryClient, + domainId, + organizationId) + .filter( + resource -> + spaceId.equals( + ResourceUtils.getId( + resource))) + .single() + .map(ResourceUtils::getId), + Mono.just(spaceId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -280,21 +404,32 @@ public void listFilterByName() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createDomainId(this.cloudFoundryClient, domainName, organizationId) - )) - .flatMap(function((organizationId, domainId) -> Mono.zip( - requestListDomains(this.cloudFoundryClient, domainName) - .filter(resource -> domainId.equals(ResourceUtils.getId(resource))) - .single() - .map(ResourceUtils::getEntity), - Mono.just(organizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId))) + .flatMap( + function( + (organizationId, domainId) -> + Mono.zip( + requestListDomains( + this.cloudFoundryClient, domainName) + .filter( + resource -> + domainId.equals( + ResourceUtils.getId( + resource))) + .single() + .map(ResourceUtils::getEntity), + Mono.just(organizationId)))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -302,216 +437,268 @@ public void listFilterByOwningOrganizationId() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createDomainId(this.cloudFoundryClient, domainName, organizationId) - )) - .flatMap(function((organizationId, domainId) -> Mono.zip( - requestListDomainsByOwningOrganization(this.cloudFoundryClient, organizationId) - .filter(resource -> domainId.equals(ResourceUtils.getId(resource))) - .single() - .map(ResourceUtils::getEntity), - Mono.just(organizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono createDomainEntity(CloudFoundryClient cloudFoundryClient, String organizationId, String domainName) { + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId))) + .flatMap( + function( + (organizationId, domainId) -> + Mono.zip( + requestListDomainsByOwningOrganization( + this.cloudFoundryClient, + organizationId) + .filter( + resource -> + domainId.equals( + ResourceUtils.getId( + resource))) + .single() + .map(ResourceUtils::getEntity), + Mono.just(organizationId)))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono createDomainEntity( + CloudFoundryClient cloudFoundryClient, String organizationId, String domainName) { return requestCreateDomain(cloudFoundryClient, organizationId, domainName) - .map(ResourceUtils::getEntity); + .map(ResourceUtils::getEntity); } - private static Mono createDomainId(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + private static Mono createDomainId( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { return requestCreateDomain(cloudFoundryClient, organizationId, domainName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Consumer> domainNameAndOrganizationIdEquality(String domainName) { - return consumer((entity, organizationId) -> { - assertThat(entity.getName()).isEqualTo(domainName); - assertThat(entity.getOwningOrganizationId()).isEqualTo(organizationId); - }); + private static Consumer> domainNameAndOrganizationIdEquality( + String domainName) { + return consumer( + (entity, organizationId) -> { + assertThat(entity.getName()).isEqualTo(domainName); + assertThat(entity.getOwningOrganizationId()).isEqualTo(organizationId); + }); } - private static Mono getApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + private static Mono getApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getDomainEntity(CloudFoundryClient cloudFoundryClient, String domainId) { - return requestGetDomain(cloudFoundryClient, domainId) - .map(ResourceUtils::getEntity); + private static Mono getDomainEntity( + CloudFoundryClient cloudFoundryClient, String domainId) { + return requestGetDomain(cloudFoundryClient, domainId).map(ResourceUtils::getEntity); } - private static Mono getRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) { - return requestCreateRoute(cloudFoundryClient, domainId, spaceId) - .map(ResourceUtils::getId); + private static Mono getRouteId( + CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) { + return requestCreateRoute(cloudFoundryClient, domainId, spaceId).map(ResourceUtils::getId); } - private static Mono getSpaceName(CloudFoundryClient cloudFoundryClient, String spaceId) { + private static Mono getSpaceName( + CloudFoundryClient cloudFoundryClient, String spaceId) { return requestSpace(cloudFoundryClient, spaceId) - .map(ResourceUtils::getEntity) - .map(SpaceEntity::getName); - } - - private static Mono requestAssociateOrganizationUser(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateUser(AssociateOrganizationUserRequest.builder() - .organizationId(organizationId) - .userId(userId) - .build()); - } - - private static Mono requestAssociateRouteApplication(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { - return cloudFoundryClient.routes() - .associateApplication(AssociateRouteApplicationRequest.builder() - .routeId(routeId) - .applicationId(applicationId) - .build()); - } - - private static Mono requestAssociateSpaceDeveloper(CloudFoundryClient cloudFoundryClient, String spaceId, String developerId) { - return cloudFoundryClient.spaces() - .associateDeveloper(AssociateSpaceDeveloperRequest.builder() - .spaceId(spaceId) - .developerId(developerId) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreateDomain(CloudFoundryClient cloudFoundryClient, String organizationId, String domainName) { - return cloudFoundryClient.domains() - .create(CreateDomainRequest.builder() - .name(domainName) - .owningOrganizationId(organizationId) - .wildcard(true) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) { - return cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .spaceId(spaceId) - .build()); - } - - private static Mono requestDeleteDomain(CloudFoundryClient cloudFoundryClient, String domainId) { - return cloudFoundryClient.domains() - .delete(DeleteDomainRequest.builder() - .async(true) - .domainId(domainId) - .build()); - } - - private static Mono requestDeleteDomainAsyncFalse(CloudFoundryClient cloudFoundryClient, String domainId) { - return cloudFoundryClient.domains() - .delete(DeleteDomainRequest.builder() - .async(false) - .domainId(domainId) - .build()); - } - - private static Mono requestGetDomain(CloudFoundryClient cloudFoundryClient, String domainId) { - return cloudFoundryClient.domains() - .get(GetDomainRequest.builder() - .domainId(domainId) - .build()); - } - - private static Flux requestListDomainSpaces(CloudFoundryClient cloudFoundryClient, String domainId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.domains() - .listSpaces(ListDomainSpacesRequest.builder() - .domainId(domainId) - .page(page) - .build())); - } - - private static Flux requestListDomainSpacesByApplicationId(CloudFoundryClient cloudFoundryClient, String applicationId, String domainId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.domains() - .listSpaces(ListDomainSpacesRequest.builder() - .page(page) - .applicationId(applicationId) - .domainId(domainId) - .build()) - ); - } - - private static Flux requestListDomainSpacesByOrganizationId(CloudFoundryClient cloudFoundryClient, String domainId, String organizationId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.domains() - .listSpaces(ListDomainSpacesRequest.builder() - .domainId(domainId) - .organizationId(organizationId) - .page(page) - .build())); - } - - private static Flux requestListDomainSpacesBySpaceName(CloudFoundryClient cloudFoundryClient, String domainId, String spaceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.domains() - .listSpaces(ListDomainSpacesRequest.builder() - .domainId(domainId) - .name(spaceName) - .page(page) - .build())); - } - - private static Flux requestListDomains(CloudFoundryClient cloudFoundryClient, String domainName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.domains() - .list(ListDomainsRequest.builder() - .name(domainName) - .page(page) - .build())); + .map(ResourceUtils::getEntity) + .map(SpaceEntity::getName); + } + + private static Mono requestAssociateOrganizationUser( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateUser( + AssociateOrganizationUserRequest.builder() + .organizationId(organizationId) + .userId(userId) + .build()); + } + + private static Mono requestAssociateRouteApplication( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + return cloudFoundryClient + .routes() + .associateApplication( + AssociateRouteApplicationRequest.builder() + .routeId(routeId) + .applicationId(applicationId) + .build()); + } + + private static Mono requestAssociateSpaceDeveloper( + CloudFoundryClient cloudFoundryClient, String spaceId, String developerId) { + return cloudFoundryClient + .spaces() + .associateDeveloper( + AssociateSpaceDeveloperRequest.builder() + .spaceId(spaceId) + .developerId(developerId) + .build()); + } + + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreateDomain( + CloudFoundryClient cloudFoundryClient, String organizationId, String domainName) { + return cloudFoundryClient + .domains() + .create( + CreateDomainRequest.builder() + .name(domainName) + .owningOrganizationId(organizationId) + .wildcard(true) + .build()); + } + + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) { + return cloudFoundryClient + .routes() + .create(CreateRouteRequest.builder().domainId(domainId).spaceId(spaceId).build()); + } + + private static Mono requestDeleteDomain( + CloudFoundryClient cloudFoundryClient, String domainId) { + return cloudFoundryClient + .domains() + .delete(DeleteDomainRequest.builder().async(true).domainId(domainId).build()); + } + + private static Mono requestDeleteDomainAsyncFalse( + CloudFoundryClient cloudFoundryClient, String domainId) { + return cloudFoundryClient + .domains() + .delete(DeleteDomainRequest.builder().async(false).domainId(domainId).build()); + } + + private static Mono requestGetDomain( + CloudFoundryClient cloudFoundryClient, String domainId) { + return cloudFoundryClient + .domains() + .get(GetDomainRequest.builder().domainId(domainId).build()); + } + + private static Flux requestListDomainSpaces( + CloudFoundryClient cloudFoundryClient, String domainId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .domains() + .listSpaces( + ListDomainSpacesRequest.builder() + .domainId(domainId) + .page(page) + .build())); + } + + private static Flux requestListDomainSpacesByApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationId, String domainId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .domains() + .listSpaces( + ListDomainSpacesRequest.builder() + .page(page) + .applicationId(applicationId) + .domainId(domainId) + .build())); + } + + private static Flux requestListDomainSpacesByOrganizationId( + CloudFoundryClient cloudFoundryClient, String domainId, String organizationId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .domains() + .listSpaces( + ListDomainSpacesRequest.builder() + .domainId(domainId) + .organizationId(organizationId) + .page(page) + .build())); + } + + private static Flux requestListDomainSpacesBySpaceName( + CloudFoundryClient cloudFoundryClient, String domainId, String spaceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .domains() + .listSpaces( + ListDomainSpacesRequest.builder() + .domainId(domainId) + .name(spaceName) + .page(page) + .build())); + } + + private static Flux requestListDomains( + CloudFoundryClient cloudFoundryClient, String domainName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .domains() + .list( + ListDomainsRequest.builder() + .name(domainName) + .page(page) + .build())); } private static Flux requestListDomains(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.domains() - .list(ListDomainsRequest.builder() - .page(page) - .build())); - } - - private static Flux requestListDomainsByOwningOrganization(CloudFoundryClient cloudFoundryClient, String organizationId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.domains() - .list(ListDomainsRequest.builder() - .owningOrganizationId(organizationId) - .page(page) - .build())); - } - - private static Flux requestListSpaceDevelopers(CloudFoundryClient cloudFoundryClient, String domainId, String userId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.domains() - .listSpaces(ListDomainSpacesRequest.builder() - .page(page) - .developerId(userId) - .domainId(domainId) - .build()) - ); - } - - private static Mono requestSpace(CloudFoundryClient cloudFoundryClient, String spaceId) { - return cloudFoundryClient.spaces() - .get(GetSpaceRequest.builder() - .spaceId(spaceId) - .build()); + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .domains() + .list(ListDomainsRequest.builder().page(page).build())); + } + + private static Flux requestListDomainsByOwningOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .domains() + .list( + ListDomainsRequest.builder() + .owningOrganizationId(organizationId) + .page(page) + .build())); + } + + private static Flux requestListSpaceDevelopers( + CloudFoundryClient cloudFoundryClient, String domainId, String userId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .domains() + .listSpaces( + ListDomainSpacesRequest.builder() + .page(page) + .developerId(userId) + .domainId(domainId) + .build())); + } + + private static Mono requestSpace( + CloudFoundryClient cloudFoundryClient, String spaceId) { + return cloudFoundryClient.spaces().get(GetSpaceRequest.builder().spaceId(spaceId).build()); } - } - diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/EventsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/EventsTest.java index f3546825047..76dcea594d2 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/EventsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/EventsTest.java @@ -16,159 +16,191 @@ package org.cloudfoundry.client.v2; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.events.EventResource; import org.cloudfoundry.client.v2.events.GetEventRequest; import org.cloudfoundry.client.v2.events.ListEventsRequest; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - public final class EventsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void get() { getFirstEvent(this.cloudFoundryClient) - .flatMap(resource -> Mono.zip( - Mono.just(resource) - .map(ResourceUtils::getId), - this.cloudFoundryClient.events() - .get(GetEventRequest.builder() - .eventId(ResourceUtils.getId(resource)) - .build()) - .map(ResourceUtils::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + resource -> + Mono.zip( + Mono.just(resource).map(ResourceUtils::getId), + this.cloudFoundryClient + .events() + .get( + GetEventRequest.builder() + .eventId( + ResourceUtils.getId( + resource)) + .build()) + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { getFirstEvent(this.cloudFoundryClient) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.events() - .list(ListEventsRequest.builder() - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .events() + .list(ListEventsRequest.builder().build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByActee() { getFirstEvent(this.cloudFoundryClient) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.events() - .list(ListEventsRequest.builder() - .actee(ResourceUtils.getEntity(resource).getActee()) - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .events() + .list( + ListEventsRequest.builder() + .actee( + ResourceUtils.getEntity( + resource) + .getActee()) + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByOrganizationId() { getFirstEvent(this.cloudFoundryClient) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.events() - .list(ListEventsRequest.builder() - .organizationId(ResourceUtils.getEntity(resource).getOrganizationId()) - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .events() + .list( + ListEventsRequest.builder() + .organizationId( + ResourceUtils.getEntity( + resource) + .getOrganizationId()) + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterBySpaceId() { getFirstEvent(this.cloudFoundryClient) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.events() - .list(ListEventsRequest.builder() - .spaceId(ResourceUtils.getEntity(resource).getSpaceId()) - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .events() + .list( + ListEventsRequest.builder() + .spaceId( + ResourceUtils.getEntity( + resource) + .getSpaceId()) + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByTimestamp() { getFirstEvent(this.cloudFoundryClient) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.events() - .list(ListEventsRequest.builder() - .timestamp(ResourceUtils.getEntity(resource).getTimestamp()) - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .events() + .list( + ListEventsRequest.builder() + .timestamp( + ResourceUtils.getEntity( + resource) + .getTimestamp()) + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByType() { getFirstEvent(this.cloudFoundryClient) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.events() - .list(ListEventsRequest.builder() - .type(ResourceUtils.getEntity(resource).getType()) - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .events() + .list( + ListEventsRequest.builder() + .type( + ResourceUtils.getEntity( + resource) + .getType()) + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } private static Mono getFirstEvent(CloudFoundryClient cloudFoundryClient) { - return listEvents(cloudFoundryClient) - .next(); + return listEvents(cloudFoundryClient).next(); } private static Flux listEvents(CloudFoundryClient cloudFoundryClient) { - return cloudFoundryClient.events() - .list(ListEventsRequest.builder() - .build()) - .flatMapMany(ResourceUtils::getResources); + return cloudFoundryClient + .events() + .list(ListEventsRequest.builder().build()) + .flatMapMany(ResourceUtils::getResources); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/FeatureFlagsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/FeatureFlagsTest.java index 4d659103622..d47962b5aa9 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/FeatureFlagsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/FeatureFlagsTest.java @@ -16,114 +16,141 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.Arrays; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.featureflags.FeatureFlagEntity; import org.cloudfoundry.client.v2.featureflags.GetFeatureFlagRequest; import org.cloudfoundry.client.v2.featureflags.ListFeatureFlagsRequest; import org.cloudfoundry.client.v2.featureflags.SetFeatureFlagRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuples; -import java.time.Duration; -import java.util.Arrays; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class FeatureFlagsTest extends AbstractIntegrationTest { - private static final List coreFeatureFlagNameList = Arrays.asList( - "app_bits_upload", - "app_scaling", - "diego_docker", - "private_domain_creation", - "route_creation", - "service_instance_creation", - "set_roles_by_username", - "unset_roles_by_username", - "user_org_creation" - ); + private static final List coreFeatureFlagNameList = + Arrays.asList( + "app_bits_upload", + "app_scaling", + "diego_docker", + "private_domain_creation", + "route_creation", + "service_instance_creation", + "set_roles_by_username", + "unset_roles_by_username", + "user_org_creation"); - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void getEach() { - Flux - .fromIterable(coreFeatureFlagNameList) - .flatMap(flagName -> this.cloudFoundryClient.featureFlags() - .get(GetFeatureFlagRequest.builder() - .name(flagName) - .build()) - .map(response -> Tuples.of(flagName, response))) - .collectList() - .as(StepVerifier::create) - .consumeNextWith(list -> list.forEach(consumer((name, entity) -> assertThat(entity.getName()).isEqualTo(name)))) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Flux.fromIterable(coreFeatureFlagNameList) + .flatMap( + flagName -> + this.cloudFoundryClient + .featureFlags() + .get(GetFeatureFlagRequest.builder().name(flagName).build()) + .map(response -> Tuples.of(flagName, response))) + .collectList() + .as(StepVerifier::create) + .consumeNextWith( + list -> + list.forEach( + consumer( + (name, entity) -> + assertThat(entity.getName()) + .isEqualTo(name)))) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { - this.cloudFoundryClient.featureFlags() - .list(ListFeatureFlagsRequest.builder() - .build()) - .as(StepVerifier::create) - .consumeNextWith(response -> { - Set returnedFlagSet = flagNameSetFrom(response.getFeatureFlags()); - assertThat(returnedFlagSet).containsAll(coreFeatureFlagNameList); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .featureFlags() + .list(ListFeatureFlagsRequest.builder().build()) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + Set returnedFlagSet = + flagNameSetFrom(response.getFeatureFlags()); + assertThat(returnedFlagSet).containsAll(coreFeatureFlagNameList); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void setAndResetEach() { Flux.fromIterable(coreFeatureFlagNameList) - .flatMap(flagName -> this.cloudFoundryClient.featureFlags() - .get(GetFeatureFlagRequest.builder() - .name(flagName) - .build()) - .flatMap(getResponse -> Mono.zip( - Mono.just(getResponse), - this.cloudFoundryClient.featureFlags() - .set(SetFeatureFlagRequest.builder() - .name(getResponse.getName()) - .enabled(!getResponse.getEnabled()) - .build()) - )) - .flatMap(function((getResponse, setResponse) -> Mono.zip( - Mono.just(getResponse), - Mono.just(setResponse), - this.cloudFoundryClient.featureFlags() - .set(SetFeatureFlagRequest.builder() - .name(getResponse.getName()) - .enabled(getResponse.getEnabled()) - .build()) - )))) - .collectList() - .as(StepVerifier::create) - .consumeNextWith(list -> list.forEach(consumer((getResponse, setResponse, resetResponse) -> { - assertThat(setResponse.getEnabled()).isNotEqualTo(getResponse.getEnabled()); - assertThat(resetResponse.getEnabled()).isEqualTo(getResponse.getEnabled()); - }))) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + flagName -> + this.cloudFoundryClient + .featureFlags() + .get(GetFeatureFlagRequest.builder().name(flagName).build()) + .flatMap( + getResponse -> + Mono.zip( + Mono.just(getResponse), + this.cloudFoundryClient + .featureFlags() + .set( + SetFeatureFlagRequest + .builder() + .name( + getResponse + .getName()) + .enabled( + !getResponse + .getEnabled()) + .build()))) + .flatMap( + function( + (getResponse, setResponse) -> + Mono.zip( + Mono.just(getResponse), + Mono.just(setResponse), + this.cloudFoundryClient + .featureFlags() + .set( + SetFeatureFlagRequest + .builder() + .name( + getResponse + .getName()) + .enabled( + getResponse + .getEnabled()) + .build()))))) + .collectList() + .as(StepVerifier::create) + .consumeNextWith( + list -> + list.forEach( + consumer( + (getResponse, setResponse, resetResponse) -> { + assertThat(setResponse.getEnabled()) + .isNotEqualTo(getResponse.getEnabled()); + assertThat(resetResponse.getEnabled()) + .isEqualTo(getResponse.getEnabled()); + }))) + .expectComplete() + .verify(Duration.ofMinutes(5)); } private static Set flagNameSetFrom(List listFlags) { - return listFlags - .stream() - .map(FeatureFlagEntity::getName) - .collect(Collectors.toSet()); + return listFlags.stream().map(FeatureFlagEntity::getName).collect(Collectors.toSet()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/InfoTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/InfoTest.java index 70b92b66157..471cb284e8a 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/InfoTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/InfoTest.java @@ -16,37 +16,36 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.client.CloudFoundryClient.SUPPORTED_API_VERSION; + import com.github.zafarkhaja.semver.Version; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.info.GetInfoRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.client.CloudFoundryClient.SUPPORTED_API_VERSION; - public final class InfoTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void info() { - this.cloudFoundryClient.info() - .get(GetInfoRequest.builder() - .build()) - .as(StepVerifier::create) - .consumeNextWith(response -> { - Version expected = Version.valueOf(SUPPORTED_API_VERSION); - Version actual = Version.valueOf(response.getApiVersion()); - - assertThat(actual).isLessThanOrEqualTo(expected); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .info() + .get(GetInfoRequest.builder().build()) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + Version expected = Version.valueOf(SUPPORTED_API_VERSION); + Version actual = Version.valueOf(response.getApiVersion()); + + assertThat(actual).isLessThanOrEqualTo(expected); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/JobsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/JobsTest.java index 81df89392f4..0727b062d2e 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/JobsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/JobsTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.util.tuple.TupleUtils.predicate; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.jobs.GetJobRequest; @@ -23,46 +26,45 @@ import org.cloudfoundry.client.v2.organizations.DeleteOrganizationRequest; import org.cloudfoundry.util.DelayUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.util.tuple.TupleUtils.predicate; - public final class JobsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void getJob() { String organizationName = this.nameFactory.getOrganizationName(); - this.cloudFoundryClient.organizations() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()) - .map(ResourceUtils::getId) - .flatMap(organizationId -> this.cloudFoundryClient.organizations() - .delete(DeleteOrganizationRequest.builder() - .organizationId(organizationId) - .async(true) - .build()) - .map(ResourceUtils::getId)) - .flatMap(jobId -> this.cloudFoundryClient.jobs() - .get(GetJobRequest.builder() - .jobId(jobId) - .build()) + this.cloudFoundryClient + .organizations() + .create(CreateOrganizationRequest.builder().name(organizationName).build()) .map(ResourceUtils::getId) - .zipWith(Mono.just(jobId))) - .filter(predicate((getId, deleteId) -> !"0".equals(getId))) - .repeatWhenEmpty(5, DelayUtils.instant()) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizations() + .delete( + DeleteOrganizationRequest.builder() + .organizationId(organizationId) + .async(true) + .build()) + .map(ResourceUtils::getId)) + .flatMap( + jobId -> + this.cloudFoundryClient + .jobs() + .get(GetJobRequest.builder().jobId(jobId).build()) + .map(ResourceUtils::getId) + .zipWith(Mono.just(jobId))) + .filter(predicate((getId, deleteId) -> !"0".equals(getId))) + .repeatWhenEmpty(5, DelayUtils.instant()) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/OrganizationQuotaDefinitionsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/OrganizationQuotaDefinitionsTest.java index b9b1b0c1bf0..c7f8c0b4f64 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/OrganizationQuotaDefinitionsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/OrganizationQuotaDefinitionsTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.organizationquotadefinitions.CreateOrganizationQuotaDefinitionRequest; @@ -29,51 +32,50 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class OrganizationQuotaDefinitionsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @SuppressWarnings("deprecation") @Test public void create() { String quotaDefinitionName = this.nameFactory.getQuotaDefinitionName(); - this.cloudFoundryClient.organizationQuotaDefinitions() - .create(CreateOrganizationQuotaDefinitionRequest.builder() - .instanceMemoryLimit(1024) - .memoryLimit(1024) - .name(quotaDefinitionName) - .nonBasicServicesAllowed(false) - .totalRoutes(10) - .totalServices(-1) - .build()) - .map(ResourceUtils::getEntity) - .as(StepVerifier::create) - .expectNext(OrganizationQuotaDefinitionEntity.builder() - .applicationInstanceLimit(-1) - .applicationTaskLimit(-1) - .instanceMemoryLimit(1024) - .memoryLimit(1024) - .name(quotaDefinitionName) - .nonBasicServicesAllowed(false) - .totalPrivateDomains(-1) - .totalRoutes(10) - .totalReservedRoutePorts(0) - .totalServiceKeys(-1) - .totalServices(-1) - .trialDatabaseAllowed(false) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .organizationQuotaDefinitions() + .create( + CreateOrganizationQuotaDefinitionRequest.builder() + .instanceMemoryLimit(1024) + .memoryLimit(1024) + .name(quotaDefinitionName) + .nonBasicServicesAllowed(false) + .totalRoutes(10) + .totalServices(-1) + .build()) + .map(ResourceUtils::getEntity) + .as(StepVerifier::create) + .expectNext( + OrganizationQuotaDefinitionEntity.builder() + .applicationInstanceLimit(-1) + .applicationTaskLimit(-1) + .instanceMemoryLimit(1024) + .memoryLimit(1024) + .name(quotaDefinitionName) + .nonBasicServicesAllowed(false) + .totalPrivateDomains(-1) + .totalRoutes(10) + .totalReservedRoutePorts(0) + .totalServiceKeys(-1) + .totalServices(-1) + .trialDatabaseAllowed(false) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -81,17 +83,36 @@ public void delete() { String quotaDefinitionName = this.nameFactory.getQuotaDefinitionName(); requestCreateOrganizationQuotaDefinition(this.cloudFoundryClient, quotaDefinitionName) - .map(ResourceUtils::getId) - .delayUntil(organizationQuotaDefinitionId -> this.cloudFoundryClient.organizationQuotaDefinitions() - .delete(DeleteOrganizationQuotaDefinitionRequest.builder() - .async(true) - .organizationQuotaDefinitionId(organizationQuotaDefinitionId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMap(organizationQuotaDefinitionId -> requestGetOrganizationQuotaDefinition(this.cloudFoundryClient, organizationQuotaDefinitionId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-QuotaDefinitionNotFound\\([0-9]+\\): Quota Definition could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .map(ResourceUtils::getId) + .delayUntil( + organizationQuotaDefinitionId -> + this.cloudFoundryClient + .organizationQuotaDefinitions() + .delete( + DeleteOrganizationQuotaDefinitionRequest.builder() + .async(true) + .organizationQuotaDefinitionId( + organizationQuotaDefinitionId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMap( + organizationQuotaDefinitionId -> + requestGetOrganizationQuotaDefinition( + this.cloudFoundryClient, organizationQuotaDefinitionId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-QuotaDefinitionNotFound\\([0-9]+\\): Quota" + + " Definition could not be found: .*")) + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("deprecation") @@ -100,29 +121,35 @@ public void get() { String quotaDefinitionName = this.nameFactory.getQuotaDefinitionName(); requestCreateOrganizationQuotaDefinition(this.cloudFoundryClient, quotaDefinitionName) - .map(ResourceUtils::getId) - .flatMap(organizationQuotaDefinitionId -> this.cloudFoundryClient.organizationQuotaDefinitions() - .get(GetOrganizationQuotaDefinitionRequest.builder() - .organizationQuotaDefinitionId(organizationQuotaDefinitionId) - .build())) - .map(ResourceUtils::getEntity) - .as(StepVerifier::create) - .expectNext(OrganizationQuotaDefinitionEntity.builder() - .applicationInstanceLimit(-1) - .applicationTaskLimit(-1) - .instanceMemoryLimit(50) - .memoryLimit(500) - .name(quotaDefinitionName) - .nonBasicServicesAllowed(false) - .totalPrivateDomains(-1) - .totalRoutes(10) - .totalReservedRoutePorts(0) - .totalServiceKeys(-1) - .totalServices(5) - .trialDatabaseAllowed(false) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .map(ResourceUtils::getId) + .flatMap( + organizationQuotaDefinitionId -> + this.cloudFoundryClient + .organizationQuotaDefinitions() + .get( + GetOrganizationQuotaDefinitionRequest.builder() + .organizationQuotaDefinitionId( + organizationQuotaDefinitionId) + .build())) + .map(ResourceUtils::getEntity) + .as(StepVerifier::create) + .expectNext( + OrganizationQuotaDefinitionEntity.builder() + .applicationInstanceLimit(-1) + .applicationTaskLimit(-1) + .instanceMemoryLimit(50) + .memoryLimit(500) + .name(quotaDefinitionName) + .nonBasicServicesAllowed(false) + .totalPrivateDomains(-1) + .totalRoutes(10) + .totalReservedRoutePorts(0) + .totalServiceKeys(-1) + .totalServices(5) + .trialDatabaseAllowed(false) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -130,20 +157,30 @@ public void list() { String quotaDefinitionName = this.nameFactory.getQuotaDefinitionName(); requestCreateOrganizationQuotaDefinition(this.cloudFoundryClient, quotaDefinitionName) - .map(ResourceUtils::getId) - .flatMap(organizationQuotaDefinitionId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.organizationQuotaDefinitions() - .list(ListOrganizationQuotaDefinitionsRequest.builder() - .page(page) - .build())) - .filter(quotaDefinition -> ResourceUtils.getId(quotaDefinition).equals(organizationQuotaDefinitionId)) - .single()) - .map(ResourceUtils::getEntity) - .map(OrganizationQuotaDefinitionEntity::getName) - .as(StepVerifier::create) - .expectNext(quotaDefinitionName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .map(ResourceUtils::getId) + .flatMap( + organizationQuotaDefinitionId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .organizationQuotaDefinitions() + .list( + ListOrganizationQuotaDefinitionsRequest + .builder() + .page(page) + .build())) + .filter( + quotaDefinition -> + ResourceUtils.getId(quotaDefinition) + .equals( + organizationQuotaDefinitionId)) + .single()) + .map(ResourceUtils::getEntity) + .map(OrganizationQuotaDefinitionEntity::getName) + .as(StepVerifier::create) + .expectNext(quotaDefinitionName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("deprecation") @@ -152,54 +189,72 @@ public void update() { String quotaDefinitionName = this.nameFactory.getQuotaDefinitionName(); requestCreateOrganizationQuotaDefinition(this.cloudFoundryClient, quotaDefinitionName) - .map(ResourceUtils::getId) - .delayUntil(organizationQuotaDefinitionId -> this.cloudFoundryClient.organizationQuotaDefinitions() - .update(UpdateOrganizationQuotaDefinitionRequest.builder() - .organizationQuotaDefinitionId(organizationQuotaDefinitionId) - .totalServices(10) - .memoryLimit(1000) - .build())) - .flatMap(organizationQuotaDefinitionId -> this.cloudFoundryClient.organizationQuotaDefinitions() - .get(GetOrganizationQuotaDefinitionRequest.builder() - .organizationQuotaDefinitionId(organizationQuotaDefinitionId) - .build())) - .map(ResourceUtils::getEntity) - .as(StepVerifier::create) - .expectNext(OrganizationQuotaDefinitionEntity.builder() - .applicationInstanceLimit(-1) - .applicationTaskLimit(-1) - .instanceMemoryLimit(50) - .memoryLimit(1000) - .name(quotaDefinitionName) - .nonBasicServicesAllowed(false) - .totalPrivateDomains(-1) - .totalRoutes(10) - .totalReservedRoutePorts(0) - .totalServiceKeys(-1) - .totalServices(10) - .trialDatabaseAllowed(false) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .map(ResourceUtils::getId) + .delayUntil( + organizationQuotaDefinitionId -> + this.cloudFoundryClient + .organizationQuotaDefinitions() + .update( + UpdateOrganizationQuotaDefinitionRequest.builder() + .organizationQuotaDefinitionId( + organizationQuotaDefinitionId) + .totalServices(10) + .memoryLimit(1000) + .build())) + .flatMap( + organizationQuotaDefinitionId -> + this.cloudFoundryClient + .organizationQuotaDefinitions() + .get( + GetOrganizationQuotaDefinitionRequest.builder() + .organizationQuotaDefinitionId( + organizationQuotaDefinitionId) + .build())) + .map(ResourceUtils::getEntity) + .as(StepVerifier::create) + .expectNext( + OrganizationQuotaDefinitionEntity.builder() + .applicationInstanceLimit(-1) + .applicationTaskLimit(-1) + .instanceMemoryLimit(50) + .memoryLimit(1000) + .name(quotaDefinitionName) + .nonBasicServicesAllowed(false) + .totalPrivateDomains(-1) + .totalRoutes(10) + .totalReservedRoutePorts(0) + .totalServiceKeys(-1) + .totalServices(10) + .trialDatabaseAllowed(false) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono requestCreateOrganizationQuotaDefinition(CloudFoundryClient cloudFoundryClient, String quotaDefinitionName) { - return cloudFoundryClient.organizationQuotaDefinitions() - .create(CreateOrganizationQuotaDefinitionRequest.builder() - .instanceMemoryLimit(50) - .memoryLimit(500) - .name(quotaDefinitionName) - .nonBasicServicesAllowed(false) - .totalRoutes(10) - .totalServices(5) - .build()); + private static Mono + requestCreateOrganizationQuotaDefinition( + CloudFoundryClient cloudFoundryClient, String quotaDefinitionName) { + return cloudFoundryClient + .organizationQuotaDefinitions() + .create( + CreateOrganizationQuotaDefinitionRequest.builder() + .instanceMemoryLimit(50) + .memoryLimit(500) + .name(quotaDefinitionName) + .nonBasicServicesAllowed(false) + .totalRoutes(10) + .totalServices(5) + .build()); } - private static Mono requestGetOrganizationQuotaDefinition(CloudFoundryClient cloudFoundryClient, String organizationQuotaDefinitionId) { - return cloudFoundryClient.organizationQuotaDefinitions() - .get(GetOrganizationQuotaDefinitionRequest.builder() - .organizationQuotaDefinitionId(organizationQuotaDefinitionId) - .build()); + private static Mono + requestGetOrganizationQuotaDefinition( + CloudFoundryClient cloudFoundryClient, String organizationQuotaDefinitionId) { + return cloudFoundryClient + .organizationQuotaDefinitions() + .get( + GetOrganizationQuotaDefinitionRequest.builder() + .organizationQuotaDefinitionId(organizationQuotaDefinitionId) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/OrganizationsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/OrganizationsTest.java index fa18fc1d85d..e1d1762e649 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/OrganizationsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/OrganizationsTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.function.UnaryOperator; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; @@ -87,59 +92,50 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.function.UnaryOperator; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class OrganizationsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono userId; + @Autowired private Mono userId; - @Autowired - private String username; + @Autowired private String username; @Test public void associateAuditor() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associateAuditor(AssociateOrganizationAuditorRequest.builder() - .auditorId(userId) - .organizationId(organizationId) - .build()) - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associateAuditor( + AssociateOrganizationAuditorRequest + .builder() + .auditorId(userId) + .organizationId( + organizationId) + .build()) + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -147,44 +143,50 @@ public void associateAuditorByUsername() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associateAuditorByUsername(AssociateOrganizationAuditorByUsernameRequest.builder() - .origin("uaa") - .organizationId(organizationId) - .username(this.username) - .build()) - .map(ResourceUtils::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associateAuditorByUsername( + AssociateOrganizationAuditorByUsernameRequest + .builder() + .origin("uaa") + .organizationId(organizationId) + .username(this.username) + .build()) + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void associateBillingManager() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associateBillingManager(AssociateOrganizationBillingManagerRequest.builder() - .billingManagerId(userId) - .organizationId(organizationId) - .build()) - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associateBillingManager( + AssociateOrganizationBillingManagerRequest + .builder() + .billingManagerId(userId) + .organizationId( + organizationId) + .build()) + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -192,43 +194,49 @@ public void associateBillingManagerByUsername() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associateBillingManagerByUsername(AssociateOrganizationBillingManagerByUsernameRequest.builder() - .organizationId(organizationId) - .username(this.username) - .build()) - .map(ResourceUtils::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associateBillingManagerByUsername( + AssociateOrganizationBillingManagerByUsernameRequest + .builder() + .organizationId(organizationId) + .username(this.username) + .build()) + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void associateManager() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associateManager(AssociateOrganizationManagerRequest.builder() - .managerId(userId) - .organizationId(organizationId) - .build()) - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associateManager( + AssociateOrganizationManagerRequest + .builder() + .managerId(userId) + .organizationId( + organizationId) + .build()) + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -236,19 +244,23 @@ public void associateManagerByUsername() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associateManagerByUsername(AssociateOrganizationManagerByUsernameRequest.builder() - .organizationId(organizationId) - .username(this.username) - .build()) - .map(ResourceUtils::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associateManagerByUsername( + AssociateOrganizationManagerByUsernameRequest + .builder() + .organizationId(organizationId) + .username(this.username) + .build()) + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -257,47 +269,60 @@ public void associatePrivateDomain() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, organizationId, domainName), - Mono.just(organizationId) - )) - .flatMap(function((privateDomainId, organizationId) -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associatePrivateDomain(AssociateOrganizationPrivateDomainRequest.builder() - .organizationId(organizationId) - .privateDomainId(privateDomainId) - .build()) - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + organizationId, + domainName), + Mono.just(organizationId))) + .flatMap( + function( + (privateDomainId, organizationId) -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associatePrivateDomain( + AssociateOrganizationPrivateDomainRequest + .builder() + .organizationId( + organizationId) + .privateDomainId( + privateDomainId) + .build()) + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void associateUser() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associateUser(AssociateOrganizationUserRequest.builder() - .userId(userId) - .organizationId(organizationId) - .build()) - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associateUser( + AssociateOrganizationUserRequest + .builder() + .userId(userId) + .organizationId( + organizationId) + .build()) + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -305,35 +330,38 @@ public void associateUserByUsername() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.organizations() - .associateUserByUsername(AssociateOrganizationUserByUsernameRequest.builder() - .organizationId(organizationId) - .username(this.username) - .build()) - .map(ResourceUtils::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .organizations() + .associateUserByUsername( + AssociateOrganizationUserByUsernameRequest + .builder() + .organizationId(organizationId) + .username(this.username) + .build()) + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void create() { String organizationName = this.nameFactory.getOrganizationName(); - this.cloudFoundryClient.organizations() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()) - .map(ResourceUtils::getEntity) - .map(OrganizationEntity::getName) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .organizations() + .create(CreateOrganizationRequest.builder().name(organizationName).build()) + .map(ResourceUtils::getEntity) + .map(OrganizationEntity::getName) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -341,16 +369,33 @@ public void delete() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> this.cloudFoundryClient.organizations() - .delete(DeleteOrganizationRequest.builder() - .organizationId(organizationId) - .async(true) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMap(organizationId -> requestGetOrganization(this.cloudFoundryClient, organizationId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-OrganizationNotFound\\([0-9]+\\): The organization could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + this.cloudFoundryClient + .organizations() + .delete( + DeleteOrganizationRequest.builder() + .organizationId(organizationId) + .async(true) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMap( + organizationId -> + requestGetOrganization(this.cloudFoundryClient, organizationId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-OrganizationNotFound\\([0-9]+\\): The" + + " organization could not be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -358,15 +403,27 @@ public void deleteAsyncFalse() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> this.cloudFoundryClient.organizations() - .delete(DeleteOrganizationRequest.builder() - .organizationId(organizationId) - .async(false) - .build())) - .flatMap(organizationId -> requestGetOrganization(this.cloudFoundryClient, organizationId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-OrganizationNotFound\\([0-9]+\\): The organization could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + this.cloudFoundryClient + .organizations() + .delete( + DeleteOrganizationRequest.builder() + .organizationId(organizationId) + .async(false) + .build())) + .flatMap( + organizationId -> + requestGetOrganization(this.cloudFoundryClient, organizationId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-OrganizationNotFound\\([0-9]+\\): The" + + " organization could not be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -374,16 +431,20 @@ public void get() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.organizations() - .get(GetOrganizationRequest.builder() - .organizationId(organizationId) - .build())) - .map(ResourceUtils::getEntity) - .map(OrganizationEntity::getName) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizations() + .get( + GetOrganizationRequest.builder() + .organizationId(organizationId) + .build())) + .map(ResourceUtils::getEntity) + .map(OrganizationEntity::getName) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -391,15 +452,19 @@ public void getInstanceUsage() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.organizations() - .getInstanceUsage(GetOrganizationInstanceUsageRequest.builder() - .organizationId(organizationId) - .build())) - .map(GetOrganizationInstanceUsageResponse::getInstanceUsage) - .as(StepVerifier::create) - .expectNext(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizations() + .getInstanceUsage( + GetOrganizationInstanceUsageRequest.builder() + .organizationId(organizationId) + .build())) + .map(GetOrganizationInstanceUsageResponse::getInstanceUsage) + .as(StepVerifier::create) + .expectNext(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -407,39 +472,55 @@ public void getMemoryUsage() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.organizations() - .getMemoryUsage(GetOrganizationMemoryUsageRequest.builder() - .organizationId(organizationId) - .build())) - .map(GetOrganizationMemoryUsageResponse::getMemoryUsageInMb) - .as(StepVerifier::create) - .expectNext(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizations() + .getMemoryUsage( + GetOrganizationMemoryUsageRequest.builder() + .organizationId(organizationId) + .build())) + .map(GetOrganizationMemoryUsageResponse::getMemoryUsageInMb) + .as(StepVerifier::create) + .expectNext(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getUserRoles() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .flatMap(function((organizationId, userId) -> requestAssociateUser(this.cloudFoundryClient, organizationId, userId) - .thenReturn(organizationId))) - .flatMapMany(organizationId -> PaginationUtils. - requestClientV2Resources(page -> this.cloudFoundryClient.organizations() - .getUserRoles(GetOrganizationUserRolesRequest.builder() - .organizationId(organizationId) - .page(page) - .build())) - .map(response -> ResourceUtils.getEntity(response).getUsername())) - .as(StepVerifier::create) - .expectNext(this.username) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .flatMap( + function( + (organizationId, userId) -> + requestAssociateUser( + this.cloudFoundryClient, + organizationId, + userId) + .thenReturn(organizationId))) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .organizations() + .getUserRoles( + GetOrganizationUserRolesRequest + .builder() + .organizationId( + organizationId) + .page(page) + .build())) + .map( + response -> + ResourceUtils.getEntity(response) + .getUsername())) + .as(StepVerifier::create) + .expectNext(this.username) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -447,35 +528,41 @@ public void list() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMapMany(organizationId -> requestListOrganizations(this.cloudFoundryClient) - .map(ResourceUtils::getId) - .filter(organizationId::equals)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + organizationId -> + requestListOrganizations(this.cloudFoundryClient) + .map(ResourceUtils::getId) + .filter(organizationId::equals)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listAuditors() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateAuditor(this.cloudFoundryClient, organizationId, userId))) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationAuditors(this.cloudFoundryClient, organizationId) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateAuditor( + this.cloudFoundryClient, organizationId, userId))) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationAuditors( + this.cloudFoundryClient, + organizationId) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -483,26 +570,40 @@ public void listAuditorsFilterByAuditedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateAuditor(this.cloudFoundryClient, organizationId1, userId), - requestAssociateAuditor(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationAuditors(this.cloudFoundryClient, organizationId1, builder -> builder.auditedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationAuditors( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .auditedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -511,32 +612,54 @@ public void listAuditorsFilterByAuditedSpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateAuditor(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceAuditor(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationAuditors(this.cloudFoundryClient, organizationId, builder -> builder.auditedSpaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceAuditor( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationAuditors( + this.cloudFoundryClient, + organizationId, + builder -> + builder.auditedSpaceId( + spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -544,26 +667,40 @@ public void listAuditorsFilterByBillingManagedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateAuditor(this.cloudFoundryClient, organizationId1, userId), - requestAssociateBillingManager(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationAuditors(this.cloudFoundryClient, organizationId1, builder -> builder.billingManagedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationAuditors( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .billingManagedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -571,26 +708,40 @@ public void listAuditorsFilterByManagedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateAuditor(this.cloudFoundryClient, organizationId1, userId), - requestAssociateManager(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationAuditors(this.cloudFoundryClient, organizationId1, builder -> builder.managedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateManager( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationAuditors( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .managedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -599,32 +750,54 @@ public void listAuditorsFilterByManagedSpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateAuditor(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationAuditors(this.cloudFoundryClient, organizationId, builder -> builder.managedSpaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationAuditors( + this.cloudFoundryClient, + organizationId, + builder -> + builder.managedSpaceId( + spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -633,54 +806,78 @@ public void listAuditorsFilterBySpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateAuditor(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationAuditors(this.cloudFoundryClient, organizationId, builder -> builder.spaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationAuditors( + this.cloudFoundryClient, + organizationId, + builder -> builder.spaceId(spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listBillingManagers() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateBillingManager(this.cloudFoundryClient, organizationId, userId))) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateBillingManager( + this.cloudFoundryClient, organizationId, userId))) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationBillingManagers( + this.cloudFoundryClient, + organizationId) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -688,26 +885,40 @@ public void listBillingManagersFilterByAuditedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateBillingManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateAuditor(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId1, builder -> builder.auditedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationBillingManagers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .auditedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -716,32 +927,54 @@ public void listBillingManagersFilterByAuditedSpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateBillingManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceAuditor(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId, builder -> builder.auditedSpaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceAuditor( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationBillingManagers( + this.cloudFoundryClient, + organizationId, + builder -> + builder.auditedSpaceId( + spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -749,26 +982,40 @@ public void listBillingManagersFilterByBillingManagedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateBillingManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateBillingManager(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId1, builder -> builder.billingManagedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationBillingManagers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .billingManagedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -776,26 +1023,40 @@ public void listBillingManagersFilterByManagedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateBillingManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateManager(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId1, builder -> builder.managedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateManager( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationBillingManagers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .managedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -804,32 +1065,54 @@ public void listBillingManagersFilterByManagedSpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateBillingManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId, builder -> builder.managedSpaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationBillingManagers( + this.cloudFoundryClient, + organizationId, + builder -> + builder.managedSpaceId( + spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -838,32 +1121,52 @@ public void listBillingManagersFilterBySpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateBillingManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId, builder -> builder.spaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationBillingManagers( + this.cloudFoundryClient, + organizationId, + builder -> builder.spaceId(spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("deprecation") @@ -873,19 +1176,32 @@ public void listDomains() { String privateDomainName = this.nameFactory.getDomainName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> createPrivateDomainId(this.cloudFoundryClient, organizationId, privateDomainName)) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.organizations() - .listDomains(ListOrganizationDomainsRequest.builder() - .organizationId(organizationId) - .page(page) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName())) - .filter(privateDomainName::equals) - .as(StepVerifier::create) - .expectNext(privateDomainName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, organizationId, privateDomainName)) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .organizations() + .listDomains( + ListOrganizationDomainsRequest + .builder() + .organizationId( + organizationId) + .page(page) + .build())) + .map( + response -> + ResourceUtils.getEntity(response) + .getName())) + .filter(privateDomainName::equals) + .as(StepVerifier::create) + .expectNext(privateDomainName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("deprecation") @@ -895,76 +1211,105 @@ public void listDomainsFilterByName() { String privateDomainName = this.nameFactory.getDomainName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> createPrivateDomainId(this.cloudFoundryClient, organizationId, privateDomainName)) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.organizations() - .listDomains(ListOrganizationDomainsRequest.builder() - .name(privateDomainName) - .organizationId(organizationId) - .page(page) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName())) - .as(StepVerifier::create) - .expectNext(privateDomainName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, organizationId, privateDomainName)) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .organizations() + .listDomains( + ListOrganizationDomainsRequest + .builder() + .name( + privateDomainName) + .organizationId( + organizationId) + .page(page) + .build())) + .map( + response -> + ResourceUtils.getEntity(response) + .getName())) + .as(StepVerifier::create) + .expectNext(privateDomainName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByAuditorId() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateAuditor(this.cloudFoundryClient, organizationId, userId))) - .flatMapMany(function((organizationId, auditorId) -> requestListOrganizations(this.cloudFoundryClient, builder -> builder.auditorId(auditorId)) - .map(ResourceUtils::getId) - .filter(organizationId::equals))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateAuditor( + this.cloudFoundryClient, organizationId, userId))) + .flatMapMany( + function( + (organizationId, auditorId) -> + requestListOrganizations( + this.cloudFoundryClient, + builder -> builder.auditorId(auditorId)) + .map(ResourceUtils::getId) + .filter(organizationId::equals))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByBillingManagerId() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateBillingManager(this.cloudFoundryClient, organizationId, userId))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizations(this.cloudFoundryClient, builder -> builder.billingManagerId(userId)) - .map(ResourceUtils::getId) - .filter(organizationId::equals))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateBillingManager( + this.cloudFoundryClient, organizationId, userId))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizations( + this.cloudFoundryClient, + builder -> builder.billingManagerId(userId)) + .map(ResourceUtils::getId) + .filter(organizationId::equals))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByManagerId() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateManager(this.cloudFoundryClient, organizationId, userId))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizations(this.cloudFoundryClient, builder -> builder.managerId(userId)) - .map(ResourceUtils::getId) - .filter(organizationId::equals))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateManager( + this.cloudFoundryClient, organizationId, userId))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizations( + this.cloudFoundryClient, + builder -> builder.managerId(userId)) + .map(ResourceUtils::getId) + .filter(organizationId::equals))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -972,11 +1317,13 @@ public void listFilterByName() { String organizationName = this.nameFactory.getOrganizationName(); requestCreateOrganization(this.cloudFoundryClient, organizationName) - .thenMany(requestListOrganizations(this.cloudFoundryClient, builder -> builder.name(organizationName))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + requestListOrganizations( + this.cloudFoundryClient, builder -> builder.name(organizationName))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -985,20 +1332,28 @@ public void listFilterBySpaceId() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - requestListOrganizations(this.cloudFoundryClient, builder -> builder.spaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + requestListOrganizations( + this.cloudFoundryClient, + builder -> builder.spaceId(spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1006,57 +1361,76 @@ public void listFilterByStatus() { String organizationName = this.nameFactory.getOrganizationName(); String organizationStatus = "suspended"; - requestCreateOrganization(this.cloudFoundryClient, organizationName, builder -> builder.status(organizationStatus)) - .map(ResourceUtils::getId) - .flatMapMany(organizationId -> requestListOrganizations(this.cloudFoundryClient, builder -> builder.status(organizationStatus)) - .filter(resource -> organizationId.equals(ResourceUtils.getId(resource))) - .map(ResourceUtils::getEntity) - .map(OrganizationEntity::getName)) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + requestCreateOrganization( + this.cloudFoundryClient, + organizationName, + builder -> builder.status(organizationStatus)) + .map(ResourceUtils::getId) + .flatMapMany( + organizationId -> + requestListOrganizations( + this.cloudFoundryClient, + builder -> builder.status(organizationStatus)) + .filter( + resource -> + organizationId.equals( + ResourceUtils.getId(resource))) + .map(ResourceUtils::getEntity) + .map(OrganizationEntity::getName)) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByUserId() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateUser(this.cloudFoundryClient, organizationId, userId))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizations(this.cloudFoundryClient, builder -> builder.userId(userId)) - .map(ResourceUtils::getId) - .filter(organizationId::equals))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateUser( + this.cloudFoundryClient, organizationId, userId))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizations( + this.cloudFoundryClient, + builder -> builder.userId(userId)) + .map(ResourceUtils::getId) + .filter(organizationId::equals))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listManagers() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateManager(this.cloudFoundryClient, organizationId, userId))) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationManagers(this.cloudFoundryClient, organizationId) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateManager( + this.cloudFoundryClient, organizationId, userId))) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationManagers( + this.cloudFoundryClient, + organizationId) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1064,26 +1438,40 @@ public void listManagersFilterByAuditedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateAuditor(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationManagers(this.cloudFoundryClient, organizationId1, builder -> builder.auditedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationManagers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .auditedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1092,32 +1480,54 @@ public void listManagersFilterByAuditedSpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceAuditor(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationManagers(this.cloudFoundryClient, organizationId, builder -> builder.auditedSpaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceAuditor( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationManagers( + this.cloudFoundryClient, + organizationId, + builder -> + builder.auditedSpaceId( + spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1125,26 +1535,40 @@ public void listManagersFilterByBillingManagedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateBillingManager(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationManagers(this.cloudFoundryClient, organizationId1, builder -> builder.billingManagedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationManagers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .billingManagedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1152,26 +1576,40 @@ public void listManagersFilterByManagedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateManager(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationManagers(this.cloudFoundryClient, organizationId1, builder -> builder.managedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateManager( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationManagers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .managedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1180,32 +1618,54 @@ public void listManagersFilterByManagedSpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationManagers(this.cloudFoundryClient, organizationId, builder -> builder.managedSpaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationManagers( + this.cloudFoundryClient, + organizationId, + builder -> + builder.managedSpaceId( + spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1214,32 +1674,52 @@ public void listManagersFilterBySpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateManager(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationManagers(this.cloudFoundryClient, organizationId, builder -> builder.spaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateManager( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationManagers( + this.cloudFoundryClient, + organizationId, + builder -> builder.spaceId(spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1248,26 +1728,39 @@ public void listPrivateDomains() { String defaultOrganizationName = this.nameFactory.getOrganizationName(); String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, defaultOrganizationName), - createOrganizationId(this.cloudFoundryClient, organizationName) - ) - .flatMap(function((defaultOrganizationId, organizationId) -> Mono.zip( - Mono.just(organizationId), - createPrivateDomainId(this.cloudFoundryClient, defaultOrganizationId, domainName) - ))) - .delayUntil(function((organizationId, privateDomainId) -> requestAssociatePrivateDomain(this.cloudFoundryClient, organizationId, privateDomainId))) - .flatMap(function((organizationId, privateDomainId) -> Mono.zip( - Mono.just(privateDomainId), - requestListOrganizationPrivateDomains(this.cloudFoundryClient, organizationId) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, defaultOrganizationName), + createOrganizationId(this.cloudFoundryClient, organizationName)) + .flatMap( + function( + (defaultOrganizationId, organizationId) -> + Mono.zip( + Mono.just(organizationId), + createPrivateDomainId( + this.cloudFoundryClient, + defaultOrganizationId, + domainName)))) + .delayUntil( + function( + (organizationId, privateDomainId) -> + requestAssociatePrivateDomain( + this.cloudFoundryClient, + organizationId, + privateDomainId))) + .flatMap( + function( + (organizationId, privateDomainId) -> + Mono.zip( + Mono.just(privateDomainId), + requestListOrganizationPrivateDomains( + this.cloudFoundryClient, + organizationId) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1276,74 +1769,119 @@ public void listPrivateDomainsFilterByName() { String privateDomainName = this.nameFactory.getDomainName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createPrivateDomainId(this.cloudFoundryClient, organizationId, privateDomainName) - )) - .flatMap(function((organizationId, privateDomainId) -> Mono.zip( - Mono.just(privateDomainId), - requestListOrganizationPrivateDomains(this.cloudFoundryClient, organizationId, builder -> builder.name(privateDomainName)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createPrivateDomainId( + this.cloudFoundryClient, + organizationId, + privateDomainName))) + .flatMap( + function( + (organizationId, privateDomainId) -> + Mono.zip( + Mono.just(privateDomainId), + requestListOrganizationPrivateDomains( + this.cloudFoundryClient, + organizationId, + builder -> + builder.name( + privateDomainName)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServices() { - Mono - .zip(this.organizationId, this.serviceBrokerId) - .flatMapMany(function((organizationId, serviceBrokerId) -> requestListOrganizationServices(this.cloudFoundryClient, organizationId) - .filter(resource -> serviceBrokerId.equals(ResourceUtils.getEntity(resource).getServiceBrokerId())))) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectNext(this.serviceName + "-shareable") - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.serviceBrokerId) + .flatMapMany( + function( + (organizationId, serviceBrokerId) -> + requestListOrganizationServices( + this.cloudFoundryClient, organizationId) + .filter( + resource -> + serviceBrokerId.equals( + ResourceUtils.getEntity( + resource) + .getServiceBrokerId())))) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectNext(this.serviceName + "-shareable") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServicesFilterByActive() { - Mono - .zip(this.organizationId, this.serviceBrokerId) - .flatMapMany(function((organizationId, serviceBrokerId) -> requestListOrganizationServices(this.cloudFoundryClient, organizationId, builder -> builder.active(true)) - .filter(resource -> serviceBrokerId.equals(ResourceUtils.getEntity(resource).getServiceBrokerId())))) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectNext(this.serviceName + "-shareable") - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.serviceBrokerId) + .flatMapMany( + function( + (organizationId, serviceBrokerId) -> + requestListOrganizationServices( + this.cloudFoundryClient, + organizationId, + builder -> builder.active(true)) + .filter( + resource -> + serviceBrokerId.equals( + ResourceUtils.getEntity( + resource) + .getServiceBrokerId())))) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectNext(this.serviceName + "-shareable") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServicesFilterByLabel() { - Mono - .zip(this.organizationId, this.serviceBrokerId) - .flatMapMany(function((organizationId, serviceBrokerId) -> requestListOrganizationServices(this.cloudFoundryClient, organizationId, builder -> builder.label(this.serviceName)) - .filter(resource -> serviceBrokerId.equals(ResourceUtils.getEntity(resource).getServiceBrokerId())))) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.serviceBrokerId) + .flatMapMany( + function( + (organizationId, serviceBrokerId) -> + requestListOrganizationServices( + this.cloudFoundryClient, + organizationId, + builder -> builder.label(this.serviceName)) + .filter( + resource -> + serviceBrokerId.equals( + ResourceUtils.getEntity( + resource) + .getServiceBrokerId())))) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServicesFilterByServiceBrokerId() { - Mono - .zip(this.organizationId, this.serviceBrokerId) - .flatMapMany(function((organizationId, serviceBrokerId) -> requestListOrganizationServices(this.cloudFoundryClient, organizationId, builder -> builder.serviceBrokerId(serviceBrokerId)))) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectNext(this.serviceName + "-shareable") - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.serviceBrokerId) + .flatMapMany( + function( + (organizationId, serviceBrokerId) -> + requestListOrganizationServices( + this.cloudFoundryClient, + organizationId, + builder -> + builder.serviceBrokerId(serviceBrokerId)))) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectNext(this.serviceName + "-shareable") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1351,15 +1889,22 @@ public void listSpaceQuotaDefinitions() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMapMany(organizationId -> PaginationUtils. - requestClientV2Resources(page -> this.cloudFoundryClient.organizations() - .listSpaceQuotaDefinitions(ListOrganizationSpaceQuotaDefinitionsRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .organizations() + .listSpaceQuotaDefinitions( + ListOrganizationSpaceQuotaDefinitionsRequest + .builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1368,12 +1913,18 @@ public void listSpaces() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateSpace(this.cloudFoundryClient, organizationId, spaceName)) - .flatMapMany(organizationId -> requestListOrganizationSpaces(this.cloudFoundryClient, organizationId)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateSpace( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMapMany( + organizationId -> + requestListOrganizationSpaces( + this.cloudFoundryClient, organizationId)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1383,25 +1934,41 @@ public void listSpacesFilterByApplicationId() { String applicationName = this.nameFactory.getApplicationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - ))) - .flatMapMany((function((organizationId, spaceId, applicationId) -> Mono.zip( - Mono.just(spaceId), - requestListOrganizationSpaces(this.cloudFoundryClient, organizationId, builder -> builder.applicationId(applicationId)) - .single() - .map(ResourceUtils::getId) - )))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName)))) + .flatMapMany( + (function( + (organizationId, spaceId, applicationId) -> + Mono.zip( + Mono.just(spaceId), + requestListOrganizationSpaces( + this.cloudFoundryClient, + organizationId, + builder -> + builder.applicationId( + applicationId)) + .single() + .map(ResourceUtils::getId))))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1409,28 +1976,43 @@ public void listSpacesFilterByDeveloperId() { String organizationName = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateUser(this.cloudFoundryClient, organizationId, userId))) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, spaceId, userId))) - .flatMapMany((function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(spaceId), - requestListOrganizationSpaces(this.cloudFoundryClient, organizationId, builder -> builder.developerId(userId)) - .single() - .map(ResourceUtils::getId) - )))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateUser( + this.cloudFoundryClient, organizationId, userId))) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, spaceId, userId))) + .flatMapMany( + (function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(spaceId), + requestListOrganizationSpaces( + this.cloudFoundryClient, + organizationId, + builder -> + builder.developerId(userId)) + .single() + .map(ResourceUtils::getId))))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1439,42 +2021,55 @@ public void listSpacesFilterByName() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMapMany((function((organizationId, spaceId) -> Mono.zip( - Mono.just(spaceId), - requestListOrganizationSpaces(this.cloudFoundryClient, organizationId, builder -> builder.name(spaceName)) - .single() - .map(ResourceUtils::getId) - )))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMapMany( + (function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(spaceId), + requestListOrganizationSpaces( + this.cloudFoundryClient, + organizationId, + builder -> builder.name(spaceName)) + .single() + .map(ResourceUtils::getId))))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listUsers() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateUser(this.cloudFoundryClient, organizationId, userId))) - .flatMap(function((organizationId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationUsers(this.cloudFoundryClient, organizationId) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateUser( + this.cloudFoundryClient, organizationId, userId))) + .flatMap( + function( + (organizationId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationUsers( + this.cloudFoundryClient, + organizationId) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1482,26 +2077,40 @@ public void listUsersFilterByAuditedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateUser(this.cloudFoundryClient, organizationId1, userId), - requestAssociateAuditor(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationUsers(this.cloudFoundryClient, organizationId1, builder -> builder.auditedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateUser( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateAuditor( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationUsers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .auditedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1510,32 +2119,54 @@ public void listUsersFilterByAuditedSpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateUser(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceAuditor(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationUsers(this.cloudFoundryClient, organizationId, builder -> builder.auditedSpaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateUser( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceAuditor( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationUsers( + this.cloudFoundryClient, + organizationId, + builder -> + builder.auditedSpaceId( + spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1543,26 +2174,40 @@ public void listUsersFilterByBillingManagedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateUser(this.cloudFoundryClient, organizationId1, userId), - requestAssociateBillingManager(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationUsers(this.cloudFoundryClient, organizationId1, builder -> builder.billingManagedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateUser( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateBillingManager( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationUsers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .billingManagedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1570,26 +2215,40 @@ public void listUsersFilterByManagedOrganizationId() { String organizationName1 = this.nameFactory.getOrganizationName(); String organizationName2 = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateUser(this.cloudFoundryClient, organizationId1, userId), - requestAssociateManager(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationUsers(this.cloudFoundryClient, organizationId1, builder -> builder.managedOrganizationId(organizationId2)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateUser( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateManager( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationUsers( + this.cloudFoundryClient, + organizationId1, + builder -> + builder + .managedOrganizationId( + organizationId2)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1598,32 +2257,54 @@ public void listUsersFilterByManagedSpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateUser(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationUsers(this.cloudFoundryClient, organizationId, builder -> builder.managedSpaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateUser( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationUsers( + this.cloudFoundryClient, + organizationId, + builder -> + builder.managedSpaceId( + spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1632,159 +2313,237 @@ public void listUsersFilterBySpaceId() { String organizationName2 = this.nameFactory.getOrganizationName(); String spaceName = this.nameFactory.getSpaceName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2), - this.userId - ) - .delayUntil(function((organizationId1, organizationId2, userId) -> Mono.zip( - requestAssociateUser(this.cloudFoundryClient, organizationId1, userId), - requestAssociateUser(this.cloudFoundryClient, organizationId2, userId) - ))) - .flatMap(function((organizationId1, organizationId2, userId) -> Mono.zip( - Mono.just(organizationId1), - createSpaceId(this.cloudFoundryClient, organizationId2, spaceName), - Mono.just(userId) - ))) - .delayUntil(function((organizationId, spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((organizationId, spaceId, userId) -> Mono.zip( - Mono.just(userId), - requestListOrganizationUsers(this.cloudFoundryClient, organizationId, builder -> builder.spaceId(spaceId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2), + this.userId) + .delayUntil( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + requestAssociateUser( + this.cloudFoundryClient, + organizationId1, + userId), + requestAssociateUser( + this.cloudFoundryClient, + organizationId2, + userId)))) + .flatMap( + function( + (organizationId1, organizationId2, userId) -> + Mono.zip( + Mono.just(organizationId1), + createSpaceId( + this.cloudFoundryClient, + organizationId2, + spaceName), + Mono.just(userId)))) + .delayUntil( + function( + (organizationId, spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (organizationId, spaceId, userId) -> + Mono.zip( + Mono.just(userId), + requestListOrganizationUsers( + this.cloudFoundryClient, + organizationId, + builder -> builder.spaceId(spaceId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void removeAuditor() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateAuditor(this.cloudFoundryClient, organizationId, userId))) - .delayUntil(function((organizationId, userId) -> this.cloudFoundryClient.organizations() - .removeAuditor(RemoveOrganizationAuditorRequest.builder() - .auditorId(userId) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizationAuditors(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateAuditor( + this.cloudFoundryClient, organizationId, userId))) + .delayUntil( + function( + (organizationId, userId) -> + this.cloudFoundryClient + .organizations() + .removeAuditor( + RemoveOrganizationAuditorRequest.builder() + .auditorId(userId) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizationAuditors( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void removeAuditorByUsername() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateAuditor(this.cloudFoundryClient, organizationId, userId))) - .delayUntil(function((organizationId, userId) -> this.cloudFoundryClient.organizations() - .removeAuditorByUsername(RemoveOrganizationAuditorByUsernameRequest.builder() - .username(this.username) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizationAuditors(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateAuditor( + this.cloudFoundryClient, organizationId, userId))) + .delayUntil( + function( + (organizationId, userId) -> + this.cloudFoundryClient + .organizations() + .removeAuditorByUsername( + RemoveOrganizationAuditorByUsernameRequest + .builder() + .username(this.username) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizationAuditors( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void removeBillingManager() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateBillingManager(this.cloudFoundryClient, organizationId, userId))) - .delayUntil(function((organizationId, userId) -> this.cloudFoundryClient.organizations() - .removeBillingManager(RemoveOrganizationBillingManagerRequest.builder() - .billingManagerId(userId) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateBillingManager( + this.cloudFoundryClient, organizationId, userId))) + .delayUntil( + function( + (organizationId, userId) -> + this.cloudFoundryClient + .organizations() + .removeBillingManager( + RemoveOrganizationBillingManagerRequest + .builder() + .billingManagerId(userId) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizationBillingManagers( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void removeBillingManagerByUsername() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateBillingManager(this.cloudFoundryClient, organizationId, userId))) - .delayUntil(function((organizationId, userId) -> this.cloudFoundryClient.organizations() - .removeBillingManagerByUsername(RemoveOrganizationBillingManagerByUsernameRequest.builder() - .origin("uaa") - .username(this.username) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizationBillingManagers(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateBillingManager( + this.cloudFoundryClient, organizationId, userId))) + .delayUntil( + function( + (organizationId, userId) -> + this.cloudFoundryClient + .organizations() + .removeBillingManagerByUsername( + RemoveOrganizationBillingManagerByUsernameRequest + .builder() + .origin("uaa") + .username(this.username) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizationBillingManagers( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void removeManager() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateManager(this.cloudFoundryClient, organizationId, userId))) - .delayUntil(function((organizationId, userId) -> this.cloudFoundryClient.organizations() - .removeManager(RemoveOrganizationManagerRequest.builder() - .managerId(userId) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizationManagers(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateManager( + this.cloudFoundryClient, organizationId, userId))) + .delayUntil( + function( + (organizationId, userId) -> + this.cloudFoundryClient + .organizations() + .removeManager( + RemoveOrganizationManagerRequest.builder() + .managerId(userId) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizationManagers( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void removeManagerByUsername() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateManager(this.cloudFoundryClient, organizationId, userId))) - .delayUntil(function((organizationId, userId) -> this.cloudFoundryClient.organizations() - .removeManagerByUsername(RemoveOrganizationManagerByUsernameRequest.builder() - .username(this.username) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizationManagers(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateManager( + this.cloudFoundryClient, organizationId, userId))) + .delayUntil( + function( + (organizationId, userId) -> + this.cloudFoundryClient + .organizations() + .removeManagerByUsername( + RemoveOrganizationManagerByUsernameRequest + .builder() + .username(this.username) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizationManagers( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1793,67 +2552,105 @@ public void removePrivateDomain() { String defaultOrganizationName = this.nameFactory.getOrganizationName(); String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, defaultOrganizationName), - createOrganizationId(this.cloudFoundryClient, organizationName) - ) - .flatMap(function((defaultOrganizationId, organizationId) -> Mono.zip( - Mono.just(organizationId), - createPrivateDomainId(this.cloudFoundryClient, defaultOrganizationId, domainName) - ))) - .delayUntil(function((organizationId, privateDomainId) -> requestAssociatePrivateDomain(this.cloudFoundryClient, organizationId, privateDomainId))) - .delayUntil(function((organizationId, privateDomainId) -> this.cloudFoundryClient.organizations() - .removePrivateDomain(RemoveOrganizationPrivateDomainRequest.builder() - .privateDomainId(privateDomainId) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, privateDomainId) -> requestListOrganizationPrivateDomains(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createOrganizationId(this.cloudFoundryClient, defaultOrganizationName), + createOrganizationId(this.cloudFoundryClient, organizationName)) + .flatMap( + function( + (defaultOrganizationId, organizationId) -> + Mono.zip( + Mono.just(organizationId), + createPrivateDomainId( + this.cloudFoundryClient, + defaultOrganizationId, + domainName)))) + .delayUntil( + function( + (organizationId, privateDomainId) -> + requestAssociatePrivateDomain( + this.cloudFoundryClient, + organizationId, + privateDomainId))) + .delayUntil( + function( + (organizationId, privateDomainId) -> + this.cloudFoundryClient + .organizations() + .removePrivateDomain( + RemoveOrganizationPrivateDomainRequest + .builder() + .privateDomainId(privateDomainId) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, privateDomainId) -> + requestListOrganizationPrivateDomains( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void removeUser() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateUser(this.cloudFoundryClient, organizationId, userId))) - .delayUntil(function((organizationId, userId) -> this.cloudFoundryClient.organizations() - .removeUser(RemoveOrganizationUserRequest.builder() - .userId(userId) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizationUsers(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateUser( + this.cloudFoundryClient, organizationId, userId))) + .delayUntil( + function( + (organizationId, userId) -> + this.cloudFoundryClient + .organizations() + .removeUser( + RemoveOrganizationUserRequest.builder() + .userId(userId) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizationUsers( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void removeUserByUsername() { String organizationName = this.nameFactory.getOrganizationName(); - Mono - .zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - this.userId - ) - .delayUntil(function((organizationId, userId) -> requestAssociateUser(this.cloudFoundryClient, organizationId, userId))) - .delayUntil(function((organizationId, userId) -> this.cloudFoundryClient.organizations() - .removeUserByUsername(RemoveOrganizationUserByUsernameRequest.builder() - .username(this.username) - .organizationId(organizationId) - .build()))) - .flatMapMany(function((organizationId, userId) -> requestListOrganizationUsers(this.cloudFoundryClient, organizationId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createOrganizationId(this.cloudFoundryClient, organizationName), this.userId) + .delayUntil( + function( + (organizationId, userId) -> + requestAssociateUser( + this.cloudFoundryClient, organizationId, userId))) + .delayUntil( + function( + (organizationId, userId) -> + this.cloudFoundryClient + .organizations() + .removeUserByUsername( + RemoveOrganizationUserByUsernameRequest + .builder() + .username(this.username) + .organizationId(organizationId) + .build()))) + .flatMapMany( + function( + (organizationId, userId) -> + requestListOrganizationUsers( + this.cloudFoundryClient, organizationId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1861,15 +2658,19 @@ public void summary() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.organizations() - .summary(SummaryOrganizationRequest.builder() - .organizationId(organizationId) - .build()) - .map(SummaryOrganizationResponse::getName)) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizations() + .summary( + SummaryOrganizationRequest.builder() + .organizationId(organizationId) + .build()) + .map(SummaryOrganizationResponse::getName)) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1878,275 +2679,393 @@ public void update() { String organizationName2 = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> this.cloudFoundryClient.organizations() - .update(UpdateOrganizationRequest.builder() - .organizationId(organizationId) - .name(organizationName2) - .build())) - .flatMap(organizationId -> requestGetOrganization(this.cloudFoundryClient, organizationId)) - .map(ResourceUtils::getEntity) - .map(OrganizationEntity::getName) - .as(StepVerifier::create) - .expectNext(organizationName2) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + .delayUntil( + organizationId -> + this.cloudFoundryClient + .organizations() + .update( + UpdateOrganizationRequest.builder() + .organizationId(organizationId) + .name(organizationName2) + .build())) + .flatMap( + organizationId -> + requestGetOrganization(this.cloudFoundryClient, organizationId)) + .map(ResourceUtils::getEntity) + .map(OrganizationEntity::getName) + .as(StepVerifier::create) + .expectNext(organizationName2) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createPrivateDomainId(CloudFoundryClient cloudFoundryClient, String organizationId, String domainName) { + private static Mono createPrivateDomainId( + CloudFoundryClient cloudFoundryClient, String organizationId, String domainName) { return requestCreatePrivateDomain(cloudFoundryClient, domainName, organizationId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getUserDefaultSpaceId(CloudFoundryClient cloudFoundryClient, String userId) { + private static Mono getUserDefaultSpaceId( + CloudFoundryClient cloudFoundryClient, String userId) { return requestListUsers(cloudFoundryClient) - .filter(resource -> userId.equals(ResourceUtils.getId(resource))) - .single() - .map(resource -> ResourceUtils.getEntity(resource).getDefaultSpaceId()); - } - - private static Mono requestAssociateAuditor(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateAuditor(AssociateOrganizationAuditorRequest.builder() - .auditorId(userId) - .organizationId(organizationId) - .build()); - } - - private static Mono requestAssociateBillingManager(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateBillingManager(AssociateOrganizationBillingManagerRequest.builder() - .billingManagerId(userId) - .organizationId(organizationId) - .build()); - } - - private static Mono requestAssociateManager(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateManager(AssociateOrganizationManagerRequest.builder() - .managerId(userId) - .organizationId(organizationId) - .build()); - } - - private static Mono requestAssociatePrivateDomain(CloudFoundryClient cloudFoundryClient, String organizationId, String privateDomainId) { - return cloudFoundryClient.organizations() - .associatePrivateDomain(AssociateOrganizationPrivateDomainRequest.builder() - .organizationId(organizationId) - .privateDomainId(privateDomainId) - .build()); - } - - private static Mono requestAssociateSpaceAuditor(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.spaces() - .associateAuditor(AssociateSpaceAuditorRequest.builder() - .spaceId(spaceId) - .auditorId(userId) - .build()); - } - - private static Mono requestAssociateSpaceDeveloper(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.spaces() - .associateDeveloper(AssociateSpaceDeveloperRequest.builder() - .spaceId(spaceId) - .developerId(userId) - .build()); - } - - private static Mono requestAssociateSpaceManager(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.spaces() - .associateManager(AssociateSpaceManagerRequest.builder() - .spaceId(spaceId) - .managerId(userId) - .build()); - } - - private static Mono requestAssociateUser(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateUser(AssociateOrganizationUserRequest.builder() - .userId(userId) - .organizationId(organizationId) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return requestCreateOrganization(cloudFoundryClient, organizationName, UnaryOperator.identity()); - } - - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName, - UnaryOperator transformer) { - return cloudFoundryClient.organizations() - .create(transformer.apply(CreateOrganizationRequest.builder()) - .name(organizationName) - .build()); - } - - private static Mono requestCreatePrivateDomain(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { - return cloudFoundryClient.privateDomains() - .create(CreatePrivateDomainRequest.builder() - .name(domainName) - .owningOrganizationId(organizationId) - .build()); - } - - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organizationId(organizationId) - .build()); - } - - private static Mono requestGetOrganization(CloudFoundryClient cloudFoundryClient, String organizationId) { - return cloudFoundryClient.organizations() - .get(GetOrganizationRequest.builder() - .organizationId(organizationId) - .build()); - } - - private static Flux requestListOrganizationAuditors(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListOrganizationAuditors(cloudFoundryClient, organizationId, UnaryOperator.identity()); - } - - private static Flux requestListOrganizationAuditors(CloudFoundryClient cloudFoundryClient, String organizationId, - UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.organizations() - .listAuditors(transformer.apply(ListOrganizationAuditorsRequest.builder()) - .page(page) - .organizationId(organizationId) - .build())); - } - - private static Flux requestListOrganizationBillingManagers(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListOrganizationBillingManagers(cloudFoundryClient, organizationId, UnaryOperator.identity()); - } - - private static Flux requestListOrganizationBillingManagers(CloudFoundryClient cloudFoundryClient, String organizationId, - UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.organizations() - .listBillingManagers(transformer.apply(ListOrganizationBillingManagersRequest.builder()) - .page(page) - .organizationId(organizationId) - .build())); - } - - private static Flux requestListOrganizationManagers(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListOrganizationManagers(cloudFoundryClient, organizationId, UnaryOperator.identity()); - } - - private static Flux requestListOrganizationManagers(CloudFoundryClient cloudFoundryClient, String organizationId, - UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.organizations() - .listManagers(transformer.apply(ListOrganizationManagersRequest.builder()) - .page(page) - .organizationId(organizationId) - .build())); - } - - private static Flux requestListOrganizationPrivateDomains(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListOrganizationPrivateDomains(cloudFoundryClient, organizationId, UnaryOperator.identity()); - } - - private static Flux requestListOrganizationPrivateDomains(CloudFoundryClient cloudFoundryClient, String organizationId, - UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.organizations() - .listPrivateDomains(transformer.apply(ListOrganizationPrivateDomainsRequest.builder()) - .page(page) - .organizationId(organizationId) - .build())); - } - - private static Flux requestListOrganizationServices(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListOrganizationServices(cloudFoundryClient, organizationId, UnaryOperator.identity()); - } - - private static Flux requestListOrganizationServices(CloudFoundryClient cloudFoundryClient, String organizationId, - UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.organizations() - .listServices(transformer.apply(ListOrganizationServicesRequest.builder()) - .organizationId(organizationId) - .page(page) - .build())); - } - - private static Flux requestListOrganizationSpaces(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListOrganizationSpaces(cloudFoundryClient, organizationId, UnaryOperator.identity()); - } - - private static Flux requestListOrganizationSpaces(CloudFoundryClient cloudFoundryClient, String organizationId, UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.organizations() - .listSpaces(transformer.apply(ListOrganizationSpacesRequest.builder()) - .organizationId(organizationId) - .page(page) - .build())); - } - - private static Flux requestListOrganizationUsers(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListOrganizationUsers(cloudFoundryClient, organizationId, UnaryOperator.identity()); - } - - private static Flux requestListOrganizationUsers(CloudFoundryClient cloudFoundryClient, String organizationId, UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.organizations() - .listUsers(transformer.apply(ListOrganizationUsersRequest.builder()) - .page(page) - .organizationId(organizationId) - .build())); - } - - private static Flux requestListOrganizations(CloudFoundryClient cloudFoundryClient) { + .filter(resource -> userId.equals(ResourceUtils.getId(resource))) + .single() + .map(resource -> ResourceUtils.getEntity(resource).getDefaultSpaceId()); + } + + private static Mono requestAssociateAuditor( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateAuditor( + AssociateOrganizationAuditorRequest.builder() + .auditorId(userId) + .organizationId(organizationId) + .build()); + } + + private static Mono requestAssociateBillingManager( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateBillingManager( + AssociateOrganizationBillingManagerRequest.builder() + .billingManagerId(userId) + .organizationId(organizationId) + .build()); + } + + private static Mono requestAssociateManager( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateManager( + AssociateOrganizationManagerRequest.builder() + .managerId(userId) + .organizationId(organizationId) + .build()); + } + + private static Mono requestAssociatePrivateDomain( + CloudFoundryClient cloudFoundryClient, String organizationId, String privateDomainId) { + return cloudFoundryClient + .organizations() + .associatePrivateDomain( + AssociateOrganizationPrivateDomainRequest.builder() + .organizationId(organizationId) + .privateDomainId(privateDomainId) + .build()); + } + + private static Mono requestAssociateSpaceAuditor( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .spaces() + .associateAuditor( + AssociateSpaceAuditorRequest.builder() + .spaceId(spaceId) + .auditorId(userId) + .build()); + } + + private static Mono requestAssociateSpaceDeveloper( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .spaces() + .associateDeveloper( + AssociateSpaceDeveloperRequest.builder() + .spaceId(spaceId) + .developerId(userId) + .build()); + } + + private static Mono requestAssociateSpaceManager( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .spaces() + .associateManager( + AssociateSpaceManagerRequest.builder() + .spaceId(spaceId) + .managerId(userId) + .build()); + } + + private static Mono requestAssociateUser( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateUser( + AssociateOrganizationUserRequest.builder() + .userId(userId) + .organizationId(organizationId) + .build()); + } + + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return requestCreateOrganization( + cloudFoundryClient, organizationName, UnaryOperator.identity()); + } + + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, + String organizationName, + UnaryOperator transformer) { + return cloudFoundryClient + .organizations() + .create( + transformer + .apply(CreateOrganizationRequest.builder()) + .name(organizationName) + .build()); + } + + private static Mono requestCreatePrivateDomain( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + return cloudFoundryClient + .privateDomains() + .create( + CreatePrivateDomainRequest.builder() + .name(domainName) + .owningOrganizationId(organizationId) + .build()); + } + + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organizationId(organizationId) + .build()); + } + + private static Mono requestGetOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return cloudFoundryClient + .organizations() + .get(GetOrganizationRequest.builder().organizationId(organizationId).build()); + } + + private static Flux requestListOrganizationAuditors( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListOrganizationAuditors( + cloudFoundryClient, organizationId, UnaryOperator.identity()); + } + + private static Flux requestListOrganizationAuditors( + CloudFoundryClient cloudFoundryClient, + String organizationId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .listAuditors( + transformer + .apply(ListOrganizationAuditorsRequest.builder()) + .page(page) + .organizationId(organizationId) + .build())); + } + + private static Flux requestListOrganizationBillingManagers( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListOrganizationBillingManagers( + cloudFoundryClient, organizationId, UnaryOperator.identity()); + } + + private static Flux requestListOrganizationBillingManagers( + CloudFoundryClient cloudFoundryClient, + String organizationId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .listBillingManagers( + transformer + .apply( + ListOrganizationBillingManagersRequest + .builder()) + .page(page) + .organizationId(organizationId) + .build())); + } + + private static Flux requestListOrganizationManagers( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListOrganizationManagers( + cloudFoundryClient, organizationId, UnaryOperator.identity()); + } + + private static Flux requestListOrganizationManagers( + CloudFoundryClient cloudFoundryClient, + String organizationId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .listManagers( + transformer + .apply(ListOrganizationManagersRequest.builder()) + .page(page) + .organizationId(organizationId) + .build())); + } + + private static Flux requestListOrganizationPrivateDomains( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListOrganizationPrivateDomains( + cloudFoundryClient, organizationId, UnaryOperator.identity()); + } + + private static Flux requestListOrganizationPrivateDomains( + CloudFoundryClient cloudFoundryClient, + String organizationId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .listPrivateDomains( + transformer + .apply( + ListOrganizationPrivateDomainsRequest + .builder()) + .page(page) + .organizationId(organizationId) + .build())); + } + + private static Flux requestListOrganizationServices( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListOrganizationServices( + cloudFoundryClient, organizationId, UnaryOperator.identity()); + } + + private static Flux requestListOrganizationServices( + CloudFoundryClient cloudFoundryClient, + String organizationId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .listServices( + transformer + .apply(ListOrganizationServicesRequest.builder()) + .organizationId(organizationId) + .page(page) + .build())); + } + + private static Flux requestListOrganizationSpaces( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListOrganizationSpaces( + cloudFoundryClient, organizationId, UnaryOperator.identity()); + } + + private static Flux requestListOrganizationSpaces( + CloudFoundryClient cloudFoundryClient, + String organizationId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .listSpaces( + transformer + .apply(ListOrganizationSpacesRequest.builder()) + .organizationId(organizationId) + .page(page) + .build())); + } + + private static Flux requestListOrganizationUsers( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListOrganizationUsers( + cloudFoundryClient, organizationId, UnaryOperator.identity()); + } + + private static Flux requestListOrganizationUsers( + CloudFoundryClient cloudFoundryClient, + String organizationId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .listUsers( + transformer + .apply(ListOrganizationUsersRequest.builder()) + .page(page) + .organizationId(organizationId) + .build())); + } + + private static Flux requestListOrganizations( + CloudFoundryClient cloudFoundryClient) { return requestListOrganizations(cloudFoundryClient, UnaryOperator.identity()); } - private static Flux requestListOrganizations(CloudFoundryClient cloudFoundryClient, UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.organizations() - .list(transformer.apply(ListOrganizationsRequest.builder()) - .page(page) - .build())); + private static Flux requestListOrganizations( + CloudFoundryClient cloudFoundryClient, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .list( + transformer + .apply(ListOrganizationsRequest.builder()) + .page(page) + .build())); } - private static Flux requestListServices(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .build())); + private static Flux requestListServices( + CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV2Resources( + page -> cloudFoundryClient.services().list(ListServicesRequest.builder().build())); } private static Flux requestListUsers(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.users() - .list(ListUsersRequest.builder() - .page(page) - .build())); + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .users() + .list(ListUsersRequest.builder().page(page).build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/PrivateDomainsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/PrivateDomainsTest.java index d1fd29709d1..587cfa35aea 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/PrivateDomainsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/PrivateDomainsTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.function.Consumer; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.organizations.AssociateOrganizationAuditorRequest; @@ -44,43 +50,38 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuple2; -import java.time.Duration; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class PrivateDomainsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono userId; + @Autowired private Mono userId; @Test public void create() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - requestCreatePrivateDomain(this.cloudFoundryClient, privateDomainName, organizationId), - Mono.just(organizationId) - )) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(privateDomainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + requestCreatePrivateDomain( + this.cloudFoundryClient, + privateDomainName, + organizationId), + Mono.just(organizationId))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(privateDomainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -88,13 +89,35 @@ public void delete() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> requestCreatePrivateDomain(this.cloudFoundryClient, privateDomainName, organizationId)) - .delayUntil(privateDomainResource -> requestDeletePrivateDomain(this.cloudFoundryClient, ResourceUtils.getId(privateDomainResource)) - .flatMap(jobResource -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), jobResource))) - .flatMap(privateDomainResource -> requestGetPrivateDomain(this.cloudFoundryClient, ResourceUtils.getId(privateDomainResource))) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-DomainNotFound\\([0-9]+\\): The domain could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreatePrivateDomain( + this.cloudFoundryClient, privateDomainName, organizationId)) + .delayUntil( + privateDomainResource -> + requestDeletePrivateDomain( + this.cloudFoundryClient, + ResourceUtils.getId(privateDomainResource)) + .flatMap( + jobResource -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + jobResource))) + .flatMap( + privateDomainResource -> + requestGetPrivateDomain( + this.cloudFoundryClient, + ResourceUtils.getId(privateDomainResource))) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-DomainNotFound\\([0-9]+\\): The domain could" + + " not be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -102,18 +125,26 @@ public void get() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - requestCreatePrivateDomain(this.cloudFoundryClient, privateDomainName, organizationId) - )) - .flatMap(function((organizationId, privateDomainResource) -> Mono.zip( - requestGetPrivateDomain(this.cloudFoundryClient, ResourceUtils.getId(privateDomainResource)), - Mono.just(organizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(privateDomainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + requestCreatePrivateDomain( + this.cloudFoundryClient, + privateDomainName, + organizationId))) + .flatMap( + function( + (organizationId, privateDomainResource) -> + Mono.zip( + requestGetPrivateDomain( + this.cloudFoundryClient, + ResourceUtils.getId(privateDomainResource)), + Mono.just(organizationId)))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(privateDomainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -121,20 +152,33 @@ public void list() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - requestCreatePrivateDomain(this.cloudFoundryClient, privateDomainName, organizationId) - )) - .flatMap(function((organizationId, privateDomainResource) -> Mono.zip( - listPrivateDomains(this.cloudFoundryClient) - .filter(resource -> ResourceUtils.getId(privateDomainResource).equals(ResourceUtils.getId(resource))) - .single(), - Mono.just(organizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(privateDomainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + requestCreatePrivateDomain( + this.cloudFoundryClient, + privateDomainName, + organizationId))) + .flatMap( + function( + (organizationId, privateDomainResource) -> + Mono.zip( + listPrivateDomains(this.cloudFoundryClient) + .filter( + resource -> + ResourceUtils.getId( + privateDomainResource) + .equals( + ResourceUtils + .getId( + resource))) + .single(), + Mono.just(organizationId)))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(privateDomainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -142,20 +186,35 @@ public void listFilterByName() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - requestCreatePrivateDomain(this.cloudFoundryClient, privateDomainName, organizationId) - )) - .flatMap(function((organizationId, privateDomainResource) -> Mono.zip( - listPrivateDomains(this.cloudFoundryClient, privateDomainName) - .filter(resource -> ResourceUtils.getId(privateDomainResource).equals(ResourceUtils.getId(resource))) - .single(), - Mono.just(organizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(domainNameAndOrganizationIdEquality(privateDomainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + requestCreatePrivateDomain( + this.cloudFoundryClient, + privateDomainName, + organizationId))) + .flatMap( + function( + (organizationId, privateDomainResource) -> + Mono.zip( + listPrivateDomains( + this.cloudFoundryClient, + privateDomainName) + .filter( + resource -> + ResourceUtils.getId( + privateDomainResource) + .equals( + ResourceUtils + .getId( + resource))) + .single(), + Mono.just(organizationId)))) + .as(StepVerifier::create) + .consumeNextWith(domainNameAndOrganizationIdEquality(privateDomainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -164,24 +223,41 @@ public void listSharedOrganizations() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, privateDomainName, organizationId), - createOrganizationId(this.cloudFoundryClient, sharedOrganizationName) - )) - .flatMap(function((domainId, organizationId) -> requestAssociateOrganizationPrivateDomain(this.cloudFoundryClient, domainId, organizationId) - .thenReturn(domainId))) - .flatMapMany(domainId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.privateDomains() - .listSharedOrganizations(ListPrivateDomainSharedOrganizationsRequest.builder() - .page(page) - .privateDomainId(domainId) - .build()))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .filter(sharedOrganizationName::equals) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + privateDomainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, sharedOrganizationName))) + .flatMap( + function( + (domainId, organizationId) -> + requestAssociateOrganizationPrivateDomain( + this.cloudFoundryClient, + domainId, + organizationId) + .thenReturn(domainId))) + .flatMapMany( + domainId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .privateDomains() + .listSharedOrganizations( + ListPrivateDomainSharedOrganizationsRequest + .builder() + .page(page) + .privateDomainId(domainId) + .build()))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .filter(sharedOrganizationName::equals) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -190,29 +266,50 @@ public void listSharedOrganizationsFilterByAuditorId() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, privateDomainName, organizationId), - createOrganizationId(this.cloudFoundryClient, sharedOrganizationName), - this.userId - )) - .flatMap(function((domainId, organizationId, userId) -> Mono.zip( - requestAssociateOrganizationPrivateDomain(this.cloudFoundryClient, domainId, organizationId) - .thenReturn(domainId), - requestAssociateOrganizationAuditor(this.cloudFoundryClient, organizationId, userId) - .thenReturn(userId) - ))) - .flatMapMany(function((domainId, userId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.privateDomains() - .listSharedOrganizations(ListPrivateDomainSharedOrganizationsRequest.builder() - .auditorId(userId) - .page(page) - .privateDomainId(domainId) - .build())))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(sharedOrganizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + privateDomainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, sharedOrganizationName), + this.userId)) + .flatMap( + function( + (domainId, organizationId, userId) -> + Mono.zip( + requestAssociateOrganizationPrivateDomain( + this.cloudFoundryClient, + domainId, + organizationId) + .thenReturn(domainId), + requestAssociateOrganizationAuditor( + this.cloudFoundryClient, + organizationId, + userId) + .thenReturn(userId)))) + .flatMapMany( + function( + (domainId, userId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .privateDomains() + .listSharedOrganizations( + ListPrivateDomainSharedOrganizationsRequest + .builder() + .auditorId(userId) + .page(page) + .privateDomainId( + domainId) + .build())))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(sharedOrganizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -221,29 +318,51 @@ public void listSharedOrganizationsFilterByBillingManagerId() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, privateDomainName, organizationId), - createOrganizationId(this.cloudFoundryClient, sharedOrganizationName), - this.userId - )) - .flatMap(function((domainId, organizationId, userId) -> Mono.zip( - requestAssociateOrganizationPrivateDomain(this.cloudFoundryClient, domainId, organizationId) - .thenReturn(domainId), - requestAssociateOrganizationBillingManager(this.cloudFoundryClient, organizationId, userId) - .thenReturn(userId) - ))) - .flatMapMany(function((domainId, userId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.privateDomains() - .listSharedOrganizations(ListPrivateDomainSharedOrganizationsRequest.builder() - .billingManagerId(userId) - .page(page) - .privateDomainId(domainId) - .build())))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(sharedOrganizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + privateDomainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, sharedOrganizationName), + this.userId)) + .flatMap( + function( + (domainId, organizationId, userId) -> + Mono.zip( + requestAssociateOrganizationPrivateDomain( + this.cloudFoundryClient, + domainId, + organizationId) + .thenReturn(domainId), + requestAssociateOrganizationBillingManager( + this.cloudFoundryClient, + organizationId, + userId) + .thenReturn(userId)))) + .flatMapMany( + function( + (domainId, userId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .privateDomains() + .listSharedOrganizations( + ListPrivateDomainSharedOrganizationsRequest + .builder() + .billingManagerId( + userId) + .page(page) + .privateDomainId( + domainId) + .build())))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(sharedOrganizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -252,29 +371,50 @@ public void listSharedOrganizationsFilterByManagerId() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, privateDomainName, organizationId), - createOrganizationId(this.cloudFoundryClient, sharedOrganizationName), - this.userId - )) - .flatMap(function((domainId, organizationId, userId) -> Mono.zip( - requestAssociateOrganizationPrivateDomain(this.cloudFoundryClient, domainId, organizationId) - .thenReturn(domainId), - requestAssociateOrganizationManager(this.cloudFoundryClient, organizationId, userId) - .thenReturn(userId) - ))) - .flatMapMany(function((domainId, userId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.privateDomains() - .listSharedOrganizations(ListPrivateDomainSharedOrganizationsRequest.builder() - .managerId(userId) - .page(page) - .privateDomainId(domainId) - .build())))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(sharedOrganizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + privateDomainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, sharedOrganizationName), + this.userId)) + .flatMap( + function( + (domainId, organizationId, userId) -> + Mono.zip( + requestAssociateOrganizationPrivateDomain( + this.cloudFoundryClient, + domainId, + organizationId) + .thenReturn(domainId), + requestAssociateOrganizationManager( + this.cloudFoundryClient, + organizationId, + userId) + .thenReturn(userId)))) + .flatMapMany( + function( + (domainId, userId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .privateDomains() + .listSharedOrganizations( + ListPrivateDomainSharedOrganizationsRequest + .builder() + .managerId(userId) + .page(page) + .privateDomainId( + domainId) + .build())))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(sharedOrganizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -283,24 +423,42 @@ public void listSharedOrganizationsFilterByName() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, privateDomainName, organizationId), - createOrganizationId(this.cloudFoundryClient, sharedOrganizationName) - )) - .flatMap(function((domainId, organizationId) -> requestAssociateOrganizationPrivateDomain(this.cloudFoundryClient, domainId, organizationId) - .thenReturn(domainId))) - .flatMapMany(domainId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.privateDomains() - .listSharedOrganizations(ListPrivateDomainSharedOrganizationsRequest.builder() - .name(sharedOrganizationName) - .page(page) - .privateDomainId(domainId) - .build()))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(sharedOrganizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + privateDomainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, sharedOrganizationName))) + .flatMap( + function( + (domainId, organizationId) -> + requestAssociateOrganizationPrivateDomain( + this.cloudFoundryClient, + domainId, + organizationId) + .thenReturn(domainId))) + .flatMapMany( + domainId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .privateDomains() + .listSharedOrganizations( + ListPrivateDomainSharedOrganizationsRequest + .builder() + .name( + sharedOrganizationName) + .page(page) + .privateDomainId(domainId) + .build()))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(sharedOrganizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -310,27 +468,48 @@ public void listSharedOrganizationsFilterBySpaceId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, privateDomainName, organizationId), - createOrganizationId(this.cloudFoundryClient, sharedOrganizationName) - )) - .flatMap(function((domainId, organizationId) -> Mono.zip( - requestAssociateOrganizationPrivateDomain(this.cloudFoundryClient, domainId, organizationId) - .thenReturn(domainId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - ))) - .flatMapMany(function((domainId, spaceId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.privateDomains() - .listSharedOrganizations(ListPrivateDomainSharedOrganizationsRequest.builder() - .page(page) - .privateDomainId(domainId) - .spaceId(spaceId) - .build())))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(sharedOrganizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + privateDomainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, sharedOrganizationName))) + .flatMap( + function( + (domainId, organizationId) -> + Mono.zip( + requestAssociateOrganizationPrivateDomain( + this.cloudFoundryClient, + domainId, + organizationId) + .thenReturn(domainId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName)))) + .flatMapMany( + function( + (domainId, spaceId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .privateDomains() + .listSharedOrganizations( + ListPrivateDomainSharedOrganizationsRequest + .builder() + .page(page) + .privateDomainId( + domainId) + .spaceId(spaceId) + .build())))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(sharedOrganizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -339,24 +518,41 @@ public void listSharedOrganizationsFilterByStatus() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, privateDomainName, organizationId), - createOrganizationId(this.cloudFoundryClient, sharedOrganizationName) - )) - .flatMap(function((domainId, organizationId) -> requestAssociateOrganizationPrivateDomain(this.cloudFoundryClient, domainId, organizationId) - .thenReturn(domainId))) - .flatMapMany(domainId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.privateDomains() - .listSharedOrganizations(ListPrivateDomainSharedOrganizationsRequest.builder() - .page(page) - .privateDomainId(domainId) - .status("active") - .build()))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(sharedOrganizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + privateDomainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, sharedOrganizationName))) + .flatMap( + function( + (domainId, organizationId) -> + requestAssociateOrganizationPrivateDomain( + this.cloudFoundryClient, + domainId, + organizationId) + .thenReturn(domainId))) + .flatMapMany( + domainId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .privateDomains() + .listSharedOrganizations( + ListPrivateDomainSharedOrganizationsRequest + .builder() + .page(page) + .privateDomainId(domainId) + .status("active") + .build()))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(sharedOrganizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -365,143 +561,201 @@ public void listSharedOrganizationsFilterByUserId() { String privateDomainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, privateDomainName, organizationId), - createOrganizationId(this.cloudFoundryClient, sharedOrganizationName), - this.userId - )) - .flatMap(function((domainId, organizationId, userId) -> Mono.zip( - requestAssociateOrganizationPrivateDomain(this.cloudFoundryClient, domainId, organizationId) - .thenReturn(domainId), - requestAssociateOrganizationUser(this.cloudFoundryClient, organizationId, userId) - .thenReturn(userId) - ))) - .flatMapMany(function((domainId, userId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.privateDomains() - .listSharedOrganizations(ListPrivateDomainSharedOrganizationsRequest.builder() - .page(page) - .privateDomainId(domainId) - .userId(userId) - .build())))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(sharedOrganizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + privateDomainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, sharedOrganizationName), + this.userId)) + .flatMap( + function( + (domainId, organizationId, userId) -> + Mono.zip( + requestAssociateOrganizationPrivateDomain( + this.cloudFoundryClient, + domainId, + organizationId) + .thenReturn(domainId), + requestAssociateOrganizationUser( + this.cloudFoundryClient, + organizationId, + userId) + .thenReturn(userId)))) + .flatMapMany( + function( + (domainId, userId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .privateDomains() + .listSharedOrganizations( + ListPrivateDomainSharedOrganizationsRequest + .builder() + .page(page) + .privateDomainId( + domainId) + .userId(userId) + .build())))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(sharedOrganizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createPrivateDomainId(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + private static Mono createPrivateDomainId( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { return requestCreatePrivateDomain(cloudFoundryClient, domainName, organizationId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .organizationId(organizationId) - .name(spaceName) - .build()) - .map(ResourceUtils::getId); + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .organizationId(organizationId) + .name(spaceName) + .build()) + .map(ResourceUtils::getId); } - private static Consumer> domainNameAndOrganizationIdEquality(String domainName) { - return consumer((resource, organizationId) -> { - assertThat(ResourceUtils.getEntity(resource).getName()).isEqualTo(domainName); - assertThat(ResourceUtils.getEntity(resource).getOwningOrganizationId()).isEqualTo(organizationId); - }); + private static + Consumer> domainNameAndOrganizationIdEquality(String domainName) { + return consumer( + (resource, organizationId) -> { + assertThat(ResourceUtils.getEntity(resource).getName()).isEqualTo(domainName); + assertThat(ResourceUtils.getEntity(resource).getOwningOrganizationId()) + .isEqualTo(organizationId); + }); } - private static Flux listPrivateDomains(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.privateDomains() - .list(ListPrivateDomainsRequest.builder() - .page(page) - .build())); + private static Flux listPrivateDomains( + CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .privateDomains() + .list(ListPrivateDomainsRequest.builder().page(page).build())); } - private static Flux listPrivateDomains(CloudFoundryClient cloudFoundryClient, String privateDomainName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.privateDomains() - .list(ListPrivateDomainsRequest.builder() - .page(page) - .name(privateDomainName) - .build())); + private static Flux listPrivateDomains( + CloudFoundryClient cloudFoundryClient, String privateDomainName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .privateDomains() + .list( + ListPrivateDomainsRequest.builder() + .page(page) + .name(privateDomainName) + .build())); } - private static Mono requestAssociateOrganizationAuditor(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateAuditor(AssociateOrganizationAuditorRequest.builder() - .auditorId(userId) - .organizationId(organizationId) - .build()); + private static Mono requestAssociateOrganizationAuditor( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateAuditor( + AssociateOrganizationAuditorRequest.builder() + .auditorId(userId) + .organizationId(organizationId) + .build()); } - private static Mono requestAssociateOrganizationBillingManager(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateBillingManager(AssociateOrganizationBillingManagerRequest.builder() - .billingManagerId(userId) - .organizationId(organizationId) - .build()); + private static Mono + requestAssociateOrganizationBillingManager( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateBillingManager( + AssociateOrganizationBillingManagerRequest.builder() + .billingManagerId(userId) + .organizationId(organizationId) + .build()); } - private static Mono requestAssociateOrganizationManager(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateManager(AssociateOrganizationManagerRequest.builder() - .managerId(userId) - .organizationId(organizationId) - .build()); + private static Mono requestAssociateOrganizationManager( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateManager( + AssociateOrganizationManagerRequest.builder() + .managerId(userId) + .organizationId(organizationId) + .build()); } - private static Mono requestAssociateOrganizationPrivateDomain(CloudFoundryClient cloudFoundryClient, String domainId, String organizationId) { - return cloudFoundryClient.organizations() - .associatePrivateDomain(AssociateOrganizationPrivateDomainRequest.builder() - .organizationId(organizationId) - .privateDomainId(domainId) - .build()); + private static Mono + requestAssociateOrganizationPrivateDomain( + CloudFoundryClient cloudFoundryClient, String domainId, String organizationId) { + return cloudFoundryClient + .organizations() + .associatePrivateDomain( + AssociateOrganizationPrivateDomainRequest.builder() + .organizationId(organizationId) + .privateDomainId(domainId) + .build()); } - private static Mono requestAssociateOrganizationUser(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateUser(AssociateOrganizationUserRequest.builder() - .organizationId(organizationId) - .userId(userId) - .build()); + private static Mono requestAssociateOrganizationUser( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateUser( + AssociateOrganizationUserRequest.builder() + .organizationId(organizationId) + .userId(userId) + .build()); } - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizations() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .status("active") - .build()); + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizations() + .create( + CreateOrganizationRequest.builder() + .name(organizationName) + .status("active") + .build()); } - private static Mono requestCreatePrivateDomain(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { - return cloudFoundryClient.privateDomains() - .create(CreatePrivateDomainRequest.builder() - .name(domainName) - .owningOrganizationId(organizationId) - .build()); + private static Mono requestCreatePrivateDomain( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + return cloudFoundryClient + .privateDomains() + .create( + CreatePrivateDomainRequest.builder() + .name(domainName) + .owningOrganizationId(organizationId) + .build()); } - private static Mono requestDeletePrivateDomain(CloudFoundryClient cloudFoundryClient, String privateDomainId) { - return cloudFoundryClient.privateDomains() - .delete(DeletePrivateDomainRequest.builder() - .privateDomainId(privateDomainId) - .build()); + private static Mono requestDeletePrivateDomain( + CloudFoundryClient cloudFoundryClient, String privateDomainId) { + return cloudFoundryClient + .privateDomains() + .delete( + DeletePrivateDomainRequest.builder() + .privateDomainId(privateDomainId) + .build()); } - private static Mono requestGetPrivateDomain(CloudFoundryClient cloudFoundryClient, String privateDomainId) { - return cloudFoundryClient.privateDomains() - .get(GetPrivateDomainRequest.builder() - .privateDomainId(privateDomainId) - .build()); + private static Mono requestGetPrivateDomain( + CloudFoundryClient cloudFoundryClient, String privateDomainId) { + return cloudFoundryClient + .privateDomains() + .get(GetPrivateDomainRequest.builder().privateDomainId(privateDomainId).build()); } - } - diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/RouteMappingsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/RouteMappingsTest.java index d56a526afa2..1056e983040 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/RouteMappingsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/RouteMappingsTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; @@ -33,23 +38,16 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class RouteMappingsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void createSharedDomain() { @@ -57,32 +55,44 @@ public void createSharedDomain() { String domainName = this.nameFactory.getDomainName(); String hostName = this.nameFactory.getHostName(); - Mono - .zip( - getSharedDomainId(this.cloudFoundryClient, domainName), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - getApplicationId(this.cloudFoundryClient, applicationName, spaceId), - getRouteId(this.cloudFoundryClient, domainId, hostName, spaceId)) - )) - .flatMap(function((applicationId, routeId) -> Mono.zip( - Mono.just(applicationId), - Mono.just(routeId), - this.cloudFoundryClient.routeMappings() - .create(CreateRouteMappingRequest.builder() - .applicationId(applicationId) - .routeId(routeId) - .build()) - .map(ResourceUtils::getEntity) - ))) - .as(StepVerifier::create) - .consumeNextWith(consumer((applicationId, routeId, entity) -> { - assertThat(entity.getApplicationId()).isEqualTo(applicationId); - assertThat(entity.getRouteId()).isEqualTo(routeId); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(getSharedDomainId(this.cloudFoundryClient, domainName), this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + getApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + getRouteId( + this.cloudFoundryClient, + domainId, + hostName, + spaceId)))) + .flatMap( + function( + (applicationId, routeId) -> + Mono.zip( + Mono.just(applicationId), + Mono.just(routeId), + this.cloudFoundryClient + .routeMappings() + .create( + CreateRouteMappingRequest.builder() + .applicationId( + applicationId) + .routeId(routeId) + .build()) + .map(ResourceUtils::getEntity)))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (applicationId, routeId, entity) -> { + assertThat(entity.getApplicationId()).isEqualTo(applicationId); + assertThat(entity.getRouteId()).isEqualTo(routeId); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -92,16 +102,33 @@ public void deleteAsyncFalse() { String hostName = this.nameFactory.getHostName(); this.spaceId - .flatMap(spaceId -> getRouteMappingId(this.cloudFoundryClient, applicationName, domainName, hostName, spaceId)) - .delayUntil(routeMappingId -> this.cloudFoundryClient.routeMappings() - .delete(DeleteRouteMappingRequest.builder() - .async(false) - .routeMappingId(routeMappingId) - .build())) - .flatMap(routeMappingId -> requestGetRouteMapping(this.cloudFoundryClient, routeMappingId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching(".*\\([0-9]+\\): .*")) - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + getRouteMappingId( + this.cloudFoundryClient, + applicationName, + domainName, + hostName, + spaceId)) + .delayUntil( + routeMappingId -> + this.cloudFoundryClient + .routeMappings() + .delete( + DeleteRouteMappingRequest.builder() + .async(false) + .routeMappingId(routeMappingId) + .build())) + .flatMap( + routeMappingId -> + requestGetRouteMapping(this.cloudFoundryClient, routeMappingId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching(".*\\([0-9]+\\): .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -111,17 +138,39 @@ public void deleteAsyncTrue() { String hostName = this.nameFactory.getHostName(); this.spaceId - .flatMap(spaceId -> getRouteMappingId(this.cloudFoundryClient, applicationName, domainName, hostName, spaceId)) - .delayUntil(routeMappingId -> this.cloudFoundryClient.routeMappings() - .delete(DeleteRouteMappingRequest.builder() - .async(true) - .routeMappingId(routeMappingId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMap(routeMappingId -> requestGetRouteMapping(this.cloudFoundryClient, routeMappingId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching(".*\\([0-9]+\\): .*")) - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + getRouteMappingId( + this.cloudFoundryClient, + applicationName, + domainName, + hostName, + spaceId)) + .delayUntil( + routeMappingId -> + this.cloudFoundryClient + .routeMappings() + .delete( + DeleteRouteMappingRequest.builder() + .async(true) + .routeMappingId(routeMappingId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMap( + routeMappingId -> + requestGetRouteMapping(this.cloudFoundryClient, routeMappingId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching(".*\\([0-9]+\\): .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -131,18 +180,29 @@ public void get() { String hostName = this.nameFactory.getHostName(); this.spaceId - .flatMap(spaceId -> getRouteMappingId(this.cloudFoundryClient, applicationName, domainName, hostName, spaceId)) - .flatMap(routeMappingId -> Mono.zip( - Mono.just(routeMappingId), - this.cloudFoundryClient.routeMappings() - .get(GetRouteMappingRequest.builder() - .routeMappingId(routeMappingId) - .build()) - .map(ResourceUtils::getId))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + getRouteMappingId( + this.cloudFoundryClient, + applicationName, + domainName, + hostName, + spaceId)) + .flatMap( + routeMappingId -> + Mono.zip( + Mono.just(routeMappingId), + this.cloudFoundryClient + .routeMappings() + .get( + GetRouteMappingRequest.builder() + .routeMappingId(routeMappingId) + .build()) + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -152,28 +212,55 @@ public void listFilterByApplicationId() { String hostName = this.nameFactory.getHostName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - getSharedDomainId(this.cloudFoundryClient, domainName), - Mono.just(spaceId) - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - getApplicationId(this.cloudFoundryClient, applicationName, spaceId), - getRouteId(this.cloudFoundryClient, domainId, hostName, spaceId) - ))) - .flatMap(function((applicationId, routeId) -> requestCreateRouteMapping(this.cloudFoundryClient, applicationId, routeId) - .thenReturn(applicationId))) - .flatMapMany(applicationId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routeMappings() - .list(ListRouteMappingsRequest.builder() - .page(page) - .applicationId(applicationId) - .build())) - .filter(resource -> ResourceUtils.getEntity(resource).getApplicationId().equals(applicationId)) - .single()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + getSharedDomainId(this.cloudFoundryClient, domainName), + Mono.just(spaceId))) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + getApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + getRouteId( + this.cloudFoundryClient, + domainId, + hostName, + spaceId)))) + .flatMap( + function( + (applicationId, routeId) -> + requestCreateRouteMapping( + this.cloudFoundryClient, + applicationId, + routeId) + .thenReturn(applicationId))) + .flatMapMany( + applicationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routeMappings() + .list( + ListRouteMappingsRequest + .builder() + .page(page) + .applicationId( + applicationId) + .build())) + .filter( + resource -> + ResourceUtils.getEntity(resource) + .getApplicationId() + .equals(applicationId)) + .single()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -183,97 +270,152 @@ public void listFilterByRouteId() { String hostName = this.nameFactory.getHostName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - getSharedDomainId(this.cloudFoundryClient, domainName), - Mono.just(spaceId) - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - getApplicationId(this.cloudFoundryClient, applicationName, spaceId), - getRouteId(this.cloudFoundryClient, domainId, hostName, spaceId) - ))) - .flatMap(function((applicationId, routeId) -> requestCreateRouteMapping(this.cloudFoundryClient, applicationId, routeId) - .thenReturn(routeId))) - .flatMapMany(routeId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routeMappings() - .list(ListRouteMappingsRequest.builder() - .page(page) - .routeId(routeId) - .build())) - .filter(resource -> ResourceUtils.getEntity(resource).getRouteId().equals(routeId)) - .single()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + getSharedDomainId(this.cloudFoundryClient, domainName), + Mono.just(spaceId))) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + getApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + getRouteId( + this.cloudFoundryClient, + domainId, + hostName, + spaceId)))) + .flatMap( + function( + (applicationId, routeId) -> + requestCreateRouteMapping( + this.cloudFoundryClient, + applicationId, + routeId) + .thenReturn(routeId))) + .flatMapMany( + routeId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routeMappings() + .list( + ListRouteMappingsRequest + .builder() + .page(page) + .routeId(routeId) + .build())) + .filter( + resource -> + ResourceUtils.getEntity(resource) + .getRouteId() + .equals(routeId)) + .single()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createRouteMappingId(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + private static Mono createRouteMappingId( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { return requestCreateRouteMapping(cloudFoundryClient, applicationId, routeId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + private static Mono getApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String spaceId) { + private static Mono getRouteId( + CloudFoundryClient cloudFoundryClient, + String domainId, + String hostName, + String spaceId) { return requestCreateRoute(cloudFoundryClient, domainId, hostName, spaceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getRouteMappingId(CloudFoundryClient cloudFoundryClient, String applicationName, String domainName, String hostName, String spaceId) { + private static Mono getRouteMappingId( + CloudFoundryClient cloudFoundryClient, + String applicationName, + String domainName, + String hostName, + String spaceId) { return getSharedDomainId(cloudFoundryClient, domainName) - .flatMap(domainId -> Mono.zip( - getApplicationId(cloudFoundryClient, applicationName, spaceId), - getRouteId(cloudFoundryClient, domainId, hostName, spaceId) - )) - .flatMap(function((applicationId, routeId) -> createRouteMappingId(cloudFoundryClient, applicationId, routeId))); + .flatMap( + domainId -> + Mono.zip( + getApplicationId( + cloudFoundryClient, applicationName, spaceId), + getRouteId( + cloudFoundryClient, domainId, hostName, spaceId))) + .flatMap( + function( + (applicationId, routeId) -> + createRouteMappingId( + cloudFoundryClient, applicationId, routeId))); } - private static Mono getSharedDomainId(CloudFoundryClient cloudFoundryClient, String domainName) { - return requestCreateSharedDomain(cloudFoundryClient, domainName) - .map(ResourceUtils::getId); + private static Mono getSharedDomainId( + CloudFoundryClient cloudFoundryClient, String domainName) { + return requestCreateSharedDomain(cloudFoundryClient, domainName).map(ResourceUtils::getId); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .diego(true) - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .diego(true) + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String spaceId) { - return cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .host(hostName) - .domainId(domainId) - .spaceId(spaceId) - .build()); + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, + String domainId, + String hostName, + String spaceId) { + return cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .host(hostName) + .domainId(domainId) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateRouteMapping(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { - return cloudFoundryClient.routeMappings() - .create(CreateRouteMappingRequest.builder() - .applicationId(applicationId) - .routeId(routeId) - .build()); + private static Mono requestCreateRouteMapping( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + return cloudFoundryClient + .routeMappings() + .create( + CreateRouteMappingRequest.builder() + .applicationId(applicationId) + .routeId(routeId) + .build()); } - private static Mono requestCreateSharedDomain(CloudFoundryClient cloudFoundryClient, String domainName) { - return cloudFoundryClient.sharedDomains() - .create(CreateSharedDomainRequest.builder() - .name(domainName) - .build()); + private static Mono requestCreateSharedDomain( + CloudFoundryClient cloudFoundryClient, String domainName) { + return cloudFoundryClient + .sharedDomains() + .create(CreateSharedDomainRequest.builder().name(domainName).build()); } - private static Mono requestGetRouteMapping(CloudFoundryClient cloudFoundryClient, String routeMappingId) { - return cloudFoundryClient.routeMappings() - .get(GetRouteMappingRequest.builder() - .routeMappingId(routeMappingId) - .build()); + private static Mono requestGetRouteMapping( + CloudFoundryClient cloudFoundryClient, String routeMappingId) { + return cloudFoundryClient + .routeMappings() + .get(GetRouteMappingRequest.builder().routeMappingId(routeMappingId).build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/RoutesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/RoutesTest.java index 7232e7aaab2..3ee56508931 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/RoutesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/RoutesTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.function.Consumer; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; @@ -41,129 +47,182 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuple3; -import java.time.Duration; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class RoutesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; - @Autowired - private Mono stackId; + @Autowired private Mono stackId; @Test public void associateApplication() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId) - ))) - .delayUntil(function((applicationId, routeId) -> associateApplicationWithRoute(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listApplications(ListRouteApplicationsRequest.builder() - .page(page) - .routeId(routeId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .delayUntil( + function( + (applicationId, routeId) -> + associateApplicationWithRoute( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listApplications( + ListRouteApplicationsRequest + .builder() + .page(page) + .routeId(routeId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void create() { String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - Mono.just(domainId), - Mono.just(spaceId), - this.cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .spaceId(spaceId) - .build()) - .map(ResourceUtils::getEntity)) - )) - .as(StepVerifier::create) - .consumeNextWith(domainIdSpaceIdEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + Mono.just(domainId), + Mono.just(spaceId), + this.cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .domainId(domainId) + .spaceId(spaceId) + .build()) + .map(ResourceUtils::getEntity)))) + .as(StepVerifier::create) + .consumeNextWith(domainIdSpaceIdEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void delete() { String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> createRouteId(this.cloudFoundryClient, domainId, spaceId))) - .delayUntil(routeId -> this.cloudFoundryClient.routes() - .delete(DeleteRouteRequest.builder() - .async(true) - .routeId(routeId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMap(routeId -> requestGetRoute(this.cloudFoundryClient, routeId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-RouteNotFound\\([0-9]+\\): The route could not be found: .*")) - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + createRouteId(this.cloudFoundryClient, domainId, spaceId))) + .delayUntil( + routeId -> + this.cloudFoundryClient + .routes() + .delete( + DeleteRouteRequest.builder() + .async(true) + .routeId(routeId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMap(routeId -> requestGetRoute(this.cloudFoundryClient, routeId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-RouteNotFound\\([0-9]+\\): The route could not" + + " be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test public void deleteAsyncFalse() { String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> createRouteId(this.cloudFoundryClient, domainId, spaceId))) - .delayUntil(routeId -> this.cloudFoundryClient.routes() - .delete(DeleteRouteRequest.builder() - .async(false) - .routeId(routeId) - .build())) - .flatMap(routeId -> requestGetRoute(this.cloudFoundryClient, routeId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-RouteNotFound\\([0-9]+\\): The route could not be found: .*")) - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + createRouteId(this.cloudFoundryClient, domainId, spaceId))) + .delayUntil( + routeId -> + this.cloudFoundryClient + .routes() + .delete( + DeleteRouteRequest.builder() + .async(false) + .routeId(routeId) + .build())) + .flatMap(routeId -> requestGetRoute(this.cloudFoundryClient, routeId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-RouteNotFound\\([0-9]+\\): The route could not" + + " be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -171,22 +230,36 @@ public void exists() { String domainName = this.nameFactory.getDomainName(); String hostName = this.nameFactory.getHostName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .delayUntil(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, hostName, spaceId))) - .flatMap(function((domainId, spaceId) -> this.cloudFoundryClient.routes() - .exists(RouteExistsRequest.builder() - .domainId(domainId) - .host(hostName) - .build()))) - .as(StepVerifier::create) - .expectNext(true) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .delayUntil( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + hostName, + spaceId))) + .flatMap( + function( + (domainId, spaceId) -> + this.cloudFoundryClient + .routes() + .exists( + RouteExistsRequest.builder() + .domainId(domainId) + .host(hostName) + .build()))) + .as(StepVerifier::create) + .expectNext(true) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -195,57 +268,80 @@ public void existsDoesNotExist() { String hostName1 = this.nameFactory.getHostName(); String hostName2 = this.nameFactory.getHostName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .delayUntil(function((domainId, spaceId) -> this.cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .host(hostName1) - .spaceId(spaceId) - .build()))) - .flatMap(function((domainId, spaceId) -> this.cloudFoundryClient.routes() - .exists(RouteExistsRequest.builder() - .domainId(domainId) - .host(hostName2) - .build()))) - .as(StepVerifier::create) - .expectNext(false) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .delayUntil( + function( + (domainId, spaceId) -> + this.cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .domainId(domainId) + .host(hostName1) + .spaceId(spaceId) + .build()))) + .flatMap( + function( + (domainId, spaceId) -> + this.cloudFoundryClient + .routes() + .exists( + RouteExistsRequest.builder() + .domainId(domainId) + .host(hostName2) + .build()))) + .as(StepVerifier::create) + .expectNext(false) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void get() { String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - Mono.just(domainId), - Mono.just(spaceId), - createRouteId(this.cloudFoundryClient, domainId, spaceId)) - )) - .flatMap(function((domainId, spaceId, routeId) -> Mono.zip( - Mono.just(domainId), - Mono.just(spaceId), - this.cloudFoundryClient.routes() - .get(GetRouteRequest.builder() - .routeId(routeId) - .build()) - .map(ResourceUtils::getEntity)) - )) - .as(StepVerifier::create) - .consumeNextWith(domainIdSpaceIdEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + Mono.just(domainId), + Mono.just(spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .flatMap( + function( + (domainId, spaceId, routeId) -> + Mono.zip( + Mono.just(domainId), + Mono.just(spaceId), + this.cloudFoundryClient + .routes() + .get( + GetRouteRequest.builder() + .routeId(routeId) + .build()) + .map(ResourceUtils::getEntity)))) + .as(StepVerifier::create) + .consumeNextWith(domainIdSpaceIdEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -253,27 +349,49 @@ public void listApplications() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId) - ))) - .delayUntil(function((applicationId, routeId) -> associateApplicationWithRoute(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listApplications(ListRouteApplicationsRequest.builder() - .page(page) - .routeId(routeId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .delayUntil( + function( + (applicationId, routeId) -> + associateApplicationWithRoute( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listApplications( + ListRouteApplicationsRequest + .builder() + .page(page) + .routeId(routeId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -281,28 +399,50 @@ public void listApplicationsFilterByDiego() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId) - ))) - .delayUntil(function((applicationId, routeId) -> associateApplicationWithRoute(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listApplications(ListRouteApplicationsRequest.builder() - .diego(true) - .page(page) - .routeId(routeId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .delayUntil( + function( + (applicationId, routeId) -> + associateApplicationWithRoute( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listApplications( + ListRouteApplicationsRequest + .builder() + .diego(true) + .page(page) + .routeId(routeId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -310,28 +450,51 @@ public void listApplicationsFilterByName() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId) - ))) - .delayUntil(function((applicationId, routeId) -> associateApplicationWithRoute(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listApplications(ListRouteApplicationsRequest.builder() - .name(applicationName) - .page(page) - .routeId(routeId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .delayUntil( + function( + (applicationId, routeId) -> + associateApplicationWithRoute( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listApplications( + ListRouteApplicationsRequest + .builder() + .name( + applicationName) + .page(page) + .routeId(routeId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -340,28 +503,51 @@ public void listApplicationsFilterByOrganizationId() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId, - Mono.just(organizationId) - )) - .flatMap(function((domainId, spaceId, organizationId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId), - Mono.just(organizationId) - ))) - .delayUntil(function((applicationId, routeId, organizationId) -> associateApplicationWithRoute(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId, organizationId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listApplications(ListRouteApplicationsRequest.builder() - .organizationId(organizationId) - .page(page) - .routeId(routeId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId, + Mono.just(organizationId))) + .flatMap( + function( + (domainId, spaceId, organizationId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, domainId, spaceId), + Mono.just(organizationId)))) + .delayUntil( + function( + (applicationId, routeId, organizationId) -> + associateApplicationWithRoute( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId, organizationId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listApplications( + ListRouteApplicationsRequest + .builder() + .organizationId( + organizationId) + .page(page) + .routeId(routeId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -369,29 +555,49 @@ public void listApplicationsFilterBySpaceId() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId), - Mono.just(spaceId) - ))) - .delayUntil(function((applicationId, routeId, spaceId) -> associateApplicationWithRoute(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId, spaceId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listApplications(ListRouteApplicationsRequest.builder() - .page(page) - .routeId(routeId) - .spaceId(spaceId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, domainId, spaceId), + Mono.just(spaceId)))) + .delayUntil( + function( + (applicationId, routeId, spaceId) -> + associateApplicationWithRoute( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId, spaceId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listApplications( + ListRouteApplicationsRequest + .builder() + .page(page) + .routeId(routeId) + .spaceId(spaceId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -399,54 +605,85 @@ public void listApplicationsFilterByStackId() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId, - this.stackId - ) - .flatMap(function((domainId, spaceId, stackId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, stackId), - createRouteId(this.cloudFoundryClient, domainId, spaceId), - Mono.just(stackId) - ) - )) - .delayUntil(function((applicationId, routeId, stackId) -> associateApplicationWithRoute(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId, stackId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listApplications(ListRouteApplicationsRequest.builder() - .page(page) - .routeId(routeId) - .stackId(stackId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId, + this.stackId) + .flatMap( + function( + (domainId, spaceId, stackId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + stackId), + createRouteId( + this.cloudFoundryClient, domainId, spaceId), + Mono.just(stackId)))) + .delayUntil( + function( + (applicationId, routeId, stackId) -> + associateApplicationWithRoute( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId, stackId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listApplications( + ListRouteApplicationsRequest + .builder() + .page(page) + .routeId(routeId) + .stackId(stackId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByDomainId() { String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .delayUntil(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, spaceId))) - .flatMapMany(function((domainId, spaceId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .list(ListRoutesRequest.builder() - .domainId(domainId) - .page(page) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .delayUntil( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, domainId, spaceId))) + .flatMapMany( + function( + (domainId, spaceId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .list( + ListRoutesRequest.builder() + .domainId(domainId) + .page(page) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -454,23 +691,34 @@ public void listFilterByHost() { String domainName = this.nameFactory.getDomainName(); String host = this.nameFactory.getHostName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, host, spaceId))) - .flatMapMany(response -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .list(ListRoutesRequest.builder() - .host(host) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, domainId, host, spaceId))) + .flatMapMany( + response -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .list( + ListRoutesRequest.builder() + .host(host) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -478,23 +726,38 @@ public void listFilterByOrganizationId() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId, - Mono.just(organizationId) - )) - .delayUntil(function((domainId, spaceId, organizationId) -> requestCreateRoute(this.cloudFoundryClient, domainId, spaceId))) - .flatMapMany(function((domainId, spaceId, organizationId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .list(ListRoutesRequest.builder() - .organizationId(organizationId) - .page(page) - .build())))) - .count() - .as(StepVerifier::create) - .consumeNextWith(count -> assertThat(count).isGreaterThan(0)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId, + Mono.just(organizationId))) + .delayUntil( + function( + (domainId, spaceId, organizationId) -> + requestCreateRoute( + this.cloudFoundryClient, domainId, spaceId))) + .flatMapMany( + function( + (domainId, spaceId, organizationId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .list( + ListRoutesRequest.builder() + .organizationId( + organizationId) + .page(page) + .build())))) + .count() + .as(StepVerifier::create) + .consumeNextWith(count -> assertThat(count).isGreaterThan(0)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -502,28 +765,40 @@ public void listFilterByPath() { String domainName = this.nameFactory.getDomainName(); String path = this.nameFactory.getPath(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> this.cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .path(path) - .spaceId(spaceId) - .build()))) - .flatMapMany(response -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .list(ListRoutesRequest.builder() - .page(page) - .path(path) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + this.cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .domainId(domainId) + .path(path) + .spaceId(spaceId) + .build()))) + .flatMapMany( + response -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .list( + ListRoutesRequest.builder() + .page(page) + .path(path) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -531,31 +806,59 @@ public void listMappings() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId) - ))) - .delayUntil(function((applicationId, routeId) -> requestCreateRouteMapping(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId) -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listMappings(ListRouteMappingsRequest.builder() - .page(page) - .routeId(routeId) - .build())) - .single() - .map(response -> ResourceUtils.getEntity(response).getApplicationId())))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .delayUntil( + function( + (applicationId, routeId) -> + requestCreateRouteMapping( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId) -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listMappings( + ListRouteMappingsRequest + .builder() + .page( + page) + .routeId( + routeId) + .build())) + .single() + .map( + response -> + ResourceUtils.getEntity( + response) + .getApplicationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -563,32 +866,61 @@ public void listMappingsFilterByApplicationId() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId) - ))) - .delayUntil(function((applicationId, routeId) -> requestCreateRouteMapping(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, routeId) -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listMappings(ListRouteMappingsRequest.builder() - .applicationId(applicationId) - .page(page) - .routeId(routeId) - .build())) - .single() - .map(response -> ResourceUtils.getEntity(response).getApplicationId())))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .delayUntil( + function( + (applicationId, routeId) -> + requestCreateRouteMapping( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, routeId) -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listMappings( + ListRouteMappingsRequest + .builder() + .applicationId( + applicationId) + .page( + page) + .routeId( + routeId) + .build())) + .single() + .map( + response -> + ResourceUtils.getEntity( + response) + .getApplicationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -596,135 +928,191 @@ public void removeApplication() { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName, null), - createRouteId(this.cloudFoundryClient, domainId, spaceId) - ))) - .delayUntil(function((applicationId, routeId) -> associateApplicationWithRoute(this.cloudFoundryClient, applicationId, routeId))) - .delayUntil(function((applicationId, routeId) -> this.cloudFoundryClient.routes() - .removeApplication(RemoveRouteApplicationRequest.builder() - .applicationId(applicationId) - .routeId(routeId) - .build()))) - .flatMapMany(function((applicationId, routeId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.routes() - .listApplications(ListRouteApplicationsRequest.builder() - .page(page) - .routeId(routeId) - .build())))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + null), + createRouteId( + this.cloudFoundryClient, + domainId, + spaceId)))) + .delayUntil( + function( + (applicationId, routeId) -> + associateApplicationWithRoute( + this.cloudFoundryClient, applicationId, routeId))) + .delayUntil( + function( + (applicationId, routeId) -> + this.cloudFoundryClient + .routes() + .removeApplication( + RemoveRouteApplicationRequest.builder() + .applicationId(applicationId) + .routeId(routeId) + .build()))) + .flatMapMany( + function( + (applicationId, routeId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .routes() + .listApplications( + ListRouteApplicationsRequest + .builder() + .page(page) + .routeId(routeId) + .build())))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void update() { String domainName = this.nameFactory.getDomainName(); - Mono - .zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> createRouteId(this.cloudFoundryClient, domainId, spaceId))) - .flatMap(routeId -> this.cloudFoundryClient.routes() - .update(UpdateRouteRequest.builder() - .host("test-host") - .routeId(routeId) - .build()) - .map(ResourceUtils::getEntity) - .map(RouteEntity::getHost)) - .as(StepVerifier::create) - .expectNext("test-host") - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono associateApplicationWithRoute(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { - return cloudFoundryClient.routes() - .associateApplication(AssociateRouteApplicationRequest.builder() - .applicationId(applicationId) - .routeId(routeId) - .build()); - } - - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName, String stackId) { + Mono.zip( + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + createRouteId(this.cloudFoundryClient, domainId, spaceId))) + .flatMap( + routeId -> + this.cloudFoundryClient + .routes() + .update( + UpdateRouteRequest.builder() + .host("test-host") + .routeId(routeId) + .build()) + .map(ResourceUtils::getEntity) + .map(RouteEntity::getHost)) + .as(StepVerifier::create) + .expectNext("test-host") + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono associateApplicationWithRoute( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + return cloudFoundryClient + .routes() + .associateApplication( + AssociateRouteApplicationRequest.builder() + .applicationId(applicationId) + .routeId(routeId) + .build()); + } + + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String applicationName, + String stackId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName, stackId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createPrivateDomainId(CloudFoundryClient cloudFoundryClient, String name, String organizationId) { + private static Mono createPrivateDomainId( + CloudFoundryClient cloudFoundryClient, String name, String organizationId) { return requestCreatePrivateDomain(cloudFoundryClient, name, organizationId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) { - return requestCreateRoute(cloudFoundryClient, domainId, spaceId) - .map(ResourceUtils::getId); + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) { + return requestCreateRoute(cloudFoundryClient, domainId, spaceId).map(ResourceUtils::getId); } private static Consumer> domainIdSpaceIdEquality() { - return consumer((domainId, spaceId, entity) -> { - assertThat(entity.getDomainId()).isEqualTo(domainId); - assertThat(entity.getSpaceId()).isEqualTo(spaceId); - }); + return consumer( + (domainId, spaceId, entity) -> { + assertThat(entity.getDomainId()).isEqualTo(domainId); + assertThat(entity.getSpaceId()).isEqualTo(spaceId); + }); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName, String stackId) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .diego(true) - .name(applicationName) - .spaceId(spaceId) - .stackId(stackId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String applicationName, + String stackId) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .diego(true) + .name(applicationName) + .spaceId(spaceId) + .stackId(stackId) + .build()); } - private static Mono requestCreatePrivateDomain(CloudFoundryClient cloudFoundryClient, String name, String organizationId) { - return cloudFoundryClient.privateDomains() - .create(CreatePrivateDomainRequest.builder() - .name(name) - .owningOrganizationId(organizationId) - .build()); + private static Mono requestCreatePrivateDomain( + CloudFoundryClient cloudFoundryClient, String name, String organizationId) { + return cloudFoundryClient + .privateDomains() + .create( + CreatePrivateDomainRequest.builder() + .name(name) + .owningOrganizationId(organizationId) + .build()); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) { - return cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .spaceId(spaceId) - .build()); + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, String domainId, String spaceId) { + return cloudFoundryClient + .routes() + .create(CreateRouteRequest.builder().domainId(domainId).spaceId(spaceId).build()); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String host, String spaceId) { - return cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .host(host) - .spaceId(spaceId) - .build()); + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, String domainId, String host, String spaceId) { + return cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .domainId(domainId) + .host(host) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateRouteMapping(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { - return cloudFoundryClient.routeMappings() - .create(CreateRouteMappingRequest.builder() - .applicationId(applicationId) - .routeId(routeId) - .build()); + private static Mono requestCreateRouteMapping( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + return cloudFoundryClient + .routeMappings() + .create( + CreateRouteMappingRequest.builder() + .applicationId(applicationId) + .routeId(routeId) + .build()); } - private static Mono requestGetRoute(CloudFoundryClient cloudFoundryClient, String routeId) { - return cloudFoundryClient.routes() - .get(GetRouteRequest.builder() - .routeId(routeId) - .build()); + private static Mono requestGetRoute( + CloudFoundryClient cloudFoundryClient, String routeId) { + return cloudFoundryClient.routes().get(GetRouteRequest.builder().routeId(routeId).build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/SecurityGroupsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/SecurityGroupsTest.java index a3256df3c40..64ee5df01a8 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/SecurityGroupsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/SecurityGroupsTest.java @@ -16,6 +16,10 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.client.v2.securitygroups.Protocol.TCP; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.securitygroups.AssociateSecurityGroupSpaceRequest; @@ -45,23 +49,17 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.client.v2.securitygroups.Protocol.TCP; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class SecurityGroupsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; @Test public void associateSpace() { @@ -69,43 +67,56 @@ public void associateSpace() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSecurityGroupId(this.cloudFoundryClient, securityGroupName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((securityGroupId, spaceId) -> this.cloudFoundryClient.securityGroups() - .associateSpace(AssociateSecurityGroupSpaceRequest.builder() - .securityGroupId(securityGroupId) - .spaceId(spaceId) - .build()))) - .map(ResourceUtils::getEntity) - .map(SecurityGroupEntity::getName) - .as(StepVerifier::create) - .expectNext(securityGroupName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSecurityGroupId( + this.cloudFoundryClient, securityGroupName), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (securityGroupId, spaceId) -> + this.cloudFoundryClient + .securityGroups() + .associateSpace( + AssociateSecurityGroupSpaceRequest.builder() + .securityGroupId(securityGroupId) + .spaceId(spaceId) + .build()))) + .map(ResourceUtils::getEntity) + .map(SecurityGroupEntity::getName) + .as(StepVerifier::create) + .expectNext(securityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void create() { String securityGroupName = this.nameFactory.getSecurityGroupName(); - this.cloudFoundryClient.securityGroups() - .create(CreateSecurityGroupRequest.builder() - .name(securityGroupName) - .rule(RuleEntity.builder() - .destination("0.0.0.0/0") - .log(false) - .ports("2048-3000") - .protocol(TCP) - .build()) - .build()) - .map(ResourceUtils::getEntity) - .map(SecurityGroupEntity::getName) - .as(StepVerifier::create) - .expectNext(securityGroupName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .securityGroups() + .create( + CreateSecurityGroupRequest.builder() + .name(securityGroupName) + .rule( + RuleEntity.builder() + .destination("0.0.0.0/0") + .log(false) + .ports("2048-3000") + .protocol(TCP) + .build()) + .build()) + .map(ResourceUtils::getEntity) + .map(SecurityGroupEntity::getName) + .as(StepVerifier::create) + .expectNext(securityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -113,15 +124,24 @@ public void delete() { String securityGroupName = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, securityGroupName) - .flatMap(securityGroupId -> this.cloudFoundryClient.securityGroups() - .delete(DeleteSecurityGroupRequest.builder() - .securityGroupId(securityGroupId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .thenMany(requestListSecurityGroups(this.cloudFoundryClient, securityGroupName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + this.cloudFoundryClient + .securityGroups() + .delete( + DeleteSecurityGroupRequest.builder() + .securityGroupId(securityGroupId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .thenMany(requestListSecurityGroups(this.cloudFoundryClient, securityGroupName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -130,20 +150,38 @@ public void deleteSpace() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSecurityGroupId(this.cloudFoundryClient, securityGroupName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .delayUntil(function((securityGroupId, spaceId) -> associateSpace(this.cloudFoundryClient, spaceId, securityGroupId))) - .delayUntil(function((securityGroupId, spaceId) -> this.cloudFoundryClient.securityGroups() - .removeSpace(RemoveSecurityGroupSpaceRequest.builder() - .securityGroupId(securityGroupId) - .spaceId(spaceId) - .build()))) - .flatMapMany(function((securityGroupId, spaceId) -> requestListSecurityGroupSpaces(this.cloudFoundryClient, spaceId, securityGroupId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSecurityGroupId( + this.cloudFoundryClient, securityGroupName), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .delayUntil( + function( + (securityGroupId, spaceId) -> + associateSpace( + this.cloudFoundryClient, spaceId, securityGroupId))) + .delayUntil( + function( + (securityGroupId, spaceId) -> + this.cloudFoundryClient + .securityGroups() + .removeSpace( + RemoveSecurityGroupSpaceRequest.builder() + .securityGroupId(securityGroupId) + .spaceId(spaceId) + .build()))) + .flatMapMany( + function( + (securityGroupId, spaceId) -> + requestListSecurityGroupSpaces( + this.cloudFoundryClient, spaceId, securityGroupId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -151,16 +189,20 @@ public void get() { String securityGroupName = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, securityGroupName) - .flatMap(securityGroupId -> this.cloudFoundryClient.securityGroups() - .get(GetSecurityGroupRequest.builder() - .securityGroupId(securityGroupId) - .build()) - .map(ResourceUtils::getEntity) - .map(SecurityGroupEntity::getName)) - .as(StepVerifier::create) - .expectNext(securityGroupName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + this.cloudFoundryClient + .securityGroups() + .get( + GetSecurityGroupRequest.builder() + .securityGroupId(securityGroupId) + .build()) + .map(ResourceUtils::getEntity) + .map(SecurityGroupEntity::getName)) + .as(StepVerifier::create) + .expectNext(securityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -168,18 +210,22 @@ public void list() { String securityGroupName = this.nameFactory.getSecurityGroupName(); requestCreateSecurityGroup(this.cloudFoundryClient, securityGroupName) - .thenMany(PaginationUtils. - requestClientV2Resources(page -> this.cloudFoundryClient.securityGroups() - .list(ListSecurityGroupsRequest.builder() - .name(securityGroupName) - .page(page) - .build())) - .map(ResourceUtils::getEntity) - .map(SecurityGroupEntity::getName)) - .as(StepVerifier::create) - .expectNext(securityGroupName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .securityGroups() + .list( + ListSecurityGroupsRequest.builder() + .name(securityGroupName) + .page(page) + .build())) + .map(ResourceUtils::getEntity) + .map(SecurityGroupEntity::getName)) + .as(StepVerifier::create) + .expectNext(securityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -188,15 +234,25 @@ public void listRunningDefaults() { String securityGroupName2 = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, securityGroupName1) - .flatMap(securityGroupId -> requestSetRunningDefault(this.cloudFoundryClient, securityGroupId)) - .then(createSecurityGroupId(this.cloudFoundryClient, securityGroupName2) - .flatMap(securityGroupId -> requestSetRunningDefault(this.cloudFoundryClient, securityGroupId))) - .thenMany(requestListRunningDefaults(this.cloudFoundryClient)) - .filter(response -> securityGroupName1.equals(response.getEntity().getName()) || securityGroupName2.equals(response.getEntity().getName())) - .as(StepVerifier::create) - .expectNextCount(2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + requestSetRunningDefault(this.cloudFoundryClient, securityGroupId)) + .then( + createSecurityGroupId(this.cloudFoundryClient, securityGroupName2) + .flatMap( + securityGroupId -> + requestSetRunningDefault( + this.cloudFoundryClient, securityGroupId))) + .thenMany(requestListRunningDefaults(this.cloudFoundryClient)) + .filter( + response -> + securityGroupName1.equals(response.getEntity().getName()) + || securityGroupName2.equals( + response.getEntity().getName())) + .as(StepVerifier::create) + .expectNextCount(2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -205,25 +261,41 @@ public void listSpaces() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSecurityGroupId(this.cloudFoundryClient, securityGroupName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .delayUntil(function((securityGroupId, spaceId) -> associateSpace(this.cloudFoundryClient, spaceId, securityGroupId))) - .flatMapMany(function((securityGroupId, spaceId) -> PaginationUtils. - requestClientV2Resources(page -> this.cloudFoundryClient.securityGroups() - .listSpaces(ListSecurityGroupSpacesRequest.builder() - .page(page) - .securityGroupId(securityGroupId) - .spaceId(spaceId) - .build())))) - .map(ResourceUtils::getEntity) - .map(SpaceEntity::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); - + .flatMap( + organizationId -> + Mono.zip( + createSecurityGroupId( + this.cloudFoundryClient, securityGroupName), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .delayUntil( + function( + (securityGroupId, spaceId) -> + associateSpace( + this.cloudFoundryClient, spaceId, securityGroupId))) + .flatMapMany( + function( + (securityGroupId, spaceId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .securityGroups() + .listSpaces( + ListSecurityGroupSpacesRequest + .builder() + .page(page) + .securityGroupId( + securityGroupId) + .spaceId(spaceId) + .build())))) + .map(ResourceUtils::getEntity) + .map(SpaceEntity::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -232,15 +304,25 @@ public void listStagingDefaults() { String securityGroupName2 = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, securityGroupName1) - .flatMap(securityGroupId -> requestSetStagingDefault(this.cloudFoundryClient, securityGroupId)) - .then(createSecurityGroupId(this.cloudFoundryClient, securityGroupName2) - .flatMap(securityGroupId -> requestSetStagingDefault(this.cloudFoundryClient, securityGroupId))) - .thenMany(requestListStagingDefaults(this.cloudFoundryClient)) - .filter(response -> securityGroupName1.equals(response.getEntity().getName()) || securityGroupName2.equals(response.getEntity().getName())) - .as(StepVerifier::create) - .expectNextCount(2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + requestSetStagingDefault(this.cloudFoundryClient, securityGroupId)) + .then( + createSecurityGroupId(this.cloudFoundryClient, securityGroupName2) + .flatMap( + securityGroupId -> + requestSetStagingDefault( + this.cloudFoundryClient, securityGroupId))) + .thenMany(requestListStagingDefaults(this.cloudFoundryClient)) + .filter( + response -> + securityGroupName1.equals(response.getEntity().getName()) + || securityGroupName2.equals( + response.getEntity().getName())) + .as(StepVerifier::create) + .expectNextCount(2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -248,16 +330,20 @@ public void setRunningDefault() { String securityGroupName = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, securityGroupName) - .flatMap(securityGroupId -> this.cloudFoundryClient.securityGroups() - .setRunningDefault(SetSecurityGroupRunningDefaultRequest.builder() - .securityGroupId(securityGroupId) - .build())) - .map(ResourceUtils::getEntity) - .map(SecurityGroupEntity::getName) - .as(StepVerifier::create) - .expectNext(securityGroupName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + this.cloudFoundryClient + .securityGroups() + .setRunningDefault( + SetSecurityGroupRunningDefaultRequest.builder() + .securityGroupId(securityGroupId) + .build())) + .map(ResourceUtils::getEntity) + .map(SecurityGroupEntity::getName) + .as(StepVerifier::create) + .expectNext(securityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -265,16 +351,20 @@ public void setStagingDefault() { String securityGroupName = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, securityGroupName) - .flatMap(securityGroupId -> this.cloudFoundryClient.securityGroups() - .setStagingDefault(SetSecurityGroupStagingDefaultRequest.builder() - .securityGroupId(securityGroupId) - .build())) - .map(ResourceUtils::getEntity) - .map(SecurityGroupEntity::getName) - .as(StepVerifier::create) - .expectNext(securityGroupName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + this.cloudFoundryClient + .securityGroups() + .setStagingDefault( + SetSecurityGroupStagingDefaultRequest.builder() + .securityGroupId(securityGroupId) + .build())) + .map(ResourceUtils::getEntity) + .map(SecurityGroupEntity::getName) + .as(StepVerifier::create) + .expectNext(securityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -282,16 +372,23 @@ public void unsetRunningDefault() { String securityGroupName = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, securityGroupName) - .flatMap(securityGroupId -> requestSetRunningDefault(this.cloudFoundryClient, securityGroupId) - .then(this.cloudFoundryClient.securityGroups() - .removeRunningDefault(RemoveSecurityGroupRunningDefaultRequest.builder() - .securityGroupId(securityGroupId) - .build()))) - .thenMany(requestListRunningDefaults(this.cloudFoundryClient)) - .filter(response -> securityGroupName.equals(response.getEntity().getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + requestSetRunningDefault(this.cloudFoundryClient, securityGroupId) + .then( + this.cloudFoundryClient + .securityGroups() + .removeRunningDefault( + RemoveSecurityGroupRunningDefaultRequest + .builder() + .securityGroupId( + securityGroupId) + .build()))) + .thenMany(requestListRunningDefaults(this.cloudFoundryClient)) + .filter(response -> securityGroupName.equals(response.getEntity().getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -299,16 +396,23 @@ public void unsetStagingDefault() { String securityGroupName = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, securityGroupName) - .flatMap(securityGroupId -> requestSetStagingDefault(this.cloudFoundryClient, securityGroupId) - .then(this.cloudFoundryClient.securityGroups() - .removeStagingDefault(RemoveSecurityGroupStagingDefaultRequest.builder() - .securityGroupId(securityGroupId) - .build()))) - .thenMany(requestListRunningDefaults(this.cloudFoundryClient)) - .filter(response -> securityGroupName.equals(response.getEntity().getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + requestSetStagingDefault(this.cloudFoundryClient, securityGroupId) + .then( + this.cloudFoundryClient + .securityGroups() + .removeStagingDefault( + RemoveSecurityGroupStagingDefaultRequest + .builder() + .securityGroupId( + securityGroupId) + .build()))) + .thenMany(requestListRunningDefaults(this.cloudFoundryClient)) + .filter(response -> securityGroupName.equals(response.getEntity().getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -317,93 +421,126 @@ public void update() { String newSecurityGroupName = this.nameFactory.getSecurityGroupName(); createSecurityGroupId(this.cloudFoundryClient, oldSecurityGroupName) - .flatMap(securityGroupId -> this.cloudFoundryClient.securityGroups() - .update(UpdateSecurityGroupRequest.builder() - .securityGroupId(securityGroupId) - .name(newSecurityGroupName) - .build())) - .then(requestListSecurityGroups(this.cloudFoundryClient, newSecurityGroupName) - .single() - .map(ResourceUtils::getEntity) - .map(SecurityGroupEntity::getName)) - .as(StepVerifier::create) - .expectNext(newSecurityGroupName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + securityGroupId -> + this.cloudFoundryClient + .securityGroups() + .update( + UpdateSecurityGroupRequest.builder() + .securityGroupId(securityGroupId) + .name(newSecurityGroupName) + .build())) + .then( + requestListSecurityGroups(this.cloudFoundryClient, newSecurityGroupName) + .single() + .map(ResourceUtils::getEntity) + .map(SecurityGroupEntity::getName)) + .as(StepVerifier::create) + .expectNext(newSecurityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono associateSpace(CloudFoundryClient cloudFoundryClient, String spaceId, String securityGroupId) { - return cloudFoundryClient.securityGroups() - .associateSpace(AssociateSecurityGroupSpaceRequest.builder() - .securityGroupId(securityGroupId) - .spaceId(spaceId) - .build()); + private static Mono associateSpace( + CloudFoundryClient cloudFoundryClient, String spaceId, String securityGroupId) { + return cloudFoundryClient + .securityGroups() + .associateSpace( + AssociateSecurityGroupSpaceRequest.builder() + .securityGroupId(securityGroupId) + .spaceId(spaceId) + .build()); } - private static Mono createSecurityGroupId(CloudFoundryClient cloudFoundryClient, String securityGroupName) { + private static Mono createSecurityGroupId( + CloudFoundryClient cloudFoundryClient, String securityGroupName) { return requestCreateSecurityGroup(cloudFoundryClient, securityGroupName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .organizationId(organizationId) - .name(spaceName) - .build()) - .map(ResourceUtils::getId); + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .organizationId(organizationId) + .name(spaceName) + .build()) + .map(ResourceUtils::getId); } - private static Mono requestCreateSecurityGroup(CloudFoundryClient cloudFoundryClient, String securityGroupName) { - return cloudFoundryClient.securityGroups() - .create(CreateSecurityGroupRequest.builder() - .name(securityGroupName) - .build()); + private static Mono requestCreateSecurityGroup( + CloudFoundryClient cloudFoundryClient, String securityGroupName) { + return cloudFoundryClient + .securityGroups() + .create(CreateSecurityGroupRequest.builder().name(securityGroupName).build()); } - private static Flux requestListRunningDefaults(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.securityGroups() - .listRunningDefaults(ListSecurityGroupRunningDefaultsRequest.builder() - .build())); + private static Flux requestListRunningDefaults( + CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .securityGroups() + .listRunningDefaults( + ListSecurityGroupRunningDefaultsRequest.builder().build())); } - private static Flux requestListSecurityGroupSpaces(CloudFoundryClient cloudFoundryClient, String spaceId, String securityGroupId) { - return PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.securityGroups() - .listSpaces(ListSecurityGroupSpacesRequest.builder() - .page(page) - .securityGroupId(securityGroupId) - .spaceId(spaceId) - .build())); + private static Flux requestListSecurityGroupSpaces( + CloudFoundryClient cloudFoundryClient, String spaceId, String securityGroupId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .securityGroups() + .listSpaces( + ListSecurityGroupSpacesRequest.builder() + .page(page) + .securityGroupId(securityGroupId) + .spaceId(spaceId) + .build())); } - private static Flux requestListSecurityGroups(CloudFoundryClient cloudFoundryClient, String securityGroupName) { - return PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.securityGroups() - .list(ListSecurityGroupsRequest.builder() - .name(securityGroupName) - .page(page) - .build())); + private static Flux requestListSecurityGroups( + CloudFoundryClient cloudFoundryClient, String securityGroupName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .securityGroups() + .list( + ListSecurityGroupsRequest.builder() + .name(securityGroupName) + .page(page) + .build())); } - private static Flux requestListStagingDefaults(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.securityGroups() - .listStagingDefaults(ListSecurityGroupStagingDefaultsRequest.builder() - .build())); + private static Flux requestListStagingDefaults( + CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .securityGroups() + .listStagingDefaults( + ListSecurityGroupStagingDefaultsRequest.builder().build())); } - private static Mono requestSetRunningDefault(CloudFoundryClient cloudFoundryClient, String securityGroupId) { - return cloudFoundryClient.securityGroups() - .setRunningDefault(SetSecurityGroupRunningDefaultRequest.builder() - .securityGroupId(securityGroupId) - .build()); + private static Mono requestSetRunningDefault( + CloudFoundryClient cloudFoundryClient, String securityGroupId) { + return cloudFoundryClient + .securityGroups() + .setRunningDefault( + SetSecurityGroupRunningDefaultRequest.builder() + .securityGroupId(securityGroupId) + .build()); } - private static Mono requestSetStagingDefault(CloudFoundryClient cloudFoundryClient, String securityGroupId) { - return cloudFoundryClient.securityGroups() - .setStagingDefault(SetSecurityGroupStagingDefaultRequest.builder() - .securityGroupId(securityGroupId) - .build()); + private static Mono requestSetStagingDefault( + CloudFoundryClient cloudFoundryClient, String securityGroupId) { + return cloudFoundryClient + .securityGroups() + .setStagingDefault( + SetSecurityGroupStagingDefaultRequest.builder() + .securityGroupId(securityGroupId) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceBindingsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceBindingsTest.java index f9a482729f7..668976376d4 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceBindingsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceBindingsTest.java @@ -16,6 +16,13 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.Optional; +import java.util.function.Consumer; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; @@ -34,6 +41,7 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -41,37 +49,33 @@ import reactor.util.function.Tuple2; import reactor.util.function.Tuple3; -import java.time.Duration; -import java.util.Optional; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ServiceBindingsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void create() { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createServiceInstanceAndApplicationIds(this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) - .flatMap(function((serviceInstanceId, applicationId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - requestCreateServiceBinding(this.cloudFoundryClient, applicationId, serviceInstanceId) - ))) - .as(StepVerifier::create) - .consumeNextWith(serviceBindingEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createServiceInstanceAndApplicationIds( + this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) + .flatMap( + function( + (serviceInstanceId, applicationId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + requestCreateServiceBinding( + this.cloudFoundryClient, + applicationId, + serviceInstanceId)))) + .as(StepVerifier::create) + .consumeNextWith(serviceBindingEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -79,17 +83,37 @@ public void delete() { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createServiceInstanceAndApplicationIds(this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) - .flatMap(function((serviceInstanceId, applicationId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId) - ))) - .delayUntil(function((serviceInstanceId, applicationId, serviceBindingId) -> deleteServiceBinding(this.cloudFoundryClient, serviceBindingId))) - .flatMap(function((serviceInstanceId, applicationId, serviceBindingId) -> requestGetServiceBinding(this.cloudFoundryClient, serviceBindingId))) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-ServiceBindingNotFound\\([0-9]+\\): The service binding could not be found: .*")) - .verify(Duration.ofMinutes(5)); + createServiceInstanceAndApplicationIds( + this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) + .flatMap( + function( + (serviceInstanceId, applicationId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId)))) + .delayUntil( + function( + (serviceInstanceId, applicationId, serviceBindingId) -> + deleteServiceBinding( + this.cloudFoundryClient, serviceBindingId))) + .flatMap( + function( + (serviceInstanceId, applicationId, serviceBindingId) -> + requestGetServiceBinding( + this.cloudFoundryClient, serviceBindingId))) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-ServiceBindingNotFound\\([0-9]+\\): The service" + + " binding could not be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -97,21 +121,31 @@ public void get() { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createServiceInstanceAndApplicationIds(this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) - .flatMap(function((serviceInstanceId, applicationId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId) - ))) - .flatMap(function((serviceInstanceId, applicationId, serviceBindingId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - requestGetServiceBinding(this.cloudFoundryClient, serviceBindingId) - ))) - .as(StepVerifier::create) - .consumeNextWith(serviceBindingEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createServiceInstanceAndApplicationIds( + this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) + .flatMap( + function( + (serviceInstanceId, applicationId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId)))) + .flatMap( + function( + (serviceInstanceId, applicationId, serviceBindingId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + requestGetServiceBinding( + this.cloudFoundryClient, + serviceBindingId)))) + .as(StepVerifier::create) + .consumeNextWith(serviceBindingEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -119,23 +153,36 @@ public void list() { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createServiceInstanceAndApplicationIds(this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) - .flatMap(function((serviceInstanceId, applicationId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId) - ))) - .flatMap(function((serviceInstanceId, applicationId, serviceBindingId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - requestListServiceBindings(this.cloudFoundryClient, null, null) - .filter(resource -> serviceBindingId.equals(ResourceUtils.getId(resource))) - .single() - ))) - .as(StepVerifier::create) - .consumeNextWith(serviceBindingEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createServiceInstanceAndApplicationIds( + this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) + .flatMap( + function( + (serviceInstanceId, applicationId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId)))) + .flatMap( + function( + (serviceInstanceId, applicationId, serviceBindingId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + requestListServiceBindings( + this.cloudFoundryClient, null, null) + .filter( + resource -> + serviceBindingId.equals( + ResourceUtils.getId( + resource))) + .single()))) + .as(StepVerifier::create) + .consumeNextWith(serviceBindingEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -143,23 +190,38 @@ public void listFilterByApplicationId() { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createServiceInstanceAndApplicationIds(this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) - .flatMap(function((serviceInstanceId, applicationId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId) - ))) - .flatMap(function((serviceInstanceId, applicationId, serviceBindingId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - requestListServiceBindings(this.cloudFoundryClient, applicationId, null) - .filter(resource -> serviceBindingId.equals(ResourceUtils.getId(resource))) - .single() - ))) - .as(StepVerifier::create) - .consumeNextWith(serviceBindingEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createServiceInstanceAndApplicationIds( + this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) + .flatMap( + function( + (serviceInstanceId, applicationId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId)))) + .flatMap( + function( + (serviceInstanceId, applicationId, serviceBindingId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + requestListServiceBindings( + this.cloudFoundryClient, + applicationId, + null) + .filter( + resource -> + serviceBindingId.equals( + ResourceUtils.getId( + resource))) + .single()))) + .as(StepVerifier::create) + .consumeNextWith(serviceBindingEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -167,114 +229,160 @@ public void listFilterByServiceInstanceId() { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createServiceInstanceAndApplicationIds(this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) - .flatMap(function((serviceInstanceId, applicationId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId) - ))) - .flatMap(function((serviceInstanceId, applicationId, serviceBindingId) -> Mono.zip( - Mono.just(serviceInstanceId), - Mono.just(applicationId), - requestListServiceBindings(this.cloudFoundryClient, null, serviceInstanceId) - .filter(resource -> serviceBindingId.equals(ResourceUtils.getId(resource))) - .single() - ))) - .as(StepVerifier::create) - .consumeNextWith(serviceBindingEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createServiceInstanceAndApplicationIds( + this.spaceId, this.cloudFoundryClient, serviceInstanceName, applicationName) + .flatMap( + function( + (serviceInstanceId, applicationId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId)))) + .flatMap( + function( + (serviceInstanceId, applicationId, serviceBindingId) -> + Mono.zip( + Mono.just(serviceInstanceId), + Mono.just(applicationId), + requestListServiceBindings( + this.cloudFoundryClient, + null, + serviceInstanceId) + .filter( + resource -> + serviceBindingId.equals( + ResourceUtils.getId( + resource))) + .single()))) + .as(StepVerifier::create) + .consumeNextWith(serviceBindingEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return requestCreateApplication(cloudFoundryClient, spaceId, applicationName, null, null, null, null) - .map(ResourceUtils::getId); + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return requestCreateApplication( + cloudFoundryClient, spaceId, applicationName, null, null, null, null) + .map(ResourceUtils::getId); } - private static Mono createServiceBindingId(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + private static Mono createServiceBindingId( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { return requestCreateServiceBinding(cloudFoundryClient, applicationId, serviceInstanceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono> createServiceInstanceAndApplicationIds(Mono spaceId, CloudFoundryClient cloudFoundryClient, String serviceInstance, String application) { - return spaceId - .flatMap(spaceId1 -> Mono.zip( - createUserServiceInstanceId(cloudFoundryClient, spaceId1, serviceInstance), - createApplicationId(cloudFoundryClient, spaceId1, application) - )); + private static Mono> createServiceInstanceAndApplicationIds( + Mono spaceId, + CloudFoundryClient cloudFoundryClient, + String serviceInstance, + String application) { + return spaceId.flatMap( + spaceId1 -> + Mono.zip( + createUserServiceInstanceId( + cloudFoundryClient, spaceId1, serviceInstance), + createApplicationId(cloudFoundryClient, spaceId1, application))); } - private static Mono createUserServiceInstanceId(CloudFoundryClient cloudFoundryClient, String spaceId, String serviceInstanceName) { + private static Mono createUserServiceInstanceId( + CloudFoundryClient cloudFoundryClient, String spaceId, String serviceInstanceName) { return requestCreateUserServiceInstance(cloudFoundryClient, spaceId, serviceInstanceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono deleteServiceBinding(CloudFoundryClient cloudFoundryClient, String serviceBindingId) { + private static Mono deleteServiceBinding( + CloudFoundryClient cloudFoundryClient, String serviceBindingId) { return requestDeleteServiceBinding(cloudFoundryClient, serviceBindingId) - .flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job)); + .flatMap( + job -> + JobUtils.waitForCompletion( + cloudFoundryClient, Duration.ofMinutes(5), job)); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName, String buildpack, Boolean diego, Integer - diskQuota, Integer memory) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .buildpack(buildpack) - .diego(diego) - .diskQuota(diskQuota) - .memory(memory) - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String applicationName, + String buildpack, + Boolean diego, + Integer diskQuota, + Integer memory) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .buildpack(buildpack) + .diego(diego) + .diskQuota(diskQuota) + .memory(memory) + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateServiceBinding(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { - return cloudFoundryClient.serviceBindingsV2() - .create(CreateServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(serviceInstanceId) - .build()); + private static Mono requestCreateServiceBinding( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + return cloudFoundryClient + .serviceBindingsV2() + .create( + CreateServiceBindingRequest.builder() + .applicationId(applicationId) + .serviceInstanceId(serviceInstanceId) + .build()); } - private static Mono requestCreateUserServiceInstance(CloudFoundryClient cloudFoundryClient, String spaceId, String name) { - return cloudFoundryClient.userProvidedServiceInstances() - .create(CreateUserProvidedServiceInstanceRequest.builder() - .name(name) - .spaceId(spaceId) - .build()); + private static Mono requestCreateUserServiceInstance( + CloudFoundryClient cloudFoundryClient, String spaceId, String name) { + return cloudFoundryClient + .userProvidedServiceInstances() + .create( + CreateUserProvidedServiceInstanceRequest.builder() + .name(name) + .spaceId(spaceId) + .build()); } - private static Mono requestDeleteServiceBinding(CloudFoundryClient cloudFoundryClient, String serviceBindingId) { - return cloudFoundryClient.serviceBindingsV2() - .delete(DeleteServiceBindingRequest.builder() - .serviceBindingId(serviceBindingId) - .build()); + private static Mono requestDeleteServiceBinding( + CloudFoundryClient cloudFoundryClient, String serviceBindingId) { + return cloudFoundryClient + .serviceBindingsV2() + .delete( + DeleteServiceBindingRequest.builder() + .serviceBindingId(serviceBindingId) + .build()); } - private static Mono requestGetServiceBinding(CloudFoundryClient cloudFoundryClient, String serviceBindingId) { - return cloudFoundryClient.serviceBindingsV2() - .get(GetServiceBindingRequest.builder() - .serviceBindingId(serviceBindingId) - .build()); + private static Mono requestGetServiceBinding( + CloudFoundryClient cloudFoundryClient, String serviceBindingId) { + return cloudFoundryClient + .serviceBindingsV2() + .get(GetServiceBindingRequest.builder().serviceBindingId(serviceBindingId).build()); } - private static Flux requestListServiceBindings(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + private static Flux requestListServiceBindings( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { ListServiceBindingsRequest.Builder builder = ListServiceBindingsRequest.builder(); Optional.ofNullable(applicationId).map(builder::applicationId); Optional.ofNullable(serviceInstanceId).map(builder::serviceInstanceId); - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceBindingsV2() - .list(builder - .page(page) - .build())); + return PaginationUtils.requestClientV2Resources( + page -> cloudFoundryClient.serviceBindingsV2().list(builder.page(page).build())); } - private static Consumer> serviceBindingEquality() { - return consumer((serviceInstanceId, applicationId, resource) -> { - assertThat(ResourceUtils.getEntity(resource).getServiceInstanceId()).isEqualTo(serviceInstanceId); - assertThat(ResourceUtils.getEntity(resource).getApplicationId()).isEqualTo(applicationId); - }); + private static + Consumer> serviceBindingEquality() { + return consumer( + (serviceInstanceId, applicationId, resource) -> { + assertThat(ResourceUtils.getEntity(resource).getServiceInstanceId()) + .isEqualTo(serviceInstanceId); + assertThat(ResourceUtils.getEntity(resource).getApplicationId()) + .isEqualTo(applicationId); + }); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceBrokersTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceBrokersTest.java index 96e7fc3118d..75486720fc8 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceBrokersTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceBrokersTest.java @@ -16,6 +16,13 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; +import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; + +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.ApplicationUtils; import org.cloudfoundry.ServiceBrokerUtils; @@ -29,33 +36,22 @@ import org.cloudfoundry.client.v2.spaces.CreateSpaceResponse; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.Exceptions; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; -import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; - public final class ServiceBrokersTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceBrokerName; + @Autowired private String serviceBrokerName; @Test public void create() { @@ -71,32 +67,51 @@ public void create() { throw Exceptions.propagate(e); } - ApplicationUtils.ApplicationMetadata applicationMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> ServiceBrokerUtils.pushServiceBrokerApplication(this.cloudFoundryClient, application, this.nameFactory, planName, serviceName, spaceId)) - .block(Duration.ofMinutes(5)); - - this.cloudFoundryClient.serviceBrokers() - .create(CreateServiceBrokerRequest.builder() - .authenticationPassword("test-authentication-password") - .authenticationUsername("test-authentication-username") - .brokerUrl(applicationMetadata.uri) - .name(serviceBrokerName) - .spaceId(applicationMetadata.spaceId) - .build()) - .flatMapMany(response -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceBrokers() - .list(ListServiceBrokersRequest.builder() - .name(serviceBrokerName) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + ApplicationUtils.ApplicationMetadata applicationMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + ServiceBrokerUtils.pushServiceBrokerApplication( + this.cloudFoundryClient, + application, + this.nameFactory, + planName, + serviceName, + spaceId)) + .block(Duration.ofMinutes(5)); + + this.cloudFoundryClient + .serviceBrokers() + .create( + CreateServiceBrokerRequest.builder() + .authenticationPassword("test-authentication-password") + .authenticationUsername("test-authentication-username") + .brokerUrl(applicationMetadata.uri) + .name(serviceBrokerName) + .spaceId(applicationMetadata.spaceId) + .build()) + .flatMapMany( + response -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceBrokers() + .list( + ListServiceBrokersRequest.builder() + .name(serviceBrokerName) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); deleteServiceBroker(this.cloudFoundryClient, applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .block(Duration.ofMinutes(5)); } @Test @@ -106,54 +121,86 @@ public void delete() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); - - this.cloudFoundryClient.serviceBrokers() - .delete(DeleteServiceBrokerRequest.builder() - .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) - .build()) - .flatMapMany(response -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceBrokers() - .list(ListServiceBrokersRequest.builder() - .name(serviceBrokerName) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); + + this.cloudFoundryClient + .serviceBrokers() + .delete( + DeleteServiceBrokerRequest.builder() + .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) + .build()) + .flatMapMany( + response -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceBrokers() + .list( + ListServiceBrokersRequest.builder() + .name(serviceBrokerName) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test public void get() { this.serviceBrokerId - .flatMap(serviceBrokerId -> this.cloudFoundryClient.serviceBrokers() - .get(GetServiceBrokerRequest.builder() - .serviceBrokerId(serviceBrokerId) - .build())) - .as(StepVerifier::create) - .assertNext(serviceBroker -> assertThat(ResourceUtils.getEntity(serviceBroker).getName()).isEqualTo(this.serviceBrokerName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + this.cloudFoundryClient + .serviceBrokers() + .get( + GetServiceBrokerRequest.builder() + .serviceBrokerId(serviceBrokerId) + .build())) + .as(StepVerifier::create) + .assertNext( + serviceBroker -> + assertThat(ResourceUtils.getEntity(serviceBroker).getName()) + .isEqualTo(this.serviceBrokerName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceBrokers() - .list(ListServiceBrokersRequest.builder() - .name(this.serviceBrokerName) - .page(page) - .build())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceBrokers() + .list( + ListServiceBrokersRequest.builder() + .name(this.serviceBrokerName) + .page(page) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -164,42 +211,67 @@ public void update() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName1, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); - - this.cloudFoundryClient.serviceBrokers() - .update(UpdateServiceBrokerRequest.builder() - .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) - .name(serviceBrokerName2) - .build()) - .flatMapMany(serviceBrokerId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceBrokers() - .list(ListServiceBrokersRequest.builder() - .name(serviceBrokerName2) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName1, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); + + this.cloudFoundryClient + .serviceBrokers() + .update( + UpdateServiceBrokerRequest.builder() + .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) + .name(serviceBrokerName2) + .build()) + .flatMapMany( + serviceBrokerId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceBrokers() + .list( + ListServiceBrokersRequest.builder() + .name(serviceBrokerName2) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organizationId(organizationId) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organizationId(organizationId) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceInstancesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceInstancesTest.java index 021d6e1a038..ed152f87a39 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceInstancesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceInstancesTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.Collections; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -53,39 +58,28 @@ import org.cloudfoundry.util.LastOperationUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuples; -import java.time.Duration; -import java.util.Collections; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ServiceInstancesTest extends AbstractIntegrationTest { private static final String DEFAULT_ROUTER_GROUP = "default-tcp"; - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private RoutingClient routingClient; + @Autowired private RoutingClient routingClient; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void bindRoute() { @@ -93,76 +87,128 @@ public void bindRoute() { String hostName = this.nameFactory.getHostName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((domainId, serviceInstanceId, spaceId) -> Mono.zip( - createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId), - Mono.just(serviceInstanceId)) - )) - .flatMap(function((routeId, serviceInstanceId) -> this.cloudFoundryClient.serviceInstances() - .bindRoute(BindServiceInstanceRouteRequest.builder() - .routeId(routeId) - .serviceInstanceId(serviceInstanceId) - .build()) - .thenReturn(serviceInstanceId))) - .flatMapMany(serviceInstanceId -> requestListRoutes(this.cloudFoundryClient, serviceInstanceId) - .filter(route -> serviceInstanceId.equals(route.getEntity().getServiceInstanceId()))) - .map(route -> ResourceUtils.getEntity(route).getHost()) - .as(StepVerifier::create) - .expectNext(hostName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (domainId, serviceInstanceId, spaceId) -> + Mono.zip( + createRouteId( + this.cloudFoundryClient, + domainId, + hostName, + null, + spaceId), + Mono.just(serviceInstanceId)))) + .flatMap( + function( + (routeId, serviceInstanceId) -> + this.cloudFoundryClient + .serviceInstances() + .bindRoute( + BindServiceInstanceRouteRequest.builder() + .routeId(routeId) + .serviceInstanceId( + serviceInstanceId) + .build()) + .thenReturn(serviceInstanceId))) + .flatMapMany( + serviceInstanceId -> + requestListRoutes(this.cloudFoundryClient, serviceInstanceId) + .filter( + route -> + serviceInstanceId.equals( + route.getEntity() + .getServiceInstanceId()))) + .map(route -> ResourceUtils.getEntity(route).getHost()) + .as(StepVerifier::create) + .expectNext(hostName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void create() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> Mono.zip( - getPlanId(this.cloudFoundryClient, serviceBrokerId, this.serviceName), - Mono.just(spaceId) - ))) - .flatMap(function((planId, spaceId) -> this.cloudFoundryClient.serviceInstances() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .servicePlanId(planId) - .spaceId(spaceId) - .build()))) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + Mono.zip( + getPlanId( + this.cloudFoundryClient, + serviceBrokerId, + this.serviceName), + Mono.just(spaceId)))) + .flatMap( + function( + (planId, spaceId) -> + this.cloudFoundryClient + .serviceInstances() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .servicePlanId(planId) + .spaceId(spaceId) + .build()))) + .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void createAcceptsIncomplete() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> Mono.zip( - getPlanId(this.cloudFoundryClient, serviceBrokerId, this.serviceName), - Mono.just(spaceId) - ))) - .flatMap(function((planId, spaceId) -> this.cloudFoundryClient.serviceInstances() - .create(CreateServiceInstanceRequest.builder() - .acceptsIncomplete(true) - .name(serviceInstanceName) - .servicePlanId(planId) - .spaceId(spaceId) - .build()))) - .as(StepVerifier::create) - .assertNext(response -> assertThat(ResourceUtils.getEntity(response).getLastOperation().getType()).isEqualTo("create")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + Mono.zip( + getPlanId( + this.cloudFoundryClient, + serviceBrokerId, + this.serviceName), + Mono.just(spaceId)))) + .flatMap( + function( + (planId, spaceId) -> + this.cloudFoundryClient + .serviceInstances() + .create( + CreateServiceInstanceRequest.builder() + .acceptsIncomplete(true) + .name(serviceInstanceName) + .servicePlanId(planId) + .spaceId(spaceId) + .build()))) + .as(StepVerifier::create) + .assertNext( + response -> + assertThat( + ResourceUtils.getEntity(response) + .getLastOperation() + .getType()) + .isEqualTo("create")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -170,17 +216,33 @@ public void delete() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .delete(DeleteServiceInstanceRequest.builder() - .async(true) - .serviceInstanceId(serviceInstanceId) - .build())) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), (JobEntity) ResourceUtils.getEntity(job))) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .delete( + DeleteServiceInstanceRequest.builder() + .async(true) + .serviceInstanceId(serviceInstanceId) + .build())) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + (JobEntity) ResourceUtils.getEntity(job))) + .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -188,22 +250,45 @@ public void deleteAcceptsIncomplete() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .delete(DeleteServiceInstanceRequest.builder() - .acceptsIncomplete(true) - .async(true) - .serviceInstanceId(serviceInstanceId) - .build())) - .flatMap(response -> LastOperationUtils.waitForCompletion(Duration.ofMinutes(5), () -> this.cloudFoundryClient.serviceInstances() - .get(GetServiceInstanceRequest.builder() - .serviceInstanceId(ResourceUtils.getId(response)) - .build()) - .map(r2 -> ResourceUtils.getEntity(r2).getLastOperation()))) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .delete( + DeleteServiceInstanceRequest.builder() + .acceptsIncomplete(true) + .async(true) + .serviceInstanceId(serviceInstanceId) + .build())) + .flatMap( + response -> + LastOperationUtils.waitForCompletion( + Duration.ofMinutes(5), + () -> + this.cloudFoundryClient + .serviceInstances() + .get( + GetServiceInstanceRequest.builder() + .serviceInstanceId( + ResourceUtils.getId( + response)) + .build()) + .map( + r2 -> + ResourceUtils.getEntity(r2) + .getLastOperation()))) + .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -211,22 +296,45 @@ public void deleteAcceptsIncompleteAsyncFalse() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .delete(DeleteServiceInstanceRequest.builder() - .acceptsIncomplete(true) - .async(false) - .serviceInstanceId(serviceInstanceId) - .build())) - .flatMap(response -> LastOperationUtils.waitForCompletion(Duration.ofMinutes(5), () -> this.cloudFoundryClient.serviceInstances() - .get(GetServiceInstanceRequest.builder() - .serviceInstanceId(ResourceUtils.getId(response)) - .build()) - .map(r2 -> ResourceUtils.getEntity(r2).getLastOperation()))) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .delete( + DeleteServiceInstanceRequest.builder() + .acceptsIncomplete(true) + .async(false) + .serviceInstanceId(serviceInstanceId) + .build())) + .flatMap( + response -> + LastOperationUtils.waitForCompletion( + Duration.ofMinutes(5), + () -> + this.cloudFoundryClient + .serviceInstances() + .get( + GetServiceInstanceRequest.builder() + .serviceInstanceId( + ResourceUtils.getId( + response)) + .build()) + .map( + r2 -> + ResourceUtils.getEntity(r2) + .getLastOperation()))) + .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -234,16 +342,27 @@ public void deleteAsyncFalse() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .delete(DeleteServiceInstanceRequest.builder() - .async(false) - .serviceInstanceId(serviceInstanceId) - .build())) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .delete( + DeleteServiceInstanceRequest.builder() + .async(false) + .serviceInstanceId(serviceInstanceId) + .build())) + .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -251,28 +370,55 @@ public void deletePurge() { String domainName = this.nameFactory.getDomainName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((organizationId, serviceInstanceId, spaceId) -> createAndBindRoute(this.cloudFoundryClient, domainName, organizationId, spaceId, serviceInstanceId) - .thenReturn(serviceInstanceId))) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .delete(DeleteServiceInstanceRequest.builder() - .async(true) - .purge(true) - .recursive(false) - .serviceInstanceId(serviceInstanceId) - .build())) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), (JobEntity) ResourceUtils.getEntity(job))) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName) - .filter(resource -> serviceInstanceName.equals(resource.getEntity().getName()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (organizationId, serviceInstanceId, spaceId) -> + createAndBindRoute( + this.cloudFoundryClient, + domainName, + organizationId, + spaceId, + serviceInstanceId) + .thenReturn(serviceInstanceId))) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .delete( + DeleteServiceInstanceRequest.builder() + .async(true) + .purge(true) + .recursive(false) + .serviceInstanceId(serviceInstanceId) + .build())) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + (JobEntity) ResourceUtils.getEntity(job))) + .thenMany( + requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName) + .filter( + resource -> + serviceInstanceName.equals( + resource.getEntity().getName()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -280,28 +426,55 @@ public void deleteRecursive() { String domainName = this.nameFactory.getDomainName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(organizationId), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((organizationId, serviceInstanceId, spaceId) -> createAndBindRoute(this.cloudFoundryClient, domainName, organizationId, spaceId, serviceInstanceId) - .thenReturn(serviceInstanceId))) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .delete(DeleteServiceInstanceRequest.builder() - .async(true) - .purge(false) - .recursive(true) - .serviceInstanceId(serviceInstanceId) - .build())) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), (JobEntity) ResourceUtils.getEntity(job))) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName) - .filter(resource -> serviceInstanceName.equals(resource.getEntity().getName()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(organizationId), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (organizationId, serviceInstanceId, spaceId) -> + createAndBindRoute( + this.cloudFoundryClient, + domainName, + organizationId, + spaceId, + serviceInstanceId) + .thenReturn(serviceInstanceId))) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .delete( + DeleteServiceInstanceRequest.builder() + .async(true) + .purge(false) + .recursive(true) + .serviceInstanceId(serviceInstanceId) + .build())) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + (JobEntity) ResourceUtils.getEntity(job))) + .thenMany( + requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName) + .filter( + resource -> + serviceInstanceName.equals( + resource.getEntity().getName()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -309,27 +482,46 @@ public void get() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .get(GetServiceInstanceRequest.builder() - .serviceInstanceId(serviceInstanceId) - .build())) - .map(response -> response.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .get( + GetServiceInstanceRequest.builder() + .serviceInstanceId(serviceInstanceId) + .build())) + .map(response -> response.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getNotFound() { - this.cloudFoundryClient.serviceInstances() - .get(GetServiceInstanceRequest.builder() - .serviceInstanceId("test-service-instance-id") - .build()) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-ServiceInstanceNotFound\\([0-9]+\\): The service instance could not be found: .*")) - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .serviceInstances() + .get( + GetServiceInstanceRequest.builder() + .serviceInstanceId("test-service-instance-id") + .build()) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-ServiceInstanceNotFound\\([0-9]+\\): The" + + " service instance could not be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -337,17 +529,31 @@ public void list() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .page(page) - .build()))) - .filter(resource -> serviceInstanceName.equals(ResourceUtils.getEntity(resource).getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest.builder() + .page(page) + .build()))) + .filter( + resource -> + serviceInstanceName.equals( + ResourceUtils.getEntity(resource).getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -355,40 +561,68 @@ public void listFilterByName() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .name(serviceInstanceName) - .page(page) - .build()))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest.builder() + .name(serviceInstanceName) + .page(page) + .build()))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByOrganizationId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId) - .thenReturn(organizationId))) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .filter(resource -> serviceInstanceName.equals(ResourceUtils.getEntity(resource).getName())) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId) + .thenReturn(organizationId))) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest + .builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .filter( + resource -> + serviceInstanceName.equals( + ResourceUtils.getEntity(resource).getName())) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -397,22 +631,42 @@ public void listFilterByServiceBindingId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId) - )) - .flatMap(function((applicationId, serviceInstanceId) -> createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId))) - .flatMapMany(serviceBindingId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .serviceBindingId(serviceBindingId) - .page(page) - .build()))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .flatMap( + function( + (applicationId, serviceInstanceId) -> + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId))) + .flatMapMany( + serviceBindingId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest + .builder() + .serviceBindingId( + serviceBindingId) + .page(page) + .build()))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -421,44 +675,80 @@ public void listFilterByServiceKeyId() { String serviceKeyName = this.nameFactory.getServiceKeyName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> createServiceKeyId(this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) - .flatMapMany(serviceKeyId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .serviceKeyId(serviceKeyId) - .page(page) - .build()))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + createServiceKeyId( + this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) + .flatMapMany( + serviceKeyId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest + .builder() + .serviceKeyId(serviceKeyId) + .page(page) + .build()))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByServicePlanId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> Mono.zip( - getPlanId(this.cloudFoundryClient, serviceBrokerId, this.serviceName), - Mono.just(spaceId) - ))) - .flatMap(function((planId, spaceId) -> requestCreateServiceInstance(this.cloudFoundryClient, planId, serviceInstanceName, spaceId) - .thenReturn(planId))) - .flatMapMany(planId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .page(page) - .servicePlanId(planId) - .build()))) - .filter(resource -> serviceInstanceName.equals(ResourceUtils.getEntity(resource).getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + Mono.zip( + getPlanId( + this.cloudFoundryClient, + serviceBrokerId, + this.serviceName), + Mono.just(spaceId)))) + .flatMap( + function( + (planId, spaceId) -> + requestCreateServiceInstance( + this.cloudFoundryClient, + planId, + serviceInstanceName, + spaceId) + .thenReturn(planId))) + .flatMapMany( + planId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest + .builder() + .page(page) + .servicePlanId(planId) + .build()))) + .filter( + resource -> + serviceInstanceName.equals( + ResourceUtils.getEntity(resource).getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -466,19 +756,32 @@ public void listFilterBySpaceId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .delayUntil(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMapMany(spaceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .page(page) - .spaceId(spaceId) - .build()))) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .filter(serviceInstanceName::equals) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest + .builder() + .page(page) + .spaceId(spaceId) + .build()))) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .filter(serviceInstanceName::equals) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -488,30 +791,64 @@ public void listRoutes() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((domainId, serviceInstanceId, spaceId) -> Mono.zip( - createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId), - Mono.just(serviceInstanceId)) - )) - .flatMap(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId) - .thenReturn(serviceInstanceId))) - .flatMapMany(serviceInstanceId -> Mono.zip( - Mono.just(serviceInstanceId), - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .listRoutes(ListServiceInstanceRoutesRequest.builder() - .page(page) - .serviceInstanceId(serviceInstanceId) - .build())) - .map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId()) - .single())) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (domainId, serviceInstanceId, spaceId) -> + Mono.zip( + createRouteId( + this.cloudFoundryClient, + domainId, + hostName, + null, + spaceId), + Mono.just(serviceInstanceId)))) + .flatMap( + function( + (routeId, serviceInstanceId) -> + requestBindServiceInstanceRoute( + this.cloudFoundryClient, + routeId, + serviceInstanceId) + .thenReturn(serviceInstanceId))) + .flatMapMany( + serviceInstanceId -> + Mono.zip( + Mono.just(serviceInstanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .listRoutes( + ListServiceInstanceRoutesRequest + .builder() + .page(page) + .serviceInstanceId( + serviceInstanceId) + .build())) + .map( + resource -> + ResourceUtils.getEntity(resource) + .getServiceInstanceId()) + .single())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -521,32 +858,71 @@ public void listRoutesFilterByDomainId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((domainId, serviceInstanceId, spaceId) -> Mono.zip( - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId), - Mono.just(serviceInstanceId)) - )) - .flatMap(function((domainId, routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId) - .thenReturn(Tuples.of(domainId, serviceInstanceId)))) - .flatMapMany(function((domainId, serviceInstanceId) -> Mono.zip( - Mono.just(serviceInstanceId), - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .listRoutes(ListServiceInstanceRoutesRequest.builder() - .domainId(domainId) - .page(page) - .serviceInstanceId(serviceInstanceId) - .build())) - .map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId()) - .single()))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (domainId, serviceInstanceId, spaceId) -> + Mono.zip( + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + hostName, + null, + spaceId), + Mono.just(serviceInstanceId)))) + .flatMap( + function( + (domainId, routeId, serviceInstanceId) -> + requestBindServiceInstanceRoute( + this.cloudFoundryClient, + routeId, + serviceInstanceId) + .thenReturn( + Tuples.of(domainId, serviceInstanceId)))) + .flatMapMany( + function( + (domainId, serviceInstanceId) -> + Mono.zip( + Mono.just(serviceInstanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .listRoutes( + ListServiceInstanceRoutesRequest + .builder() + .domainId( + domainId) + .page( + page) + .serviceInstanceId( + serviceInstanceId) + .build())) + .map( + resource -> + ResourceUtils.getEntity( + resource) + .getServiceInstanceId()) + .single()))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -556,31 +932,66 @@ public void listRoutesFilterByHost() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((domainId, serviceInstanceId, spaceId) -> Mono.zip( - createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId), - Mono.just(serviceInstanceId)) - )) - .flatMap(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId) - .thenReturn(serviceInstanceId))) - .flatMapMany(serviceInstanceId -> Mono.zip( - Mono.just(serviceInstanceId), - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .listRoutes(ListServiceInstanceRoutesRequest.builder() - .host(hostName) - .page(page) - .serviceInstanceId(serviceInstanceId) - .build())) - .map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId()) - .single())) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (domainId, serviceInstanceId, spaceId) -> + Mono.zip( + createRouteId( + this.cloudFoundryClient, + domainId, + hostName, + null, + spaceId), + Mono.just(serviceInstanceId)))) + .flatMap( + function( + (routeId, serviceInstanceId) -> + requestBindServiceInstanceRoute( + this.cloudFoundryClient, + routeId, + serviceInstanceId) + .thenReturn(serviceInstanceId))) + .flatMapMany( + serviceInstanceId -> + Mono.zip( + Mono.just(serviceInstanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .listRoutes( + ListServiceInstanceRoutesRequest + .builder() + .host( + hostName) + .page(page) + .serviceInstanceId( + serviceInstanceId) + .build())) + .map( + resource -> + ResourceUtils.getEntity(resource) + .getServiceInstanceId()) + .single())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -590,31 +1001,65 @@ public void listRoutesFilterByPath() { String path = this.nameFactory.getPath(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((domainId, serviceInstanceId, spaceId) -> Mono.zip( - createRouteId(this.cloudFoundryClient, domainId, null, path, spaceId), - Mono.just(serviceInstanceId)) - )) - .flatMap(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId) - .thenReturn(serviceInstanceId))) - .flatMapMany(serviceInstanceId -> Mono.zip( - Mono.just(serviceInstanceId), - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .listRoutes(ListServiceInstanceRoutesRequest.builder() - .page(page) - .path(path) - .serviceInstanceId(serviceInstanceId) - .build())) - .map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId()) - .single())) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (domainId, serviceInstanceId, spaceId) -> + Mono.zip( + createRouteId( + this.cloudFoundryClient, + domainId, + null, + path, + spaceId), + Mono.just(serviceInstanceId)))) + .flatMap( + function( + (routeId, serviceInstanceId) -> + requestBindServiceInstanceRoute( + this.cloudFoundryClient, + routeId, + serviceInstanceId) + .thenReturn(serviceInstanceId))) + .flatMapMany( + serviceInstanceId -> + Mono.zip( + Mono.just(serviceInstanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .listRoutes( + ListServiceInstanceRoutesRequest + .builder() + .page(page) + .path(path) + .serviceInstanceId( + serviceInstanceId) + .build())) + .map( + resource -> + ResourceUtils.getEntity(resource) + .getServiceInstanceId()) + .single())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -623,26 +1068,50 @@ public void listServiceBindings() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId) - )) - .delayUntil(function((applicationId, serviceInstanceId) -> createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId))) - .flatMapMany(function((applicationId, serviceInstanceId) -> Mono.zip( - Mono.just(applicationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .listServiceBindings(ListServiceInstanceServiceBindingsRequest.builder() - .serviceInstanceId(serviceInstanceId) - .page(page) - .build())) - .single() - .map(resource -> resource.getEntity().getApplicationId()) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .delayUntil( + function( + (applicationId, serviceInstanceId) -> + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId))) + .flatMapMany( + function( + (applicationId, serviceInstanceId) -> + Mono.zip( + Mono.just(applicationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .listServiceBindings( + ListServiceInstanceServiceBindingsRequest + .builder() + .serviceInstanceId( + serviceInstanceId) + .page( + page) + .build())) + .single() + .map( + resource -> + resource.getEntity() + .getApplicationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -651,22 +1120,44 @@ public void listServiceBindingsFilterByApplicationId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId) - )) - .delayUntil(function((applicationId, serviceInstanceId) -> createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId))) - .flatMapMany(function((applicationId, serviceInstanceId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceInstances() - .listServiceBindings(ListServiceInstanceServiceBindingsRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(serviceInstanceId) - .page(page) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .delayUntil( + function( + (applicationId, serviceInstanceId) -> + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId))) + .flatMapMany( + function( + (applicationId, serviceInstanceId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceInstances() + .listServiceBindings( + ListServiceInstanceServiceBindingsRequest + .builder() + .applicationId( + applicationId) + .serviceInstanceId( + serviceInstanceId) + .page(page) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -675,29 +1166,62 @@ public void unbindRoute() { String hostName = this.nameFactory.getHostName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId), - createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((domainId, serviceInstanceId, spaceId) -> Mono.zip( - createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId), - Mono.just(serviceInstanceId)) - )) - .flatMap(function((routeId, serviceInstanceId) -> requestBindServiceInstanceRoute(this.cloudFoundryClient, routeId, serviceInstanceId) - .then(this.cloudFoundryClient.serviceInstances() - .unbindRoute(UnbindServiceInstanceRouteRequest.builder() - .routeId(routeId) - .serviceInstanceId(serviceInstanceId) - .build())) - .thenReturn(serviceInstanceId))) - .flatMapMany(serviceInstanceId -> requestListRoutes(this.cloudFoundryClient, serviceInstanceId) - .filter(route -> serviceInstanceId.equals(route.getEntity().getServiceInstanceId()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.organizationId, this.spaceId) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (domainId, serviceInstanceId, spaceId) -> + Mono.zip( + createRouteId( + this.cloudFoundryClient, + domainId, + hostName, + null, + spaceId), + Mono.just(serviceInstanceId)))) + .flatMap( + function( + (routeId, serviceInstanceId) -> + requestBindServiceInstanceRoute( + this.cloudFoundryClient, + routeId, + serviceInstanceId) + .then( + this.cloudFoundryClient + .serviceInstances() + .unbindRoute( + UnbindServiceInstanceRouteRequest + .builder() + .routeId(routeId) + .serviceInstanceId( + serviceInstanceId) + .build())) + .thenReturn(serviceInstanceId))) + .flatMapMany( + serviceInstanceId -> + requestListRoutes(this.cloudFoundryClient, serviceInstanceId) + .filter( + route -> + serviceInstanceId.equals( + route.getEntity() + .getServiceInstanceId()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -706,17 +1230,30 @@ public void update() { String newServiceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, oldServiceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .update(UpdateServiceInstanceRequest.builder() - .name(newServiceInstanceName) - .serviceInstanceId(serviceInstanceId) - .build())) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, newServiceInstanceName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + oldServiceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .update( + UpdateServiceInstanceRequest.builder() + .name(newServiceInstanceName) + .serviceInstanceId(serviceInstanceId) + .build())) + .thenMany( + requestListServiceInstances( + this.cloudFoundryClient, newServiceInstanceName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -725,18 +1262,31 @@ public void updateEmptyCollections() { String newServiceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, oldServiceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .update(UpdateServiceInstanceRequest.builder() - .name(newServiceInstanceName) - .parameters(Collections.emptyMap()) - .serviceInstanceId(serviceInstanceId) - .build())) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, newServiceInstanceName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + oldServiceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .update( + UpdateServiceInstanceRequest.builder() + .name(newServiceInstanceName) + .parameters(Collections.emptyMap()) + .serviceInstanceId(serviceInstanceId) + .build())) + .thenMany( + requestListServiceInstances( + this.cloudFoundryClient, newServiceInstanceName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -745,166 +1295,263 @@ public void upgrade() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstances() - .update(UpdateServiceInstanceRequest.builder() - .maintenanceInfo(MaintenanceInfo.builder() - .description("test-update") - .version("9.9") - .build()) - .serviceInstanceId(serviceInstanceId) - .build())) - .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) - .map(resource -> ResourceUtils.getEntity(resource).getMaintenanceInfo().getVersion()) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-MaintenanceInfoNotSupported\\([0-9]+\\): The service broker does not support upgrades " + - "for service instances created from this plan.")) - .verify(Duration.ofMinutes(5)); - } - - private static Mono createAndBindRoute(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId, String spaceId, String - serviceInstanceId) { + .flatMap( + spaceId -> + createServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstances() + .update( + UpdateServiceInstanceRequest.builder() + .maintenanceInfo( + MaintenanceInfo.builder() + .description("test-update") + .version("9.9") + .build()) + .serviceInstanceId(serviceInstanceId) + .build())) + .thenMany(requestListServiceInstances(this.cloudFoundryClient, serviceInstanceName)) + .map( + resource -> + ResourceUtils.getEntity(resource).getMaintenanceInfo().getVersion()) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-MaintenanceInfoNotSupported\\([0-9]+\\): The" + + " service broker does not support upgrades" + + " for service instances created from this" + + " plan.")) + .verify(Duration.ofMinutes(5)); + } + + private static Mono createAndBindRoute( + CloudFoundryClient cloudFoundryClient, + String domainName, + String organizationId, + String spaceId, + String serviceInstanceId) { return createPrivateDomainId(cloudFoundryClient, domainName, organizationId) - .flatMap(domainId -> createRouteId(cloudFoundryClient, domainId, null, null, spaceId)) - .flatMap(routeId -> requestBindServiceInstanceRoute(cloudFoundryClient, routeId, serviceInstanceId)); + .flatMap( + domainId -> + createRouteId(cloudFoundryClient, domainId, null, null, spaceId)) + .flatMap( + routeId -> + requestBindServiceInstanceRoute( + cloudFoundryClient, routeId, serviceInstanceId)); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createPrivateDomainId(CloudFoundryClient cloudFoundryClient, String name, String organizationId) { + private static Mono createPrivateDomainId( + CloudFoundryClient cloudFoundryClient, String name, String organizationId) { return requestCreatePrivateDomain(cloudFoundryClient, name, organizationId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String path, String spaceId) { + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, + String domainId, + String hostName, + String path, + String spaceId) { return requestCreateRoute(cloudFoundryClient, domainId, hostName, path, spaceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createServiceBindingId(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + private static Mono createServiceBindingId( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { return requestCreateServiceBinding(cloudFoundryClient, applicationId, serviceInstanceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createServiceInstanceId(CloudFoundryClient cloudFoundryClient, Mono serviceBrokerId, String serviceInstanceName, String serviceName, String spaceId) { + private static Mono createServiceInstanceId( + CloudFoundryClient cloudFoundryClient, + Mono serviceBrokerId, + String serviceInstanceName, + String serviceName, + String spaceId) { return serviceBrokerId - .flatMap(s -> getPlanId(cloudFoundryClient, s, serviceName)) - .flatMap(planId -> requestCreateServiceInstance(cloudFoundryClient, planId, serviceInstanceName, spaceId)) - .map(ResourceUtils::getId); + .flatMap(s -> getPlanId(cloudFoundryClient, s, serviceName)) + .flatMap( + planId -> + requestCreateServiceInstance( + cloudFoundryClient, planId, serviceInstanceName, spaceId)) + .map(ResourceUtils::getId); } - private static Mono createServiceKeyId(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String serviceKeyName) { + private static Mono createServiceKeyId( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceId, + String serviceKeyName) { return requestCreateServiceKey(cloudFoundryClient, serviceInstanceId, serviceKeyName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getPlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + private static Mono getPlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { return requestListServices(cloudFoundryClient, serviceBrokerId, serviceName) - .filter(resource -> serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) - .single() - .map(ResourceUtils::getId) - .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) - .single() - .map(ResourceUtils::getId); - } - - private static Mono requestBindServiceInstanceRoute(CloudFoundryClient cloudFoundryClient, String routeId, String serviceInstanceId) { - return cloudFoundryClient.serviceInstances() - .bindRoute(BindServiceInstanceRouteRequest.builder() - .routeId(routeId) - .serviceInstanceId(serviceInstanceId) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreatePrivateDomain(CloudFoundryClient cloudFoundryClient, String name, String organizationId) { - return cloudFoundryClient.privateDomains() - .create(CreatePrivateDomainRequest.builder() - .name(name) - .owningOrganizationId(organizationId) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String path, String spaceId) { - return cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .host(hostName) - .path(path) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreateServiceBinding(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { - return cloudFoundryClient.serviceBindingsV2() - .create(CreateServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(serviceInstanceId) - .build()); - } - - private static Mono requestCreateServiceInstance(CloudFoundryClient cloudFoundryClient, String planId, String serviceInstanceName, String spaceId) { - return cloudFoundryClient.serviceInstances() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .parameter("test-key", "test-value") - .servicePlanId(planId) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreateServiceKey(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String serviceKeyName) { - return cloudFoundryClient.serviceKeys() - .create(CreateServiceKeyRequest.builder() - .name(serviceKeyName) - .serviceInstanceId(serviceInstanceId) - .build()); - } - - private static Flux requestListRoutes(CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceInstances() - .listRoutes(ListServiceInstanceRoutesRequest.builder() - .page(page) - .serviceInstanceId(serviceInstanceId) - .build())); - } - - private static Flux requestListServiceInstances(CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .name(serviceInstanceName) - .page(page) - .build())); - } - - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceId(serviceId) - .build())); - } - - private static Flux requestListServices(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build())); + .filter( + resource -> + serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) + .single() + .map(ResourceUtils::getId) + .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) + .single() + .map(ResourceUtils::getId); + } + + private static Mono requestBindServiceInstanceRoute( + CloudFoundryClient cloudFoundryClient, String routeId, String serviceInstanceId) { + return cloudFoundryClient + .serviceInstances() + .bindRoute( + BindServiceInstanceRouteRequest.builder() + .routeId(routeId) + .serviceInstanceId(serviceInstanceId) + .build()); } + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreatePrivateDomain( + CloudFoundryClient cloudFoundryClient, String name, String organizationId) { + return cloudFoundryClient + .privateDomains() + .create( + CreatePrivateDomainRequest.builder() + .name(name) + .owningOrganizationId(organizationId) + .build()); + } + + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, + String domainId, + String hostName, + String path, + String spaceId) { + return cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .domainId(domainId) + .host(hostName) + .path(path) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreateServiceBinding( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + return cloudFoundryClient + .serviceBindingsV2() + .create( + CreateServiceBindingRequest.builder() + .applicationId(applicationId) + .serviceInstanceId(serviceInstanceId) + .build()); + } + + private static Mono requestCreateServiceInstance( + CloudFoundryClient cloudFoundryClient, + String planId, + String serviceInstanceName, + String spaceId) { + return cloudFoundryClient + .serviceInstances() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .parameter("test-key", "test-value") + .servicePlanId(planId) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreateServiceKey( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceId, + String serviceKeyName) { + return cloudFoundryClient + .serviceKeys() + .create( + CreateServiceKeyRequest.builder() + .name(serviceKeyName) + .serviceInstanceId(serviceInstanceId) + .build()); + } + + private static Flux requestListRoutes( + CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceInstances() + .listRoutes( + ListServiceInstanceRoutesRequest.builder() + .page(page) + .serviceInstanceId(serviceInstanceId) + .build())); + } + + private static Flux requestListServiceInstances( + CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest.builder() + .name(serviceInstanceName) + .page(page) + .build())); + } + + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceId(serviceId) + .build())); + } + + private static Flux requestListServices( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .list( + ListServicesRequest.builder() + .page(page) + .serviceBrokerId(serviceBrokerId) + .build())); + } } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceKeysTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceKeysTest.java index ae12918d5c9..58067e0d31f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceKeysTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceKeysTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.serviceinstances.CreateServiceInstanceRequest; @@ -33,28 +36,21 @@ import org.cloudfoundry.client.v2.services.ServiceResource; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ServiceKeysTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @SuppressWarnings("unchecked") @Test @@ -62,22 +58,34 @@ public void create() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId))) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceKeys() - .create(CreateServiceKeyRequest.builder() - .parameter("test-key", "test-value") - .name(serviceKeyName) - .serviceInstanceId(serviceInstanceId) - .build()) - .map(ResourceUtils::getId)) - .flatMap(serviceKeyId -> requestGetServiceKey(this.cloudFoundryClient, serviceKeyId)) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(serviceKeyName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceKeys() + .create( + CreateServiceKeyRequest.builder() + .parameter("test-key", "test-value") + .name(serviceKeyName) + .serviceInstanceId(serviceInstanceId) + .build()) + .map(ResourceUtils::getId)) + .flatMap( + serviceKeyId -> requestGetServiceKey(this.cloudFoundryClient, serviceKeyId)) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(serviceKeyName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -85,19 +93,35 @@ public void delete() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId))) - .flatMap(serviceInstanceId -> createServiceKeyId(this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) - .flatMap(serviceKeyId -> this.cloudFoundryClient.serviceKeys() - .delete(DeleteServiceKeyRequest.builder() - .serviceKeyId(serviceKeyId) - .build())) - .thenMany(requestListServiceKeys(this.cloudFoundryClient)) - .filter(response -> serviceKeyName.equals(ResourceUtils.getEntity(response).getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .flatMap( + serviceInstanceId -> + createServiceKeyId( + this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) + .flatMap( + serviceKeyId -> + this.cloudFoundryClient + .serviceKeys() + .delete( + DeleteServiceKeyRequest.builder() + .serviceKeyId(serviceKeyId) + .build())) + .thenMany(requestListServiceKeys(this.cloudFoundryClient)) + .filter( + response -> + serviceKeyName.equals(ResourceUtils.getEntity(response).getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -105,19 +129,33 @@ public void get() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId))) - .flatMap(serviceInstanceId -> createServiceKeyId(this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) - .flatMap(serviceKeyId -> this.cloudFoundryClient.serviceKeys() - .get(GetServiceKeyRequest.builder() - .serviceKeyId(serviceKeyId) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(serviceKeyName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .flatMap( + serviceInstanceId -> + createServiceKeyId( + this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) + .flatMap( + serviceKeyId -> + this.cloudFoundryClient + .serviceKeys() + .get( + GetServiceKeyRequest.builder() + .serviceKeyId(serviceKeyId) + .build())) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(serviceKeyName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -125,21 +163,35 @@ public void list() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId))) - .flatMap(serviceInstanceId -> createServiceKeyId(this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceKeys() - .list(ListServiceKeysRequest.builder() - .page(page) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName())) - .filter(serviceKeyName::equals) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .flatMap( + serviceInstanceId -> + createServiceKeyId( + this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceKeys() + .list( + ListServiceKeysRequest.builder() + .page(page) + .build())) + .map(response -> ResourceUtils.getEntity(response).getName())) + .filter(serviceKeyName::equals) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -147,21 +199,35 @@ public void listFilterByName() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId))) - .flatMap(serviceInstanceId -> createServiceKeyId(this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceKeys() - .list(ListServiceKeysRequest.builder() - .name(serviceKeyName) - .page(page) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName())) - .as(StepVerifier::create) - .expectNext(serviceKeyName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .flatMap( + serviceInstanceId -> + createServiceKeyId( + this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceKeys() + .list( + ListServiceKeysRequest.builder() + .name(serviceKeyName) + .page(page) + .build())) + .map(response -> ResourceUtils.getEntity(response).getName())) + .as(StepVerifier::create) + .expectNext(serviceKeyName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -169,91 +235,143 @@ public void listFilterByServiceInstanceId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId))) - .delayUntil(serviceInstanceId -> createServiceKeyId(this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) - .flatMapMany(serviceInstanceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.serviceKeys() - .list(ListServiceKeysRequest.builder() - .page(page) - .serviceInstanceId(serviceInstanceId) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName())) - .as(StepVerifier::create) - .expectNext(serviceKeyName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId))) + .delayUntil( + serviceInstanceId -> + createServiceKeyId( + this.cloudFoundryClient, serviceInstanceId, serviceKeyName)) + .flatMapMany( + serviceInstanceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .serviceKeys() + .list( + ListServiceKeysRequest + .builder() + .page(page) + .serviceInstanceId( + serviceInstanceId) + .build())) + .map( + response -> + ResourceUtils.getEntity(response) + .getName())) + .as(StepVerifier::create) + .expectNext(serviceKeyName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createServiceInstanceId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceInstanceName, String serviceName, String spaceId) { + private static Mono createServiceInstanceId( + CloudFoundryClient cloudFoundryClient, + String serviceBrokerId, + String serviceInstanceName, + String serviceName, + String spaceId) { return getPlanId(cloudFoundryClient, serviceBrokerId, serviceName) - .flatMap(planId -> requestCreateServiceInstance(cloudFoundryClient, planId, serviceInstanceName, spaceId)) - .map(ResourceUtils::getId); + .flatMap( + planId -> + requestCreateServiceInstance( + cloudFoundryClient, planId, serviceInstanceName, spaceId)) + .map(ResourceUtils::getId); } - private static Mono createServiceKeyId(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String serviceKeyName) { + private static Mono createServiceKeyId( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceId, + String serviceKeyName) { return requestCreateServiceKey(cloudFoundryClient, serviceInstanceId, serviceKeyName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getPlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + private static Mono getPlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { return requestListServices(cloudFoundryClient, serviceBrokerId, serviceName) - .single() - .map(ResourceUtils::getId) - .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) - .single() - .map(ResourceUtils::getId); + .single() + .map(ResourceUtils::getId) + .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) + .single() + .map(ResourceUtils::getId); } - private static Mono requestCreateServiceInstance(CloudFoundryClient cloudFoundryClient, String planId, String serviceInstanceName, String spaceId) { - return cloudFoundryClient.serviceInstances() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .servicePlanId(planId) - .spaceId(spaceId) - .build()); + private static Mono requestCreateServiceInstance( + CloudFoundryClient cloudFoundryClient, + String planId, + String serviceInstanceName, + String spaceId) { + return cloudFoundryClient + .serviceInstances() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .servicePlanId(planId) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateServiceKey(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String serviceKeyName) { - return cloudFoundryClient.serviceKeys() - .create(CreateServiceKeyRequest.builder() - .name(serviceKeyName) - .serviceInstanceId(serviceInstanceId) - .build()); + private static Mono requestCreateServiceKey( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceId, + String serviceKeyName) { + return cloudFoundryClient + .serviceKeys() + .create( + CreateServiceKeyRequest.builder() + .name(serviceKeyName) + .serviceInstanceId(serviceInstanceId) + .build()); } - private static Mono requestGetServiceKey(CloudFoundryClient cloudFoundryClient, String serviceKeyId) { - return cloudFoundryClient.serviceKeys() - .get(GetServiceKeyRequest.builder() - .serviceKeyId(serviceKeyId) - .build()); + private static Mono requestGetServiceKey( + CloudFoundryClient cloudFoundryClient, String serviceKeyId) { + return cloudFoundryClient + .serviceKeys() + .get(GetServiceKeyRequest.builder().serviceKeyId(serviceKeyId).build()); } - private static Flux requestListServiceKeys(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.serviceKeys() - .list(ListServiceKeysRequest.builder() - .page(page) - .build())); + private static Flux requestListServiceKeys( + CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceKeys() + .list(ListServiceKeysRequest.builder().page(page).build())); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceId(serviceId) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceId(serviceId) + .build())); } - private static Flux requestListServices(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .page(page) - .label(serviceName) - .serviceBrokerId(serviceBrokerId) - .build())); + private static Flux requestListServices( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .list( + ListServicesRequest.builder() + .page(page) + .label(serviceName) + .serviceBrokerId(serviceBrokerId) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicePlanVisibilitiesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicePlanVisibilitiesTest.java index 88a2d31b1c2..fff382a4cb7 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicePlanVisibilitiesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicePlanVisibilitiesTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; +import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.ServiceBrokerUtils; import org.cloudfoundry.client.CloudFoundryClient; @@ -35,25 +40,18 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuples; -import java.time.Duration; - -import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; -import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ServicePlanVisibilitiesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; @Test public void create() { @@ -62,31 +60,62 @@ public void create() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); - - Mono - .zip( - this.organizationId, - getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - ) - .delayUntil(function((organizationId, servicePlanId) -> this.cloudFoundryClient.servicePlanVisibilities() - .create(CreateServicePlanVisibilityRequest.builder() - .organizationId(organizationId) - .servicePlanId(servicePlanId) - .build()))) - .flatMapMany(function((organizationId, servicePlanId) -> requestListServicePlanVisibilities(this.cloudFoundryClient, servicePlanId) - .single() - .flatMap(response -> Mono.just(Tuples.of(ResourceUtils.getEntity(response).getOrganizationId(), organizationId))))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); + + Mono.zip( + this.organizationId, + getServicePlanId( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .delayUntil( + function( + (organizationId, servicePlanId) -> + this.cloudFoundryClient + .servicePlanVisibilities() + .create( + CreateServicePlanVisibilityRequest.builder() + .organizationId(organizationId) + .servicePlanId(servicePlanId) + .build()))) + .flatMapMany( + function( + (organizationId, servicePlanId) -> + requestListServicePlanVisibilities( + this.cloudFoundryClient, servicePlanId) + .single() + .flatMap( + response -> + Mono.just( + Tuples.of( + ResourceUtils + .getEntity( + response) + .getOrganizationId(), + organizationId))))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -96,34 +125,67 @@ public void delete() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); - - Mono - .zip( - this.organizationId, - getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - ) - .flatMap(function((organizationId, servicePlanId) -> Mono.zip( - Mono.just(servicePlanId), - createServicePlanVisibilityId(this.cloudFoundryClient, organizationId, servicePlanId) - ))) - .flatMap(function((servicePlanId, servicePlanIdVisibilityId) -> this.cloudFoundryClient.servicePlanVisibilities() - .delete(DeleteServicePlanVisibilityRequest.builder() - .async(true) - .servicePlanVisibilityId(servicePlanIdVisibilityId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .thenReturn(servicePlanId))) - .flatMapMany(servicePlanId -> requestListServicePlanVisibilities(this.cloudFoundryClient, servicePlanId)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); + + Mono.zip( + this.organizationId, + getServicePlanId( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .flatMap( + function( + (organizationId, servicePlanId) -> + Mono.zip( + Mono.just(servicePlanId), + createServicePlanVisibilityId( + this.cloudFoundryClient, + organizationId, + servicePlanId)))) + .flatMap( + function( + (servicePlanId, servicePlanIdVisibilityId) -> + this.cloudFoundryClient + .servicePlanVisibilities() + .delete( + DeleteServicePlanVisibilityRequest.builder() + .async(true) + .servicePlanVisibilityId( + servicePlanIdVisibilityId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .thenReturn(servicePlanId))) + .flatMapMany( + servicePlanId -> + requestListServicePlanVisibilities( + this.cloudFoundryClient, servicePlanId)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -133,33 +195,61 @@ public void deleteAsyncFalse() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); - - Mono - .zip( - this.organizationId, - getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - ) - .flatMap(function((organizationId, servicePlanId) -> Mono.zip( - Mono.just(servicePlanId), - createServicePlanVisibilityId(this.cloudFoundryClient, organizationId, servicePlanId) - ))) - .flatMap(function((servicePlanId, servicePlanIdVisibilityId) -> this.cloudFoundryClient.servicePlanVisibilities() - .delete(DeleteServicePlanVisibilityRequest.builder() - .async(false) - .servicePlanVisibilityId(servicePlanIdVisibilityId) - .build()) - .thenReturn(servicePlanId))) - .flatMapMany(servicePlanId -> requestListServicePlanVisibilities(this.cloudFoundryClient, servicePlanId)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); + + Mono.zip( + this.organizationId, + getServicePlanId( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .flatMap( + function( + (organizationId, servicePlanId) -> + Mono.zip( + Mono.just(servicePlanId), + createServicePlanVisibilityId( + this.cloudFoundryClient, + organizationId, + servicePlanId)))) + .flatMap( + function( + (servicePlanId, servicePlanIdVisibilityId) -> + this.cloudFoundryClient + .servicePlanVisibilities() + .delete( + DeleteServicePlanVisibilityRequest.builder() + .async(false) + .servicePlanVisibilityId( + servicePlanIdVisibilityId) + .build()) + .thenReturn(servicePlanId))) + .flatMapMany( + servicePlanId -> + requestListServicePlanVisibilities( + this.cloudFoundryClient, servicePlanId)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -169,35 +259,64 @@ public void get() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); - - Mono - .zip( - this.organizationId, - getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - ) - .flatMap(function((organizationId, servicePlanId) -> Mono.zip( - Mono.just(organizationId), - createServicePlanVisibilityId(this.cloudFoundryClient, organizationId, servicePlanId) - ))) - .flatMap(function((organizationId, servicePlanVisibilityId) -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.servicePlanVisibilities() - .get(GetServicePlanVisibilityRequest.builder() - .servicePlanVisibilityId(servicePlanVisibilityId) - .build()) - .map(response -> ResourceUtils.getEntity(response).getOrganizationId()) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); + + Mono.zip( + this.organizationId, + getServicePlanId( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .flatMap( + function( + (organizationId, servicePlanId) -> + Mono.zip( + Mono.just(organizationId), + createServicePlanVisibilityId( + this.cloudFoundryClient, + organizationId, + servicePlanId)))) + .flatMap( + function( + (organizationId, servicePlanVisibilityId) -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .servicePlanVisibilities() + .get( + GetServicePlanVisibilityRequest + .builder() + .servicePlanVisibilityId( + servicePlanVisibilityId) + .build()) + .map( + response -> + ResourceUtils.getEntity( + response) + .getOrganizationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -207,38 +326,74 @@ public void list() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); - - Mono - .zip( - this.organizationId, - getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - ) - .flatMap(function((organizationId, servicePlanId) -> Mono.zip( - Mono.just(organizationId), - createServicePlanVisibilityId(this.cloudFoundryClient, organizationId, servicePlanId) - ))) - .flatMapMany(function((organizationId, servicePlanVisibilityId) -> Mono.zip( - Mono.just(organizationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlanVisibilities() - .list(ListServicePlanVisibilitiesRequest.builder() - .page(page) - .build())) - .filter(response -> servicePlanVisibilityId.equals(ResourceUtils.getId(response))) - .single() - .map(response -> ResourceUtils.getEntity(response).getOrganizationId()) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); + + Mono.zip( + this.organizationId, + getServicePlanId( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .flatMap( + function( + (organizationId, servicePlanId) -> + Mono.zip( + Mono.just(organizationId), + createServicePlanVisibilityId( + this.cloudFoundryClient, + organizationId, + servicePlanId)))) + .flatMapMany( + function( + (organizationId, servicePlanVisibilityId) -> + Mono.zip( + Mono.just(organizationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlanVisibilities() + .list( + ListServicePlanVisibilitiesRequest + .builder() + .page( + page) + .build())) + .filter( + response -> + servicePlanVisibilityId + .equals( + ResourceUtils + .getId( + response))) + .single() + .map( + response -> + ResourceUtils.getEntity( + response) + .getOrganizationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -248,39 +403,76 @@ public void listFilterByOrganizationId() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); - - Mono - .zip( - this.organizationId, - getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - ) - .flatMap(function((organizationId, servicePlanId) -> Mono.zip( - Mono.just(organizationId), - createServicePlanVisibilityId(this.cloudFoundryClient, organizationId, servicePlanId) - ))) - .flatMapMany(function((organizationId, servicePlanVisibilityId) -> Mono.zip( - Mono.just(organizationId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlanVisibilities() - .list(ListServicePlanVisibilitiesRequest.builder() - .organizationId(organizationId) - .page(page) - .build())) - .filter(response -> servicePlanVisibilityId.equals(ResourceUtils.getId(response))) - .single() - .map(response -> ResourceUtils.getEntity(response).getOrganizationId()) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); + + Mono.zip( + this.organizationId, + getServicePlanId( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .flatMap( + function( + (organizationId, servicePlanId) -> + Mono.zip( + Mono.just(organizationId), + createServicePlanVisibilityId( + this.cloudFoundryClient, + organizationId, + servicePlanId)))) + .flatMapMany( + function( + (organizationId, servicePlanVisibilityId) -> + Mono.zip( + Mono.just(organizationId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlanVisibilities() + .list( + ListServicePlanVisibilitiesRequest + .builder() + .organizationId( + organizationId) + .page( + page) + .build())) + .filter( + response -> + servicePlanVisibilityId + .equals( + ResourceUtils + .getId( + response))) + .single() + .map( + response -> + ResourceUtils.getEntity( + response) + .getOrganizationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -290,38 +482,69 @@ public void listFilterByServicePlanId() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); - - Mono - .zip( - this.organizationId, - getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - ) - .flatMap(function((organizationId, servicePlanId) -> Mono.zip( - Mono.just(servicePlanId), - createServicePlanVisibilityId(this.cloudFoundryClient, organizationId, servicePlanId) - ))) - .flatMapMany(function((servicePlanId, servicePlanVisibilityId) -> Mono.zip( - Mono.just(servicePlanId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlanVisibilities() - .list(ListServicePlanVisibilitiesRequest.builder() - .servicePlanId(servicePlanId) - .page(page) - .build())) - .single() - .map(response -> ResourceUtils.getEntity(response).getServicePlanId()) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); + + Mono.zip( + this.organizationId, + getServicePlanId( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .flatMap( + function( + (organizationId, servicePlanId) -> + Mono.zip( + Mono.just(servicePlanId), + createServicePlanVisibilityId( + this.cloudFoundryClient, + organizationId, + servicePlanId)))) + .flatMapMany( + function( + (servicePlanId, servicePlanVisibilityId) -> + Mono.zip( + Mono.just(servicePlanId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlanVisibilities() + .list( + ListServicePlanVisibilitiesRequest + .builder() + .servicePlanId( + servicePlanId) + .page( + page) + .build())) + .single() + .map( + response -> + ResourceUtils.getEntity( + response) + .getServicePlanId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -332,103 +555,159 @@ public void update() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); - - Mono - .zip( - this.organizationId, - getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - ) - .flatMap(function((organizationId, servicePlanId) -> Mono.zip( - createOrganizationId(this.cloudFoundryClient, organizationName), - Mono.just(servicePlanId), - createServicePlanVisibilityId(this.cloudFoundryClient, organizationId, servicePlanId) - ))) - .flatMap(function((newOrganizationId, servicePlanId, servicePlanIdVisibilityId) -> this.cloudFoundryClient.servicePlanVisibilities() - .update(UpdateServicePlanVisibilityRequest.builder() - .organizationId(newOrganizationId) - .servicePlanId(servicePlanId) - .servicePlanVisibilityId(servicePlanIdVisibilityId) - .build()) - .thenReturn(Tuples.of(newOrganizationId, servicePlanId)))) - .flatMapMany(function((newOrganizationId, servicePlanId) -> Mono.zip( - Mono.just(newOrganizationId), - requestListServicePlanVisibilities(this.cloudFoundryClient, servicePlanId) - .single() - .map(response -> ResourceUtils.getEntity(response).getOrganizationId()) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); + + Mono.zip( + this.organizationId, + getServicePlanId( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .flatMap( + function( + (organizationId, servicePlanId) -> + Mono.zip( + createOrganizationId( + this.cloudFoundryClient, organizationName), + Mono.just(servicePlanId), + createServicePlanVisibilityId( + this.cloudFoundryClient, + organizationId, + servicePlanId)))) + .flatMap( + function( + (newOrganizationId, servicePlanId, servicePlanIdVisibilityId) -> + this.cloudFoundryClient + .servicePlanVisibilities() + .update( + UpdateServicePlanVisibilityRequest.builder() + .organizationId(newOrganizationId) + .servicePlanId(servicePlanId) + .servicePlanVisibilityId( + servicePlanIdVisibilityId) + .build()) + .thenReturn( + Tuples.of( + newOrganizationId, servicePlanId)))) + .flatMapMany( + function( + (newOrganizationId, servicePlanId) -> + Mono.zip( + Mono.just(newOrganizationId), + requestListServicePlanVisibilities( + this.cloudFoundryClient, + servicePlanId) + .single() + .map( + response -> + ResourceUtils.getEntity( + response) + .getOrganizationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createServicePlanVisibilityId(CloudFoundryClient cloudFoundryClient, String organizationId, String servicePlanId) { + private static Mono createServicePlanVisibilityId( + CloudFoundryClient cloudFoundryClient, String organizationId, String servicePlanId) { return requestCreateServicePlanVisibility(cloudFoundryClient, organizationId, servicePlanId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getServicePlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + private static Mono getServicePlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { return requestListServicePlans(cloudFoundryClient, serviceBrokerId) - .filter(resource -> "test-plan-description".equals(ResourceUtils.getEntity(resource).getDescription())) - .map(ResourceUtils::getId) - .single(); + .filter( + resource -> + "test-plan-description" + .equals(ResourceUtils.getEntity(resource).getDescription())) + .map(ResourceUtils::getId) + .single(); } - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizations() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()); + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizations() + .create(CreateOrganizationRequest.builder().name(organizationName).build()); } - private static Mono requestCreateServicePlanVisibility(CloudFoundryClient cloudFoundryClient, String organizationId, String servicePlanId) { - return cloudFoundryClient.servicePlanVisibilities() - .create(CreateServicePlanVisibilityRequest.builder() - .organizationId(organizationId) - .servicePlanId(servicePlanId) - .build()); + private static Mono requestCreateServicePlanVisibility( + CloudFoundryClient cloudFoundryClient, String organizationId, String servicePlanId) { + return cloudFoundryClient + .servicePlanVisibilities() + .create( + CreateServicePlanVisibilityRequest.builder() + .organizationId(organizationId) + .servicePlanId(servicePlanId) + .build()); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organizationId(organizationId) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organizationId(organizationId) + .build()); } - private static Flux requestListServicePlanVisibilities(CloudFoundryClient cloudFoundryClient, String servicePlanId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlanVisibilities() - .list(ListServicePlanVisibilitiesRequest.builder() - .servicePlanId(servicePlanId) - .build())); + private static Flux requestListServicePlanVisibilities( + CloudFoundryClient cloudFoundryClient, String servicePlanId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlanVisibilities() + .list( + ListServicePlanVisibilitiesRequest.builder() + .servicePlanId(servicePlanId) + .build())); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceBrokerId(serviceBrokerId) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicePlansTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicePlansTest.java index 1c609290578..c8f4db7e148 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicePlansTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicePlansTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; +import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.ServiceBrokerUtils; import org.cloudfoundry.client.CloudFoundryClient; @@ -42,36 +47,25 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; -import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ServicePlansTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private String planName; + @Autowired private String planName; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void delete() { @@ -80,26 +74,52 @@ public void delete() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - .flatMap(servicePlanId -> this.cloudFoundryClient.servicePlans() - .delete(DeleteServicePlanRequest.builder() - .async(true) - .servicePlanId(servicePlanId) - .build())) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), ResourceUtils.getEntity(job))) - .thenMany(requestListServicePlans(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(response -> serviceName.equals(ResourceUtils.getEntity(response).getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlans() + .delete( + DeleteServicePlanRequest.builder() + .async(true) + .servicePlanId(servicePlanId) + .build())) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + ResourceUtils.getEntity(job))) + .thenMany( + requestListServicePlans( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter(response -> serviceName.equals(ResourceUtils.getEntity(response).getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -109,105 +129,146 @@ public void deleteAsyncFalse() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - .flatMap(servicePlanId -> this.cloudFoundryClient.servicePlans() - .delete(DeleteServicePlanRequest.builder() - .async(false) - .servicePlanId(servicePlanId) - .build())) - .thenMany(requestListServicePlans(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(response -> serviceName.equals(ResourceUtils.getEntity(response).getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlans() + .delete( + DeleteServicePlanRequest.builder() + .async(false) + .servicePlanId(servicePlanId) + .build())) + .thenMany( + requestListServicePlans( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter(response -> serviceName.equals(ResourceUtils.getEntity(response).getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test public void get() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServicePlanId(this.cloudFoundryClient, serviceBrokerId)) - .flatMap(servicePlanId -> this.cloudFoundryClient.servicePlans() - .get(GetServicePlanRequest.builder() - .servicePlanId(servicePlanId) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + getServicePlanId(this.cloudFoundryClient, serviceBrokerId)) + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlans() + .get( + GetServicePlanRequest.builder() + .servicePlanId(servicePlanId) + .build())) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName()) - .filter(name -> this.planName.equals(name)) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .list(ListServicePlansRequest.builder().page(page).build())) + .map(response -> ResourceUtils.getEntity(response).getName()) + .filter(name -> this.planName.equals(name)) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByActive() { - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .active(true) - .page(page) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName()) - .filter(name -> this.planName.equals(name)) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .active(true) + .page(page) + .build())) + .map(response -> ResourceUtils.getEntity(response).getName()) + .filter(name -> this.planName.equals(name)) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByServiceBrokerId() { this.serviceBrokerId - .flatMapMany(serviceBrokerId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build()))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .filter(planName -> this.planName.equals(planName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + serviceBrokerId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceBrokerId( + serviceBrokerId) + .build()))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .filter(planName -> this.planName.equals(planName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByServiceId() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) - .flatMapMany(serviceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceId(serviceId) - .build()))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) + .flatMapMany( + serviceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceId(serviceId) + .build()))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -215,22 +276,36 @@ public void listFilterByServiceInstanceId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> Mono.zip( - getServicePlanId(this.cloudFoundryClient, serviceBrokerId), - this.spaceId - )) - .flatMap(function((servicePlanId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, servicePlanId, spaceId))) - .flatMapMany(serviceInstanceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceInstanceId(serviceInstanceId) - .build()))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + Mono.zip( + getServicePlanId(this.cloudFoundryClient, serviceBrokerId), + this.spaceId)) + .flatMap( + function( + (servicePlanId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + servicePlanId, + spaceId))) + .flatMapMany( + serviceInstanceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceInstanceId( + serviceInstanceId) + .build()))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -238,24 +313,39 @@ public void listServiceInstances() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> Mono.zip( - getServicePlanId(this.cloudFoundryClient, serviceBrokerId), - this.spaceId - )) - .flatMap(function((servicePlanId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, servicePlanId, spaceId) - .thenReturn(servicePlanId))) - .flatMapMany(servicePlanId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .listServiceInstances(ListServicePlanServiceInstancesRequest.builder() - .page(page) - .servicePlanId(servicePlanId) - .build()))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .filter(serviceInstanceName::equals) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + Mono.zip( + getServicePlanId(this.cloudFoundryClient, serviceBrokerId), + this.spaceId)) + .flatMap( + function( + (servicePlanId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + servicePlanId, + spaceId) + .thenReturn(servicePlanId))) + .flatMapMany( + servicePlanId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .listServiceInstances( + ListServicePlanServiceInstancesRequest + .builder() + .page(page) + .servicePlanId( + servicePlanId) + .build()))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .filter(serviceInstanceName::equals) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -263,24 +353,39 @@ public void listServiceInstancesFilterByName() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> Mono.zip( - getServicePlanId(this.cloudFoundryClient, serviceBrokerId), - this.spaceId - )) - .flatMap(function((servicePlanId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, servicePlanId, spaceId) - .thenReturn(servicePlanId))) - .flatMapMany(servicePlanId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .listServiceInstances(ListServicePlanServiceInstancesRequest.builder() - .page(page) - .name(serviceInstanceName) - .servicePlanId(servicePlanId) - .build()))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + Mono.zip( + getServicePlanId(this.cloudFoundryClient, serviceBrokerId), + this.spaceId)) + .flatMap( + function( + (servicePlanId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + servicePlanId, + spaceId) + .thenReturn(servicePlanId))) + .flatMapMany( + servicePlanId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .listServiceInstances( + ListServicePlanServiceInstancesRequest + .builder() + .page(page) + .name(serviceInstanceName) + .servicePlanId( + servicePlanId) + .build()))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -289,31 +394,55 @@ public void listServiceInstancesFilterByServiceBindingId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> Mono.zip( - getServicePlanId(this.cloudFoundryClient, serviceBrokerId), - this.spaceId - )) - .flatMap(function((servicePlanId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, servicePlanId, spaceId), - Mono.just(servicePlanId) - ))) - .flatMap(function((applicationId, serviceInstanceId, servicePlanId) -> Mono.zip( - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId), - Mono.just(servicePlanId) - ))) - .flatMapMany(function((serviceBindingId, servicePlanId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .listServiceInstances(ListServicePlanServiceInstancesRequest.builder() - .page(page) - .serviceBindingId(serviceBindingId) - .servicePlanId(servicePlanId) - .build())))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + Mono.zip( + getServicePlanId(this.cloudFoundryClient, serviceBrokerId), + this.spaceId)) + .flatMap( + function( + (servicePlanId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName), + createServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + servicePlanId, + spaceId), + Mono.just(servicePlanId)))) + .flatMap( + function( + (applicationId, serviceInstanceId, servicePlanId) -> + Mono.zip( + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId), + Mono.just(servicePlanId)))) + .flatMapMany( + function( + (serviceBindingId, servicePlanId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .listServiceInstances( + ListServicePlanServiceInstancesRequest + .builder() + .page(page) + .serviceBindingId( + serviceBindingId) + .servicePlanId( + servicePlanId) + .build())))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -322,30 +451,51 @@ public void listServiceInstancesFilterByServiceKeyId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> Mono.zip( - getServicePlanId(this.cloudFoundryClient, serviceBrokerId), - this.spaceId - )) - .flatMap(function((servicePlanId, spaceId) -> Mono.zip( - createServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, servicePlanId, spaceId), - Mono.just(servicePlanId) - ))) - .flatMap(function((serviceInstanceId, servicePlanId) -> Mono.zip( - createServiceKeyId(this.cloudFoundryClient, serviceInstanceId, serviceKeyName), - Mono.just(servicePlanId) - ))) - .flatMapMany(function((serviceKeyId, servicePlanId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .listServiceInstances(ListServicePlanServiceInstancesRequest.builder() - .page(page) - .serviceKeyId(serviceKeyId) - .servicePlanId(servicePlanId) - .build())))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + Mono.zip( + getServicePlanId(this.cloudFoundryClient, serviceBrokerId), + this.spaceId)) + .flatMap( + function( + (servicePlanId, spaceId) -> + Mono.zip( + createServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + servicePlanId, + spaceId), + Mono.just(servicePlanId)))) + .flatMap( + function( + (serviceInstanceId, servicePlanId) -> + Mono.zip( + createServiceKeyId( + this.cloudFoundryClient, + serviceInstanceId, + serviceKeyName), + Mono.just(servicePlanId)))) + .flatMapMany( + function( + (serviceKeyId, servicePlanId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .listServiceInstances( + ListServicePlanServiceInstancesRequest + .builder() + .page(page) + .serviceKeyId( + serviceKeyId) + .servicePlanId( + servicePlanId) + .build())))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -353,24 +503,40 @@ public void listServiceInstancesFilterBySpaceId() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> Mono.zip( - getServicePlanId(this.cloudFoundryClient, serviceBrokerId), - this.spaceId - )) - .delayUntil(function((servicePlanId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, servicePlanId, spaceId))) - .flatMapMany(function((servicePlanId, spaceId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.servicePlans() - .listServiceInstances(ListServicePlanServiceInstancesRequest.builder() - .page(page) - .spaceId(spaceId) - .servicePlanId(servicePlanId) - .build())))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .filter(serviceInstanceName::equals) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + Mono.zip( + getServicePlanId(this.cloudFoundryClient, serviceBrokerId), + this.spaceId)) + .delayUntil( + function( + (servicePlanId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + servicePlanId, + spaceId))) + .flatMapMany( + function( + (servicePlanId, spaceId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .servicePlans() + .listServiceInstances( + ListServicePlanServiceInstancesRequest + .builder() + .page(page) + .spaceId(spaceId) + .servicePlanId( + servicePlanId) + .build())))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .filter(serviceInstanceName::equals) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -380,136 +546,205 @@ public void update() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - .flatMap(servicePlanId -> this.cloudFoundryClient.servicePlans() - .update(UpdateServicePlanRequest.builder() - .publiclyVisible(false) - .servicePlanId(servicePlanId) - .build())) - .thenMany(requestListServicePlans(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(response -> planName.equals(ResourceUtils.getEntity(response).getName())) - .map(response -> ResourceUtils.getEntity(response).getPubliclyVisible()) - .as(StepVerifier::create) - .expectNext(false) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlans() + .update( + UpdateServicePlanRequest.builder() + .publiclyVisible(false) + .servicePlanId(servicePlanId) + .build())) + .thenMany( + requestListServicePlans( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter(response -> planName.equals(ResourceUtils.getEntity(response).getName())) + .map(response -> ResourceUtils.getEntity(response).getPubliclyVisible()) + .as(StepVerifier::create) + .expectNext(false) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createServiceBindingId(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + private static Mono createServiceBindingId( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { return requestCreateServiceBinding(cloudFoundryClient, applicationId, serviceInstanceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createServiceInstanceId(CloudFoundryClient cloudFoundryClient, String serviceInstanceName, String servicePlanId, String spaceId) { - return requestCreateServiceInstance(cloudFoundryClient, serviceInstanceName, servicePlanId, spaceId) - .then(requestListServiceInstances(cloudFoundryClient, serviceInstanceName) - .single() - .map(ResourceUtils::getId)); + private static Mono createServiceInstanceId( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceName, + String servicePlanId, + String spaceId) { + return requestCreateServiceInstance( + cloudFoundryClient, serviceInstanceName, servicePlanId, spaceId) + .then( + requestListServiceInstances(cloudFoundryClient, serviceInstanceName) + .single() + .map(ResourceUtils::getId)); } - private static Mono createServiceKeyId(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String serviceKeyName) { + private static Mono createServiceKeyId( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceId, + String serviceKeyName) { return requestCreateServiceKey(cloudFoundryClient, serviceInstanceId, serviceKeyName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getServiceId(CloudFoundryClient cloudFoundryClient, String serviceName) { + private static Mono getServiceId( + CloudFoundryClient cloudFoundryClient, String serviceName) { return requestListServices(cloudFoundryClient, serviceName) - .single() - .map(ResourceUtils::getId); + .single() + .map(ResourceUtils::getId); } - private static Mono getServicePlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + private static Mono getServicePlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { return requestListServicePlans(cloudFoundryClient, serviceBrokerId) - .filter(resource -> "test-plan-description".equals(ResourceUtils.getEntity(resource).getDescription())) - .map(ResourceUtils::getId) - .single(); + .filter( + resource -> + "test-plan-description" + .equals(ResourceUtils.getEntity(resource).getDescription())) + .map(ResourceUtils::getId) + .single(); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .buildpack("https://github.com/cloudfoundry/java-buildpack.git") - .memory(64) - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .buildpack("https://github.com/cloudfoundry/java-buildpack.git") + .memory(64) + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateServiceBinding(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { - return cloudFoundryClient.serviceBindingsV2() - .create(CreateServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(serviceInstanceId) - .build()); + private static Mono requestCreateServiceBinding( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + return cloudFoundryClient + .serviceBindingsV2() + .create( + CreateServiceBindingRequest.builder() + .applicationId(applicationId) + .serviceInstanceId(serviceInstanceId) + .build()); } - private static Mono requestCreateServiceInstance(CloudFoundryClient cloudFoundryClient, String serviceInstanceName, String servicePlanId, String spaceId) { - return cloudFoundryClient.serviceInstances() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .servicePlanId(servicePlanId) - .spaceId(spaceId) - .build()); + private static Mono requestCreateServiceInstance( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceName, + String servicePlanId, + String spaceId) { + return cloudFoundryClient + .serviceInstances() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .servicePlanId(servicePlanId) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateServiceKey(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String serviceKeyName) { - return cloudFoundryClient.serviceKeys() - .create(CreateServiceKeyRequest.builder() - .name(serviceKeyName) - .serviceInstanceId(serviceInstanceId) - .build()); + private static Mono requestCreateServiceKey( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceId, + String serviceKeyName) { + return cloudFoundryClient + .serviceKeys() + .create( + CreateServiceKeyRequest.builder() + .name(serviceKeyName) + .serviceInstanceId(serviceInstanceId) + .build()); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organizationId(organizationId) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organizationId(organizationId) + .build()); } - private static Flux requestListServiceInstances(CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceInstances() - .list(ListServiceInstancesRequest.builder() - .name(serviceInstanceName) - .build())); + private static Flux requestListServiceInstances( + CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceInstances() + .list( + ListServiceInstancesRequest.builder() + .name(serviceInstanceName) + .build())); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceBrokerId(serviceBrokerId) + .build())); } - private static Flux requestListServices(CloudFoundryClient cloudFoundryClient, String serviceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .page(page) - .label(serviceName) - .build())); + private static Flux requestListServices( + CloudFoundryClient cloudFoundryClient, String serviceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .list( + ListServicesRequest.builder() + .page(page) + .label(serviceName) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceUsageEventsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceUsageEventsTest.java index cdfd9f1f4b5..987de74b28b 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceUsageEventsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServiceUsageEventsTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.NameFactory; import org.cloudfoundry.client.CloudFoundryClient; @@ -31,225 +34,307 @@ import org.cloudfoundry.client.v2.serviceusageevents.ServiceUsageEventResource; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ServiceUsageEventsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void get() { - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> seedEvents(this.cloudFoundryClient, this.nameFactory, serviceBrokerId, this.serviceName, spaceId))) - .then(getFirstEvent(this.cloudFoundryClient)) - .flatMap(resource -> Mono.zip( - Mono.just(resource) - .map(ResourceUtils::getId), - this.cloudFoundryClient.serviceUsageEvents() - .get(GetServiceUsageEventRequest.builder() - .serviceUsageEventId(ResourceUtils.getId(resource)) - .build()) - .map(ResourceUtils::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + seedEvents( + this.cloudFoundryClient, + this.nameFactory, + serviceBrokerId, + this.serviceName, + spaceId))) + .then(getFirstEvent(this.cloudFoundryClient)) + .flatMap( + resource -> + Mono.zip( + Mono.just(resource).map(ResourceUtils::getId), + this.cloudFoundryClient + .serviceUsageEvents() + .get( + GetServiceUsageEventRequest.builder() + .serviceUsageEventId( + ResourceUtils.getId( + resource)) + .build()) + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> seedEvents(this.cloudFoundryClient, this.nameFactory, serviceBrokerId, this.serviceName, spaceId))) - .then(getFirstEvent(this.cloudFoundryClient)) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.serviceUsageEvents() - .list(ListServiceUsageEventsRequest.builder() - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + seedEvents( + this.cloudFoundryClient, + this.nameFactory, + serviceBrokerId, + this.serviceName, + spaceId))) + .then(getFirstEvent(this.cloudFoundryClient)) + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .serviceUsageEvents() + .list( + ListServiceUsageEventsRequest.builder() + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listAfterServiceUsageEventId() { - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> seedEvents(this.cloudFoundryClient, this.nameFactory, serviceBrokerId, this.serviceName, spaceId))) - .then(getFirstEvent(this.cloudFoundryClient)) - .flatMap(resource -> Mono.zip( - getSecondEvent(this.cloudFoundryClient), - this.cloudFoundryClient.serviceUsageEvents() - .list(ListServiceUsageEventsRequest.builder() - .afterServiceUsageEventId(ResourceUtils.getId(resource)) - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + seedEvents( + this.cloudFoundryClient, + this.nameFactory, + serviceBrokerId, + this.serviceName, + spaceId))) + .then(getFirstEvent(this.cloudFoundryClient)) + .flatMap( + resource -> + Mono.zip( + getSecondEvent(this.cloudFoundryClient), + this.cloudFoundryClient + .serviceUsageEvents() + .list( + ListServiceUsageEventsRequest.builder() + .afterServiceUsageEventId( + ResourceUtils.getId( + resource)) + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByServiceId() { - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> seedEvents(this.cloudFoundryClient, this.nameFactory, serviceBrokerId, this.serviceName, spaceId))) - .then(getFirstEventWithServiceId(this.cloudFoundryClient)) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.serviceUsageEvents() - .list(ListServiceUsageEventsRequest.builder() - .serviceId(ResourceUtils.getEntity(resource).getServiceId()) - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + seedEvents( + this.cloudFoundryClient, + this.nameFactory, + serviceBrokerId, + this.serviceName, + spaceId))) + .then(getFirstEventWithServiceId(this.cloudFoundryClient)) + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .serviceUsageEvents() + .list( + ListServiceUsageEventsRequest.builder() + .serviceId( + ResourceUtils.getEntity( + resource) + .getServiceId()) + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByServiceInstanceType() { - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMap(function((serviceBrokerId, spaceId) -> seedEvents(this.cloudFoundryClient, this.nameFactory, serviceBrokerId, this.serviceName, spaceId))) - .then(getFirstEvent(this.cloudFoundryClient)) - .flatMap(resource -> Mono.zip( - Mono.just(resource), - this.cloudFoundryClient.serviceUsageEvents() - .list(ListServiceUsageEventsRequest.builder() - .serviceInstanceType(ResourceUtils.getEntity(resource).getServiceInstanceType()) - .build()) - .flatMapMany(ResourceUtils::getResources) - .next() - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + seedEvents( + this.cloudFoundryClient, + this.nameFactory, + serviceBrokerId, + this.serviceName, + spaceId))) + .then(getFirstEvent(this.cloudFoundryClient)) + .flatMap( + resource -> + Mono.zip( + Mono.just(resource), + this.cloudFoundryClient + .serviceUsageEvents() + .list( + ListServiceUsageEventsRequest.builder() + .serviceInstanceType( + ResourceUtils.getEntity( + resource) + .getServiceInstanceType()) + .build()) + .flatMapMany(ResourceUtils::getResources) + .next())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listNoneFound() { - this.cloudFoundryClient.serviceUsageEvents() - .list(ListServiceUsageEventsRequest.builder() - .serviceId("test-service-id") - .build()) - .flatMapMany(ResourceUtils::getResources) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .serviceUsageEvents() + .list(ListServiceUsageEventsRequest.builder().serviceId("test-service-id").build()) + .flatMapMany(ResourceUtils::getResources) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void purgeAndReseed() { - this.cloudFoundryClient.serviceUsageEvents() - .purgeAndReseed(PurgeAndReseedServiceUsageEventsRequest.builder() - .build()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .serviceUsageEvents() + .purgeAndReseed(PurgeAndReseedServiceUsageEventsRequest.builder().build()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono getFirstEvent(CloudFoundryClient cloudFoundryClient) { - return listServiceUsageEvents(cloudFoundryClient) - .next(); + private static Mono getFirstEvent( + CloudFoundryClient cloudFoundryClient) { + return listServiceUsageEvents(cloudFoundryClient).next(); } - private static Mono getFirstEventWithServiceId(CloudFoundryClient cloudFoundryClient) { + private static Mono getFirstEventWithServiceId( + CloudFoundryClient cloudFoundryClient) { return listServiceUsageEvents(cloudFoundryClient) - .filter(resource -> ResourceUtils.getEntity(resource).getServiceId() != null) - .next(); + .filter(resource -> ResourceUtils.getEntity(resource).getServiceId() != null) + .next(); } - private static Mono getPlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + private static Mono getPlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { return requestListServices(cloudFoundryClient, serviceBrokerId, serviceName) - .single() - .map(ResourceUtils::getId) - .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) - .single() - .map(ResourceUtils::getId); + .single() + .map(ResourceUtils::getId) + .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) + .single() + .map(ResourceUtils::getId); } - private static Mono getSecondEvent(CloudFoundryClient cloudFoundryClient) { - return listServiceUsageEvents(cloudFoundryClient) - .skip(1) - .next(); + private static Mono getSecondEvent( + CloudFoundryClient cloudFoundryClient) { + return listServiceUsageEvents(cloudFoundryClient).skip(1).next(); } - private static Flux listServiceUsageEvents(CloudFoundryClient cloudFoundryClient) { - return cloudFoundryClient.serviceUsageEvents() - .list(ListServiceUsageEventsRequest.builder() - .build()) - .flatMapMany(ResourceUtils::getResources); + private static Flux listServiceUsageEvents( + CloudFoundryClient cloudFoundryClient) { + return cloudFoundryClient + .serviceUsageEvents() + .list(ListServiceUsageEventsRequest.builder().build()) + .flatMapMany(ResourceUtils::getResources); } - private static Mono requestCreateServiceInstance(CloudFoundryClient cloudFoundryClient, String planId, String serviceInstanceName, String spaceId) { - return cloudFoundryClient.serviceInstances() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .parameter("test-key", "test-value") - .servicePlanId(planId) - .spaceId(spaceId) - .build()); + private static Mono requestCreateServiceInstance( + CloudFoundryClient cloudFoundryClient, + String planId, + String serviceInstanceName, + String spaceId) { + return cloudFoundryClient + .serviceInstances() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .parameter("test-key", "test-value") + .servicePlanId(planId) + .spaceId(spaceId) + .build()); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceId(serviceId) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceId(serviceId) + .build())); } - private static Flux requestListServices(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .label(serviceName) - .page(page) - .serviceBrokerId(serviceBrokerId) - .build())); + private static Flux requestListServices( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .list( + ListServicesRequest.builder() + .label(serviceName) + .page(page) + .serviceBrokerId(serviceBrokerId) + .build())); } - private static Mono seedEvents(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, String serviceBrokerId, String serviceName, String spaceId) { + private static Mono seedEvents( + CloudFoundryClient cloudFoundryClient, + NameFactory nameFactory, + String serviceBrokerId, + String serviceName, + String spaceId) { String serviceInstanceName1 = nameFactory.getServiceInstanceName(); String serviceInstanceName2 = nameFactory.getServiceInstanceName(); return getPlanId(cloudFoundryClient, serviceBrokerId, serviceName) - .flatMap(planId -> requestCreateServiceInstance(cloudFoundryClient, planId, serviceInstanceName1, spaceId) - .then(requestCreateServiceInstance(cloudFoundryClient, planId, serviceInstanceName2, spaceId))) - .then(); + .flatMap( + planId -> + requestCreateServiceInstance( + cloudFoundryClient, + planId, + serviceInstanceName1, + spaceId) + .then( + requestCreateServiceInstance( + cloudFoundryClient, + planId, + serviceInstanceName2, + spaceId))) + .then(); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicesTest.java index 1b0b4b9a8dd..9af396d3159 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/ServicesTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; +import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.ServiceBrokerUtils; import org.cloudfoundry.client.CloudFoundryClient; @@ -35,36 +40,25 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; -import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ServicesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private String planName; + @Autowired private String planName; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void delete() { @@ -73,28 +67,59 @@ public void delete() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServiceId(this.cloudFoundryClient, serviceName) - .flatMapMany(serviceId -> deleteServicePlans(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId, serviceId) - .thenMany(Mono.just(serviceId))) - .flatMap(serviceId -> this.cloudFoundryClient.services() - .delete(DeleteServiceRequest.builder() - .async(true) - .serviceId(serviceId) - .build())) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .thenMany(requestListServices(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(resource -> serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .flatMapMany( + serviceId -> + deleteServicePlans( + this.cloudFoundryClient, + serviceBrokerMetadata.serviceBrokerId, + serviceId) + .thenMany(Mono.just(serviceId))) + .flatMap( + serviceId -> + this.cloudFoundryClient + .services() + .delete( + DeleteServiceRequest.builder() + .async(true) + .serviceId(serviceId) + .build())) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .thenMany( + requestListServices( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter( + resource -> + serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -104,28 +129,56 @@ public void deleteAsyncFalse() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServiceId(this.cloudFoundryClient, serviceName) - .flatMapMany(serviceId -> deleteServicePlans(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId, serviceId) - .thenMany(Mono.just(serviceId))) - .flatMap(serviceId -> this.cloudFoundryClient.services() - .delete(DeleteServiceRequest.builder() - .async(false) - .serviceId(serviceId) - .build()) - .thenReturn(serviceBrokerMetadata.serviceBrokerId)) - .thenMany(requestListServices(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(resource -> serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(1)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .flatMapMany( + serviceId -> + deleteServicePlans( + this.cloudFoundryClient, + serviceBrokerMetadata.serviceBrokerId, + serviceId) + .thenMany(Mono.just(serviceId))) + .flatMap( + serviceId -> + this.cloudFoundryClient + .services() + .delete( + DeleteServiceRequest.builder() + .async(false) + .serviceId(serviceId) + .build()) + .thenReturn(serviceBrokerMetadata.serviceBrokerId)) + .thenMany( + requestListServices( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter( + resource -> + serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(1)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -135,159 +188,243 @@ public void deletePurge() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServiceId(this.cloudFoundryClient, serviceName) - .flatMap(serviceId -> this.cloudFoundryClient.services() - .delete(DeleteServiceRequest.builder() - .async(true) - .purge(true) - .serviceId(serviceId) - .build())) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .thenMany(requestListServices(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(resource -> serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(1)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .flatMap( + serviceId -> + this.cloudFoundryClient + .services() + .delete( + DeleteServiceRequest.builder() + .async(true) + .purge(true) + .serviceId(serviceId) + .build())) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .thenMany( + requestListServices( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter( + resource -> + serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(1)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test public void get() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) - .flatMap(serviceId -> this.cloudFoundryClient.services() - .get(GetServiceRequest.builder() - .serviceId(serviceId) - .build())) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) + .flatMap( + serviceId -> + this.cloudFoundryClient + .services() + .get( + GetServiceRequest.builder() + .serviceId(serviceId) + .build())) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { this.serviceBrokerId - .flatMapMany(serviceBrokerId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .page(page) - .build())) - .filter(resource -> serviceBrokerId.equals(ResourceUtils.getEntity(resource).getServiceBrokerId()))) - .map(response -> response.getEntity().getLabel()) - .filter(label -> this.serviceName.equals(label)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + serviceBrokerId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .list( + ListServicesRequest + .builder() + .page(page) + .build())) + .filter( + resource -> + serviceBrokerId.equals( + ResourceUtils.getEntity(resource) + .getServiceBrokerId()))) + .map(response -> response.getEntity().getLabel()) + .filter(label -> this.serviceName.equals(label)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByActive() { this.serviceBrokerId - .flatMapMany(serviceBrokerId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .active(true) - .page(page) - .build())) - .filter(resource -> serviceBrokerId.equals(ResourceUtils.getEntity(resource).getServiceBrokerId()))) - .map(response -> response.getEntity().getLabel()) - .filter(label -> this.serviceName.equals(label)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + serviceBrokerId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .list( + ListServicesRequest + .builder() + .active(true) + .page(page) + .build())) + .filter( + resource -> + serviceBrokerId.equals( + ResourceUtils.getEntity(resource) + .getServiceBrokerId()))) + .map(response -> response.getEntity().getLabel()) + .filter(label -> this.serviceName.equals(label)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByLabels() { this.serviceBrokerId - .flatMapMany(serviceBrokerId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .label(this.serviceName) - .page(page) - .build())) - .filter(resource -> serviceBrokerId.equals(ResourceUtils.getEntity(resource).getServiceBrokerId()))) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + serviceBrokerId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .list( + ListServicesRequest + .builder() + .label( + this + .serviceName) + .page(page) + .build())) + .filter( + resource -> + serviceBrokerId.equals( + ResourceUtils.getEntity(resource) + .getServiceBrokerId()))) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByServiceBrokerIds() { this.serviceBrokerId - .flatMapMany(serviceBrokerId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .serviceBrokerId(serviceBrokerId) - .page(page) - .build()))) - .map(response -> response.getEntity().getLabel()) - .filter(label -> this.serviceName.equals(label)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + serviceBrokerId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .list( + ListServicesRequest.builder() + .serviceBrokerId( + serviceBrokerId) + .page(page) + .build()))) + .map(response -> response.getEntity().getLabel()) + .filter(label -> this.serviceName.equals(label)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listNoneFound() { - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .label("unmatched-filter") - .page(page) - .build())) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .list( + ListServicesRequest.builder() + .label("unmatched-filter") + .page(page) + .build())) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServicePlans() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) - .flatMapMany(serviceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.services() - .listServicePlans(ListServiceServicePlansRequest.builder() - .serviceId(serviceId) - .page(page) - .build()))) - .map(response -> response.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) + .flatMapMany( + serviceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .listServicePlans( + ListServiceServicePlansRequest + .builder() + .serviceId(serviceId) + .page(page) + .build()))) + .map(response -> response.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServicePlansFilterByActive() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) - .flatMapMany(serviceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.services() - .listServicePlans(ListServiceServicePlansRequest.builder() - .active(true) - .serviceId(serviceId) - .page(page) - .build()))) - .map(response -> response.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) + .flatMapMany( + serviceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .listServicePlans( + ListServiceServicePlansRequest + .builder() + .active(true) + .serviceId(serviceId) + .page(page) + .build()))) + .map(response -> response.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -295,125 +432,179 @@ public void listServicePlansFilterByServiceInstanceIds() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> Mono.zip( - getServiceId(this.cloudFoundryClient, this.serviceName), - this.spaceId - )) - .flatMap(function((serviceId, spaceId) -> Mono.zip( - Mono.just(serviceId), - createServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, serviceId, spaceId) - ))) - .flatMapMany(function((serviceId, serviceInstanceId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.services() - .listServicePlans(ListServiceServicePlansRequest.builder() - .serviceId(serviceId) - .serviceInstanceId(serviceInstanceId) - .page(page) - .build())))) - .map(response -> response.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + Mono.zip( + getServiceId(this.cloudFoundryClient, this.serviceName), + this.spaceId)) + .flatMap( + function( + (serviceId, spaceId) -> + Mono.zip( + Mono.just(serviceId), + createServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + serviceId, + spaceId)))) + .flatMapMany( + function( + (serviceId, serviceInstanceId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .listServicePlans( + ListServiceServicePlansRequest + .builder() + .serviceId( + serviceId) + .serviceInstanceId( + serviceInstanceId) + .page(page) + .build())))) + .map(response -> response.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServicePlansNoneFound() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) - .flatMapMany(serviceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.services() - .listServicePlans(ListServiceServicePlansRequest.builder() - .serviceId(serviceId) - .serviceInstanceId("unmatched-filter") - .page(page) - .build()))) - .map(response -> response.getEntity().getName()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap(serviceBrokerId -> getServiceId(this.cloudFoundryClient, this.serviceName)) + .flatMapMany( + serviceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .services() + .listServicePlans( + ListServiceServicePlansRequest + .builder() + .serviceId(serviceId) + .serviceInstanceId( + "unmatched-filter") + .page(page) + .build()))) + .map(response -> response.getEntity().getName()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Flux deleteServicePlans(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceId) { + private static Flux deleteServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceId) { return listServicePlanIds(cloudFoundryClient, serviceBrokerId, serviceId) - .flatMap(servicePlanId -> requestDeleteServicePlan(cloudFoundryClient, servicePlanId)); + .flatMap( + servicePlanId -> + requestDeleteServicePlan(cloudFoundryClient, servicePlanId)); } - private static Mono getServiceId(CloudFoundryClient cloudFoundryClient, String serviceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .page(page) - .build())) - .filter(resource -> serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) - .single() - .map(ResourceUtils::getId); + private static Mono getServiceId( + CloudFoundryClient cloudFoundryClient, String serviceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .list(ListServicesRequest.builder().page(page).build())) + .filter( + resource -> + serviceName.equals(ResourceUtils.getEntity(resource).getLabel())) + .single() + .map(ResourceUtils::getId); } - private static Flux listServicePlanIds(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .serviceId(serviceId) - .build())) - .map(ResourceUtils::getId); + private static Flux listServicePlanIds( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceBrokerId(serviceBrokerId) + .serviceId(serviceId) + .build())) + .map(ResourceUtils::getId); } - private static Mono requestCreateServiceInstance(CloudFoundryClient cloudFoundryClient, String name, String servicePlanId, String spaceId) { - return cloudFoundryClient.serviceInstances() - .create(CreateServiceInstanceRequest.builder() - .name(name) - .servicePlanId(servicePlanId) - .spaceId(spaceId) - .build()); + private static Mono requestCreateServiceInstance( + CloudFoundryClient cloudFoundryClient, + String name, + String servicePlanId, + String spaceId) { + return cloudFoundryClient + .serviceInstances() + .create( + CreateServiceInstanceRequest.builder() + .name(name) + .servicePlanId(servicePlanId) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organizationId(organizationId) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organizationId(organizationId) + .build()); } - private static Mono requestDeleteServicePlan(CloudFoundryClient cloudFoundryClient, String servicePlanId) { - return cloudFoundryClient.servicePlans() - .delete(DeleteServicePlanRequest.builder() - .servicePlanId(servicePlanId) - .build()); + private static Mono requestDeleteServicePlan( + CloudFoundryClient cloudFoundryClient, String servicePlanId) { + return cloudFoundryClient + .servicePlans() + .delete(DeleteServicePlanRequest.builder().servicePlanId(servicePlanId).build()); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .listServicePlans(ListServiceServicePlansRequest.builder() - .page(page) - .serviceId(serviceId) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .listServicePlans( + ListServiceServicePlansRequest.builder() + .page(page) + .serviceId(serviceId) + .build())); } - private static Flux requestListServices(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .serviceBrokerId(serviceBrokerId) - .page(page) - .build())); + private static Flux requestListServices( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .list( + ListServicesRequest.builder() + .serviceBrokerId(serviceBrokerId) + .page(page) + .build())); } - private Mono createServiceInstanceId(CloudFoundryClient cloudFoundryClient, String name, String serviceId, String spaceId) { + private Mono createServiceInstanceId( + CloudFoundryClient cloudFoundryClient, String name, String serviceId, String spaceId) { return requestListServicePlans(cloudFoundryClient, serviceId) - .single() - .map(ResourceUtils::getId) - .flatMap(servicePlanId -> requestCreateServiceInstance(cloudFoundryClient, name, servicePlanId, spaceId) - .map(ResourceUtils::getId)); + .single() + .map(ResourceUtils::getId) + .flatMap( + servicePlanId -> + requestCreateServiceInstance( + cloudFoundryClient, name, servicePlanId, spaceId) + .map(ResourceUtils::getId)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/SharedDomainsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/SharedDomainsTest.java index 94c484f9068..063992a6574 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/SharedDomainsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/SharedDomainsTest.java @@ -16,6 +16,8 @@ package org.cloudfoundry.client.v2; +import java.time.Duration; +import java.util.Optional; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.shareddomains.CreateSharedDomainRequest; @@ -29,34 +31,32 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.Optional; - public final class SharedDomainsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void create() { String domainName = this.nameFactory.getDomainName(); - this.cloudFoundryClient.sharedDomains() - .create(CreateSharedDomainRequest.builder() - .name(domainName) - .build()) - .map(ResourceUtils::getId) - .flatMap(sharedDomainId -> getSharedDomainResource(this.cloudFoundryClient, sharedDomainId)) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(domainName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .sharedDomains() + .create(CreateSharedDomainRequest.builder().name(domainName).build()) + .map(ResourceUtils::getId) + .flatMap( + sharedDomainId -> + getSharedDomainResource(this.cloudFoundryClient, sharedDomainId)) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(domainName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -64,16 +64,19 @@ public void deleteAsyncFalse() { String domainName = this.nameFactory.getDomainName(); getSharedDomainId(this.cloudFoundryClient, domainName) - .flatMap(sharedDomainId -> this.cloudFoundryClient.sharedDomains() - .delete(DeleteSharedDomainRequest.builder() - .async(false) - .sharedDomainId(sharedDomainId) - .build())) - .then(requestListSharedDomains(this.cloudFoundryClient, domainName) - .singleOrEmpty()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + sharedDomainId -> + this.cloudFoundryClient + .sharedDomains() + .delete( + DeleteSharedDomainRequest.builder() + .async(false) + .sharedDomainId(sharedDomainId) + .build())) + .then(requestListSharedDomains(this.cloudFoundryClient, domainName).singleOrEmpty()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -81,17 +84,25 @@ public void deleteAsyncTrue() { String domainName = this.nameFactory.getDomainName(); getSharedDomainId(this.cloudFoundryClient, domainName) - .flatMap(sharedDomainId -> this.cloudFoundryClient.sharedDomains() - .delete(DeleteSharedDomainRequest.builder() - .async(true) - .sharedDomainId(sharedDomainId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .then(requestListSharedDomains(this.cloudFoundryClient, domainName) - .singleOrEmpty()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + sharedDomainId -> + this.cloudFoundryClient + .sharedDomains() + .delete( + DeleteSharedDomainRequest.builder() + .async(true) + .sharedDomainId(sharedDomainId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .then(requestListSharedDomains(this.cloudFoundryClient, domainName).singleOrEmpty()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -99,16 +110,20 @@ public void get() { String domainName = this.nameFactory.getDomainName(); getSharedDomainId(this.cloudFoundryClient, domainName) - .flatMap(sharedDomainId -> this.cloudFoundryClient.sharedDomains() - .get(GetSharedDomainRequest.builder() - .sharedDomainId(sharedDomainId) - .build())) - .map(ResourceUtils::getEntity) - .map(SharedDomainEntity::getName) - .as(StepVerifier::create) - .expectNext(domainName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + sharedDomainId -> + this.cloudFoundryClient + .sharedDomains() + .get( + GetSharedDomainRequest.builder() + .sharedDomainId(sharedDomainId) + .build())) + .map(ResourceUtils::getEntity) + .map(SharedDomainEntity::getName) + .as(StepVerifier::create) + .expectNext(domainName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -116,14 +131,19 @@ public void list() { String domainName = this.nameFactory.getDomainName(); getSharedDomainId(this.cloudFoundryClient, domainName) - .flatMap(sharedDomainId -> requestListSharedDomains(this.cloudFoundryClient, null) - .filter(resource -> sharedDomainId.equals(ResourceUtils.getId(resource))) - .single()) - .map(resource -> ResourceUtils.getEntity(resource).getName()) - .as(StepVerifier::create) - .expectNext(domainName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + sharedDomainId -> + requestListSharedDomains(this.cloudFoundryClient, null) + .filter( + resource -> + sharedDomainId.equals( + ResourceUtils.getId(resource))) + .single()) + .map(resource -> ResourceUtils.getEntity(resource).getName()) + .as(StepVerifier::create) + .expectNext(domainName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -131,45 +151,45 @@ public void listFilterByName() { String domainName = this.nameFactory.getDomainName(); getSharedDomainId(this.cloudFoundryClient, domainName) - .flatMap(sharedDomainId -> Mono.zip( - Mono.just(sharedDomainId), - requestListSharedDomains(this.cloudFoundryClient, domainName) - .single() - .map(ResourceUtils::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + sharedDomainId -> + Mono.zip( + Mono.just(sharedDomainId), + requestListSharedDomains( + this.cloudFoundryClient, domainName) + .single() + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono getSharedDomainId(CloudFoundryClient cloudFoundryClient, String domainName) { - return requestCreateSharedDomain(cloudFoundryClient, domainName) - .map(ResourceUtils::getId); + private static Mono getSharedDomainId( + CloudFoundryClient cloudFoundryClient, String domainName) { + return requestCreateSharedDomain(cloudFoundryClient, domainName).map(ResourceUtils::getId); } - private static Mono getSharedDomainResource(CloudFoundryClient cloudFoundryClient, String sharedDomainId) { - return cloudFoundryClient.sharedDomains() - .get(GetSharedDomainRequest.builder() - .sharedDomainId(sharedDomainId) - .build()); + private static Mono getSharedDomainResource( + CloudFoundryClient cloudFoundryClient, String sharedDomainId) { + return cloudFoundryClient + .sharedDomains() + .get(GetSharedDomainRequest.builder().sharedDomainId(sharedDomainId).build()); } - private static Mono requestCreateSharedDomain(CloudFoundryClient cloudFoundryClient, String sharedDomainName) { - return cloudFoundryClient.sharedDomains() - .create(CreateSharedDomainRequest.builder() - .name(sharedDomainName) - .build()); + private static Mono requestCreateSharedDomain( + CloudFoundryClient cloudFoundryClient, String sharedDomainName) { + return cloudFoundryClient + .sharedDomains() + .create(CreateSharedDomainRequest.builder().name(sharedDomainName).build()); } - private static Flux requestListSharedDomains(CloudFoundryClient cloudFoundryClient, String sharedDomainName) { + private static Flux requestListSharedDomains( + CloudFoundryClient cloudFoundryClient, String sharedDomainName) { ListSharedDomainsRequest.Builder requestBuilder = ListSharedDomainsRequest.builder(); Optional.ofNullable(sharedDomainName).ifPresent(requestBuilder::name); - return PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.sharedDomains() - .list(requestBuilder - .page(page) - .build())); + return PaginationUtils.requestClientV2Resources( + page -> cloudFoundryClient.sharedDomains().list(requestBuilder.page(page).build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/SpaceQuotaDefinitionsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/SpaceQuotaDefinitionsTest.java index e66fccb24f3..47c9ae0f5f3 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/SpaceQuotaDefinitionsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/SpaceQuotaDefinitionsTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; @@ -37,24 +40,19 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuples; -import java.time.Duration; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class SpaceQuotaDefinitionsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; @Test public void associateSpace() { @@ -62,21 +60,32 @@ public void associateSpace() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName) - )) - .flatMap(function((spaceId, quotaId) -> this.cloudFoundryClient.spaceQuotaDefinitions() - .associateSpace(AssociateSpaceQuotaDefinitionRequest.builder() - .spaceId(spaceId) - .spaceQuotaDefinitionId(quotaId) - .build()))) - .map(ResourceUtils::getEntity) - .map(SpaceQuotaDefinitionEntity::getName) - .as(StepVerifier::create) - .expectNext(quotaName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, + organizationId, + quotaName))) + .flatMap( + function( + (spaceId, quotaId) -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .associateSpace( + AssociateSpaceQuotaDefinitionRequest + .builder() + .spaceId(spaceId) + .spaceQuotaDefinitionId(quotaId) + .build()))) + .map(ResourceUtils::getEntity) + .map(SpaceQuotaDefinitionEntity::getName) + .as(StepVerifier::create) + .expectNext(quotaName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -84,21 +93,25 @@ public void create() { String quotaName = this.nameFactory.getQuotaDefinitionName(); this.organizationId - .flatMap(organizationId -> this.cloudFoundryClient.spaceQuotaDefinitions() - .create(CreateSpaceQuotaDefinitionRequest.builder() - .memoryLimit(512) - .name(quotaName) - .nonBasicServicesAllowed(false) - .organizationId(organizationId) - .totalRoutes(1) - .totalServices(1) - .build())) - .map(ResourceUtils::getEntity) - .map(SpaceQuotaDefinitionEntity::getName) - .as(StepVerifier::create) - .expectNext(quotaName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .create( + CreateSpaceQuotaDefinitionRequest.builder() + .memoryLimit(512) + .name(quotaName) + .nonBasicServicesAllowed(false) + .organizationId(organizationId) + .totalRoutes(1) + .totalServices(1) + .build())) + .map(ResourceUtils::getEntity) + .map(SpaceQuotaDefinitionEntity::getName) + .as(StepVerifier::create) + .expectNext(quotaName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -106,17 +119,28 @@ public void delete() { String quotaName = this.nameFactory.getQuotaDefinitionName(); this.organizationId - .flatMap(organizationId -> createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName)) - .flatMap(quotaId -> this.cloudFoundryClient.spaceQuotaDefinitions() - .delete(DeleteSpaceQuotaDefinitionRequest.builder() - .async(true) - .spaceQuotaDefinitionId(quotaId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - + .flatMap( + organizationId -> + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, organizationId, quotaName)) + .flatMap( + quotaId -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .delete( + DeleteSpaceQuotaDefinitionRequest.builder() + .async(true) + .spaceQuotaDefinitionId(quotaId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -124,17 +148,24 @@ public void get() { String quotaName = this.nameFactory.getQuotaDefinitionName(); this.organizationId - .flatMap(organizationId -> createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName)) - .flatMap(quotaId -> this.cloudFoundryClient.spaceQuotaDefinitions() - .get(GetSpaceQuotaDefinitionRequest.builder() - .spaceQuotaDefinitionId(quotaId) - .build())) - .map(ResourceUtils::getEntity) - .map(SpaceQuotaDefinitionEntity::getName) - .as(StepVerifier::create) - .expectNext(quotaName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, organizationId, quotaName)) + .flatMap( + quotaId -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .get( + GetSpaceQuotaDefinitionRequest.builder() + .spaceQuotaDefinitionId(quotaId) + .build())) + .map(ResourceUtils::getEntity) + .map(SpaceQuotaDefinitionEntity::getName) + .as(StepVerifier::create) + .expectNext(quotaName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -142,18 +173,26 @@ public void list() { String quotaName = this.nameFactory.getQuotaDefinitionName(); this.organizationId - .flatMap(organizationId -> createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaceQuotaDefinitions() - .list(ListSpaceQuotaDefinitionsRequest.builder() - .page(page) - .build())) - .map(ResourceUtils::getEntity)) - .filter(quota -> quotaName.equals(quota.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, organizationId, quotaName)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .list( + ListSpaceQuotaDefinitionsRequest + .builder() + .page(page) + .build())) + .map(ResourceUtils::getEntity)) + .filter(quota -> quotaName.equals(quota.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -162,24 +201,40 @@ public void listSpaces() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName) - )) - .flatMap(function((spaceId, quotaId) -> requestAssociateSpace(this.cloudFoundryClient, quotaId, spaceId) - .thenReturn(quotaId))) - .flatMapMany(quotaId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaceQuotaDefinitions() - .listSpaces(ListSpaceQuotaDefinitionSpacesRequest.builder() - .page(page) - .spaceQuotaDefinitionId(quotaId) - .build()))) - .map(ResourceUtils::getEntity) - .map(SpaceEntity::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, + organizationId, + quotaName))) + .flatMap( + function( + (spaceId, quotaId) -> + requestAssociateSpace( + this.cloudFoundryClient, quotaId, spaceId) + .thenReturn(quotaId))) + .flatMapMany( + quotaId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .listSpaces( + ListSpaceQuotaDefinitionSpacesRequest + .builder() + .page(page) + .spaceQuotaDefinitionId( + quotaId) + .build()))) + .map(ResourceUtils::getEntity) + .map(SpaceEntity::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -189,36 +244,56 @@ public void listSpacesFilterByApplicationId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((quotaId, spaceId) -> Mono.zip( - requestAssociateSpace(this.cloudFoundryClient, quotaId, spaceId) - .thenReturn(quotaId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - )) - .flatMapMany(function((quotaId, applicationId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaceQuotaDefinitions() - .listSpaces(ListSpaceQuotaDefinitionSpacesRequest.builder() - .applicationId(applicationId) - .page(page) - .spaceQuotaDefinitionId(quotaId) - .build())))) - .map(ResourceUtils::getEntity) - .map(SpaceEntity::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, organizationId, quotaName), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (quotaId, spaceId) -> + Mono.zip( + requestAssociateSpace( + this.cloudFoundryClient, + quotaId, + spaceId) + .thenReturn(quotaId), + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName)))) + .flatMapMany( + function( + (quotaId, applicationId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .listSpaces( + ListSpaceQuotaDefinitionSpacesRequest + .builder() + .applicationId( + applicationId) + .page(page) + .spaceQuotaDefinitionId( + quotaId) + .build())))) + .map(ResourceUtils::getEntity) + .map(SpaceEntity::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - //TODO: Await https://github.com/cloudfoundry/cf-java-client/issues/643 - @Ignore("Await https://github.com/cloudfoundry/cf-java-client/issues/643") + // TODO: Await https://github.com/cloudfoundry/cf-java-client/issues/643 + @Disabled("Await https://github.com/cloudfoundry/cf-java-client/issues/643") @Test - public void listSpacesFilterByDeveloperId() { - - } + public void listSpacesFilterByDeveloperId() {} @Test public void listSpacesFilterByName() { @@ -226,25 +301,41 @@ public void listSpacesFilterByName() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName) - )) - .flatMap(function((spaceId, quotaId) -> requestAssociateSpace(this.cloudFoundryClient, quotaId, spaceId) - .thenReturn(quotaId))) - .flatMapMany(quotaId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaceQuotaDefinitions() - .listSpaces(ListSpaceQuotaDefinitionSpacesRequest.builder() - .name(spaceName) - .page(page) - .spaceQuotaDefinitionId(quotaId) - .build()))) - .map(ResourceUtils::getEntity) - .map(SpaceEntity::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, + organizationId, + quotaName))) + .flatMap( + function( + (spaceId, quotaId) -> + requestAssociateSpace( + this.cloudFoundryClient, quotaId, spaceId) + .thenReturn(quotaId))) + .flatMapMany( + quotaId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .listSpaces( + ListSpaceQuotaDefinitionSpacesRequest + .builder() + .name(spaceName) + .page(page) + .spaceQuotaDefinitionId( + quotaId) + .build()))) + .map(ResourceUtils::getEntity) + .map(SpaceEntity::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -253,26 +344,44 @@ public void listSpacesFilterByOrganizationId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName) - )) - .flatMap(function((organizationId, spaceId, quotaId) -> requestAssociateSpace(this.cloudFoundryClient, quotaId, spaceId) - .thenReturn(Tuples.of(organizationId, quotaId)))) - .flatMapMany(function((organizationId, quotaId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaceQuotaDefinitions() - .listSpaces(ListSpaceQuotaDefinitionSpacesRequest.builder() - .organizationId(organizationId) - .page(page) - .spaceQuotaDefinitionId(quotaId) - .build())))) - .map(ResourceUtils::getEntity) - .map(SpaceEntity::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, + organizationId, + quotaName))) + .flatMap( + function( + (organizationId, spaceId, quotaId) -> + requestAssociateSpace( + this.cloudFoundryClient, quotaId, spaceId) + .thenReturn(Tuples.of(organizationId, quotaId)))) + .flatMapMany( + function( + (organizationId, quotaId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .listSpaces( + ListSpaceQuotaDefinitionSpacesRequest + .builder() + .organizationId( + organizationId) + .page(page) + .spaceQuotaDefinitionId( + quotaId) + .build())))) + .map(ResourceUtils::getEntity) + .map(SpaceEntity::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -280,15 +389,25 @@ public void listSpacesNotFound() { String quotaName = this.nameFactory.getQuotaDefinitionName(); this.organizationId - .flatMap(organizationId -> createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName)) - .flatMapMany(quotaId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaceQuotaDefinitions() - .listSpaces(ListSpaceQuotaDefinitionSpacesRequest.builder() - .spaceQuotaDefinitionId(quotaId) - .build()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, organizationId, quotaName)) + .flatMapMany( + quotaId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .listSpaces( + ListSpaceQuotaDefinitionSpacesRequest + .builder() + .spaceQuotaDefinitionId( + quotaId) + .build()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -297,24 +416,40 @@ public void listSpacesQueryBySpaceId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName) - )) - .flatMap(function((spaceId, quotaId) -> requestAssociateSpace(this.cloudFoundryClient, quotaId, spaceId) - .thenReturn(quotaId))) - .flatMapMany(quotaId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaceQuotaDefinitions() - .listSpaces(ListSpaceQuotaDefinitionSpacesRequest.builder() - .page(page) - .spaceQuotaDefinitionId(quotaId) - .build()))) - .map(ResourceUtils::getEntity) - .map(SpaceEntity::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, + organizationId, + quotaName))) + .flatMap( + function( + (spaceId, quotaId) -> + requestAssociateSpace( + this.cloudFoundryClient, quotaId, spaceId) + .thenReturn(quotaId))) + .flatMapMany( + quotaId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .listSpaces( + ListSpaceQuotaDefinitionSpacesRequest + .builder() + .page(page) + .spaceQuotaDefinitionId( + quotaId) + .build()))) + .map(ResourceUtils::getEntity) + .map(SpaceEntity::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -323,20 +458,34 @@ public void removeSpace() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName) - )) - .flatMap(function((spaceId, quotaId) -> requestAssociateSpace(this.cloudFoundryClient, quotaId, spaceId) - .then(this.cloudFoundryClient.spaceQuotaDefinitions() - .removeSpace(RemoveSpaceQuotaDefinitionRequest.builder() - .spaceId(spaceId) - .spaceQuotaDefinitionId(quotaId) - .build())) - .then())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, + organizationId, + quotaName))) + .flatMap( + function( + (spaceId, quotaId) -> + requestAssociateSpace( + this.cloudFoundryClient, quotaId, spaceId) + .then( + this.cloudFoundryClient + .spaceQuotaDefinitions() + .removeSpace( + RemoveSpaceQuotaDefinitionRequest + .builder() + .spaceId(spaceId) + .spaceQuotaDefinitionId( + quotaId) + .build())) + .then())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -345,78 +494,101 @@ public void update() { String quotaName2 = this.nameFactory.getQuotaDefinitionName(); this.organizationId - .flatMap(organizationId -> createSpaceQuotaDefinitionId(this.cloudFoundryClient, organizationId, quotaName1)) - .flatMap(quotaId -> this.cloudFoundryClient.spaceQuotaDefinitions() - .update(UpdateSpaceQuotaDefinitionRequest.builder() - .name(quotaName2) - .spaceQuotaDefinitionId(quotaId) - .build())) - .thenMany(requestList(this.cloudFoundryClient) - .map(ResourceUtils::getEntity)) - .filter(quota -> quotaName2.equals(quota.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceQuotaDefinitionId( + this.cloudFoundryClient, organizationId, quotaName1)) + .flatMap( + quotaId -> + this.cloudFoundryClient + .spaceQuotaDefinitions() + .update( + UpdateSpaceQuotaDefinitionRequest.builder() + .name(quotaName2) + .spaceQuotaDefinitionId(quotaId) + .build())) + .thenMany(requestList(this.cloudFoundryClient).map(ResourceUtils::getEntity)) + .filter(quota -> quotaName2.equals(quota.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .organizationId(organizationId) - .name(spaceName) - .build()) - .map(ResourceUtils::getId); + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .organizationId(organizationId) + .name(spaceName) + .build()) + .map(ResourceUtils::getId); } - private static Mono createSpaceQuotaDefinitionId(CloudFoundryClient cloudFoundryClient, String organizationId, String quotaName) { + private static Mono createSpaceQuotaDefinitionId( + CloudFoundryClient cloudFoundryClient, String organizationId, String quotaName) { return requestCreateSpaceQuotaDefinition(cloudFoundryClient, organizationId, quotaName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono requestAssociateSpace(CloudFoundryClient cloudFoundryClient, String quotaId, String spaceId) { - return cloudFoundryClient.spaceQuotaDefinitions() - .associateSpace(AssociateSpaceQuotaDefinitionRequest.builder() - .spaceId(spaceId) - .spaceQuotaDefinitionId(quotaId) - .build()); + private static Mono requestAssociateSpace( + CloudFoundryClient cloudFoundryClient, String quotaId, String spaceId) { + return cloudFoundryClient + .spaceQuotaDefinitions() + .associateSpace( + AssociateSpaceQuotaDefinitionRequest.builder() + .spaceId(spaceId) + .spaceQuotaDefinitionId(quotaId) + .build()); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .buildpack("staticfile_buildpack") + .diego(true) + .diskQuota(512) + .memory(64) + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateSpaceQuotaDefinition(CloudFoundryClient cloudFoundryClient, String organizationId, String quotaName) { - return cloudFoundryClient.spaceQuotaDefinitions() - .create(CreateSpaceQuotaDefinitionRequest.builder() - .memoryLimit(512) - .name(quotaName) - .nonBasicServicesAllowed(false) - .organizationId(organizationId) - .totalRoutes(1) - .totalServices(1) - .build()); + private static Mono requestCreateSpaceQuotaDefinition( + CloudFoundryClient cloudFoundryClient, String organizationId, String quotaName) { + return cloudFoundryClient + .spaceQuotaDefinitions() + .create( + CreateSpaceQuotaDefinitionRequest.builder() + .memoryLimit(512) + .name(quotaName) + .nonBasicServicesAllowed(false) + .organizationId(organizationId) + .totalRoutes(1) + .totalServices(1) + .build()); } - private static Flux requestList(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaceQuotaDefinitions() - .list(ListSpaceQuotaDefinitionsRequest.builder() - .page(page) - .build())); + private static Flux requestList( + CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaceQuotaDefinitions() + .list( + ListSpaceQuotaDefinitionsRequest.builder() + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/SpacesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/SpacesTest.java index fe2cb72c408..4193ec53d6e 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/SpacesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/SpacesTest.java @@ -16,6 +16,16 @@ package org.cloudfoundry.client.v2; +import static java.time.temporal.ChronoUnit.MINUTES; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.time.Instant; +import java.util.Collections; +import java.util.Date; +import java.util.function.Function; +import java.util.function.UnaryOperator; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.ApplicationResource; @@ -98,46 +108,29 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuple2; -import java.time.Duration; -import java.time.Instant; -import java.util.Collections; -import java.util.Date; -import java.util.function.Function; -import java.util.function.UnaryOperator; - -import static java.time.temporal.ChronoUnit.MINUTES; -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class SpacesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; - @Autowired - private Mono stackId; + @Autowired private Mono stackId; - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; @Test public void associateAuditor() { @@ -145,20 +138,30 @@ public void associateAuditor() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .flatMap(function((spaceId, userId) -> Mono.zip( - Mono.just(spaceId), - this.cloudFoundryClient.spaces() - .associateAuditor(AssociateSpaceAuditorRequest.builder() - .spaceId(spaceId) - .auditorId(userId) - .build()) - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .flatMap( + function( + (spaceId, userId) -> + Mono.zip( + Mono.just(spaceId), + this.cloudFoundryClient + .spaces() + .associateAuditor( + AssociateSpaceAuditorRequest + .builder() + .spaceId(spaceId) + .auditorId(userId) + .build()) + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -167,19 +170,33 @@ public void associateAuditorByUsername() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .associateAuditorByUsername(AssociateSpaceAuditorByUsernameRequest.builder() - .spaceId(spaceId) - .username(userName) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceAuditors(this.cloudFoundryClient, spaceId) - .map(ResourceUtils::getEntity) - .map(UserEntity::getUsername))) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .associateAuditorByUsername( + AssociateSpaceAuditorByUsernameRequest + .builder() + .spaceId(spaceId) + .username(userName) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceAuditors(this.cloudFoundryClient, spaceId) + .map(ResourceUtils::getEntity) + .map(UserEntity::getUsername))) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -188,20 +205,30 @@ public void associateDeveloper() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .flatMap(function((spaceId, userId) -> Mono.zip( - Mono.just(spaceId), - this.cloudFoundryClient.spaces() - .associateDeveloper(AssociateSpaceDeveloperRequest.builder() - .spaceId(spaceId) - .developerId(userId) - .build()) - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .flatMap( + function( + (spaceId, userId) -> + Mono.zip( + Mono.just(spaceId), + this.cloudFoundryClient + .spaces() + .associateDeveloper( + AssociateSpaceDeveloperRequest + .builder() + .spaceId(spaceId) + .developerId(userId) + .build()) + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -210,18 +237,35 @@ public void associateDeveloperByUsername() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .associateDeveloperByUsername(AssociateSpaceDeveloperByUsernameRequest.builder() - .spaceId(spaceId) - .username(userName) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceDevelopers(this.cloudFoundryClient, spaceId) - .map(response -> ResourceUtils.getEntity(response).getUsername()))) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .associateDeveloperByUsername( + AssociateSpaceDeveloperByUsernameRequest + .builder() + .spaceId(spaceId) + .username(userName) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceDevelopers(this.cloudFoundryClient, spaceId) + .map( + response -> + ResourceUtils.getEntity(response) + .getUsername()))) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -230,20 +274,30 @@ public void associateManager() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .flatMap(function((spaceId, userId) -> Mono.zip( - Mono.just(spaceId), - this.cloudFoundryClient.spaces() - .associateManager(AssociateSpaceManagerRequest.builder() - .spaceId(spaceId) - .managerId(userId) - .build()) - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .flatMap( + function( + (spaceId, userId) -> + Mono.zip( + Mono.just(spaceId), + this.cloudFoundryClient + .spaces() + .associateManager( + AssociateSpaceManagerRequest + .builder() + .spaceId(spaceId) + .managerId(userId) + .build()) + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -252,18 +306,35 @@ public void associateManagerByUsername() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .associateManagerByUsername(AssociateSpaceManagerByUsernameRequest.builder() - .spaceId(spaceId) - .username(userName) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceManagers(this.cloudFoundryClient, spaceId) - .map(response -> ResourceUtils.getEntity(response).getUsername()))) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .associateManagerByUsername( + AssociateSpaceManagerByUsernameRequest + .builder() + .spaceId(spaceId) + .username(userName) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceManagers(this.cloudFoundryClient, spaceId) + .map( + response -> + ResourceUtils.getEntity(response) + .getUsername()))) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -272,22 +343,32 @@ public void associateSecurityGroup() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSecurityGroupId(this.cloudFoundryClient, securityGroupName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((securityGroupId, spaceId) -> this.cloudFoundryClient.spaces() - .associateSecurityGroup(AssociateSpaceSecurityGroupRequest.builder() - .securityGroupId(securityGroupId) - .spaceId(spaceId) - .build()) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> requestListSecurityGroups(this.cloudFoundryClient, spaceId)) - .filter(response -> securityGroupName.equals(response.getEntity().getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSecurityGroupId( + this.cloudFoundryClient, securityGroupName), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (securityGroupId, spaceId) -> + this.cloudFoundryClient + .spaces() + .associateSecurityGroup( + AssociateSpaceSecurityGroupRequest.builder() + .securityGroupId(securityGroupId) + .spaceId(spaceId) + .build()) + .thenReturn(spaceId))) + .flatMapMany(spaceId -> requestListSecurityGroups(this.cloudFoundryClient, spaceId)) + .filter(response -> securityGroupName.equals(response.getEntity().getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -295,16 +376,20 @@ public void create() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> this.cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .organizationId(organizationId) - .name(spaceName) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .organizationId(organizationId) + .name(spaceName) + .build())) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -312,19 +397,32 @@ public void delete() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .delayUntil(spaceId -> this.cloudFoundryClient.spaces() - .delete(DeleteSpaceRequest.builder() - .spaceId(spaceId) - .async(true) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMapMany(spaceId -> requestListSpaces(this.cloudFoundryClient) - .map(ResourceUtils::getId) - .filter(spaceId::equals)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .delayUntil( + spaceId -> + this.cloudFoundryClient + .spaces() + .delete( + DeleteSpaceRequest.builder() + .spaceId(spaceId) + .async(true) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMapMany( + spaceId -> + requestListSpaces(this.cloudFoundryClient) + .map(ResourceUtils::getId) + .filter(spaceId::equals)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -332,18 +430,26 @@ public void deleteAsyncFalse() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .delayUntil(spaceId -> this.cloudFoundryClient.spaces() - .delete(DeleteSpaceRequest.builder() - .spaceId(spaceId) - .async(false) - .build())) - .flatMapMany(spaceId -> requestListSpaces(this.cloudFoundryClient) - .map(ResourceUtils::getId) - .filter(spaceId::equals)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .delayUntil( + spaceId -> + this.cloudFoundryClient + .spaces() + .delete( + DeleteSpaceRequest.builder() + .spaceId(spaceId) + .async(false) + .build())) + .flatMapMany( + spaceId -> + requestListSpaces(this.cloudFoundryClient) + .map(ResourceUtils::getId) + .filter(spaceId::equals)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -351,16 +457,19 @@ public void get() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> this.cloudFoundryClient.spaces() - .get(GetSpaceRequest.builder() - .spaceId(spaceId) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + this.cloudFoundryClient + .spaces() + .get(GetSpaceRequest.builder().spaceId(spaceId).build())) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -368,16 +477,22 @@ public void getSummary() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> this.cloudFoundryClient.spaces() - .getSummary(GetSpaceSummaryRequest.builder() - .spaceId(spaceId) - .build())) - .map(GetSpaceSummaryResponse::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + this.cloudFoundryClient + .spaces() + .getSummary( + GetSpaceSummaryRequest.builder() + .spaceId(spaceId) + .build())) + .map(GetSpaceSummaryResponse::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -386,18 +501,33 @@ public void list() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationIdAndSpaceId(this.cloudFoundryClient, organizationName, spaceName) - .flatMap(function((organizationId, spaceId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaces() - .list(ListSpacesRequest.builder() - .page(page) - .build())) - .filter(response -> organizationId.equals(ResourceUtils.getEntity(response).getOrganizationId())) - .single() - .map(response -> ResourceUtils.getEntity(response).getName()))) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaces() + .list( + ListSpacesRequest + .builder() + .page(page) + .build())) + .filter( + response -> + organizationId.equals( + ResourceUtils.getEntity( + response) + .getOrganizationId())) + .single() + .map( + response -> + ResourceUtils.getEntity(response) + .getName()))) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -406,15 +536,22 @@ public void listApplications() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .delayUntil(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(spaceId -> requestListSpaceApplications(this.cloudFoundryClient, spaceId) - .single()) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .delayUntil( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + spaceId -> + requestListSpaceApplications(this.cloudFoundryClient, spaceId) + .single()) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -423,15 +560,25 @@ public void listApplicationsFilterByDiego() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .delayUntil(spaceId -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName)) - .flatMap(spaceId -> requestListSpaceApplications(this.cloudFoundryClient, spaceId, builder -> builder.diego(true)) - .single()) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .delayUntil( + spaceId -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName)) + .flatMap( + spaceId -> + requestListSpaceApplications( + this.cloudFoundryClient, + spaceId, + builder -> builder.diego(true)) + .single()) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -440,21 +587,32 @@ public void listApplicationsFilterByName() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - )) - .flatMapMany(function((spaceId, applicationId) -> Mono.zip( - Mono.just(applicationId), - requestListSpaceApplications(this.cloudFoundryClient, spaceId, builder -> builder.name(applicationName)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName))) + .flatMapMany( + function( + (spaceId, applicationId) -> + Mono.zip( + Mono.just(applicationId), + requestListSpaceApplications( + this.cloudFoundryClient, + spaceId, + builder -> + builder.name( + applicationName)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -463,17 +621,31 @@ public void listApplicationsFilterByOrganizationId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .delayUntil(function((organizationId, spaceId) -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName))) - .flatMapMany(function((organizationId, spaceId) -> requestListSpaceApplications(this.cloudFoundryClient, spaceId, builder -> builder.organizationId(organizationId)))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .delayUntil( + function( + (organizationId, spaceId) -> + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName))) + .flatMapMany( + function( + (organizationId, spaceId) -> + requestListSpaceApplications( + this.cloudFoundryClient, + spaceId, + builder -> builder.organizationId(organizationId)))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -482,17 +654,35 @@ public void listApplicationsFilterByStackId() { String spaceName = this.nameFactory.getSpaceName(); Mono.zip(this.organizationId, this.stackId) - .flatMap(function((organizationId, stackId) -> Mono.zip( - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - Mono.just(stackId) - ))) - .delayUntil(function((spaceId, stackId) -> createApplicationId(this.cloudFoundryClient, spaceId, applicationName, stackId))) - .flatMapMany(function((spaceId, stackId) -> requestListSpaceApplications(this.cloudFoundryClient, spaceId, builder -> builder.stackId(stackId)))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, stackId) -> + Mono.zip( + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName), + Mono.just(stackId)))) + .delayUntil( + function( + (spaceId, stackId) -> + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName, + stackId))) + .flatMapMany( + function( + (spaceId, stackId) -> + requestListSpaceApplications( + this.cloudFoundryClient, + spaceId, + builder -> builder.stackId(stackId)))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -501,23 +691,40 @@ public void listAuditors() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .associateAuditor(AssociateSpaceAuditorRequest.builder() - .spaceId(spaceId) - .auditorId(userId) - .build()))) - .flatMapMany(function((spaceId, userId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaces() - .listAuditors(ListSpaceAuditorsRequest.builder() - .page(page) - .spaceId(spaceId) - .build())))) - .map(response -> ResourceUtils.getEntity(response).getUsername()) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .associateAuditor( + AssociateSpaceAuditorRequest.builder() + .spaceId(spaceId) + .auditorId(userId) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaces() + .listAuditors( + ListSpaceAuditorsRequest + .builder() + .page(page) + .spaceId(spaceId) + .build())))) + .map(response -> ResourceUtils.getEntity(response).getUsername()) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -526,23 +733,40 @@ public void listDevelopers() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .associateDeveloper(AssociateSpaceDeveloperRequest.builder() - .spaceId(spaceId) - .developerId(userId) - .build()))) - .flatMapMany(function((spaceId, userId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaces() - .listDevelopers(ListSpaceDevelopersRequest.builder() - .page(page) - .spaceId(spaceId) - .build())))) - .map(response -> ResourceUtils.getEntity(response).getUsername()) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .associateDeveloper( + AssociateSpaceDeveloperRequest.builder() + .spaceId(spaceId) + .developerId(userId) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaces() + .listDevelopers( + ListSpaceDevelopersRequest + .builder() + .page(page) + .spaceId(spaceId) + .build())))) + .map(response -> ResourceUtils.getEntity(response).getUsername()) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("deprecation") @@ -552,13 +776,22 @@ public void listDomains() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceIdWithDomain(this.cloudFoundryClient, organizationId, spaceName, domainName)) - .flatMapMany(spaceId -> requestListSpaceDomains(this.cloudFoundryClient, spaceId)) - .filter(domainResource -> domainName.equals(ResourceUtils.getEntity(domainResource).getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceIdWithDomain( + this.cloudFoundryClient, + organizationId, + spaceName, + domainName)) + .flatMapMany(spaceId -> requestListSpaceDomains(this.cloudFoundryClient, spaceId)) + .filter( + domainResource -> + domainName.equals( + ResourceUtils.getEntity(domainResource).getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("deprecation") @@ -568,13 +801,24 @@ public void listDomainsFilterByName() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceIdWithDomain(this.cloudFoundryClient, organizationId, spaceName, domainName)) - .flatMapMany(spaceId -> requestListSpaceDomains(this.cloudFoundryClient, spaceId, builder -> builder.name(domainName))) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(domainName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceIdWithDomain( + this.cloudFoundryClient, + organizationId, + spaceName, + domainName)) + .flatMapMany( + spaceId -> + requestListSpaceDomains( + this.cloudFoundryClient, + spaceId, + builder -> builder.name(domainName))) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(domainName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -582,13 +826,15 @@ public void listEvents() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMapMany(spaceId -> requestListSpaceEvents(this.cloudFoundryClient, spaceId)) - .map(response -> ResourceUtils.getEntity(response).getType()) - .as(StepVerifier::create) - .expectNext("audit.space.create") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMapMany(spaceId -> requestListSpaceEvents(this.cloudFoundryClient, spaceId)) + .map(response -> ResourceUtils.getEntity(response).getType()) + .as(StepVerifier::create) + .expectNext("audit.space.create") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -596,13 +842,20 @@ public void listEventsFilterByActee() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMapMany(spaceId -> requestListSpaceEvents(this.cloudFoundryClient, spaceId, builder -> builder.actee(spaceId))) - .map(response -> ResourceUtils.getEntity(response).getType()) - .as(StepVerifier::create) - .expectNext("audit.space.create") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMapMany( + spaceId -> + requestListSpaceEvents( + this.cloudFoundryClient, + spaceId, + builder -> builder.actee(spaceId))) + .map(response -> ResourceUtils.getEntity(response).getType()) + .as(StepVerifier::create) + .expectNext("audit.space.create") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -611,13 +864,20 @@ public void listEventsFilterByTimestamp() { String timestamp = getPastTimestamp(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMapMany(spaceId -> requestListSpaceEvents(this.cloudFoundryClient, spaceId, builder -> builder.timestamp(timestamp))) - .map(response -> ResourceUtils.getEntity(response).getType()) - .as(StepVerifier::create) - .expectNext("audit.space.create") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMapMany( + spaceId -> + requestListSpaceEvents( + this.cloudFoundryClient, + spaceId, + builder -> builder.timestamp(timestamp))) + .map(response -> ResourceUtils.getEntity(response).getType()) + .as(StepVerifier::create) + .expectNext("audit.space.create") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -625,17 +885,27 @@ public void listEventsFilterByType() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - requestListSpaceEvents(this.cloudFoundryClient, spaceId, builder -> builder.type("audit.space.create")) - .single() - .map(response -> ResourceUtils.getEntity(response).getSpaceId()) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + requestListSpaceEvents( + this.cloudFoundryClient, + spaceId, + builder -> + builder.type("audit.space.create")) + .single() + .map( + response -> + ResourceUtils.getEntity(response) + .getSpaceId()))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -644,21 +914,31 @@ public void listFilterByApplicationId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, spaceId, applicationName) - )) - .flatMap(function((spaceId, applicationId) -> Mono.zip( - Mono.just(spaceId), - requestListSpaces(this.cloudFoundryClient, builder -> builder.applicationId(applicationId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, spaceId, applicationName))) + .flatMap( + function( + (spaceId, applicationId) -> + Mono.zip( + Mono.just(spaceId), + requestListSpaces( + this.cloudFoundryClient, + builder -> + builder.applicationId( + applicationId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -667,18 +947,32 @@ public void listFilterByDeveloperId() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, userId, spaceId))) - .flatMap(function((spaceId, userId) -> Mono.zip( - Mono.just(spaceId), - requestListSpaces(this.cloudFoundryClient, builder -> builder.developerId(userId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, userId, spaceId))) + .flatMap( + function( + (spaceId, userId) -> + Mono.zip( + Mono.just(spaceId), + requestListSpaces( + this.cloudFoundryClient, + builder -> + builder.developerId(userId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -686,17 +980,22 @@ public void listFilterByName() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - requestListSpaces(this.cloudFoundryClient, builder -> builder.name(spaceName)) - .single() - .map(ResourceUtils::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + requestListSpaces( + this.cloudFoundryClient, + builder -> builder.name(spaceName)) + .single() + .map(ResourceUtils::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -705,16 +1004,22 @@ public void listFilterByOrganizationId() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationIdAndSpaceId(this.cloudFoundryClient, organizationName, spaceName) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - Mono.just(spaceId), - requestListSpaces(this.cloudFoundryClient, builder -> builder.organizationId(organizationId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + Mono.just(spaceId), + requestListSpaces( + this.cloudFoundryClient, + builder -> + builder.organizationId( + organizationId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -723,14 +1028,29 @@ public void listManagers() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceManagers(this.cloudFoundryClient, spaceId) - .map(response -> ResourceUtils.getEntity(response).getUsername()))) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceManagers(this.cloudFoundryClient, spaceId) + .map( + response -> + ResourceUtils.getEntity(response) + .getUsername()))) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -740,24 +1060,49 @@ public void listManagersFilterByAuditedOrganizationId() { String userName = this.nameFactory.getUserName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createUserId(this.cloudFoundryClient, this.uaaClient, organizationId, userName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - Mono.just(organizationId) - )) - .delayUntil(function((userId, spaceId, organizationId) -> Mono.zip( - requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId), - this.cloudFoundryClient.organizations() - .associateAuditor(AssociateOrganizationAuditorRequest.builder() - .organizationId(organizationId) - .auditorId(userId) - .build())))) - .flatMapMany(function((userId, spaceId, organizationId) -> requestListSpaceManagers(this.cloudFoundryClient, spaceId, builder -> builder.auditedOrganizationId(organizationId)) - .map(response -> ResourceUtils.getEntity(response).getUsername()))) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationId, + userName), + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + Mono.just(organizationId))) + .delayUntil( + function( + (userId, spaceId, organizationId) -> + Mono.zip( + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId), + this.cloudFoundryClient + .organizations() + .associateAuditor( + AssociateOrganizationAuditorRequest + .builder() + .organizationId( + organizationId) + .auditorId(userId) + .build())))) + .flatMapMany( + function( + (userId, spaceId, organizationId) -> + requestListSpaceManagers( + this.cloudFoundryClient, + spaceId, + builder -> + builder.auditedOrganizationId( + organizationId)) + .map( + response -> + ResourceUtils.getEntity(response) + .getUsername()))) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -766,17 +1111,35 @@ public void listManagersFilterByAuditedSpaceId() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> Mono.zip( - requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId), - requestAssociateSpaceAuditor(this.cloudFoundryClient, spaceId, userId) - ))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceManagers(this.cloudFoundryClient, spaceId, builder -> builder.auditedSpaceId(spaceId)) - .map(response -> ResourceUtils.getEntity(response).getUsername()))) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + Mono.zip( + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId), + requestAssociateSpaceAuditor( + this.cloudFoundryClient, spaceId, userId)))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceManagers( + this.cloudFoundryClient, + spaceId, + builder -> builder.auditedSpaceId(spaceId)) + .map( + response -> + ResourceUtils.getEntity(response) + .getUsername()))) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -786,29 +1149,50 @@ public void listManagersFilterByBillingManagedOrganizationId() { String userName = this.nameFactory.getUserName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createUserId(this.cloudFoundryClient, this.uaaClient, organizationId, userName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - Mono.just(organizationId) - )) - .delayUntil(function((userId, spaceId, organizationId) -> Mono.zip( - requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId), - this.cloudFoundryClient.organizations() - .associateBillingManager(AssociateOrganizationBillingManagerRequest.builder() - .organizationId(organizationId) - .billingManagerId(userId) - .build()) - ))) - .flatMap(function((userId, spaceId, organizationId) -> Mono.zip( - Mono.just(userId), - requestListSpaceManagers(this.cloudFoundryClient, spaceId, builder -> builder.billingManagedOrganizationId(organizationId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationId, + userName), + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + Mono.just(organizationId))) + .delayUntil( + function( + (userId, spaceId, organizationId) -> + Mono.zip( + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId), + this.cloudFoundryClient + .organizations() + .associateBillingManager( + AssociateOrganizationBillingManagerRequest + .builder() + .organizationId( + organizationId) + .billingManagerId(userId) + .build())))) + .flatMap( + function( + (userId, spaceId, organizationId) -> + Mono.zip( + Mono.just(userId), + requestListSpaceManagers( + this.cloudFoundryClient, + spaceId, + builder -> + builder + .billingManagedOrganizationId( + organizationId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -818,29 +1202,50 @@ public void listManagersFilterByManagedOrganizationId() { String userName = this.nameFactory.getUserName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createUserId(this.cloudFoundryClient, this.uaaClient, organizationId, userName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - Mono.just(organizationId) - )) - .delayUntil(function((userId, spaceId, organizationId) -> Mono.zip( - requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId), - this.cloudFoundryClient.organizations() - .associateManager(AssociateOrganizationManagerRequest.builder() - .organizationId(organizationId) - .managerId(userId) - .build()) - ))) - .flatMap(function((userId, spaceId, organizationId) -> Mono.zip( - Mono.just(userId), - requestListSpaceManagers(this.cloudFoundryClient, spaceId, builder -> builder.managedOrganizationId(organizationId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationId, + userName), + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + Mono.just(organizationId))) + .delayUntil( + function( + (userId, spaceId, organizationId) -> + Mono.zip( + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId), + this.cloudFoundryClient + .organizations() + .associateManager( + AssociateOrganizationManagerRequest + .builder() + .organizationId( + organizationId) + .managerId(userId) + .build())))) + .flatMap( + function( + (userId, spaceId, organizationId) -> + Mono.zip( + Mono.just(userId), + requestListSpaceManagers( + this.cloudFoundryClient, + spaceId, + builder -> + builder + .managedOrganizationId( + organizationId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -849,14 +1254,32 @@ public void listManagersFilterByManagedSpaceId() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceManagers(this.cloudFoundryClient, spaceId, builder -> builder.managedSpaceId(spaceId)) - .map(response -> ResourceUtils.getEntity(response).getUsername()))) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceManagers( + this.cloudFoundryClient, + spaceId, + builder -> builder.managedSpaceId(spaceId)) + .map( + response -> + ResourceUtils.getEntity(response) + .getUsername()))) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -866,22 +1289,39 @@ public void listManagersFilterByOrganizationId() { String userName = this.nameFactory.getUserName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createUserId(this.cloudFoundryClient, this.uaaClient, organizationId, userName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName), - Mono.just(organizationId) - )) - .delayUntil(function((userId, spaceId, organizationId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .flatMap(function((userId, spaceId, organizationId) -> Mono.zip( - Mono.just(userId), - requestListSpaceManagers(this.cloudFoundryClient, spaceId, builder -> builder.organizationId(organizationId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationId, + userName), + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName), + Mono.just(organizationId))) + .delayUntil( + function( + (userId, spaceId, organizationId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .flatMap( + function( + (userId, spaceId, organizationId) -> + Mono.zip( + Mono.just(userId), + requestListSpaceManagers( + this.cloudFoundryClient, + spaceId, + builder -> + builder.organizationId( + organizationId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -891,21 +1331,36 @@ public void listRoutes() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceIdWithDomain(this.cloudFoundryClient, organizationId, spaceName, domainName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - createRouteId(this.cloudFoundryClient, spaceId, domainName, hostName, "/test-path") - )) - .flatMapMany(function((spaceId, routeId) -> Mono.zip( - Mono.just(routeId), - requestListSpaceRoutes(this.cloudFoundryClient, spaceId) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceIdWithDomain( + this.cloudFoundryClient, + organizationId, + spaceName, + domainName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + createRouteId( + this.cloudFoundryClient, + spaceId, + domainName, + hostName, + "/test-path"))) + .flatMapMany( + function( + (spaceId, routeId) -> + Mono.zip( + Mono.just(routeId), + requestListSpaceRoutes( + this.cloudFoundryClient, spaceId) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -915,22 +1370,40 @@ public void listRoutesFilterByDomainId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceIdWithDomain(this.cloudFoundryClient, organizationId, spaceName, domainName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - getSharedDomainId(this.cloudFoundryClient, domainName), - createRouteId(this.cloudFoundryClient, spaceId, domainName, hostName, "/test-path") - )) - .flatMapMany(function((spaceId, domainId, routeId) -> Mono.zip( - Mono.just(routeId), - requestListSpaceRoutes(this.cloudFoundryClient, spaceId, builder -> builder.domainId(domainId)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceIdWithDomain( + this.cloudFoundryClient, + organizationId, + spaceName, + domainName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + getSharedDomainId(this.cloudFoundryClient, domainName), + createRouteId( + this.cloudFoundryClient, + spaceId, + domainName, + hostName, + "/test-path"))) + .flatMapMany( + function( + (spaceId, domainId, routeId) -> + Mono.zip( + Mono.just(routeId), + requestListSpaceRoutes( + this.cloudFoundryClient, + spaceId, + builder -> + builder.domainId(domainId)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -940,21 +1413,38 @@ public void listRoutesFilterByHost() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceIdWithDomain(this.cloudFoundryClient, organizationId, spaceName, domainName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - createRouteId(this.cloudFoundryClient, spaceId, domainName, hostName, "/test-path") - )) - .flatMapMany(function((spaceId, routeId) -> Mono.zip( - Mono.just(routeId), - requestListSpaceRoutes(this.cloudFoundryClient, spaceId, builder -> builder.host(hostName)) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceIdWithDomain( + this.cloudFoundryClient, + organizationId, + spaceName, + domainName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + createRouteId( + this.cloudFoundryClient, + spaceId, + domainName, + hostName, + "/test-path"))) + .flatMapMany( + function( + (spaceId, routeId) -> + Mono.zip( + Mono.just(routeId), + requestListSpaceRoutes( + this.cloudFoundryClient, + spaceId, + builder -> builder.host(hostName)) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -964,21 +1454,39 @@ public void listRoutesFilterByPath() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceIdWithDomain(this.cloudFoundryClient, organizationId, spaceName, domainName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - createRouteId(this.cloudFoundryClient, spaceId, domainName, hostName, "/test-path") - )) - .flatMapMany(function((spaceId, routeId) -> Mono.zip( - Mono.just(routeId), - requestListSpaceRoutes(this.cloudFoundryClient, spaceId, builder -> builder.path("/test-path")) - .single() - .map(ResourceUtils::getId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceIdWithDomain( + this.cloudFoundryClient, + organizationId, + spaceName, + domainName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + createRouteId( + this.cloudFoundryClient, + spaceId, + domainName, + hostName, + "/test-path"))) + .flatMapMany( + function( + (spaceId, routeId) -> + Mono.zip( + Mono.just(routeId), + requestListSpaceRoutes( + this.cloudFoundryClient, + spaceId, + builder -> + builder.path("/test-path")) + .single() + .map(ResourceUtils::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -987,23 +1495,40 @@ public void listSecurityGroups() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSecurityGroupId(this.cloudFoundryClient, securityGroupName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((securityGroupId, spaceId) -> requestAssociateSpaceSecurityGroup(this.cloudFoundryClient, spaceId, securityGroupId) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaces() - .listSecurityGroups(ListSpaceSecurityGroupsRequest.builder() - .page(page) - .spaceId(spaceId) - .build()))) - .filter(response -> securityGroupName.equals(response.getEntity().getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSecurityGroupId( + this.cloudFoundryClient, securityGroupName), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (securityGroupId, spaceId) -> + requestAssociateSpaceSecurityGroup( + this.cloudFoundryClient, + spaceId, + securityGroupId) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaces() + .listSecurityGroups( + ListSpaceSecurityGroupsRequest + .builder() + .page(page) + .spaceId(spaceId) + .build()))) + .filter(response -> securityGroupName.equals(response.getEntity().getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1012,23 +1537,40 @@ public void listSecurityGroupsFilterByName() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSecurityGroupId(this.cloudFoundryClient, securityGroupName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((securityGroupId, spaceId) -> requestAssociateSpaceSecurityGroup(this.cloudFoundryClient, spaceId, securityGroupId) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaces() - .listSecurityGroups(ListSpaceSecurityGroupsRequest.builder() - .page(page) - .spaceId(spaceId) - .name(securityGroupName) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSecurityGroupId( + this.cloudFoundryClient, securityGroupName), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (securityGroupId, spaceId) -> + requestAssociateSpaceSecurityGroup( + this.cloudFoundryClient, + spaceId, + securityGroupId) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaces() + .listSecurityGroups( + ListSpaceSecurityGroupsRequest + .builder() + .page(page) + .spaceId(spaceId) + .name(securityGroupName) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1037,18 +1579,34 @@ public void listServiceInstances() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - this.serviceBrokerId, - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> requestListServiceInstances(this.cloudFoundryClient, spaceId)) - .filter(resource -> serviceInstanceName.equals(ResourceUtils.getEntity(resource).getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + this.serviceBrokerId, + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> requestListServiceInstances(this.cloudFoundryClient, spaceId)) + .filter( + resource -> + serviceInstanceName.equals( + ResourceUtils.getEntity(resource).getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1057,17 +1615,34 @@ public void listServiceInstancesFilterByGatewayName() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - this.serviceBrokerId, - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> requestListServiceInstances(this.cloudFoundryClient, spaceId, builder -> builder.gatewayName("test-gateway-name"))) - .as(StepVerifier::create) - .expectNextCount(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + this.serviceBrokerId, + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + requestListServiceInstances( + this.cloudFoundryClient, + spaceId, + builder -> builder.gatewayName("test-gateway-name"))) + .as(StepVerifier::create) + .expectNextCount(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1076,17 +1651,34 @@ public void listServiceInstancesFilterByName() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - this.serviceBrokerId, - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((serviceBrokerId, spaceId) -> createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> requestListServiceInstances(this.cloudFoundryClient, spaceId, builder -> builder.name(serviceInstanceName))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + this.serviceBrokerId, + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + requestListServiceInstances( + this.cloudFoundryClient, + spaceId, + builder -> builder.name(serviceInstanceName))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1096,24 +1688,51 @@ public void listServiceInstancesFilterByServiceBindingId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - this.serviceBrokerId, - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((serviceBrokerId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, spaceId, applicationName), - createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((applicationId, serviceInstanceId, spaceId) -> Mono.zip( - createServiceBindingId(this.cloudFoundryClient, applicationId, serviceInstanceId), - Mono.just(spaceId) - ))) - .flatMapMany(function((serviceBindingId, spaceId) -> requestListServiceInstances(this.cloudFoundryClient, spaceId, builder -> builder.serviceBindingId(serviceBindingId)))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + this.serviceBrokerId, + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + spaceId, + applicationName), + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (applicationId, serviceInstanceId, spaceId) -> + Mono.zip( + createServiceBindingId( + this.cloudFoundryClient, + applicationId, + serviceInstanceId), + Mono.just(spaceId)))) + .flatMapMany( + function( + (serviceBindingId, spaceId) -> + requestListServiceInstances( + this.cloudFoundryClient, + spaceId, + builder -> + builder.serviceBindingId( + serviceBindingId)))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1123,23 +1742,45 @@ public void listServiceInstancesFilterByServiceKeyId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - this.serviceBrokerId, - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((serviceBrokerId, spaceId) -> Mono.zip( - createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - Mono.just(spaceId) - ))) - .flatMap(function((serviceInstanceId, spaceId) -> Mono.zip( - createServiceKeyId(this.cloudFoundryClient, serviceInstanceId, serviceKeyName), - Mono.just(spaceId) - ))) - .flatMapMany(function((serviceKeyId, spaceId) -> requestListServiceInstances(this.cloudFoundryClient, spaceId, builder -> builder.serviceKeyId(serviceKeyId)))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + this.serviceBrokerId, + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + Mono.zip( + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + Mono.just(spaceId)))) + .flatMap( + function( + (serviceInstanceId, spaceId) -> + Mono.zip( + createServiceKeyId( + this.cloudFoundryClient, + serviceInstanceId, + serviceKeyName), + Mono.just(spaceId)))) + .flatMapMany( + function( + (serviceKeyId, spaceId) -> + requestListServiceInstances( + this.cloudFoundryClient, + spaceId, + builder -> builder.serviceKeyId(serviceKeyId)))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1148,70 +1789,121 @@ public void listServiceInstancesFilterByServicePlanId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - this.serviceBrokerId, - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((serviceBrokerId, spaceId) -> Mono.zip( - createServiceInstanceId(this.cloudFoundryClient, serviceBrokerId, serviceInstanceName, this.serviceName, spaceId), - getServicePlanId(this.cloudFoundryClient, serviceBrokerId, this.serviceName), - Mono.just(spaceId) - ))) - .flatMapMany(function((ignore, servicePlanId, spaceId) -> requestListServiceInstances(this.cloudFoundryClient, spaceId, builder -> builder.servicePlanId(servicePlanId)))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + this.serviceBrokerId, + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (serviceBrokerId, spaceId) -> + Mono.zip( + createServiceInstanceId( + this.cloudFoundryClient, + serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId), + getServicePlanId( + this.cloudFoundryClient, + serviceBrokerId, + this.serviceName), + Mono.just(spaceId)))) + .flatMapMany( + function( + (ignore, servicePlanId, spaceId) -> + requestListServiceInstances( + this.cloudFoundryClient, + spaceId, + builder -> builder.servicePlanId(servicePlanId)))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServices() { this.spaceId - .flatMapMany(spaceId -> requestListSpaceServices(this.cloudFoundryClient, spaceId) - .filter(resource -> this.serviceName.equals(ResourceUtils.getEntity(resource).getLabel()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + requestListSpaceServices(this.cloudFoundryClient, spaceId) + .filter( + resource -> + this.serviceName.equals( + ResourceUtils.getEntity(resource) + .getLabel()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServicesFilterByActive() { this.spaceId - .flatMapMany(spaceId -> requestListSpaceServices(this.cloudFoundryClient, spaceId) - .filter(resource -> this.serviceName.equals(ResourceUtils.getEntity(resource).getLabel()))) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + requestListSpaceServices(this.cloudFoundryClient, spaceId) + .filter( + resource -> + this.serviceName.equals( + ResourceUtils.getEntity(resource) + .getLabel()))) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServicesFilterByLabel() { - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMapMany(function((serviceBrokerId, spaceId) -> requestListSpaceServices(this.cloudFoundryClient, spaceId, builder -> builder.label(this.serviceName)) - .filter(resource -> serviceBrokerId.equals(ResourceUtils.getEntity(resource).getServiceBrokerId())))) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - //TODO: Await https://github.com/cloudfoundry/cloud_controller_ng/issues/856 for this test to work - @Ignore("Await https://github.com/cloudfoundry/cloud_controller_ng/issues/856 for this test to work") + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMapMany( + function( + (serviceBrokerId, spaceId) -> + requestListSpaceServices( + this.cloudFoundryClient, + spaceId, + builder -> builder.label(this.serviceName)) + .filter( + resource -> + serviceBrokerId.equals( + ResourceUtils.getEntity( + resource) + .getServiceBrokerId())))) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + // TODO: Await https://github.com/cloudfoundry/cloud_controller_ng/issues/856 for this test to + // work + @Disabled( + "Await https://github.com/cloudfoundry/cloud_controller_ng/issues/856 for this test to" + + " work") @Test public void listServicesFilterByServiceBrokerId() { - Mono - .zip(this.serviceBrokerId, this.spaceId) - .flatMapMany(function((serviceBrokerId, spaceId) -> requestListSpaceServices(this.cloudFoundryClient, spaceId, builder -> builder.serviceBrokerId(serviceBrokerId)))) - .map(response -> response.getEntity().getLabel()) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(this.serviceBrokerId, this.spaceId) + .flatMapMany( + function( + (serviceBrokerId, spaceId) -> + requestListSpaceServices( + this.cloudFoundryClient, + spaceId, + builder -> + builder.serviceBrokerId(serviceBrokerId)))) + .map(response -> response.getEntity().getLabel()) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1220,22 +1912,40 @@ public void listUserRoles() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .flatMapMany(function((spaceId, userId) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.spaces() - .listUserRoles(ListSpaceUserRolesRequest.builder() - .page(page) - .spaceId(spaceId) - .build())) - .map(ResourceUtils::getEntity))) - .as(StepVerifier::create) - .consumeNextWith(entity -> { - assertThat(entity.getUsername()).isEqualTo(userName); - assertThat(entity.getSpaceRoles()).containsExactly("space_manager"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .flatMapMany( + function( + (spaceId, userId) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .spaces() + .listUserRoles( + ListSpaceUserRolesRequest + .builder() + .page(page) + .spaceId( + spaceId) + .build())) + .map(ResourceUtils::getEntity))) + .as(StepVerifier::create) + .consumeNextWith( + entity -> { + assertThat(entity.getUsername()).isEqualTo(userName); + assertThat(entity.getSpaceRoles()).containsExactly("space_manager"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1244,17 +1954,34 @@ public void removeAuditor() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceAuditor(this.cloudFoundryClient, spaceId, userId))) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .removeAuditor(RemoveSpaceAuditorRequest.builder() - .spaceId(spaceId) - .auditorId(userId) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceAuditors(this.cloudFoundryClient, spaceId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceAuditor( + this.cloudFoundryClient, spaceId, userId))) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .removeAuditor( + RemoveSpaceAuditorRequest.builder() + .spaceId(spaceId) + .auditorId(userId) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceAuditors(this.cloudFoundryClient, spaceId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1263,17 +1990,35 @@ public void removeAuditorByUsername() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceAuditor(this.cloudFoundryClient, spaceId, userId))) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .removeAuditorByUsername(RemoveSpaceAuditorByUsernameRequest.builder() - .spaceId(spaceId) - .username(userName) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceAuditors(this.cloudFoundryClient, spaceId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceAuditor( + this.cloudFoundryClient, spaceId, userId))) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .removeAuditorByUsername( + RemoveSpaceAuditorByUsernameRequest + .builder() + .spaceId(spaceId) + .username(userName) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceAuditors(this.cloudFoundryClient, spaceId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1282,17 +2027,35 @@ public void removeDeveloper() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, userId, spaceId))) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .removeDeveloper(RemoveSpaceDeveloperRequest.builder() - .spaceId(spaceId) - .developerId(userId) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceDevelopers(this.cloudFoundryClient, spaceId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, userId, spaceId))) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .removeDeveloper( + RemoveSpaceDeveloperRequest.builder() + .spaceId(spaceId) + .developerId(userId) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceDevelopers( + this.cloudFoundryClient, spaceId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1301,17 +2064,36 @@ public void removeDeveloperByUsername() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceDeveloper(this.cloudFoundryClient, userId, spaceId))) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .removeDeveloperByUsername(RemoveSpaceDeveloperByUsernameRequest.builder() - .spaceId(spaceId) - .username(userName) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceDevelopers(this.cloudFoundryClient, spaceId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceDeveloper( + this.cloudFoundryClient, userId, spaceId))) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .removeDeveloperByUsername( + RemoveSpaceDeveloperByUsernameRequest + .builder() + .spaceId(spaceId) + .username(userName) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceDevelopers( + this.cloudFoundryClient, spaceId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1320,17 +2102,34 @@ public void removeManager() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .removeManager(RemoveSpaceManagerRequest.builder() - .spaceId(spaceId) - .managerId(userId) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceManagers(this.cloudFoundryClient, spaceId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .removeManager( + RemoveSpaceManagerRequest.builder() + .spaceId(spaceId) + .managerId(userId) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceManagers(this.cloudFoundryClient, spaceId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1339,17 +2138,35 @@ public void removeManagerByUsername() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .removeManagerByUsername(RemoveSpaceManagerByUsernameRequest.builder() - .spaceId(spaceId) - .username(userName) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceManagers(this.cloudFoundryClient, spaceId))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .removeManagerByUsername( + RemoveSpaceManagerByUsernameRequest + .builder() + .spaceId(spaceId) + .username(userName) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceManagers(this.cloudFoundryClient, spaceId))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1358,22 +2175,36 @@ public void removeSecurityGroup() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createSecurityGroupId(this.cloudFoundryClient, securityGroupName), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .delayUntil(function((securityGroupId, spaceId) -> requestAssociateSpaceSecurityGroup(this.cloudFoundryClient, spaceId, securityGroupId))) - .flatMap(function((securityGroupId, spaceId) -> this.cloudFoundryClient.spaces() - .removeSecurityGroup(RemoveSpaceSecurityGroupRequest.builder() - .securityGroupId(securityGroupId) - .spaceId(spaceId) - .build()) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> requestListSecurityGroups(this.cloudFoundryClient, spaceId)) - .filter(response -> securityGroupName.equals(response.getEntity().getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createSecurityGroupId( + this.cloudFoundryClient, securityGroupName), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .delayUntil( + function( + (securityGroupId, spaceId) -> + requestAssociateSpaceSecurityGroup( + this.cloudFoundryClient, spaceId, securityGroupId))) + .flatMap( + function( + (securityGroupId, spaceId) -> + this.cloudFoundryClient + .spaces() + .removeSecurityGroup( + RemoveSpaceSecurityGroupRequest.builder() + .securityGroupId(securityGroupId) + .spaceId(spaceId) + .build()) + .thenReturn(spaceId))) + .flatMapMany(spaceId -> requestListSecurityGroups(this.cloudFoundryClient, spaceId)) + .filter(response -> securityGroupName.equals(response.getEntity().getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1382,21 +2213,31 @@ public void update() { String spaceName2 = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .delayUntil(spaceId -> this.cloudFoundryClient.spaces() - .update(UpdateSpaceRequest.builder() - .spaceId(spaceId) - .name(spaceName2) - .build())) - .flatMap(spaceId -> this.cloudFoundryClient.spaces() - .getSummary(GetSpaceSummaryRequest.builder() - .spaceId(spaceId) - .build())) - .map(GetSpaceSummaryResponse::getName) - .as(StepVerifier::create) - .expectNext(spaceName2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .delayUntil( + spaceId -> + this.cloudFoundryClient + .spaces() + .update( + UpdateSpaceRequest.builder() + .spaceId(spaceId) + .name(spaceName2) + .build())) + .flatMap( + spaceId -> + this.cloudFoundryClient + .spaces() + .getSummary( + GetSpaceSummaryRequest.builder() + .spaceId(spaceId) + .build())) + .map(GetSpaceSummaryResponse::getName) + .as(StepVerifier::create) + .expectNext(spaceName2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1405,127 +2246,210 @@ public void updateEmptyManagers() { String spaceName = this.nameFactory.getSpaceName(); String userName = this.nameFactory.getUserName(); - createSpaceIdAndUserId(this.cloudFoundryClient, this.uaaClient, organizationName, spaceName, userName) - .delayUntil(function((spaceId, userId) -> requestAssociateSpaceManager(this.cloudFoundryClient, spaceId, userId))) - .delayUntil(function((spaceId, userId) -> this.cloudFoundryClient.spaces() - .update(UpdateSpaceRequest.builder() - .spaceId(spaceId) - .managerIds(Collections.emptyList()) - .build()))) - .flatMapMany(function((spaceId, userId) -> requestListSpaceManagers(this.cloudFoundryClient, spaceId) - .map(response -> ResourceUtils.getEntity(response).getUsername()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + createSpaceIdAndUserId( + this.cloudFoundryClient, + this.uaaClient, + organizationName, + spaceName, + userName) + .delayUntil( + function( + (spaceId, userId) -> + requestAssociateSpaceManager( + this.cloudFoundryClient, spaceId, userId))) + .delayUntil( + function( + (spaceId, userId) -> + this.cloudFoundryClient + .spaces() + .update( + UpdateSpaceRequest.builder() + .spaceId(spaceId) + .managerIds(Collections.emptyList()) + .build()))) + .flatMapMany( + function( + (spaceId, userId) -> + requestListSpaceManagers(this.cloudFoundryClient, spaceId) + .map( + response -> + ResourceUtils.getEntity(response) + .getUsername()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName, String stackId) { + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String applicationName, + String stackId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName, stackId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organization) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organization) { return requestCreateOrganization(cloudFoundryClient, organization) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono> createOrganizationIdAndSpaceId(CloudFoundryClient cloudFoundryClient, String organizationName, String spaceName) { + private static Mono> createOrganizationIdAndSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationName, String spaceName) { return createOrganizationId(cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(cloudFoundryClient, organizationId, spaceName))); - } - - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String spaceId, String domainName, String host, String path) { + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + cloudFoundryClient, organizationId, spaceName))); + } + + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String domainName, + String host, + String path) { return getSharedDomainId(cloudFoundryClient, domainName) - .flatMap(domainId -> requestCreateRoute(cloudFoundryClient, spaceId, domainId, path, host)) - .map(ResourceUtils::getId); + .flatMap( + domainId -> + requestCreateRoute( + cloudFoundryClient, spaceId, domainId, path, host)) + .map(ResourceUtils::getId); } - private static Mono createSecurityGroupId(CloudFoundryClient cloudFoundryClient, String securityGroupName) { + private static Mono createSecurityGroupId( + CloudFoundryClient cloudFoundryClient, String securityGroupName) { return requestCreateSecurityGroup(cloudFoundryClient, securityGroupName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createServiceBindingId(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + private static Mono createServiceBindingId( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { return requestCreateServiceBinding(cloudFoundryClient, applicationId, serviceInstanceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createServiceInstanceId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceInstanceName, String serviceName, String spaceId) { + private static Mono createServiceInstanceId( + CloudFoundryClient cloudFoundryClient, + String serviceBrokerId, + String serviceInstanceName, + String serviceName, + String spaceId) { return getServicePlanId(cloudFoundryClient, serviceBrokerId, serviceName) - .flatMap(planId -> requestCreateServiceInstance(cloudFoundryClient, planId, serviceInstanceName, spaceId)) - .map(ResourceUtils::getId); + .flatMap( + planId -> + requestCreateServiceInstance( + cloudFoundryClient, planId, serviceInstanceName, spaceId)) + .map(ResourceUtils::getId); } - private static Mono createServiceKeyId(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String serviceKeyName) { + private static Mono createServiceKeyId( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceId, + String serviceKeyName) { return requestCreateServiceKey(cloudFoundryClient, serviceInstanceId, serviceKeyName) - .map(ResourceUtils::getId); - } - - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .organizationId(organizationId) - .name(spaceName) - .build()) - .map(ResourceUtils::getId); - } - - private static Mono> createSpaceIdAndUserId(CloudFoundryClient cloudFoundryClient, UaaClient uaaClient, String organizationName, String spaceName, String userName) { + .map(ResourceUtils::getId); + } + + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .organizationId(organizationId) + .name(spaceName) + .build()) + .map(ResourceUtils::getId); + } + + private static Mono> createSpaceIdAndUserId( + CloudFoundryClient cloudFoundryClient, + UaaClient uaaClient, + String organizationName, + String spaceName, + String userName) { return createOrganizationId(cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createSpaceId(cloudFoundryClient, organizationId, spaceName), - createUserId(cloudFoundryClient, uaaClient, organizationId, userName) - )); - } - - private static Mono createSpaceIdWithDomain(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName, String domainName) { - return cloudFoundryClient.sharedDomains() - .create(CreateSharedDomainRequest.builder() - .name(domainName) - .build()) - .map(ResourceUtils::getId) - .flatMap(domainId -> cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .domainId(domainId) - .organizationId(organizationId) - .name(spaceName) - .build())) - .map(ResourceUtils::getId); - } - - private static Mono createUserId(CloudFoundryClient cloudFoundryClient, UaaClient uaaClient, String organizationId, String username) { - return uaaClient.users() - .create(org.cloudfoundry.uaa.users.CreateUserRequest.builder() - .email(Email.builder() - .primary(true) - .value(String.format("%s@%s.com", username, username)) - .build()) - .name(Name.builder() - .givenName("Test") - .familyName("User") - .build()) - .password("test-password") - .userName(username) - .build()) - .map(CreateUserResponse::getId) - .flatMap(uaaId -> cloudFoundryClient.users() - .create(CreateUserRequest.builder() - .uaaId(uaaId) - .build()) - .map(ResourceUtils::getId)) - .flatMap(userId -> cloudFoundryClient.organizations() - .associateUser(AssociateOrganizationUserRequest.builder() - .organizationId(organizationId) - .userId(userId) - .build()) - .thenReturn(userId)); + .flatMap( + organizationId -> + Mono.zip( + createSpaceId( + cloudFoundryClient, organizationId, spaceName), + createUserId( + cloudFoundryClient, + uaaClient, + organizationId, + userName))); + } + + private static Mono createSpaceIdWithDomain( + CloudFoundryClient cloudFoundryClient, + String organizationId, + String spaceName, + String domainName) { + return cloudFoundryClient + .sharedDomains() + .create(CreateSharedDomainRequest.builder().name(domainName).build()) + .map(ResourceUtils::getId) + .flatMap( + domainId -> + cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .domainId(domainId) + .organizationId(organizationId) + .name(spaceName) + .build())) + .map(ResourceUtils::getId); + } + + private static Mono createUserId( + CloudFoundryClient cloudFoundryClient, + UaaClient uaaClient, + String organizationId, + String username) { + return uaaClient + .users() + .create( + org.cloudfoundry.uaa.users.CreateUserRequest.builder() + .email( + Email.builder() + .primary(true) + .value( + String.format( + "%s@%s.com", username, username)) + .build()) + .name(Name.builder().givenName("Test").familyName("User").build()) + .password("test-password") + .userName(username) + .build()) + .map(CreateUserResponse::getId) + .flatMap( + uaaId -> + cloudFoundryClient + .users() + .create(CreateUserRequest.builder().uaaId(uaaId).build()) + .map(ResourceUtils::getId)) + .flatMap( + userId -> + cloudFoundryClient + .organizations() + .associateUser( + AssociateOrganizationUserRequest.builder() + .organizationId(organizationId) + .userId(userId) + .build()) + .thenReturn(userId)); } private static String getPastTimestamp() { @@ -1533,282 +2457,410 @@ private static String getPastTimestamp() { return DateUtils.formatToIso8601(past); } - private static Mono getServicePlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + private static Mono getServicePlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { return requestListServices(cloudFoundryClient, serviceBrokerId, serviceName) - .single() - .map(ResourceUtils::getId) - .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) - .single() - .map(ResourceUtils::getId); + .single() + .map(ResourceUtils::getId) + .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) + .single() + .map(ResourceUtils::getId); } - private static Mono getSharedDomainId(CloudFoundryClient cloudFoundryClient, String domain) { + private static Mono getSharedDomainId( + CloudFoundryClient cloudFoundryClient, String domain) { return requestSharedDomain(cloudFoundryClient, domain) - .map(ResourceUtils::getId) - .single() - .switchIfEmpty(ExceptionUtils.illegalArgument("Domain %s not found", domain)); - } - - private static Mono requestAssociateSpaceAuditor(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.spaces() - .associateAuditor(AssociateSpaceAuditorRequest.builder() - .spaceId(spaceId) - .auditorId(userId) - .build()); - } - - private static Mono requestAssociateSpaceDeveloper(CloudFoundryClient cloudFoundryClient, String developerId, String spaceId) { - return cloudFoundryClient.spaces() - .associateDeveloper(AssociateSpaceDeveloperRequest.builder() - .developerId(developerId) - .spaceId(spaceId) - .build()); - } - - private static Mono requestAssociateSpaceManager(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.spaces() - .associateManager(AssociateSpaceManagerRequest.builder() - .spaceId(spaceId) - .managerId(userId) - .build()); - } - - private static Mono requestAssociateSpaceSecurityGroup(CloudFoundryClient cloudFoundryClient, String spaceId, String securityGroupId) { - return cloudFoundryClient.spaces() - .associateSecurityGroup(AssociateSpaceSecurityGroupRequest.builder() - .securityGroupId(securityGroupId) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .diego(true) - .name(applicationName) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName, String stackId) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .diego(true) - .name(applicationName) - .spaceId(spaceId) - .stackId(stackId) - .build()); - } - - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organization) { - return cloudFoundryClient.organizations() - .create(CreateOrganizationRequest.builder() - .name(organization) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String spaceId, String domainId, String path, String host) { - return cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .spaceId(spaceId) - .domainId(domainId) - .host(host) - .path(path) - .build()); - } - - private static Mono requestCreateSecurityGroup(CloudFoundryClient cloudFoundryClient, String securityGroupName) { - return cloudFoundryClient.securityGroups() - .create(CreateSecurityGroupRequest.builder() - .name(securityGroupName) - .build()); - } - - private static Mono requestCreateServiceBinding(CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { - return cloudFoundryClient.serviceBindingsV2() - .create(CreateServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(serviceInstanceId) - .build()); - } - - private static Mono requestCreateServiceInstance(CloudFoundryClient cloudFoundryClient, String planId, String serviceInstanceName, String spaceId) { - return cloudFoundryClient.serviceInstances() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .parameter("test-key", "test-value") - .servicePlanId(planId) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreateServiceKey(CloudFoundryClient cloudFoundryClient, String serviceInstanceId, String serviceKeyName) { - return cloudFoundryClient.serviceKeys() - .create(CreateServiceKeyRequest.builder() - .name(serviceKeyName) - .serviceInstanceId(serviceInstanceId) - .build()); - } - - private static Flux requestListSecurityGroups(CloudFoundryClient cloudFoundryClient, String spaceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listSecurityGroups(ListSpaceSecurityGroupsRequest.builder() - .page(page) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListServiceInstances(CloudFoundryClient cloudFoundryClient, String spaceId) { + .map(ResourceUtils::getId) + .single() + .switchIfEmpty(ExceptionUtils.illegalArgument("Domain %s not found", domain)); + } + + private static Mono requestAssociateSpaceAuditor( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .spaces() + .associateAuditor( + AssociateSpaceAuditorRequest.builder() + .spaceId(spaceId) + .auditorId(userId) + .build()); + } + + private static Mono requestAssociateSpaceDeveloper( + CloudFoundryClient cloudFoundryClient, String developerId, String spaceId) { + return cloudFoundryClient + .spaces() + .associateDeveloper( + AssociateSpaceDeveloperRequest.builder() + .developerId(developerId) + .spaceId(spaceId) + .build()); + } + + private static Mono requestAssociateSpaceManager( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .spaces() + .associateManager( + AssociateSpaceManagerRequest.builder() + .spaceId(spaceId) + .managerId(userId) + .build()); + } + + private static Mono requestAssociateSpaceSecurityGroup( + CloudFoundryClient cloudFoundryClient, String spaceId, String securityGroupId) { + return cloudFoundryClient + .spaces() + .associateSecurityGroup( + AssociateSpaceSecurityGroupRequest.builder() + .securityGroupId(securityGroupId) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .diego(true) + .name(applicationName) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String applicationName, + String stackId) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .diego(true) + .name(applicationName) + .spaceId(spaceId) + .stackId(stackId) + .build()); + } + + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organization) { + return cloudFoundryClient + .organizations() + .create(CreateOrganizationRequest.builder().name(organization).build()); + } + + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, + String spaceId, + String domainId, + String path, + String host) { + return cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .spaceId(spaceId) + .domainId(domainId) + .host(host) + .path(path) + .build()); + } + + private static Mono requestCreateSecurityGroup( + CloudFoundryClient cloudFoundryClient, String securityGroupName) { + return cloudFoundryClient + .securityGroups() + .create(CreateSecurityGroupRequest.builder().name(securityGroupName).build()); + } + + private static Mono requestCreateServiceBinding( + CloudFoundryClient cloudFoundryClient, String applicationId, String serviceInstanceId) { + return cloudFoundryClient + .serviceBindingsV2() + .create( + CreateServiceBindingRequest.builder() + .applicationId(applicationId) + .serviceInstanceId(serviceInstanceId) + .build()); + } + + private static Mono requestCreateServiceInstance( + CloudFoundryClient cloudFoundryClient, + String planId, + String serviceInstanceName, + String spaceId) { + return cloudFoundryClient + .serviceInstances() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .parameter("test-key", "test-value") + .servicePlanId(planId) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreateServiceKey( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceId, + String serviceKeyName) { + return cloudFoundryClient + .serviceKeys() + .create( + CreateServiceKeyRequest.builder() + .name(serviceKeyName) + .serviceInstanceId(serviceInstanceId) + .build()); + } + + private static Flux requestListSecurityGroups( + CloudFoundryClient cloudFoundryClient, String spaceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listSecurityGroups( + ListSpaceSecurityGroupsRequest.builder() + .page(page) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListServiceInstances( + CloudFoundryClient cloudFoundryClient, String spaceId) { return requestListServiceInstances(cloudFoundryClient, spaceId, UnaryOperator.identity()); } - private static Flux requestListServiceInstances(CloudFoundryClient cloudFoundryClient, String spaceId, - UnaryOperator transformer) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listServiceInstances(transformer.apply(ListSpaceServiceInstancesRequest.builder()) - .page(page) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.servicePlans() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceId(serviceId) - .build())); - } - - private static Flux requestListServices(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.services() - .list(ListServicesRequest.builder() - .label(serviceName) - .page(page) - .serviceBrokerId(serviceBrokerId) - .build())); - } - - private static Flux requestListSpaceApplications(CloudFoundryClient cloudFoundryClient, String spaceId) { + private static Flux requestListServiceInstances( + CloudFoundryClient cloudFoundryClient, + String spaceId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listServiceInstances( + transformer + .apply(ListSpaceServiceInstancesRequest.builder()) + .page(page) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .servicePlans() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceId(serviceId) + .build())); + } + + private static Flux requestListServices( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .services() + .list( + ListServicesRequest.builder() + .label(serviceName) + .page(page) + .serviceBrokerId(serviceBrokerId) + .build())); + } + + private static Flux requestListSpaceApplications( + CloudFoundryClient cloudFoundryClient, String spaceId) { return requestListSpaceApplications(cloudFoundryClient, spaceId, UnaryOperator.identity()); } - private static Flux requestListSpaceApplications(CloudFoundryClient cloudFoundryClient, String spaceId, UnaryOperator transformer) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listApplications(transformer.apply(ListSpaceApplicationsRequest.builder()) - .page(page) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListSpaceAuditors(CloudFoundryClient cloudFoundryClient, String spaceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listAuditors(ListSpaceAuditorsRequest.builder() - .page(page) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListSpaceDevelopers(CloudFoundryClient cloudFoundryClient, String spaceId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listDevelopers(ListSpaceDevelopersRequest.builder() - .page(page) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListSpaceDomains(CloudFoundryClient cloudFoundryClient, String spaceId) { + private static Flux requestListSpaceApplications( + CloudFoundryClient cloudFoundryClient, + String spaceId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listApplications( + transformer + .apply(ListSpaceApplicationsRequest.builder()) + .page(page) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListSpaceAuditors( + CloudFoundryClient cloudFoundryClient, String spaceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listAuditors( + ListSpaceAuditorsRequest.builder() + .page(page) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListSpaceDevelopers( + CloudFoundryClient cloudFoundryClient, String spaceId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listDevelopers( + ListSpaceDevelopersRequest.builder() + .page(page) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListSpaceDomains( + CloudFoundryClient cloudFoundryClient, String spaceId) { return requestListSpaceDomains(cloudFoundryClient, spaceId, UnaryOperator.identity()); } @SuppressWarnings("deprecation") - private static Flux requestListSpaceDomains(CloudFoundryClient cloudFoundryClient, String spaceId, UnaryOperator transformer) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listDomains(transformer.apply(ListSpaceDomainsRequest.builder()) - .page(page) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListSpaceEvents(CloudFoundryClient cloudFoundryClient, String spaceId) { + private static Flux requestListSpaceDomains( + CloudFoundryClient cloudFoundryClient, + String spaceId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listDomains( + transformer + .apply(ListSpaceDomainsRequest.builder()) + .page(page) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListSpaceEvents( + CloudFoundryClient cloudFoundryClient, String spaceId) { return requestListSpaceEvents(cloudFoundryClient, spaceId, UnaryOperator.identity()); } - private static Flux requestListSpaceEvents(CloudFoundryClient cloudFoundryClient, String spaceId, UnaryOperator transformer) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listEvents(transformer.apply(ListSpaceEventsRequest.builder()) - .page(page) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListSpaceManagers(CloudFoundryClient cloudFoundryClient, String spaceId) { + private static Flux requestListSpaceEvents( + CloudFoundryClient cloudFoundryClient, + String spaceId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listEvents( + transformer + .apply(ListSpaceEventsRequest.builder()) + .page(page) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListSpaceManagers( + CloudFoundryClient cloudFoundryClient, String spaceId) { return requestListSpaceManagers(cloudFoundryClient, spaceId, Function.identity()); } - private static Flux requestListSpaceManagers(CloudFoundryClient cloudFoundryClient, String spaceId, Function - transformer) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listManagers(transformer.apply(ListSpaceManagersRequest.builder()) - .page(page) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListSpaceRoutes(CloudFoundryClient cloudFoundryClient, String spaceId) { + private static Flux requestListSpaceManagers( + CloudFoundryClient cloudFoundryClient, + String spaceId, + Function + transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listManagers( + transformer + .apply(ListSpaceManagersRequest.builder()) + .page(page) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListSpaceRoutes( + CloudFoundryClient cloudFoundryClient, String spaceId) { return requestListSpaceRoutes(cloudFoundryClient, spaceId, UnaryOperator.identity()); } - private static Flux requestListSpaceRoutes(CloudFoundryClient cloudFoundryClient, String spaceId, UnaryOperator transformer) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listRoutes(transformer.apply(ListSpaceRoutesRequest.builder()) - .spaceId(spaceId) - .build())); - } - - private static Flux requestListSpaceServices(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListSpaceServices(cloudFoundryClient, organizationId, UnaryOperator.identity()); - } - - private static Flux requestListSpaceServices(CloudFoundryClient cloudFoundryClient, String spaceId, - UnaryOperator transformer) { - return PaginationUtils. - requestClientV2Resources(page -> cloudFoundryClient.spaces() - .listServices(transformer.apply(ListSpaceServicesRequest.builder()) - .spaceId(spaceId) - .page(page) - .build())); + private static Flux requestListSpaceRoutes( + CloudFoundryClient cloudFoundryClient, + String spaceId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listRoutes( + transformer + .apply(ListSpaceRoutesRequest.builder()) + .spaceId(spaceId) + .build())); + } + + private static Flux requestListSpaceServices( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListSpaceServices( + cloudFoundryClient, organizationId, UnaryOperator.identity()); + } + + private static Flux requestListSpaceServices( + CloudFoundryClient cloudFoundryClient, + String spaceId, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .listServices( + transformer + .apply(ListSpaceServicesRequest.builder()) + .spaceId(spaceId) + .page(page) + .build())); } private static Flux requestListSpaces(CloudFoundryClient cloudFoundryClient) { return requestListSpaces(cloudFoundryClient, UnaryOperator.identity()); } - private static Flux requestListSpaces(CloudFoundryClient cloudFoundryClient, UnaryOperator transformer) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.spaces() - .list(transformer.apply(ListSpacesRequest.builder()) - .page(page) - .build())); + private static Flux requestListSpaces( + CloudFoundryClient cloudFoundryClient, + UnaryOperator transformer) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .spaces() + .list( + transformer + .apply(ListSpacesRequest.builder()) + .page(page) + .build())); + } + + private static Flux requestSharedDomain( + CloudFoundryClient cloudFoundryClient, String domain) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .sharedDomains() + .list( + ListSharedDomainsRequest.builder() + .name(domain) + .page(page) + .build())); } - - private static Flux requestSharedDomain(CloudFoundryClient cloudFoundryClient, String domain) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.sharedDomains() - .list(ListSharedDomainsRequest.builder() - .name(domain) - .page(page) - .build())); - } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/StacksTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/StacksTest.java index cb86a6274e0..93b267adde5 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/StacksTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/StacksTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.stacks.CreateStackRequest; @@ -28,38 +31,35 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class StacksTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private String stackName; + @Autowired private String stackName; @Test public void create() { String stackName = this.nameFactory.getStackName(); - this.cloudFoundryClient.stacks() - .create(CreateStackRequest.builder() - .description("Test stack description") - .name(stackName) - .build()) - .thenMany(requestListStacks(this.cloudFoundryClient, stackName)) - .map(response -> ResourceUtils.getEntity(response).getDescription()) - .as(StepVerifier::create) - .expectNext("Test stack description") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .stacks() + .create( + CreateStackRequest.builder() + .description("Test stack description") + .name(stackName) + .build()) + .thenMany(requestListStacks(this.cloudFoundryClient, stackName)) + .map(response -> ResourceUtils.getEntity(response).getDescription()) + .as(StepVerifier::create) + .expectNext("Test stack description") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -67,15 +67,25 @@ public void delete() { String stackName = this.nameFactory.getStackName(); createStackId(this.cloudFoundryClient, stackName) - .delayUntil(stackId -> this.cloudFoundryClient.stacks() - .delete(DeleteStackRequest.builder() - .async(false) - .stackId(stackId) - .build())) - .flatMap(stackId -> requestGetStack(this.cloudFoundryClient, stackId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-StackNotFound\\([0-9]+\\): The stack could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .delayUntil( + stackId -> + this.cloudFoundryClient + .stacks() + .delete( + DeleteStackRequest.builder() + .async(false) + .stackId(stackId) + .build())) + .flatMap(stackId -> requestGetStack(this.cloudFoundryClient, stackId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-StackNotFound\\([0-9]+\\): The stack could not" + + " be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -83,96 +93,126 @@ public void deleteAsync() { String stackName = this.nameFactory.getStackName(); createStackId(this.cloudFoundryClient, stackName) - .delayUntil(stackId -> this.cloudFoundryClient.stacks() - .delete(DeleteStackRequest.builder() - .async(true) - .stackId(stackId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMap(stackId -> requestGetStack(this.cloudFoundryClient, stackId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-StackNotFound\\([0-9]+\\): The stack could not be found: .*")) - .verify(Duration.ofMinutes(5)); + .delayUntil( + stackId -> + this.cloudFoundryClient + .stacks() + .delete( + DeleteStackRequest.builder() + .async(true) + .stackId(stackId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMap(stackId -> requestGetStack(this.cloudFoundryClient, stackId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-StackNotFound\\([0-9]+\\): The stack could not" + + " be found: .*")) + .verify(Duration.ofMinutes(5)); } @Test public void get() { getStackId(this.cloudFoundryClient, this.stackName) - .flatMap(stackId -> this.cloudFoundryClient.stacks() - .get(GetStackRequest.builder() - .stackId(stackId) - .build())) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(this.stackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + stackId -> + this.cloudFoundryClient + .stacks() + .get(GetStackRequest.builder().stackId(stackId).build())) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(this.stackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { getStackId(this.cloudFoundryClient, this.stackName) - .flatMapMany(stackId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.stacks() - .list(ListStacksRequest.builder() - .page(page) - .build())) - .filter(resource -> ResourceUtils.getId(resource).equals(stackId))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(this.stackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + stackId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .stacks() + .list( + ListStacksRequest.builder() + .page(page) + .build())) + .filter( + resource -> + ResourceUtils.getId(resource) + .equals(stackId))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(this.stackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByName() { - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.stacks() - .list(ListStacksRequest.builder() - .name(this.stackName) - .page(page) - .build())) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(this.stackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .stacks() + .list( + ListStacksRequest.builder() + .name(this.stackName) + .page(page) + .build())) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(this.stackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createStackId(CloudFoundryClient cloudFoundryClient, String stackName) { - return requestCreateStack(cloudFoundryClient, stackName) - .map(ResourceUtils::getId); + private static Mono createStackId( + CloudFoundryClient cloudFoundryClient, String stackName) { + return requestCreateStack(cloudFoundryClient, stackName).map(ResourceUtils::getId); } - private static Mono getStackId(CloudFoundryClient cloudFoundryClient, String stackName) { - return requestListStacks(cloudFoundryClient, stackName) - .single() - .map(ResourceUtils::getId); + private static Mono getStackId( + CloudFoundryClient cloudFoundryClient, String stackName) { + return requestListStacks(cloudFoundryClient, stackName).single().map(ResourceUtils::getId); } - private static Mono requestCreateStack(CloudFoundryClient cloudFoundryClient, String stackName) { - return cloudFoundryClient.stacks() - .create(CreateStackRequest.builder() - .description("Test stack description") - .name(stackName) - .build()); + private static Mono requestCreateStack( + CloudFoundryClient cloudFoundryClient, String stackName) { + return cloudFoundryClient + .stacks() + .create( + CreateStackRequest.builder() + .description("Test stack description") + .name(stackName) + .build()); } - private static Mono requestGetStack(CloudFoundryClient cloudFoundryClient, String stackId) { - return cloudFoundryClient.stacks() - .get(GetStackRequest.builder() - .stackId(stackId) - .build()); + private static Mono requestGetStack( + CloudFoundryClient cloudFoundryClient, String stackId) { + return cloudFoundryClient.stacks().get(GetStackRequest.builder().stackId(stackId).build()); } - private static Flux requestListStacks(CloudFoundryClient cloudFoundryClient, String stackName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.stacks() - .list(ListStacksRequest.builder() - .name(stackName) - .page(page) - .build())); + private static Flux requestListStacks( + CloudFoundryClient cloudFoundryClient, String stackName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .stacks() + .list( + ListStacksRequest.builder() + .name(stackName) + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/UserProvidedServicesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/UserProvidedServicesTest.java index 3561e835c1e..555741d6340 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/UserProvidedServicesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/UserProvidedServicesTest.java @@ -16,6 +16,13 @@ package org.cloudfoundry.client.v2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.Collections; +import java.util.function.Consumer; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; @@ -41,6 +48,7 @@ import org.cloudfoundry.routing.RoutingClient; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -48,45 +56,37 @@ import reactor.util.function.Tuple3; import reactor.util.function.Tuples; -import java.time.Duration; -import java.util.Collections; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class UserProvidedServicesTest extends AbstractIntegrationTest { private static final String DEFAULT_ROUTER_GROUP = "default-tcp"; - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private RoutingClient routingClient; + @Autowired private RoutingClient routingClient; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void create() { String instanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> this.cloudFoundryClient.userProvidedServiceInstances() - .create(CreateUserProvidedServiceInstanceRequest.builder() - .name(instanceName) - .spaceId(spaceId) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(instanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .create( + CreateUserProvidedServiceInstanceRequest.builder() + .name(instanceName) + .spaceId(spaceId) + .build())) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(instanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -94,15 +94,24 @@ public void delete() { String instanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createUserProvidedServiceInstanceId(this.cloudFoundryClient, instanceName, spaceId)) - .flatMap(instanceId -> this.cloudFoundryClient.userProvidedServiceInstances() - .delete(DeleteUserProvidedServiceInstanceRequest.builder() - .userProvidedServiceInstanceId(instanceId) - .build())) - .thenMany(requestListUserProvidedServiceInstances(this.cloudFoundryClient, instanceName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, instanceName, spaceId)) + .flatMap( + instanceId -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .delete( + DeleteUserProvidedServiceInstanceRequest.builder() + .userProvidedServiceInstanceId(instanceId) + .build())) + .thenMany( + requestListUserProvidedServiceInstances( + this.cloudFoundryClient, instanceName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -110,16 +119,23 @@ public void get() { String instanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createUserProvidedServiceInstanceId(this.cloudFoundryClient, instanceName, spaceId)) - .flatMap(instanceId -> this.cloudFoundryClient.userProvidedServiceInstances() - .get(GetUserProvidedServiceInstanceRequest.builder() - .userProvidedServiceInstanceId(instanceId) - .build())) - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(instanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, instanceName, spaceId)) + .flatMap( + instanceId -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .get( + GetUserProvidedServiceInstanceRequest.builder() + .userProvidedServiceInstanceId(instanceId) + .build())) + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(instanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -127,19 +143,27 @@ public void list() { String instanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> requestCreateUserProvidedServiceInstance(this.cloudFoundryClient, instanceName, spaceId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.userProvidedServiceInstances() - .list(ListUserProvidedServiceInstancesRequest.builder() - .name(instanceName) - .page(page) - .build()))) - .single() - .map(response -> ResourceUtils.getEntity(response).getName()) - .as(StepVerifier::create) - .expectNext(instanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + requestCreateUserProvidedServiceInstance( + this.cloudFoundryClient, instanceName, spaceId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .list( + ListUserProvidedServiceInstancesRequest + .builder() + .name(instanceName) + .page(page) + .build()))) + .single() + .map(response -> ResourceUtils.getEntity(response).getName()) + .as(StepVerifier::create) + .expectNext(instanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -148,29 +172,59 @@ public void listRoutes() { String instanceName = this.nameFactory.getServiceInstanceName(); Mono.zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createUserProvidedServiceInstanceId(this.cloudFoundryClient, instanceName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, null, null, spaceId)) - )) - .flatMap(function((instanceId, routeId) -> requestAssociateRoute(this.cloudFoundryClient, instanceId, routeId) - .thenReturn(instanceId))) - .flatMapMany(instanceId -> Mono.zip( - Mono.just(instanceId), - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.userProvidedServiceInstances() - .listRoutes(ListUserProvidedServiceInstanceRoutesRequest.builder() - .page(page) - .userProvidedServiceInstanceId(instanceId) - .build())) - .map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId()) - .single())) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + instanceName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + null, + null, + spaceId)))) + .flatMap( + function( + (instanceId, routeId) -> + requestAssociateRoute( + this.cloudFoundryClient, + instanceId, + routeId) + .thenReturn(instanceId))) + .flatMapMany( + instanceId -> + Mono.zip( + Mono.just(instanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .listRoutes( + ListUserProvidedServiceInstanceRoutesRequest + .builder() + .page(page) + .userProvidedServiceInstanceId( + instanceId) + .build())) + .map( + resource -> + ResourceUtils.getEntity(resource) + .getServiceInstanceId()) + .single())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -179,31 +233,65 @@ public void listRoutesFilterByDomainId() { String instanceName = this.nameFactory.getServiceInstanceName(); Mono.zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - Mono.just(domainId), - createUserProvidedServiceInstanceId(this.cloudFoundryClient, instanceName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, null, null, spaceId)) - )) - .flatMap(function((domainId, instanceId, routeId) -> requestAssociateRoute(this.cloudFoundryClient, instanceId, routeId) - .thenReturn(Tuples.of(domainId, instanceId)))) - .flatMapMany(function((domainId, instanceId) -> Mono.zip( - Mono.just(instanceId), - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.userProvidedServiceInstances() - .listRoutes(ListUserProvidedServiceInstanceRoutesRequest.builder() - .domainId(domainId) - .page(page) - .userProvidedServiceInstanceId(instanceId) - .build())) - .map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId()) - .single()))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + Mono.just(domainId), + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + instanceName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + null, + null, + spaceId)))) + .flatMap( + function( + (domainId, instanceId, routeId) -> + requestAssociateRoute( + this.cloudFoundryClient, + instanceId, + routeId) + .thenReturn(Tuples.of(domainId, instanceId)))) + .flatMapMany( + function( + (domainId, instanceId) -> + Mono.zip( + Mono.just(instanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .listRoutes( + ListUserProvidedServiceInstanceRoutesRequest + .builder() + .domainId( + domainId) + .page( + page) + .userProvidedServiceInstanceId( + instanceId) + .build())) + .map( + resource -> + ResourceUtils.getEntity( + resource) + .getServiceInstanceId()) + .single()))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -213,30 +301,61 @@ public void listRoutesFilterByHost() { String instanceName = this.nameFactory.getServiceInstanceName(); Mono.zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createUserProvidedServiceInstanceId(this.cloudFoundryClient, instanceName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, hostName, null, spaceId)) - )) - .flatMap(function((instanceId, routeId) -> requestAssociateRoute(this.cloudFoundryClient, instanceId, routeId) - .thenReturn(instanceId))) - .flatMapMany(instanceId -> Mono.zip( - Mono.just(instanceId), - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.userProvidedServiceInstances() - .listRoutes(ListUserProvidedServiceInstanceRoutesRequest.builder() - .host(hostName) - .page(page) - .userProvidedServiceInstanceId(instanceId) - .build())) - .map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId()) - .single())) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + instanceName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + hostName, + null, + spaceId)))) + .flatMap( + function( + (instanceId, routeId) -> + requestAssociateRoute( + this.cloudFoundryClient, + instanceId, + routeId) + .thenReturn(instanceId))) + .flatMapMany( + instanceId -> + Mono.zip( + Mono.just(instanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .listRoutes( + ListUserProvidedServiceInstanceRoutesRequest + .builder() + .host( + hostName) + .page(page) + .userProvidedServiceInstanceId( + instanceId) + .build())) + .map( + resource -> + ResourceUtils.getEntity(resource) + .getServiceInstanceId()) + .single())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -246,30 +365,60 @@ public void listRoutesFilterByPath() { String path = this.nameFactory.getPath(); Mono.zip( - this.organizationId - .flatMap(organizationId -> createPrivateDomainId(this.cloudFoundryClient, domainName, organizationId)), - this.spaceId - ) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createUserProvidedServiceInstanceId(this.cloudFoundryClient, instanceName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, null, path, spaceId)) - )) - .flatMap(function((instanceId, routeId) -> requestAssociateRoute(this.cloudFoundryClient, instanceId, routeId) - .thenReturn(instanceId))) - .flatMapMany(instanceId -> Mono.zip( - Mono.just(instanceId), - PaginationUtils.requestClientV2Resources(page -> this.cloudFoundryClient.userProvidedServiceInstances() - .listRoutes(ListUserProvidedServiceInstanceRoutesRequest.builder() - .page(page) - .path(path) - .userProvidedServiceInstanceId(instanceId) - .build())) - .map(resource -> ResourceUtils.getEntity(resource).getServiceInstanceId()) - .single())) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.organizationId.flatMap( + organizationId -> + createPrivateDomainId( + this.cloudFoundryClient, + domainName, + organizationId)), + this.spaceId) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + instanceName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + null, + path, + spaceId)))) + .flatMap( + function( + (instanceId, routeId) -> + requestAssociateRoute( + this.cloudFoundryClient, + instanceId, + routeId) + .thenReturn(instanceId))) + .flatMapMany( + instanceId -> + Mono.zip( + Mono.just(instanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .listRoutes( + ListUserProvidedServiceInstanceRoutesRequest + .builder() + .page(page) + .path(path) + .userProvidedServiceInstanceId( + instanceId) + .build())) + .map( + resource -> + ResourceUtils.getEntity(resource) + .getServiceInstanceId()) + .single())) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -278,30 +427,48 @@ public void listServiceBindings() { String instanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - createUserProvidedServiceInstanceId(this.cloudFoundryClient, instanceName, spaceId) - )) - .delayUntil(function((applicationId, instanceId) -> this.cloudFoundryClient.serviceBindingsV2() - .create(CreateServiceBindingRequest.builder() - .applicationId(applicationId) - .serviceInstanceId(instanceId) - .build()))) - .flatMap(function((applicationId, instanceId) -> Mono.zip( - Mono.just(applicationId), - Mono.just(instanceId), - PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.userProvidedServiceInstances() - .listServiceBindings(ListUserProvidedServiceInstanceServiceBindingsRequest.builder() - .applicationId(applicationId) - .page(page) - .userProvidedServiceInstanceId(instanceId) - .build())) - .single()))) - .as(StepVerifier::create) - .consumeNextWith(serviceBindingEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId), + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, instanceName, spaceId))) + .delayUntil( + function( + (applicationId, instanceId) -> + this.cloudFoundryClient + .serviceBindingsV2() + .create( + CreateServiceBindingRequest.builder() + .applicationId(applicationId) + .serviceInstanceId(instanceId) + .build()))) + .flatMap( + function( + (applicationId, instanceId) -> + Mono.zip( + Mono.just(applicationId), + Mono.just(instanceId), + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .userProvidedServiceInstances() + .listServiceBindings( + ListUserProvidedServiceInstanceServiceBindingsRequest + .builder() + .applicationId( + applicationId) + .page( + page) + .userProvidedServiceInstanceId( + instanceId) + .build())) + .single()))) + .as(StepVerifier::create) + .consumeNextWith(serviceBindingEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -310,113 +477,171 @@ public void update() { String newInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createUserProvidedServiceInstanceId(this.cloudFoundryClient, instanceName, spaceId)) - .flatMap(instanceId -> Mono.zip( - Mono.just(instanceId), - this.cloudFoundryClient.userProvidedServiceInstances() - .update(UpdateUserProvidedServiceInstanceRequest.builder() - .userProvidedServiceInstanceId(instanceId) - .name(newInstanceName) - .credential("test-cred", "some value") - .build()) - .map(UpdateUserProvidedServiceInstanceResponse::getEntity) - )) - .flatMap(function((instanceId, entity1) -> Mono.zip( - Mono.just(entity1), - this.cloudFoundryClient.userProvidedServiceInstances() - .update(UpdateUserProvidedServiceInstanceRequest.builder() - .userProvidedServiceInstanceId(instanceId) - .credentials(Collections.emptyMap()) - .build()) - .map(UpdateUserProvidedServiceInstanceResponse::getEntity) - ))) - .as(StepVerifier::create) - .consumeNextWith(consumer((entity1, entity2) -> { - assertThat(entity1.getName()).isEqualTo(newInstanceName); - assertThat(entity1.getCredentials()).containsEntry("test-cred", "some value"); - assertThat(entity2.getCredentials()).isEmpty(); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, instanceName, spaceId)) + .flatMap( + instanceId -> + Mono.zip( + Mono.just(instanceId), + this.cloudFoundryClient + .userProvidedServiceInstances() + .update( + UpdateUserProvidedServiceInstanceRequest + .builder() + .userProvidedServiceInstanceId( + instanceId) + .name(newInstanceName) + .credential( + "test-cred", "some value") + .build()) + .map( + UpdateUserProvidedServiceInstanceResponse + ::getEntity))) + .flatMap( + function( + (instanceId, entity1) -> + Mono.zip( + Mono.just(entity1), + this.cloudFoundryClient + .userProvidedServiceInstances() + .update( + UpdateUserProvidedServiceInstanceRequest + .builder() + .userProvidedServiceInstanceId( + instanceId) + .credentials( + Collections + .emptyMap()) + .build()) + .map( + UpdateUserProvidedServiceInstanceResponse + ::getEntity)))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (entity1, entity2) -> { + assertThat(entity1.getName()).isEqualTo(newInstanceName); + assertThat(entity1.getCredentials()) + .containsEntry("test-cred", "some value"); + assertThat(entity2.getCredentials()).isEmpty(); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createPrivateDomainId(CloudFoundryClient cloudFoundryClient, String name, String organizationId) { + private static Mono createPrivateDomainId( + CloudFoundryClient cloudFoundryClient, String name, String organizationId) { return requestCreatePrivateDomain(cloudFoundryClient, name, organizationId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String path, String spaceId) { + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, + String domainId, + String hostName, + String path, + String spaceId) { return requestCreateRoute(cloudFoundryClient, domainId, hostName, path, spaceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createUserProvidedServiceInstanceId(CloudFoundryClient cloudFoundryClient, String instanceName, String spaceId) { + private static Mono createUserProvidedServiceInstanceId( + CloudFoundryClient cloudFoundryClient, String instanceName, String spaceId) { return requestCreateUserProvidedServiceInstance(cloudFoundryClient, instanceName, spaceId) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono requestAssociateRoute(CloudFoundryClient cloudFoundryClient, String instanceId, String routeId) { - return cloudFoundryClient.userProvidedServiceInstances() - .associateRoute(AssociateUserProvidedServiceInstanceRouteRequest.builder() - .routeId(routeId) - .userProvidedServiceInstanceId(instanceId) - .build()); + private static Mono requestAssociateRoute( + CloudFoundryClient cloudFoundryClient, String instanceId, String routeId) { + return cloudFoundryClient + .userProvidedServiceInstances() + .associateRoute( + AssociateUserProvidedServiceInstanceRouteRequest.builder() + .routeId(routeId) + .userProvidedServiceInstanceId(instanceId) + .build()); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Mono requestCreatePrivateDomain(CloudFoundryClient cloudFoundryClient, String name, String organizationId) { - return cloudFoundryClient.privateDomains() - .create(CreatePrivateDomainRequest.builder() - .name(name) - .owningOrganizationId(organizationId) - .build()); + private static Mono requestCreatePrivateDomain( + CloudFoundryClient cloudFoundryClient, String name, String organizationId) { + return cloudFoundryClient + .privateDomains() + .create( + CreatePrivateDomainRequest.builder() + .name(name) + .owningOrganizationId(organizationId) + .build()); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String hostName, String path, String spaceId) { - return cloudFoundryClient.routes() - .create(CreateRouteRequest.builder() - .domainId(domainId) - .host(hostName) - .path(path) - .spaceId(spaceId) - .build()); + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, + String domainId, + String hostName, + String path, + String spaceId) { + return cloudFoundryClient + .routes() + .create( + CreateRouteRequest.builder() + .domainId(domainId) + .host(hostName) + .path(path) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateUserProvidedServiceInstance(CloudFoundryClient cloudFoundryClient, String instanceName, String spaceId) { - return cloudFoundryClient.userProvidedServiceInstances() - .create(CreateUserProvidedServiceInstanceRequest.builder() - .name(instanceName) - .routeServiceUrl("https://test.url") - .spaceId(spaceId) - .build()); + private static Mono + requestCreateUserProvidedServiceInstance( + CloudFoundryClient cloudFoundryClient, String instanceName, String spaceId) { + return cloudFoundryClient + .userProvidedServiceInstances() + .create( + CreateUserProvidedServiceInstanceRequest.builder() + .name(instanceName) + .routeServiceUrl("https://test.url") + .spaceId(spaceId) + .build()); } - private static Flux requestListUserProvidedServiceInstances(CloudFoundryClient cloudFoundryClient, String instanceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.userProvidedServiceInstances() - .list(ListUserProvidedServiceInstancesRequest.builder() - .name(instanceName) - .page(page) - .build())); + private static Flux + requestListUserProvidedServiceInstances( + CloudFoundryClient cloudFoundryClient, String instanceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .userProvidedServiceInstances() + .list( + ListUserProvidedServiceInstancesRequest.builder() + .name(instanceName) + .page(page) + .build())); } - private static Consumer> serviceBindingEquality() { - return consumer((applicationId, instanceId, resource) -> { - assertThat(resource.getEntity().getApplicationId()).isEqualTo(applicationId); - assertThat(resource.getEntity().getServiceInstanceId()).isEqualTo(instanceId); - }); + private static Consumer> + serviceBindingEquality() { + return consumer( + (applicationId, instanceId, resource) -> { + assertThat(resource.getEntity().getApplicationId()).isEqualTo(applicationId); + assertThat(resource.getEntity().getServiceInstanceId()).isEqualTo(instanceId); + }); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v2/UsersTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v2/UsersTest.java index 7b97e0b6500..27f1232c3d0 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v2/UsersTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v2/UsersTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v2; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.applications.CreateApplicationRequest; @@ -70,25 +73,20 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuples; -import java.time.Duration; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class UsersTest extends AbstractIntegrationTest { private static final String STATUS_FILTER = "active"; - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; @Test public void associateAuditedOrganization() { @@ -96,21 +94,34 @@ public void associateAuditedOrganization() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganizationAuditor(this.cloudFoundryClient, organizationId, userId)) - .then(this.cloudFoundryClient.users() - .associateAuditedOrganization(AssociateUserAuditedOrganizationRequest.builder() - .auditedOrganizationId(organizationId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId) - .flatMapIterable(response -> response.getEntity().getAuditedOrganizations()) - .map(resource -> resource.getEntity().getName()) - .single()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganizationAuditor( + this.cloudFoundryClient, + organizationId, + userId)) + .then( + this.cloudFoundryClient + .users() + .associateAuditedOrganization( + AssociateUserAuditedOrganizationRequest + .builder() + .auditedOrganizationId( + organizationId) + .userId(userId) + .build()))) + .then( + requestSummaryUser(this.cloudFoundryClient, userId) + .flatMapIterable( + response -> response.getEntity().getAuditedOrganizations()) + .map(resource -> resource.getEntity().getName()) + .single()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -119,20 +130,28 @@ public void associateAuditedSpace() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(this.cloudFoundryClient.users() - .associateAuditedSpace(AssociateUserAuditedSpaceRequest.builder() - .auditedSpaceId(spaceId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getAuditedSpaces()) - .map(space -> space.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + this.cloudFoundryClient + .users() + .associateAuditedSpace( + AssociateUserAuditedSpaceRequest + .builder() + .auditedSpaceId(spaceId) + .userId(userId) + .build()))) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getAuditedSpaces()) + .map(space -> space.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -141,21 +160,36 @@ public void associateBillingManagedOrganization() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganizationBillingManager(this.cloudFoundryClient, organizationId, userId)) - .then(this.cloudFoundryClient.users() - .associateBillingManagedOrganization(AssociateUserBillingManagedOrganizationRequest.builder() - .billingManagedOrganizationId(organizationId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId) - .flatMapIterable(response -> response.getEntity().getBillingManagedOrganizations()) - .map(resource -> resource.getEntity().getName()) - .single()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganizationBillingManager( + this.cloudFoundryClient, + organizationId, + userId)) + .then( + this.cloudFoundryClient + .users() + .associateBillingManagedOrganization( + AssociateUserBillingManagedOrganizationRequest + .builder() + .billingManagedOrganizationId( + organizationId) + .userId(userId) + .build()))) + .then( + requestSummaryUser(this.cloudFoundryClient, userId) + .flatMapIterable( + response -> + response.getEntity() + .getBillingManagedOrganizations()) + .map(resource -> resource.getEntity().getName()) + .single()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -164,21 +198,34 @@ public void associateManagedOrganization() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganizationManager(this.cloudFoundryClient, organizationId, userId)) - .then(this.cloudFoundryClient.users() - .associateManagedOrganization(AssociateUserManagedOrganizationRequest.builder() - .managedOrganizationId(organizationId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId) - .flatMapIterable(response -> response.getEntity().getManagedOrganizations()) - .map(resource -> resource.getEntity().getName()) - .single()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganizationManager( + this.cloudFoundryClient, + organizationId, + userId)) + .then( + this.cloudFoundryClient + .users() + .associateManagedOrganization( + AssociateUserManagedOrganizationRequest + .builder() + .managedOrganizationId( + organizationId) + .userId(userId) + .build()))) + .then( + requestSummaryUser(this.cloudFoundryClient, userId) + .flatMapIterable( + response -> response.getEntity().getManagedOrganizations()) + .map(resource -> resource.getEntity().getName()) + .single()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -187,20 +234,28 @@ public void associateManagedSpace() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(this.cloudFoundryClient.users() - .associateManagedSpace(AssociateUserManagedSpaceRequest.builder() - .managedSpaceId(spaceId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getManagedSpaces()) - .map(space -> space.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + this.cloudFoundryClient + .users() + .associateManagedSpace( + AssociateUserManagedSpaceRequest + .builder() + .managedSpaceId(spaceId) + .userId(userId) + .build()))) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getManagedSpaces()) + .map(space -> space.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -209,20 +264,29 @@ public void associateOrganization() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(this.cloudFoundryClient.users() - .associateOrganization(AssociateUserOrganizationRequest.builder() - .organizationId(organizationId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId) - .flatMapIterable(response -> response.getEntity().getOrganizations()) - .map(resource -> resource.getEntity().getName()) - .single()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + this.cloudFoundryClient + .users() + .associateOrganization( + AssociateUserOrganizationRequest + .builder() + .organizationId( + organizationId) + .userId(userId) + .build()))) + .then( + requestSummaryUser(this.cloudFoundryClient, userId) + .flatMapIterable( + response -> response.getEntity().getOrganizations()) + .map(resource -> resource.getEntity().getName()) + .single()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -231,20 +295,27 @@ public void associateSpace() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(this.cloudFoundryClient.users() - .associateSpace(AssociateUserSpaceRequest.builder() - .spaceId(spaceId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getSpaces()) - .map(space -> space.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + this.cloudFoundryClient + .users() + .associateSpace( + AssociateUserSpaceRequest.builder() + .spaceId(spaceId) + .userId(userId) + .build()))) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getSpaces()) + .map(space -> space.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -253,18 +324,24 @@ public void create() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> this.cloudFoundryClient.users() - .create(CreateUserRequest.builder() - .defaultSpaceId(spaceId) - .uaaId(userId) - .build())) - .thenMany(requestListUsers(this.cloudFoundryClient)) - .filter(resource -> userId.equals(resource.getMetadata().getId())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + this.cloudFoundryClient + .users() + .create( + CreateUserRequest.builder() + .defaultSpaceId(spaceId) + .uaaId(userId) + .build())) + .thenMany(requestListUsers(this.cloudFoundryClient)) + .filter(resource -> userId.equals(resource.getMetadata().getId())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -272,17 +349,25 @@ public void deleteAsync() { String userId = this.nameFactory.getUserId(); requestCreateUser(this.cloudFoundryClient, userId) - .then(this.cloudFoundryClient.users() - .delete(DeleteUserRequest.builder() - .async(true) - .userId(userId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .thenMany(requestListUsers(this.cloudFoundryClient)) - .filter(resource -> userId.equals(resource.getMetadata().getId())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryClient + .users() + .delete( + DeleteUserRequest.builder() + .async(true) + .userId(userId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .thenMany(requestListUsers(this.cloudFoundryClient)) + .filter(resource -> userId.equals(resource.getMetadata().getId())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -290,17 +375,20 @@ public void deleteNoAsync() { String userId = this.nameFactory.getUserId(); requestCreateUser(this.cloudFoundryClient, userId) - .then(this.cloudFoundryClient.users() - .delete(DeleteUserRequest.builder() - .async(false) - .userId(userId) - .build())) - .thenMany(requestListUsers(this.cloudFoundryClient)) - .filter(resource -> userId.equals(resource.getMetadata().getId())) - .map(ResourceUtils::getId) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryClient + .users() + .delete( + DeleteUserRequest.builder() + .async(false) + .userId(userId) + .build())) + .thenMany(requestListUsers(this.cloudFoundryClient)) + .filter(resource -> userId.equals(resource.getMetadata().getId())) + .map(ResourceUtils::getId) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -309,17 +397,29 @@ public void get() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(this.cloudFoundryClient.users() - .get(GetUserRequest.builder() - .userId(userId) - .build()) - .map(response -> Tuples.of(spaceId, response.getEntity().getDefaultSpaceId())))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + this.cloudFoundryClient + .users() + .get( + GetUserRequest.builder() + .userId(userId) + .build()) + .map( + response -> + Tuples.of( + spaceId, + response.getEntity() + .getDefaultSpaceId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -327,17 +427,20 @@ public void list() { String userId = this.nameFactory.getUserId(); requestCreateUser(this.cloudFoundryClient, userId) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .list(ListUsersRequest.builder() - .page(page) - .build()))) - .filter(resource -> userId.equals(resource.getMetadata().getId())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); - + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .list( + ListUsersRequest.builder() + .page(page) + .build()))) + .filter(resource -> userId.equals(resource.getMetadata().getId())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -346,19 +449,27 @@ public void listAuditedOrganizations() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedOrganizations(ListUserAuditedOrganizationsRequest.builder() - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + associateAuditorOrganization( + this.cloudFoundryClient, organizationId, userId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedOrganizations( + ListUserAuditedOrganizationsRequest + .builder() + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -367,20 +478,28 @@ public void listAuditedOrganizationsFilterByAuditorId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedOrganizations(ListUserAuditedOrganizationsRequest.builder() - .auditorId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + associateAuditorOrganization( + this.cloudFoundryClient, organizationId, userId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedOrganizations( + ListUserAuditedOrganizationsRequest + .builder() + .auditorId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -389,22 +508,31 @@ public void listAuditedOrganizationsFilterByBillingManagerId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> Mono.zip( - associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId), - associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedOrganizations(ListUserAuditedOrganizationsRequest.builder() - .billingManagerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + Mono.zip( + associateBillingManagerOrganization( + this.cloudFoundryClient, organizationId, userId), + associateAuditorOrganization( + this.cloudFoundryClient, organizationId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedOrganizations( + ListUserAuditedOrganizationsRequest + .builder() + .billingManagerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -413,22 +541,31 @@ public void listAuditedOrganizationsFilterByManagerId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> Mono.zip( - associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId), - associateManagerOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedOrganizations(ListUserAuditedOrganizationsRequest.builder() - .managerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + Mono.zip( + associateAuditorOrganization( + this.cloudFoundryClient, organizationId, userId), + associateManagerOrganization( + this.cloudFoundryClient, organizationId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedOrganizations( + ListUserAuditedOrganizationsRequest + .builder() + .managerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -437,20 +574,31 @@ public void listAuditedOrganizationsFilterByName() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedOrganizations(ListUserAuditedOrganizationsRequest.builder() - .name(organizationName) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + associateAuditorOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedOrganizations( + ListUserAuditedOrganizationsRequest + .builder() + .name(organizationName) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -460,24 +608,42 @@ public void listAuditedOrganizationsFilterBySpaceId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName))) - .flatMap(function((organizationId, spaceId) -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedOrganizations(ListUserAuditedOrganizationsRequest.builder() - .page(page) - .spaceId(spaceId) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + associateAuditorOrganization( + this.cloudFoundryClient, + organizationId, + userId)) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedOrganizations( + ListUserAuditedOrganizationsRequest + .builder() + .page(page) + .spaceId(spaceId) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -486,20 +652,31 @@ public void listAuditedOrganizationsFilterByStatus() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedOrganizations(ListUserAuditedOrganizationsRequest.builder() - .page(page) - .status(STATUS_FILTER) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + associateAuditorOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedOrganizations( + ListUserAuditedOrganizationsRequest + .builder() + .page(page) + .status(STATUS_FILTER) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -508,19 +685,29 @@ public void listAuditedSpaces() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateAuditedSpace(this.cloudFoundryClient, spaceId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedSpaces(ListUserAuditedSpacesRequest.builder() - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateAuditedSpace( + this.cloudFoundryClient, spaceId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedSpaces( + ListUserAuditedSpacesRequest.builder() + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -530,23 +717,39 @@ public void listAuditedSpacesFilterByApplicationId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> Mono.zip( - getApplicationId(this.cloudFoundryClient, applicationName, spaceId), - requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateAuditedSpace(this.cloudFoundryClient, spaceId, userId))) - ) - .flatMapMany(function((applicationId, ignore) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedSpaces(ListUserAuditedSpacesRequest.builder() - .applicationId(applicationId) - .page(page) - .userId(userId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + Mono.zip( + getApplicationId( + this.cloudFoundryClient, applicationName, spaceId), + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateAuditedSpace( + this.cloudFoundryClient, + spaceId, + userId)))) + .flatMapMany( + function( + (applicationId, ignore) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedSpaces( + ListUserAuditedSpacesRequest + .builder() + .applicationId( + applicationId) + .page(page) + .userId(userId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -555,23 +758,37 @@ public void listAuditedSpacesFilterByDeveloperId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(Mono.zip( - requestAssociateSpace(this.cloudFoundryClient, spaceId, userId), - requestAssociateAuditedSpace(this.cloudFoundryClient, spaceId, userId)) - )) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedSpaces(ListUserAuditedSpacesRequest.builder() - .developerId(userId) - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + Mono.zip( + requestAssociateSpace( + this.cloudFoundryClient, + spaceId, + userId), + requestAssociateAuditedSpace( + this.cloudFoundryClient, + spaceId, + userId)))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedSpaces( + ListUserAuditedSpacesRequest.builder() + .developerId(userId) + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -580,20 +797,30 @@ public void listAuditedSpacesFilterByName() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateAuditedSpace(this.cloudFoundryClient, spaceId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedSpaces(ListUserAuditedSpacesRequest.builder() - .name(spaceName) - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateAuditedSpace( + this.cloudFoundryClient, spaceId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedSpaces( + ListUserAuditedSpacesRequest.builder() + .name(spaceName) + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -602,24 +829,42 @@ public void listAuditedSpacesFilterByOrganizationId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((organizationId, spaceId) -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateAuditedSpace(this.cloudFoundryClient, spaceId, userId)) - .thenReturn(organizationId))) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listAuditedSpaces(ListUserAuditedSpacesRequest.builder() - .organizationId(organizationId) - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateAuditedSpace( + this.cloudFoundryClient, + spaceId, + userId)) + .thenReturn(organizationId))) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listAuditedSpaces( + ListUserAuditedSpacesRequest + .builder() + .organizationId( + organizationId) + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -628,19 +873,27 @@ public void listBillingManagedOrganizations() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listBillingManagedOrganizations(ListUserBillingManagedOrganizationsRequest.builder() - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + associateBillingManagerOrganization( + this.cloudFoundryClient, organizationId, userId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listBillingManagedOrganizations( + ListUserBillingManagedOrganizationsRequest + .builder() + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -649,22 +902,31 @@ public void listBillingManagedOrganizationsFilterByAuditorId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> Mono.zip( - associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId), - associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listBillingManagedOrganizations(ListUserBillingManagedOrganizationsRequest.builder() - .auditorId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + Mono.zip( + associateBillingManagerOrganization( + this.cloudFoundryClient, organizationId, userId), + associateAuditorOrganization( + this.cloudFoundryClient, organizationId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listBillingManagedOrganizations( + ListUserBillingManagedOrganizationsRequest + .builder() + .auditorId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -673,20 +935,28 @@ public void listBillingManagedOrganizationsFilterByBillingManagerId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listBillingManagedOrganizations(ListUserBillingManagedOrganizationsRequest.builder() - .billingManagerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + associateBillingManagerOrganization( + this.cloudFoundryClient, organizationId, userId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listBillingManagedOrganizations( + ListUserBillingManagedOrganizationsRequest + .builder() + .billingManagerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -695,22 +965,31 @@ public void listBillingManagedOrganizationsFilterByManagerId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> Mono.zip( - associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId), - associateManagerOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listBillingManagedOrganizations(ListUserBillingManagedOrganizationsRequest.builder() - .managerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + Mono.zip( + associateBillingManagerOrganization( + this.cloudFoundryClient, organizationId, userId), + associateManagerOrganization( + this.cloudFoundryClient, organizationId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listBillingManagedOrganizations( + ListUserBillingManagedOrganizationsRequest + .builder() + .managerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -719,20 +998,31 @@ public void listBillingManagedOrganizationsFilterByName() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listBillingManagedOrganizations(ListUserBillingManagedOrganizationsRequest.builder() - .name(organizationName) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + associateBillingManagerOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listBillingManagedOrganizations( + ListUserBillingManagedOrganizationsRequest + .builder() + .name(organizationName) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -742,24 +1032,42 @@ public void listBillingManagedOrganizationsFilterBySpaceId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName))) - .flatMap(function((organizationId, spaceId) -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listBillingManagedOrganizations(ListUserBillingManagedOrganizationsRequest.builder() - .page(page) - .spaceId(spaceId) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + associateBillingManagerOrganization( + this.cloudFoundryClient, + organizationId, + userId)) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listBillingManagedOrganizations( + ListUserBillingManagedOrganizationsRequest + .builder() + .page(page) + .spaceId(spaceId) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -768,20 +1076,31 @@ public void listBillingManagedOrganizationsFilterByStatus() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listBillingManagedOrganizations(ListUserBillingManagedOrganizationsRequest.builder() - .page(page) - .status(STATUS_FILTER) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + associateBillingManagerOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listBillingManagedOrganizations( + ListUserBillingManagedOrganizationsRequest + .builder() + .page(page) + .status(STATUS_FILTER) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -789,19 +1108,28 @@ public void listFilterByOrganization() { String userId = this.nameFactory.getUserId(); this.organizationId - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .delayUntil(organizationId -> requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId)) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .list(ListUsersRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .filter(resource -> userId.equals(resource.getMetadata().getId())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .delayUntil( + organizationId -> + requestAssociateOrganization( + this.cloudFoundryClient, organizationId, userId)) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .list( + ListUsersRequest.builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .filter(resource -> userId.equals(resource.getMetadata().getId())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -810,20 +1138,28 @@ public void listFilterBySpace() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .delayUntil(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId)) - .delayUntil(spaceId -> requestAssociateSpace(this.cloudFoundryClient, spaceId, userId)) - .flatMapMany(spaceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .list(ListUsersRequest.builder() - .page(page) - .spaceId(spaceId) - .build()))) - .filter(resource -> userId.equals(resource.getMetadata().getId())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .delayUntil(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId)) + .delayUntil( + spaceId -> requestAssociateSpace(this.cloudFoundryClient, spaceId, userId)) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .list( + ListUsersRequest.builder() + .page(page) + .spaceId(spaceId) + .build()))) + .filter(resource -> userId.equals(resource.getMetadata().getId())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -832,19 +1168,27 @@ public void listManagedOrganizations() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> associateManagerOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedOrganizations(ListUserManagedOrganizationsRequest.builder() - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + associateManagerOrganization( + this.cloudFoundryClient, organizationId, userId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedOrganizations( + ListUserManagedOrganizationsRequest + .builder() + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -853,22 +1197,31 @@ public void listManagedOrganizationsFilterByAuditorId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> Mono.zip( - associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId), - associateManagerOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedOrganizations(ListUserManagedOrganizationsRequest.builder() - .auditorId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + Mono.zip( + associateAuditorOrganization( + this.cloudFoundryClient, organizationId, userId), + associateManagerOrganization( + this.cloudFoundryClient, organizationId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedOrganizations( + ListUserManagedOrganizationsRequest + .builder() + .auditorId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -877,22 +1230,31 @@ public void listManagedOrganizationsFilterByBillingManagerId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> Mono.zip( - associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId), - associateManagerOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedOrganizations(ListUserManagedOrganizationsRequest.builder() - .billingManagerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + Mono.zip( + associateBillingManagerOrganization( + this.cloudFoundryClient, organizationId, userId), + associateManagerOrganization( + this.cloudFoundryClient, organizationId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedOrganizations( + ListUserManagedOrganizationsRequest + .builder() + .billingManagerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -901,20 +1263,28 @@ public void listManagedOrganizationsFilterByManagerId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> associateManagerOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedOrganizations(ListUserManagedOrganizationsRequest.builder() - .managerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + associateManagerOrganization( + this.cloudFoundryClient, organizationId, userId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedOrganizations( + ListUserManagedOrganizationsRequest + .builder() + .managerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -923,20 +1293,31 @@ public void listManagedOrganizationsFilterByName() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(associateManagerOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedOrganizations(ListUserManagedOrganizationsRequest.builder() - .name(organizationName) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + associateManagerOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedOrganizations( + ListUserManagedOrganizationsRequest + .builder() + .name(organizationName) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -946,24 +1327,42 @@ public void listManagedOrganizationsFilterBySpaceId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName))) - .flatMap(function((organizationId, spaceId) -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(associateManagerOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedOrganizations(ListUserManagedOrganizationsRequest.builder() - .page(page) - .spaceId(spaceId) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + associateManagerOrganization( + this.cloudFoundryClient, + organizationId, + userId)) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedOrganizations( + ListUserManagedOrganizationsRequest + .builder() + .page(page) + .spaceId(spaceId) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -972,20 +1371,31 @@ public void listManagedOrganizationsFilterByStatus() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(associateManagerOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedOrganizations(ListUserManagedOrganizationsRequest.builder() - .page(page) - .status(STATUS_FILTER) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + associateManagerOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedOrganizations( + ListUserManagedOrganizationsRequest + .builder() + .page(page) + .status(STATUS_FILTER) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -994,19 +1404,29 @@ public void listManagedSpaces() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateManagedSpace(this.cloudFoundryClient, spaceId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedSpaces(ListUserManagedSpacesRequest.builder() - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateManagedSpace( + this.cloudFoundryClient, spaceId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedSpaces( + ListUserManagedSpacesRequest.builder() + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1016,23 +1436,39 @@ public void listManagedSpacesFilterByApplicationId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> Mono.zip( - getApplicationId(this.cloudFoundryClient, applicationName, spaceId), - requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateManagedSpace(this.cloudFoundryClient, spaceId, userId))) - ) - .flatMapMany(function((applicationId, ignore) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedSpaces(ListUserManagedSpacesRequest.builder() - .applicationId(applicationId) - .page(page) - .userId(userId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + Mono.zip( + getApplicationId( + this.cloudFoundryClient, applicationName, spaceId), + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateManagedSpace( + this.cloudFoundryClient, + spaceId, + userId)))) + .flatMapMany( + function( + (applicationId, ignore) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedSpaces( + ListUserManagedSpacesRequest + .builder() + .applicationId( + applicationId) + .page(page) + .userId(userId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1041,23 +1477,37 @@ public void listManagedSpacesFilterByDeveloperId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(Mono.zip( - requestAssociateSpace(this.cloudFoundryClient, spaceId, userId), - requestAssociateManagedSpace(this.cloudFoundryClient, spaceId, userId)) - )) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedSpaces(ListUserManagedSpacesRequest.builder() - .developerId(userId) - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + Mono.zip( + requestAssociateSpace( + this.cloudFoundryClient, + spaceId, + userId), + requestAssociateManagedSpace( + this.cloudFoundryClient, + spaceId, + userId)))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedSpaces( + ListUserManagedSpacesRequest.builder() + .developerId(userId) + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1066,20 +1516,30 @@ public void listManagedSpacesFilterByName() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateManagedSpace(this.cloudFoundryClient, spaceId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedSpaces(ListUserManagedSpacesRequest.builder() - .name(spaceName) - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateManagedSpace( + this.cloudFoundryClient, spaceId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedSpaces( + ListUserManagedSpacesRequest.builder() + .name(spaceName) + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1088,24 +1548,42 @@ public void listManagedSpacesFilterByOrganizationId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((organizationId, spaceId) -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateManagedSpace(this.cloudFoundryClient, spaceId, userId)) - .thenReturn(organizationId))) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listManagedSpaces(ListUserManagedSpacesRequest.builder() - .organizationId(organizationId) - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateManagedSpace( + this.cloudFoundryClient, + spaceId, + userId)) + .thenReturn(organizationId))) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listManagedSpaces( + ListUserManagedSpacesRequest + .builder() + .organizationId( + organizationId) + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1114,19 +1592,26 @@ public void listOrganizations() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) - .flatMap(organizationId -> requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listOrganizations(ListUserOrganizationsRequest.builder() - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId)) + .flatMap( + organizationId -> + requestAssociateOrganization( + this.cloudFoundryClient, organizationId, userId)) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listOrganizations( + ListUserOrganizationsRequest.builder() + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1135,22 +1620,35 @@ public void listOrganizationsFilterByAuditorId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(Mono.zip( - requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId), - associateAuditorOrganization(this.cloudFoundryClient, organizationId, userId)))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listOrganizations(ListUserOrganizationsRequest.builder() - .auditorId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + Mono.zip( + requestAssociateOrganization( + this.cloudFoundryClient, + organizationId, + userId), + associateAuditorOrganization( + this.cloudFoundryClient, + organizationId, + userId)))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listOrganizations( + ListUserOrganizationsRequest.builder() + .auditorId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1159,22 +1657,35 @@ public void listOrganizationsFilterByBillingManagerId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(Mono.zip( - requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId), - associateBillingManagerOrganization(this.cloudFoundryClient, organizationId, userId)))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listOrganizations(ListUserOrganizationsRequest.builder() - .billingManagerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + Mono.zip( + requestAssociateOrganization( + this.cloudFoundryClient, + organizationId, + userId), + associateBillingManagerOrganization( + this.cloudFoundryClient, + organizationId, + userId)))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listOrganizations( + ListUserOrganizationsRequest.builder() + .billingManagerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1183,22 +1694,35 @@ public void listOrganizationsFilterByManagerId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(Mono.zip( - requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId), - associateManagerOrganization(this.cloudFoundryClient, organizationId, userId)))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listOrganizations(ListUserOrganizationsRequest.builder() - .managerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + Mono.zip( + requestAssociateOrganization( + this.cloudFoundryClient, + organizationId, + userId), + associateManagerOrganization( + this.cloudFoundryClient, + organizationId, + userId)))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listOrganizations( + ListUserOrganizationsRequest.builder() + .managerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1207,20 +1731,30 @@ public void listOrganizationsFilterByName() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listOrganizations(ListUserOrganizationsRequest.builder() - .name(organizationName) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listOrganizations( + ListUserOrganizationsRequest.builder() + .name(organizationName) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1230,24 +1764,42 @@ public void listOrganizationsFilterBySpaceId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName))) - .flatMap(function((organizationId, spaceId) -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId)) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listOrganizations(ListUserOrganizationsRequest.builder() - .page(page) - .spaceId(spaceId) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateOrganization( + this.cloudFoundryClient, + organizationId, + userId)) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listOrganizations( + ListUserOrganizationsRequest + .builder() + .page(page) + .spaceId(spaceId) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1256,20 +1808,30 @@ public void listOrganizationsFilterByStatus() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listOrganizations(ListUserOrganizationsRequest.builder() - .page(page) - .status(STATUS_FILTER) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listOrganizations( + ListUserOrganizationsRequest.builder() + .page(page) + .status(STATUS_FILTER) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1278,19 +1840,29 @@ public void listSpaces() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateSpace(this.cloudFoundryClient, spaceId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listSpaces(ListUserSpacesRequest.builder() - .page(page) - .userId(userId) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateSpace( + this.cloudFoundryClient, spaceId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listSpaces( + ListUserSpacesRequest.builder() + .page(page) + .userId(userId) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1300,23 +1872,39 @@ public void listSpacesFilterByApplicationId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> Mono.zip( - getApplicationId(this.cloudFoundryClient, applicationName, spaceId), - requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateSpace(this.cloudFoundryClient, spaceId, userId))) - ) - .flatMapMany(function((applicationId, ignore) -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listSpaces(ListUserSpacesRequest.builder() - .applicationId(applicationId) - .page(page) - .userId(userId) - .build())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + Mono.zip( + getApplicationId( + this.cloudFoundryClient, applicationName, spaceId), + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateSpace( + this.cloudFoundryClient, + spaceId, + userId)))) + .flatMapMany( + function( + (applicationId, ignore) -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listSpaces( + ListUserSpacesRequest + .builder() + .applicationId( + applicationId) + .page(page) + .userId(userId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1325,21 +1913,31 @@ public void listSpacesFilterByDeveloperId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateSpace(this.cloudFoundryClient, spaceId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listSpaces(ListUserSpacesRequest.builder() - .developerId(userId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateSpace( + this.cloudFoundryClient, spaceId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listSpaces( + ListUserSpacesRequest.builder() + .developerId(userId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1348,21 +1946,31 @@ public void listSpacesFilterByName() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateSpace(this.cloudFoundryClient, spaceId, userId))) - .thenMany(PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listSpaces(ListUserSpacesRequest.builder() - .name(spaceName) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateSpace( + this.cloudFoundryClient, spaceId, userId))) + .thenMany( + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listSpaces( + ListUserSpacesRequest.builder() + .name(spaceName) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1371,25 +1979,42 @@ public void listSpacesFilterByOrganizationId() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((organizationId, spaceId) -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateSpace(this.cloudFoundryClient, spaceId, userId)) - .thenReturn(organizationId))) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV2Resources(page -> this.cloudFoundryClient.users() - .listSpaces(ListUserSpacesRequest.builder() - .organizationId(organizationId) - .page(page) - .userId(userId) - .build()))) - .map(resource -> resource.getEntity().getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateSpace( + this.cloudFoundryClient, + spaceId, + userId)) + .thenReturn(organizationId))) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV2Resources( + page -> + this.cloudFoundryClient + .users() + .listSpaces( + ListUserSpacesRequest.builder() + .organizationId( + organizationId) + .page(page) + .userId(userId) + .build()))) + .map(resource -> resource.getEntity().getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1397,19 +2022,33 @@ public void removeAuditedOrganization() { String userId = this.nameFactory.getUserId(); this.organizationId - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganizationAuditor(this.cloudFoundryClient, organizationId, userId)) - .then(requestAssociateAuditedOrganization(this.cloudFoundryClient, organizationId, userId))) - .flatMap(organizationId -> this.cloudFoundryClient.users() - .removeAuditedOrganization(RemoveUserAuditedOrganizationRequest.builder() - .auditedOrganizationId(organizationId) - .userId(userId) - .build())) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getAuditedOrganizations()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganizationAuditor( + this.cloudFoundryClient, + organizationId, + userId)) + .then( + requestAssociateAuditedOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .flatMap( + organizationId -> + this.cloudFoundryClient + .users() + .removeAuditedOrganization( + RemoveUserAuditedOrganizationRequest.builder() + .auditedOrganizationId(organizationId) + .userId(userId) + .build())) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getAuditedOrganizations()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1418,19 +2057,29 @@ public void removeAuditedSpace() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateAuditedSpace(this.cloudFoundryClient, spaceId, userId)) - .then(this.cloudFoundryClient.users() - .removeAuditedSpace(RemoveUserAuditedSpaceRequest.builder() - .auditedSpaceId(spaceId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getAuditedSpaces()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateAuditedSpace( + this.cloudFoundryClient, spaceId, userId)) + .then( + this.cloudFoundryClient + .users() + .removeAuditedSpace( + RemoveUserAuditedSpaceRequest + .builder() + .auditedSpaceId(spaceId) + .userId(userId) + .build()))) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getAuditedSpaces()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1438,19 +2087,35 @@ public void removeBillingManagedOrganization() { String userId = this.nameFactory.getUserId(); this.organizationId - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganizationBillingManager(this.cloudFoundryClient, organizationId, userId)) - .then(requestAssociateBillingManagedOrganization(this.cloudFoundryClient, organizationId, userId))) - .flatMap(organizationId -> this.cloudFoundryClient.users() - .removeBillingManagedOrganization(RemoveUserBillingManagedOrganizationRequest.builder() - .billingManagedOrganizationId(organizationId) - .userId(userId) - .build())) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getBillingManagedOrganizations()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganizationBillingManager( + this.cloudFoundryClient, + organizationId, + userId)) + .then( + requestAssociateBillingManagedOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .flatMap( + organizationId -> + this.cloudFoundryClient + .users() + .removeBillingManagedOrganization( + RemoveUserBillingManagedOrganizationRequest + .builder() + .billingManagedOrganizationId( + organizationId) + .userId(userId) + .build())) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getBillingManagedOrganizations()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1458,19 +2123,33 @@ public void removeManagedOrganization() { String userId = this.nameFactory.getUserId(); this.organizationId - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganizationManager(this.cloudFoundryClient, organizationId, userId)) - .then(requestAssociateManagedOrganization(this.cloudFoundryClient, organizationId, userId))) - .flatMap(organizationId -> this.cloudFoundryClient.users() - .removeManagedOrganization(RemoveUserManagedOrganizationRequest.builder() - .managedOrganizationId(organizationId) - .userId(userId) - .build())) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getManagedOrganizations()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganizationManager( + this.cloudFoundryClient, + organizationId, + userId)) + .then( + requestAssociateManagedOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .flatMap( + organizationId -> + this.cloudFoundryClient + .users() + .removeManagedOrganization( + RemoveUserManagedOrganizationRequest.builder() + .managedOrganizationId(organizationId) + .userId(userId) + .build())) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getManagedOrganizations()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1479,19 +2158,29 @@ public void removeManagedSpace() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateManagedSpace(this.cloudFoundryClient, spaceId, userId)) - .then(this.cloudFoundryClient.users() - .removeManagedSpace(RemoveUserManagedSpaceRequest.builder() - .managedSpaceId(spaceId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getManagedSpaces()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateManagedSpace( + this.cloudFoundryClient, spaceId, userId)) + .then( + this.cloudFoundryClient + .users() + .removeManagedSpace( + RemoveUserManagedSpaceRequest + .builder() + .managedSpaceId(spaceId) + .userId(userId) + .build()))) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getManagedSpaces()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1499,18 +2188,28 @@ public void removeOrganization() { String userId = this.nameFactory.getUserId(); this.organizationId - .delayUntil(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId))) - .flatMap(organizationId -> this.cloudFoundryClient.users() - .removeOrganization(RemoveUserOrganizationRequest.builder() - .organizationId(organizationId) - .userId(userId) - .build())) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getOrganizations()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .flatMap( + organizationId -> + this.cloudFoundryClient + .users() + .removeOrganization( + RemoveUserOrganizationRequest.builder() + .organizationId(organizationId) + .userId(userId) + .build())) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getOrganizations()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1519,19 +2218,28 @@ public void removeSpace() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> requestCreateUser(this.cloudFoundryClient, spaceId, userId) - .then(requestAssociateSpace(this.cloudFoundryClient, spaceId, userId)) - .then(this.cloudFoundryClient.users() - .removeSpace(RemoveUserSpaceRequest.builder() - .spaceId(spaceId) - .userId(userId) - .build()))) - .then(requestSummaryUser(this.cloudFoundryClient, userId)) - .flatMapIterable(response -> response.getEntity().getSpaces()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + requestCreateUser(this.cloudFoundryClient, spaceId, userId) + .then( + requestAssociateSpace( + this.cloudFoundryClient, spaceId, userId)) + .then( + this.cloudFoundryClient + .users() + .removeSpace( + RemoveUserSpaceRequest.builder() + .spaceId(spaceId) + .userId(userId) + .build()))) + .then(requestSummaryUser(this.cloudFoundryClient, userId)) + .flatMapIterable(response -> response.getEntity().getSpaces()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1540,17 +2248,23 @@ public void summary() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateUser(this.cloudFoundryClient, userId) - .then(requestAssociateOrganization(this.cloudFoundryClient, organizationId, userId))) - .then(this.cloudFoundryClient.users() - .summary(SummaryUserRequest.builder() - .userId(userId) - .build())) - .map(response -> ResourceUtils.getEntity(response).getOrganizations()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateUser(this.cloudFoundryClient, userId) + .then( + requestAssociateOrganization( + this.cloudFoundryClient, + organizationId, + userId))) + .then( + this.cloudFoundryClient + .users() + .summary(SummaryUserRequest.builder().userId(userId).build())) + .map(response -> ResourceUtils.getEntity(response).getOrganizations()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -1559,183 +2273,248 @@ public void update() { String userId = this.nameFactory.getUserId(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .delayUntil(spaceId -> requestCreateUser(this.cloudFoundryClient, userId)) - .delayUntil(spaceId -> this.cloudFoundryClient.users() - .update(UpdateUserRequest.builder() - .defaultSpaceId(spaceId) - .userId(userId) - .build())) - .flatMapMany(spaceId -> requestListUsers(this.cloudFoundryClient) - .filter(resource -> spaceId.equals(resource.getEntity().getDefaultSpaceId()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono associateAuditorOrganization(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .delayUntil(spaceId -> requestCreateUser(this.cloudFoundryClient, userId)) + .delayUntil( + spaceId -> + this.cloudFoundryClient + .users() + .update( + UpdateUserRequest.builder() + .defaultSpaceId(spaceId) + .userId(userId) + .build())) + .flatMapMany( + spaceId -> + requestListUsers(this.cloudFoundryClient) + .filter( + resource -> + spaceId.equals( + resource.getEntity() + .getDefaultSpaceId()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono associateAuditorOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { return requestAssociateOrganizationAuditor(cloudFoundryClient, organizationId, userId) - .then(requestAssociateAuditedOrganization(cloudFoundryClient, organizationId, userId)); + .then( + requestAssociateAuditedOrganization( + cloudFoundryClient, organizationId, userId)); } - private static Mono associateBillingManagerOrganization(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return requestAssociateOrganizationBillingManager(cloudFoundryClient, organizationId, userId) - .then(requestAssociateBillingManagedOrganization(cloudFoundryClient, organizationId, userId)); + private static Mono + associateBillingManagerOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return requestAssociateOrganizationBillingManager( + cloudFoundryClient, organizationId, userId) + .then( + requestAssociateBillingManagedOrganization( + cloudFoundryClient, organizationId, userId)); } - private static Mono associateManagerOrganization(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + private static Mono associateManagerOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { return requestAssociateOrganizationManager(cloudFoundryClient, organizationId, userId) - .then(requestAssociateManagedOrganization(cloudFoundryClient, organizationId, userId)); + .then( + requestAssociateManagedOrganization( + cloudFoundryClient, organizationId, userId)); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono getApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + private static Mono getApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); - } - - private static Mono requestAssociateAuditedOrganization(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.users() - .associateAuditedOrganization(AssociateUserAuditedOrganizationRequest.builder() - .auditedOrganizationId(organizationId) - .userId(userId) - .build()); - } - - private static Mono requestAssociateAuditedSpace(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.users() - .associateAuditedSpace(AssociateUserAuditedSpaceRequest.builder() - .auditedSpaceId(spaceId) - .userId(userId) - .build()); - } - - private static Mono requestAssociateBillingManagedOrganization(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.users() - .associateBillingManagedOrganization(AssociateUserBillingManagedOrganizationRequest.builder() - .billingManagedOrganizationId(organizationId) - .userId(userId) - .build()); - } - - private static Mono requestAssociateManagedOrganization(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.users() - .associateManagedOrganization(AssociateUserManagedOrganizationRequest.builder() - .managedOrganizationId(organizationId) - .userId(userId) - .build()); - } - - private static Mono requestAssociateManagedSpace(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.users() - .associateManagedSpace(AssociateUserManagedSpaceRequest.builder() - .managedSpaceId(spaceId) - .userId(userId) - .build()); - } - - private static Mono requestAssociateOrganization(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.users() - .associateOrganization(AssociateUserOrganizationRequest.builder() - .organizationId(organizationId) - .userId(userId) - .build()); - } - - private static Mono requestAssociateOrganizationAuditor(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateAuditor(AssociateOrganizationAuditorRequest.builder() - .auditorId(userId) - .organizationId(organizationId) - .build()); - } - - private static Mono requestAssociateOrganizationBillingManager(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateBillingManager(AssociateOrganizationBillingManagerRequest.builder() - .billingManagerId(userId) - .organizationId(organizationId) - .build()); - } - - private static Mono requestAssociateOrganizationManager(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.organizations() - .associateManager(AssociateOrganizationManagerRequest.builder() - .managerId(userId) - .organizationId(organizationId) - .build()); - } - - private static Mono requestAssociateSpace(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.users() - .associateSpace(AssociateUserSpaceRequest.builder() - .spaceId(spaceId) - .userId(userId) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .spaceId(spaceId) - .build()); - } - - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizations() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .status(STATUS_FILTER) - .build()); - } - - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .organizationId(organizationId) - .name(spaceName) - .build()); - } - - private static Mono requestCreateUser(CloudFoundryClient cloudFoundryClient, String userId) { - return cloudFoundryClient.users() - .create(CreateUserRequest.builder() - .uaaId(userId) - .build()); - } - - private static Mono requestCreateUser(CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { - return cloudFoundryClient.users() - .create(CreateUserRequest.builder() - .defaultSpaceId(spaceId) - .uaaId(userId) - .build()); + .map(ResourceUtils::getId); + } + + private static Mono + requestAssociateAuditedOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .users() + .associateAuditedOrganization( + AssociateUserAuditedOrganizationRequest.builder() + .auditedOrganizationId(organizationId) + .userId(userId) + .build()); + } + + private static Mono requestAssociateAuditedSpace( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .users() + .associateAuditedSpace( + AssociateUserAuditedSpaceRequest.builder() + .auditedSpaceId(spaceId) + .userId(userId) + .build()); + } + + private static Mono + requestAssociateBillingManagedOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .users() + .associateBillingManagedOrganization( + AssociateUserBillingManagedOrganizationRequest.builder() + .billingManagedOrganizationId(organizationId) + .userId(userId) + .build()); + } + + private static Mono + requestAssociateManagedOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .users() + .associateManagedOrganization( + AssociateUserManagedOrganizationRequest.builder() + .managedOrganizationId(organizationId) + .userId(userId) + .build()); + } + + private static Mono requestAssociateManagedSpace( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .users() + .associateManagedSpace( + AssociateUserManagedSpaceRequest.builder() + .managedSpaceId(spaceId) + .userId(userId) + .build()); + } + + private static Mono requestAssociateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .users() + .associateOrganization( + AssociateUserOrganizationRequest.builder() + .organizationId(organizationId) + .userId(userId) + .build()); + } + + private static Mono requestAssociateOrganizationAuditor( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateAuditor( + AssociateOrganizationAuditorRequest.builder() + .auditorId(userId) + .organizationId(organizationId) + .build()); + } + + private static Mono + requestAssociateOrganizationBillingManager( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateBillingManager( + AssociateOrganizationBillingManagerRequest.builder() + .billingManagerId(userId) + .organizationId(organizationId) + .build()); + } + + private static Mono requestAssociateOrganizationManager( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .organizations() + .associateManager( + AssociateOrganizationManagerRequest.builder() + .managerId(userId) + .organizationId(organizationId) + .build()); + } + + private static Mono requestAssociateSpace( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .users() + .associateSpace( + AssociateUserSpaceRequest.builder() + .spaceId(spaceId) + .userId(userId) + .build()); + } + + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .spaceId(spaceId) + .build()); + } + + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizations() + .create( + CreateOrganizationRequest.builder() + .name(organizationName) + .status(STATUS_FILTER) + .build()); + } + + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .organizationId(organizationId) + .name(spaceName) + .build()); + } + + private static Mono requestCreateUser( + CloudFoundryClient cloudFoundryClient, String userId) { + return cloudFoundryClient.users().create(CreateUserRequest.builder().uaaId(userId).build()); + } + + private static Mono requestCreateUser( + CloudFoundryClient cloudFoundryClient, String spaceId, String userId) { + return cloudFoundryClient + .users() + .create(CreateUserRequest.builder().defaultSpaceId(spaceId).uaaId(userId).build()); } private static Flux requestListUsers(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.users() - .list(ListUsersRequest.builder() - .page(page) - .build())); + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .users() + .list(ListUsersRequest.builder().page(page).build())); } - private static Mono requestSummaryUser(CloudFoundryClient cloudFoundryClient, String userId) { - return cloudFoundryClient.users() - .summary(SummaryUserRequest.builder() - .userId(userId) - .build()); + private static Mono requestSummaryUser( + CloudFoundryClient cloudFoundryClient, String userId) { + return cloudFoundryClient + .users() + .summary(SummaryUserRequest.builder().userId(userId).build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/AdminTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/AdminTest.java index 868ec17ca12..6775ef1df5b 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/AdminTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/AdminTest.java @@ -16,32 +16,33 @@ package org.cloudfoundry.client.v3; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v3.admin.ClearBuildpackCacheRequest; import org.cloudfoundry.util.JobUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.test.StepVerifier; -import java.time.Duration; - public final class AdminTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_10) @Test public void clearBuildpackCache() { - this.cloudFoundryClient.adminV3() - .clearBuildpackCache(ClearBuildpackCacheRequest.builder() - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .adminV3() + .clearBuildpackCache(ClearBuildpackCacheRequest.builder().build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ApplicationsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ApplicationsTest.java index 40d937c0c70..3354b24ed7a 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ApplicationsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ApplicationsTest.java @@ -16,6 +16,17 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.client.v3.applications.ApplicationState.STARTED; +import static org.cloudfoundry.client.v3.applications.ApplicationState.STOPPED; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.io.IOException; +import java.time.Duration; +import java.time.Instant; +import java.util.Collections; +import java.util.Map; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -88,62 +99,65 @@ import org.cloudfoundry.util.DelayUtils; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; import reactor.util.function.Tuples; -import java.io.IOException; -import java.time.Duration; -import java.time.Instant; -import java.util.Collections; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.client.v3.applications.ApplicationState.STARTED; -import static org.cloudfoundry.client.v3.applications.ApplicationState.STOPPED; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class ApplicationsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void create() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> this.cloudFoundryClient.applicationsV3() - .create(CreateApplicationRequest.builder() - .environmentVariable("test-create-env-key", "test-create-env-value") - .metadata(Metadata.builder() - .label("test-create-label-key", "test-create-label-value") - .build()) - .name(applicationName) - .relationships(ApplicationRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()) - .map(CreateApplicationResponse::getId)) - .flatMap(applicationId -> requestGetApplication(this.cloudFoundryClient, applicationId)) - .map(response -> response.getMetadata().getLabels().get(("test-create-label-key"))) - .as(StepVerifier::create) - .expectNext("test-create-label-value") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + this.cloudFoundryClient + .applicationsV3() + .create( + CreateApplicationRequest.builder() + .environmentVariable( + "test-create-env-key", + "test-create-env-value") + .metadata( + Metadata.builder() + .label( + "test-create-label-key", + "test-create-label-value") + .build()) + .name(applicationName) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + spaceId) + .build()) + .build()) + .build()) + .build()) + .map(CreateApplicationResponse::getId)) + .flatMap( + applicationId -> + requestGetApplication(this.cloudFoundryClient, applicationId)) + .map(response -> response.getMetadata().getLabels().get(("test-create-label-key"))) + .as(StepVerifier::create) + .expectNext("test-create-label-value") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -151,16 +165,35 @@ public void delete() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .delayUntil(applicationId -> this.cloudFoundryClient.applicationsV3() - .delete(DeleteApplicationRequest.builder() - .applicationId(applicationId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMap(applicationId -> requestGetApplications(this.cloudFoundryClient, applicationId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV3Exception.class).hasMessageMatching("CF-ResourceNotFound\\([0-9]+\\): App not found.*")) - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .delayUntil( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .delete( + DeleteApplicationRequest.builder() + .applicationId(applicationId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMap( + applicationId -> + requestGetApplications(this.cloudFoundryClient, applicationId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV3Exception.class) + .hasMessageMatching( + "CF-ResourceNotFound\\([0-9]+\\): App not found.*")) + .verify(Duration.ofMinutes(5)); } @Test @@ -168,16 +201,23 @@ public void get() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV3() - .get(GetApplicationRequest.builder() - .applicationId(applicationId) - .build())) - .map(GetApplicationResponse::getName) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .get( + GetApplicationRequest.builder() + .applicationId(applicationId) + .build())) + .map(GetApplicationResponse::getName) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -185,24 +225,42 @@ public void getDropletAssociation() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - uploadPackageAndCreateDropletId(this.cloudFoundryClient, applicationId) - )) - .delayUntil(function((applicationId, dropletId) -> requestSetDroplet(this.cloudFoundryClient, applicationId, dropletId))) - .flatMap(function((applicationId, dropletId) -> Mono.zip( - Mono.just(dropletId), - this.cloudFoundryClient.applicationsV3() - .getCurrentDropletRelationship(GetApplicationCurrentDropletRelationshipRequest.builder() - .applicationId(applicationId) - .build()) - .map(response -> response.getData().getId())) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + uploadPackageAndCreateDropletId( + this.cloudFoundryClient, applicationId))) + .delayUntil( + function( + (applicationId, dropletId) -> + requestSetDroplet( + this.cloudFoundryClient, applicationId, dropletId))) + .flatMap( + function( + (applicationId, dropletId) -> + Mono.zip( + Mono.just(dropletId), + this.cloudFoundryClient + .applicationsV3() + .getCurrentDropletRelationship( + GetApplicationCurrentDropletRelationshipRequest + .builder() + .applicationId( + applicationId) + .build()) + .map( + response -> + response.getData() + .getId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("unchecked") @@ -211,16 +269,28 @@ public void getEnvironment() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV3() - .getEnvironment(GetApplicationEnvironmentRequest.builder() - .applicationId(applicationId) - .build())) - .map(env -> ((Map) env.getApplicationEnvironmentVariables().get("VCAP_APPLICATION")).get("name")) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .getEnvironment( + GetApplicationEnvironmentRequest.builder() + .applicationId(applicationId) + .build())) + .map( + env -> + ((Map) + env.getApplicationEnvironmentVariables() + .get("VCAP_APPLICATION")) + .get("name")) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -228,20 +298,28 @@ public void getFeature() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV3() - .getFeature(GetApplicationFeatureRequest.builder() - .applicationId(applicationId) - .featureName("ssh") - .build())) - .as(StepVerifier::create) - .expectNext(GetApplicationFeatureResponse.builder() - .description("Enable SSHing into the app.") - .enabled(true) - .name("ssh") - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .getFeature( + GetApplicationFeatureRequest.builder() + .applicationId(applicationId) + .featureName("ssh") + .build())) + .as(StepVerifier::create) + .expectNext( + GetApplicationFeatureResponse.builder() + .description("Enable SSHing into the app.") + .enabled(true) + .name("ssh") + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_10) @@ -250,18 +328,26 @@ public void getPermissions() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV3() - .getPermissions(GetApplicationPermissionsRequest.builder() - .applicationId(applicationId) - .build())) - .as(StepVerifier::create) - .expectNext(GetApplicationPermissionsResponse.builder() - .readBasicData(true) - .readSensitiveData(true) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .getPermissions( + GetApplicationPermissionsRequest.builder() + .applicationId(applicationId) + .build())) + .as(StepVerifier::create) + .expectNext( + GetApplicationPermissionsResponse.builder() + .readBasicData(true) + .readSensitiveData(true) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -269,18 +355,23 @@ public void getSshEnabled() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV3() - .getSshEnabled(GetApplicationSshEnabledRequest.builder() - .applicationId(applicationId) - .build())) - .as(StepVerifier::create) - .expectNext(GetApplicationSshEnabledResponse.builder() - .enabled(true) - .reason("") - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .getSshEnabled( + GetApplicationSshEnabledRequest.builder() + .applicationId(applicationId) + .build())) + .as(StepVerifier::create) + .expectNext( + GetApplicationSshEnabledResponse.builder().enabled(true).reason("").build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -288,18 +379,27 @@ public void list() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMapMany(applicationId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .list(ListApplicationsRequest.builder() - .page(page) - .build())) - .filter(resource -> applicationId.equals(resource.getId()))) - .map(ApplicationResource::getName) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMapMany( + applicationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .list( + ListApplicationsRequest + .builder() + .page(page) + .build())) + .filter(resource -> applicationId.equals(resource.getId()))) + .map(ApplicationResource::getName) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -309,28 +409,57 @@ public void listApplicationRoutes() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, "listApplicationRoutes", spaceId) - ))) - .flatMapMany(function((applicationId, routeId) -> requestReplaceDestinations(this.cloudFoundryClient, applicationId, routeId) - .thenReturn(applicationId))) - .flatMap(applicationId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .page(page) - .build()))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listApplicationRoutes-key", "test-listApplicationRoutes-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + "listApplicationRoutes", + spaceId)))) + .flatMapMany( + function( + (applicationId, routeId) -> + requestReplaceDestinations( + this.cloudFoundryClient, + applicationId, + routeId) + .thenReturn(applicationId))) + .flatMap( + applicationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .page(page) + .build()))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listApplicationRoutes-key", + "test-listApplicationRoutes-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -340,29 +469,57 @@ public void listApplicationRoutesByDomain() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, "listApplicationRoutesByDomain", spaceId) - ))) - .delayUntil(function((applicationId, domainId, routeId) -> requestReplaceDestinations(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, domainId, ignore) -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .domainId(domainId) - .page(page) - .build())))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listApplicationRoutesByDomain-key", "test-listApplicationRoutesByDomain-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + "listApplicationRoutesByDomain", + spaceId)))) + .delayUntil( + function( + (applicationId, domainId, routeId) -> + requestReplaceDestinations( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, domainId, ignore) -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .domainId(domainId) + .page(page) + .build())))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listApplicationRoutesByDomain-key", + "test-listApplicationRoutesByDomain-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -373,30 +530,66 @@ public void listApplicationRoutesByHost() { String hostName = this.nameFactory.getHostName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, hostName, "listApplicationRoutesByHost", null, null, spaceId) - ))) - .flatMap(function((applicationId, routeId) -> requestReplaceDestinations(this.cloudFoundryClient, applicationId, routeId) - .thenReturn(applicationId))) - .flatMapMany(applicationId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .host(hostName) - .page(page) - .build()))) - .filter(route -> route.getMetadata().getLabels().containsKey("test-listApplicationRoutesByHost-key")) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listApplicationRoutesByHost-key", "test-listApplicationRoutesByHost-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + hostName, + "listApplicationRoutesByHost", + null, + null, + spaceId)))) + .flatMap( + function( + (applicationId, routeId) -> + requestReplaceDestinations( + this.cloudFoundryClient, + applicationId, + routeId) + .thenReturn(applicationId))) + .flatMapMany( + applicationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .host(hostName) + .page(page) + .build()))) + .filter( + route -> + route.getMetadata() + .getLabels() + .containsKey("test-listApplicationRoutesByHost-key")) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listApplicationRoutesByHost-key", + "test-listApplicationRoutesByHost-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -407,29 +600,62 @@ public void listApplicationRoutesByLabelSelector() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, "listApplicationRoutesByLabelSelector", spaceId) - ))) - .flatMapMany(function((applicationId, routeId) -> requestReplaceDestinations(this.cloudFoundryClient, applicationId, routeId) - .thenReturn(applicationId))) - .flatMap(applicationId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .labelSelector("test-listApplicationRoutesByLabelSelector-key=test-listApplicationRoutesByLabelSelector-value") - .page(page) - .build()))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listApplicationRoutesByLabelSelector-key", "test-listApplicationRoutesByLabelSelector-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + "listApplicationRoutesByLabelSelector", + spaceId)))) + .flatMapMany( + function( + (applicationId, routeId) -> + requestReplaceDestinations( + this.cloudFoundryClient, + applicationId, + routeId) + .thenReturn(applicationId))) + .flatMap( + applicationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .labelSelector( + "test-listApplicationRoutesByLabelSelector-key=test-listApplicationRoutesByLabelSelector-value") + .page(page) + .build()))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listApplicationRoutesByLabelSelector-key", + "test-listApplicationRoutesByLabelSelector-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -441,31 +667,62 @@ public void listApplicationRoutesByOrganizationId() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - - .flatMap(function((domainId, organizationId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - Mono.just(organizationId), - createRouteId(this.cloudFoundryClient, domainId, "listApplicationRoutesByOrganizationId", spaceId) - ))) - .delayUntil(function((applicationId, organizationId, routeId) -> requestReplaceDestinations(this.cloudFoundryClient, applicationId, routeId))) - .flatMapMany(function((applicationId, organizationId, ignore) -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .organizationId(organizationId) - .page(page) - .build())))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listApplicationRoutesByOrganizationId-key", "test-listApplicationRoutesByOrganizationId-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (domainId, organizationId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + Mono.just(organizationId), + createRouteId( + this.cloudFoundryClient, + domainId, + "listApplicationRoutesByOrganizationId", + spaceId)))) + .delayUntil( + function( + (applicationId, organizationId, routeId) -> + requestReplaceDestinations( + this.cloudFoundryClient, applicationId, routeId))) + .flatMapMany( + function( + (applicationId, organizationId, ignore) -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .organizationId( + organizationId) + .page(page) + .build())))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listApplicationRoutesByOrganizationId-key", + "test-listApplicationRoutesByOrganizationId-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -476,31 +733,66 @@ public void listApplicationRoutesByPath() { String path = this.nameFactory.getPath(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, null, "listApplicationRoutesByPath", path, null, spaceId) - ))) - .flatMapMany(function((applicationId, routeId) -> requestReplaceDestinations(this.cloudFoundryClient, applicationId, routeId) - .thenReturn(applicationId))) - .flatMap(applicationId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .path(path) - .page(page) - .build()))) - .filter(route -> route.getMetadata().getLabels().containsKey("test-listApplicationRoutesByPath-key")) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listApplicationRoutesByPath-key", "test-listApplicationRoutesByPath-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + null, + "listApplicationRoutesByPath", + path, + null, + spaceId)))) + .flatMapMany( + function( + (applicationId, routeId) -> + requestReplaceDestinations( + this.cloudFoundryClient, + applicationId, + routeId) + .thenReturn(applicationId))) + .flatMap( + applicationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .path(path) + .page(page) + .build()))) + .filter( + route -> + route.getMetadata() + .getLabels() + .containsKey("test-listApplicationRoutesByPath-key")) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listApplicationRoutesByPath-key", + "test-listApplicationRoutesByPath-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -511,32 +803,68 @@ public void listApplicationRoutesBySpaceId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, "listApplicationRoutesBySpaceId", spaceId), - Mono.just(spaceId) - ))) - .delayUntil(function((applicationId, routeId, spaceId) -> requestReplaceDestinations(this.cloudFoundryClient, applicationId, routeId) - .thenReturn(applicationId))) - .flatMapMany(function((applicationId, ignore, spaceId) -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .listRoutes(ListApplicationRoutesRequest.builder() - .applicationId(applicationId) - .page(page) - .spaceId(spaceId) - .build())))) - .filter(route -> route.getMetadata().getLabels().containsKey("test-listApplicationRoutesBySpaceId-key")) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listApplicationRoutesBySpaceId-key", "test-listApplicationRoutesBySpaceId-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + "listApplicationRoutesBySpaceId", + spaceId), + Mono.just(spaceId)))) + .delayUntil( + function( + (applicationId, routeId, spaceId) -> + requestReplaceDestinations( + this.cloudFoundryClient, + applicationId, + routeId) + .thenReturn(applicationId))) + .flatMapMany( + function( + (applicationId, ignore, spaceId) -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .listRoutes( + ListApplicationRoutesRequest + .builder() + .applicationId( + applicationId) + .page(page) + .spaceId(spaceId) + .build())))) + .filter( + route -> + route.getMetadata() + .getLabels() + .containsKey("test-listApplicationRoutesBySpaceId-key")) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listApplicationRoutesBySpaceId-key", + "test-listApplicationRoutesBySpaceId-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -544,19 +872,32 @@ public void listFeatures() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMapMany(applicationId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .listFeatures(ListApplicationFeaturesRequest.builder() - .applicationId(applicationId) - .page(page) - .build()))) - .filter(resource -> "revisions".equals(resource.getName())) - .map(ApplicationFeatureResource::getDescription) - .as(StepVerifier::create) - .consumeNextWith(description -> assertThat(description).startsWith("Enable versioning of an application")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMapMany( + applicationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .listFeatures( + ListApplicationFeaturesRequest + .builder() + .applicationId( + applicationId) + .page(page) + .build()))) + .filter(resource -> "revisions".equals(resource.getName())) + .map(ApplicationFeatureResource::getDescription) + .as(StepVerifier::create) + .consumeNextWith( + description -> + assertThat(description) + .startsWith("Enable versioning of an application")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -565,23 +906,33 @@ public void listFilterBySpaceId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> Mono.zip( - Mono.just(spaceId), - createApplicationId(this.cloudFoundryClient, applicationName, spaceId) - )) - .flatMapMany(function((spaceId, applicationId) -> PaginationUtils - .requestClientV3Resources(page -> - this.cloudFoundryClient.applicationsV3() - .list(ListApplicationsRequest.builder() - .spaceId(spaceId) - .page(page) - .build())))) - .map(ApplicationResource::getName) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + Mono.zip( + Mono.just(spaceId), + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId))) + .flatMapMany( + function( + (spaceId, applicationId) -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .applicationsV3() + .list( + ListApplicationsRequest + .builder() + .spaceId(spaceId) + .page(page) + .build())))) + .map(ApplicationResource::getName) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -590,20 +941,29 @@ public void scale() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV3() - .scale(ScaleApplicationRequest.builder() - .applicationId(applicationId) - .diskInMb(404) - .type("web") - .build()) - .thenReturn(applicationId)) - .flatMap(applicationId -> requestApplicationProcess(this.cloudFoundryClient, applicationId)) - .map(GetApplicationProcessResponse::getDiskInMb) - .as(StepVerifier::create) - .expectNext(404) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .scale( + ScaleApplicationRequest.builder() + .applicationId(applicationId) + .diskInMb(404) + .type("web") + .build()) + .thenReturn(applicationId)) + .flatMap( + applicationId -> + requestApplicationProcess(this.cloudFoundryClient, applicationId)) + .map(GetApplicationProcessResponse::getDiskInMb) + .as(StepVerifier::create) + .expectNext(404) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -611,29 +971,50 @@ public void setAndGetDroplet() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - uploadPackageAndCreateDropletId(this.cloudFoundryClient, applicationId) - )) - .delayUntil(function((applicationId, dropletId) -> this.cloudFoundryClient.applicationsV3() - .setCurrentDroplet(SetApplicationCurrentDropletRequest.builder() - .applicationId(applicationId) - .data(Relationship.builder() - .id(dropletId) - .build()) - .build()))) - .flatMap(function((applicationId, dropletId) -> Mono.zip( - Mono.just(dropletId), - this.cloudFoundryClient.applicationsV3() - .getCurrentDroplet(GetApplicationCurrentDropletRequest.builder() - .applicationId(applicationId) - .build()) - .map(GetApplicationCurrentDropletResponse::getId)))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + uploadPackageAndCreateDropletId( + this.cloudFoundryClient, applicationId))) + .delayUntil( + function( + (applicationId, dropletId) -> + this.cloudFoundryClient + .applicationsV3() + .setCurrentDroplet( + SetApplicationCurrentDropletRequest + .builder() + .applicationId(applicationId) + .data( + Relationship.builder() + .id(dropletId) + .build()) + .build()))) + .flatMap( + function( + (applicationId, dropletId) -> + Mono.zip( + Mono.just(dropletId), + this.cloudFoundryClient + .applicationsV3() + .getCurrentDroplet( + GetApplicationCurrentDropletRequest + .builder() + .applicationId( + applicationId) + .build()) + .map( + GetApplicationCurrentDropletResponse + ::getId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -641,18 +1022,29 @@ public void start() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .delayUntil(applicationId -> prepareApplicationToStart(this.cloudFoundryClient, applicationId)) - .delayUntil((applicationId -> this.cloudFoundryClient.applicationsV3() - .start(StartApplicationRequest.builder() - .applicationId(applicationId) - .build()))) - .flatMap(applicationId -> requestGetApplication(this.cloudFoundryClient, applicationId)) - .map(GetApplicationResponse::getState) - .as(StepVerifier::create) - .expectNext(STARTED) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .delayUntil( + applicationId -> + prepareApplicationToStart(this.cloudFoundryClient, applicationId)) + .delayUntil( + (applicationId -> + this.cloudFoundryClient + .applicationsV3() + .start( + StartApplicationRequest.builder() + .applicationId(applicationId) + .build()))) + .flatMap( + applicationId -> + requestGetApplication(this.cloudFoundryClient, applicationId)) + .map(GetApplicationResponse::getState) + .as(StepVerifier::create) + .expectNext(STARTED) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -660,25 +1052,52 @@ public void restart() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .delayUntil(applicationId -> prepareApplicationToStart(this.cloudFoundryClient, applicationId)) - .delayUntil(applicationId -> requestStartApplication(this.cloudFoundryClient, applicationId)) - .flatMap(applicationId -> requestApplicationProcess(this.cloudFoundryClient, applicationId) - .map(process -> Instant.parse(process.getUpdatedAt())) - .map(updatedAt -> Tuples.of(applicationId, updatedAt))) - .delayUntil(function((applicationId, oldUpdatedAt) -> this.cloudFoundryClient.applicationsV3() - .restart(RestartApplicationRequest.builder() - .applicationId(applicationId) - .build()) - .delaySubscription(Duration.ofSeconds(2)))) - .flatMap(function((applicationId, oldUpdatedAt) -> requestApplicationProcess(this.cloudFoundryClient, applicationId) - .map(process -> Instant.parse(process.getUpdatedAt())) - .map(newUpdatedAt -> Tuples.of(oldUpdatedAt, newUpdatedAt)) - .delaySubscription(Duration.ofSeconds(2)))) - .as(StepVerifier::create) - .consumeNextWith(consumer((oldUpdatedAt, newUpdatedAt) -> assertThat(newUpdatedAt).isAfter(oldUpdatedAt))) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .delayUntil( + applicationId -> + prepareApplicationToStart(this.cloudFoundryClient, applicationId)) + .delayUntil( + applicationId -> + requestStartApplication(this.cloudFoundryClient, applicationId)) + .flatMap( + applicationId -> + requestApplicationProcess(this.cloudFoundryClient, applicationId) + .map(process -> Instant.parse(process.getUpdatedAt())) + .map(updatedAt -> Tuples.of(applicationId, updatedAt))) + .delayUntil( + function( + (applicationId, oldUpdatedAt) -> + this.cloudFoundryClient + .applicationsV3() + .restart( + RestartApplicationRequest.builder() + .applicationId(applicationId) + .build()) + .delaySubscription(Duration.ofSeconds(2)))) + .flatMap( + function( + (applicationId, oldUpdatedAt) -> + requestApplicationProcess( + this.cloudFoundryClient, applicationId) + .map( + process -> + Instant.parse( + process.getUpdatedAt())) + .map( + newUpdatedAt -> + Tuples.of( + oldUpdatedAt, newUpdatedAt)) + .delaySubscription(Duration.ofSeconds(2)))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (oldUpdatedAt, newUpdatedAt) -> + assertThat(newUpdatedAt).isAfter(oldUpdatedAt))) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -686,19 +1105,32 @@ public void stop() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .delayUntil(applicationId -> prepareApplicationToStart(this.cloudFoundryClient, applicationId)) - .delayUntil((applicationId -> requestStartApplication(this.cloudFoundryClient, applicationId))) - .delayUntil(applicationId -> this.cloudFoundryClient.applicationsV3() - .stop(StopApplicationRequest.builder() - .applicationId(applicationId) - .build())) - .flatMap(applicationId -> requestGetApplication(this.cloudFoundryClient, applicationId)) - .map(GetApplicationResponse::getState) - .as(StepVerifier::create) - .expectNext(STOPPED) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .delayUntil( + applicationId -> + prepareApplicationToStart(this.cloudFoundryClient, applicationId)) + .delayUntil( + (applicationId -> + requestStartApplication(this.cloudFoundryClient, applicationId))) + .delayUntil( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .stop( + StopApplicationRequest.builder() + .applicationId(applicationId) + .build())) + .flatMap( + applicationId -> + requestGetApplication(this.cloudFoundryClient, applicationId)) + .map(GetApplicationResponse::getState) + .as(StepVerifier::create) + .expectNext(STOPPED) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -706,20 +1138,32 @@ public void update() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .delayUntil(applicationId -> this.cloudFoundryClient.applicationsV3() - .update(UpdateApplicationRequest.builder() - .applicationId(applicationId) - .metadata(Metadata.builder() - .label("test-update-key", "test-update-value") - .build()) - .build())) - .flatMap(applicationId -> requestGetApplication(this.cloudFoundryClient, applicationId)) - .map(response -> response.getMetadata().getLabels()) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-update-key", "test-update-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .delayUntil( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .update( + UpdateApplicationRequest.builder() + .applicationId(applicationId) + .metadata( + Metadata.builder() + .label( + "test-update-key", + "test-update-value") + .build()) + .build())) + .flatMap( + applicationId -> + requestGetApplication(this.cloudFoundryClient, applicationId)) + .map(response -> response.getMetadata().getLabels()) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-update-key", "test-update-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -727,21 +1171,35 @@ public void updateAndGetEnvironmentVariables() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .delayUntil(applicationId -> this.cloudFoundryClient.applicationsV3() - .updateEnvironmentVariables(UpdateApplicationEnvironmentVariablesRequest.builder() - .applicationId(applicationId) - .var("test-updateEnv-key", "test-updateEnv-key") - .build())) - .flatMap(applicationId -> this.cloudFoundryClient.applicationsV3() - .getEnvironmentVariables(GetApplicationEnvironmentVariablesRequest.builder() - .applicationId(applicationId) - .build())) - .map(GetApplicationEnvironmentVariablesResponse::getVars) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-updateEnv-key", "test-updateEnv-key")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .delayUntil( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .updateEnvironmentVariables( + UpdateApplicationEnvironmentVariablesRequest + .builder() + .applicationId(applicationId) + .var( + "test-updateEnv-key", + "test-updateEnv-key") + .build())) + .flatMap( + applicationId -> + this.cloudFoundryClient + .applicationsV3() + .getEnvironmentVariables( + GetApplicationEnvironmentVariablesRequest.builder() + .applicationId(applicationId) + .build())) + .map(GetApplicationEnvironmentVariablesResponse::getVars) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-updateEnv-key", "test-updateEnv-key")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -749,306 +1207,408 @@ public void updateFeature() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> createApplicationId(this.cloudFoundryClient, applicationName, spaceId)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getFeatureEnabled(this.cloudFoundryClient, applicationId, "ssh") - )) - .delayUntil(function((applicationId, enabled) -> this.cloudFoundryClient.applicationsV3() - .updateFeature(UpdateApplicationFeatureRequest.builder() - .applicationId(applicationId) - .enabled(!enabled) - .featureName("ssh") - .build()))) - .flatMap(function((applicationId, enabled) -> Mono.zip( - Mono.just(!enabled), - getFeatureEnabled(this.cloudFoundryClient, applicationId, "ssh")) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getFeatureEnabled( + this.cloudFoundryClient, applicationId, "ssh"))) + .delayUntil( + function( + (applicationId, enabled) -> + this.cloudFoundryClient + .applicationsV3() + .updateFeature( + UpdateApplicationFeatureRequest.builder() + .applicationId(applicationId) + .enabled(!enabled) + .featureName("ssh") + .build()))) + .flatMap( + function( + (applicationId, enabled) -> + Mono.zip( + Mono.just(!enabled), + getFeatureEnabled( + this.cloudFoundryClient, + applicationId, + "ssh")))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, applicationName, spaceId) - .map(CreateApplicationResponse::getId); + .map(CreateApplicationResponse::getId); } - private static Mono createBuildId(CloudFoundryClient cloudFoundryClient, String packageId) { - return requestCreateBuild(cloudFoundryClient, packageId) - .map(CreateBuildResponse::getId); + private static Mono createBuildId( + CloudFoundryClient cloudFoundryClient, String packageId) { + return requestCreateBuild(cloudFoundryClient, packageId).map(CreateBuildResponse::getId); } - private static Mono createDomainId(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + private static Mono createDomainId( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { return requestCreateDomain(cloudFoundryClient, domainName, organizationId) - .map(CreateDomainResponse::getId); + .map(CreateDomainResponse::getId); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(CreateOrganizationResponse::getId); + .map(CreateOrganizationResponse::getId); } - private static Mono createPackageId(CloudFoundryClient cloudFoundryClient, String applicationId) { - return requestCreatePackage(cloudFoundryClient, applicationId).map(CreatePackageResponse::getId); + private static Mono createPackageId( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return requestCreatePackage(cloudFoundryClient, applicationId) + .map(CreatePackageResponse::getId); } - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { return requestCreateRoute(cloudFoundryClient, domainId, label, spaceId) - .map(CreateRouteResponse::getId); + .map(CreateRouteResponse::getId); } - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String host, String label, String path, Integer port, String spaceId) { + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, + String domainId, + String host, + String label, + String path, + Integer port, + String spaceId) { return requestCreateRoute(cloudFoundryClient, domainId, host, label, path, port, spaceId) - .map(CreateRouteResponse::getId); + .map(CreateRouteResponse::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(CreateSpaceResponse::getId); + .map(CreateSpaceResponse::getId); } - private static Mono getFeatureEnabled(CloudFoundryClient cloudFoundryClient, String applicationId, String featureName) { + private static Mono getFeatureEnabled( + CloudFoundryClient cloudFoundryClient, String applicationId, String featureName) { return requestGetFeature(cloudFoundryClient, applicationId, featureName) - .map(GetApplicationFeatureResponse::getEnabled); + .map(GetApplicationFeatureResponse::getEnabled); } - private static Mono requestApplicationProcess(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono requestApplicationProcess( + CloudFoundryClient cloudFoundryClient, String applicationId) { System.out.println(Instant.now()); - return cloudFoundryClient.applicationsV3() - .getProcess(GetApplicationProcessRequest.builder() - .applicationId(applicationId) - .type("web") - .build()); + return cloudFoundryClient + .applicationsV3() + .getProcess( + GetApplicationProcessRequest.builder() + .applicationId(applicationId) + .type("web") + .build()); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { - return cloudFoundryClient.applicationsV3() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .relationships(ApplicationRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + return cloudFoundryClient + .applicationsV3() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCreateBuild(CloudFoundryClient cloudFoundryClient, String packageId) { - return cloudFoundryClient.builds() - .create(CreateBuildRequest.builder() - .getPackage(Relationship.builder() - .id(packageId) - .build()) - .build()); + private static Mono requestCreateBuild( + CloudFoundryClient cloudFoundryClient, String packageId) { + return cloudFoundryClient + .builds() + .create( + CreateBuildRequest.builder() + .getPackage(Relationship.builder().id(packageId).build()) + .build()); } - private static Mono requestCreateDomain(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { - return cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .internal(false) - .name(domainName) - .relationships(DomainRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateDomain( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + return cloudFoundryClient + .domainsV3() + .create( + CreateDomainRequest.builder() + .internal(false) + .name(domainName) + .relationships( + DomainRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizationsV3() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()); + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizationsV3() + .create(CreateOrganizationRequest.builder().name(organizationName).build()); } - private static Mono requestCreatePackage(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.packages() - .create(CreatePackageRequest.builder() - .relationships(PackageRelationships.builder() - .application(ToOneRelationship.builder() - .data(Relationship.builder() - .id(applicationId) - .build()) - .build()) - .build()) - .type(PackageType.BITS) - .build()); + private static Mono requestCreatePackage( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .packages() + .create( + CreatePackageRequest.builder() + .relationships( + PackageRelationships.builder() + .application( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(applicationId) + .build()) + .build()) + .build()) + .type(PackageType.BITS) + .build()); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String host, String label, String path, Integer port, String spaceId) { + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, + String domainId, + String host, + String label, + String path, + Integer port, + String spaceId) { String key = String.format("test-%s-key", label); String value = String.format("test-%s-value", label); - return cloudFoundryClient.routesV3() - .create(CreateRouteRequest.builder() - .host(host) - .metadata(Metadata.builder() - .label(key, value) - .build()) - .path(path) - .port(port) - .relationships(RouteRelationships.builder() - .domain(ToOneRelationship.builder() - .data(Relationship.builder() - .id(domainId) - .build()) - .build()) - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); + return cloudFoundryClient + .routesV3() + .create( + CreateRouteRequest.builder() + .host(host) + .metadata(Metadata.builder().label(key, value).build()) + .path(path) + .port(port) + .relationships( + RouteRelationships.builder() + .domain( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(domainId) + .build()) + .build()) + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { String key = String.format("test-%s-key", label); String value = String.format("test-%s-value", label); - return cloudFoundryClient.routesV3() - .create(CreateRouteRequest.builder() - .metadata(Metadata.builder() - .label(key, value) - .build()) - .relationships(RouteRelationships.builder() - .domain(ToOneRelationship.builder() - .data(Relationship.builder() - .id(domainId) - .build()) - .build()) - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); + return cloudFoundryClient + .routesV3() + .create( + CreateRouteRequest.builder() + .metadata(Metadata.builder().label(key, value).build()) + .relationships( + RouteRelationships.builder() + .domain( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(domainId) + .build()) + .build()) + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestGetApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV3() - .get(GetApplicationRequest.builder() - .applicationId(applicationId) - .build()); + private static Mono requestGetApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV3() + .get(GetApplicationRequest.builder().applicationId(applicationId).build()); } - private static Mono requestGetApplications(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV3() - .get(GetApplicationRequest.builder() - .applicationId(applicationId) - .build()); + private static Mono requestGetApplications( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV3() + .get(GetApplicationRequest.builder().applicationId(applicationId).build()); } - private static Mono requestGetBuild(CloudFoundryClient cloudFoundryClient, String buildId) { - return cloudFoundryClient.builds() - .get(GetBuildRequest.builder() - .buildId(buildId) - .build()); + private static Mono requestGetBuild( + CloudFoundryClient cloudFoundryClient, String buildId) { + return cloudFoundryClient.builds().get(GetBuildRequest.builder().buildId(buildId).build()); } - private static Mono requestGetFeature(CloudFoundryClient cloudFoundryClient, String applicationId, String featureName) { - return cloudFoundryClient.applicationsV3() - .getFeature(GetApplicationFeatureRequest.builder() - .applicationId(applicationId) - .featureName(featureName) - .build()); + private static Mono requestGetFeature( + CloudFoundryClient cloudFoundryClient, String applicationId, String featureName) { + return cloudFoundryClient + .applicationsV3() + .getFeature( + GetApplicationFeatureRequest.builder() + .applicationId(applicationId) + .featureName(featureName) + .build()); } - private static Mono requestGetPackage(CloudFoundryClient cloudFoundryClient, String packageId) { - return cloudFoundryClient.packages() - .get(GetPackageRequest.builder() - .packageId(packageId) - .build()); + private static Mono requestGetPackage( + CloudFoundryClient cloudFoundryClient, String packageId) { + return cloudFoundryClient + .packages() + .get(GetPackageRequest.builder().packageId(packageId).build()); } - private static Mono requestReplaceDestinations(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { - return cloudFoundryClient.routesV3() - .replaceDestinations(ReplaceRouteDestinationsRequest.builder() - .destination(Destination.builder() - .application(Application.builder() - .applicationId(applicationId) - .build()) - .build()) - .routeId(routeId) - .build()); + private static Mono requestReplaceDestinations( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + return cloudFoundryClient + .routesV3() + .replaceDestinations( + ReplaceRouteDestinationsRequest.builder() + .destination( + Destination.builder() + .application( + Application.builder() + .applicationId(applicationId) + .build()) + .build()) + .routeId(routeId) + .build()); } - private static Mono requestSetDroplet(CloudFoundryClient cloudFoundryClient, String applicationId, String dropletId) { - return cloudFoundryClient.applicationsV3() - .setCurrentDroplet(SetApplicationCurrentDropletRequest.builder() - .applicationId(applicationId) - .data(Relationship.builder() - .id(dropletId) - .build()) - .build()); + private static Mono requestSetDroplet( + CloudFoundryClient cloudFoundryClient, String applicationId, String dropletId) { + return cloudFoundryClient + .applicationsV3() + .setCurrentDroplet( + SetApplicationCurrentDropletRequest.builder() + .applicationId(applicationId) + .data(Relationship.builder().id(dropletId).build()) + .build()); } - private static Mono requestStartApplication(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV3() - .start(StartApplicationRequest.builder() - .applicationId(applicationId) - .build()); + private static Mono requestStartApplication( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV3() + .start(StartApplicationRequest.builder().applicationId(applicationId).build()); } - private static Mono requestUploadPackage(CloudFoundryClient cloudFoundryClient, String packageId) { + private static Mono requestUploadPackage( + CloudFoundryClient cloudFoundryClient, String packageId) { try { - return cloudFoundryClient.packages() - .upload(UploadPackageRequest.builder() - .bits(new ClassPathResource("test-application.zip").getFile().toPath()) - .packageId(packageId) - .build()); + return cloudFoundryClient + .packages() + .upload( + UploadPackageRequest.builder() + .bits( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .packageId(packageId) + .build()); } catch (IOException e) { throw new RuntimeException(e); } } - private static Mono uploadPackageAndCreateDropletId(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono uploadPackageAndCreateDropletId( + CloudFoundryClient cloudFoundryClient, String applicationId) { return createPackageId(cloudFoundryClient, applicationId) - .delayUntil(packageId -> requestUploadPackage(cloudFoundryClient, packageId)) - .delayUntil(packageId -> waitForPackageUpload(cloudFoundryClient, packageId)) - .flatMap(packageId -> createBuildId(cloudFoundryClient, packageId)) - .delayUntil(buildId -> waitForBuild(cloudFoundryClient, buildId)) - .flatMap(buildId -> requestGetBuild(cloudFoundryClient, buildId)) - .map(build -> build.getDroplet().getId()); + .delayUntil(packageId -> requestUploadPackage(cloudFoundryClient, packageId)) + .delayUntil(packageId -> waitForPackageUpload(cloudFoundryClient, packageId)) + .flatMap(packageId -> createBuildId(cloudFoundryClient, packageId)) + .delayUntil(buildId -> waitForBuild(cloudFoundryClient, buildId)) + .flatMap(buildId -> requestGetBuild(cloudFoundryClient, buildId)) + .map(build -> build.getDroplet().getId()); } - private static Mono waitForBuild(CloudFoundryClient cloudFoundryClient, String buildId) { + private static Mono waitForBuild( + CloudFoundryClient cloudFoundryClient, String buildId) { return requestGetBuild(cloudFoundryClient, buildId) - .filter(response -> BuildState.STAGED.equals(response.getState())) - .repeatWhenEmpty(DelayUtils.exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), Duration.ofMinutes(5))); + .filter(response -> BuildState.STAGED.equals(response.getState())) + .repeatWhenEmpty( + DelayUtils.exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5))); } - private static Mono waitForPackageUpload(CloudFoundryClient cloudFoundryClient, String packageId) { + private static Mono waitForPackageUpload( + CloudFoundryClient cloudFoundryClient, String packageId) { return requestGetPackage(cloudFoundryClient, packageId) - .filter(response -> PackageState.READY.equals(response.getState())) - .repeatWhenEmpty(DelayUtils.exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), Duration.ofMinutes(5))); + .filter(response -> PackageState.READY.equals(response.getState())) + .repeatWhenEmpty( + DelayUtils.exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5))); } - private Mono prepareApplicationToStart(CloudFoundryClient cloudFoundryClient, String applicationId) { + private Mono prepareApplicationToStart( + CloudFoundryClient cloudFoundryClient, String applicationId) { return uploadPackageAndCreateDropletId(cloudFoundryClient, applicationId) - .flatMap(dropletId -> requestSetDroplet(cloudFoundryClient, applicationId, dropletId)); + .flatMap( + dropletId -> + requestSetDroplet(cloudFoundryClient, applicationId, dropletId)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/AuditEventsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/AuditEventsTest.java index cb4246afbba..873759568de 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/AuditEventsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/AuditEventsTest.java @@ -16,6 +16,7 @@ package org.cloudfoundry.client.v3; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -30,56 +31,65 @@ import org.cloudfoundry.client.v3.spaces.CreateSpaceResponse; import org.cloudfoundry.client.v3.spaces.SpaceRelationships; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_8) public final class AuditEventsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; @Test public void get() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMapMany(organizationId -> getEventId(this.cloudFoundryClient, organizationId)) - .flatMap(eventId -> this.cloudFoundryClient.auditEventsV3() - .get(GetAuditEventRequest.builder() - .eventId(eventId) - .build())) - .map(GetAuditEventResponse::getType) - .as(StepVerifier::create) - .expectNext("audit.organization.create") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany(organizationId -> getEventId(this.cloudFoundryClient, organizationId)) + .flatMap( + eventId -> + this.cloudFoundryClient + .auditEventsV3() + .get( + GetAuditEventRequest.builder() + .eventId(eventId) + .build())) + .map(GetAuditEventResponse::getType) + .as(StepVerifier::create) + .expectNext("audit.organization.create") + .expectComplete() + .verify(Duration.ofMinutes(5)); } - //Note: Basic list() test is omitted as the potential volume of data means it take several minutes, with little benefit over the listFilterBy... tests. + // Note: Basic list() test is omitted as the potential volume of data means it take several + // minutes, with little benefit over the listFilterBy... tests. @Test public void lisFilterByOrganization() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.auditEventsV3() - .list(ListAuditEventsRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .map(resource -> resource.getAuditEventTarget().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .auditEventsV3() + .list( + ListAuditEventsRequest.builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .map(resource -> resource.getAuditEventTarget().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -87,17 +97,24 @@ public void lisFilterByType() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.auditEventsV3() - .list(ListAuditEventsRequest.builder() - .type("audit.organization.create") - .page(page) - .build()))) - .map(resource -> resource.getAuditEventTarget().getName()) - .filter(organizationName::equals) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .auditEventsV3() + .list( + ListAuditEventsRequest.builder() + .type( + "audit.organization.create") + .page(page) + .build()))) + .map(resource -> resource.getAuditEventTarget().getName()) + .filter(organizationName::equals) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -105,17 +122,25 @@ public void listFilterBySpace() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMapMany(spaceId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.auditEventsV3() - .list(ListAuditEventsRequest.builder() - .page(page) - .spaceId(spaceId) - .build()))) - .map(resource -> resource.getAuditEventTarget().getName()) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .auditEventsV3() + .list( + ListAuditEventsRequest.builder() + .page(page) + .spaceId(spaceId) + .build()))) + .map(resource -> resource.getAuditEventTarget().getName()) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -123,60 +148,78 @@ public void listFilterByTarget() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.auditEventsV3() - .list(ListAuditEventsRequest.builder() - .targetId(organizationId) - .page(page) - .build()))) - .map(resource -> resource.getAuditEventTarget().getName()) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .auditEventsV3() + .list( + ListAuditEventsRequest.builder() + .targetId(organizationId) + .page(page) + .build()))) + .map(resource -> resource.getAuditEventTarget().getName()) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(CreateOrganizationResponse::getId); + .map(CreateOrganizationResponse::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(CreateSpaceResponse::getId); + .map(CreateSpaceResponse::getId); } - private static Flux getEventId(CloudFoundryClient cloudFoundryClient, String organizationId) { - return requestListEvents(cloudFoundryClient, organizationId) - .map(AuditEventResource::getId); + private static Flux getEventId( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return requestListEvents(cloudFoundryClient, organizationId).map(AuditEventResource::getId); } - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizationsV3() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()); + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizationsV3() + .create(CreateOrganizationRequest.builder().name(organizationName).build()); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Flux requestListEvents(CloudFoundryClient cloudFoundryClient, String organizationId) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.auditEventsV3() - .list(ListAuditEventsRequest.builder() - .organizationId(organizationId) - .page(page) - .build())); + private static Flux requestListEvents( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .auditEventsV3() + .list( + ListAuditEventsRequest.builder() + .organizationId(organizationId) + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/BuildpacksTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/BuildpacksTest.java index 40c8628f50f..e8ef885c039 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/BuildpacksTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/BuildpacksTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v3; +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v3.buildpacks.BuildpackResource; @@ -29,38 +32,37 @@ import org.cloudfoundry.client.v3.buildpacks.UploadBuildpackRequest; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; - public final class BuildpacksTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void create() { String buildpackName = this.nameFactory.getBuildpackName(); - this.cloudFoundryClient.buildpacksV3() - .create(CreateBuildpackRequest.builder() - .enabled(false) - .locked(true) - .name(buildpackName) - .position(2) - .build()) - .thenMany(requestListBuildpacks(this.cloudFoundryClient, buildpackName) - .map(BuildpackResource::getName)) - .as(StepVerifier::create) - .expectNext(buildpackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .buildpacksV3() + .create( + CreateBuildpackRequest.builder() + .enabled(false) + .locked(true) + .name(buildpackName) + .position(2) + .build()) + .thenMany( + requestListBuildpacks(this.cloudFoundryClient, buildpackName) + .map(BuildpackResource::getName)) + .as(StepVerifier::create) + .expectNext(buildpackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -68,15 +70,24 @@ public void delete() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacksV3() - .delete(DeleteBuildpackRequest.builder() - .buildpackId(buildpackId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .thenMany(requestListBuildpacks(this.cloudFoundryClient, buildpackName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacksV3() + .delete( + DeleteBuildpackRequest.builder() + .buildpackId(buildpackId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .thenMany(requestListBuildpacks(this.cloudFoundryClient, buildpackName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -84,15 +95,19 @@ public void get() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacksV3() - .get(GetBuildpackRequest.builder() - .buildpackId(buildpackId) - .build())) - .map(GetBuildpackResponse::getName) - .as(StepVerifier::create) - .expectNext(buildpackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacksV3() + .get( + GetBuildpackRequest.builder() + .buildpackId(buildpackId) + .build())) + .map(GetBuildpackResponse::getName) + .as(StepVerifier::create) + .expectNext(buildpackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -100,17 +115,25 @@ public void list() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMapMany(buildpackId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.buildpacksV3() - .list(ListBuildpacksRequest.builder() - .page(page) - .build())) - .filter(resource -> buildpackName.equals(resource.getName())) - .map(BuildpackResource::getPosition)) - .as(StepVerifier::create) - .expectNext(3) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + buildpackId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .buildpacksV3() + .list( + ListBuildpacksRequest + .builder() + .page(page) + .build())) + .filter( + resource -> + buildpackName.equals(resource.getName())) + .map(BuildpackResource::getPosition)) + .as(StepVerifier::create) + .expectNext(3) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -118,17 +141,22 @@ public void listFilterByName() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMapMany(buildpackId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.buildpacksV3() - .list(ListBuildpacksRequest.builder() - .name(buildpackName) - .page(page) - .build()))) - .map(BuildpackResource::getName) - .as(StepVerifier::create) - .expectNext(buildpackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + buildpackId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .buildpacksV3() + .list( + ListBuildpacksRequest.builder() + .name(buildpackName) + .page(page) + .build()))) + .map(BuildpackResource::getName) + .as(StepVerifier::create) + .expectNext(buildpackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -136,19 +164,24 @@ public void update() { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacksV3() - .update(UpdateBuildpackRequest.builder() - .buildpackId(buildpackId) - .enabled(true) - .locked(true) - .position(4) - .build())) - .thenMany(requestListBuildpacks(this.cloudFoundryClient, buildpackName) - .map(BuildpackResource::getPosition)) - .as(StepVerifier::create) - .expectNext(4) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacksV3() + .update( + UpdateBuildpackRequest.builder() + .buildpackId(buildpackId) + .enabled(true) + .locked(true) + .position(4) + .build())) + .thenMany( + requestListBuildpacks(this.cloudFoundryClient, buildpackName) + .map(BuildpackResource::getPosition)) + .as(StepVerifier::create) + .expectNext(4) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -157,17 +190,22 @@ public void upload() throws IOException { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacksV3() - .upload(UploadBuildpackRequest.builder() - .bits(buildpack) - .buildpackId(buildpackId) - .build())) - .thenMany(requestListBuildpacks(this.cloudFoundryClient, buildpackName) - .map(BuildpackResource::getName)) - .as(StepVerifier::create) - .expectNext(buildpackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacksV3() + .upload( + UploadBuildpackRequest.builder() + .bits(buildpack) + .buildpackId(buildpackId) + .build())) + .thenMany( + requestListBuildpacks(this.cloudFoundryClient, buildpackName) + .map(BuildpackResource::getName)) + .as(StepVerifier::create) + .expectNext(buildpackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -176,42 +214,54 @@ public void uploadDirectory() throws IOException { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpackId(this.cloudFoundryClient, buildpackName) - .flatMap(buildpackId -> this.cloudFoundryClient.buildpacksV3() - .upload(UploadBuildpackRequest.builder() - .bits(buildpack) - .buildpackId(buildpackId) - .build())) - .thenMany(requestListBuildpacks(this.cloudFoundryClient, buildpackName) - .map(BuildpackResource::getName)) - .as(StepVerifier::create) - .expectNext(buildpackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + buildpackId -> + this.cloudFoundryClient + .buildpacksV3() + .upload( + UploadBuildpackRequest.builder() + .bits(buildpack) + .buildpackId(buildpackId) + .build())) + .thenMany( + requestListBuildpacks(this.cloudFoundryClient, buildpackName) + .map(BuildpackResource::getName)) + .as(StepVerifier::create) + .expectNext(buildpackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createBuildpackId(CloudFoundryClient cloudFoundryClient, String buildpackName) { + private static Mono createBuildpackId( + CloudFoundryClient cloudFoundryClient, String buildpackName) { return requestCreateBuildpack(cloudFoundryClient, buildpackName) - .map(CreateBuildpackResponse::getId); + .map(CreateBuildpackResponse::getId); } - private static Mono requestCreateBuildpack(CloudFoundryClient cloudFoundryClient, String buildpackName) { - return cloudFoundryClient.buildpacksV3() - .create(CreateBuildpackRequest.builder() - .enabled(false) - .locked(false) - .name(buildpackName) - .position(3) - .stack("cflinuxfs3") - .build()); + private static Mono requestCreateBuildpack( + CloudFoundryClient cloudFoundryClient, String buildpackName) { + return cloudFoundryClient + .buildpacksV3() + .create( + CreateBuildpackRequest.builder() + .enabled(false) + .locked(false) + .name(buildpackName) + .position(3) + .stack("cflinuxfs3") + .build()); } - private static Flux requestListBuildpacks(CloudFoundryClient cloudFoundryClient, String buildpackName) { - return PaginationUtils.requestClientV3Resources(page -> - cloudFoundryClient.buildpacksV3() - .list(ListBuildpacksRequest.builder() - .name(buildpackName) - .page(page) - .build())); + private static Flux requestListBuildpacks( + CloudFoundryClient cloudFoundryClient, String buildpackName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .buildpacksV3() + .list( + ListBuildpacksRequest.builder() + .name(buildpackName) + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/DeploymentsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/DeploymentsTest.java index b37ab449272..61ec02076fc 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/DeploymentsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/DeploymentsTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.nio.file.Path; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -38,26 +43,19 @@ import org.cloudfoundry.operations.applications.GetApplicationRequest; import org.cloudfoundry.operations.applications.PushApplicationRequest; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.nio.file.Path; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_4) public final class DeploymentsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_11) public void cancel_2_11() throws Exception { @@ -65,24 +63,42 @@ public void cancel_2_11() throws Exception { Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplicationId(this.cloudFoundryOperations, name, path) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId) - )) - .flatMap(function((applicationId, dropletId) -> Mono.zip( - Mono.just(applicationId), - createDeploymentId(this.cloudFoundryClient, applicationId, dropletId) - ))) - .flatMap(function((applicationId, deploymentId) -> this.cloudFoundryClient.deploymentsV3() - .cancel(CancelDeploymentRequest.builder() - .deploymentId(deploymentId) - .build()) - .then(Mono.just(applicationId)))) - .flatMapMany(applicationId -> requestListDeployments(this.cloudFoundryClient, applicationId)) - .as(StepVerifier::create) - .consumeNextWith(deploymentResource -> assertThat(deploymentResource.getStatus().getReason()).isIn(DeploymentStatusReason.CANCELED, DeploymentStatusReason.CANCELING)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + Mono.zip( + Mono.just(applicationId), + createDeploymentId( + this.cloudFoundryClient, + applicationId, + dropletId)))) + .flatMap( + function( + (applicationId, deploymentId) -> + this.cloudFoundryClient + .deploymentsV3() + .cancel( + CancelDeploymentRequest.builder() + .deploymentId(deploymentId) + .build()) + .then(Mono.just(applicationId)))) + .flatMapMany( + applicationId -> + requestListDeployments(this.cloudFoundryClient, applicationId)) + .as(StepVerifier::create) + .consumeNextWith( + deploymentResource -> + assertThat(deploymentResource.getStatus().getReason()) + .isIn( + DeploymentStatusReason.CANCELED, + DeploymentStatusReason.CANCELING)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("deprecation") @@ -93,24 +109,40 @@ public void cancel() throws Exception { Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplicationId(this.cloudFoundryOperations, name, path) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId) - )) - .flatMap(function((applicationId, dropletId) -> Mono.zip( - Mono.just(applicationId), - createDeploymentId(this.cloudFoundryClient, applicationId, dropletId) - ))) - .flatMap(function((applicationId, deploymentId) -> this.cloudFoundryClient.deploymentsV3() - .cancel(CancelDeploymentRequest.builder() - .deploymentId(deploymentId) - .build()) - .then(Mono.just(applicationId)))) - .flatMapMany(applicationId -> requestListDeployments(this.cloudFoundryClient, applicationId)) - .as(StepVerifier::create) - .consumeNextWith(deploymentResource -> assertThat(deploymentResource.getState()).isIn(DeploymentState.CANCELING, DeploymentState.CANCELED)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + Mono.zip( + Mono.just(applicationId), + createDeploymentId( + this.cloudFoundryClient, + applicationId, + dropletId)))) + .flatMap( + function( + (applicationId, deploymentId) -> + this.cloudFoundryClient + .deploymentsV3() + .cancel( + CancelDeploymentRequest.builder() + .deploymentId(deploymentId) + .build()) + .then(Mono.just(applicationId)))) + .flatMapMany( + applicationId -> + requestListDeployments(this.cloudFoundryClient, applicationId)) + .as(StepVerifier::create) + .consumeNextWith( + deploymentResource -> + assertThat(deploymentResource.getState()) + .isIn(DeploymentState.CANCELING, DeploymentState.CANCELED)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -119,29 +151,45 @@ public void create() throws Exception { Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplicationId(this.cloudFoundryOperations, name, path) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId) - )) - .flatMap(function((applicationId, dropletId) -> this.cloudFoundryClient.deploymentsV3() - .create(CreateDeploymentRequest.builder() - .droplet(Relationship.builder() - .id(dropletId) - .build()) - .relationships(DeploymentRelationships.builder() - .app(ToOneRelationship.builder() - .data(Relationship.builder() - .id(applicationId) - .build()) - .build()) - .build()) - .build()) - .then(Mono.just(applicationId)))) - .flatMapMany(applicationId -> requestListDeployments(this.cloudFoundryClient, applicationId)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + this.cloudFoundryClient + .deploymentsV3() + .create( + CreateDeploymentRequest.builder() + .droplet( + Relationship.builder() + .id(dropletId) + .build()) + .relationships( + DeploymentRelationships + .builder() + .app( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + applicationId) + .build()) + .build()) + .build()) + .build()) + .then(Mono.just(applicationId)))) + .flatMapMany( + applicationId -> + requestListDeployments(this.cloudFoundryClient, applicationId)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -150,19 +198,28 @@ public void get() throws Exception { Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplicationId(this.cloudFoundryOperations, name, path) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId) - )) - .flatMap(function((applicationId, dropletId) -> createDeploymentId(this.cloudFoundryClient, applicationId, dropletId))) - .flatMap(deploymentId -> this.cloudFoundryClient.deploymentsV3() - .get(GetDeploymentRequest.builder() - .deploymentId(deploymentId) - .build())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + createDeploymentId( + this.cloudFoundryClient, applicationId, dropletId))) + .flatMap( + deploymentId -> + this.cloudFoundryClient + .deploymentsV3() + .get( + GetDeploymentRequest.builder() + .deploymentId(deploymentId) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -171,20 +228,32 @@ public void list() throws Exception { Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplicationId(this.cloudFoundryOperations, name, path) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId) - )) - .flatMap(function((applicationId, dropletId) -> createDeploymentId(this.cloudFoundryClient, applicationId, dropletId))) - .flatMapMany(deploymentId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.deploymentsV3() - .list(ListDeploymentsRequest.builder() - .page(page) - .build())) - .filter(resource -> deploymentId.equals(resource.getId()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + createDeploymentId( + this.cloudFoundryClient, applicationId, dropletId))) + .flatMapMany( + deploymentId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .deploymentsV3() + .list( + ListDeploymentsRequest + .builder() + .page(page) + .build())) + .filter(resource -> deploymentId.equals(resource.getId()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -193,21 +262,35 @@ public void listFilterByApplication() throws Exception { Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplicationId(this.cloudFoundryOperations, name, path) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId) - )) - .flatMap(function((applicationId, dropletId) -> requestCreateDeployment(this.cloudFoundryClient, applicationId, dropletId) - .then(Mono.just(applicationId)))) - .flatMapMany(applicationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.deploymentsV3() - .list(ListDeploymentsRequest.builder() - .applicationId(applicationId) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + requestCreateDeployment( + this.cloudFoundryClient, + applicationId, + dropletId) + .then(Mono.just(applicationId)))) + .flatMapMany( + applicationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .deploymentsV3() + .list( + ListDeploymentsRequest.builder() + .applicationId( + applicationId) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -216,21 +299,37 @@ public void listFilterByState() throws Exception { Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplicationId(this.cloudFoundryOperations, name, path) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId) - )) - .flatMap(function((applicationId, dropletId) -> createDeploymentId(this.cloudFoundryClient, applicationId, dropletId))) - .flatMapMany(deploymentId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.deploymentsV3() - .list(ListDeploymentsRequest.builder() - .states(DeploymentState.DEPLOYED, DeploymentState.DEPLOYING) - .page(page) - .build())) - .filter(resource -> deploymentId.equals(resource.getId()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + createDeploymentId( + this.cloudFoundryClient, applicationId, dropletId))) + .flatMapMany( + deploymentId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .deploymentsV3() + .list( + ListDeploymentsRequest + .builder() + .states( + DeploymentState + .DEPLOYED, + DeploymentState + .DEPLOYING) + .page(page) + .build())) + .filter(resource -> deploymentId.equals(resource.getId()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -240,88 +339,121 @@ public void listFilterByStatusValues() throws Exception { Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplicationId(this.cloudFoundryOperations, name, path) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId) - )) - .flatMap(function((applicationId, dropletId) -> createDeploymentId(this.cloudFoundryClient, applicationId, dropletId))) - .flatMapMany(deploymentId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.deploymentsV3() - .list(ListDeploymentsRequest.builder() - .statusValues(DeploymentStatusValue.DEPLOYING, DeploymentStatusValue.ACTIVE) - .page(page) - .build())) - .filter(resource -> deploymentId.equals(resource.getId()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + createDeploymentId( + this.cloudFoundryClient, applicationId, dropletId))) + .flatMapMany( + deploymentId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .deploymentsV3() + .list( + ListDeploymentsRequest + .builder() + .statusValues( + DeploymentStatusValue + .DEPLOYING, + DeploymentStatusValue + .ACTIVE) + .page(page) + .build())) + .filter(resource -> deploymentId.equals(resource.getId()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplicationId(CloudFoundryOperations cloudFoundryOperations, String name, Path path) { + private static Mono createApplicationId( + CloudFoundryOperations cloudFoundryOperations, String name, Path path) { return requestCreateApplication(cloudFoundryOperations, name, path) - .then(getApplicationId(cloudFoundryOperations, name)); + .then(getApplicationId(cloudFoundryOperations, name)); } - private static Mono createDeploymentId(CloudFoundryClient cloudFoundryClient, String applicationId, String dropletId) { + private static Mono createDeploymentId( + CloudFoundryClient cloudFoundryClient, String applicationId, String dropletId) { return requestCreateDeployment(cloudFoundryClient, applicationId, dropletId) - .map(CreateDeploymentResponse::getId); + .map(CreateDeploymentResponse::getId); } - private static Mono getApplicationId(CloudFoundryOperations cloudFoundryOperations, String name) { - return cloudFoundryOperations.applications() - .get(GetApplicationRequest.builder() - .name(name) - .build()) - .map(ApplicationDetail::getId); + private static Mono getApplicationId( + CloudFoundryOperations cloudFoundryOperations, String name) { + return cloudFoundryOperations + .applications() + .get(GetApplicationRequest.builder().name(name).build()) + .map(ApplicationDetail::getId); } - private static Mono getDropletId(CloudFoundryClient cloudFoundryClient, String applicationId) { + private static Mono getDropletId( + CloudFoundryClient cloudFoundryClient, String applicationId) { return requestCurrentDroplet(cloudFoundryClient, applicationId) - .map(GetApplicationCurrentDropletResponse::getId); + .map(GetApplicationCurrentDropletResponse::getId); } - private static Mono requestCreateApplication(CloudFoundryOperations cloudFoundryOperations, String name, Path path) { - return cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(path) - .buildpack("staticfile_buildpack") - .diskQuota(256) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(name) - .noStart(false) - .build()); + private static Mono requestCreateApplication( + CloudFoundryOperations cloudFoundryOperations, String name, Path path) { + return cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path(path) + .buildpack("staticfile_buildpack") + .diskQuota(256) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(name) + .noStart(false) + .build()); } - private static Mono requestCreateDeployment(CloudFoundryClient cloudFoundryClient, String applicationId, String dropletId) { - return cloudFoundryClient.deploymentsV3() - .create(CreateDeploymentRequest.builder() - .droplet(Relationship.builder() - .id(dropletId) - .build()) - .relationships(DeploymentRelationships.builder() - .app(ToOneRelationship.builder() - .data(Relationship.builder() - .id(applicationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateDeployment( + CloudFoundryClient cloudFoundryClient, String applicationId, String dropletId) { + return cloudFoundryClient + .deploymentsV3() + .create( + CreateDeploymentRequest.builder() + .droplet(Relationship.builder().id(dropletId).build()) + .relationships( + DeploymentRelationships.builder() + .app( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(applicationId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCurrentDroplet(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV3() - .getCurrentDroplet(GetApplicationCurrentDropletRequest.builder() - .applicationId(applicationId) - .build()); + private static Mono requestCurrentDroplet( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV3() + .getCurrentDroplet( + GetApplicationCurrentDropletRequest.builder() + .applicationId(applicationId) + .build()); } - private static Flux requestListDeployments(CloudFoundryClient cloudFoundryClient, String applicationId) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.deploymentsV3() - .list(ListDeploymentsRequest.builder() - .applicationId(applicationId) - .page(page) - .build())); + private static Flux requestListDeployments( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .deploymentsV3() + .list( + ListDeploymentsRequest.builder() + .applicationId(applicationId) + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/DomainsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/DomainsTest.java index 654e3d1fb0c..45925ac902f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/DomainsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/DomainsTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.function.Consumer; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -43,6 +49,7 @@ import org.cloudfoundry.client.v3.routes.RouteRelationships; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -50,26 +57,16 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) public final class DomainsTest extends AbstractIntegrationTest { private static final Logger LOGGER = LoggerFactory.getLogger(DomainsTest.class); - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @Test @@ -77,18 +74,21 @@ public void checkReservedRoutes() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> createDomainId(this.cloudFoundryClient, domainName, organizationId)) - .flatMap(domainId -> - this.cloudFoundryClient.domainsV3() - .checkReservedRoutes(CheckReservedRoutesRequest.builder() - .domainId(domainId) - .build())) - .as(StepVerifier::create) - .expectNext(CheckReservedRoutesResponse.builder() - .matchingRoute(false) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createDomainId(this.cloudFoundryClient, domainName, organizationId)) + .flatMap( + domainId -> + this.cloudFoundryClient + .domainsV3() + .checkReservedRoutes( + CheckReservedRoutesRequest.builder() + .domainId(domainId) + .build())) + .as(StepVerifier::create) + .expectNext(CheckReservedRoutesResponse.builder().matchingRoute(false).build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -98,23 +98,38 @@ public void checkReservedRoutesByHost() { String hostName = this.nameFactory.getHostName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, hostName, null, null, spaceId) - .thenReturn(domainId))) - .flatMap(domainId -> this.cloudFoundryClient.domainsV3() - .checkReservedRoutes(CheckReservedRoutesRequest.builder() - .domainId(domainId) - .host(hostName) - .build())) - .as(StepVerifier::create) - .expectNext(CheckReservedRoutesResponse.builder() - .matchingRoute(true) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + hostName, + null, + null, + spaceId) + .thenReturn(domainId))) + .flatMap( + domainId -> + this.cloudFoundryClient + .domainsV3() + .checkReservedRoutes( + CheckReservedRoutesRequest.builder() + .domainId(domainId) + .host(hostName) + .build())) + .as(StepVerifier::create) + .expectNext(CheckReservedRoutesResponse.builder().matchingRoute(true).build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -124,70 +139,113 @@ public void checkReservedRoutesByPath() { String path = this.nameFactory.getPath(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, null, path,null, spaceId) - .thenReturn(domainId))) - .flatMap(domainId -> this.cloudFoundryClient.domainsV3() - .checkReservedRoutes(CheckReservedRoutesRequest.builder() - .domainId(domainId) - .path(path) - .build())) - .as(StepVerifier::create) - .expectNext(CheckReservedRoutesResponse.builder() - .matchingRoute(true) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + null, + path, + null, + spaceId) + .thenReturn(domainId))) + .flatMap( + domainId -> + this.cloudFoundryClient + .domainsV3() + .checkReservedRoutes( + CheckReservedRoutesRequest.builder() + .domainId(domainId) + .path(path) + .build())) + .as(StepVerifier::create) + .expectNext(CheckReservedRoutesResponse.builder().matchingRoute(true).build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - //TODO: Establish router group availability. This test has not been verified. + // TODO: Establish router group availability. This test has not been verified. public void checkReservedRoutesByPort() { String domainName = this.nameFactory.getDomainName(); Integer port = this.nameFactory.getPort(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, null, null,port, spaceId) - .thenReturn(domainId))) - .flatMap(domainId -> this.cloudFoundryClient.domainsV3() - .checkReservedRoutes(CheckReservedRoutesRequest.builder() - .domainId(domainId) - .port(port) - .build())) - .as(StepVerifier::create) - .expectNext(CheckReservedRoutesResponse.builder() - .matchingRoute(true) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + null, + null, + port, + spaceId) + .thenReturn(domainId))) + .flatMap( + domainId -> + this.cloudFoundryClient + .domainsV3() + .checkReservedRoutes( + CheckReservedRoutesRequest.builder() + .domainId(domainId) + .port(port) + .build())) + .as(StepVerifier::create) + .expectNext(CheckReservedRoutesResponse.builder().matchingRoute(true).build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String host, String path, Integer port, String spaceId) { - - return cloudFoundryClient.routesV3() - .create(CreateRouteRequest.builder() - .host(host) - .path(path) - .port(port) - .relationships(RouteRelationships.builder() - .domain(ToOneRelationship.builder() - .data(Relationship.builder() - .id(domainId) - .build()) - .build()) - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, + String domainId, + String host, + String path, + Integer port, + String spaceId) { + + return cloudFoundryClient + .routesV3() + .create( + CreateRouteRequest.builder() + .host(host) + .path(path) + .port(port) + .relationships( + RouteRelationships.builder() + .domain( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(domainId) + .build()) + .build()) + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_6) @@ -195,15 +253,13 @@ private static Mono requestCreateRoute(CloudFoundryClient c public void create() { String domainName = this.nameFactory.getDomainName(); - this.cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .internal(false) - .name(domainName) - .build()) - .as(StepVerifier::create) - .consumeNextWith(globalDomainNameEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .domainsV3() + .create(CreateDomainRequest.builder().internal(false).name(domainName).build()) + .as(StepVerifier::create) + .consumeNextWith(globalDomainNameEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_6) @@ -212,28 +268,49 @@ public void createForAnOrganization() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - this.cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .name(domainName) - .relationships(DomainRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()), - Mono.just(organizationId) - )) - .as(StepVerifier::create) - .consumeNextWith(consumer((response, organizationId) -> { - assertThat(response.getName()).isEqualTo(domainName); - assertThat(response.getRelationships().getOrganization().getData().getId()).isEqualTo(organizationId); - assertThat(response.getRelationships().getSharedOrganizations().getData()).isEmpty(); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + this.cloudFoundryClient + .domainsV3() + .create( + CreateDomainRequest.builder() + .name(domainName) + .relationships( + DomainRelationships + .builder() + .organization( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + organizationId) + .build()) + .build()) + .build()) + .build()), + Mono.just(organizationId))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (response, organizationId) -> { + assertThat(response.getName()).isEqualTo(domainName); + assertThat( + response.getRelationships() + .getOrganization() + .getData() + .getId()) + .isEqualTo(organizationId); + assertThat( + response.getRelationships() + .getSharedOrganizations() + .getData()) + .isEmpty(); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -242,15 +319,30 @@ public void delete() { String domainName = this.nameFactory.getDomainName(); createDomainId(this.cloudFoundryClient, domainName) - .delayUntil(domainId -> this.cloudFoundryClient.domainsV3() - .delete(DeleteDomainRequest.builder() - .domainId(domainId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMap(domainId -> requestGetDomain(this.cloudFoundryClient, domainId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV3Exception.class).hasMessageMatching("CF-ResourceNotFound\\([0-9]+\\): Domain not found.*")) - .verify(Duration.ofMinutes(5)); + .delayUntil( + domainId -> + this.cloudFoundryClient + .domainsV3() + .delete( + DeleteDomainRequest.builder() + .domainId(domainId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMap(domainId -> requestGetDomain(this.cloudFoundryClient, domainId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV3Exception.class) + .hasMessageMatching( + "CF-ResourceNotFound\\([0-9]+\\): Domain not" + + " found.*")) + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_6) @@ -259,14 +351,15 @@ public void get() { String domainName = this.nameFactory.getDomainName(); createDomainId(this.cloudFoundryClient, domainName) - .flatMap(domainId -> this.cloudFoundryClient.domainsV3() - .get(GetDomainRequest.builder() - .domainId(domainId) - .build())) - .as(StepVerifier::create) - .consumeNextWith(globalDomainNameEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + domainId -> + this.cloudFoundryClient + .domainsV3() + .get(GetDomainRequest.builder().domainId(domainId).build())) + .as(StepVerifier::create) + .consumeNextWith(globalDomainNameEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_6) @@ -275,17 +368,22 @@ public void list() { String domainName = this.nameFactory.getDomainName(); createDomainId(this.cloudFoundryClient, domainName) - .flatMap(domainId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.domainsV3() - .list(ListDomainsRequest.builder() - .page(page) - .build())) - .filter(resource -> domainId.equals(resource.getId())) - .single() - ) - .as(StepVerifier::create) - .consumeNextWith(globalDomainNameEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + domainId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .domainsV3() + .list( + ListDomainsRequest.builder() + .page(page) + .build())) + .filter(resource -> domainId.equals(resource.getId())) + .single()) + .as(StepVerifier::create) + .consumeNextWith(globalDomainNameEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -294,16 +392,21 @@ public void listFilterById() { String domainName = this.nameFactory.getDomainName(); createDomainId(this.cloudFoundryClient, domainName) - .flatMapMany(domainId -> PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.domainsV3() - .list(ListDomainsRequest.builder() - .domainId(domainId) - .page(page) - .build()))) - .as(StepVerifier::create) - .consumeNextWith(globalDomainNameEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + domainId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .domainsV3() + .list( + ListDomainsRequest.builder() + .domainId(domainId) + .page(page) + .build()))) + .as(StepVerifier::create) + .consumeNextWith(globalDomainNameEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -312,19 +415,23 @@ public void listFilterByName() { String domainName = this.nameFactory.getDomainName(); createDomainId(this.cloudFoundryClient, domainName) - .flatMap(domainId -> PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.domainsV3() - .list(ListDomainsRequest.builder() - .name(domainName) - .page(page) - .build())) - .filter(resource -> domainId.equals(resource.getId())) - .single() - ) - .as(StepVerifier::create) - .consumeNextWith(globalDomainNameEquality(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + domainId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .domainsV3() + .list( + ListDomainsRequest.builder() + .name(domainName) + .page(page) + .build())) + .filter(resource -> domainId.equals(resource.getId())) + .single()) + .as(StepVerifier::create) + .consumeNextWith(globalDomainNameEquality(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -333,28 +440,55 @@ public void listFilterByOwningOrganizationId() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createDomainId(this.cloudFoundryClient, domainName, organizationId) - )) - .flatMap(function((organizationId, domainId) -> Mono.zip( - PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.domainsV3() - .list(ListDomainsRequest.builder() - .owningOrganizationId(organizationId) - .page(page) - .build())) - .filter(resource -> domainId.equals(resource.getId())) - .single(), - Mono.just(organizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(consumer((response, organizationId) -> { - assertThat(response.getName()).isEqualTo(domainName); - assertThat(response.getRelationships().getOrganization().getData().getId()).isEqualTo(organizationId); - assertThat(response.getRelationships().getSharedOrganizations().getData()).isEmpty(); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId))) + .flatMap( + function( + (organizationId, domainId) -> + Mono.zip( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .domainsV3() + .list( + ListDomainsRequest + .builder() + .owningOrganizationId( + organizationId) + .page( + page) + .build())) + .filter( + resource -> + domainId.equals( + resource.getId())) + .single(), + Mono.just(organizationId)))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (response, organizationId) -> { + assertThat(response.getName()).isEqualTo(domainName); + assertThat( + response.getRelationships() + .getOrganization() + .getData() + .getId()) + .isEqualTo(organizationId); + assertThat( + response.getRelationships() + .getSharedOrganizations() + .getData()) + .isEmpty(); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -364,31 +498,58 @@ public void share() { String organizationName = this.nameFactory.getOrganizationName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createDomainId(this.cloudFoundryClient, domainName, organizationId), - createOrganizationId(this.cloudFoundryClient, organizationName) - )) - .delayUntil(function((organizationId, domainId, newOrganizationId) -> this.cloudFoundryClient.domainsV3() - .share(ShareDomainRequest.builder() - .domainId(domainId) - .data(Relationship.builder() - .id(newOrganizationId) - .build()) - .build()))) - .flatMap(function((organizationId, domainId, newOrganizationId) -> Mono.zip( - requestGetDomain(this.cloudFoundryClient, domainId), - Mono.just(organizationId), - Mono.just(newOrganizationId) - ))) - .as(StepVerifier::create) - .consumeNextWith(consumer((response, organizationId, newOrganizationId) -> { - assertThat(response.getName()).isEqualTo(domainName); - assertThat(response.getRelationships().getOrganization().getData().getId()).isEqualTo(organizationId); - assertThat(response.getRelationships().getSharedOrganizations().getData().get(0).getId()).isEqualTo(newOrganizationId); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, organizationName))) + .delayUntil( + function( + (organizationId, domainId, newOrganizationId) -> + this.cloudFoundryClient + .domainsV3() + .share( + ShareDomainRequest.builder() + .domainId(domainId) + .data( + Relationship.builder() + .id( + newOrganizationId) + .build()) + .build()))) + .flatMap( + function( + (organizationId, domainId, newOrganizationId) -> + Mono.zip( + requestGetDomain(this.cloudFoundryClient, domainId), + Mono.just(organizationId), + Mono.just(newOrganizationId)))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (response, organizationId, newOrganizationId) -> { + assertThat(response.getName()).isEqualTo(domainName); + assertThat( + response.getRelationships() + .getOrganization() + .getData() + .getId()) + .isEqualTo(organizationId); + assertThat( + response.getRelationships() + .getSharedOrganizations() + .getData() + .get(0) + .getId()) + .isEqualTo(newOrganizationId); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -398,27 +559,52 @@ public void unshare() { String organizationName = this.nameFactory.getOrganizationName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createDomainId(this.cloudFoundryClient, domainName, organizationId), - createOrganizationId(this.cloudFoundryClient, organizationName) - )) - .doOnSuccess(T -> LOGGER.info("OrganizationId: {}, domainId: {}, newOrganizationId: {}", T.getT1(), T.getT2(), T.getT3())) - .delayUntil(function((organizationId, domainId, newOrganizationId) -> - requestShareDomain(this.cloudFoundryClient, domainId, newOrganizationId))) - .delayUntil(function((organizationId, domainId, newOrganizationId) -> this.cloudFoundryClient.domainsV3() - .unshare(UnshareDomainRequest.builder() - .domainId(domainId) - .organizationId(newOrganizationId) - .build()))) - .flatMapMany(function((organizationId, domainId, newOrganizationId) -> - requestListDomainsForOrganization(this.cloudFoundryClient, newOrganizationId) - .filter(resource -> domainId.equals(resource.getId())) - )) - .as(StepVerifier::create) - .expectNextCount(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createOrganizationId( + this.cloudFoundryClient, organizationName))) + .doOnSuccess( + T -> + LOGGER.info( + "OrganizationId: {}, domainId: {}, newOrganizationId: {}", + T.getT1(), + T.getT2(), + T.getT3())) + .delayUntil( + function( + (organizationId, domainId, newOrganizationId) -> + requestShareDomain( + this.cloudFoundryClient, + domainId, + newOrganizationId))) + .delayUntil( + function( + (organizationId, domainId, newOrganizationId) -> + this.cloudFoundryClient + .domainsV3() + .unshare( + UnshareDomainRequest.builder() + .domainId(domainId) + .organizationId(newOrganizationId) + .build()))) + .flatMapMany( + function( + (organizationId, domainId, newOrganizationId) -> + requestListDomainsForOrganization( + this.cloudFoundryClient, newOrganizationId) + .filter( + resource -> + domainId.equals(resource.getId())))) + .as(StepVerifier::create) + .expectNextCount(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -427,41 +613,54 @@ public void update() { String domainName = this.nameFactory.getDomainName(); createDomainId(this.cloudFoundryClient, domainName) - .flatMap(domainId -> this.cloudFoundryClient.domainsV3() - .update(UpdateDomainRequest.builder() - .domainId(domainId) - .metadata(Metadata.builder() - .annotation("annotationKey", "annotationValue") - .label("labelKey", "labelValue") - .build()) - .build())) - .thenMany(requestListDomains(this.cloudFoundryClient, domainName)) - .map(DomainResource::getMetadata) - .as(StepVerifier::create) - .consumeNextWith(metadata -> { - assertThat(metadata.getAnnotations().get("annotationKey")).isEqualTo("annotationValue"); - assertThat(metadata.getLabels().get("labelKey")).isEqualTo("labelValue"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + domainId -> + this.cloudFoundryClient + .domainsV3() + .update( + UpdateDomainRequest.builder() + .domainId(domainId) + .metadata( + Metadata.builder() + .annotation( + "annotationKey", + "annotationValue") + .label( + "labelKey", + "labelValue") + .build()) + .build())) + .thenMany(requestListDomains(this.cloudFoundryClient, domainName)) + .map(DomainResource::getMetadata) + .as(StepVerifier::create) + .consumeNextWith( + metadata -> { + assertThat(metadata.getAnnotations().get("annotationKey")) + .isEqualTo("annotationValue"); + assertThat(metadata.getLabels().get("labelKey")) + .isEqualTo("labelValue"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createDomainId(CloudFoundryClient cloudFoundryClient, String domainName) { - return requestCreateDomain(cloudFoundryClient, domainName) - .map(CreateDomainResponse::getId); + private static Mono createDomainId( + CloudFoundryClient cloudFoundryClient, String domainName) { + return requestCreateDomain(cloudFoundryClient, domainName).map(CreateDomainResponse::getId); } - private static Mono createDomainId(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + private static Mono createDomainId( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { return requestCreateDomain(cloudFoundryClient, domainName, organizationId) - .map(CreateDomainResponse::getId); + .map(CreateDomainResponse::getId); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizationsV3() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()) - .map(CreateOrganizationResponse::getId); + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizationsV3() + .create(CreateOrganizationRequest.builder().name(organizationName).build()) + .map(CreateOrganizationResponse::getId); } private static Consumer globalDomainNameEquality(String domainName) { @@ -472,61 +671,74 @@ private static Consumer globalDomainNameEquality(String domainName) { }; } - private static Mono requestCreateDomain(CloudFoundryClient cloudFoundryClient, String domainName) { - return cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .internal(false) - .name(domainName) - .build()); + private static Mono requestCreateDomain( + CloudFoundryClient cloudFoundryClient, String domainName) { + return cloudFoundryClient + .domainsV3() + .create(CreateDomainRequest.builder().internal(false).name(domainName).build()); } - private static Mono requestCreateDomain(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { - return cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .name(domainName) - .relationships(DomainRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateDomain( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + return cloudFoundryClient + .domainsV3() + .create( + CreateDomainRequest.builder() + .name(domainName) + .relationships( + DomainRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestGetDomain(CloudFoundryClient cloudFoundryClient, String domainId) { - return cloudFoundryClient.domainsV3() - .get(GetDomainRequest.builder() - .domainId(domainId) - .build()); + private static Mono requestGetDomain( + CloudFoundryClient cloudFoundryClient, String domainId) { + return cloudFoundryClient + .domainsV3() + .get(GetDomainRequest.builder().domainId(domainId).build()); } - private static Flux requestListDomains(CloudFoundryClient cloudFoundryClient, String domainName) { - return PaginationUtils - .requestClientV3Resources(page -> cloudFoundryClient.domainsV3() - .list(ListDomainsRequest.builder() - .name(domainName) - .page(page) - .build())); + private static Flux requestListDomains( + CloudFoundryClient cloudFoundryClient, String domainName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .domainsV3() + .list( + ListDomainsRequest.builder() + .name(domainName) + .page(page) + .build())); } - private static Flux requestListDomainsForOrganization(CloudFoundryClient cloudFoundryClient, String organizationId) { - return PaginationUtils - .requestClientV3Resources(page -> cloudFoundryClient.organizationsV3() - .listDomains(ListOrganizationDomainsRequest.builder() - .organizationId(organizationId) - .page(page) - .build())); + private static Flux requestListDomainsForOrganization( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .organizationsV3() + .listDomains( + ListOrganizationDomainsRequest.builder() + .organizationId(organizationId) + .page(page) + .build())); } - private static Mono requestShareDomain(CloudFoundryClient cloudFoundryClient, String domainId, String organizationId) { - return cloudFoundryClient.domainsV3() - .share(ShareDomainRequest.builder() - .domainId(domainId) - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()); + private static Mono requestShareDomain( + CloudFoundryClient cloudFoundryClient, String domainId, String organizationId) { + return cloudFoundryClient + .domainsV3() + .share( + ShareDomainRequest.builder() + .domainId(domainId) + .data(Relationship.builder().id(organizationId).build()) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/IsolationSegmentsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/IsolationSegmentsTest.java index 5d6970ef09d..0f0a56fc1cd 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/IsolationSegmentsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/IsolationSegmentsTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v3; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -43,20 +46,16 @@ import org.cloudfoundry.client.v3.spaces.AssignSpaceIsolationSegmentResponse; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_11) public final class IsolationSegmentsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void addOrganizationEntitlement() { @@ -64,41 +63,52 @@ public void addOrganizationEntitlement() { String organizationName = this.nameFactory.getOrganizationName(); Mono.zip( - createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName), - createOrganizationId(this.cloudFoundryClient, organizationName) - ) - .flatMap(function((isolationSegmentId, organizationId) -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.isolationSegments() - .addOrganizationEntitlement(AddIsolationSegmentOrganizationEntitlementRequest.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .isolationSegmentId(isolationSegmentId) - .build()) - .map(response -> response.getData().get(0).getId())) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName), + createOrganizationId(this.cloudFoundryClient, organizationName)) + .flatMap( + function( + (isolationSegmentId, organizationId) -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .isolationSegments() + .addOrganizationEntitlement( + AddIsolationSegmentOrganizationEntitlementRequest + .builder() + .data( + Relationship + .builder() + .id( + organizationId) + .build()) + .isolationSegmentId( + isolationSegmentId) + .build()) + .map( + response -> + response.getData() + .get(0) + .getId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void create() { String isolationSegmentName = this.nameFactory.getIsolationSegmentName(); - this.cloudFoundryClient.isolationSegments() - .create(CreateIsolationSegmentRequest.builder() - .name(isolationSegmentName) - .build()) - .thenMany(requestListIsolationSegments(this.cloudFoundryClient, isolationSegmentName)) - .map(IsolationSegmentResource::getName) - .as(StepVerifier::create) - .expectNext(isolationSegmentName) - .expectComplete() - .verify(Duration.ofMinutes(5)); - + this.cloudFoundryClient + .isolationSegments() + .create(CreateIsolationSegmentRequest.builder().name(isolationSegmentName).build()) + .thenMany( + requestListIsolationSegments(this.cloudFoundryClient, isolationSegmentName)) + .map(IsolationSegmentResource::getName) + .as(StepVerifier::create) + .expectNext(isolationSegmentName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -106,14 +116,19 @@ public void delete() { String isolationSegmentName = this.nameFactory.getIsolationSegmentName(); createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName) - .flatMap(isolationSegmentId -> this.cloudFoundryClient.isolationSegments() - .delete(DeleteIsolationSegmentRequest.builder() - .isolationSegmentId(isolationSegmentId) - .build())) - .thenMany(requestListIsolationSegments(this.cloudFoundryClient, isolationSegmentName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + isolationSegmentId -> + this.cloudFoundryClient + .isolationSegments() + .delete( + DeleteIsolationSegmentRequest.builder() + .isolationSegmentId(isolationSegmentId) + .build())) + .thenMany( + requestListIsolationSegments(this.cloudFoundryClient, isolationSegmentName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -121,15 +136,19 @@ public void get() { String isolationSegmentName = this.nameFactory.getIsolationSegmentName(); createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName) - .flatMap(isolationSegmentId -> this.cloudFoundryClient.isolationSegments() - .get(GetIsolationSegmentRequest.builder() - .isolationSegmentId(isolationSegmentId) - .build()) - .map(GetIsolationSegmentResponse::getName)) - .as(StepVerifier::create) - .expectNext(isolationSegmentName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + isolationSegmentId -> + this.cloudFoundryClient + .isolationSegments() + .get( + GetIsolationSegmentRequest.builder() + .isolationSegmentId(isolationSegmentId) + .build()) + .map(GetIsolationSegmentResponse::getName)) + .as(StepVerifier::create) + .expectNext(isolationSegmentName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -137,15 +156,20 @@ public void list() { String isolationSegmentName = this.nameFactory.getIsolationSegmentName(); requestCreateIsolationSegment(this.cloudFoundryClient, isolationSegmentName) - .thenMany(PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.isolationSegments() - .list(ListIsolationSegmentsRequest.builder() - .page(page) - .build()))) - .filter(response -> isolationSegmentName.equals(response.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .isolationSegments() + .list( + ListIsolationSegmentsRequest.builder() + .page(page) + .build()))) + .filter(response -> isolationSegmentName.equals(response.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -154,24 +178,37 @@ public void listEntitledOrganizations() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createEntitledIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId), - Mono.just(organizationId) - )) - .flatMapMany(function((isolationSegmentId, organizationId) -> Mono.zip( - Mono.just(organizationId), - PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.isolationSegments() - .listEntitledOrganizations(ListIsolationSegmentEntitledOrganizationsRequest.builder() - .isolationSegmentId(isolationSegmentId) - .page(page) - .build())) - .map(OrganizationResource::getId) - .single() - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createEntitledIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId), + Mono.just(organizationId))) + .flatMapMany( + function( + (isolationSegmentId, organizationId) -> + Mono.zip( + Mono.just(organizationId), + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .isolationSegments() + .listEntitledOrganizations( + ListIsolationSegmentEntitledOrganizationsRequest + .builder() + .isolationSegmentId( + isolationSegmentId) + .page( + page) + .build())) + .map(OrganizationResource::getId) + .single()))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -180,25 +217,39 @@ public void listEntitledOrganizationsFilterByName() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createEntitledIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId), - Mono.just(organizationId) - )) - .flatMapMany(function((isolationSegmentId, organizationId) -> Mono.zip( - Mono.just(organizationId), - PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.isolationSegments() - .listEntitledOrganizations(ListIsolationSegmentEntitledOrganizationsRequest.builder() - .isolationSegmentId(isolationSegmentId) - .name(organizationName) - .page(page) - .build())) - .map(OrganizationResource::getId) - .single() - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createEntitledIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId), + Mono.just(organizationId))) + .flatMapMany( + function( + (isolationSegmentId, organizationId) -> + Mono.zip( + Mono.just(organizationId), + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .isolationSegments() + .listEntitledOrganizations( + ListIsolationSegmentEntitledOrganizationsRequest + .builder() + .isolationSegmentId( + isolationSegmentId) + .name( + organizationName) + .page( + page) + .build())) + .map(OrganizationResource::getId) + .single()))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -206,16 +257,24 @@ public void listFilterById() { String isolationSegmentName = this.nameFactory.getIsolationSegmentName(); createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName) - .flatMapMany(isolationSegmentId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.isolationSegments() - .list(ListIsolationSegmentsRequest.builder() - .isolationSegmentId(isolationSegmentId) - .page(page) - .build())) - .map(IsolationSegmentResource::getName)) - .as(StepVerifier::create) - .expectNext(isolationSegmentName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + isolationSegmentId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .isolationSegments() + .list( + ListIsolationSegmentsRequest + .builder() + .isolationSegmentId( + isolationSegmentId) + .page(page) + .build())) + .map(IsolationSegmentResource::getName)) + .as(StepVerifier::create) + .expectNext(isolationSegmentName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -223,15 +282,20 @@ public void listFilterByName() { String isolationSegmentName = this.nameFactory.getIsolationSegmentName(); requestCreateIsolationSegment(this.cloudFoundryClient, isolationSegmentName) - .thenMany(PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.isolationSegments() - .list(ListIsolationSegmentsRequest.builder() - .name(isolationSegmentName) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .isolationSegments() + .list( + ListIsolationSegmentsRequest.builder() + .name(isolationSegmentName) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -240,19 +304,31 @@ public void listFilterByOrganizationId() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> createEntitledIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId) - .thenReturn(organizationId)) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.isolationSegments() - .list(ListIsolationSegmentsRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .filter(resource -> isolationSegmentName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createEntitledIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId) + .thenReturn(organizationId)) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .isolationSegments() + .list( + ListIsolationSegmentsRequest + .builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .filter(resource -> isolationSegmentName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -262,31 +338,56 @@ public void listOrganizationsRelationship() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createEntitledIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId), - Mono.just(organizationId), - Mono.just(spaceId) - ))) - .flatMap(function((isolationSegmentId, organizationId, spaceId) -> Mono.zip( - requestAssignIsolationSegment(this.cloudFoundryClient, isolationSegmentId, spaceId) - .thenReturn(isolationSegmentId), - Mono.just(organizationId) - ))) - .flatMapMany(function((isolationSegmentId, organizationId) -> Mono.zip( - Mono.just(organizationId), - this.cloudFoundryClient.isolationSegments() - .listOrganizationsRelationship(ListIsolationSegmentOrganizationsRelationshipRequest.builder() - .isolationSegmentId(isolationSegmentId) - .build()) - .map(response -> response.getData().get(0).getId())))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createEntitledIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId), + Mono.just(organizationId), + Mono.just(spaceId)))) + .flatMap( + function( + (isolationSegmentId, organizationId, spaceId) -> + Mono.zip( + requestAssignIsolationSegment( + this.cloudFoundryClient, + isolationSegmentId, + spaceId) + .thenReturn(isolationSegmentId), + Mono.just(organizationId)))) + .flatMapMany( + function( + (isolationSegmentId, organizationId) -> + Mono.zip( + Mono.just(organizationId), + this.cloudFoundryClient + .isolationSegments() + .listOrganizationsRelationship( + ListIsolationSegmentOrganizationsRelationshipRequest + .builder() + .isolationSegmentId( + isolationSegmentId) + .build()) + .map( + response -> + response.getData() + .get(0) + .getId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -296,26 +397,52 @@ public void listSpacesRelationship() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createEntitledIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId), - Mono.just(spaceId) - ))) - .delayUntil(function((isolationSegmentId, spaceId) -> requestAssignIsolationSegment(this.cloudFoundryClient, isolationSegmentId, spaceId))) - .flatMapMany(function((isolationSegmentId, spaceId) -> Mono.zip( - Mono.just(spaceId), - this.cloudFoundryClient.isolationSegments() - .listSpacesRelationship(ListIsolationSegmentSpacesRelationshipRequest.builder() - .isolationSegmentId(isolationSegmentId) - .build()) - .map(response -> response.getData().get(0).getId())))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createEntitledIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId), + Mono.just(spaceId)))) + .delayUntil( + function( + (isolationSegmentId, spaceId) -> + requestAssignIsolationSegment( + this.cloudFoundryClient, + isolationSegmentId, + spaceId))) + .flatMapMany( + function( + (isolationSegmentId, spaceId) -> + Mono.zip( + Mono.just(spaceId), + this.cloudFoundryClient + .isolationSegments() + .listSpacesRelationship( + ListIsolationSegmentSpacesRelationshipRequest + .builder() + .isolationSegmentId( + isolationSegmentId) + .build()) + .map( + response -> + response.getData() + .get(0) + .getId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -324,24 +451,43 @@ public void removeOrganizationEntitlement() { String organizationName = this.nameFactory.getOrganizationName(); Mono.zip( - createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName), - createOrganizationId(this.cloudFoundryClient, organizationName) - ) - .delayUntil(function((isolationSegmentId, organizationId) -> requestAddOrganizationEntitlement(this.cloudFoundryClient, isolationSegmentId, organizationId))) - .flatMap(function((isolationSegmentId, organizationId) -> this.cloudFoundryClient.isolationSegments() - .removeOrganizationEntitlement(RemoveIsolationSegmentOrganizationEntitlementRequest.builder() - .isolationSegmentId(isolationSegmentId) - .organizationId(organizationId) - .build()) - .thenReturn(isolationSegmentId))) - .flatMapMany(isolationSegmentId -> PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.isolationSegments() - .listEntitledOrganizations(ListIsolationSegmentEntitledOrganizationsRequest.builder() - .isolationSegmentId(isolationSegmentId) - .build()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName), + createOrganizationId(this.cloudFoundryClient, organizationName)) + .delayUntil( + function( + (isolationSegmentId, organizationId) -> + requestAddOrganizationEntitlement( + this.cloudFoundryClient, + isolationSegmentId, + organizationId))) + .flatMap( + function( + (isolationSegmentId, organizationId) -> + this.cloudFoundryClient + .isolationSegments() + .removeOrganizationEntitlement( + RemoveIsolationSegmentOrganizationEntitlementRequest + .builder() + .isolationSegmentId( + isolationSegmentId) + .organizationId(organizationId) + .build()) + .thenReturn(isolationSegmentId))) + .flatMapMany( + isolationSegmentId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .isolationSegments() + .listEntitledOrganizations( + ListIsolationSegmentEntitledOrganizationsRequest + .builder() + .isolationSegmentId( + isolationSegmentId) + .build()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -350,98 +496,128 @@ public void update() { String isolationSegmentName2 = this.nameFactory.getIsolationSegmentName(); createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName1) - .flatMap(isolationSegmentId -> this.cloudFoundryClient.isolationSegments() - .update(UpdateIsolationSegmentRequest.builder() - .isolationSegmentId(isolationSegmentId) - .name(isolationSegmentName2) - .build())) - .thenMany(requestListIsolationSegments(this.cloudFoundryClient, isolationSegmentName2)) - .map(IsolationSegmentResource::getName) - .as(StepVerifier::create) - .expectNext(isolationSegmentName2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + isolationSegmentId -> + this.cloudFoundryClient + .isolationSegments() + .update( + UpdateIsolationSegmentRequest.builder() + .isolationSegmentId(isolationSegmentId) + .name(isolationSegmentName2) + .build())) + .thenMany( + requestListIsolationSegments( + this.cloudFoundryClient, isolationSegmentName2)) + .map(IsolationSegmentResource::getName) + .as(StepVerifier::create) + .expectNext(isolationSegmentName2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createEntitledIsolationSegmentId(CloudFoundryClient cloudFoundryClient, String isolationSegmentName, String organizationId) { + private static Mono createEntitledIsolationSegmentId( + CloudFoundryClient cloudFoundryClient, + String isolationSegmentName, + String organizationId) { return createIsolationSegmentId(cloudFoundryClient, isolationSegmentName) - .delayUntil(isolationSegmentId -> requestAddIsolationSegmentOrganizationEntitlement(cloudFoundryClient, isolationSegmentId, organizationId)); + .delayUntil( + isolationSegmentId -> + requestAddIsolationSegmentOrganizationEntitlement( + cloudFoundryClient, isolationSegmentId, organizationId)); } - private static Mono createIsolationSegmentId(CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { + private static Mono createIsolationSegmentId( + CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { return requestCreateIsolationSegment(cloudFoundryClient, isolationSegmentName) - .map(CreateIsolationSegmentResponse::getId); + .map(CreateIsolationSegmentResponse::getId); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono requestAddIsolationSegmentOrganizationEntitlement(CloudFoundryClient cloudFoundryClient, String isolationSegmentId, - String organizationId) { - return cloudFoundryClient.isolationSegments() - .addOrganizationEntitlement(AddIsolationSegmentOrganizationEntitlementRequest.builder() - .isolationSegmentId(isolationSegmentId) - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()); + private static Mono + requestAddIsolationSegmentOrganizationEntitlement( + CloudFoundryClient cloudFoundryClient, + String isolationSegmentId, + String organizationId) { + return cloudFoundryClient + .isolationSegments() + .addOrganizationEntitlement( + AddIsolationSegmentOrganizationEntitlementRequest.builder() + .isolationSegmentId(isolationSegmentId) + .data(Relationship.builder().id(organizationId).build()) + .build()); } - private static Mono requestAddOrganizationEntitlement(CloudFoundryClient cloudFoundryClient, String isolationSegmentId, String organizationId) { - return cloudFoundryClient.isolationSegments() - .addOrganizationEntitlement(AddIsolationSegmentOrganizationEntitlementRequest.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .isolationSegmentId(isolationSegmentId) - .build()); + private static Mono + requestAddOrganizationEntitlement( + CloudFoundryClient cloudFoundryClient, + String isolationSegmentId, + String organizationId) { + return cloudFoundryClient + .isolationSegments() + .addOrganizationEntitlement( + AddIsolationSegmentOrganizationEntitlementRequest.builder() + .data(Relationship.builder().id(organizationId).build()) + .isolationSegmentId(isolationSegmentId) + .build()); } - private static Mono requestAssignIsolationSegment(CloudFoundryClient cloudFoundryClient, String isolationSegmentId, String spaceId) { - return cloudFoundryClient.spacesV3() - .assignIsolationSegment(AssignSpaceIsolationSegmentRequest.builder() - .data(Relationship.builder() - .id(isolationSegmentId) - .build()) - .spaceId(spaceId) - .build()); + private static Mono requestAssignIsolationSegment( + CloudFoundryClient cloudFoundryClient, String isolationSegmentId, String spaceId) { + return cloudFoundryClient + .spacesV3() + .assignIsolationSegment( + AssignSpaceIsolationSegmentRequest.builder() + .data(Relationship.builder().id(isolationSegmentId).build()) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateIsolationSegment(CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { - return cloudFoundryClient.isolationSegments() - .create(CreateIsolationSegmentRequest.builder() - .name(isolationSegmentName) - .build()); + private static Mono requestCreateIsolationSegment( + CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { + return cloudFoundryClient + .isolationSegments() + .create(CreateIsolationSegmentRequest.builder().name(isolationSegmentName).build()); } - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizations() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()); + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizations() + .create(CreateOrganizationRequest.builder().name(organizationName).build()); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organizationId(organizationId) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organizationId(organizationId) + .build()); } - private static Flux requestListIsolationSegments(CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.isolationSegments() - .list(ListIsolationSegmentsRequest.builder() - .name(isolationSegmentName) - .page(page) - .build())); + private static Flux requestListIsolationSegments( + CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .isolationSegments() + .list( + ListIsolationSegmentsRequest.builder() + .name(isolationSegmentName) + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/OrganizationsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/OrganizationsTest.java index f5a2cdc3f30..12bc9d106c1 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/OrganizationsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/OrganizationsTest.java @@ -16,6 +16,10 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -45,24 +49,18 @@ import org.cloudfoundry.client.v3.organizations.UpdateOrganizationRequest; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) public final class OrganizationsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; @Test public void assignDefaultIsolationSegment() { @@ -70,40 +68,53 @@ public void assignDefaultIsolationSegment() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createEntitledIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId), - Mono.just(organizationId) - )) - .flatMap(function((isolationSegmentId, organizationId) -> Mono.zip( - Mono.just(isolationSegmentId), - this.cloudFoundryClient.organizationsV3() - .assignDefaultIsolationSegment(AssignOrganizationDefaultIsolationSegmentRequest.builder() - .organizationId(organizationId) - .data(Relationship.builder() - .id(isolationSegmentId) - .build()) - .build()) - .map(r -> r.getData().getId())))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createEntitledIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId), + Mono.just(organizationId))) + .flatMap( + function( + (isolationSegmentId, organizationId) -> + Mono.zip( + Mono.just(isolationSegmentId), + this.cloudFoundryClient + .organizationsV3() + .assignDefaultIsolationSegment( + AssignOrganizationDefaultIsolationSegmentRequest + .builder() + .organizationId( + organizationId) + .data( + Relationship + .builder() + .id( + isolationSegmentId) + .build()) + .build()) + .map(r -> r.getData().getId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void create() { String organizationName = this.nameFactory.getOrganizationName(); - this.cloudFoundryClient.organizationsV3() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()) - .thenMany(requestListOrganizations(this.cloudFoundryClient, organizationName)) - .single() - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .organizationsV3() + .create(CreateOrganizationRequest.builder().name(organizationName).build()) + .thenMany(requestListOrganizations(this.cloudFoundryClient, organizationName)) + .single() + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_8) @@ -112,15 +123,24 @@ public void delete() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.organizationsV3() - .delete(DeleteOrganizationRequest.builder() - .organizationId(organizationId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .thenMany(requestListOrganizations(this.cloudFoundryClient, organizationName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizationsV3() + .delete( + DeleteOrganizationRequest.builder() + .organizationId(organizationId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .thenMany(requestListOrganizations(this.cloudFoundryClient, organizationName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -128,15 +148,19 @@ public void get() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.organizationsV3() - .get(GetOrganizationRequest.builder() - .organizationId(organizationId) - .build())) - .map(GetOrganizationResponse::getName) - .as(StepVerifier::create) - .expectNext(organizationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizationsV3() + .get( + GetOrganizationRequest.builder() + .organizationId(organizationId) + .build())) + .map(GetOrganizationResponse::getName) + .as(StepVerifier::create) + .expectNext(organizationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_7) @@ -145,15 +169,19 @@ public void getDefaultDomain() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.organizationsV3() - .getDefaultDomain(GetOrganizationDefaultDomainRequest.builder() - .organizationId(organizationId) - .build())) - .map(GetOrganizationDefaultDomainResponse::getName) - .as(StepVerifier::create) - .consumeNextWith(name -> assertThat(name).contains("apps.", ".cf-app.com")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizationsV3() + .getDefaultDomain( + GetOrganizationDefaultDomainRequest.builder() + .organizationId(organizationId) + .build())) + .map(GetOrganizationDefaultDomainResponse::getName) + .as(StepVerifier::create) + .consumeNextWith(name -> assertThat(name).contains("apps.", ".cf-app.com")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -162,40 +190,62 @@ public void getDefaultIsolationSegment() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createEntitledIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId), - Mono.just(organizationId) - )) - .delayUntil(function((isolationSegmentId, organizationId) -> requestAssignDefaultIsolationSegment(this.cloudFoundryClient, isolationSegmentId, organizationId))) - .flatMap(function((isolationSegmentId, organizationId) -> Mono.zip( - Mono.just(isolationSegmentId), - this.cloudFoundryClient.organizationsV3() - .getDefaultIsolationSegment(GetOrganizationDefaultIsolationSegmentRequest.builder() - .organizationId(organizationId) - .build()) - .map(r -> r.getData().getId())))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createEntitledIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId), + Mono.just(organizationId))) + .delayUntil( + function( + (isolationSegmentId, organizationId) -> + requestAssignDefaultIsolationSegment( + this.cloudFoundryClient, + isolationSegmentId, + organizationId))) + .flatMap( + function( + (isolationSegmentId, organizationId) -> + Mono.zip( + Mono.just(isolationSegmentId), + this.cloudFoundryClient + .organizationsV3() + .getDefaultIsolationSegment( + GetOrganizationDefaultIsolationSegmentRequest + .builder() + .organizationId( + organizationId) + .build()) + .map(r -> r.getData().getId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_8) @Test public void getUsageSummary() { this.organizationId - .flatMap(organizationId -> this.cloudFoundryClient.organizationsV3() - .getUsageSummary(GetOrganizationUsageSummaryRequest.builder() - .organizationId(organizationId) - .build())) - .map(GetOrganizationUsageSummaryResponse::getUsageSummary) - .as(StepVerifier::create) - .consumeNextWith(usage -> { - assertThat(usage.getMemoryInMb()).isGreaterThan(63); - assertThat(usage.getStartedInstances()).isGreaterThan(0); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizationsV3() + .getUsageSummary( + GetOrganizationUsageSummaryRequest.builder() + .organizationId(organizationId) + .build())) + .map(GetOrganizationUsageSummaryResponse::getUsageSummary) + .as(StepVerifier::create) + .consumeNextWith( + usage -> { + assertThat(usage.getMemoryInMb()).isGreaterThan(63); + assertThat(usage.getStartedInstances()).isGreaterThan(0); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -203,15 +253,20 @@ public void list() { String organizationName = this.nameFactory.getOrganizationName(); requestCreateOrganization(this.cloudFoundryClient, organizationName) - .thenMany(PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.organizationsV3() - .list(ListOrganizationsRequest.builder() - .page(page) - .build()))) - .filter(resource -> organizationName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .organizationsV3() + .list( + ListOrganizationsRequest.builder() + .page(page) + .build()))) + .filter(resource -> organizationName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -221,17 +276,28 @@ public void listDomains() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateDomain(this.cloudFoundryClient, domainName, organizationId)) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.organizationsV3() - .listDomains(ListOrganizationDomainsRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .filter(resource -> domainName.equals(resource.getName())) - .as(StepVerifier::create) - .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateDomain( + this.cloudFoundryClient, domainName, organizationId)) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .organizationsV3() + .listDomains( + ListOrganizationDomainsRequest + .builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .filter(resource -> domainName.equals(resource.getName())) + .as(StepVerifier::create) + .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -241,20 +307,33 @@ public void listDomainsFilterById() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - Mono.just(organizationId) - )) - .flatMapMany(function((domainId, organizationId) -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.organizationsV3() - .listDomains(ListOrganizationDomainsRequest.builder() - .domainId(domainId) - .organizationId(organizationId) - .page(page) - .build())))) - .as(StepVerifier::create) - .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + Mono.just(organizationId))) + .flatMapMany( + function( + (domainId, organizationId) -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .organizationsV3() + .listDomains( + ListOrganizationDomainsRequest + .builder() + .domainId(domainId) + .organizationId( + organizationId) + .page(page) + .build())))) + .as(StepVerifier::create) + .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -264,17 +343,28 @@ public void listDomainsFilterByName() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateDomain(this.cloudFoundryClient, domainName, organizationId)) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.organizationsV3() - .listDomains(ListOrganizationDomainsRequest.builder() - .name(domainName) - .organizationId(organizationId) - .page(page) - .build()))) - .as(StepVerifier::create) - .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateDomain( + this.cloudFoundryClient, domainName, organizationId)) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .organizationsV3() + .listDomains( + ListOrganizationDomainsRequest + .builder() + .name(domainName) + .organizationId( + organizationId) + .page(page) + .build()))) + .as(StepVerifier::create) + .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -285,20 +375,38 @@ public void listDomainsFilterByOwningOrganizationIds() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> Mono.when( - requestCreateDomain(this.cloudFoundryClient, domainName, organizationId), - requestCreateDomain(this.cloudFoundryClient, globalDomainName))) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.organizationsV3() - .listDomains(ListOrganizationDomainsRequest.builder() - .organizationId(organizationId) - .owningOrganizationId(organizationId) - .page(page) - .build()))) - .filter(resource -> domainName.equals(resource.getName()) || globalDomainName.equals(resource.getName())) - .as(StepVerifier::create) - .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + Mono.when( + requestCreateDomain( + this.cloudFoundryClient, + domainName, + organizationId), + requestCreateDomain( + this.cloudFoundryClient, globalDomainName))) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .organizationsV3() + .listDomains( + ListOrganizationDomainsRequest + .builder() + .organizationId( + organizationId) + .owningOrganizationId( + organizationId) + .page(page) + .build()))) + .filter( + resource -> + domainName.equals(resource.getName()) + || globalDomainName.equals(resource.getName())) + .as(StepVerifier::create) + .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_6) @@ -308,17 +416,28 @@ public void listDomainsReturningGlobalDomains() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .delayUntil(organizationId -> requestCreateDomain(this.cloudFoundryClient, globalDomainName)) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.organizationsV3() - .listDomains(ListOrganizationDomainsRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .filter(resource -> globalDomainName.equals(resource.getName())) - .as(StepVerifier::create) - .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(globalDomainName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateDomain(this.cloudFoundryClient, globalDomainName)) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .organizationsV3() + .listDomains( + ListOrganizationDomainsRequest + .builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .filter(resource -> globalDomainName.equals(resource.getName())) + .as(StepVerifier::create) + .consumeNextWith( + resource -> assertThat(resource.getName()).isEqualTo(globalDomainName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -330,23 +449,42 @@ public void listDomainsReturningSharedDomains() { String organizationName2 = this.nameFactory.getOrganizationName(); Mono.zip( - createOrganizationId(this.cloudFoundryClient, organizationName1), - createOrganizationId(this.cloudFoundryClient, organizationName2)) - .flatMap(function((organizationId1, organizationId2) -> Mono - .when( - requestCreateDomain(this.cloudFoundryClient, domainName1, organizationId1), - requestCreateDomain(this.cloudFoundryClient, domainName2, organizationId2)) - .thenReturn(organizationId1))) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.organizationsV3() - .listDomains(ListOrganizationDomainsRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .filter(resource -> domainName1.equals(resource.getName()) || domainName2.equals(resource.getName())) - .as(StepVerifier::create) - .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName1)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createOrganizationId(this.cloudFoundryClient, organizationName1), + createOrganizationId(this.cloudFoundryClient, organizationName2)) + .flatMap( + function( + (organizationId1, organizationId2) -> + Mono.when( + requestCreateDomain( + this.cloudFoundryClient, + domainName1, + organizationId1), + requestCreateDomain( + this.cloudFoundryClient, + domainName2, + organizationId2)) + .thenReturn(organizationId1))) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .organizationsV3() + .listDomains( + ListOrganizationDomainsRequest + .builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .filter( + resource -> + domainName1.equals(resource.getName()) + || domainName2.equals(resource.getName())) + .as(StepVerifier::create) + .consumeNextWith(resource -> assertThat(resource.getName()).isEqualTo(domainName1)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -354,15 +492,20 @@ public void listFilterByName() { String organizationName = this.nameFactory.getOrganizationName(); requestCreateOrganization(this.cloudFoundryClient, organizationName) - .thenMany(PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.organizationsV3() - .list(ListOrganizationsRequest.builder() - .name(organizationName) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .organizationsV3() + .list( + ListOrganizationsRequest.builder() + .name(organizationName) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_8) @@ -371,109 +514,146 @@ public void update() { String organizationName = this.nameFactory.getOrganizationName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.organizationsV3().update(UpdateOrganizationRequest.builder() - .metadata(Metadata.builder() - .annotation("annotationKey", "annotationValue") - .label("labelKey", "labelValue") - .build()) - .organizationId(organizationId) - .build())) - .thenMany(requestListOrganizations(this.cloudFoundryClient, organizationName)) - .map(OrganizationResource::getMetadata) - .as(StepVerifier::create) - .consumeNextWith(metadata -> { - assertThat(metadata.getAnnotations().get("annotationKey")).isEqualTo("annotationValue"); - assertThat(metadata.getLabels().get("labelKey")).isEqualTo("labelValue"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .organizationsV3() + .update( + UpdateOrganizationRequest.builder() + .metadata( + Metadata.builder() + .annotation( + "annotationKey", + "annotationValue") + .label( + "labelKey", + "labelValue") + .build()) + .organizationId(organizationId) + .build())) + .thenMany(requestListOrganizations(this.cloudFoundryClient, organizationName)) + .map(OrganizationResource::getMetadata) + .as(StepVerifier::create) + .consumeNextWith( + metadata -> { + assertThat(metadata.getAnnotations().get("annotationKey")) + .isEqualTo("annotationValue"); + assertThat(metadata.getLabels().get("labelKey")) + .isEqualTo("labelValue"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createDomainId(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + private static Mono createDomainId( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { return requestCreateDomain(cloudFoundryClient, domainName, organizationId) - .map(CreateDomainResponse::getId); + .map(CreateDomainResponse::getId); } - private static Mono createEntitledIsolationSegmentId(CloudFoundryClient cloudFoundryClient, String isolationSegmentName, String organizationId) { + private static Mono createEntitledIsolationSegmentId( + CloudFoundryClient cloudFoundryClient, + String isolationSegmentName, + String organizationId) { return createIsolationSegmentId(cloudFoundryClient, isolationSegmentName) - .delayUntil(isolationSegmentId -> requestAddIsolationSegmentOrganizationEntitlement(cloudFoundryClient, isolationSegmentId, organizationId)); + .delayUntil( + isolationSegmentId -> + requestAddIsolationSegmentOrganizationEntitlement( + cloudFoundryClient, isolationSegmentId, organizationId)); } - private static Mono createIsolationSegmentId(CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { + private static Mono createIsolationSegmentId( + CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { return requestCreateIsolationSegment(cloudFoundryClient, isolationSegmentName) - .map(CreateIsolationSegmentResponse::getId); + .map(CreateIsolationSegmentResponse::getId); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(CreateOrganizationResponse::getId); + .map(CreateOrganizationResponse::getId); } - private static Mono requestAddIsolationSegmentOrganizationEntitlement(CloudFoundryClient cloudFoundryClient, String isolationSegmentId, - String organizationId) { - return cloudFoundryClient.isolationSegments() - .addOrganizationEntitlement(AddIsolationSegmentOrganizationEntitlementRequest.builder() - .isolationSegmentId(isolationSegmentId) - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()); + private static Mono + requestAddIsolationSegmentOrganizationEntitlement( + CloudFoundryClient cloudFoundryClient, + String isolationSegmentId, + String organizationId) { + return cloudFoundryClient + .isolationSegments() + .addOrganizationEntitlement( + AddIsolationSegmentOrganizationEntitlementRequest.builder() + .isolationSegmentId(isolationSegmentId) + .data(Relationship.builder().id(organizationId).build()) + .build()); } - private static Mono requestAssignDefaultIsolationSegment(CloudFoundryClient cloudFoundryClient, String isolationSegmentId, - String organizationId) { - return cloudFoundryClient.organizationsV3() - .assignDefaultIsolationSegment(AssignOrganizationDefaultIsolationSegmentRequest.builder() - .organizationId(organizationId) - .data(Relationship.builder() - .id(isolationSegmentId) - .build()) - .build()); + private static Mono + requestAssignDefaultIsolationSegment( + CloudFoundryClient cloudFoundryClient, + String isolationSegmentId, + String organizationId) { + return cloudFoundryClient + .organizationsV3() + .assignDefaultIsolationSegment( + AssignOrganizationDefaultIsolationSegmentRequest.builder() + .organizationId(organizationId) + .data(Relationship.builder().id(isolationSegmentId).build()) + .build()); } - private static Mono requestCreateDomain(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { - return cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .internal(false) - .name(domainName) - .relationships(DomainRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateDomain( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + return cloudFoundryClient + .domainsV3() + .create( + CreateDomainRequest.builder() + .internal(false) + .name(domainName) + .relationships( + DomainRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCreateDomain(CloudFoundryClient cloudFoundryClient, String domainName) { - return cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .internal(false) - .name(domainName) - .build()); + private static Mono requestCreateDomain( + CloudFoundryClient cloudFoundryClient, String domainName) { + return cloudFoundryClient + .domainsV3() + .create(CreateDomainRequest.builder().internal(false).name(domainName).build()); } - private static Mono requestCreateIsolationSegment(CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { - return cloudFoundryClient.isolationSegments() - .create(CreateIsolationSegmentRequest.builder() - .name(isolationSegmentName) - .build()); + private static Mono requestCreateIsolationSegment( + CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { + return cloudFoundryClient + .isolationSegments() + .create(CreateIsolationSegmentRequest.builder().name(isolationSegmentName).build()); } - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizationsV3() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()); + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizationsV3() + .create(CreateOrganizationRequest.builder().name(organizationName).build()); } - private static Flux requestListOrganizations(CloudFoundryClient cloudFoundryClient, String organizationName) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.organizationsV3() - .list(ListOrganizationsRequest.builder() - .name(organizationName) - .page(page) - .build())); + private static Flux requestListOrganizations( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .organizationsV3() + .list( + ListOrganizationsRequest.builder() + .name(organizationName) + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/PackagesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/PackagesTest.java index 689c1fd8414..967923af843 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/PackagesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/PackagesTest.java @@ -16,82 +16,104 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.client.v3.packages.PackageState.PROCESSING_UPLOAD; +import static org.cloudfoundry.client.v3.packages.PackageState.READY; + +import java.io.IOException; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v3.applications.Application; -import org.cloudfoundry.client.v3.applications.CreateApplicationRequest; import org.cloudfoundry.client.v3.applications.ApplicationRelationships; +import org.cloudfoundry.client.v3.applications.CreateApplicationRequest; import org.cloudfoundry.client.v3.packages.CreatePackageRequest; import org.cloudfoundry.client.v3.packages.GetPackageRequest; import org.cloudfoundry.client.v3.packages.Package; import org.cloudfoundry.client.v3.packages.PackageType; import org.cloudfoundry.client.v3.packages.UploadPackageRequest; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.Exceptions; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.client.v3.packages.PackageState.PROCESSING_UPLOAD; -import static org.cloudfoundry.client.v3.packages.PackageState.READY; - -@Ignore("Until Packages are no longer experimental") +@Disabled("Until Packages are no longer experimental") public final class PackagesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void upload() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> this.cloudFoundryClient.applicationsV3() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .relationships(ApplicationRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build())) - .map(Application::getId) - .flatMap(applicationId -> this.cloudFoundryClient.packages() - .create(CreatePackageRequest.builder() - .type(PackageType.BITS) - .build())) - .map(Package::getId) - .flatMap(packageId -> { - try { - return this.cloudFoundryClient.packages() - .upload(UploadPackageRequest.builder() - .packageId(packageId) - .bits(new ClassPathResource("test-application.zip").getFile().toPath()) - .build()); - } catch (IOException e) { - throw Exceptions.propagate(e); - } - }) - .map(Package::getId) - .flatMap(packageId -> this.cloudFoundryClient.packages() - .get(GetPackageRequest.builder() - .packageId(packageId) - .build())) - .map(Package::getState) - .as(StepVerifier::create) - .consumeNextWith(state -> assertThat(state).isIn(PROCESSING_UPLOAD, READY)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + this.cloudFoundryClient + .applicationsV3() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + spaceId) + .build()) + .build()) + .build()) + .build())) + .map(Application::getId) + .flatMap( + applicationId -> + this.cloudFoundryClient + .packages() + .create( + CreatePackageRequest.builder() + .type(PackageType.BITS) + .build())) + .map(Package::getId) + .flatMap( + packageId -> { + try { + return this.cloudFoundryClient + .packages() + .upload( + UploadPackageRequest.builder() + .packageId(packageId) + .bits( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .build()); + } catch (IOException e) { + throw Exceptions.propagate(e); + } + }) + .map(Package::getId) + .flatMap( + packageId -> + this.cloudFoundryClient + .packages() + .get( + GetPackageRequest.builder() + .packageId(packageId) + .build())) + .map(Package::getState) + .as(StepVerifier::create) + .consumeNextWith(state -> assertThat(state).isIn(PROCESSING_UPLOAD, READY)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ProcessesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ProcessesTest.java index b6500c7d4b3..5b2f10bfb07 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ProcessesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ProcessesTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -41,195 +46,230 @@ import org.cloudfoundry.operations.applications.GetApplicationRequest; import org.cloudfoundry.operations.applications.PushApplicationRequest; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_0) public final class ProcessesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; @Test public void get() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - Path path = new ClassPathResource("test-application.zip").getFile().toPath(); + Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplication(this.cloudFoundryOperations, applicationName, path) - .then(getApplicationId(this.cloudFoundryOperations, applicationName)) - .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) - .flatMap(processId -> this.cloudFoundryClient.processes() - .get(GetProcessRequest.builder() - .processId(processId) - .build())) - .map(GetProcessResponse::getDiskInMb) - .as(StepVerifier::create) - .expectNext(258) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryOperations, applicationName)) + .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) + .flatMap( + processId -> + this.cloudFoundryClient + .processes() + .get( + GetProcessRequest.builder() + .processId(processId) + .build())) + .map(GetProcessResponse::getDiskInMb) + .as(StepVerifier::create) + .expectNext(258) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getStatistics() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - Path path = new ClassPathResource("test-application.zip").getFile().toPath(); + Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplication(this.cloudFoundryOperations, applicationName, path) - .then(getApplicationId(this.cloudFoundryOperations, applicationName)) - .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) - .flatMap(processId -> this.cloudFoundryClient.processes() - .getStatistics(GetProcessStatisticsRequest.builder() - .processId(processId) - .build())) - .flatMapIterable(GetProcessStatisticsResponse::getResources) - .map(ProcessStatisticsResource::getType) - .as(StepVerifier::create) - .expectNext("web") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryOperations, applicationName)) + .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) + .flatMap( + processId -> + this.cloudFoundryClient + .processes() + .getStatistics( + GetProcessStatisticsRequest.builder() + .processId(processId) + .build())) + .flatMapIterable(GetProcessStatisticsResponse::getResources) + .map(ProcessStatisticsResource::getType) + .as(StepVerifier::create) + .expectNext("web") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - Path path = new ClassPathResource("test-application.zip").getFile().toPath(); + Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplication(this.cloudFoundryOperations, applicationName, path) - .then(getApplicationId(this.cloudFoundryOperations, applicationName)) - .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) - .flatMapMany(processId -> PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.processes() - .list(ListProcessesRequest.builder() - .page(page) - .processId(processId) - .build()))) - .map(ProcessResource::getDiskInMb) - .as(StepVerifier::create) - .expectNext(258) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryOperations, applicationName)) + .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) + .flatMapMany( + processId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .processes() + .list( + ListProcessesRequest.builder() + .page(page) + .processId(processId) + .build()))) + .map(ProcessResource::getDiskInMb) + .as(StepVerifier::create) + .expectNext(258) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void scale() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - Path path = new ClassPathResource("test-application.zip").getFile().toPath(); + Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplication(this.cloudFoundryOperations, applicationName, path) - .then(getApplicationId(this.cloudFoundryOperations, applicationName)) - .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) - .flatMap(processId -> this.cloudFoundryClient.processes() - .scale(ScaleProcessRequest.builder() - .diskInMb(259) - .processId(processId) - .build()) - .then(Mono.just(processId))) - .flatMap(processId -> requestGetProcess(this.cloudFoundryClient, processId)) - .map(GetProcessResponse::getDiskInMb) - .as(StepVerifier::create) - .expectNext(259) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryOperations, applicationName)) + .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) + .flatMap( + processId -> + this.cloudFoundryClient + .processes() + .scale( + ScaleProcessRequest.builder() + .diskInMb(259) + .processId(processId) + .build()) + .then(Mono.just(processId))) + .flatMap(processId -> requestGetProcess(this.cloudFoundryClient, processId)) + .map(GetProcessResponse::getDiskInMb) + .as(StepVerifier::create) + .expectNext(259) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void terminateInstance() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - Path path = new ClassPathResource("test-application.zip").getFile().toPath(); + Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplication(this.cloudFoundryOperations, applicationName, path) - .then(getApplicationId(this.cloudFoundryOperations, applicationName)) - .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) - .flatMap(processId -> this.cloudFoundryClient.processes() - .terminateInstance(TerminateProcessInstanceRequest.builder() - .index("1") - .processId(processId) - .build()) - .then(Mono.just(processId))) - .flatMap(processId -> requestGetProcess(this.cloudFoundryClient, processId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV3Exception.class).hasMessageMatching("CF-ResourceNotFound\\([0-9]+\\): Instance not found")) - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryOperations, applicationName)) + .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) + .flatMap( + processId -> + this.cloudFoundryClient + .processes() + .terminateInstance( + TerminateProcessInstanceRequest.builder() + .index("1") + .processId(processId) + .build()) + .then(Mono.just(processId))) + .flatMap(processId -> requestGetProcess(this.cloudFoundryClient, processId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV3Exception.class) + .hasMessageMatching( + "CF-ResourceNotFound\\([0-9]+\\): Instance not" + + " found")) + .verify(Duration.ofMinutes(5)); } @Test public void update() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - Path path = new ClassPathResource("test-application.zip").getFile().toPath(); + Path path = new ClassPathResource("test-application.zip").getFile().toPath(); createApplication(this.cloudFoundryOperations, applicationName, path) - .then(getApplicationId(this.cloudFoundryOperations, applicationName)) - .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) - .flatMap(processId -> this.cloudFoundryClient.processes() - .update(UpdateProcessRequest.builder() - .healthCheck(HealthCheck.builder() - .type(HealthCheckType.PROCESS) - .build()) - .processId(processId) - .build()) - .then(Mono.just(processId))) - .flatMap(processId -> requestGetProcess(this.cloudFoundryClient, processId)) - .map(GetProcessResponse::getHealthCheck) - .map(HealthCheck::getType) - .as(StepVerifier::create) - .expectNext(HealthCheckType.PROCESS) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryOperations, applicationName)) + .flatMap(applicationId -> getProcessId(this.cloudFoundryClient, applicationId)) + .flatMap( + processId -> + this.cloudFoundryClient + .processes() + .update( + UpdateProcessRequest.builder() + .healthCheck( + HealthCheck.builder() + .type( + HealthCheckType + .PROCESS) + .build()) + .processId(processId) + .build()) + .then(Mono.just(processId))) + .flatMap(processId -> requestGetProcess(this.cloudFoundryClient, processId)) + .map(GetProcessResponse::getHealthCheck) + .map(HealthCheck::getType) + .as(StepVerifier::create) + .expectNext(HealthCheckType.PROCESS) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplication(CloudFoundryOperations cloudFoundryOperations, String name, Path path) throws IOException { - return cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diskQuota(258) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(name) - .path(path) - .noStart(false) - .build()); + private static Mono createApplication( + CloudFoundryOperations cloudFoundryOperations, String name, Path path) + throws IOException { + return cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .buildpack("staticfile_buildpack") + .diskQuota(258) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(name) + .path(path) + .noStart(false) + .build()); } - private static Mono getApplicationId(CloudFoundryOperations cloudFoundryOperations, String applicationName) { + private static Mono getApplicationId( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { return requestGetApplication(cloudFoundryOperations, applicationName) - .map(ApplicationDetail::getId); + .map(ApplicationDetail::getId); } - private static Mono getProcessId(CloudFoundryClient cloudFoundryClient, String applicationId) { - return requestGetApplicationProcess(cloudFoundryClient, applicationId) - .map(Process::getId); + private static Mono getProcessId( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return requestGetApplicationProcess(cloudFoundryClient, applicationId).map(Process::getId); } - private static Mono requestGetApplication(CloudFoundryOperations cloudFoundryOperations, String applicationName) { - return cloudFoundryOperations.applications() - .get(GetApplicationRequest.builder() - .name(applicationName) - .build()); + private static Mono requestGetApplication( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { + return cloudFoundryOperations + .applications() + .get(GetApplicationRequest.builder().name(applicationName).build()); } - private static Mono requestGetApplicationProcess(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV3() - .getProcess(GetApplicationProcessRequest.builder() - .applicationId(applicationId) - .type("web") - .build()); + private static Mono requestGetApplicationProcess( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV3() + .getProcess( + GetApplicationProcessRequest.builder() + .applicationId(applicationId) + .type("web") + .build()); } - private static Mono requestGetProcess(CloudFoundryClient cloudFoundryClient, String processId) { - return cloudFoundryClient.processes() - .get(GetProcessRequest.builder() - .processId(processId) - .build()); + private static Mono requestGetProcess( + CloudFoundryClient cloudFoundryClient, String processId) { + return cloudFoundryClient + .processes() + .get(GetProcessRequest.builder().processId(processId).build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ResourceMatchTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ResourceMatchTest.java index 6f847e9b225..4e3c2f1401a 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ResourceMatchTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ResourceMatchTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.DelayUtils.exponentialBackOff; + +import java.io.IOException; +import java.time.Duration; +import java.util.EnumSet; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -34,89 +40,132 @@ import org.cloudfoundry.util.DelayTimeoutException; import org.cloudfoundry.util.ExceptionUtils; import org.cloudfoundry.util.ResourceMatchingUtilsV3; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.Exceptions; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.time.Duration; -import java.util.EnumSet; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.DelayUtils.exponentialBackOff; - public class ResourceMatchTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @Test - @Ignore("Cloud Controller is configured not to cache resource smaller than 4k - Find a better way to test this") + @Disabled( + "Cloud Controller is configured not to cache resource smaller than 4k - Find a better" + + " way to test this") public void upload() throws IOException { createAndUploadPackage() - .flatMap(this::waitForReady) - .then(ResourceMatchingUtilsV3.getMatchedResources(this.cloudFoundryClient, new ClassPathResource("test-application.zip").getFile().toPath())) - .as(StepVerifier::create) - .consumeNextWith(matchedResources -> assertThat(matchedResources).isNotEmpty()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap(this::waitForReady) + .then( + ResourceMatchingUtilsV3.getMatchedResources( + this.cloudFoundryClient, + new ClassPathResource("test-application.zip").getFile().toPath())) + .as(StepVerifier::create) + .consumeNextWith(matchedResources -> assertThat(matchedResources).isNotEmpty()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } private Mono createAndUploadPackage() { String applicationName = this.nameFactory.getApplicationName(); return this.spaceId - .flatMap(spaceId -> this.cloudFoundryClient.applicationsV3() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .relationships(ApplicationRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build())) - .map(Application::getId) - .flatMap(applicationId -> this.cloudFoundryClient.packages() - .create(CreatePackageRequest.builder() - .type(PackageType.BITS) - .relationships(PackageRelationships.builder() - .application(ToOneRelationship.builder() - .data(Relationship.builder() - .id(applicationId) - .build()) - .build()) - .build()) - .build())) - .map(Package::getId) - .flatMap(packageId -> { - try { - return this.cloudFoundryClient.packages() - .upload(UploadPackageRequest.builder() - .packageId(packageId) - .bits(new ClassPathResource("test-application.zip").getFile().toPath()) - .build()); - } catch (IOException e) { - return Mono.error(Exceptions.propagate(e)); - } - }) - .map(Package::getId); + .flatMap( + spaceId -> + this.cloudFoundryClient + .applicationsV3() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + spaceId) + .build()) + .build()) + .build()) + .build())) + .map(Application::getId) + .flatMap( + applicationId -> + this.cloudFoundryClient + .packages() + .create( + CreatePackageRequest.builder() + .type(PackageType.BITS) + .relationships( + PackageRelationships.builder() + .application( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + applicationId) + .build()) + .build()) + .build()) + .build())) + .map(Package::getId) + .flatMap( + packageId -> { + try { + return this.cloudFoundryClient + .packages() + .upload( + UploadPackageRequest.builder() + .packageId(packageId) + .bits( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .build()); + } catch (IOException e) { + return Mono.error(Exceptions.propagate(e)); + } + }) + .map(Package::getId); } private Mono waitForReady(String packageId) { - return this.cloudFoundryClient.packages().get(GetPackageRequest.builder().packageId(packageId).build()) - .filter(packageResponse -> EnumSet.of(PackageState.READY, PackageState.FAILED, PackageState.EXPIRED).contains(packageResponse.getState())) - .repeatWhenEmpty(exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(15), Duration.ofMinutes(5))) - .filter(packageResponse -> packageResponse.getState() == PackageState.READY) - .switchIfEmpty(ExceptionUtils.illegalState("Package %s failed upload processing", packageId)) - .onErrorResume(DelayTimeoutException.class, t -> ExceptionUtils.illegalState("Package %s timed out during upload processing", packageId)); + return this.cloudFoundryClient + .packages() + .get(GetPackageRequest.builder().packageId(packageId).build()) + .filter( + packageResponse -> + EnumSet.of( + PackageState.READY, + PackageState.FAILED, + PackageState.EXPIRED) + .contains(packageResponse.getState())) + .repeatWhenEmpty( + exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(15), + Duration.ofMinutes(5))) + .filter(packageResponse -> packageResponse.getState() == PackageState.READY) + .switchIfEmpty( + ExceptionUtils.illegalState( + "Package %s failed upload processing", packageId)) + .onErrorResume( + DelayTimeoutException.class, + t -> + ExceptionUtils.illegalState( + "Package %s timed out during upload processing", + packageId)); } } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/RolesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/RolesTest.java index a04ae0685e7..251951b5c02 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/RolesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/RolesTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v3; +import static org.cloudfoundry.client.v3.roles.RoleType.ORGANIZATION_USER; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -31,20 +34,16 @@ import org.cloudfoundry.client.v3.roles.RoleResource; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.client.v3.roles.RoleType.ORGANIZATION_USER; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) public final class RolesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; @Test public void create() { @@ -52,37 +51,62 @@ public void create() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> this.cloudFoundryClient.rolesV3() - .create(CreateRoleRequest.builder() - .relationships(RoleRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .user(ToOneRelationship.builder() - .data(Relationship.builder() - .id(userId) - .build()) - .build()) - .build()) - .type(ORGANIZATION_USER) - .build()) - .thenReturn(organizationId)) - .flatMapMany(organizationId -> requestListRoles(this.cloudFoundryClient) - .map(RoleResource::getRelationships) - .filter(relationship -> { - if (relationship.getOrganization().getData() != null) { - return organizationId.equals(relationship.getOrganization().getData().getId()); - } else { - return false; - } - }) - .map(relationship -> relationship.getUser().getData().getId())) - .as(StepVerifier::create) - .expectNext(userId) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .rolesV3() + .create( + CreateRoleRequest.builder() + .relationships( + RoleRelationships.builder() + .organization( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + organizationId) + .build()) + .build()) + .user( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + userId) + .build()) + .build()) + .build()) + .type(ORGANIZATION_USER) + .build()) + .thenReturn(organizationId)) + .flatMapMany( + organizationId -> + requestListRoles(this.cloudFoundryClient) + .map(RoleResource::getRelationships) + .filter( + relationship -> { + if (relationship.getOrganization().getData() + != null) { + return organizationId.equals( + relationship + .getOrganization() + .getData() + .getId()); + } else { + return false; + } + }) + .map( + relationship -> + relationship.getUser().getData().getId())) + .as(StepVerifier::create) + .expectNext(userId) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -91,18 +115,29 @@ public void delete() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateOrganizationRelationship(this.cloudFoundryClient, organizationId, userId) - .map(CreateRoleResponse::getId)) - .delayUntil(roleId -> this.cloudFoundryClient.rolesV3() - .delete(DeleteRoleRequest.builder() - .roleId(roleId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .flatMapMany(roleId -> requestListRoles(this.cloudFoundryClient) - .filter(resource -> roleId.equals(resource.getId()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateOrganizationRelationship( + this.cloudFoundryClient, organizationId, userId) + .map(CreateRoleResponse::getId)) + .delayUntil( + roleId -> + this.cloudFoundryClient + .rolesV3() + .delete(DeleteRoleRequest.builder().roleId(roleId).build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .flatMapMany( + roleId -> + requestListRoles(this.cloudFoundryClient) + .filter(resource -> roleId.equals(resource.getId()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -111,17 +146,26 @@ public void get() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateOrganizationRelationship(this.cloudFoundryClient, organizationId, userId) - .map(CreateRoleResponse::getId)) - .flatMap(roleId -> this.cloudFoundryClient.rolesV3() - .get(GetRoleRequest.builder() - .roleId(roleId) - .build()) - .map(response -> response.getRelationships().getUser().getData().getId())) - .as(StepVerifier::create) - .expectNext(userId) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateOrganizationRelationship( + this.cloudFoundryClient, organizationId, userId) + .map(CreateRoleResponse::getId)) + .flatMap( + roleId -> + this.cloudFoundryClient + .rolesV3() + .get(GetRoleRequest.builder().roleId(roleId).build()) + .map( + response -> + response.getRelationships() + .getUser() + .getData() + .getId())) + .as(StepVerifier::create) + .expectNext(userId) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -130,58 +174,79 @@ public void listFilterByOrganizationId() { String userId = this.nameFactory.getUserId(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> requestCreateOrganizationRelationship(this.cloudFoundryClient, organizationId, userId) - .map(CreateRoleResponse::getId)) - .flatMapMany(roleId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.rolesV3() - .list(ListRolesRequest.builder() - .roleId(roleId) - .page(page) - .build())) - .map(resource -> resource.getRelationships().getUser().getData().getId())) - .as(StepVerifier::create) - .expectNext(userId) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateOrganizationRelationship( + this.cloudFoundryClient, organizationId, userId) + .map(CreateRoleResponse::getId)) + .flatMapMany( + roleId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .rolesV3() + .list( + ListRolesRequest.builder() + .roleId(roleId) + .page(page) + .build())) + .map( + resource -> + resource.getRelationships() + .getUser() + .getData() + .getId())) + .as(StepVerifier::create) + .expectNext(userId) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(CreateOrganizationResponse::getId); + .map(CreateOrganizationResponse::getId); } - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizationsV3() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()); + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizationsV3() + .create(CreateOrganizationRequest.builder().name(organizationName).build()); } - private static Mono requestCreateOrganizationRelationship(CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { - return cloudFoundryClient.rolesV3() - .create(CreateRoleRequest.builder() - .relationships(RoleRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .user(ToOneRelationship.builder() - .data(Relationship.builder() - .id(userId) - .build()) - .build()) - .build()) - .type(ORGANIZATION_USER) - .build()); + private static Mono requestCreateOrganizationRelationship( + CloudFoundryClient cloudFoundryClient, String organizationId, String userId) { + return cloudFoundryClient + .rolesV3() + .create( + CreateRoleRequest.builder() + .relationships( + RoleRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .user( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(userId) + .build()) + .build()) + .build()) + .type(ORGANIZATION_USER) + .build()); } private static Flux requestListRoles(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils.requestClientV3Resources(page -> - cloudFoundryClient.rolesV3() - .list(ListRolesRequest.builder() - .page(page) - .build())); + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .rolesV3() + .list(ListRolesRequest.builder().page(page).build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/RoutesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/RoutesTest.java index 5f7545a1011..d3f5bf4ff64 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/RoutesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/RoutesTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v3; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.Collections; +import java.util.List; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -48,27 +53,19 @@ import org.cloudfoundry.client.v3.spaces.CreateSpaceResponse; import org.cloudfoundry.client.v3.spaces.SpaceRelationships; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.Collections; -import java.util.List; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class RoutesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @Test @@ -76,37 +73,59 @@ public void create() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> - this.cloudFoundryClient.routesV3() - .create(CreateRouteRequest.builder() - .metadata(Metadata.builder() - .label("test-create-key", "test-create-value") - .build()) - .relationships(RouteRelationships.builder() - .domain(ToOneRelationship.builder() - .data(Relationship.builder() - .id(domainId) - .build()) - .build()) - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()) - .thenReturn(domainId))) - .flatMapMany(domainId -> requestListRoutes(this.cloudFoundryClient, domainId)) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-create-key", "test-create-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + this.cloudFoundryClient + .routesV3() + .create( + CreateRouteRequest.builder() + .metadata( + Metadata.builder() + .label( + "test-create-key", + "test-create-value") + .build()) + .relationships( + RouteRelationships.builder() + .domain( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + domainId) + .build()) + .build()) + .space( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + spaceId) + .build()) + .build()) + .build()) + .build()) + .thenReturn(domainId))) + .flatMapMany(domainId -> requestListRoutes(this.cloudFoundryClient, domainId)) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-create-key", "test-create-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -115,22 +134,30 @@ public void get() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> createRouteId(this.cloudFoundryClient, domainId, "get", spaceId))) - .flatMapMany(routeId -> - this.cloudFoundryClient.routesV3() - .get(GetRouteRequest.builder() - .routeId(routeId) - .build())) - .map(GetRouteResponse::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-get-key", "test-get-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + createRouteId( + this.cloudFoundryClient, domainId, "get", spaceId))) + .flatMapMany( + routeId -> + this.cloudFoundryClient + .routesV3() + .get(GetRouteRequest.builder().routeId(routeId).build())) + .map(GetRouteResponse::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-get-key", "test-get-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -141,33 +168,55 @@ public void insertDestinations() { Integer port = this.nameFactory.getPort(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, "insertDestinations", spaceId) - ))) - .flatMapMany(function((applicationId, domainId, routeId) -> this.cloudFoundryClient.routesV3() - .insertDestinations(InsertRouteDestinationsRequest.builder() - .destination(Destination.builder() - .application(Application.builder() - .applicationId(applicationId) - .build()) - .port(port) - .build()) - .routeId(routeId) - .build()) - .thenReturn(domainId))) - .flatMap(domainId -> requestListRoutes(this.cloudFoundryClient, domainId)) - .flatMapIterable(RouteResource::getDestinations) - .map(Destination::getPort) - .as(StepVerifier::create) - .expectNext(port) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + "insertDestinations", + spaceId)))) + .flatMapMany( + function( + (applicationId, domainId, routeId) -> + this.cloudFoundryClient + .routesV3() + .insertDestinations( + InsertRouteDestinationsRequest.builder() + .destination( + Destination.builder() + .application( + Application + .builder() + .applicationId( + applicationId) + .build()) + .port(port) + .build()) + .routeId(routeId) + .build()) + .thenReturn(domainId))) + .flatMap(domainId -> requestListRoutes(this.cloudFoundryClient, domainId)) + .flatMapIterable(RouteResource::getDestinations) + .map(Destination::getPort) + .as(StepVerifier::create) + .expectNext(port) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -176,26 +225,41 @@ public void list() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> createRouteId(this.cloudFoundryClient, domainId, "list", spaceId))) - .thenMany(PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .page(page) - .build()))) - .filter(route -> route.getMetadata().getLabels().containsKey("test-list-key")) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-list-key", "test-list-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - //TODO: Test has not been validated + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + createRouteId( + this.cloudFoundryClient, + domainId, + "list", + spaceId))) + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .page(page) + .build()))) + .filter(route -> route.getMetadata().getLabels().containsKey("test-list-key")) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-list-key", "test-list-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + // TODO: Test has not been validated @IfCloudFoundryVersion(greaterThan = CloudFoundryVersion.PCF_2_9) @Test public void listByApplicationId() { @@ -203,28 +267,55 @@ public void listByApplicationId() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - createRouteId(this.cloudFoundryClient, domainId, "listByApplicationId", spaceId) - ))) - .flatMapMany(function((applicationId, routeId) -> requestReplaceDestinations(this.cloudFoundryClient, applicationId, routeId) - .thenReturn(applicationId))) - .flatMap(applicationId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .applicationId(applicationId) - .page(page) - .build()))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listByApplicationId-key", "test-listByApplicationId-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + createRouteId( + this.cloudFoundryClient, + domainId, + "listByApplicationId", + spaceId)))) + .flatMapMany( + function( + (applicationId, routeId) -> + requestReplaceDestinations( + this.cloudFoundryClient, + applicationId, + routeId) + .thenReturn(applicationId))) + .flatMap( + applicationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .applicationId( + applicationId) + .page(page) + .build()))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listByApplicationId-key", "test-listByApplicationId-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -233,24 +324,42 @@ public void listByDomain() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, "listByDomain", spaceId) - .thenReturn(domainId))) - .flatMapMany(domainId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .domainId(domainId) - .page(page) - .build()))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listByDomain-key", "test-listByDomain-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + "listByDomain", + spaceId) + .thenReturn(domainId))) + .flatMapMany( + domainId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .domainId(domainId) + .page(page) + .build()))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listByDomain-key", "test-listByDomain-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -260,24 +369,43 @@ public void listByHost() { String hostName = this.nameFactory.getHostName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, hostName, "listByHost", null, null, spaceId))) - .thenMany(PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .host(hostName) - .page(page) - .build()))) - .filter(route -> route.getMetadata().getLabels().containsKey("test-listByHost-key")) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listByHost-key", "test-listByHost-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + hostName, + "listByHost", + null, + null, + spaceId))) + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .host(hostName) + .page(page) + .build()))) + .filter(route -> route.getMetadata().getLabels().containsKey("test-listByHost-key")) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap("test-listByHost-key", "test-listByHost-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -287,24 +415,46 @@ public void listByLabelSelector() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, "listByLabelSelector", spaceId) - .thenReturn(domainId))) - .flatMapMany(domainId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .labelSelector("test-listByLabelSelector-key=test-listByLabelSelector-value") - .page(page) - .build()))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listByLabelSelector-key", "test-listByLabelSelector-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + "listByLabelSelector", + spaceId) + .thenReturn(domainId))) + .flatMapMany( + domainId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .labelSelector( + "test-listByLabelSelector-key=test-listByLabelSelector-value") + .page(page) + .build()))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listByLabelSelector-key", "test-listByLabelSelector-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -315,25 +465,47 @@ public void listByOrganizationId() { String spaceName = this.nameFactory.getSpaceName(); createOrganizationId(this.cloudFoundryClient, organizationName) - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - Mono.just(organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((domainId, organizationId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, "listByOrganizationId", spaceId) - .thenReturn(organizationId))) - .flatMapMany(organizationId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listByOrganizationId-key", "test-listByOrganizationId-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + Mono.just(organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (domainId, organizationId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + "listByOrganizationId", + spaceId) + .thenReturn(organizationId))) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listByOrganizationId-key", "test-listByOrganizationId-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -343,24 +515,43 @@ public void listByPath() { String path = this.nameFactory.getPath(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> requestCreateRoute(this.cloudFoundryClient, domainId, null, "listByPath", path, null, spaceId))) - .thenMany(PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .path(path) - .page(page) - .build()))) - .filter(route -> route.getMetadata().getLabels().containsKey("test-listByPath-key")) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listByPath-key", "test-listByPath-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + requestCreateRoute( + this.cloudFoundryClient, + domainId, + null, + "listByPath", + path, + null, + spaceId))) + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .path(path) + .page(page) + .build()))) + .filter(route -> route.getMetadata().getLabels().containsKey("test-listByPath-key")) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap("test-listByPath-key", "test-listByPath-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -370,25 +561,50 @@ public void listBySpaceId() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName) - )) - .flatMap(function((domainId, spaceId) -> createRouteId(this.cloudFoundryClient, domainId, "listBySpaceId", spaceId) - .thenReturn(spaceId))) - .flatMapMany(spaceId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .page(page) - .spaceId(spaceId) - .build()))) - .filter(route -> route.getMetadata().getLabels().containsKey("test-listBySpaceId-key")) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-listBySpaceId-key", "test-listBySpaceId-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (domainId, spaceId) -> + createRouteId( + this.cloudFoundryClient, + domainId, + "listBySpaceId", + spaceId) + .thenReturn(spaceId))) + .flatMapMany( + spaceId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .page(page) + .spaceId(spaceId) + .build()))) + .filter( + route -> + route.getMetadata() + .getLabels() + .containsKey("test-listBySpaceId-key")) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-listBySpaceId-key", "test-listBySpaceId-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -398,32 +614,60 @@ public void listDestinations() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, "removeDestinations", spaceId) - ))) - .flatMapMany(function((applicationId, domainId, routeId) -> Mono.zip( - Mono.just(applicationId), - createDestinationId(this.cloudFoundryClient, applicationId, routeId), - Mono.just(routeId) - ))) - .flatMap(function((applicationId, ignore, routeId) -> Mono.zip( - Mono.just(applicationId), - this.cloudFoundryClient.routesV3() - .listDestinations(ListRouteDestinationsRequest.builder() - .routeId(routeId) - .build()) - .map(response -> response.getDestinations().get(0).getApplication().getApplicationId())) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + "removeDestinations", + spaceId)))) + .flatMapMany( + function( + (applicationId, domainId, routeId) -> + Mono.zip( + Mono.just(applicationId), + createDestinationId( + this.cloudFoundryClient, + applicationId, + routeId), + Mono.just(routeId)))) + .flatMap( + function( + (applicationId, ignore, routeId) -> + Mono.zip( + Mono.just(applicationId), + this.cloudFoundryClient + .routesV3() + .listDestinations( + ListRouteDestinationsRequest + .builder() + .routeId(routeId) + .build()) + .map( + response -> + response.getDestinations() + .get(0) + .getApplication() + .getApplicationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -433,33 +677,61 @@ public void listDestinationsByApplicationId() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, "removeDestinations", spaceId) - ))) - .flatMapMany(function((applicationId, domainId, routeId) -> Mono.zip( - Mono.just(applicationId), - createDestinationId(this.cloudFoundryClient, applicationId, routeId), - Mono.just(routeId) - ))) - .flatMap(function((applicationId, destinationId, routeId) -> Mono.zip( - Mono.just(destinationId), - this.cloudFoundryClient.routesV3() - .listDestinations(ListRouteDestinationsRequest.builder() - .applicationId(applicationId) - .routeId(routeId) - .build()) - .map(response -> response.getDestinations().get(0).getDestinationId())) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + "removeDestinations", + spaceId)))) + .flatMapMany( + function( + (applicationId, domainId, routeId) -> + Mono.zip( + Mono.just(applicationId), + createDestinationId( + this.cloudFoundryClient, + applicationId, + routeId), + Mono.just(routeId)))) + .flatMap( + function( + (applicationId, destinationId, routeId) -> + Mono.zip( + Mono.just(destinationId), + this.cloudFoundryClient + .routesV3() + .listDestinations( + ListRouteDestinationsRequest + .builder() + .applicationId( + applicationId) + .routeId(routeId) + .build()) + .map( + response -> + response.getDestinations() + .get(0) + .getDestinationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -469,33 +741,62 @@ public void listDestinationsById() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, "removeDestinations", spaceId) - ))) - .flatMapMany(function((applicationId, domainId, routeId) -> Mono.zip( - Mono.just(applicationId), - createDestinationId(this.cloudFoundryClient, applicationId, routeId), - Mono.just(routeId) - ))) - .flatMap(function((applicationId, destinationId, routeId) -> Mono.zip( - Mono.just(applicationId), - this.cloudFoundryClient.routesV3() - .listDestinations(ListRouteDestinationsRequest.builder() - .destinationId(destinationId) - .routeId(routeId) - .build()) - .map(response -> response.getDestinations().get(0).getApplication().getApplicationId())) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + "removeDestinations", + spaceId)))) + .flatMapMany( + function( + (applicationId, domainId, routeId) -> + Mono.zip( + Mono.just(applicationId), + createDestinationId( + this.cloudFoundryClient, + applicationId, + routeId), + Mono.just(routeId)))) + .flatMap( + function( + (applicationId, destinationId, routeId) -> + Mono.zip( + Mono.just(applicationId), + this.cloudFoundryClient + .routesV3() + .listDestinations( + ListRouteDestinationsRequest + .builder() + .destinationId( + destinationId) + .routeId(routeId) + .build()) + .map( + response -> + response.getDestinations() + .get(0) + .getApplication() + .getApplicationId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -505,31 +806,54 @@ public void removeDestinations() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, "removeDestinations", spaceId) - ))) - .flatMapMany(function((applicationId, domainId, routeId) -> Mono.zip( - createDestinationId(this.cloudFoundryClient, applicationId, routeId), - Mono.just(routeId) - ))) - .flatMap(function((destinationId, routeId) -> this.cloudFoundryClient.routesV3() - .removeDestinations(RemoveRouteDestinationsRequest.builder() - .destinationId(destinationId) - .routeId(routeId) - .build()) - .thenReturn(routeId))) - .flatMap(routeId -> getDestinations(this.cloudFoundryClient, routeId)) - .map(List::size) - .as(StepVerifier::create) - .expectNext(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + "removeDestinations", + spaceId)))) + .flatMapMany( + function( + (applicationId, domainId, routeId) -> + Mono.zip( + createDestinationId( + this.cloudFoundryClient, + applicationId, + routeId), + Mono.just(routeId)))) + .flatMap( + function( + (destinationId, routeId) -> + this.cloudFoundryClient + .routesV3() + .removeDestinations( + RemoveRouteDestinationsRequest.builder() + .destinationId(destinationId) + .routeId(routeId) + .build()) + .thenReturn(routeId))) + .flatMap(routeId -> getDestinations(this.cloudFoundryClient, routeId)) + .map(List::size) + .as(StepVerifier::create) + .expectNext(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -540,33 +864,55 @@ public void replaceDestinations() { Integer port = this.nameFactory.getPort(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - createApplicationId(this.cloudFoundryClient, applicationName, spaceId), - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, "insertDestinations", spaceId) - ))) - .flatMapMany(function((applicationId, domainId, routeId) -> this.cloudFoundryClient.routesV3() - .replaceDestinations(ReplaceRouteDestinationsRequest.builder() - .destination(Destination.builder() - .application(Application.builder() - .applicationId(applicationId) - .build()) - .port(port) - .build()) - .routeId(routeId) - .build()) - .thenReturn(domainId))) - .flatMap(domainId -> requestListRoutes(this.cloudFoundryClient, domainId)) - .flatMapIterable(RouteResource::getDestinations) - .map(Destination::getPort) - .as(StepVerifier::create) - .expectNext(port) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + applicationName, + spaceId), + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + "insertDestinations", + spaceId)))) + .flatMapMany( + function( + (applicationId, domainId, routeId) -> + this.cloudFoundryClient + .routesV3() + .replaceDestinations( + ReplaceRouteDestinationsRequest.builder() + .destination( + Destination.builder() + .application( + Application + .builder() + .applicationId( + applicationId) + .build()) + .port(port) + .build()) + .routeId(routeId) + .build()) + .thenReturn(domainId))) + .flatMap(domainId -> requestListRoutes(this.cloudFoundryClient, domainId)) + .flatMapIterable(RouteResource::getDestinations) + .map(Destination::getPort) + .as(StepVerifier::create) + .expectNext(port) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) @@ -575,195 +921,266 @@ public void update() { String domainName = this.nameFactory.getDomainName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - this.spaceId - )) - .flatMap(function((domainId, spaceId) -> Mono.zip( - Mono.just(domainId), - createRouteId(this.cloudFoundryClient, domainId, "update", spaceId)) - )) - .delayUntil(function((domainId, routeId) -> - this.cloudFoundryClient.routesV3() - .update(UpdateRouteRequest.builder() - .routeId(routeId) - .metadata(Metadata.builder() - .label("test-update-key", "test-update-value") - .build()) - .build()))) - .flatMapMany(function((domainId, ignore) -> requestListRoutes(this.cloudFoundryClient, domainId))) - .map(RouteResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-update-key", "test-update-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + this.spaceId)) + .flatMap( + function( + (domainId, spaceId) -> + Mono.zip( + Mono.just(domainId), + createRouteId( + this.cloudFoundryClient, + domainId, + "update", + spaceId)))) + .delayUntil( + function( + (domainId, routeId) -> + this.cloudFoundryClient + .routesV3() + .update( + UpdateRouteRequest.builder() + .routeId(routeId) + .metadata( + Metadata.builder() + .label( + "test-update-key", + "test-update-value") + .build()) + .build()))) + .flatMapMany( + function( + (domainId, ignore) -> + requestListRoutes(this.cloudFoundryClient, domainId))) + .map(RouteResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-update-key", "test-update-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, applicationName, spaceId) - .map(CreateApplicationResponse::getId); + .map(CreateApplicationResponse::getId); } - private static Mono createDestinationId(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + private static Mono createDestinationId( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { return requestReplaceDestinations(cloudFoundryClient, applicationId, routeId) - .flatMapIterable(ReplaceRouteDestinationsResponse::getDestinations) - .single() - .map(Destination::getDestinationId); + .flatMapIterable(ReplaceRouteDestinationsResponse::getDestinations) + .single() + .map(Destination::getDestinationId); } - private static Mono createDomainId(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + private static Mono createDomainId( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { return requestCreateDomain(cloudFoundryClient, domainName, organizationId) - .map(CreateDomainResponse::getId); + .map(CreateDomainResponse::getId); } - private static Mono createOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { + private static Mono createOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { return requestCreateOrganization(cloudFoundryClient, organizationName) - .map(CreateOrganizationResponse::getId); + .map(CreateOrganizationResponse::getId); } - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { return requestCreateRoute(cloudFoundryClient, domainId, label, spaceId) - .map(CreateRouteResponse::getId); + .map(CreateRouteResponse::getId); } - private static Mono> getDestinations(CloudFoundryClient cloudFoundryClient, String routeId) { + private static Mono> getDestinations( + CloudFoundryClient cloudFoundryClient, String routeId) { return requestListDestinations(cloudFoundryClient, routeId) - .map(ListRouteDestinationsResponse::getDestinations); - } - - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { - return cloudFoundryClient.applicationsV3() - .create(CreateApplicationRequest.builder() - .name(applicationName) - .relationships(ApplicationRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); - } - - private static Mono requestCreateDomain(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { - return cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .internal(false) - .name(domainName) - .relationships(DomainRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); - } - - private static Mono requestCreateOrganization(CloudFoundryClient cloudFoundryClient, String organizationName) { - return cloudFoundryClient.organizationsV3() - .create(CreateOrganizationRequest.builder() - .name(organizationName) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String host, String label, String path, Integer port, String spaceId) { + .map(ListRouteDestinationsResponse::getDestinations); + } + + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + return cloudFoundryClient + .applicationsV3() + .create( + CreateApplicationRequest.builder() + .name(applicationName) + .relationships( + ApplicationRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); + } + + private static Mono requestCreateDomain( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + return cloudFoundryClient + .domainsV3() + .create( + CreateDomainRequest.builder() + .internal(false) + .name(domainName) + .relationships( + DomainRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); + } + + private static Mono requestCreateOrganization( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return cloudFoundryClient + .organizationsV3() + .create(CreateOrganizationRequest.builder().name(organizationName).build()); + } + + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, + String domainId, + String host, + String label, + String path, + Integer port, + String spaceId) { String key = String.format("test-%s-key", label); String value = String.format("test-%s-value", label); - return cloudFoundryClient.routesV3() - .create(CreateRouteRequest.builder() - .host(host) - .metadata(Metadata.builder() - .label(key, value) - .build()) - .path(path) - .port(port) - .relationships(RouteRelationships.builder() - .domain(ToOneRelationship.builder() - .data(Relationship.builder() - .id(domainId) - .build()) - .build()) - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { + return cloudFoundryClient + .routesV3() + .create( + CreateRouteRequest.builder() + .host(host) + .metadata(Metadata.builder().label(key, value).build()) + .path(path) + .port(port) + .relationships( + RouteRelationships.builder() + .domain( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(domainId) + .build()) + .build()) + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); + } + + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { String key = String.format("test-%s-key", label); String value = String.format("test-%s-value", label); - return cloudFoundryClient.routesV3() - .create(CreateRouteRequest.builder() - .metadata(Metadata.builder() - .label(key, value) - .build()) - .relationships(RouteRelationships.builder() - .domain(ToOneRelationship.builder() - .data(Relationship.builder() - .id(domainId) - .build()) - .build()) - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); - } - - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); - } - - private static Mono requestListDestinations(CloudFoundryClient cloudFoundryClient, String routeId) { - return cloudFoundryClient.routesV3() - .listDestinations(ListRouteDestinationsRequest.builder() - .routeId(routeId) - .build()); - } - - private static Flux requestListRoutes(CloudFoundryClient cloudFoundryClient, String domainId) { - return PaginationUtils.requestClientV3Resources(page -> - cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .domainId(domainId) - .page(page) - .build())); - } - - private static Mono requestReplaceDestinations(CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { - return cloudFoundryClient.routesV3() - .replaceDestinations(ReplaceRouteDestinationsRequest.builder() - .destination(Destination.builder() - .application(Application.builder() - .applicationId(applicationId) - .build()) - .build()) - .routeId(routeId) - .build()); - } - - private Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(CreateSpaceResponse::getId); + return cloudFoundryClient + .routesV3() + .create( + CreateRouteRequest.builder() + .metadata(Metadata.builder().label(key, value).build()) + .relationships( + RouteRelationships.builder() + .domain( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(domainId) + .build()) + .build()) + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); + } + + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); + } + + private static Mono requestListDestinations( + CloudFoundryClient cloudFoundryClient, String routeId) { + return cloudFoundryClient + .routesV3() + .listDestinations(ListRouteDestinationsRequest.builder().routeId(routeId).build()); + } + + private static Flux requestListRoutes( + CloudFoundryClient cloudFoundryClient, String domainId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .domainId(domainId) + .page(page) + .build())); } + private static Mono requestReplaceDestinations( + CloudFoundryClient cloudFoundryClient, String applicationId, String routeId) { + return cloudFoundryClient + .routesV3() + .replaceDestinations( + ReplaceRouteDestinationsRequest.builder() + .destination( + Destination.builder() + .application( + Application.builder() + .applicationId(applicationId) + .build()) + .build()) + .routeId(routeId) + .build()); + } + + private Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) + .map(CreateSpaceResponse::getId); + } } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/SecurityGroupsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/SecurityGroupsTest.java new file mode 100644 index 00000000000..2b8a0d4be1f --- /dev/null +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/SecurityGroupsTest.java @@ -0,0 +1,302 @@ +/* + * Copyright 2013-2023 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + +package org.cloudfoundry.client.v3; + +import static org.cloudfoundry.client.v3.securitygroups.Protocol.TCP; + +import java.time.Duration; +import java.util.Arrays; +import org.cloudfoundry.AbstractIntegrationTest; +import org.cloudfoundry.client.CloudFoundryClient; +import org.cloudfoundry.client.v3.securitygroups.BindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.BindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.CreateSecurityGroupResponse; +import org.cloudfoundry.client.v3.securitygroups.DeleteSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GetSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.GloballyEnabled; +import org.cloudfoundry.client.v3.securitygroups.ListRunningSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.ListStagingSecurityGroupsRequest; +import org.cloudfoundry.client.v3.securitygroups.Rule; +import org.cloudfoundry.client.v3.securitygroups.UnbindRunningSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UnbindStagingSecurityGroupRequest; +import org.cloudfoundry.client.v3.securitygroups.UpdateSecurityGroupRequest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import reactor.core.publisher.Mono; +import reactor.test.StepVerifier; + +public final class SecurityGroupsTest extends AbstractIntegrationTest { + + @Autowired private CloudFoundryClient cloudFoundryClient; + + @Autowired private Mono spaceId; + private Mono securityGroup; + private String securityGroupName; + + @BeforeEach + public void setup() { + this.securityGroupName = this.nameFactory.getSecurityGroupName(); + + this.securityGroup = + this.cloudFoundryClient + .securityGroupsV3() + .create( + CreateSecurityGroupRequest.builder() + .name(this.securityGroupName) + .globallyEnabled( + GloballyEnabled.builder() + .staging(true) + .running(true) + .build()) + .rule( + Rule.builder() + .destination("0.0.0.0/0") + .log(false) + .ports("2048-3000") + .protocol(TCP) + .build()) + .build()); + } + + @Test + public void create() { + this.securityGroup + .map(securityGroup -> securityGroup.getName()) + .as(StepVerifier::create) + .expectNext(this.securityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void get() { + this.securityGroup + .flatMap( + securityGroup -> + this.cloudFoundryClient + .securityGroupsV3() + .get( + GetSecurityGroupRequest.builder() + .securityGroupId(securityGroup.getId()) + .build()) + .map(sg -> sg.getName())) + .as(StepVerifier::create) + .expectNext(this.securityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void update() { + String newSecurityGroupName = this.nameFactory.getSecurityGroupName(); + this.securityGroup + .flatMap( + securityGroup -> + this.cloudFoundryClient + .securityGroupsV3() + .update( + UpdateSecurityGroupRequest.builder() + .globallyEnabled( + GloballyEnabled.builder().build()) + .securityGroupId(securityGroup.getId()) + .name(newSecurityGroupName) + .build())) + .map(securityGroup -> securityGroup.getName()) + .as(StepVerifier::create) + .expectNext(newSecurityGroupName) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void delete() { + this.securityGroup + .flatMap( + securityGroup -> + this.cloudFoundryClient + .securityGroupsV3() + .delete( + DeleteSecurityGroupRequest.builder() + .securityGroupId(securityGroup.getId()) + .build()) + .map(id -> Arrays.asList(id))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void list() { + this.securityGroup + .map( + securityGroup -> + this.cloudFoundryClient + .securityGroupsV3() + .list( + ListSecurityGroupsRequest.builder() + .names( + Arrays.asList( + securityGroup.getName())) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void listRunning() { + Mono.zip(this.securityGroup, this.spaceId) + .flatMap( + v -> + this.cloudFoundryClient + .securityGroupsV3() + .listRunning( + ListRunningSecurityGroupsRequest.builder() + .spaceId(v.getT2()) + .names(Arrays.asList(v.getT1().getName())) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void listStaging() { + Mono.zip(this.securityGroup, this.spaceId) + .flatMap( + v -> + this.cloudFoundryClient + .securityGroupsV3() + .listStaging( + ListStagingSecurityGroupsRequest.builder() + .spaceId(v.getT2()) + .names(Arrays.asList(v.getT1().getName())) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void bindStagingSecurityGroup() { + Mono.zip(this.securityGroup, this.spaceId) + .flatMap( + v -> + this.cloudFoundryClient + .securityGroupsV3() + .bindStagingSecurityGroup( + BindStagingSecurityGroupRequest.builder() + .securityGroupId(v.getT1().getId()) + .boundSpaces( + Relationship.builder() + .id(v.getT2()) + .build()) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void unbindStagingSecurityGroup() { + Mono.zip(this.securityGroup, this.spaceId) + .flatMap( + v -> + this.cloudFoundryClient + .securityGroupsV3() + .bindStagingSecurityGroup( + BindStagingSecurityGroupRequest.builder() + .securityGroupId(v.getT1().getId()) + .boundSpaces( + Relationship.builder() + .id(v.getT2()) + .build()) + .build()) + .then( + this.cloudFoundryClient + .securityGroupsV3() + .unbindStagingSecurityGroup( + UnbindStagingSecurityGroupRequest + .builder() + .securityGroupId( + v.getT1().getId()) + .spaceId(v.getT2()) + .build()))) + .as(StepVerifier::create) + .expectNextCount(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void bindRunningSecurityGroup() { + Mono.zip(this.securityGroup, this.spaceId) + .flatMap( + v -> + this.cloudFoundryClient + .securityGroupsV3() + .bindRunningSecurityGroup( + BindRunningSecurityGroupRequest.builder() + .securityGroupId(v.getT1().getId()) + .boundSpaces( + Relationship.builder() + .id(v.getT2()) + .build()) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + @Test + public void unbindRunningSecurityGroup() { + Mono.zip(this.securityGroup, this.spaceId) + .flatMap( + v -> + this.cloudFoundryClient + .securityGroupsV3() + .bindRunningSecurityGroup( + BindRunningSecurityGroupRequest.builder() + .securityGroupId(v.getT1().getId()) + .boundSpaces( + Relationship.builder() + .id(v.getT2()) + .build()) + .build()) + .then( + this.cloudFoundryClient + .securityGroupsV3() + .unbindRunningSecurityGroup( + UnbindRunningSecurityGroupRequest + .builder() + .securityGroupId( + v.getT1().getId()) + .spaceId(v.getT2()) + .build()))) + .as(StepVerifier::create) + .expectNextCount(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } +} diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceBindingsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceBindingsTest.java index 96ee53685d6..81477aef522 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceBindingsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceBindingsTest.java @@ -16,57 +16,53 @@ package org.cloudfoundry.client.v3; +import static org.cloudfoundry.client.v3.ApplicationsTest.createApplicationId; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.Collections; +import java.util.Map; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; import org.cloudfoundry.client.CloudFoundryClient; +import org.cloudfoundry.client.v3.servicebindings.CreateServiceBindingRequest; import org.cloudfoundry.client.v3.servicebindings.DeleteServiceBindingRequest; import org.cloudfoundry.client.v3.servicebindings.GetServiceBindingDetailsRequest; import org.cloudfoundry.client.v3.servicebindings.GetServiceBindingDetailsResponse; import org.cloudfoundry.client.v3.servicebindings.GetServiceBindingRequest; -import org.cloudfoundry.client.v3.servicebindings.ListServiceBindingsResponse; -import org.cloudfoundry.client.v3.serviceinstances.CreateServiceInstanceRequest; -import org.cloudfoundry.client.v3.serviceinstances.CreateServiceInstanceResponse; -import org.cloudfoundry.client.v3.serviceplans.ListServicePlansRequest; -import org.cloudfoundry.client.v3.servicebindings.CreateServiceBindingRequest; import org.cloudfoundry.client.v3.servicebindings.ListServiceBindingsRequest; +import org.cloudfoundry.client.v3.servicebindings.ListServiceBindingsResponse; import org.cloudfoundry.client.v3.servicebindings.ServiceBinding; import org.cloudfoundry.client.v3.servicebindings.ServiceBindingRelationships; import org.cloudfoundry.client.v3.servicebindings.ServiceBindingResource; import org.cloudfoundry.client.v3.servicebindings.ServiceBindingType; +import org.cloudfoundry.client.v3.serviceinstances.CreateServiceInstanceRequest; +import org.cloudfoundry.client.v3.serviceinstances.CreateServiceInstanceResponse; import org.cloudfoundry.client.v3.serviceinstances.ListServiceInstancesRequest; import org.cloudfoundry.client.v3.serviceinstances.ServiceInstance; import org.cloudfoundry.client.v3.serviceinstances.ServiceInstanceRelationships; import org.cloudfoundry.client.v3.serviceinstances.ServiceInstanceType; +import org.cloudfoundry.client.v3.serviceplans.ListServicePlansRequest; import org.cloudfoundry.client.v3.serviceplans.ServicePlan; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.Collections; -import java.util.Map; - -import static org.cloudfoundry.client.v3.ApplicationsTest.createApplicationId; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_11) public class ServiceBindingsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void createServiceKeyFromManagedServiceInstance() { @@ -74,28 +70,50 @@ public void createServiceKeyFromManagedServiceInstance() { String serviceKeyName = this.nameFactory.getServiceKeyName(); this.spaceId - .flatMap(spaceId -> createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceBindingsV3() - .create(CreateServiceBindingRequest.builder() - .type(ServiceBindingType.KEY) - .name(serviceKeyName) - .relationships(ServiceBindingRelationships.builder() - .serviceInstance(ToOneRelationship.builder() - .data(Relationship.builder() - .id(serviceInstanceId) - .build()) - .build()) - .build()) - .build()) - .map(response -> response.getJobId() - .get()) - .flatMap(jobId -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), jobId))) - .thenMany(requestListServiceBindings(this.cloudFoundryClient, serviceInstanceName)) - .map(ServiceBinding::getName) - .as(StepVerifier::create) - .expectNext(serviceKeyName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceBindingsV3() + .create( + CreateServiceBindingRequest.builder() + .type(ServiceBindingType.KEY) + .name(serviceKeyName) + .relationships( + ServiceBindingRelationships + .builder() + .serviceInstance( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + serviceInstanceId) + .build()) + .build()) + .build()) + .build()) + .map(response -> response.getJobId().get()) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + jobId))) + .thenMany(requestListServiceBindings(this.cloudFoundryClient, serviceInstanceName)) + .map(ServiceBinding::getName) + .as(StepVerifier::create) + .expectNext(serviceKeyName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -104,37 +122,67 @@ public void createAppBindingFromUserProvidedServiceInstance() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createUserProvidedServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, Collections.emptyMap(), spaceId), - createApplicationId(this.cloudFoundryClient, applicationName, spaceId) - )) - .flatMap(function((serviceInstanceId, appId) -> this.cloudFoundryClient.serviceBindingsV3() - .create(CreateServiceBindingRequest.builder() - .type(ServiceBindingType.APPLICATION) - .metadata(Metadata.builder() - .label("test-label", "test-label-value") - .build()) - .relationships(ServiceBindingRelationships.builder() - .serviceInstance(ToOneRelationship.builder() - .data(Relationship.builder() - .id(serviceInstanceId) - .build()) - .build()) - .application(ToOneRelationship.builder() - .data(Relationship.builder() - .id(appId) - .build()) - .build()) - .build()) - .build()) - .map(response -> response.getServiceBinding() - .get()))) - .map(ServiceBindingResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-label", "test-label-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + Collections.emptyMap(), + spaceId), + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId))) + .flatMap( + function( + (serviceInstanceId, appId) -> + this.cloudFoundryClient + .serviceBindingsV3() + .create( + CreateServiceBindingRequest.builder() + .type( + ServiceBindingType + .APPLICATION) + .metadata( + Metadata.builder() + .label( + "test-label", + "test-label-value") + .build()) + .relationships( + ServiceBindingRelationships + .builder() + .serviceInstance( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + serviceInstanceId) + .build()) + .build()) + .application( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + appId) + .build()) + .build()) + .build()) + .build()) + .map( + response -> + response.getServiceBinding() + .get()))) + .map(ServiceBindingResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-label", "test-label-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -143,18 +191,35 @@ public void deleteForManagedService() { String serviceKeyName = this.nameFactory.getServiceKeyName(); this.spaceId - .flatMap(spaceId -> createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> createServiceKey(this.cloudFoundryClient, serviceKeyName, serviceInstanceName, serviceInstanceId)) - .map(ServiceBinding::getId) - .flatMap(bindingId -> this.cloudFoundryClient.serviceBindingsV3() - .delete(DeleteServiceBindingRequest.builder() - .serviceBindingId(bindingId) - .build())) - .hasElement() - .as(StepVerifier::create) - .expectNext(true) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + createServiceKey( + this.cloudFoundryClient, + serviceKeyName, + serviceInstanceName, + serviceInstanceId)) + .map(ServiceBinding::getId) + .flatMap( + bindingId -> + this.cloudFoundryClient + .serviceBindingsV3() + .delete( + DeleteServiceBindingRequest.builder() + .serviceBindingId(bindingId) + .build())) + .hasElement() + .as(StepVerifier::create) + .expectNext(true) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -163,21 +228,35 @@ public void deleteForUserProvidedService() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createUserProvidedServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, Collections.emptyMap(), spaceId), - createApplicationId(this.cloudFoundryClient, applicationName, spaceId) - )) - .flatMap(function((serviceInstanceId, appId) -> createServiceBindingForUserProvidedService(this.cloudFoundryClient, appId, serviceInstanceId))) - .map(ServiceBinding::getId) - .flatMap(bindingId -> this.cloudFoundryClient.serviceBindingsV3() - .delete(DeleteServiceBindingRequest.builder() - .serviceBindingId(bindingId) - .build())) - .hasElement() - .as(StepVerifier::create) - .expectNext(false) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + Collections.emptyMap(), + spaceId), + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId))) + .flatMap( + function( + (serviceInstanceId, appId) -> + createServiceBindingForUserProvidedService( + this.cloudFoundryClient, appId, serviceInstanceId))) + .map(ServiceBinding::getId) + .flatMap( + bindingId -> + this.cloudFoundryClient + .serviceBindingsV3() + .delete( + DeleteServiceBindingRequest.builder() + .serviceBindingId(bindingId) + .build())) + .hasElement() + .as(StepVerifier::create) + .expectNext(false) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -186,20 +265,33 @@ public void listForApplication() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createUserProvidedServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, Collections.emptyMap(), spaceId), - createApplicationId(this.cloudFoundryClient, applicationName, spaceId) - )) - .flatMap(function((serviceInstanceId, appId) -> createServiceBindingForUserProvidedService(this.cloudFoundryClient, appId, serviceInstanceId))) - .thenMany(this.cloudFoundryClient.serviceBindingsV3() - .list(ListServiceBindingsRequest.builder() - .appName(applicationName) - .build())) - .map(ListServiceBindingsResponse::getResources) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + Collections.emptyMap(), + spaceId), + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId))) + .flatMap( + function( + (serviceInstanceId, appId) -> + createServiceBindingForUserProvidedService( + this.cloudFoundryClient, appId, serviceInstanceId))) + .thenMany( + this.cloudFoundryClient + .serviceBindingsV3() + .list( + ListServiceBindingsRequest.builder() + .appName(applicationName) + .build())) + .map(ListServiceBindingsResponse::getResources) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -208,22 +300,36 @@ public void get() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createUserProvidedServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, Collections.emptyMap(), spaceId), - createApplicationId(this.cloudFoundryClient, applicationName, spaceId) - )) - .flatMap(function((serviceInstanceId, appId) -> createServiceBindingForUserProvidedService(this.cloudFoundryClient, appId, serviceInstanceId))) - .map(ServiceBinding::getId) - .flatMap(bindingId -> this.cloudFoundryClient.serviceBindingsV3() - .get(GetServiceBindingRequest.builder() - .serviceBindingId(bindingId) - .build())) - .map(ServiceBinding::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-label", "test-label-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + Collections.emptyMap(), + spaceId), + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId))) + .flatMap( + function( + (serviceInstanceId, appId) -> + createServiceBindingForUserProvidedService( + this.cloudFoundryClient, appId, serviceInstanceId))) + .map(ServiceBinding::getId) + .flatMap( + bindingId -> + this.cloudFoundryClient + .serviceBindingsV3() + .get( + GetServiceBindingRequest.builder() + .serviceBindingId(bindingId) + .build())) + .map(ServiceBinding::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-label", "test-label-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -232,152 +338,235 @@ public void getDetails() { String applicationName = this.nameFactory.getApplicationName(); this.spaceId - .flatMap(spaceId -> Mono.zip( - createUserProvidedServiceInstanceId(this.cloudFoundryClient, serviceInstanceName, Collections.singletonMap("foo", "bar"), spaceId), - createApplicationId(this.cloudFoundryClient, applicationName, spaceId) - )) - .flatMap(function((serviceInstanceId, appId) -> createServiceBindingForUserProvidedService(this.cloudFoundryClient, appId, serviceInstanceId))) - .map(ServiceBinding::getId) - .flatMap(bindingId -> this.cloudFoundryClient.serviceBindingsV3() - .getDetails(GetServiceBindingDetailsRequest.builder() - .serviceBindingId(bindingId) - .build())) - .map(GetServiceBindingDetailsResponse::getCredentials) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("foo", "bar")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + Mono.zip( + createUserProvidedServiceInstanceId( + this.cloudFoundryClient, + serviceInstanceName, + Collections.singletonMap("foo", "bar"), + spaceId), + createApplicationId( + this.cloudFoundryClient, applicationName, spaceId))) + .flatMap( + function( + (serviceInstanceId, appId) -> + createServiceBindingForUserProvidedService( + this.cloudFoundryClient, appId, serviceInstanceId))) + .map(ServiceBinding::getId) + .flatMap( + bindingId -> + this.cloudFoundryClient + .serviceBindingsV3() + .getDetails( + GetServiceBindingDetailsRequest.builder() + .serviceBindingId(bindingId) + .build())) + .map(GetServiceBindingDetailsResponse::getCredentials) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("foo", "bar")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createManagedServiceInstanceId(CloudFoundryClient cloudFoundryClient, Mono serviceBrokerId, String serviceInstanceName, String serviceName, String spaceId) { + private static Mono createManagedServiceInstanceId( + CloudFoundryClient cloudFoundryClient, + Mono serviceBrokerId, + String serviceInstanceName, + String serviceName, + String spaceId) { return serviceBrokerId - .flatMap(brokerId -> getPlanId(cloudFoundryClient, brokerId, serviceName)) - .flatMap(planId -> requestCreateManagedServiceInstance(cloudFoundryClient, planId, serviceInstanceName, spaceId)) - .map(response -> response.getJobId() - .get()) - .flatMap(jobId -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), jobId)) - .thenMany(requestListServiceInstances(cloudFoundryClient, serviceInstanceName)) - .single() - .map(ServiceInstance::getId); + .flatMap(brokerId -> getPlanId(cloudFoundryClient, brokerId, serviceName)) + .flatMap( + planId -> + requestCreateManagedServiceInstance( + cloudFoundryClient, planId, serviceInstanceName, spaceId)) + .map(response -> response.getJobId().get()) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + cloudFoundryClient, Duration.ofMinutes(5), jobId)) + .thenMany(requestListServiceInstances(cloudFoundryClient, serviceInstanceName)) + .single() + .map(ServiceInstance::getId); } - private static Mono getPlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + private static Mono getPlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { return requestListServicePlans(cloudFoundryClient, serviceName, serviceBrokerId) - .single() - .map(ServicePlan::getId); + .single() + .map(ServicePlan::getId); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceName, String serviceBrokerId) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.servicePlansV3() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceOfferingName(serviceName) - .serviceBrokerId(serviceBrokerId) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceName, String serviceBrokerId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .servicePlansV3() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceOfferingName(serviceName) + .serviceBrokerId(serviceBrokerId) + .build())); } - private static Mono requestCreateManagedServiceInstance(CloudFoundryClient cloudFoundryClient, String planId, String serviceInstanceName, String spaceId) { - return cloudFoundryClient.serviceInstancesV3() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .type(ServiceInstanceType.MANAGED) - .relationships(ServiceInstanceRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .servicePlan(ToOneRelationship.builder() - .data(Relationship.builder() - .id(planId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateManagedServiceInstance( + CloudFoundryClient cloudFoundryClient, + String planId, + String serviceInstanceName, + String spaceId) { + return cloudFoundryClient + .serviceInstancesV3() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .type(ServiceInstanceType.MANAGED) + .relationships( + ServiceInstanceRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .servicePlan( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(planId) + .build()) + .build()) + .build()) + .build()); } - private static Mono createUserProvidedServiceInstanceId(CloudFoundryClient cloudFoundryClient, String serviceInstanceName, Map credentials, String spaceId) { - return requestCreateUserProvidedServiceInstance(cloudFoundryClient, serviceInstanceName, credentials, spaceId) - .map(response -> response.getServiceInstance() - .get()) - .map(ServiceInstance::getId); + private static Mono createUserProvidedServiceInstanceId( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceName, + Map credentials, + String spaceId) { + return requestCreateUserProvidedServiceInstance( + cloudFoundryClient, serviceInstanceName, credentials, spaceId) + .map(response -> response.getServiceInstance().get()) + .map(ServiceInstance::getId); } - private static Mono requestCreateUserProvidedServiceInstance(CloudFoundryClient cloudFoundryClient, String serviceInstanceName, Map credentials, - String spaceId) { - return cloudFoundryClient.serviceInstancesV3() - .create(CreateServiceInstanceRequest.builder() - .type(ServiceInstanceType.USER_PROVIDED) - .name(serviceInstanceName) - .credentials(credentials) - .relationships(ServiceInstanceRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateUserProvidedServiceInstance( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceName, + Map credentials, + String spaceId) { + return cloudFoundryClient + .serviceInstancesV3() + .create( + CreateServiceInstanceRequest.builder() + .type(ServiceInstanceType.USER_PROVIDED) + .name(serviceInstanceName) + .credentials(credentials) + .relationships( + ServiceInstanceRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); } - private static Flux requestListServiceInstances(CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.serviceInstancesV3() - .list(ListServiceInstancesRequest.builder() - .page(page) - .serviceInstanceName(serviceInstanceName) - .build())); + private static Flux requestListServiceInstances( + CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .serviceInstancesV3() + .list( + ListServiceInstancesRequest.builder() + .page(page) + .serviceInstanceName(serviceInstanceName) + .build())); } - private static Flux requestListServiceBindings(CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.serviceBindingsV3() - .list(ListServiceBindingsRequest.builder() - .page(page) - .serviceInstanceName(serviceInstanceName) - .build())); + private static Flux requestListServiceBindings( + CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .serviceBindingsV3() + .list( + ListServiceBindingsRequest.builder() + .page(page) + .serviceInstanceName(serviceInstanceName) + .build())); } - private static Mono createServiceKey(CloudFoundryClient cloudFoundryClient, String serviceKeyName, String serviceInstanceName, String serviceInstanceId) { - return cloudFoundryClient.serviceBindingsV3() - .create(CreateServiceBindingRequest.builder() - .type(ServiceBindingType.KEY) - .name(serviceKeyName) - .relationships(ServiceBindingRelationships.builder() - .serviceInstance(ToOneRelationship.builder() - .data(Relationship.builder() - .id(serviceInstanceId) - .build()) - .build()) - .build()) - .build()) - .map(response -> response.getJobId() - .get()) - .flatMap(jobId -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), jobId)) - .thenMany(requestListServiceBindings(cloudFoundryClient, serviceInstanceName)) - .single(); + private static Mono createServiceKey( + CloudFoundryClient cloudFoundryClient, + String serviceKeyName, + String serviceInstanceName, + String serviceInstanceId) { + return cloudFoundryClient + .serviceBindingsV3() + .create( + CreateServiceBindingRequest.builder() + .type(ServiceBindingType.KEY) + .name(serviceKeyName) + .relationships( + ServiceBindingRelationships.builder() + .serviceInstance( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id( + serviceInstanceId) + .build()) + .build()) + .build()) + .build()) + .map(response -> response.getJobId().get()) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + cloudFoundryClient, Duration.ofMinutes(5), jobId)) + .thenMany(requestListServiceBindings(cloudFoundryClient, serviceInstanceName)) + .single(); } - private static Mono createServiceBindingForUserProvidedService(CloudFoundryClient cloudFoundryClient, String appId, String serviceInstanceId) { - return cloudFoundryClient.serviceBindingsV3() - .create(CreateServiceBindingRequest.builder() - .type(ServiceBindingType.APPLICATION) - .metadata(Metadata.builder() - .label("test-label", "test-label-value") - .build()) - .relationships(ServiceBindingRelationships.builder() - .serviceInstance(ToOneRelationship.builder() - .data(Relationship.builder() - .id(serviceInstanceId) - .build()) - .build()) - .application(ToOneRelationship.builder() - .data(Relationship.builder() - .id(appId) - .build()) - .build()) - .build()) - .build()) - .map(response -> response.getServiceBinding() - .get()); + private static Mono createServiceBindingForUserProvidedService( + CloudFoundryClient cloudFoundryClient, String appId, String serviceInstanceId) { + return cloudFoundryClient + .serviceBindingsV3() + .create( + CreateServiceBindingRequest.builder() + .type(ServiceBindingType.APPLICATION) + .metadata( + Metadata.builder() + .label("test-label", "test-label-value") + .build()) + .relationships( + ServiceBindingRelationships.builder() + .serviceInstance( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id( + serviceInstanceId) + .build()) + .build()) + .application( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(appId) + .build()) + .build()) + .build()) + .build()) + .map(response -> response.getServiceBinding().get()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceBrokersTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceBrokersTest.java index 2dcb88e463c..f7c063c4456 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceBrokersTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceBrokersTest.java @@ -16,6 +16,13 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; +import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; + +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.ApplicationUtils; import org.cloudfoundry.CloudFoundryVersion; @@ -34,34 +41,23 @@ import org.cloudfoundry.client.v3.spaces.SpaceRelationships; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.Exceptions; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; -import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_10) public final class ServiceBrokersTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceBrokerName; + @Autowired private String serviceBrokerName; @Test public void create() { @@ -77,42 +73,69 @@ public void create() { throw Exceptions.propagate(e); } - ApplicationUtils.ApplicationMetadata applicationMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> ServiceBrokerUtils.pushServiceBrokerApplication(this.cloudFoundryClient, application, this.nameFactory, planName, serviceName, spaceId)) - .block(Duration.ofMinutes(5)); + ApplicationUtils.ApplicationMetadata applicationMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + ServiceBrokerUtils.pushServiceBrokerApplication( + this.cloudFoundryClient, + application, + this.nameFactory, + planName, + serviceName, + spaceId)) + .block(Duration.ofMinutes(5)); - this.cloudFoundryClient.serviceBrokersV3() - .create(CreateServiceBrokerRequest.builder() - .authentication(BasicAuthentication.builder() - .password("test-authentication-password") - .username("test-authentication-username") - .build()) - .url(applicationMetadata.uri) - .name(serviceBrokerName) - .relationships(ServiceBrokerRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(applicationMetadata.spaceId) - .build()) - .build()) - .build()) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .then(PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.serviceBrokersV3() - .list(ListServiceBrokersRequest.builder() - .name(serviceBrokerName) - .page(page) - .build())) - .singleOrEmpty()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .serviceBrokersV3() + .create( + CreateServiceBrokerRequest.builder() + .authentication( + BasicAuthentication.builder() + .password("test-authentication-password") + .username("test-authentication-username") + .build()) + .url(applicationMetadata.uri) + .name(serviceBrokerName) + .relationships( + ServiceBrokerRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id( + applicationMetadata + .spaceId) + .build()) + .build()) + .build()) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .then( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .serviceBrokersV3() + .list( + ListServiceBrokersRequest.builder() + .name(serviceBrokerName) + .page(page) + .build())) + .singleOrEmpty()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); deleteServiceBroker(this.cloudFoundryClient, applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .block(Duration.ofMinutes(5)); } @Test @@ -122,56 +145,90 @@ public void delete() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); - this.cloudFoundryClient.serviceBrokersV3() - .delete(DeleteServiceBrokerRequest.builder() - .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .then(PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.serviceBrokersV3() - .list(ListServiceBrokersRequest.builder() - .name(serviceBrokerName) - .page(page) - .build())) - .singleOrEmpty()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .serviceBrokersV3() + .delete( + DeleteServiceBrokerRequest.builder() + .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .then( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .serviceBrokersV3() + .list( + ListServiceBrokersRequest.builder() + .name(serviceBrokerName) + .page(page) + .build())) + .singleOrEmpty()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test public void get() { this.serviceBrokerId - .flatMap(serviceBrokerId -> this.cloudFoundryClient.serviceBrokersV3() - .get(GetServiceBrokerRequest.builder() - .serviceBrokerId(serviceBrokerId) - .build())) - .as(StepVerifier::create) - .assertNext(serviceBroker -> assertThat(serviceBroker.getName()).isEqualTo(this.serviceBrokerName)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + this.cloudFoundryClient + .serviceBrokersV3() + .get( + GetServiceBrokerRequest.builder() + .serviceBrokerId(serviceBrokerId) + .build())) + .as(StepVerifier::create) + .assertNext( + serviceBroker -> + assertThat(serviceBroker.getName()) + .isEqualTo(this.serviceBrokerName)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { - PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.serviceBrokersV3() - .list(ListServiceBrokersRequest.builder() - .name(this.serviceBrokerName) - .page(page) - .build())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .serviceBrokersV3() + .list( + ListServiceBrokersRequest.builder() + .name(this.serviceBrokerName) + .page(page) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -182,33 +239,57 @@ public void update() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName1, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName1, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); - this.cloudFoundryClient.serviceBrokersV3() - .update(UpdateServiceBrokerRequest.builder() - .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) - .name(serviceBrokerName2) - .build()) - .filter(responseUpdate -> responseUpdate.jobId().isPresent()) - .map(responseUpdate -> responseUpdate.jobId().get()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .then(PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.serviceBrokersV3() - .list(ListServiceBrokersRequest.builder() - .name(serviceBrokerName2) - .page(page) - .build())) - .singleOrEmpty()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .serviceBrokersV3() + .update( + UpdateServiceBrokerRequest.builder() + .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) + .name(serviceBrokerName2) + .build()) + .filter(responseUpdate -> responseUpdate.jobId().isPresent()) + .map(responseUpdate -> responseUpdate.jobId().get()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .then( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .serviceBrokersV3() + .list( + ListServiceBrokersRequest.builder() + .name(serviceBrokerName2) + .page(page) + .build())) + .singleOrEmpty()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -218,53 +299,83 @@ public void updateMetadata() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); - this.cloudFoundryClient.serviceBrokersV3() - .update(UpdateServiceBrokerRequest.builder() - .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) - .metadata(Metadata.builder().label("type", "dev").build()) - .build()) - .filter(responseUpdate -> responseUpdate.jobId().isPresent()) - .map(responseUpdate -> responseUpdate.jobId().get()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .then(PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.serviceBrokersV3() - .list(ListServiceBrokersRequest.builder() - .labelSelector("type=dev") - .name(serviceBrokerName) - .page(page) - .build())) - .singleOrEmpty()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .serviceBrokersV3() + .update( + UpdateServiceBrokerRequest.builder() + .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) + .metadata(Metadata.builder().label("type", "dev").build()) + .build()) + .filter(responseUpdate -> responseUpdate.jobId().isPresent()) + .map(responseUpdate -> responseUpdate.jobId().get()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, Duration.ofMinutes(5), job)) + .then( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .serviceBrokersV3() + .list( + ListServiceBrokersRequest.builder() + .labelSelector("type=dev") + .name(serviceBrokerName) + .page(page) + .build())) + .singleOrEmpty()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(CreateSpaceResponse::getId); + .map(CreateSpaceResponse::getId); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java index 27ad2ffe1b2..507b288a653 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceInstancesTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.client.v3; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -44,50 +50,50 @@ import org.cloudfoundry.client.v3.spaces.SpaceRelationships; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.HashMap; -import java.util.Map; -import java.util.Optional; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_1) public final class ServiceInstancesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @Test public void createManagedServiceInstance() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstancesV3() - .get(GetServiceInstanceRequest.builder() - .serviceInstanceId(serviceInstanceId) - .build())) - .filter(resource -> serviceInstanceName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstancesV3() + .get( + GetServiceInstanceRequest.builder() + .serviceInstanceId(serviceInstanceId) + .build())) + .filter(resource -> serviceInstanceName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -96,80 +102,131 @@ public void getUserProvidedServiceCredentials() { Map credentials = new HashMap<>(); credentials.put("foo", "bar"); this.spaceId - .flatMap(spaceId -> createUserProvidedServiceInstance(this.cloudFoundryClient, serviceInstanceName, credentials, spaceId)) - .map(getServiceInstanceResponse -> getServiceInstanceResponse.getServiceInstance().get().getId()) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstancesV3() - .getUserProvidedCredentials(GetUserProvidedCredentialsRequest.builder() - .serviceInstanceId(serviceInstanceId) - .build())) - .filter(resource -> credentials.equals(resource.getCredentials())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createUserProvidedServiceInstance( + this.cloudFoundryClient, + serviceInstanceName, + credentials, + spaceId)) + .map( + getServiceInstanceResponse -> + getServiceInstanceResponse.getServiceInstance().get().getId()) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstancesV3() + .getUserProvidedCredentials( + GetUserProvidedCredentialsRequest.builder() + .serviceInstanceId(serviceInstanceId) + .build())) + .filter(resource -> credentials.equals(resource.getCredentials())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void delete() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstancesV3() - .get(GetServiceInstanceRequest.builder() - .serviceInstanceId(serviceInstanceId) - .build())) - .filter(resource -> serviceInstanceName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstancesV3() + .get( + GetServiceInstanceRequest.builder() + .serviceInstanceId(serviceInstanceId) + .build())) + .filter(resource -> serviceInstanceName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); this.spaceId - .flatMap(spaceId -> deleteServiceInstanceByName(this.cloudFoundryClient, serviceInstanceName, spaceId)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + deleteServiceInstanceByName( + this.cloudFoundryClient, serviceInstanceName, spaceId)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void update() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .flatMap(serviceInstanceId -> this.cloudFoundryClient.serviceInstancesV3() - .get(GetServiceInstanceRequest.builder() - .serviceInstanceId(serviceInstanceId) - .build())) - .filter(resource -> serviceInstanceName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .flatMap( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstancesV3() + .get( + GetServiceInstanceRequest.builder() + .serviceInstanceId(serviceInstanceId) + .build())) + .filter(resource -> serviceInstanceName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); this.spaceId - .flatMap(spaceId -> updateServiceInstanceByName(this.cloudFoundryClient, serviceInstanceName, spaceId)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + updateServiceInstanceByName( + this.cloudFoundryClient, serviceInstanceName, spaceId)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.spaceId - .flatMap(spaceId -> createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName, spaceId)) - .thenMany(PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.serviceInstancesV3() - .list(ListServiceInstancesRequest.builder() - .page(page) - .build()))) - .filter(resource -> serviceInstanceName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + spaceId -> + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName, + spaceId)) + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .serviceInstancesV3() + .list( + ListServiceInstancesRequest.builder() + .page(page) + .build()))) + .filter(resource -> serviceInstanceName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -178,21 +235,42 @@ public void listSharedSpaces() { String spaceName = this.nameFactory.getSpaceName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName + "-shareable", spaceId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - )) - .flatMap(function((serviceInstanceId, newSpaceId) -> requestShareServiceInstance(this.cloudFoundryClient, newSpaceId, serviceInstanceId) - .then(Mono.just(serviceInstanceId)))) - .flatMapMany(serviceInstanceId -> this.cloudFoundryClient.serviceInstancesV3() - .listSharedSpacesRelationship(ListSharedSpacesRelationshipRequest.builder() - .serviceInstanceId(serviceInstanceId) - .build()) - .flatMapIterable(ListSharedSpacesRelationshipResponse::getData)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName + "-shareable", + spaceId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName)))) + .flatMap( + function( + (serviceInstanceId, newSpaceId) -> + requestShareServiceInstance( + this.cloudFoundryClient, + newSpaceId, + serviceInstanceId) + .then(Mono.just(serviceInstanceId)))) + .flatMapMany( + serviceInstanceId -> + this.cloudFoundryClient + .serviceInstancesV3() + .listSharedSpacesRelationship( + ListSharedSpacesRelationshipRequest.builder() + .serviceInstanceId(serviceInstanceId) + .build()) + .flatMapIterable( + ListSharedSpacesRelationshipResponse::getData)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -201,26 +279,48 @@ public void share() { String spaceName = this.nameFactory.getSpaceName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName + "-shareable", spaceId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - )) - .flatMapMany(function((serviceInstanceId, newSpaceId) -> Mono.zip( - Mono.just(newSpaceId), - this.cloudFoundryClient.serviceInstancesV3() - .share(ShareServiceInstanceRequest.builder() - .data(Relationship.builder() - .id(newSpaceId) - .build()) - .serviceInstanceId(serviceInstanceId) - .build()) - .flatMapIterable(ShareServiceInstanceResponse::getData) - .map(Relationship::getId) - .next()))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName + "-shareable", + spaceId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName)))) + .flatMapMany( + function( + (serviceInstanceId, newSpaceId) -> + Mono.zip( + Mono.just(newSpaceId), + this.cloudFoundryClient + .serviceInstancesV3() + .share( + ShareServiceInstanceRequest + .builder() + .data( + Relationship + .builder() + .id( + newSpaceId) + .build()) + .serviceInstanceId( + serviceInstanceId) + .build()) + .flatMapIterable( + ShareServiceInstanceResponse + ::getData) + .map(Relationship::getId) + .next()))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -229,183 +329,284 @@ public void unshare() { String spaceName = this.nameFactory.getSpaceName(); Mono.zip(this.organizationId, this.spaceId) - .flatMap(function((organizationId, spaceId) -> Mono.zip( - createManagedServiceInstanceId(this.cloudFoundryClient, this.serviceBrokerId, serviceInstanceName, this.serviceName + "-shareable", spaceId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - )) - .delayUntil(function((serviceInstanceId, newSpaceId) -> requestShareServiceInstance(this.cloudFoundryClient, newSpaceId, serviceInstanceId))) - .delayUntil(function((serviceInstanceId, newSpaceId) -> this.cloudFoundryClient.serviceInstancesV3() - .unshare(UnshareServiceInstanceRequest.builder() - .serviceInstanceId(serviceInstanceId) - .spaceId(newSpaceId) - .build()))) - .flatMapMany(function((serviceInstanceId, newSpaceId) -> requestListSharedSpacesRelationship(this.cloudFoundryClient, serviceInstanceId) - .flatMapIterable(ListSharedSpacesRelationshipResponse::getData) - .filter(data -> newSpaceId.equals(data.getId())))) - .as(StepVerifier::create) - .expectNextCount(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + function( + (organizationId, spaceId) -> + Mono.zip( + createManagedServiceInstanceId( + this.cloudFoundryClient, + this.serviceBrokerId, + serviceInstanceName, + this.serviceName + "-shareable", + spaceId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName)))) + .delayUntil( + function( + (serviceInstanceId, newSpaceId) -> + requestShareServiceInstance( + this.cloudFoundryClient, + newSpaceId, + serviceInstanceId))) + .delayUntil( + function( + (serviceInstanceId, newSpaceId) -> + this.cloudFoundryClient + .serviceInstancesV3() + .unshare( + UnshareServiceInstanceRequest.builder() + .serviceInstanceId( + serviceInstanceId) + .spaceId(newSpaceId) + .build()))) + .flatMapMany( + function( + (serviceInstanceId, newSpaceId) -> + requestListSharedSpacesRelationship( + this.cloudFoundryClient, serviceInstanceId) + .flatMapIterable( + ListSharedSpacesRelationshipResponse + ::getData) + .filter(data -> newSpaceId.equals(data.getId())))) + .as(StepVerifier::create) + .expectNextCount(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono deleteServiceInstanceByName(CloudFoundryClient cloudFoundryClient, String serviceInstanceName, String spaceId) { - return cloudFoundryClient.serviceInstancesV3() - .list(ListServiceInstancesRequest.builder() - .spaceId(spaceId) - .serviceInstanceName(serviceInstanceName) - .build()) - .map(serviceInstances -> serviceInstances.getResources().get(0)) - .flatMap(serviceInstance -> deleteServiceInstanceById(cloudFoundryClient, serviceInstance.getId())); + private static Mono deleteServiceInstanceByName( + CloudFoundryClient cloudFoundryClient, String serviceInstanceName, String spaceId) { + return cloudFoundryClient + .serviceInstancesV3() + .list( + ListServiceInstancesRequest.builder() + .spaceId(spaceId) + .serviceInstanceName(serviceInstanceName) + .build()) + .map(serviceInstances -> serviceInstances.getResources().get(0)) + .flatMap( + serviceInstance -> + deleteServiceInstanceById( + cloudFoundryClient, serviceInstance.getId())); } - private static Mono deleteServiceInstanceById(CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { - return cloudFoundryClient.serviceInstancesV3() - .delete(DeleteServiceInstanceRequest.builder() - .serviceInstanceId(serviceInstanceId) - .build()) - .map(Optional::get); + private static Mono deleteServiceInstanceById( + CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { + return cloudFoundryClient + .serviceInstancesV3() + .delete( + DeleteServiceInstanceRequest.builder() + .serviceInstanceId(serviceInstanceId) + .build()) + .map(Optional::get); } - private static Mono updateServiceInstanceByName(CloudFoundryClient cloudFoundryClient, String serviceInstanceName, String spaceId) { - return cloudFoundryClient.serviceInstancesV3() - .list(ListServiceInstancesRequest.builder() - .spaceId(spaceId) - .serviceInstanceName(serviceInstanceName) - .build()) - .map(serviceInstances -> serviceInstances.getResources().get(0)) - .flatMap(serviceInstance -> updateServiceInstanceById(cloudFoundryClient, serviceInstance.getId())) - .map(response -> response.getJobId().get()) - .flatMap(jobId -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), jobId)) - .then(getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName)); + private static Mono updateServiceInstanceByName( + CloudFoundryClient cloudFoundryClient, String serviceInstanceName, String spaceId) { + return cloudFoundryClient + .serviceInstancesV3() + .list( + ListServiceInstancesRequest.builder() + .spaceId(spaceId) + .serviceInstanceName(serviceInstanceName) + .build()) + .map(serviceInstances -> serviceInstances.getResources().get(0)) + .flatMap( + serviceInstance -> + updateServiceInstanceById( + cloudFoundryClient, serviceInstance.getId())) + .map(response -> response.getJobId().get()) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + cloudFoundryClient, Duration.ofMinutes(5), jobId)) + .then(getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName)); } - private static Mono updateServiceInstanceById(CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { - return cloudFoundryClient.serviceInstancesV3() - .update(UpdateServiceInstanceRequest.builder() - .serviceInstanceId(serviceInstanceId) - .parameter("foo", "bar") - .tag("baz") - .build()); + private static Mono updateServiceInstanceById( + CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { + return cloudFoundryClient + .serviceInstancesV3() + .update( + UpdateServiceInstanceRequest.builder() + .serviceInstanceId(serviceInstanceId) + .parameter("foo", "bar") + .tag("baz") + .build()); } - private static Mono createManagedServiceInstanceId(CloudFoundryClient cloudFoundryClient, Mono serviceBrokerId, String serviceInstanceName, String serviceName, String spaceId) { + private static Mono createManagedServiceInstanceId( + CloudFoundryClient cloudFoundryClient, + Mono serviceBrokerId, + String serviceInstanceName, + String serviceName, + String spaceId) { return serviceBrokerId - .flatMap(brokerId -> getPlanId(cloudFoundryClient, brokerId, serviceName)) - .flatMap(planId -> requestCreateServiceInstance(cloudFoundryClient, planId, serviceInstanceName, spaceId)) - .map(response -> response.getJobId() - .get()) - .flatMap(jobId -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), jobId)) - .then(getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName)); + .flatMap(brokerId -> getPlanId(cloudFoundryClient, brokerId, serviceName)) + .flatMap( + planId -> + requestCreateServiceInstance( + cloudFoundryClient, planId, serviceInstanceName, spaceId)) + .map(response -> response.getJobId().get()) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + cloudFoundryClient, Duration.ofMinutes(5), jobId)) + .then(getServiceInstanceIdByName(cloudFoundryClient, serviceInstanceName)); } - private static Mono getServiceInstanceIdByName(CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { - return cloudFoundryClient.serviceInstancesV3() - .list(ListServiceInstancesRequest.builder() - .serviceInstanceName(serviceInstanceName) - .build()) - .map(serviceInstances -> serviceInstances.getResources() - .get(0) - .getId()); + private static Mono getServiceInstanceIdByName( + CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { + return cloudFoundryClient + .serviceInstancesV3() + .list( + ListServiceInstancesRequest.builder() + .serviceInstanceName(serviceInstanceName) + .build()) + .map(serviceInstances -> serviceInstances.getResources().get(0).getId()); } - private static Mono createUserProvidedServiceInstance(CloudFoundryClient cloudFoundryClient, String serviceInstanceName, Map credentials, - String spaceId) { - return cloudFoundryClient.serviceInstancesV3() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .type(ServiceInstanceType.USER_PROVIDED) - .relationships(ServiceInstanceRelationships.builder() - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .credentials(credentials) - .build()); + private static Mono createUserProvidedServiceInstance( + CloudFoundryClient cloudFoundryClient, + String serviceInstanceName, + Map credentials, + String spaceId) { + return cloudFoundryClient + .serviceInstancesV3() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .type(ServiceInstanceType.USER_PROVIDED) + .relationships( + ServiceInstanceRelationships.builder() + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .credentials(credentials) + .build()); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(CreateSpaceResponse::getId); + .map(CreateSpaceResponse::getId); } - private static Mono getPlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { + private static Mono getPlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId, String serviceName) { return requestListServiceOfferings(cloudFoundryClient, serviceBrokerId) - .filter(serviceOfferingResource -> serviceName.equals(serviceOfferingResource.getName())) - .single() - .map(ServiceOfferingResource::getId) - .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) - .single() - .map(ServicePlanResource::getId); + .filter( + serviceOfferingResource -> + serviceName.equals(serviceOfferingResource.getName())) + .single() + .map(ServiceOfferingResource::getId) + .flatMapMany(serviceId -> requestListServicePlans(cloudFoundryClient, serviceId)) + .single() + .map(ServicePlanResource::getId); } - private static Mono requestCreateServiceInstance(CloudFoundryClient cloudFoundryClient, String planId, String serviceInstanceName, String spaceId) { - return cloudFoundryClient.serviceInstancesV3() - .create(CreateServiceInstanceRequest.builder() - .name(serviceInstanceName) - .type(ServiceInstanceType.MANAGED) - .relationships(ServiceInstanceRelationships.builder() - .servicePlan(ToOneRelationship.builder() - .data(Relationship.builder() - .id(planId).build()) - .build()) - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateServiceInstance( + CloudFoundryClient cloudFoundryClient, + String planId, + String serviceInstanceName, + String spaceId) { + return cloudFoundryClient + .serviceInstancesV3() + .create( + CreateServiceInstanceRequest.builder() + .name(serviceInstanceName) + .type(ServiceInstanceType.MANAGED) + .relationships( + ServiceInstanceRelationships.builder() + .servicePlan( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(planId) + .build()) + .build()) + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceId) { - return PaginationUtils - .requestClientV3Resources(page -> cloudFoundryClient.servicePlansV3() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceOfferingId(serviceId) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .servicePlansV3() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceOfferingId(serviceId) + .build())); } - private static Flux requestListServiceOfferings(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { - return PaginationUtils - .requestClientV3Resources(page -> cloudFoundryClient.serviceOfferingsV3() - .list(ListServiceOfferingsRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build())); + private static Flux requestListServiceOfferings( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .serviceOfferingsV3() + .list( + ListServiceOfferingsRequest.builder() + .page(page) + .serviceBrokerId(serviceBrokerId) + .build())); } - private static Mono requestListSharedSpacesRelationship(CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { - return cloudFoundryClient.serviceInstancesV3() - .listSharedSpacesRelationship(ListSharedSpacesRelationshipRequest.builder() - .serviceInstanceId(serviceInstanceId) - .build()); + private static Mono requestListSharedSpacesRelationship( + CloudFoundryClient cloudFoundryClient, String serviceInstanceId) { + return cloudFoundryClient + .serviceInstancesV3() + .listSharedSpacesRelationship( + ListSharedSpacesRelationshipRequest.builder() + .serviceInstanceId(serviceInstanceId) + .build()); } - private static Mono requestShareServiceInstance(CloudFoundryClient cloudFoundryClient, String newSpaceId, String serviceInstanceId) { - return cloudFoundryClient.serviceInstancesV3() - .share(ShareServiceInstanceRequest.builder() - .data(Relationship.builder() - .id(newSpaceId) - .build()) - .serviceInstanceId(serviceInstanceId) - .build()); + private static Mono requestShareServiceInstance( + CloudFoundryClient cloudFoundryClient, String newSpaceId, String serviceInstanceId) { + return cloudFoundryClient + .serviceInstancesV3() + .share( + ShareServiceInstanceRequest.builder() + .data(Relationship.builder().id(newSpaceId).build()) + .serviceInstanceId(serviceInstanceId) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceOfferingsTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceOfferingsTest.java index 6b6bba65663..f0b67a37b46 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceOfferingsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServiceOfferingsTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v3; +import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; +import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; + +import java.time.Duration; +import java.util.Collections; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -31,31 +36,22 @@ import org.cloudfoundry.client.v3.spaces.CreateSpaceResponse; import org.cloudfoundry.client.v3.spaces.SpaceRelationships; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.Collections; - -import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; -import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_10) public final class ServiceOfferingsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; @Test public void delete() { @@ -64,71 +60,111 @@ public void delete() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); - - getServiceOfferingId(this.cloudFoundryClient, serviceName, serviceBrokerMetadata.serviceBrokerId) - .flatMap(serviceOfferingId -> this.cloudFoundryClient.serviceOfferingsV3() - .delete(DeleteServiceOfferingRequest.builder() - .purge(true) - .serviceOfferingId(serviceOfferingId) - .build())) - .thenMany(requestListServiceOfferings(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(resource -> serviceName.equals(resource.getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); + + getServiceOfferingId( + this.cloudFoundryClient, serviceName, serviceBrokerMetadata.serviceBrokerId) + .flatMap( + serviceOfferingId -> + this.cloudFoundryClient + .serviceOfferingsV3() + .delete( + DeleteServiceOfferingRequest.builder() + .purge(true) + .serviceOfferingId(serviceOfferingId) + .build())) + .thenMany( + requestListServiceOfferings( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter(resource -> serviceName.equals(resource.getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test public void get() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServiceOfferingId(this.cloudFoundryClient, this.serviceName, serviceBrokerId)) - .flatMap(serviceOfferingId -> this.cloudFoundryClient.serviceOfferingsV3() - .get(GetServiceOfferingRequest.builder() - .serviceOfferingId(serviceOfferingId) - .build())) - .map(GetServiceOfferingResponse::getName) - .as(StepVerifier::create) - .expectNext(this.serviceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + getServiceOfferingId( + this.cloudFoundryClient, this.serviceName, serviceBrokerId)) + .flatMap( + serviceOfferingId -> + this.cloudFoundryClient + .serviceOfferingsV3() + .get( + GetServiceOfferingRequest.builder() + .serviceOfferingId(serviceOfferingId) + .build())) + .map(GetServiceOfferingResponse::getName) + .as(StepVerifier::create) + .expectNext(this.serviceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { - PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.serviceOfferingsV3() - .list(ListServiceOfferingsRequest.builder() - .page(page) - .build())) - .filter(resource -> this.serviceName.equals(resource.getName())) - .map(ServiceOfferingResource::getDescription) - .as(StepVerifier::create) - .expectNext("test-service-description") - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .serviceOfferingsV3() + .list( + ListServiceOfferingsRequest.builder() + .page(page) + .build())) + .filter(resource -> this.serviceName.equals(resource.getName())) + .map(ServiceOfferingResource::getDescription) + .as(StepVerifier::create) + .expectNext("test-service-description") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterBy() { this.serviceBrokerId - .flatMapMany(serviceBrokerId -> PaginationUtils.requestClientV3Resources(page -> - this.cloudFoundryClient.serviceOfferingsV3() - .list(ListServiceOfferingsRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build()))) - .filter(resource -> this.serviceName.equals(resource.getName())) - .map(ServiceOfferingResource::getDescription) - .as(StepVerifier::create) - .expectNext("test-service-description") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + serviceBrokerId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .serviceOfferingsV3() + .list( + ListServiceOfferingsRequest + .builder() + .page(page) + .serviceBrokerId( + serviceBrokerId) + .build()))) + .filter(resource -> this.serviceName.equals(resource.getName())) + .map(ServiceOfferingResource::getDescription) + .as(StepVerifier::create) + .expectNext("test-service-description") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -138,65 +174,104 @@ public void update() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); - - getServiceOfferingId(this.cloudFoundryClient, serviceName, serviceBrokerMetadata.serviceBrokerId) - .flatMap(serviceOfferingId -> this.cloudFoundryClient.serviceOfferingsV3() - .update(UpdateServiceOfferingRequest.builder() - .metadata(Metadata.builder() - .label("test-service-offering-update-key", "test-service-offering-update-value") - .build()) - .serviceOfferingId(serviceOfferingId) - .build())) - .thenMany(requestListServiceOfferings(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(response -> serviceName.equals(response.getName())) - .map(ServiceOfferingResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-service-offering-update-key", "test-service-offering-update-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); + + getServiceOfferingId( + this.cloudFoundryClient, serviceName, serviceBrokerMetadata.serviceBrokerId) + .flatMap( + serviceOfferingId -> + this.cloudFoundryClient + .serviceOfferingsV3() + .update( + UpdateServiceOfferingRequest.builder() + .metadata( + Metadata.builder() + .label( + "test-service-offering-update-key", + "test-service-offering-update-value") + .build()) + .serviceOfferingId(serviceOfferingId) + .build())) + .thenMany( + requestListServiceOfferings( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter(response -> serviceName.equals(response.getName())) + .map(ServiceOfferingResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext( + Collections.singletonMap( + "test-service-offering-update-key", + "test-service-offering-update-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(CreateSpaceResponse::getId); + .map(CreateSpaceResponse::getId); } - private static Mono getServiceOfferingId(CloudFoundryClient cloudFoundryClient, String serviceName, String serviceBrokerId) { + private static Mono getServiceOfferingId( + CloudFoundryClient cloudFoundryClient, String serviceName, String serviceBrokerId) { return requestListServiceOfferings(cloudFoundryClient, serviceBrokerId) - .filter(resource -> serviceName.equals(resource.getName())) - .map(ServiceOfferingResource::getId) - .single(); + .filter(resource -> serviceName.equals(resource.getName())) + .map(ServiceOfferingResource::getId) + .single(); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Flux requestListServiceOfferings(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { - return PaginationUtils.requestClientV3Resources(page -> - cloudFoundryClient.serviceOfferingsV3() - .list(ListServiceOfferingsRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build())); + private static Flux requestListServiceOfferings( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .serviceOfferingsV3() + .list( + ListServiceOfferingsRequest.builder() + .page(page) + .serviceBrokerId(serviceBrokerId) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServicePlansTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServicePlansTest.java index c8282157022..5e37753b66b 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/ServicePlansTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/ServicePlansTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v3; +import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; +import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; + +import java.time.Duration; +import java.util.Collections; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -33,31 +38,22 @@ import org.cloudfoundry.client.v3.spaces.CreateSpaceResponse; import org.cloudfoundry.client.v3.spaces.SpaceRelationships; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.Collections; - -import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; -import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_10) public final class ServicePlansTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private String planName; + @Autowired private String planName; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; @Test public void delete() { @@ -66,84 +62,124 @@ public void delete() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - .flatMap(servicePlanId -> this.cloudFoundryClient.servicePlansV3() - .delete(DeleteServicePlanRequest.builder() - .servicePlanId(servicePlanId) - .build())) - .thenMany(requestListServicePlans(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(response -> serviceName.equals(response.getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlansV3() + .delete( + DeleteServicePlanRequest.builder() + .servicePlanId(servicePlanId) + .build())) + .thenMany( + requestListServicePlans( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter(response -> serviceName.equals(response.getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test public void get() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServicePlanId(this.cloudFoundryClient, serviceBrokerId)) - .flatMap(servicePlanId -> this.cloudFoundryClient.servicePlansV3() - .get(GetServicePlanRequest.builder() - .servicePlanId(servicePlanId) - .build())) - .map(GetServicePlanResponse::getName) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + getServicePlanId(this.cloudFoundryClient, serviceBrokerId)) + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlansV3() + .get( + GetServicePlanRequest.builder() + .servicePlanId(servicePlanId) + .build())) + .map(GetServicePlanResponse::getName) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { - PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.servicePlansV3() - .list(ListServicePlansRequest.builder() - .page(page) - .build())) - .filter(response -> this.planName.equals(response.getName())) - .map(ServicePlanResource::getDescription) - .as(StepVerifier::create) - .expectNext("test-plan-description") - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .servicePlansV3() + .list(ListServicePlansRequest.builder().page(page).build())) + .filter(response -> this.planName.equals(response.getName())) + .map(ServicePlanResource::getDescription) + .as(StepVerifier::create) + .expectNext("test-plan-description") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByServiceBrokerId() { this.serviceBrokerId - .flatMapMany(serviceBrokerId -> PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.servicePlansV3() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build()))) - .map(ServicePlanResource::getName) - .filter(planName -> this.planName.equals(planName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + serviceBrokerId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .servicePlansV3() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceBrokerId( + serviceBrokerId) + .build()))) + .map(ServicePlanResource::getName) + .filter(planName -> this.planName.equals(planName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void updateServicePlanVisibilityWithSame() { this.serviceBrokerId - .flatMap(serviceBrokerId -> getServicePlanId(this.cloudFoundryClient, serviceBrokerId)) - .flatMap(servicePlanId -> this.cloudFoundryClient - .servicePlansV3().updateVisibility(UpdateServicePlanVisibilityRequest.builder() - .servicePlanId(servicePlanId) - .type(Visibility.SPACE) - .build())) - .as(StepVerifier::create) - .expectError() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + getServicePlanId(this.cloudFoundryClient, serviceBrokerId)) + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlansV3() + .updateVisibility( + UpdateServicePlanVisibilityRequest.builder() + .servicePlanId(servicePlanId) + .type(Visibility.SPACE) + .build())) + .as(StepVerifier::create) + .expectError() + .verify(Duration.ofMinutes(5)); } @Test @@ -153,41 +189,79 @@ public void listUsingLabelSelector() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - .flatMap(servicePlanId -> this.cloudFoundryClient.servicePlansV3() - .update(UpdateServicePlanRequest.builder() - .metadata(Metadata.builder() - .label("test-label-selector-key1", "test-label-selector-value1") - .label("test-label-selector-key2", "test-label-selector-value2") - .build()) - .servicePlanId(servicePlanId) - .build())) - .thenMany(Flux.merge( - PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.servicePlansV3() - .list(ListServicePlansRequest.builder() - .labelSelector("test-label-selector-key1,test-label-selector-key1") - .page(page) - .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) - .build())), - PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.servicePlansV3() - .list(ListServicePlansRequest.builder() - .labelSelector("test-label-selector-key1,key-that-causes-no-results-because-this-is-an-AND-query") - .page(page) - .serviceBrokerId(serviceBrokerMetadata.serviceBrokerId) - .build()) - ))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlansV3() + .update( + UpdateServicePlanRequest.builder() + .metadata( + Metadata.builder() + .label( + "test-label-selector-key1", + "test-label-selector-value1") + .label( + "test-label-selector-key2", + "test-label-selector-value2") + .build()) + .servicePlanId(servicePlanId) + .build())) + .thenMany( + Flux.merge( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .servicePlansV3() + .list( + ListServicePlansRequest.builder() + .labelSelector( + "test-label-selector-key1,test-label-selector-key1") + .page(page) + .serviceBrokerId( + serviceBrokerMetadata + .serviceBrokerId) + .build())), + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .servicePlansV3() + .list( + ListServicePlansRequest.builder() + .labelSelector( + "test-label-selector-key1,key-that-causes-no-results-because-this-is-an-AND-query") + .page(page) + .serviceBrokerId( + serviceBrokerMetadata + .serviceBrokerId) + .build())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -197,65 +271,100 @@ public void update() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, true)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + true)) + .block(Duration.ofMinutes(5)); getServicePlanId(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId) - .flatMap(servicePlanId -> this.cloudFoundryClient.servicePlansV3() - .update(UpdateServicePlanRequest.builder() - .metadata(Metadata.builder() - .label("test-update-key", "test-update-value") - .build()) - .servicePlanId(servicePlanId) - .build())) - .thenMany(requestListServicePlans(this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) - .filter(response -> planName.equals(response.getName())) - .map(ServicePlanResource::getMetadata) - .map(Metadata::getLabels) - .as(StepVerifier::create) - .expectNext(Collections.singletonMap("test-update-key", "test-update-value")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + servicePlanId -> + this.cloudFoundryClient + .servicePlansV3() + .update( + UpdateServicePlanRequest.builder() + .metadata( + Metadata.builder() + .label( + "test-update-key", + "test-update-value") + .build()) + .servicePlanId(servicePlanId) + .build())) + .thenMany( + requestListServicePlans( + this.cloudFoundryClient, serviceBrokerMetadata.serviceBrokerId)) + .filter(response -> planName.equals(response.getName())) + .map(ServicePlanResource::getMetadata) + .map(Metadata::getLabels) + .as(StepVerifier::create) + .expectNext(Collections.singletonMap("test-update-key", "test-update-value")) + .expectComplete() + .verify(Duration.ofMinutes(5)); - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(CreateSpaceResponse::getId); + .map(CreateSpaceResponse::getId); } - private static Mono getServicePlanId(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + private static Mono getServicePlanId( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { return requestListServicePlans(cloudFoundryClient, serviceBrokerId) - .filter(resource -> "test-plan-description".equals(resource.getDescription())) - .map(ServicePlanResource::getId) - .single(); + .filter(resource -> "test-plan-description".equals(resource.getDescription())) + .map(ServicePlanResource::getId) + .single(); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Flux requestListServicePlans(CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { - return PaginationUtils - .requestClientV3Resources(page -> cloudFoundryClient.servicePlansV3() - .list(ListServicePlansRequest.builder() - .page(page) - .serviceBrokerId(serviceBrokerId) - .build())); + private static Flux requestListServicePlans( + CloudFoundryClient cloudFoundryClient, String serviceBrokerId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .servicePlansV3() + .list( + ListServicePlansRequest.builder() + .page(page) + .serviceBrokerId(serviceBrokerId) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/SpacesTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/SpacesTest.java index 5693df0825c..fc939770984 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/SpacesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/SpacesTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.io.IOException; +import java.io.InputStream; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -47,7 +53,8 @@ import org.cloudfoundry.client.v3.spaces.UpdateSpaceRequest; import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import org.springframework.util.StreamUtils; @@ -55,21 +62,12 @@ import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.io.InputStream; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) public final class SpacesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; @Test public void assignIsolationSegment() { @@ -77,25 +75,43 @@ public void assignIsolationSegment() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - ) - .flatMap(function((isolationSegmentId, spaceId) -> Mono.zip( - Mono.just(isolationSegmentId), - this.cloudFoundryClient.spacesV3() - .assignIsolationSegment(AssignSpaceIsolationSegmentRequest.builder() - .data(Relationship.builder() - .id(isolationSegmentId) - .build()) - .spaceId(spaceId) - .build()) - .map(response -> response.getData().getId()) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .flatMap( + function( + (isolationSegmentId, spaceId) -> + Mono.zip( + Mono.just(isolationSegmentId), + this.cloudFoundryClient + .spacesV3() + .assignIsolationSegment( + AssignSpaceIsolationSegmentRequest + .builder() + .data( + Relationship + .builder() + .id( + isolationSegmentId) + .build()) + .spaceId(spaceId) + .build()) + .map( + response -> + response.getData() + .getId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -103,23 +119,32 @@ public void create() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> this.cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build())) - .then(requestListSpaces(this.cloudFoundryClient, spaceName) - .single()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + this.cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship + .builder() + .data( + Relationship + .builder() + .id( + organizationId) + .build()) + .build()) + .build()) + .build())) + .then(requestListSpaces(this.cloudFoundryClient, spaceName).single()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_8) @@ -128,42 +153,78 @@ public void delete() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> this.cloudFoundryClient.spacesV3() - .delete(DeleteSpaceRequest.builder() - .spaceId(spaceId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job))) - .thenMany(requestListSpaces(this.cloudFoundryClient, spaceName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + this.cloudFoundryClient + .spacesV3() + .delete( + DeleteSpaceRequest.builder() + .spaceId(spaceId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job))) + .thenMany(requestListSpaces(this.cloudFoundryClient, spaceName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - //TODO: Await resolution of https://github.com/cloudfoundry/cloud_controller_ng/issues/1876 + // TODO: Await resolution of https://github.com/cloudfoundry/cloud_controller_ng/issues/1876 @IfCloudFoundryVersion(greaterThan = CloudFoundryVersion.PCF_2_9) - @Ignore("Await https://github.com/cloudfoundry/cf-java-client/issues/1876") + @Disabled("Await https://github.com/cloudfoundry/cf-java-client/issues/1876") @Test public void deleteUnmappedRoutes() { String domainName = this.nameFactory.getDomainName(); String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createDomainId(this.cloudFoundryClient, domainName, organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName))) - .delayUntil(function((domainId, spaceId) -> createRouteId(this.cloudFoundryClient, domainId, "deleteUnmappedRoutes", spaceId))) - .flatMap(function((domainId, spaceId) -> this.cloudFoundryClient.spacesV3() - .deleteUnmappedRoutes(DeleteUnmappedRoutesRequest.builder() - .spaceId(spaceId) - .build()) - .flatMap(job -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), job)) - .thenReturn(domainId))) - .flatMapMany(domainId -> requestListRoutes(this.cloudFoundryClient, domainId)) - .as(StepVerifier::create) - .expectNextCount(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createDomainId( + this.cloudFoundryClient, + domainName, + organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .delayUntil( + function( + (domainId, spaceId) -> + createRouteId( + this.cloudFoundryClient, + domainId, + "deleteUnmappedRoutes", + spaceId))) + .flatMap( + function( + (domainId, spaceId) -> + this.cloudFoundryClient + .spacesV3() + .deleteUnmappedRoutes( + DeleteUnmappedRoutesRequest.builder() + .spaceId(spaceId) + .build()) + .flatMap( + job -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + job)) + .thenReturn(domainId))) + .flatMapMany(domainId -> requestListRoutes(this.cloudFoundryClient, domainId)) + .as(StepVerifier::create) + .expectNextCount(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -172,22 +233,44 @@ public void getIsolationSegment() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> Mono.zip( - createIsolationSegmentId(this.cloudFoundryClient, isolationSegmentName, organizationId), - createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - ) - .delayUntil(function((isolationSegmentId, spaceId) -> requestAssignIsolationSegment(this.cloudFoundryClient, isolationSegmentId, spaceId))) - .flatMap(function((isolationSegmentId, spaceId) -> Mono.zip( - Mono.just(isolationSegmentId), - this.cloudFoundryClient.spacesV3() - .getIsolationSegment(GetSpaceIsolationSegmentRequest.builder() - .spaceId(spaceId) - .build()) - .map(response -> response.getData().getId())))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + Mono.zip( + createIsolationSegmentId( + this.cloudFoundryClient, + isolationSegmentName, + organizationId), + createSpaceId( + this.cloudFoundryClient, + organizationId, + spaceName))) + .delayUntil( + function( + (isolationSegmentId, spaceId) -> + requestAssignIsolationSegment( + this.cloudFoundryClient, + isolationSegmentId, + spaceId))) + .flatMap( + function( + (isolationSegmentId, spaceId) -> + Mono.zip( + Mono.just(isolationSegmentId), + this.cloudFoundryClient + .spacesV3() + .getIsolationSegment( + GetSpaceIsolationSegmentRequest + .builder() + .spaceId(spaceId) + .build()) + .map( + response -> + response.getData() + .getId())))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -195,16 +278,24 @@ public void list() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> requestCreateSpace(this.cloudFoundryClient, organizationId, spaceName)) - .thenMany(PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.spacesV3() - .list(ListSpacesRequest.builder() - .page(page) - .build()))) - .filter(resource -> spaceName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateSpace( + this.cloudFoundryClient, organizationId, spaceName)) + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .spacesV3() + .list( + ListSpacesRequest.builder() + .page(page) + .build()))) + .filter(resource -> spaceName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -212,17 +303,25 @@ public void listFilterByName() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> requestCreateSpace(this.cloudFoundryClient, organizationId, spaceName)) - .thenMany(PaginationUtils.requestClientV3Resources(page -> this.cloudFoundryClient.spacesV3() - .list(ListSpacesRequest.builder() - .name(spaceName) - .build())) - .single()) - .map(SpaceResource::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + requestCreateSpace( + this.cloudFoundryClient, organizationId, spaceName)) + .thenMany( + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .spacesV3() + .list( + ListSpacesRequest.builder() + .name(spaceName) + .build())) + .single()) + .map(SpaceResource::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -230,18 +329,27 @@ public void listFilterByOrganization() { String spaceName = this.nameFactory.getSpaceName(); this.organizationId - .delayUntil(organizationId -> requestCreateSpace(this.cloudFoundryClient, organizationId, spaceName)) - .flatMapMany(organizationId -> PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.spacesV3() - .list(ListSpacesRequest.builder() - .organizationId(organizationId) - .page(page) - .build()))) - .filter(resource -> spaceName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + organizationId -> + requestCreateSpace( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMapMany( + organizationId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .spacesV3() + .list( + ListSpacesRequest.builder() + .organizationId( + organizationId) + .page(page) + .build()))) + .filter(resource -> spaceName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_8) @@ -251,173 +359,256 @@ public void update() { String newSpaceName = this.nameFactory.getSpaceName(); this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> this.cloudFoundryClient.spacesV3().update(UpdateSpaceRequest.builder() - .metadata(Metadata.builder() - .annotation("annotationKey", "annotationValue") - .label("labelKey", "labelValue") - .build()) - .name(newSpaceName) - .spaceId(spaceId) - .build())) - .thenMany(requestListSpaces(this.cloudFoundryClient, newSpaceName)) - .map(SpaceResource::getMetadata) - .as(StepVerifier::create) - .consumeNextWith(metadata -> { - assertThat(metadata.getAnnotations().get("annotationKey")).isEqualTo("annotationValue"); - assertThat(metadata.getLabels().get("labelKey")).isEqualTo("labelValue"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + this.cloudFoundryClient + .spacesV3() + .update( + UpdateSpaceRequest.builder() + .metadata( + Metadata.builder() + .annotation( + "annotationKey", + "annotationValue") + .label( + "labelKey", + "labelValue") + .build()) + .name(newSpaceName) + .spaceId(spaceId) + .build())) + .thenMany(requestListSpaces(this.cloudFoundryClient, newSpaceName)) + .map(SpaceResource::getMetadata) + .as(StepVerifier::create) + .consumeNextWith( + metadata -> { + assertThat(metadata.getAnnotations().get("annotationKey")) + .isEqualTo("annotationValue"); + assertThat(metadata.getLabels().get("labelKey")) + .isEqualTo("labelValue"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.UNSPECIFIED) //TODO how to select this version? + @IfCloudFoundryVersion( + greaterThanOrEqualTo = + CloudFoundryVersion.UNSPECIFIED) // TODO how to select this version? @Test public void applyManifest() throws IOException { String spaceName = this.nameFactory.getSpaceName(); byte[] manifest; - try (InputStream inputStream = new ClassPathResource("test-manifest.yml").getInputStream()) { + try (InputStream inputStream = + new ClassPathResource("test-manifest.yml").getInputStream()) { manifest = StreamUtils.copyToByteArray(inputStream); } this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> this.cloudFoundryClient.spacesV3().applyManifest(ApplyManifestRequest.builder() - .spaceId(spaceId) - .manifest(manifest) - .build()) - .map(response -> response.getJobId().orElseThrow(() -> new IllegalStateException("No jobId returned for applying v3 manifest"))) - .flatMap(jobId -> JobUtils.waitForCompletion(this.cloudFoundryClient, Duration.ofMinutes(5), jobId)) - .then(Mono.just(spaceId))) - .flatMap(spaceId -> this.cloudFoundryClient.applicationsV3().list(ListApplicationsRequest.builder() - .spaceId(spaceId) - .name("test-application") - .build()) - .single()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + organizationId -> + createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + this.cloudFoundryClient + .spacesV3() + .applyManifest( + ApplyManifestRequest.builder() + .spaceId(spaceId) + .manifest(manifest) + .build()) + .map( + response -> + response.getJobId() + .orElseThrow( + () -> + new IllegalStateException( + "No jobId" + + " returned" + + " for applying" + + " v3 manifest"))) + .flatMap( + jobId -> + JobUtils.waitForCompletion( + this.cloudFoundryClient, + Duration.ofMinutes(5), + jobId)) + .then(Mono.just(spaceId))) + .flatMap( + spaceId -> + this.cloudFoundryClient + .applicationsV3() + .list( + ListApplicationsRequest.builder() + .spaceId(spaceId) + .name("test-application") + .build()) + .single()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createDomainId(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + private static Mono createDomainId( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { return requestCreateDomain(cloudFoundryClient, domainName, organizationId) - .map(CreateDomainResponse::getId); + .map(CreateDomainResponse::getId); } - private static Mono createIsolationSegmentId(CloudFoundryClient cloudFoundryClient, String isolationSegmentName, String organizationId) { + private static Mono createIsolationSegmentId( + CloudFoundryClient cloudFoundryClient, + String isolationSegmentName, + String organizationId) { return requestCreateIsolationSegment(cloudFoundryClient, isolationSegmentName) - .map(CreateIsolationSegmentResponse::getId) - .delayUntil(isolationSegmentId -> requestAddIsolationSegmentOrganizationEntitlement(cloudFoundryClient, isolationSegmentId, organizationId)); + .map(CreateIsolationSegmentResponse::getId) + .delayUntil( + isolationSegmentId -> + requestAddIsolationSegmentOrganizationEntitlement( + cloudFoundryClient, isolationSegmentId, organizationId)); } - private static Mono createRouteId(CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { + private static Mono createRouteId( + CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { return requestCreateRoute(cloudFoundryClient, domainId, label, spaceId) - .map(CreateRouteResponse::getId); + .map(CreateRouteResponse::getId); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(CreateSpaceResponse::getId); + .map(CreateSpaceResponse::getId); } - private static Mono requestAddIsolationSegmentOrganizationEntitlement(CloudFoundryClient cloudFoundryClient, String isolationSegmentId, - String organizationId) { - return cloudFoundryClient.isolationSegments() - .addOrganizationEntitlement(AddIsolationSegmentOrganizationEntitlementRequest.builder() - .isolationSegmentId(isolationSegmentId) - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()); + private static Mono + requestAddIsolationSegmentOrganizationEntitlement( + CloudFoundryClient cloudFoundryClient, + String isolationSegmentId, + String organizationId) { + return cloudFoundryClient + .isolationSegments() + .addOrganizationEntitlement( + AddIsolationSegmentOrganizationEntitlementRequest.builder() + .isolationSegmentId(isolationSegmentId) + .data(Relationship.builder().id(organizationId).build()) + .build()); } - private static Mono requestAssignIsolationSegment(CloudFoundryClient cloudFoundryClient, String isolationSegmentId, String spaceId) { - return cloudFoundryClient.spacesV3() - .assignIsolationSegment(AssignSpaceIsolationSegmentRequest.builder() - .data(Relationship.builder() - .id(isolationSegmentId) - .build()) - .spaceId(spaceId) - .build()); + private static Mono requestAssignIsolationSegment( + CloudFoundryClient cloudFoundryClient, String isolationSegmentId, String spaceId) { + return cloudFoundryClient + .spacesV3() + .assignIsolationSegment( + AssignSpaceIsolationSegmentRequest.builder() + .data(Relationship.builder().id(isolationSegmentId).build()) + .spaceId(spaceId) + .build()); } - private static Mono requestCreateDomain(CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { - return cloudFoundryClient.domainsV3() - .create(CreateDomainRequest.builder() - .internal(false) - .name(domainName) - .relationships(DomainRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateDomain( + CloudFoundryClient cloudFoundryClient, String domainName, String organizationId) { + return cloudFoundryClient + .domainsV3() + .create( + CreateDomainRequest.builder() + .internal(false) + .name(domainName) + .relationships( + DomainRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCreateIsolationSegment(CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { - return cloudFoundryClient.isolationSegments() - .create(CreateIsolationSegmentRequest.builder() - .name(isolationSegmentName) - .build()); + private static Mono requestCreateIsolationSegment( + CloudFoundryClient cloudFoundryClient, String isolationSegmentName) { + return cloudFoundryClient + .isolationSegments() + .create(CreateIsolationSegmentRequest.builder().name(isolationSegmentName).build()); } - private static Mono requestCreateRoute(CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { + private static Mono requestCreateRoute( + CloudFoundryClient cloudFoundryClient, String domainId, String label, String spaceId) { String key = String.format("test-%s-key", label); String value = String.format("test-%s-value", label); - return cloudFoundryClient.routesV3() - .create(CreateRouteRequest.builder() - .metadata(Metadata.builder() - .label(key, value) - .build()) - .relationships(RouteRelationships.builder() - .domain(ToOneRelationship.builder() - .data(Relationship.builder() - .id(domainId) - .build()) - .build()) - .space(ToOneRelationship.builder() - .data(Relationship.builder() - .id(spaceId) - .build()) - .build()) - .build()) - .build()); + return cloudFoundryClient + .routesV3() + .create( + CreateRouteRequest.builder() + .metadata(Metadata.builder().label(key, value).build()) + .relationships( + RouteRelationships.builder() + .domain( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(domainId) + .build()) + .build()) + .space( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(spaceId) + .build()) + .build()) + .build()) + .build()); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spacesV3() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .relationships(SpaceRelationships.builder() - .organization(ToOneRelationship.builder() - .data(Relationship.builder() - .id(organizationId) - .build()) - .build()) - .build()) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spacesV3() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .relationships( + SpaceRelationships.builder() + .organization( + ToOneRelationship.builder() + .data( + Relationship.builder() + .id(organizationId) + .build()) + .build()) + .build()) + .build()); } - private static Flux requestListRoutes(CloudFoundryClient cloudFoundryClient, String domainId) { - return PaginationUtils.requestClientV3Resources(page -> - cloudFoundryClient.routesV3() - .list(ListRoutesRequest.builder() - .domainId(domainId) - .page(page) - .build())); + private static Flux requestListRoutes( + CloudFoundryClient cloudFoundryClient, String domainId) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .routesV3() + .list( + ListRoutesRequest.builder() + .domainId(domainId) + .page(page) + .build())); } - private static Flux requestListSpaces(CloudFoundryClient cloudFoundryClient, String spaceName) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.spacesV3() - .list(ListSpacesRequest.builder() - .name(spaceName) - .page(page) - .build())); + private static Flux requestListSpaces( + CloudFoundryClient cloudFoundryClient, String spaceName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .spacesV3() + .list( + ListSpacesRequest.builder() + .name(spaceName) + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/StacksTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/StacksTest.java index 287ecf0647a..73f44939162 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/StacksTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/StacksTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.client.v3; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v3.stacks.CreateStackRequest; @@ -24,41 +27,38 @@ import org.cloudfoundry.client.v3.stacks.GetStackRequest; import org.cloudfoundry.client.v3.stacks.GetStackResponse; import org.cloudfoundry.client.v3.stacks.ListStacksRequest; -import org.cloudfoundry.client.v3.stacks.StackResource; import org.cloudfoundry.client.v3.stacks.Stack; +import org.cloudfoundry.client.v3.stacks.StackResource; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class StacksTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private String stackName; + @Autowired private String stackName; @Test public void create() { String stackName = this.nameFactory.getStackName(); - this.cloudFoundryClient.stacksV3() - .create(CreateStackRequest.builder() - .description("Test stack description") - .name(stackName) - .build()) - .thenMany(requestListStacks(this.cloudFoundryClient, stackName)) - .map(Stack::getDescription) - .as(StepVerifier::create) - .expectNext("Test stack description") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryClient + .stacksV3() + .create( + CreateStackRequest.builder() + .description("Test stack description") + .name(stackName) + .build()) + .thenMany(requestListStacks(this.cloudFoundryClient, stackName)) + .map(Stack::getDescription) + .as(StepVerifier::create) + .expectNext("Test stack description") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -66,94 +66,118 @@ public void delete() { String stackName = this.nameFactory.getStackName(); createStackId(this.cloudFoundryClient, stackName) - .delayUntil(stackId -> this.cloudFoundryClient.stacksV3() - .delete(DeleteStackRequest.builder() - .stackId(stackId) - .build())) - .flatMap(stackId -> requestGetStack(this.cloudFoundryClient, stackId)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV3Exception.class).hasMessageMatching("CF-ResourceNotFound\\([0-9]+\\): Stack not found.*")) - .verify(Duration.ofMinutes(5)); + .delayUntil( + stackId -> + this.cloudFoundryClient + .stacksV3() + .delete( + DeleteStackRequest.builder() + .stackId(stackId) + .build())) + .flatMap(stackId -> requestGetStack(this.cloudFoundryClient, stackId)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV3Exception.class) + .hasMessageMatching( + "CF-ResourceNotFound\\([0-9]+\\): Stack not" + + " found.*")) + .verify(Duration.ofMinutes(5)); } @Test public void get() { getStackId(this.cloudFoundryClient, this.stackName) - .flatMap(stackId -> this.cloudFoundryClient.stacksV3() - .get(GetStackRequest.builder() - .stackId(stackId) - .build())) - .map(Stack::getName) - .as(StepVerifier::create) - .expectNext(this.stackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + stackId -> + this.cloudFoundryClient + .stacksV3() + .get(GetStackRequest.builder().stackId(stackId).build())) + .map(Stack::getName) + .as(StepVerifier::create) + .expectNext(this.stackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { getStackId(this.cloudFoundryClient, this.stackName) - .flatMapMany(stackId -> PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.stacksV3() - .list(ListStacksRequest.builder() - .page(page) - .build())) - .filter(stack -> stack.getId().equals(stackId))) - .map(Stack::getName) - .as(StepVerifier::create) - .expectNext(this.stackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + stackId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .stacksV3() + .list( + ListStacksRequest.builder() + .page(page) + .build())) + .filter(stack -> stack.getId().equals(stackId))) + .map(Stack::getName) + .as(StepVerifier::create) + .expectNext(this.stackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listFilterByName() { - PaginationUtils - .requestClientV3Resources(page -> this.cloudFoundryClient.stacksV3() - .list(ListStacksRequest.builder() - .name(this.stackName) - .page(page) - .build())) - .map(Stack::getName) - .as(StepVerifier::create) - .expectNext(this.stackName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .stacksV3() + .list( + ListStacksRequest.builder() + .name(this.stackName) + .page(page) + .build())) + .map(Stack::getName) + .as(StepVerifier::create) + .expectNext(this.stackName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createStackId(CloudFoundryClient cloudFoundryClient, String stackName) { - return requestCreateStack(cloudFoundryClient, stackName) - .map(Stack::getId); + private static Mono createStackId( + CloudFoundryClient cloudFoundryClient, String stackName) { + return requestCreateStack(cloudFoundryClient, stackName).map(Stack::getId); } - private static Mono getStackId(CloudFoundryClient cloudFoundryClient, String stackName) { - return requestListStacks(cloudFoundryClient, stackName) - .single() - .map(Stack::getId); + private static Mono getStackId( + CloudFoundryClient cloudFoundryClient, String stackName) { + return requestListStacks(cloudFoundryClient, stackName).single().map(Stack::getId); } - private static Mono requestCreateStack(CloudFoundryClient cloudFoundryClient, String stackName) { - return cloudFoundryClient.stacksV3() - .create(CreateStackRequest.builder() - .description("Test stack description") - .name(stackName) - .build()); + private static Mono requestCreateStack( + CloudFoundryClient cloudFoundryClient, String stackName) { + return cloudFoundryClient + .stacksV3() + .create( + CreateStackRequest.builder() + .description("Test stack description") + .name(stackName) + .build()); } - private static Mono requestGetStack(CloudFoundryClient cloudFoundryClient, String stackId) { - return cloudFoundryClient.stacksV3() - .get(GetStackRequest.builder() - .stackId(stackId) - .build()); + private static Mono requestGetStack( + CloudFoundryClient cloudFoundryClient, String stackId) { + return cloudFoundryClient + .stacksV3() + .get(GetStackRequest.builder().stackId(stackId).build()); } - private static Flux requestListStacks(CloudFoundryClient cloudFoundryClient, String stackName) { - return PaginationUtils - .requestClientV3Resources(page -> cloudFoundryClient.stacksV3() - .list(ListStacksRequest.builder() - .name(stackName) - .page(page) - .build())); + private static Flux requestListStacks( + CloudFoundryClient cloudFoundryClient, String stackName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .stacksV3() + .list( + ListStacksRequest.builder() + .name(stackName) + .page(page) + .build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/client/v3/TasksTest.java b/integration-test/src/test/java/org/cloudfoundry/client/v3/TasksTest.java index db548472d48..a4c962d0f19 100644 --- a/integration-test/src/test/java/org/cloudfoundry/client/v3/TasksTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/client/v3/TasksTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.client.v3; +import static org.cloudfoundry.client.v3.tasks.TaskState.RUNNING; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.io.IOException; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -37,46 +42,45 @@ import org.cloudfoundry.operations.applications.ApplicationHealthCheck; import org.cloudfoundry.operations.applications.PushApplicationRequest; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.time.Duration; - -import static org.cloudfoundry.client.v3.tasks.TaskState.RUNNING; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) public final class TasksTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; @Test public void cancel() throws IOException { String applicationName = this.nameFactory.getApplicationName(); createApplication(this.cloudFoundryOperations, applicationName) - .then(getApplicationId(this.cloudFoundryClient, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId))) - .flatMap(function((applicationId, dropletId) -> createTaskId(this.cloudFoundryClient, applicationId))) - .flatMap(taskId -> this.cloudFoundryClient.tasks() - .cancel(CancelTaskRequest.builder() - .taskId(taskId) - .build()) - .map(CancelTaskResponse::getState)) - .as(StepVerifier::create) - .expectNext(TaskState.CANCELING) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryClient, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + createTaskId(this.cloudFoundryClient, applicationId))) + .flatMap( + taskId -> + this.cloudFoundryClient + .tasks() + .cancel(CancelTaskRequest.builder().taskId(taskId).build()) + .map(CancelTaskResponse::getState)) + .as(StepVerifier::create) + .expectNext(TaskState.CANCELING) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -84,22 +88,27 @@ public void create() throws IOException { String applicationName = this.nameFactory.getApplicationName(); createApplication(this.cloudFoundryOperations, applicationName) - .then(getApplicationId(this.cloudFoundryClient, applicationName)) - .delayUntil(applicationId -> getDropletId(this.cloudFoundryClient, applicationId)) - .flatMap(applicationId -> this.cloudFoundryClient.tasks() - .create(CreateTaskRequest.builder() - .applicationId(applicationId) - .command("ls") - .diskInMb(129) - .memoryInMb(129) - .build())) - .thenMany(requestListTasks(this.cloudFoundryClient) - .filter(task -> 129 == task.getMemoryInMb()) - .map(TaskResource::getDiskInMb)) - .as(StepVerifier::create) - .expectNext(129) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryClient, applicationName)) + .delayUntil(applicationId -> getDropletId(this.cloudFoundryClient, applicationId)) + .flatMap( + applicationId -> + this.cloudFoundryClient + .tasks() + .create( + CreateTaskRequest.builder() + .applicationId(applicationId) + .command("ls") + .diskInMb(129) + .memoryInMb(129) + .build())) + .thenMany( + requestListTasks(this.cloudFoundryClient) + .filter(task -> 129 == task.getMemoryInMb()) + .map(TaskResource::getDiskInMb)) + .as(StepVerifier::create) + .expectNext(129) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -107,20 +116,26 @@ public void get() throws IOException { String applicationName = this.nameFactory.getApplicationName(); createApplication(this.cloudFoundryOperations, applicationName) - .then(getApplicationId(this.cloudFoundryClient, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId))) - .flatMap(function((applicationId, dropletId) -> createTaskId(this.cloudFoundryClient, applicationId))) - .flatMap(taskId -> this.cloudFoundryClient.tasks() - .get(GetTaskRequest.builder() - .taskId(taskId) - .build()) - .map(GetTaskResponse::getCommand)) - .as(StepVerifier::create) - .expectNext("ls") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryClient, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + createTaskId(this.cloudFoundryClient, applicationId))) + .flatMap( + taskId -> + this.cloudFoundryClient + .tasks() + .get(GetTaskRequest.builder().taskId(taskId).build()) + .map(GetTaskResponse::getCommand)) + .as(StepVerifier::create) + .expectNext("ls") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -128,22 +143,32 @@ public void list() throws IOException { String applicationName = this.nameFactory.getApplicationName(); createApplication(this.cloudFoundryOperations, applicationName) - .then(getApplicationId(this.cloudFoundryClient, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId))) - .flatMap(function((applicationId, dropletId) -> requestCreateTask(this.cloudFoundryClient, applicationId) - .thenReturn(dropletId))) - .flatMapMany(dropletId -> PaginationUtils. - requestClientV3Resources(page -> this.cloudFoundryClient.tasks() - .list(ListTasksRequest.builder() - .page(page) - .build())) - .filter(task -> dropletId.equals(task.getDropletId()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryClient, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + requestCreateTask(this.cloudFoundryClient, applicationId) + .thenReturn(dropletId))) + .flatMapMany( + dropletId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .tasks() + .list( + ListTasksRequest.builder() + .page(page) + .build())) + .filter(task -> dropletId.equals(task.getDropletId()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -151,22 +176,38 @@ public void listFilterByApplication() throws IOException { String applicationName = this.nameFactory.getApplicationName(); createApplication(this.cloudFoundryOperations, applicationName) - .then(getApplicationId(this.cloudFoundryClient, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId))) - .delayUntil(function((applicationId, dropletId) -> requestCreateTask(this.cloudFoundryClient, applicationId))) - .flatMapMany(function((applicationId, dropletId) -> PaginationUtils. - requestClientV3Resources(page -> this.cloudFoundryClient.tasks() - .list(ListTasksRequest.builder() - .applicationId(applicationId) - .page(page) - .build())) - .filter(task -> dropletId.equals(task.getDropletId())))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryClient, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .delayUntil( + function( + (applicationId, dropletId) -> + requestCreateTask(this.cloudFoundryClient, applicationId))) + .flatMapMany( + function( + (applicationId, dropletId) -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .tasks() + .list( + ListTasksRequest + .builder() + .applicationId( + applicationId) + .page(page) + .build())) + .filter( + task -> + dropletId.equals( + task.getDropletId())))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -174,22 +215,32 @@ public void listFilterByName() throws IOException { String applicationName = this.nameFactory.getApplicationName(); createApplication(this.cloudFoundryOperations, applicationName) - .then(getApplicationId(this.cloudFoundryClient, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId))) - .flatMap(function((applicationId, dropletId) -> createTaskId(this.cloudFoundryClient, applicationId))) - .flatMap(taskId -> getTaskName(this.cloudFoundryClient, taskId)) - .flatMapMany(taskName -> PaginationUtils. - requestClientV3Resources(page -> this.cloudFoundryClient.tasks() - .list(ListTasksRequest.builder() - .name(taskName) - .page(page) - .build()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryClient, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + createTaskId(this.cloudFoundryClient, applicationId))) + .flatMap(taskId -> getTaskName(this.cloudFoundryClient, taskId)) + .flatMapMany( + taskName -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .tasks() + .list( + ListTasksRequest.builder() + .name(taskName) + .page(page) + .build()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -197,84 +248,109 @@ public void listFilterByState() throws IOException { String applicationName = this.nameFactory.getApplicationName(); createApplication(this.cloudFoundryOperations, applicationName) - .then(getApplicationId(this.cloudFoundryClient, applicationName)) - .flatMap(applicationId -> Mono.zip( - Mono.just(applicationId), - getDropletId(this.cloudFoundryClient, applicationId))) - .flatMap(function((applicationId, dropletId) -> requestCreateTask(this.cloudFoundryClient, applicationId) - .thenReturn(dropletId))) - .flatMapMany(dropletId -> PaginationUtils. - requestClientV3Resources(page -> this.cloudFoundryClient.tasks() - .list(ListTasksRequest.builder() - .state(RUNNING) - .page(page) - .build())) - .filter(task -> dropletId.equals(task.getDropletId()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(getApplicationId(this.cloudFoundryClient, applicationName)) + .flatMap( + applicationId -> + Mono.zip( + Mono.just(applicationId), + getDropletId(this.cloudFoundryClient, applicationId))) + .flatMap( + function( + (applicationId, dropletId) -> + requestCreateTask(this.cloudFoundryClient, applicationId) + .thenReturn(dropletId))) + .flatMapMany( + dropletId -> + PaginationUtils.requestClientV3Resources( + page -> + this.cloudFoundryClient + .tasks() + .list( + ListTasksRequest.builder() + .state(RUNNING) + .page(page) + .build())) + .filter(task -> dropletId.equals(task.getDropletId()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplication(CloudFoundryOperations cloudFoundryOperations, String name) throws IOException { - return cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(256) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(name) - .noStart(false) - .build()); + private static Mono createApplication( + CloudFoundryOperations cloudFoundryOperations, String name) throws IOException { + return cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(256) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(name) + .noStart(false) + .build()); } - private static Mono createTaskId(CloudFoundryClient cloudFoundryClient, String applicationId) { - return requestCreateTask(cloudFoundryClient, applicationId) - .map(CreateTaskResponse::getId); + private static Mono createTaskId( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return requestCreateTask(cloudFoundryClient, applicationId).map(CreateTaskResponse::getId); } - private static Mono getApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName) { - return PaginationUtils.requestClientV3Resources(page -> cloudFoundryClient.applicationsV3() - .list(ListApplicationsRequest.builder() - .name(applicationName) - .build())) - .single() - .map(ApplicationResource::getId); + private static Mono getApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName) { + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .applicationsV3() + .list( + ListApplicationsRequest.builder() + .name(applicationName) + .build())) + .single() + .map(ApplicationResource::getId); } - private static Mono getDropletId(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.applicationsV3() - .getCurrentDroplet(GetApplicationCurrentDropletRequest.builder() - .applicationId(applicationId) - .build()) - .map(GetApplicationCurrentDropletResponse::getId); + private static Mono getDropletId( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .applicationsV3() + .getCurrentDroplet( + GetApplicationCurrentDropletRequest.builder() + .applicationId(applicationId) + .build()) + .map(GetApplicationCurrentDropletResponse::getId); } private static Mono getTaskName(CloudFoundryClient cloudFoundryClient, String taskId) { - return cloudFoundryClient.tasks() - .get(GetTaskRequest.builder() - .taskId(taskId) - .build()) - .map(GetTaskResponse::getName); + return cloudFoundryClient + .tasks() + .get(GetTaskRequest.builder().taskId(taskId).build()) + .map(GetTaskResponse::getName); } - private static Mono requestCreateTask(CloudFoundryClient cloudFoundryClient, String applicationId) { - return cloudFoundryClient.tasks() - .create(CreateTaskRequest.builder() - .applicationId(applicationId) - .command("ls") - .diskInMb(64) - .memoryInMb(67) - .build()); + private static Mono requestCreateTask( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return cloudFoundryClient + .tasks() + .create( + CreateTaskRequest.builder() + .applicationId(applicationId) + .command("ls") + .diskInMb(64) + .memoryInMb(67) + .build()); } private static Flux requestListTasks(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils. - requestClientV3Resources(page -> cloudFoundryClient.tasks() - .list(ListTasksRequest.builder() - .page(page) - .build())); + return PaginationUtils.requestClientV3Resources( + page -> + cloudFoundryClient + .tasks() + .list(ListTasksRequest.builder().page(page).build())); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/logcache/v1/LogCacheTest.java b/integration-test/src/test/java/org/cloudfoundry/logcache/v1/LogCacheTest.java index 2d0cedf36c3..731d487a82f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/logcache/v1/LogCacheTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/logcache/v1/LogCacheTest.java @@ -16,40 +16,36 @@ package org.cloudfoundry.logcache.v1; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.within; +import static org.cloudfoundry.util.DelayUtils.exponentialBackOff; + +import java.math.BigInteger; +import java.time.Duration; +import java.util.Random; +import java.util.function.Predicate; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.ApplicationUtils; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.math.BigInteger; -import java.time.Duration; -import java.util.Random; -import java.util.function.Predicate; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.within; -import static org.cloudfoundry.util.DelayUtils.exponentialBackOff; - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_9) public class LogCacheTest extends AbstractIntegrationTest implements InitializingBean { - @Autowired - LogCacheClient logCacheClient; + @Autowired LogCacheClient logCacheClient; - @Autowired - Random random; + @Autowired Random random; - @Autowired - private Mono testLogCacheApp; + @Autowired private Mono testLogCacheApp; private ApplicationUtils.ApplicationMetadata testLogCacheAppMetadata; - @Autowired - private TestLogCacheEndpoints testLogCacheEndpoints; + @Autowired private TestLogCacheEndpoints testLogCacheEndpoints; @Override public void afterPropertiesSet() { @@ -58,31 +54,32 @@ public void afterPropertiesSet() { @Test public void info() { - this.logCacheClient.info(InfoRequest.builder().build()) - .as(StepVerifier::create) - .assertNext(response -> { - assertThat(response).isNotNull(); - assertThat(response.getVersion()) - .isNotBlank(); - assertThat(response.vmUptime()) - .isNotNull() - .isGreaterThan(1); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.logCacheClient + .info(InfoRequest.builder().build()) + .as(StepVerifier::create) + .assertNext( + response -> { + assertThat(response).isNotNull(); + assertThat(response.getVersion()).isNotBlank(); + assertThat(response.vmUptime()).isNotNull().isGreaterThan(1); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void meta() { - this.logCacheClient.meta(MetaRequest.builder().build()) - .as(StepVerifier::create) - .assertNext(response -> { - assertThat(response).isNotNull(); - assertThat(response.getMeta()) - .containsKey(this.testLogCacheAppMetadata.applicationId); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.logCacheClient + .meta(MetaRequest.builder().build()) + .as(StepVerifier::create) + .assertNext( + response -> { + assertThat(response).isNotNull(); + assertThat(response.getMeta()) + .containsKey(this.testLogCacheAppMetadata.applicationId); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -90,12 +87,18 @@ public void readCounter() { final String name = this.nameFactory.getName("counter-"); final int delta = this.random.nextInt(1000); - this.testLogCacheEndpoints.counter(name, delta) - .then(read(EnvelopeType.COUNTER, envelope -> hasCounter(envelope) && name.equals(envelope.getCounter().getName()))) - .as(StepVerifier::create) - .assertNext(response -> assertCounter(response, name, delta)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.testLogCacheEndpoints + .counter(name, delta) + .then( + read( + EnvelopeType.COUNTER, + envelope -> + hasCounter(envelope) + && name.equals(envelope.getCounter().getName()))) + .as(StepVerifier::create) + .assertNext(response -> assertCounter(response, name, delta)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -103,12 +106,13 @@ public void readEvent() { final String title = this.nameFactory.getName("event-"); final String body = "This is the body. " + new BigInteger(1024, this.random).toString(32); - this.testLogCacheEndpoints.event(title, body) - .then(read(EnvelopeType.EVENT, this::hasEvent)) - .as(StepVerifier::create) - .assertNext(response -> assertEvent(response, title, body)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.testLogCacheEndpoints + .event(title, body) + .then(read(EnvelopeType.EVENT, this::hasEvent)) + .as(StepVerifier::create) + .assertNext(response -> assertEvent(response, title, body)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -116,24 +120,39 @@ public void readGauge() { final String gaugeName = this.nameFactory.getName("gauge-"); final Double value = this.random.nextDouble() % 100; - this.testLogCacheEndpoints.gauge(gaugeName, value) - .then(read(EnvelopeType.GAUGE, envelope -> hasGauge(envelope) && envelope.getGauge().getMetrics().containsKey(gaugeName))) - .as(StepVerifier::create) - .assertNext(response -> assertGauge(response, gaugeName, value)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.testLogCacheEndpoints + .gauge(gaugeName, value) + .then( + read( + EnvelopeType.GAUGE, + envelope -> + hasGauge(envelope) + && envelope.getGauge() + .getMetrics() + .containsKey(gaugeName))) + .as(StepVerifier::create) + .assertNext(response -> assertGauge(response, gaugeName, value)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void readLogs() { final String logMessage = this.nameFactory.getName("log-"); - this.testLogCacheEndpoints.log(logMessage) - .then(read(EnvelopeType.LOG, envelope -> hasLog(envelope) && logMessage.equals(envelope.getLog().getPayloadAsText()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.testLogCacheEndpoints + .log(logMessage) + .then( + read( + EnvelopeType.LOG, + envelope -> + hasLog(envelope) + && logMessage.equals( + envelope.getLog().getPayloadAsText()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } private void assertCounter(Envelope envelope, String name, int delta) { @@ -156,7 +175,7 @@ private void assertEvent(Envelope envelope, String title, String body) { private void assertGauge(Envelope envelope, String gaugeName, Double value) { assertThat(envelope.getGauge().getMetrics().get(gaugeName).getValue()) - .isCloseTo(value, within(0.001)); + .isCloseTo(value, within(0.001)); } private void assertResponse(ReadResponse readResponse) { @@ -182,15 +201,25 @@ private boolean hasLog(Envelope envelope) { } private Mono read(EnvelopeType envelopeType, Predicate filter) { - return this.logCacheClient.read(ReadRequest.builder() - .sourceId(this.testLogCacheAppMetadata.applicationId) - .envelopeType(envelopeType) - .limit(1000) - .build()) - .doOnNext(this::assertResponse) - .flatMap(response -> Mono.justOrEmpty(response.getEnvelopes().getBatch().stream().filter(filter).findFirst())) - .repeatWhenEmpty(exponentialBackOff(Duration.ofSeconds(1), Duration.ofSeconds(5), Duration.ofMinutes(1))) - .doOnNext(this::assertEnvelope); + return this.logCacheClient + .read( + ReadRequest.builder() + .sourceId(this.testLogCacheAppMetadata.applicationId) + .envelopeType(envelopeType) + .limit(1000) + .build()) + .doOnNext(this::assertResponse) + .flatMap( + response -> + Mono.justOrEmpty( + response.getEnvelopes().getBatch().stream() + .filter(filter) + .findFirst())) + .repeatWhenEmpty( + exponentialBackOff( + Duration.ofSeconds(1), + Duration.ofSeconds(5), + Duration.ofMinutes(1))) + .doOnNext(this::assertEnvelope); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/logcache/v1/TestLogCacheEndpoints.java b/integration-test/src/test/java/org/cloudfoundry/logcache/v1/TestLogCacheEndpoints.java index d1f3cbb5012..64fb246eb2a 100644 --- a/integration-test/src/test/java/org/cloudfoundry/logcache/v1/TestLogCacheEndpoints.java +++ b/integration-test/src/test/java/org/cloudfoundry/logcache/v1/TestLogCacheEndpoints.java @@ -16,6 +16,9 @@ package org.cloudfoundry.logcache.v1; +import java.util.HashMap; +import java.util.function.Function; +import java.util.stream.Stream; import org.cloudfoundry.reactor.ConnectionContext; import org.cloudfoundry.reactor.TokenProvider; import org.cloudfoundry.reactor.client.QueryBuilder; @@ -25,62 +28,53 @@ import org.springframework.web.util.UriComponentsBuilder; import reactor.core.publisher.Mono; -import java.util.HashMap; -import java.util.function.Function; -import java.util.stream.Stream; - public class TestLogCacheEndpoints extends AbstractReactorOperations { - public TestLogCacheEndpoints(ConnectionContext connectionContext, Mono root, TokenProvider tokenProvider) { + public TestLogCacheEndpoints( + ConnectionContext connectionContext, Mono root, TokenProvider tokenProvider) { super(connectionContext, root, tokenProvider, new HashMap<>()); } Mono counter(String name, long delta) { - return get(CounterRequest.builder() - .name(name) - .delta(delta) - .build(), "counter"); + return get(CounterRequest.builder().name(name).delta(delta).build(), "counter"); } Mono event(String title, String body) { - return get(EventRequest.builder() - .title(title) - .body(body) - .build(), "event"); + return get(EventRequest.builder().title(title).body(body).build(), "event"); } Mono gauge(String name, Double value) { - return get(GaugeRequest.builder() - .name(name) - .value(value.toString()) - .build(), "gauge"); + return get(GaugeRequest.builder().name(name).value(value.toString()).build(), "gauge"); } Mono log(String message) { - return get(LogRequest.builder() - .message(message) - .build(), "log"); + return get(LogRequest.builder().message(message).build(), "log"); } - private Function buildPathSegments(String[] pathSegments) { + private Function buildPathSegments( + String[] pathSegments) { return builder -> builder.pathSegment(pathSegments); } private Mono get(Object requestPayload, String... pathSegments) { return createOperator() - .flatMap(operator -> operator.get() - .uri(buildPathSegments(pathSegments).andThen(queryTransformer(requestPayload))) - .response() - .get()) - .then(); + .flatMap( + operator -> + operator.get() + .uri( + buildPathSegments(pathSegments) + .andThen(queryTransformer(requestPayload))) + .response() + .get()) + .then(); } - private Function queryTransformer(Object requestPayload) { + private Function queryTransformer( + Object requestPayload) { return builder -> { Stream parameters = new QueryBuilder().build(requestPayload); UriQueryParameters.set(builder, parameters); return builder; }; } - -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java b/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java index fcefb58ceda..eaa9916908a 100644 --- a/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/networking/v1/PoliciesTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.networking.v1; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -32,24 +35,18 @@ import org.cloudfoundry.networking.v1.policies.Ports; import org.cloudfoundry.networking.v1.policies.Source; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class PoliciesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private NetworkingClient networkingClient; + @Autowired private NetworkingClient networkingClient; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) @Test @@ -60,36 +57,65 @@ public void create() { Integer endPort = this.nameFactory.getPort(); this.spaceId - .flatMapMany(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, destinationApplicationName, spaceId), - createApplicationId(this.cloudFoundryClient, sourceApplicationName, spaceId) - )) - .flatMap(function((destinationApplicationId, sourceApplicationId) -> this.networkingClient.policies() - .create(CreatePoliciesRequest.builder() - .policy(Policy.builder() - .destination(Destination.builder() - .id(destinationApplicationId) - .ports(Ports.builder() - .end(endPort) - .start(startPort) - .build()) - .protocol("tcp") - .build()) - .source(Source.builder() - .id(sourceApplicationId) - .build()) - .build()) - .build()) - .thenReturn(destinationApplicationId))) - .flatMap(destinationApplicationId -> requestListPolicies(this.networkingClient) - .flatMapIterable(ListPoliciesResponse::getPolicies) - .filter(policy -> destinationApplicationId.equals(policy.getDestination().getId())) - .single()) - .map(policy -> policy.getDestination().getPorts().getStart()) - .as(StepVerifier::create) - .expectNext(startPort) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + destinationApplicationName, + spaceId), + createApplicationId( + this.cloudFoundryClient, + sourceApplicationName, + spaceId))) + .flatMap( + function( + (destinationApplicationId, sourceApplicationId) -> + this.networkingClient + .policies() + .create( + CreatePoliciesRequest.builder() + .policy( + Policy.builder() + .destination( + Destination + .builder() + .id( + destinationApplicationId) + .ports( + Ports + .builder() + .end( + endPort) + .start( + startPort) + .build()) + .protocol( + "tcp") + .build()) + .source( + Source + .builder() + .id( + sourceApplicationId) + .build()) + .build()) + .build()) + .thenReturn(destinationApplicationId))) + .flatMap( + destinationApplicationId -> + requestListPolicies(this.networkingClient) + .flatMapIterable(ListPoliciesResponse::getPolicies) + .filter( + policy -> + destinationApplicationId.equals( + policy.getDestination().getId())) + .single()) + .map(policy -> policy.getDestination().getPorts().getStart()) + .as(StepVerifier::create) + .expectNext(startPort) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) @@ -100,34 +126,71 @@ public void delete() { Integer port = this.nameFactory.getPort(); this.spaceId - .flatMapMany(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, destinationApplicationName, spaceId), - createApplicationId(this.cloudFoundryClient, sourceApplicationName, spaceId) - )) - .delayUntil(function((destinationApplicationId, sourceApplicationId) -> requestCreatePolicy(this.networkingClient, destinationApplicationId, port, sourceApplicationId))) - .flatMap(function((destinationApplicationId, sourceApplicationId) -> this.networkingClient.policies() - .delete(DeletePoliciesRequest.builder() - .policy(Policy.builder() - .destination(Destination.builder() - .id(destinationApplicationId) - .ports(Ports.builder() - .end(port) - .start(port) - .build()) - .protocol("tcp") - .build()) - .source(Source.builder() - .id(sourceApplicationId) - .build()) - .build()) - .build()))) - .then(requestListPolicies(this.networkingClient) - .flatMapIterable(ListPoliciesResponse::getPolicies) - .filter(policy -> port.equals(policy.getDestination().getPorts().getStart())) - .singleOrEmpty()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + destinationApplicationName, + spaceId), + createApplicationId( + this.cloudFoundryClient, + sourceApplicationName, + spaceId))) + .delayUntil( + function( + (destinationApplicationId, sourceApplicationId) -> + requestCreatePolicy( + this.networkingClient, + destinationApplicationId, + port, + sourceApplicationId))) + .flatMap( + function( + (destinationApplicationId, sourceApplicationId) -> + this.networkingClient + .policies() + .delete( + DeletePoliciesRequest.builder() + .policy( + Policy.builder() + .destination( + Destination + .builder() + .id( + destinationApplicationId) + .ports( + Ports + .builder() + .end( + port) + .start( + port) + .build()) + .protocol( + "tcp") + .build()) + .source( + Source + .builder() + .id( + sourceApplicationId) + .build()) + .build()) + .build()))) + .then( + requestListPolicies(this.networkingClient) + .flatMapIterable(ListPoliciesResponse::getPolicies) + .filter( + policy -> + port.equals( + policy.getDestination() + .getPorts() + .getStart())) + .singleOrEmpty()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) @@ -138,22 +201,42 @@ public void list() { Integer port = this.nameFactory.getPort(); this.spaceId - .flatMapMany(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, destinationApplicationName, spaceId), - createApplicationId(this.cloudFoundryClient, sourceApplicationName, spaceId) - )) - .flatMap(function((destinationApplicationId, sourceApplicationId) -> requestCreatePolicy(this.networkingClient, destinationApplicationId, port, sourceApplicationId))) - .then(this.networkingClient.policies() - .list(ListPoliciesRequest.builder() - .build()) - .flatMapIterable(ListPoliciesResponse::getPolicies) - .filter(policy -> port.equals(policy.getDestination().getPorts().getStart())) - .single()) - .map(policy -> policy.getDestination().getPorts().getStart()) - .as(StepVerifier::create) - .expectNext(port) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + destinationApplicationName, + spaceId), + createApplicationId( + this.cloudFoundryClient, + sourceApplicationName, + spaceId))) + .flatMap( + function( + (destinationApplicationId, sourceApplicationId) -> + requestCreatePolicy( + this.networkingClient, + destinationApplicationId, + port, + sourceApplicationId))) + .then( + this.networkingClient + .policies() + .list(ListPoliciesRequest.builder().build()) + .flatMapIterable(ListPoliciesResponse::getPolicies) + .filter( + policy -> + port.equals( + policy.getDestination() + .getPorts() + .getStart())) + .single()) + .map(policy -> policy.getDestination().getPorts().getStart()) + .as(StepVerifier::create) + .expectNext(port) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) @@ -164,64 +247,98 @@ public void listFiltered() { Integer port = this.nameFactory.getPort(); this.spaceId - .flatMapMany(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, destinationApplicationName, spaceId), - createApplicationId(this.cloudFoundryClient, sourceApplicationName, spaceId) - )) - .flatMap(function((destinationApplicationId, sourceApplicationId) -> requestCreatePolicy(this.networkingClient, destinationApplicationId, port, sourceApplicationId) - .thenReturn(destinationApplicationId))) - .flatMap(destinationApplicationId -> this.networkingClient.policies() - .list(ListPoliciesRequest.builder() - .policyGroupId(destinationApplicationId) - .build()) - .flatMapIterable(ListPoliciesResponse::getPolicies) - .map(policy -> policy.getDestination().getPorts().getStart())) - .as(StepVerifier::create) - .expectNext(port) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + destinationApplicationName, + spaceId), + createApplicationId( + this.cloudFoundryClient, + sourceApplicationName, + spaceId))) + .flatMap( + function( + (destinationApplicationId, sourceApplicationId) -> + requestCreatePolicy( + this.networkingClient, + destinationApplicationId, + port, + sourceApplicationId) + .thenReturn(destinationApplicationId))) + .flatMap( + destinationApplicationId -> + this.networkingClient + .policies() + .list( + ListPoliciesRequest.builder() + .policyGroupId(destinationApplicationId) + .build()) + .flatMapIterable(ListPoliciesResponse::getPolicies) + .map( + policy -> + policy.getDestination() + .getPorts() + .getStart())) + .as(StepVerifier::create) + .expectNext(port) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .buildpack("staticfile_buildpack") + .diego(true) + .diskQuota(512) + .memory(64) + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Mono requestCreatePolicy(NetworkingClient networkingClient, String destinationApplicationId, Integer port, String sourceApplicationId) { - return networkingClient.policies() - .create(CreatePoliciesRequest.builder() - .policy(Policy.builder() - .destination(Destination.builder() - .id(destinationApplicationId) - .ports(Ports.builder() - .end(port) - .start(port) - .build()) - .protocol("tcp") - .build()) - .source(Source.builder() - .id(sourceApplicationId) - .build()) - .build()) - .build()); + private static Mono requestCreatePolicy( + NetworkingClient networkingClient, + String destinationApplicationId, + Integer port, + String sourceApplicationId) { + return networkingClient + .policies() + .create( + CreatePoliciesRequest.builder() + .policy( + Policy.builder() + .destination( + Destination.builder() + .id(destinationApplicationId) + .ports( + Ports.builder() + .end(port) + .start(port) + .build()) + .protocol("tcp") + .build()) + .source( + Source.builder() + .id(sourceApplicationId) + .build()) + .build()) + .build()); } - private static Mono requestListPolicies(NetworkingClient networkingClient) { - return networkingClient.policies() - .list(ListPoliciesRequest.builder() - .build()); + private static Mono requestListPolicies( + NetworkingClient networkingClient) { + return networkingClient.policies().list(ListPoliciesRequest.builder().build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java b/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java index bfb95cf3263..6393f0c2d0c 100644 --- a/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/networking/v1/TagsTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.networking.v1; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -31,24 +34,18 @@ import org.cloudfoundry.networking.v1.tags.ListTagsRequest; import org.cloudfoundry.networking.v1.tags.ListTagsResponse; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.util.tuple.TupleUtils.function; - public final class TagsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private NetworkingClient networkingClient; + @Autowired private NetworkingClient networkingClient; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) @Test @@ -58,57 +55,89 @@ public void create() { Integer port = this.nameFactory.getPort(); this.spaceId - .flatMapMany(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, destinationApplicationName, spaceId), - createApplicationId(this.cloudFoundryClient, sourceApplicationName, spaceId) - )) - .flatMap(function((destinationApplicationId, sourceApplicationId) -> requestCreatePolicy(this.networkingClient, destinationApplicationId, port, sourceApplicationId) - .thenReturn(destinationApplicationId))) - .flatMap(destinationApplicationId -> this.networkingClient.tags() - .list(ListTagsRequest.builder() - .build()) - .flatMapIterable(ListTagsResponse::getTags) - .filter(tag -> destinationApplicationId.equals(tag.getId()))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + destinationApplicationName, + spaceId), + createApplicationId( + this.cloudFoundryClient, + sourceApplicationName, + spaceId))) + .flatMap( + function( + (destinationApplicationId, sourceApplicationId) -> + requestCreatePolicy( + this.networkingClient, + destinationApplicationId, + port, + sourceApplicationId) + .thenReturn(destinationApplicationId))) + .flatMap( + destinationApplicationId -> + this.networkingClient + .tags() + .list(ListTagsRequest.builder().build()) + .flatMapIterable(ListTagsResponse::getTags) + .filter( + tag -> + destinationApplicationId.equals( + tag.getId()))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .buildpack("staticfile_buildpack") + .diego(true) + .diskQuota(512) + .memory(64) + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Mono requestCreatePolicy(NetworkingClient networkingClient, String destinationApplicationId, Integer port, String sourceApplicationId) { - return networkingClient.policies() - .create(CreatePoliciesRequest.builder() - .policy(Policy.builder() - .destination(Destination.builder() - .id(destinationApplicationId) - .ports(Ports.builder() - .end(port) - .start(port) - .build()) - .protocol("tcp") - .build()) - .source(Source.builder() - .id(sourceApplicationId) - .build()) - .build()) - .build()); + private static Mono requestCreatePolicy( + NetworkingClient networkingClient, + String destinationApplicationId, + Integer port, + String sourceApplicationId) { + return networkingClient + .policies() + .create( + CreatePoliciesRequest.builder() + .policy( + Policy.builder() + .destination( + Destination.builder() + .id(destinationApplicationId) + .ports( + Ports.builder() + .end(port) + .start(port) + .build()) + .protocol("tcp") + .build()) + .source( + Source.builder() + .id(sourceApplicationId) + .build()) + .build()) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/AdvancedTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/AdvancedTest.java index 99d4b842ebc..733e95d6bc9 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/AdvancedTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/AdvancedTest.java @@ -16,27 +16,26 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class AdvancedTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; @Test public void sshCode() { - this.cloudFoundryOperations.advanced() - .sshCode() - .as(StepVerifier::create) - .consumeNextWith(actual -> assertThat(actual.length()).isGreaterThanOrEqualTo(6)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .advanced() + .sshCode() + .as(StepVerifier::create) + .consumeNextWith(actual -> assertThat(actual.length()).isGreaterThanOrEqualTo(6)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/ApplicationsTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/ApplicationsTest.java index 62238e0c74b..2a87f6c5880 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/ApplicationsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/ApplicationsTest.java @@ -16,6 +16,15 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Map; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -68,37 +77,24 @@ import org.cloudfoundry.operations.services.GetServiceInstanceRequest; import org.cloudfoundry.operations.services.ServiceInstance; import org.cloudfoundry.util.FluentMap; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import static org.assertj.core.api.Assertions.assertThat; - public final class ApplicationsTest extends AbstractIntegrationTest { private static final String DEFAULT_ROUTER_GROUP = "default-tcp"; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; - @Autowired - private String organizationName; + @Autowired private String organizationName; - @Autowired - private String planName; + @Autowired private String planName; - @Autowired - private String serviceName; + @Autowired private String serviceName; @Test public void copySource() throws IOException { @@ -106,55 +102,79 @@ public void copySource() throws IOException { String targetName = this.nameFactory.getApplicationName(); Mono.when( - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), sourceName, false), - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), targetName, true) - ) - .then(this.cloudFoundryOperations.applications() - .copySource(CopySourceApplicationRequest.builder() - .name(sourceName) - .restart(true) - .targetName(targetName) - .build())) - .then(requestGetApplication(this.cloudFoundryOperations, targetName)) - .map(ApplicationDetail::getRequestedState) - .as(StepVerifier::create) - .expectNext("STARTED") - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + sourceName, + false), + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + targetName, + true)) + .then( + this.cloudFoundryOperations + .applications() + .copySource( + CopySourceApplicationRequest.builder() + .name(sourceName) + .restart(true) + .targetName(targetName) + .build())) + .then(requestGetApplication(this.cloudFoundryOperations, targetName)) + .map(ApplicationDetail::getRequestedState) + .as(StepVerifier::create) + .expectNext("STARTED") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void deleteApplication() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .delete(DeleteApplicationRequest.builder() - .name(applicationName) - .build())) - .thenMany(requestListApplications(this.cloudFoundryOperations)) - .filter(response -> applicationName.equals(response.getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .delete( + DeleteApplicationRequest.builder() + .name(applicationName) + .build())) + .thenMany(requestListApplications(this.cloudFoundryOperations)) + .filter(response -> applicationName.equals(response.getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void deleteApplicationAndRoutes() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .delete(DeleteApplicationRequest.builder() - .name(applicationName) - .deleteRoutes(true) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .map(org.cloudfoundry.operations.routes.Route::getApplications) - .filter(applicationName::equals) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .delete( + DeleteApplicationRequest.builder() + .name(applicationName) + .deleteRoutes(true) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .map(org.cloudfoundry.operations.routes.Route::getApplications) + .filter(applicationName::equals) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -162,175 +182,245 @@ public void deleteApplicationWithServiceBindings() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(bindServiceToApplication(this.cloudFoundryOperations, applicationName, serviceInstanceName)) - .then(this.cloudFoundryOperations.applications() - .delete(DeleteApplicationRequest.builder() - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + bindServiceToApplication( + this.cloudFoundryOperations, applicationName, serviceInstanceName)) + .then( + this.cloudFoundryOperations + .applications() + .delete( + DeleteApplicationRequest.builder() + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void disableSsh() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .disableSsh(DisableApplicationSshRequest.builder() - .name(applicationName) - .build())) - .then(requestSshEnabled(this.cloudFoundryOperations, applicationName)) - .as(StepVerifier::create) - .expectNext(false) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .disableSsh( + DisableApplicationSshRequest.builder() + .name(applicationName) + .build())) + .then(requestSshEnabled(this.cloudFoundryOperations, applicationName)) + .as(StepVerifier::create) + .expectNext(false) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void enableSsh() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .enableSsh(EnableApplicationSshRequest.builder() - .name(applicationName) - .build())) - .then(requestSshEnabled(this.cloudFoundryOperations, applicationName)) - .as(StepVerifier::create) - .expectNext(true) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .enableSsh( + EnableApplicationSshRequest.builder() + .name(applicationName) + .build())) + .then(requestSshEnabled(this.cloudFoundryOperations, applicationName)) + .as(StepVerifier::create) + .expectNext(true) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void get() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .get(GetApplicationRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationDetail::getName) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .get(GetApplicationRequest.builder().name(applicationName).build())) + .map(ApplicationDetail::getName) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getEvents() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - .thenMany(this.cloudFoundryOperations.applications() - .getEvents(GetApplicationEventsRequest.builder() - .name(applicationName) - .build()) - .next()) - .map(ApplicationEvent::getEvent) - .as(StepVerifier::create) - .expectNext("audit.app.update") - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true) + .thenMany( + this.cloudFoundryOperations + .applications() + .getEvents( + GetApplicationEventsRequest.builder() + .name(applicationName) + .build()) + .next()) + .map(ApplicationEvent::getEvent) + .as(StepVerifier::create) + .expectNext("audit.app.update") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getHealthCheck() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - .then(this.cloudFoundryOperations.applications() - .getHealthCheck(GetApplicationHealthCheckRequest.builder() - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectNext(ApplicationHealthCheck.NONE) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true) + .then( + this.cloudFoundryOperations + .applications() + .getHealthCheck( + GetApplicationHealthCheckRequest.builder() + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectNext(ApplicationHealthCheck.NONE) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getManifest() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - .then(this.cloudFoundryOperations.applications() - .getApplicationManifest(GetApplicationManifestRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationManifest::getName) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true) + .then( + this.cloudFoundryOperations + .applications() + .getApplicationManifest( + GetApplicationManifestRequest.builder() + .name(applicationName) + .build())) + .map(ApplicationManifest::getName) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getManifestForTcpRoute() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - .then(this.cloudFoundryOperations.applications() - .getApplicationManifest(GetApplicationManifestRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationManifest::getName) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true) + .then( + this.cloudFoundryOperations + .applications() + .getApplicationManifest( + GetApplicationManifestRequest.builder() + .name(applicationName) + .build())) + .map(ApplicationManifest::getName) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getMultipleBuildpacks() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplicationPhp(this.cloudFoundryOperations, new ClassPathResource("test-php.zip").getFile().toPath(), applicationName, true) - .then(this.cloudFoundryOperations.applications() - .get(GetApplicationRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationDetail::getBuildpacks) - .as(StepVerifier::create) - .expectNext(Arrays.asList("staticfile_buildpack", "php_buildpack")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplicationPhp( + this.cloudFoundryOperations, + new ClassPathResource("test-php.zip").getFile().toPath(), + applicationName, + true) + .then( + this.cloudFoundryOperations + .applications() + .get(GetApplicationRequest.builder().name(applicationName).build())) + .map(ApplicationDetail::getBuildpacks) + .as(StepVerifier::create) + .expectNext(Arrays.asList("staticfile_buildpack", "php_buildpack")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getMultipleBuildpacksManifest() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplicationPhp(this.cloudFoundryOperations, new ClassPathResource("test-php.zip").getFile().toPath(), applicationName, true) - .then(this.cloudFoundryOperations.applications() - .getApplicationManifest(GetApplicationManifestRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationManifest::getBuildpacks) - .as(StepVerifier::create) - .expectNext(Arrays.asList("staticfile_buildpack", "php_buildpack")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplicationPhp( + this.cloudFoundryOperations, + new ClassPathResource("test-php.zip").getFile().toPath(), + applicationName, + true) + .then( + this.cloudFoundryOperations + .applications() + .getApplicationManifest( + GetApplicationManifestRequest.builder() + .name(applicationName) + .build())) + .map(ApplicationManifest::getBuildpacks) + .as(StepVerifier::create) + .expectNext(Arrays.asList("staticfile_buildpack", "php_buildpack")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getStopped() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - .then(this.cloudFoundryOperations.applications() - .get(GetApplicationRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationDetail::getName) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true) + .then( + this.cloudFoundryOperations + .applications() + .get(GetApplicationRequest.builder().name(applicationName).build())) + .map(ApplicationDetail::getName) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -339,30 +429,35 @@ public void getTcp() throws IOException { String domainName = this.nameFactory.getDomainName(); requestCreateTcpDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP) - .then(createApplicationTcp(this.cloudFoundryOperations, applicationName, domainName)) - .thenMany(this.cloudFoundryOperations.applications() - .get(GetApplicationRequest.builder() - .name(applicationName) - .build())) - .map(applicationDetail -> applicationDetail.getUrls().get(0)) - .as(StepVerifier::create) - .consumeNextWith(route -> assertThat(route).matches(domainName + "+?:\\d+$")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + createApplicationTcp( + this.cloudFoundryOperations, applicationName, domainName)) + .thenMany( + this.cloudFoundryOperations + .applications() + .get(GetApplicationRequest.builder().name(applicationName).build())) + .map(applicationDetail -> applicationDetail.getUrls().get(0)) + .as(StepVerifier::create) + .consumeNextWith(route -> assertThat(route).matches(domainName + "+?:\\d+$")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .thenMany(this.cloudFoundryOperations.applications() - .list()) - .filter(response -> applicationName.equals(response.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .thenMany(this.cloudFoundryOperations.applications().list()) + .filter(response -> applicationName.equals(response.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_11) @@ -371,35 +466,49 @@ public void listTasks() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String taskName = this.nameFactory.getTaskName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(requestCreateTask(this.cloudFoundryOperations, applicationName, taskName)) - .thenMany(this.cloudFoundryOperations.applications() - .listTasks(ListApplicationTasksRequest.builder() - .name(applicationName) - .build())) - .map(Task::getName) - .as(StepVerifier::create) - .expectNext(taskName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then(requestCreateTask(this.cloudFoundryOperations, applicationName, taskName)) + .thenMany( + this.cloudFoundryOperations + .applications() + .listTasks( + ListApplicationTasksRequest.builder() + .name(applicationName) + .build())) + .map(Task::getName) + .as(StepVerifier::create) + .expectNext(taskName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void logs() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .thenMany(this.cloudFoundryOperations.applications() - .logs(LogsRequest.builder() - .name(applicationName) - .recent(true) - .build())) - .map(LogMessage::getMessageType) - .next() - .as(StepVerifier::create) - .expectNext(MessageType.OUT) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .thenMany( + this.cloudFoundryOperations + .applications() + .logs( + LogsRequest.builder() + .name(applicationName) + .recent(true) + .build())) + .map(LogMessage::getMessageType) + .next() + .as(StepVerifier::create) + .expectNext(MessageType.OUT) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -407,38 +516,56 @@ public void pushBindServices() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - .then(this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName) - .service(serviceInstanceName) - .build()) - .noStart(false) - .build())) - .then(getServiceInstance(this.cloudFoundryOperations, serviceInstanceName) - .flatMapIterable(ServiceInstance::getApplications) - .filter(applicationName::equals) - .single()) - .as(StepVerifier::create) - .expectNext(applicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName) + .then( + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType( + ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName) + .service(serviceInstanceName) + .build()) + .noStart(false) + .build())) + .then( + getServiceInstance(this.cloudFoundryOperations, serviceInstanceName) + .flatMapIterable(ServiceInstance::getApplications) + .filter(applicationName::equals) + .single()) + .as(StepVerifier::create) + .expectNext(applicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void pushDirectory() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application").getFile().toPath(), applicationName, false) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application").getFile().toPath(), + applicationName, + false) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -448,28 +575,36 @@ public void pushDomainHostPathRoute() throws IOException { String routePath = this.nameFactory.getPath(); createDomain(this.cloudFoundryOperations, domainName, this.organizationName) - .then(this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .domain(domainName) - .healthCheckType(ApplicationHealthCheck.PORT) - .host("test-host") - .memory(64) - .name(applicationName) - .noStart(false) - .routePath(routePath) - .build())) - .thenMany(this.cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .build())) - .filter(response -> domainName.equals(response.getDomain())) - .map(org.cloudfoundry.operations.routes.Route::getPath) - .as(StepVerifier::create) - .expectNext(routePath) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .domain(domainName) + .healthCheckType(ApplicationHealthCheck.PORT) + .host("test-host") + .memory(64) + .name(applicationName) + .noStart(false) + .routePath(routePath) + .build())) + .thenMany( + this.cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().build())) + .filter(response -> domainName.equals(response.getDomain())) + .map(org.cloudfoundry.operations.routes.Route::getPath) + .as(StepVerifier::create) + .expectNext(routePath) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -477,36 +612,56 @@ public void pushDomainNotFound() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .domain(domainName) - .diskQuota(512) - .memory(64) - .name(applicationName) - .build()) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("Domain %s not found", domainName)) - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .domain(domainName) + .diskQuota(512) + .memory(64) + .name(applicationName) + .build()) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Domain %s not found", domainName)) + .verify(Duration.ofMinutes(5)); } @Test public void pushExisting() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .memory(64) - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .memory(64) + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -514,81 +669,105 @@ public void pushManifestMultipleBuildpacks() throws IOException { String applicationName = this.nameFactory.getApplicationName(); List buildpacks = Arrays.asList("staticfile_buildpack", "php_buildpack"); - this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .buildpacks(buildpacks) - .disk(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName) - .path(new ClassPathResource("test-php.zip").getFile().toPath()) - .build()) - .noStart(true) - .build()) - .then(requestGetManifest(this.cloudFoundryOperations, applicationName)) - .map(ApplicationManifest::getBuildpacks) - .as(StepVerifier::create) - .expectNext(buildpacks) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .buildpacks(buildpacks) + .disk(512) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName) + .path( + new ClassPathResource("test-php.zip") + .getFile() + .toPath()) + .build()) + .noStart(true) + .build()) + .then(requestGetManifest(this.cloudFoundryOperations, applicationName)) + .map(ApplicationManifest::getBuildpacks) + .as(StepVerifier::create) + .expectNext(buildpacks) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.UNSPECIFIED) //TODO how to select this version? + @IfCloudFoundryVersion( + greaterThanOrEqualTo = + CloudFoundryVersion.UNSPECIFIED) // TODO how to select this version? public void pushManifestV3() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - ManifestV3 manifest = ManifestV3.builder() - .application(ManifestV3Application.builder() - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName) - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .build()) - .build(); - - this.cloudFoundryOperations.applications().pushManifestV3(PushManifestV3Request.builder() - .manifest(manifest) - .build()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + ManifestV3 manifest = + ManifestV3.builder() + .application( + ManifestV3Application.builder() + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName) + .path( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .build()) + .build(); + + this.cloudFoundryOperations + .applications() + .pushManifestV3(PushManifestV3Request.builder().manifest(manifest).build()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test - @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.UNSPECIFIED) //TODO how to select this version? + @IfCloudFoundryVersion( + greaterThanOrEqualTo = + CloudFoundryVersion.UNSPECIFIED) // TODO how to select this version? public void pushManifestV3MultipleApplications() throws IOException { String applicationName1 = this.nameFactory.getApplicationName(); String applicationName2 = this.nameFactory.getApplicationName(); - ManifestV3 manifest = ManifestV3.builder() - .application(ManifestV3Application.builder() - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName1) - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .build()) - .application(ManifestV3Application.builder() - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName2) - .path(new ClassPathResource("test-application").getFile().toPath()) - .build()) - .build(); - - this.cloudFoundryOperations.applications().pushManifestV3(PushManifestV3Request.builder() - .manifest(manifest) - .build()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + ManifestV3 manifest = + ManifestV3.builder() + .application( + ManifestV3Application.builder() + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName1) + .path( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .build()) + .application( + ManifestV3Application.builder() + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName2) + .path( + new ClassPathResource("test-application") + .getFile() + .toPath()) + .build()) + .build(); + + this.cloudFoundryOperations + .applications() + .pushManifestV3(PushManifestV3Request.builder().manifest(manifest).build()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -596,22 +775,24 @@ public void pushMultipleBuildpacks() throws IOException { String applicationName = this.nameFactory.getApplicationName(); List buildpacks = Arrays.asList("staticfile_buildpack", "php_buildpack"); - this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .buildpacks("staticfile_buildpack", "php_buildpack") - .diskQuota(512) - .healthCheckType(ApplicationHealthCheck.NONE) - .memory(64) - .name(applicationName) - .noStart(true) - .path(new ClassPathResource("test-php.zip").getFile().toPath()) - .build()) - .then(requestGetManifest(this.cloudFoundryOperations, applicationName)) - .map(ApplicationManifest::getBuildpacks) - .as(StepVerifier::create) - .expectNext(buildpacks) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .buildpacks("staticfile_buildpack", "php_buildpack") + .diskQuota(512) + .healthCheckType(ApplicationHealthCheck.NONE) + .memory(64) + .name(applicationName) + .noStart(true) + .path(new ClassPathResource("test-php.zip").getFile().toPath()) + .build()) + .then(requestGetManifest(this.cloudFoundryOperations, applicationName)) + .map(ApplicationManifest::getBuildpacks) + .as(StepVerifier::create) + .expectNext(buildpacks) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -620,43 +801,67 @@ public void pushMultipleRoutes() throws IOException { String domainName = this.nameFactory.getDomainName(); requestCreateDomain(this.cloudFoundryOperations, domainName, this.organizationName) - .then(this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName) - .route(Route.builder() - .route(String.format("test1.%s", domainName)) - .build()) - .route(Route.builder() - .route(String.format("test2.%s", domainName)) - .build()) - .build()) - .noStart(false) - .build())) - .thenMany(this.cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .build())) - .filter(response -> domainName.equals(response.getDomain())) - .map(org.cloudfoundry.operations.routes.Route::getApplications) - .as(StepVerifier::create) - .expectNextCount(2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType( + ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName) + .route( + Route.builder() + .route( + String + .format( + "test1.%s", + domainName)) + .build()) + .route( + Route.builder() + .route( + String + .format( + "test2.%s", + domainName)) + .build()) + .build()) + .noStart(false) + .build())) + .thenMany( + this.cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().build())) + .filter(response -> domainName.equals(response.getDomain())) + .map(org.cloudfoundry.operations.routes.Route::getApplications) + .as(StepVerifier::create) + .expectNextCount(2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void pushNew() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -664,9 +869,9 @@ public void pushNewDocker() { String applicationName = this.nameFactory.getApplicationName(); createDockerApplication(this.cloudFoundryOperations, applicationName, false) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -675,27 +880,35 @@ public void pushNoHostName() throws IOException { String domainName = this.nameFactory.getDomainName(); requestCreateDomain(this.cloudFoundryOperations, domainName, this.organizationName) - .then(this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .domain(domainName) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName) - .noHostname(true) - .noStart(false) - .build())) - .thenMany(this.cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .build())) - .filter(response -> domainName.equals(response.getDomain())) - .map(org.cloudfoundry.operations.routes.Route::getHost) - .as(StepVerifier::create) - .expectNext("") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .domain(domainName) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName) + .noHostname(true) + .noStart(false) + .build())) + .thenMany( + this.cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().build())) + .filter(response -> domainName.equals(response.getDomain())) + .map(org.cloudfoundry.operations.routes.Route::getHost) + .as(StepVerifier::create) + .expectNext("") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -704,32 +917,46 @@ public void pushNoRoute() throws IOException { String domainName = this.nameFactory.getDomainName(); createDomain(this.cloudFoundryOperations, domainName, this.organizationName) - .then(this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .domain(domainName) - .memory(64) - .name(applicationName) - .noStart(true) - .build())) - .then(this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .memory(64) - .name(applicationName) - .noRoute(true) - .noStart(true) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .flatMapIterable(org.cloudfoundry.operations.routes.Route::getApplications) - .filter(applicationName::equals) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .domain(domainName) + .memory(64) + .name(applicationName) + .noStart(true) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .memory(64) + .name(applicationName) + .noRoute(true) + .noStart(true) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .flatMapIterable(org.cloudfoundry.operations.routes.Route::getApplications) + .filter(applicationName::equals) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -738,18 +965,25 @@ public void pushPrivateDomain() throws IOException { String domainName = this.nameFactory.getDomainName(); createDomain(this.cloudFoundryOperations, domainName, this.organizationName) - .then(this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .domain(domainName) - .memory(64) - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .domain(domainName) + .memory(64) + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -760,29 +994,44 @@ public void pushRouteAndRoutePath() throws IOException { String routePath2 = this.nameFactory.getPath(); requestCreateDomain(this.cloudFoundryOperations, domainName, this.organizationName) - .then(this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName) - .route(Route.builder() - .route(String.format("test.%s%s", domainName, routePath1)) - .build()) - .routePath(routePath2) - .build()) - .noStart(false) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .map(org.cloudfoundry.operations.routes.Route::getPath) - .filter(routePath2::equals) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType( + ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName) + .route( + Route.builder() + .route( + String + .format( + "test.%s%s", + domainName, + routePath1)) + .build()) + .routePath(routePath2) + .build()) + .noStart(false) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .map(org.cloudfoundry.operations.routes.Route::getPath) + .filter(routePath2::equals) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -790,24 +1039,29 @@ public void pushRoutePath() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String routePath = this.nameFactory.getPath(); - this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .healthCheckHttpEndpoint("/health") - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(applicationName) - .noStart(false) - .routePath(routePath) - .build()) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(route -> routePath.equals(route.getPath())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .healthCheckHttpEndpoint("/health") + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(applicationName) + .noStart(false) + .routePath(routePath) + .build()) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(route -> routePath.equals(route.getPath())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -816,28 +1070,39 @@ public void pushTcpRoute() throws IOException { String domainName = this.nameFactory.getDomainName(); requestCreateTcpDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP) - .then(this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PROCESS) - .memory(64) - .name(applicationName) - .randomRoute(true) - .route(Route.builder() - .route(domainName) - .build()) - .build()) - .noStart(true) - .build())) - .then(requestGetManifest(this.cloudFoundryOperations, applicationName)) - .map(manifest -> manifest.getRoutes().get(0).getRoute()) - .as(StepVerifier::create) - .consumeNextWith(route -> assertThat(route).matches(domainName + "+?:\\d+$")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType( + ApplicationHealthCheck + .PROCESS) + .memory(64) + .name(applicationName) + .randomRoute(true) + .route( + Route.builder() + .route(domainName) + .build()) + .build()) + .noStart(true) + .build())) + .then(requestGetManifest(this.cloudFoundryOperations, applicationName)) + .map(manifest -> manifest.getRoutes().get(0).getRoute()) + .as(StepVerifier::create) + .consumeNextWith(route -> assertThat(route).matches(domainName + "+?:\\d+$")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -848,45 +1113,78 @@ public void pushUpdateRoute() throws IOException { String newHostName = this.nameFactory.getHostName(); requestCreateDomain(this.cloudFoundryOperations, domainName, this.organizationName) - .then(this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PROCESS) - .memory(64) - .name(applicationName) - .route(Route.builder() - .route(String.format("%s.%s", originalHostName, domainName)) - .build()) - .build()) - .noStart(true) - .build())) - .then(this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PROCESS) - .memory(64) - .name(applicationName) - .route(Route.builder() - .route(String.format("%s.%s", newHostName, domainName)) - .build()) - .build()) - .noStart(true) - .build())) - .thenMany(this.cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .build())) - .flatMapIterable(org.cloudfoundry.operations.routes.Route::getApplications) - .filter(applicationName::equals) - .as(StepVerifier::create) - .expectNextCount(2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType( + ApplicationHealthCheck + .PROCESS) + .memory(64) + .name(applicationName) + .route( + Route.builder() + .route( + String + .format( + "%s.%s", + originalHostName, + domainName)) + .build()) + .build()) + .noStart(true) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType( + ApplicationHealthCheck + .PROCESS) + .memory(64) + .name(applicationName) + .route( + Route.builder() + .route( + String + .format( + "%s.%s", + newHostName, + domainName)) + .build()) + .build()) + .noStart(true) + .build())) + .thenMany( + this.cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().build())) + .flatMapIterable(org.cloudfoundry.operations.routes.Route::getApplications) + .filter(applicationName::equals) + .as(StepVerifier::create) + .expectNextCount(2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -895,48 +1193,71 @@ public void pushUpdateTcpRoute() throws IOException { String domainName = this.nameFactory.getDomainName(); requestCreateTcpDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP) - .then(this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PROCESS) - .memory(64) - .name(applicationName) - .randomRoute(true) - .route(Route.builder() - .route(domainName) - .build()) - .build()) - .noStart(true) - .build())) - .then(this.cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PROCESS) - .memory(64) - .name(applicationName) - .randomRoute(true) - .route(Route.builder() - .route(domainName) - .build()) - .build()) - .noStart(true) - .build())) - .then(requestGetApplication(this.cloudFoundryOperations, applicationName)) - .map(ApplicationDetail::getUrls) - .as(StepVerifier::create) - .consumeNextWith(routes -> { - assertThat(routes.get(0).matches(domainName + "+?:\\d+$")); - assertThat(routes.get(1).matches(domainName + "+?:\\d+$")); - assertThat(!routes.get(0).matches(routes.get(1))); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType( + ApplicationHealthCheck + .PROCESS) + .memory(64) + .name(applicationName) + .randomRoute(true) + .route( + Route.builder() + .route(domainName) + .build()) + .build()) + .noStart(true) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType( + ApplicationHealthCheck + .PROCESS) + .memory(64) + .name(applicationName) + .randomRoute(true) + .route( + Route.builder() + .route(domainName) + .build()) + .build()) + .noStart(true) + .build())) + .then(requestGetApplication(this.cloudFoundryOperations, applicationName)) + .map(ApplicationDetail::getUrls) + .as(StepVerifier::create) + .consumeNextWith( + routes -> { + assertThat(routes.get(0).matches(domainName + "+?:\\d+$")); + assertThat(routes.get(1).matches(domainName + "+?:\\d+$")); + assertThat(!routes.get(0).matches(routes.get(1))); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -944,19 +1265,24 @@ public void pushWithHost() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String host = this.nameFactory.getHostName(); - this.cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .host(host) - .memory(64) - .name(applicationName) - .build()) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path( + new ClassPathResource("test-application.zip") + .getFile() + .toPath()) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .healthCheckType(ApplicationHealthCheck.PORT) + .host(host) + .memory(64) + .name(applicationName) + .build()) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -964,74 +1290,109 @@ public void rename() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String newName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .rename(RenameApplicationRequest.builder() - .name(applicationName) - .newName(newName) - .build())) - .then(requestGetApplication(this.cloudFoundryOperations, newName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .rename( + RenameApplicationRequest.builder() + .name(applicationName) + .newName(newName) + .build())) + .then(requestGetApplication(this.cloudFoundryOperations, newName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void restage() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .restage(RestageApplicationRequest.builder() - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .restage( + RestageApplicationRequest.builder() + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void restartInstance() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .restartInstance(RestartApplicationInstanceRequest.builder() - .instanceIndex(0) - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .restartInstance( + RestartApplicationInstanceRequest.builder() + .instanceIndex(0) + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void restartNotStarted() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - .then(this.cloudFoundryOperations.applications() - .restart(RestartApplicationRequest.builder() - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true) + .then( + this.cloudFoundryOperations + .applications() + .restart( + RestartApplicationRequest.builder() + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void restartStarted() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .restart(RestartApplicationRequest.builder() - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .restart( + RestartApplicationRequest.builder() + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_11) @@ -1040,39 +1401,53 @@ public void runTask() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String taskName = this.nameFactory.getTaskName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .runTask(RunApplicationTaskRequest.builder() - .applicationName(applicationName) - .command("ls") - .disk(64) - .memory(64) - .taskName(taskName) - .build())) - .map(Task::getName) - .as(StepVerifier::create) - .expectNext(taskName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .runTask( + RunApplicationTaskRequest.builder() + .applicationName(applicationName) + .command("ls") + .disk(64) + .memory(64) + .taskName(taskName) + .build())) + .map(Task::getName) + .as(StepVerifier::create) + .expectNext(taskName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void scale() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .scale(ScaleApplicationRequest.builder() - .instances(2) - .memoryLimit(65) - .name(applicationName) - .build())) - .then(requestGetApplication(this.cloudFoundryOperations, applicationName)) - .map(ApplicationDetail::getRunningInstances) - .as(StepVerifier::create) - .expectNext(2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .scale( + ScaleApplicationRequest.builder() + .instances(2) + .memoryLimit(65) + .name(applicationName) + .build())) + .then(requestGetApplication(this.cloudFoundryOperations, applicationName)) + .map(ApplicationDetail::getRunningInstances) + .as(StepVerifier::create) + .expectNext(2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("unchecked") @@ -1084,110 +1459,159 @@ public void setEnvironmentVariable() throws IOException { String variableValue1 = this.nameFactory.getVariableValue(); String variableValue2 = this.nameFactory.getVariableValue(); - Map expected = FluentMap.builder() - .entry(variableName1, variableValue1) - .entry(variableName2, variableValue2) - .build(); - - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName1) - .variableValue(variableValue1) - .build())) - .then(this.cloudFoundryOperations.applications() - .setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName2) - .variableValue(variableValue2) - .build())) - .then(this.cloudFoundryOperations.applications() - .getEnvironments(GetApplicationEnvironmentsRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationEnvironments::getUserProvided) - .as(StepVerifier::create) - .expectNext(expected) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Map expected = + FluentMap.builder() + .entry(variableName1, variableValue1) + .entry(variableName2, variableValue2) + .build(); + + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .setEnvironmentVariable( + SetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName1) + .variableValue(variableValue1) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .setEnvironmentVariable( + SetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName2) + .variableValue(variableValue2) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .getEnvironments( + GetApplicationEnvironmentsRequest.builder() + .name(applicationName) + .build())) + .map(ApplicationEnvironments::getUserProvided) + .as(StepVerifier::create) + .expectNext(expected) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void setHealthCheck() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .setHealthCheck(SetApplicationHealthCheckRequest.builder() - .name(applicationName) - .type(ApplicationHealthCheck.PROCESS) - .build())) - .then(requestGetHealthCheck(this.cloudFoundryOperations, applicationName)) - .as(StepVerifier::create) - .expectNext(ApplicationHealthCheck.PROCESS) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .setHealthCheck( + SetApplicationHealthCheckRequest.builder() + .name(applicationName) + .type(ApplicationHealthCheck.PROCESS) + .build())) + .then(requestGetHealthCheck(this.cloudFoundryOperations, applicationName)) + .as(StepVerifier::create) + .expectNext(ApplicationHealthCheck.PROCESS) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void sshEnabled() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .sshEnabled(ApplicationSshEnabledRequest.builder() - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectNext(true) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .sshEnabled( + ApplicationSshEnabledRequest.builder() + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectNext(true) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void startNotStarted() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - .then(this.cloudFoundryOperations.applications() - .start(StartApplicationRequest.builder() - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true) + .then( + this.cloudFoundryOperations + .applications() + .start( + StartApplicationRequest.builder() + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void startStarted() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .start(StartApplicationRequest.builder() - .name(applicationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .start( + StartApplicationRequest.builder() + .name(applicationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void stop() throws IOException { String applicationName = this.nameFactory.getApplicationName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .stop(StopApplicationRequest.builder() - .name(applicationName) - .build())) - .then(requestGetApplication(this.cloudFoundryOperations, applicationName)) - .map(ApplicationDetail::getRequestedState) - .as(StepVerifier::create) - .expectNext("STOPPED") - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .stop( + StopApplicationRequest.builder() + .name(applicationName) + .build())) + .then(requestGetApplication(this.cloudFoundryOperations, applicationName)) + .map(ApplicationDetail::getRequestedState) + .as(StepVerifier::create) + .expectNext("STOPPED") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_11) @@ -1196,21 +1620,31 @@ public void terminateTask() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String taskName = this.nameFactory.getTaskName(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(getLongLivedTaskId(this.cloudFoundryOperations, applicationName, taskName)) - .flatMap(sequenceId -> this.cloudFoundryOperations.applications() - .terminateTask(TerminateApplicationTaskRequest.builder() - .applicationName(applicationName) - .sequenceId(sequenceId) - .build()) - .thenReturn(sequenceId)) - .flatMapMany(sequenceId -> requestListTasks(this.cloudFoundryOperations, applicationName) - .filter(task -> sequenceId.equals(task.getSequenceId()))) - .map(Task::getState) - .as(StepVerifier::create) - .expectNext(TaskState.FAILED) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then(getLongLivedTaskId(this.cloudFoundryOperations, applicationName, taskName)) + .flatMap( + sequenceId -> + this.cloudFoundryOperations + .applications() + .terminateTask( + TerminateApplicationTaskRequest.builder() + .applicationName(applicationName) + .sequenceId(sequenceId) + .build()) + .thenReturn(sequenceId)) + .flatMapMany( + sequenceId -> + requestListTasks(this.cloudFoundryOperations, applicationName) + .filter(task -> sequenceId.equals(task.getSequenceId()))) + .map(Task::getState) + .as(StepVerifier::create) + .expectNext(TaskState.FAILED) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("unchecked") @@ -1222,38 +1656,57 @@ public void unsetEnvironmentVariableComplete() throws IOException { String variableValue1 = this.nameFactory.getVariableValue(); String variableValue2 = this.nameFactory.getVariableValue(); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName1) - .variableValue(variableValue1) - .build())) - .then(this.cloudFoundryOperations.applications() - .setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName2) - .variableValue(variableValue2) - .build())) - .then(this.cloudFoundryOperations.applications() - .unsetEnvironmentVariable(UnsetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName1) - .build())) - .then(this.cloudFoundryOperations.applications() - .unsetEnvironmentVariable(UnsetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName2) - .build())) - .then(this.cloudFoundryOperations.applications() - .getEnvironments(GetApplicationEnvironmentsRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationEnvironments::getUserProvided) - .as(StepVerifier::create) - .expectNext(Collections.emptyMap()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .setEnvironmentVariable( + SetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName1) + .variableValue(variableValue1) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .setEnvironmentVariable( + SetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName2) + .variableValue(variableValue2) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .unsetEnvironmentVariable( + UnsetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName1) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .unsetEnvironmentVariable( + UnsetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName2) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .getEnvironments( + GetApplicationEnvironmentsRequest.builder() + .name(applicationName) + .build())) + .map(ApplicationEnvironments::getUserProvided) + .as(StepVerifier::create) + .expectNext(Collections.emptyMap()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("unchecked") @@ -1267,215 +1720,295 @@ public void unsetEnvironmentVariablePartial() throws IOException { Map expected = Collections.singletonMap(variableName2, variableValue2); - createApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, false) - .then(this.cloudFoundryOperations.applications() - .setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName1) - .variableValue(variableValue1) - .build())) - .then(this.cloudFoundryOperations.applications() - .setEnvironmentVariable(SetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName2) - .variableValue(variableValue2) - .build())) - .then(this.cloudFoundryOperations.applications() - .unsetEnvironmentVariable(UnsetEnvironmentVariableApplicationRequest.builder() - .name(applicationName) - .variableName(variableName1) - .build())) - .then(this.cloudFoundryOperations.applications() - .getEnvironments(GetApplicationEnvironmentsRequest.builder() - .name(applicationName) - .build())) - .map(ApplicationEnvironments::getUserProvided) - .as(StepVerifier::create) - .expectNext(expected) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono bindServiceToApplication(CloudFoundryOperations cloudFoundryOperations, String applicationName, String serviceInstanceName) { - return cloudFoundryOperations.services() - .createUserProvidedInstance(CreateUserProvidedServiceInstanceRequest.builder() - .name(serviceInstanceName) - .build()) - .then(cloudFoundryOperations.services() - .bind(BindServiceInstanceRequest.builder() - .serviceInstanceName(serviceInstanceName) - .applicationName(applicationName) - .build())); - } - - private static Mono createApplication(CloudFoundryOperations cloudFoundryOperations, Path application, String name, Boolean noStart) { - return cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diskQuota(512) - .healthCheckType(ApplicationHealthCheck.NONE) - .memory(64) - .name(name) - .noStart(noStart) - .path(application) - .build()); - } - - private static Mono createApplicationPhp(CloudFoundryOperations cloudFoundryOperations, Path application, String name, Boolean noStart) { - return cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .buildpacks("staticfile_buildpack", "php_buildpack") - .diskQuota(512) - .healthCheckType(ApplicationHealthCheck.NONE) - .memory(64) - .name(name) - .noStart(noStart) - .path(application) - .build()); - } - - private static Mono createApplicationTcp(CloudFoundryOperations cloudFoundryOperations, String applicationName, String domainName) throws IOException { - return cloudFoundryOperations.applications() - .pushManifest(PushApplicationManifestRequest.builder() - .manifest(ApplicationManifest.builder() - .buildpack("staticfile_buildpack") - .disk(512) - .healthCheckType(ApplicationHealthCheck.PROCESS) - .memory(64) - .name(applicationName) - .path(new ClassPathResource("test-application.zip").getFile().toPath()) - .randomRoute(true) - .route(Route.builder() - .route(domainName) - .build()) - .build()) - .noStart(true) - .build()); - } - - private static Mono createDockerApplication(CloudFoundryOperations cloudFoundryOperations, String name, Boolean noStart) { - return cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .diskQuota(512) - .dockerImage("cloudfoundry/lattice-app") - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(name) - .noStart(noStart) - .build()); - } - - private static Mono createDomain(CloudFoundryOperations cloudFoundryOperations, String domainName, String organizationName) { - return cloudFoundryOperations.domains() - .create(CreateDomainRequest.builder() - .domain(domainName) - .organization(organizationName) - .build()); - } - - private static Mono createServiceInstance(CloudFoundryOperations cloudFoundryOperations, String planName, String serviceInstanceName, String serviceName) { - return cloudFoundryOperations.services() - .createInstance(CreateServiceInstanceRequest.builder() - .planName(planName) - .serviceInstanceName(serviceInstanceName) - .serviceName(serviceName) - .build()); - } - - private static Mono getLongLivedTaskId(CloudFoundryOperations cloudFoundryOperations, String applicationName, String taskName) { + createApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + false) + .then( + this.cloudFoundryOperations + .applications() + .setEnvironmentVariable( + SetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName1) + .variableValue(variableValue1) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .setEnvironmentVariable( + SetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName2) + .variableValue(variableValue2) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .unsetEnvironmentVariable( + UnsetEnvironmentVariableApplicationRequest.builder() + .name(applicationName) + .variableName(variableName1) + .build())) + .then( + this.cloudFoundryOperations + .applications() + .getEnvironments( + GetApplicationEnvironmentsRequest.builder() + .name(applicationName) + .build())) + .map(ApplicationEnvironments::getUserProvided) + .as(StepVerifier::create) + .expectNext(expected) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono bindServiceToApplication( + CloudFoundryOperations cloudFoundryOperations, + String applicationName, + String serviceInstanceName) { + return cloudFoundryOperations + .services() + .createUserProvidedInstance( + CreateUserProvidedServiceInstanceRequest.builder() + .name(serviceInstanceName) + .build()) + .then( + cloudFoundryOperations + .services() + .bind( + BindServiceInstanceRequest.builder() + .serviceInstanceName(serviceInstanceName) + .applicationName(applicationName) + .build())); + } + + private static Mono createApplication( + CloudFoundryOperations cloudFoundryOperations, + Path application, + String name, + Boolean noStart) { + return cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .buildpack("staticfile_buildpack") + .diskQuota(512) + .healthCheckType(ApplicationHealthCheck.NONE) + .memory(64) + .name(name) + .noStart(noStart) + .path(application) + .build()); + } + + private static Mono createApplicationPhp( + CloudFoundryOperations cloudFoundryOperations, + Path application, + String name, + Boolean noStart) { + return cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .buildpacks("staticfile_buildpack", "php_buildpack") + .diskQuota(512) + .healthCheckType(ApplicationHealthCheck.NONE) + .memory(64) + .name(name) + .noStart(noStart) + .path(application) + .build()); + } + + private static Mono createApplicationTcp( + CloudFoundryOperations cloudFoundryOperations, + String applicationName, + String domainName) + throws IOException { + return cloudFoundryOperations + .applications() + .pushManifest( + PushApplicationManifestRequest.builder() + .manifest( + ApplicationManifest.builder() + .buildpack("staticfile_buildpack") + .disk(512) + .healthCheckType(ApplicationHealthCheck.PROCESS) + .memory(64) + .name(applicationName) + .path( + new ClassPathResource( + "test-application.zip") + .getFile() + .toPath()) + .randomRoute(true) + .route(Route.builder().route(domainName).build()) + .build()) + .noStart(true) + .build()); + } + + private static Mono createDockerApplication( + CloudFoundryOperations cloudFoundryOperations, String name, Boolean noStart) { + return cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .diskQuota(512) + .dockerImage("cloudfoundry/lattice-app") + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(name) + .noStart(noStart) + .build()); + } + + private static Mono createDomain( + CloudFoundryOperations cloudFoundryOperations, + String domainName, + String organizationName) { + return cloudFoundryOperations + .domains() + .create( + CreateDomainRequest.builder() + .domain(domainName) + .organization(organizationName) + .build()); + } + + private static Mono createServiceInstance( + CloudFoundryOperations cloudFoundryOperations, + String planName, + String serviceInstanceName, + String serviceName) { + return cloudFoundryOperations + .services() + .createInstance( + CreateServiceInstanceRequest.builder() + .planName(planName) + .serviceInstanceName(serviceInstanceName) + .serviceName(serviceName) + .build()); + } + + private static Mono getLongLivedTaskId( + CloudFoundryOperations cloudFoundryOperations, + String applicationName, + String taskName) { return requestCreateLongLivedTask(cloudFoundryOperations, applicationName, taskName) - .map(Task::getSequenceId); - } - - private static Mono getServiceInstance(CloudFoundryOperations cloudFoundryOperations, String serviceInstanceName) { - return cloudFoundryOperations.services() - .getInstance(GetServiceInstanceRequest.builder() - .name(serviceInstanceName) - .build()); - } - - private static Mono requestCreateDomain(CloudFoundryOperations cloudFoundryOperations, String domainName, String organizationName) { - return cloudFoundryOperations.domains() - .create(CreateDomainRequest.builder() - .domain(domainName) - .organization(organizationName) - .build()); - } - - private static Mono requestCreateLongLivedTask(CloudFoundryOperations cloudFoundryOperations, String applicationName, String taskName) { - return cloudFoundryOperations.applications() - .runTask(RunApplicationTaskRequest.builder() - .applicationName(applicationName) - .command("sleep 99") - .disk(64) - .memory(64) - .taskName(taskName) - .build()); - } - - private static Mono requestCreateTask(CloudFoundryOperations cloudFoundryOperations, String applicationName, String taskName) { - return cloudFoundryOperations.applications() - .runTask(RunApplicationTaskRequest.builder() - .applicationName(applicationName) - .command("ls") - .disk(64) - .memory(64) - .taskName(taskName) - .build()); - } - - private static Mono requestCreateTcpDomain(CloudFoundryOperations cloudFoundryOperations, String domainName, String routerGroup) { - return cloudFoundryOperations.domains() - .createShared(CreateSharedDomainRequest.builder() - .domain(domainName) - .routerGroup(routerGroup) - .build()); - } - - private static Mono requestGetApplication(CloudFoundryOperations cloudFoundryOperations, String applicationName) { - return cloudFoundryOperations.applications() - .get(GetApplicationRequest.builder() - .name(applicationName) - .build()); - } - - private static Mono requestGetHealthCheck(CloudFoundryOperations cloudFoundryOperations, String applicationName) { - return cloudFoundryOperations.applications() - .getHealthCheck(GetApplicationHealthCheckRequest.builder() - .name(applicationName) - .build()); - } - - private static Mono requestGetManifest(CloudFoundryOperations cloudFoundryOperations, String applicationName) { - return cloudFoundryOperations.applications() - .getApplicationManifest(GetApplicationManifestRequest.builder() - .name(applicationName) - .build()); - } - - private static Flux requestListApplications(CloudFoundryOperations cloudFoundryOperations) { - return cloudFoundryOperations.applications() - .list(); - } - - private static Flux requestListRoutes(CloudFoundryOperations cloudFoundryOperations) { - return cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .build()); - } - - private static Flux requestListTasks(CloudFoundryOperations cloudFoundryOperations, String applicationName) { - return cloudFoundryOperations.applications() - .listTasks(ListApplicationTasksRequest.builder() - .name(applicationName) - .build()); + .map(Task::getSequenceId); + } + + private static Mono getServiceInstance( + CloudFoundryOperations cloudFoundryOperations, String serviceInstanceName) { + return cloudFoundryOperations + .services() + .getInstance(GetServiceInstanceRequest.builder().name(serviceInstanceName).build()); + } + + private static Mono requestCreateDomain( + CloudFoundryOperations cloudFoundryOperations, + String domainName, + String organizationName) { + return cloudFoundryOperations + .domains() + .create( + CreateDomainRequest.builder() + .domain(domainName) + .organization(organizationName) + .build()); + } + + private static Mono requestCreateLongLivedTask( + CloudFoundryOperations cloudFoundryOperations, + String applicationName, + String taskName) { + return cloudFoundryOperations + .applications() + .runTask( + RunApplicationTaskRequest.builder() + .applicationName(applicationName) + .command("sleep 99") + .disk(64) + .memory(64) + .taskName(taskName) + .build()); + } + + private static Mono requestCreateTask( + CloudFoundryOperations cloudFoundryOperations, + String applicationName, + String taskName) { + return cloudFoundryOperations + .applications() + .runTask( + RunApplicationTaskRequest.builder() + .applicationName(applicationName) + .command("ls") + .disk(64) + .memory(64) + .taskName(taskName) + .build()); + } + + private static Mono requestCreateTcpDomain( + CloudFoundryOperations cloudFoundryOperations, String domainName, String routerGroup) { + return cloudFoundryOperations + .domains() + .createShared( + CreateSharedDomainRequest.builder() + .domain(domainName) + .routerGroup(routerGroup) + .build()); + } + + private static Mono requestGetApplication( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { + return cloudFoundryOperations + .applications() + .get(GetApplicationRequest.builder().name(applicationName).build()); + } + + private static Mono requestGetHealthCheck( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { + return cloudFoundryOperations + .applications() + .getHealthCheck( + GetApplicationHealthCheckRequest.builder().name(applicationName).build()); + } + + private static Mono requestGetManifest( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { + return cloudFoundryOperations + .applications() + .getApplicationManifest( + GetApplicationManifestRequest.builder().name(applicationName).build()); + } + + private static Flux requestListApplications( + CloudFoundryOperations cloudFoundryOperations) { + return cloudFoundryOperations.applications().list(); + } + + private static Flux requestListRoutes( + CloudFoundryOperations cloudFoundryOperations) { + return cloudFoundryOperations.routes().list(ListRoutesRequest.builder().build()); + } + + private static Flux requestListTasks( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { + return cloudFoundryOperations + .applications() + .listTasks(ListApplicationTasksRequest.builder().name(applicationName).build()); + } + + private static Mono requestSshEnabled( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { + return cloudFoundryOperations + .applications() + .sshEnabled(ApplicationSshEnabledRequest.builder().name(applicationName).build()); } - - private static Mono requestSshEnabled(CloudFoundryOperations cloudFoundryOperations, String applicationName) { - return cloudFoundryOperations.applications() - .sshEnabled(ApplicationSshEnabledRequest.builder() - .name(applicationName) - .build()); - } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/BuildpacksTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/BuildpacksTest.java index 869f00a9245..08b1dfcc243 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/BuildpacksTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/BuildpacksTest.java @@ -16,63 +16,68 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.operations.buildpacks.Buildpack; import org.cloudfoundry.operations.buildpacks.CreateBuildpackRequest; import org.cloudfoundry.operations.buildpacks.DeleteBuildpackRequest; import org.cloudfoundry.operations.buildpacks.UpdateBuildpackRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class BuildpacksTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; @Test public void create() throws IOException { String buildpackName = this.nameFactory.getBuildpackName(); - this.cloudFoundryOperations.buildpacks() - .create(CreateBuildpackRequest.builder() - .buildpack(new ClassPathResource("test-buildpack.zip").getFile().toPath()) - .name(buildpackName) - .position(Integer.MAX_VALUE) - .build()) - .thenMany(this.cloudFoundryOperations.buildpacks() - .list()) - .filter(buildpack -> buildpackName.equals(buildpack.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .buildpacks() + .create( + CreateBuildpackRequest.builder() + .buildpack( + new ClassPathResource("test-buildpack.zip") + .getFile() + .toPath()) + .name(buildpackName) + .position(Integer.MAX_VALUE) + .build()) + .thenMany(this.cloudFoundryOperations.buildpacks().list()) + .filter(buildpack -> buildpackName.equals(buildpack.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void createFromDirectory() throws IOException { String buildpackName = this.nameFactory.getBuildpackName(); - this.cloudFoundryOperations.buildpacks() - .create(CreateBuildpackRequest.builder() - .buildpack(new ClassPathResource("test-buildpack").getFile().toPath()) - .name(buildpackName) - .position(Integer.MAX_VALUE) - .build()) - .thenMany(this.cloudFoundryOperations.buildpacks() - .list()) - .filter(buildpack -> buildpackName.equals(buildpack.getName())) - .map(Buildpack::getFilename) - .as(StepVerifier::create) - .expectNext("test-buildpack.zip") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .buildpacks() + .create( + CreateBuildpackRequest.builder() + .buildpack( + new ClassPathResource("test-buildpack").getFile().toPath()) + .name(buildpackName) + .position(Integer.MAX_VALUE) + .build()) + .thenMany(this.cloudFoundryOperations.buildpacks().list()) + .filter(buildpack -> buildpackName.equals(buildpack.getName())) + .map(Buildpack::getFilename) + .as(StepVerifier::create) + .expectNext("test-buildpack.zip") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -80,29 +85,34 @@ public void delete() throws IOException { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpack(this.cloudFoundryOperations, buildpackName) - .then(this.cloudFoundryOperations.buildpacks() - .delete(DeleteBuildpackRequest.builder() - .name(buildpackName) - .build())) - .thenMany(this.cloudFoundryOperations.buildpacks() - .list()) - .filter(buildpack -> buildpackName.equals(buildpack.getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .buildpacks() + .delete( + DeleteBuildpackRequest.builder() + .name(buildpackName) + .build())) + .thenMany(this.cloudFoundryOperations.buildpacks().list()) + .filter(buildpack -> buildpackName.equals(buildpack.getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void deleteBuildpackNotFound() { String buildpackName = this.nameFactory.getBuildpackName(); - this.cloudFoundryOperations.buildpacks() - .delete(DeleteBuildpackRequest.builder() - .name(buildpackName) - .build()) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("Buildpack %s not found", buildpackName)) - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .buildpacks() + .delete(DeleteBuildpackRequest.builder().name(buildpackName).build()) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Buildpack %s not found", buildpackName)) + .verify(Duration.ofMinutes(5)); } @Test @@ -110,14 +120,13 @@ public void list() throws IOException { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpack(this.cloudFoundryOperations, buildpackName) - .thenMany(this.cloudFoundryOperations.buildpacks() - .list()) - .filter(buildpack -> buildpackName.equals(buildpack.getName())) - .map(Buildpack::getFilename) - .as(StepVerifier::create) - .expectNext("test-buildpack.zip") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany(this.cloudFoundryOperations.buildpacks().list()) + .filter(buildpack -> buildpackName.equals(buildpack.getName())) + .map(Buildpack::getFilename) + .as(StepVerifier::create) + .expectNext("test-buildpack.zip") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -125,19 +134,21 @@ public void update() throws IOException { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpack(this.cloudFoundryOperations, buildpackName) - .then(this.cloudFoundryOperations.buildpacks() - .update(UpdateBuildpackRequest.builder() - .enable(true) - .name(buildpackName) - .build())) - .thenMany(this.cloudFoundryOperations.buildpacks() - .list()) - .filter(buildpack -> buildpackName.equals(buildpack.getName())) - .map(Buildpack::getEnabled) - .as(StepVerifier::create) - .expectNext(true) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .buildpacks() + .update( + UpdateBuildpackRequest.builder() + .enable(true) + .name(buildpackName) + .build())) + .thenMany(this.cloudFoundryOperations.buildpacks().list()) + .filter(buildpack -> buildpackName.equals(buildpack.getName())) + .map(Buildpack::getEnabled) + .as(StepVerifier::create) + .expectNext(true) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -145,30 +156,41 @@ public void updateFromDirectory() throws IOException { String buildpackName = this.nameFactory.getBuildpackName(); createBuildpack(this.cloudFoundryOperations, buildpackName) - .then(this.cloudFoundryOperations.buildpacks() - .update(UpdateBuildpackRequest.builder() - .buildpack(new ClassPathResource("test-buildpack").getFile().toPath()) - .enable(true) - .name(buildpackName) - .build())) - .thenMany(this.cloudFoundryOperations.buildpacks() - .list()) - .filter(buildpack -> buildpackName.equals(buildpack.getName())) - .map(Buildpack::getFilename) - .as(StepVerifier::create) - .expectNext("test-buildpack.zip") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .buildpacks() + .update( + UpdateBuildpackRequest.builder() + .buildpack( + new ClassPathResource("test-buildpack") + .getFile() + .toPath()) + .enable(true) + .name(buildpackName) + .build())) + .thenMany(this.cloudFoundryOperations.buildpacks().list()) + .filter(buildpack -> buildpackName.equals(buildpack.getName())) + .map(Buildpack::getFilename) + .as(StepVerifier::create) + .expectNext("test-buildpack.zip") + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createBuildpack(CloudFoundryOperations cloudFoundryOperations, String buildpackName) throws IOException { - return cloudFoundryOperations.buildpacks() - .create(CreateBuildpackRequest.builder() - .buildpack(new ClassPathResource("test-buildpack.zip").getFile().toPath()) - .enable(false) - .name(buildpackName) - .position(Integer.MAX_VALUE) - .build()); + private static Mono createBuildpack( + CloudFoundryOperations cloudFoundryOperations, String buildpackName) + throws IOException { + return cloudFoundryOperations + .buildpacks() + .create( + CreateBuildpackRequest.builder() + .buildpack( + new ClassPathResource("test-buildpack.zip") + .getFile() + .toPath()) + .enable(false) + .name(buildpackName) + .position(Integer.MAX_VALUE) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/DomainsTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/DomainsTest.java index f42129db405..8fe5c90cb78 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/DomainsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/DomainsTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.operations.domains.Status.OWNED; +import static org.cloudfoundry.operations.domains.Status.SHARED; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.v2.ClientV2Exception; import org.cloudfoundry.operations.domains.CreateDomainRequest; @@ -24,90 +29,94 @@ import org.cloudfoundry.operations.domains.ShareDomainRequest; import org.cloudfoundry.operations.domains.UnshareDomainRequest; import org.cloudfoundry.operations.organizations.CreateOrganizationRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.operations.domains.Status.OWNED; -import static org.cloudfoundry.operations.domains.Status.SHARED; - public final class DomainsTest extends AbstractIntegrationTest { private static final String DEFAULT_ROUTER_GROUP = "default-tcp"; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; - @Autowired - private String organizationName; + @Autowired private String organizationName; @Test public void createInvalidDomain() { - this.cloudFoundryOperations.domains() - .create(CreateDomainRequest.builder() - .domain("invalid-domain") - .organization(this.organizationName) - .build()) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(ClientV2Exception.class).hasMessageMatching("CF-DomainInvalid\\([0-9]+\\): The domain is invalid.*")) - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .domains() + .create( + CreateDomainRequest.builder() + .domain("invalid-domain") + .organization(this.organizationName) + .build()) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(ClientV2Exception.class) + .hasMessageMatching( + "CF-DomainInvalid\\([0-9]+\\): The domain is" + + " invalid.*")) + .verify(Duration.ofMinutes(5)); } @Test public void createPrivate() { String domainName = this.nameFactory.getDomainName(); - this.cloudFoundryOperations.domains() - .create(CreateDomainRequest.builder() - .domain(domainName) - .organization(this.organizationName) - .build()) - .thenMany(requestListDomains(this.cloudFoundryOperations)) - .filter(domain -> domainName.equals(domain.getName())) - .map(Domain::getStatus) - .as(StepVerifier::create) - .expectNext(OWNED) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .domains() + .create( + CreateDomainRequest.builder() + .domain(domainName) + .organization(this.organizationName) + .build()) + .thenMany(requestListDomains(this.cloudFoundryOperations)) + .filter(domain -> domainName.equals(domain.getName())) + .map(Domain::getStatus) + .as(StepVerifier::create) + .expectNext(OWNED) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void createShared() { String domainName = this.nameFactory.getDomainName(); - this.cloudFoundryOperations.domains() - .createShared(CreateSharedDomainRequest.builder() - .domain(domainName) - .build()) - .thenMany(requestListDomains(this.cloudFoundryOperations)) - .filter(domain -> domainName.equals(domain.getName())) - .map(Domain::getStatus) - .as(StepVerifier::create) - .expectNext(SHARED) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .domains() + .createShared(CreateSharedDomainRequest.builder().domain(domainName).build()) + .thenMany(requestListDomains(this.cloudFoundryOperations)) + .filter(domain -> domainName.equals(domain.getName())) + .map(Domain::getStatus) + .as(StepVerifier::create) + .expectNext(SHARED) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void createSharedTcp() { String domainName = this.nameFactory.getDomainName(); - this.cloudFoundryOperations.domains() - .createShared(CreateSharedDomainRequest.builder() - .domain(domainName) - .routerGroup(DEFAULT_ROUTER_GROUP) - .build()) - .thenMany(requestListDomains(this.cloudFoundryOperations)) - .filter(domain -> domainName.equals(domain.getName())) - .map(Domain::getType) - .as(StepVerifier::create) - .expectNext("tcp") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .domains() + .createShared( + CreateSharedDomainRequest.builder() + .domain(domainName) + .routerGroup(DEFAULT_ROUTER_GROUP) + .build()) + .thenMany(requestListDomains(this.cloudFoundryOperations)) + .filter(domain -> domainName.equals(domain.getName())) + .map(Domain::getType) + .as(StepVerifier::create) + .expectNext("tcp") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -115,25 +124,28 @@ public void list() { String domainName = this.nameFactory.getDomainName(); requestCreateDomain(this.cloudFoundryOperations, domainName, this.organizationName) - .thenMany(this.cloudFoundryOperations.domains() - .list() - .filter(domain -> domainName.equals(domain.getName()))) - .map(Domain::getStatus) - .as(StepVerifier::create) - .expectNext(OWNED) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + this.cloudFoundryOperations + .domains() + .list() + .filter(domain -> domainName.equals(domain.getName()))) + .map(Domain::getStatus) + .as(StepVerifier::create) + .expectNext(OWNED) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listRouterGroups() { - this.cloudFoundryOperations.domains() - .listRouterGroups() - .filter(response -> DEFAULT_ROUTER_GROUP.equals(response.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .domains() + .listRouterGroups() + .filter(response -> DEFAULT_ROUTER_GROUP.equals(response.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -141,14 +153,16 @@ public void listTcp() { String domainName = this.nameFactory.getDomainName(); requestCreateTcpDomain(this.cloudFoundryOperations, domainName) - .thenMany(this.cloudFoundryOperations.domains() - .list() - .filter(domain -> domainName.equals(domain.getName()))) - .map(Domain::getType) - .as(StepVerifier::create) - .expectNext("tcp") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + this.cloudFoundryOperations + .domains() + .list() + .filter(domain -> domainName.equals(domain.getName()))) + .map(Domain::getType) + .as(StepVerifier::create) + .expectNext("tcp") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -157,15 +171,20 @@ public void share() { String targetOrganizationName = this.nameFactory.getOrganizationName(); requestCreateOrganization(this.cloudFoundryOperations, targetOrganizationName) - .then(requestCreateDomain(this.cloudFoundryOperations, domainName, this.organizationName)) - .then(this.cloudFoundryOperations.domains() - .share(ShareDomainRequest.builder() - .domain(domainName) - .organization(targetOrganizationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + requestCreateDomain( + this.cloudFoundryOperations, domainName, this.organizationName)) + .then( + this.cloudFoundryOperations + .domains() + .share( + ShareDomainRequest.builder() + .domain(domainName) + .organization(targetOrganizationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -174,52 +193,70 @@ public void unshare() { String targetOrganizationName = this.nameFactory.getOrganizationName(); requestCreateOrganization(this.cloudFoundryOperations, targetOrganizationName) - .then(requestCreateDomain(this.cloudFoundryOperations, domainName, this.organizationName)) - .then(requestShareDomain(this.cloudFoundryOperations, targetOrganizationName, domainName)) - .then(this.cloudFoundryOperations.domains() - .unshare(UnshareDomainRequest.builder() - .domain(domainName) - .organization(targetOrganizationName) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + requestCreateDomain( + this.cloudFoundryOperations, domainName, this.organizationName)) + .then( + requestShareDomain( + this.cloudFoundryOperations, targetOrganizationName, domainName)) + .then( + this.cloudFoundryOperations + .domains() + .unshare( + UnshareDomainRequest.builder() + .domain(domainName) + .organization(targetOrganizationName) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono requestCreateDomain(CloudFoundryOperations cloudFoundryOperations, String domainName, String organizationName) { - return cloudFoundryOperations.domains() - .create(CreateDomainRequest.builder() - .domain(domainName) - .organization(organizationName) - .build()); + private static Mono requestCreateDomain( + CloudFoundryOperations cloudFoundryOperations, + String domainName, + String organizationName) { + return cloudFoundryOperations + .domains() + .create( + CreateDomainRequest.builder() + .domain(domainName) + .organization(organizationName) + .build()); } - private static Mono requestCreateOrganization(CloudFoundryOperations cloudFoundryOperations, String name) { - return cloudFoundryOperations.organizations() - .create(CreateOrganizationRequest.builder() - .organizationName(name) - .build()); + private static Mono requestCreateOrganization( + CloudFoundryOperations cloudFoundryOperations, String name) { + return cloudFoundryOperations + .organizations() + .create(CreateOrganizationRequest.builder().organizationName(name).build()); } - private static Mono requestCreateTcpDomain(CloudFoundryOperations cloudFoundryOperations, String domainName) { - return cloudFoundryOperations.domains() - .createShared(CreateSharedDomainRequest.builder() - .domain(domainName) - .routerGroup(DEFAULT_ROUTER_GROUP) - .build()); + private static Mono requestCreateTcpDomain( + CloudFoundryOperations cloudFoundryOperations, String domainName) { + return cloudFoundryOperations + .domains() + .createShared( + CreateSharedDomainRequest.builder() + .domain(domainName) + .routerGroup(DEFAULT_ROUTER_GROUP) + .build()); } private static Flux requestListDomains(CloudFoundryOperations cloudFoundryOperations) { - return cloudFoundryOperations.domains() - .list(); + return cloudFoundryOperations.domains().list(); } - private static Mono requestShareDomain(CloudFoundryOperations cloudFoundryOperations, String organizationName, String domainName) { - return cloudFoundryOperations.domains() - .share(ShareDomainRequest.builder() - .domain(domainName) - .organization(organizationName) - .build()); + private static Mono requestShareDomain( + CloudFoundryOperations cloudFoundryOperations, + String organizationName, + String domainName) { + return cloudFoundryOperations + .domains() + .share( + ShareDomainRequest.builder() + .domain(domainName) + .organization(organizationName) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/NetworkPoliciesTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/NetworkPoliciesTest.java index 1ed827a1571..1643a3ef4f8 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/NetworkPoliciesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/NetworkPoliciesTest.java @@ -16,6 +16,7 @@ package org.cloudfoundry.operations; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -27,23 +28,19 @@ import org.cloudfoundry.operations.networkpolicies.Policy; import org.cloudfoundry.operations.networkpolicies.RemoveNetworkPolicyRequest; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - public final class NetworkPoliciesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; - @Autowired - private Mono spaceId; + @Autowired private Mono spaceId; @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) @Test @@ -53,22 +50,34 @@ public void add() { Integer port = this.nameFactory.getPort(); this.spaceId - .flatMapMany(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, destinationApplicationName, spaceId), - createApplicationId(this.cloudFoundryClient, sourceApplicationName, spaceId) - )) - .thenMany(this.cloudFoundryOperations.networkPolicies() - .add(AddNetworkPolicyRequest.builder() - .destination(destinationApplicationName) - .source(sourceApplicationName) - .startPort(port) - .build())) - .thenMany(requestListNetworkPolicies(this.cloudFoundryOperations, sourceApplicationName)) - .map(Policy::getDestination) - .as(StepVerifier::create) - .expectNext(destinationApplicationName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + destinationApplicationName, + spaceId), + createApplicationId( + this.cloudFoundryClient, + sourceApplicationName, + spaceId))) + .thenMany( + this.cloudFoundryOperations + .networkPolicies() + .add( + AddNetworkPolicyRequest.builder() + .destination(destinationApplicationName) + .source(sourceApplicationName) + .startPort(port) + .build())) + .thenMany( + requestListNetworkPolicies( + this.cloudFoundryOperations, sourceApplicationName)) + .map(Policy::getDestination) + .as(StepVerifier::create) + .expectNext(destinationApplicationName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) @@ -79,20 +88,35 @@ public void list() { Integer port = this.nameFactory.getPort(); this.spaceId - .flatMapMany(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, destinationApplicationName, spaceId), - createApplicationId(this.cloudFoundryClient, sourceApplicationName, spaceId) - )) - .thenMany(requestAddNetworkPolicy(this.cloudFoundryOperations, destinationApplicationName, port, sourceApplicationName)) - .thenMany(this.cloudFoundryOperations.networkPolicies() - .list(ListNetworkPoliciesRequest.builder() - .source(sourceApplicationName) - .build())) - .map(Policy::getStartPort) - .as(StepVerifier::create) - .expectNext(port) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + destinationApplicationName, + spaceId), + createApplicationId( + this.cloudFoundryClient, + sourceApplicationName, + spaceId))) + .thenMany( + requestAddNetworkPolicy( + this.cloudFoundryOperations, + destinationApplicationName, + port, + sourceApplicationName)) + .thenMany( + this.cloudFoundryOperations + .networkPolicies() + .list( + ListNetworkPoliciesRequest.builder() + .source(sourceApplicationName) + .build())) + .map(Policy::getStartPort) + .as(StepVerifier::create) + .expectNext(port) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_12) @@ -103,56 +127,82 @@ public void remove() { Integer port = this.nameFactory.getPort(); this.spaceId - .flatMapMany(spaceId -> Mono.zip( - createApplicationId(this.cloudFoundryClient, destinationApplicationName, spaceId), - createApplicationId(this.cloudFoundryClient, sourceApplicationName, spaceId) - )) - .thenMany(requestAddNetworkPolicy(this.cloudFoundryOperations, destinationApplicationName, port, sourceApplicationName)) - .thenMany(this.cloudFoundryOperations.networkPolicies() - .remove(RemoveNetworkPolicyRequest.builder() - .destination(destinationApplicationName) - .source(sourceApplicationName) - .startPort(port) - .protocol("tcp") - .build())) - .thenMany(requestListNetworkPolicies(this.cloudFoundryOperations, sourceApplicationName)) - .map(Policy::getStartPort) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + spaceId -> + Mono.zip( + createApplicationId( + this.cloudFoundryClient, + destinationApplicationName, + spaceId), + createApplicationId( + this.cloudFoundryClient, + sourceApplicationName, + spaceId))) + .thenMany( + requestAddNetworkPolicy( + this.cloudFoundryOperations, + destinationApplicationName, + port, + sourceApplicationName)) + .thenMany( + this.cloudFoundryOperations + .networkPolicies() + .remove( + RemoveNetworkPolicyRequest.builder() + .destination(destinationApplicationName) + .source(sourceApplicationName) + .startPort(port) + .protocol("tcp") + .build())) + .thenMany( + requestListNetworkPolicies( + this.cloudFoundryOperations, sourceApplicationName)) + .map(Policy::getStartPort) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createApplicationId(CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { + private static Mono createApplicationId( + CloudFoundryClient cloudFoundryClient, String applicationName, String spaceId) { return requestCreateApplication(cloudFoundryClient, spaceId, applicationName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Flux requestAddNetworkPolicy(CloudFoundryOperations cloudFoundryOperations, String destinationApplicationName, Integer port, String sourceApplicationName) { - return cloudFoundryOperations.networkPolicies() - .add(AddNetworkPolicyRequest.builder() - .destination(destinationApplicationName) - .startPort(port) - .source(sourceApplicationName) - .build()); + private static Flux requestAddNetworkPolicy( + CloudFoundryOperations cloudFoundryOperations, + String destinationApplicationName, + Integer port, + String sourceApplicationName) { + return cloudFoundryOperations + .networkPolicies() + .add( + AddNetworkPolicyRequest.builder() + .destination(destinationApplicationName) + .startPort(port) + .source(sourceApplicationName) + .build()); } - private static Mono requestCreateApplication(CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { - return cloudFoundryClient.applicationsV2() - .create(CreateApplicationRequest.builder() - .buildpack("staticfile_buildpack") - .diego(true) - .diskQuota(512) - .memory(64) - .name(applicationName) - .spaceId(spaceId) - .build()); + private static Mono requestCreateApplication( + CloudFoundryClient cloudFoundryClient, String spaceId, String applicationName) { + return cloudFoundryClient + .applicationsV2() + .create( + CreateApplicationRequest.builder() + .buildpack("staticfile_buildpack") + .diego(true) + .diskQuota(512) + .memory(64) + .name(applicationName) + .spaceId(spaceId) + .build()); } - private static Flux requestListNetworkPolicies(CloudFoundryOperations cloudFoundryOperations, String sourceApplicationName) { - return cloudFoundryOperations.networkPolicies() - .list(ListNetworkPoliciesRequest.builder() - .source(sourceApplicationName) - .build()); + private static Flux requestListNetworkPolicies( + CloudFoundryOperations cloudFoundryOperations, String sourceApplicationName) { + return cloudFoundryOperations + .networkPolicies() + .list(ListNetworkPoliciesRequest.builder().source(sourceApplicationName).build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/OrganizationAdminTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/OrganizationAdminTest.java index ee5623b423f..35186836804 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/OrganizationAdminTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/OrganizationAdminTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.operations.organizationadmin.CreateQuotaRequest; import org.cloudfoundry.operations.organizationadmin.DeleteQuotaRequest; @@ -25,37 +28,36 @@ import org.cloudfoundry.operations.organizationadmin.UpdateQuotaRequest; import org.cloudfoundry.operations.organizations.CreateOrganizationRequest; import org.cloudfoundry.operations.organizations.OrganizationInfoRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class OrganizationAdminTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; @Test public void createQuota() { String quotaName = this.nameFactory.getQuotaDefinitionName(); - this.cloudFoundryOperations.organizationAdmin() - .createQuota(CreateQuotaRequest.builder() - .applicationInstanceLimit(9) - .allowPaidServicePlans(false) - .instanceMemoryLimit(64) - .memoryLimit(512) - .name(quotaName) - .build()) - .then(requestGetQuota(this.cloudFoundryOperations, quotaName) - .map(OrganizationQuota::getInstanceMemoryLimit)) - .as(StepVerifier::create) - .expectNext(64) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .organizationAdmin() + .createQuota( + CreateQuotaRequest.builder() + .applicationInstanceLimit(9) + .allowPaidServicePlans(false) + .instanceMemoryLimit(64) + .memoryLimit(512) + .name(quotaName) + .build()) + .then( + requestGetQuota(this.cloudFoundryOperations, quotaName) + .map(OrganizationQuota::getInstanceMemoryLimit)) + .as(StepVerifier::create) + .expectNext(64) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -63,14 +65,18 @@ public void deleteQuota() { String quotaName = this.nameFactory.getQuotaDefinitionName(); requestCreateQuota(this.cloudFoundryOperations, quotaName) - .then(this.cloudFoundryOperations.organizationAdmin() - .deleteQuota(DeleteQuotaRequest.builder() - .name(quotaName) - .build())) - .then(requestGetQuota(this.cloudFoundryOperations, quotaName)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("Quota %s does not exist", quotaName)) - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .organizationAdmin() + .deleteQuota(DeleteQuotaRequest.builder().name(quotaName).build())) + .then(requestGetQuota(this.cloudFoundryOperations, quotaName)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Quota %s does not exist", quotaName)) + .verify(Duration.ofMinutes(5)); } @Test @@ -78,15 +84,15 @@ public void getQuota() { String quotaName = this.nameFactory.getQuotaDefinitionName(); requestCreateQuota(this.cloudFoundryOperations, quotaName) - .then(this.cloudFoundryOperations.organizationAdmin() - .getQuota(GetQuotaRequest.builder() - .name(quotaName) - .build()) - .map(OrganizationQuota::getApplicationInstanceLimit)) - .as(StepVerifier::create) - .expectNext(9) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .organizationAdmin() + .getQuota(GetQuotaRequest.builder().name(quotaName).build()) + .map(OrganizationQuota::getApplicationInstanceLimit)) + .as(StepVerifier::create) + .expectNext(9) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -94,14 +100,13 @@ public void listQuotas() { String quotaName = this.nameFactory.getQuotaDefinitionName(); requestCreateQuota(this.cloudFoundryOperations, quotaName) - .thenMany(this.cloudFoundryOperations.organizationAdmin() - .listQuotas()) - .filter(quota -> quotaName.equals(quota.getName())) - .map(OrganizationQuota::getTotalReservedRoutePorts) - .as(StepVerifier::create) - .expectNext(4) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany(this.cloudFoundryOperations.organizationAdmin().listQuotas()) + .filter(quota -> quotaName.equals(quota.getName())) + .map(OrganizationQuota::getTotalReservedRoutePorts) + .as(StepVerifier::create) + .expectNext(4) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -110,23 +115,28 @@ public void setQuota() { String quotaName = this.nameFactory.getQuotaDefinitionName(); Mono.when( - requestCreateOrganization(this.cloudFoundryOperations, organizationName), - requestCreateQuota(this.cloudFoundryOperations, quotaName) - ) - .then(this.cloudFoundryOperations.organizationAdmin() - .setQuota(SetQuotaRequest.builder() - .organizationName(organizationName) - .quotaName(quotaName) - .build())) - .then(this.cloudFoundryOperations.organizations() - .get(OrganizationInfoRequest.builder() - .name(organizationName) - .build()) - .map(organization -> organization.getQuota().getName())) - .as(StepVerifier::create) - .expectNext(quotaName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + requestCreateOrganization(this.cloudFoundryOperations, organizationName), + requestCreateQuota(this.cloudFoundryOperations, quotaName)) + .then( + this.cloudFoundryOperations + .organizationAdmin() + .setQuota( + SetQuotaRequest.builder() + .organizationName(organizationName) + .quotaName(quotaName) + .build())) + .then( + this.cloudFoundryOperations + .organizations() + .get( + OrganizationInfoRequest.builder() + .name(organizationName) + .build()) + .map(organization -> organization.getQuota().getName())) + .as(StepVerifier::create) + .expectNext(quotaName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -134,45 +144,54 @@ public void updateQuota() { String quotaName = this.nameFactory.getQuotaDefinitionName(); requestCreateQuota(this.cloudFoundryOperations, quotaName) - .then(this.cloudFoundryOperations.organizationAdmin() - .updateQuota(UpdateQuotaRequest.builder() - .name(quotaName) - .memoryLimit(513) - .build())) - .then(requestGetQuota(this.cloudFoundryOperations, quotaName) - .map(OrganizationQuota::getMemoryLimit)) - .as(StepVerifier::create) - .expectNext(513) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .organizationAdmin() + .updateQuota( + UpdateQuotaRequest.builder() + .name(quotaName) + .memoryLimit(513) + .build())) + .then( + requestGetQuota(this.cloudFoundryOperations, quotaName) + .map(OrganizationQuota::getMemoryLimit)) + .as(StepVerifier::create) + .expectNext(513) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono requestCreateOrganization(CloudFoundryOperations cloudFoundryOperations, String organizationName) { - return cloudFoundryOperations.organizations() - .create(CreateOrganizationRequest.builder() - .organizationName(organizationName) - .build()); + private static Mono requestCreateOrganization( + CloudFoundryOperations cloudFoundryOperations, String organizationName) { + return cloudFoundryOperations + .organizations() + .create( + CreateOrganizationRequest.builder() + .organizationName(organizationName) + .build()); } - private static Mono requestCreateQuota(CloudFoundryOperations cloudFoundryOperations, String quotaName) { - return cloudFoundryOperations.organizationAdmin() - .createQuota(CreateQuotaRequest.builder() - .applicationInstanceLimit(9) - .allowPaidServicePlans(false) - .instanceMemoryLimit(64) - .memoryLimit(512) - .totalReservedRoutePorts(4) - .totalRoutes(9) - .totalServices(9) - .name(quotaName) - .build()); + private static Mono requestCreateQuota( + CloudFoundryOperations cloudFoundryOperations, String quotaName) { + return cloudFoundryOperations + .organizationAdmin() + .createQuota( + CreateQuotaRequest.builder() + .applicationInstanceLimit(9) + .allowPaidServicePlans(false) + .instanceMemoryLimit(64) + .memoryLimit(512) + .totalReservedRoutePorts(4) + .totalRoutes(9) + .totalServices(9) + .name(quotaName) + .build()); } - private static Mono requestGetQuota(CloudFoundryOperations cloudFoundryOperations, String quotaName) { - return cloudFoundryOperations.organizationAdmin() - .getQuota(GetQuotaRequest.builder() - .name(quotaName) - .build()); + private static Mono requestGetQuota( + CloudFoundryOperations cloudFoundryOperations, String quotaName) { + return cloudFoundryOperations + .organizationAdmin() + .getQuota(GetQuotaRequest.builder().name(quotaName).build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/OrganizationsTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/OrganizationsTest.java index 0ec28ddf50a..3e4e2b57a63 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/OrganizationsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/OrganizationsTest.java @@ -16,50 +16,56 @@ package org.cloudfoundry.operations; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.operations.organizations.CreateOrganizationRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - - public final class OrganizationsTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; @Test public void create() { String organizationName = this.nameFactory.getOrganizationName(); - this.cloudFoundryOperations.organizations() - .create(CreateOrganizationRequest.builder() - .organizationName(organizationName) - .build()) - .thenMany(this.cloudFoundryOperations.organizations() - .list()) - .filter(organizationSummary -> organizationName.equals(organizationSummary.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .organizations() + .create( + CreateOrganizationRequest.builder() + .organizationName(organizationName) + .build()) + .thenMany(this.cloudFoundryOperations.organizations().list()) + .filter( + organizationSummary -> + organizationName.equals(organizationSummary.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { this.organizationId - .flatMapMany(organizationId -> this.cloudFoundryOperations.organizations() - .list() - .filter(organization -> organization.getId().equals(organizationId))) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapMany( + organizationId -> + this.cloudFoundryOperations + .organizations() + .list() + .filter( + organization -> + organization + .getId() + .equals(organizationId))) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/RoutesTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/RoutesTest.java index e5a2c3757c9..5a8c75e79c4 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/RoutesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/RoutesTest.java @@ -16,6 +16,16 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.operations.routes.Level.ORGANIZATION; +import static org.cloudfoundry.operations.routes.Level.SPACE; + +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; +import java.util.Collections; +import java.util.Optional; +import java.util.function.Predicate; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.operations.applications.ApplicationHealthCheck; import org.cloudfoundry.operations.applications.PushApplicationRequest; @@ -31,35 +41,22 @@ import org.cloudfoundry.operations.routes.UnmapRouteRequest; import org.cloudfoundry.operations.services.BindRouteServiceInstanceRequest; import org.cloudfoundry.operations.services.CreateUserProvidedServiceInstanceRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; -import java.util.Collections; -import java.util.Optional; -import java.util.function.Predicate; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.operations.routes.Level.ORGANIZATION; -import static org.cloudfoundry.operations.routes.Level.SPACE; - public final class RoutesTest extends AbstractIntegrationTest { private static final String DEFAULT_ROUTER_GROUP = "default-tcp"; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; - @Autowired - private String organizationName; + @Autowired private String organizationName; - @Autowired - private String spaceName; + @Autowired private String spaceName; @Test public void checkFalse() { @@ -67,16 +64,13 @@ public void checkFalse() { String host = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - this.cloudFoundryOperations.routes() - .check(CheckRouteRequest.builder() - .domain(domainName) - .host(host) - .path(path) - .build()) - .as(StepVerifier::create) - .expectNext(false) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .routes() + .check(CheckRouteRequest.builder().domain(domainName).host(host).path(path).build()) + .as(StepVerifier::create) + .expectNext(false) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -85,16 +79,25 @@ public void checkTruePrivateDomainNoHost() { String hostName = null; String path = this.nameFactory.getPath(); - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path) - .then(this.cloudFoundryOperations.routes() - .check(CheckRouteRequest.builder() - .domain(domainName) - .path(path) - .build())) - .as(StepVerifier::create) - .expectNext(true) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path) + .then( + this.cloudFoundryOperations + .routes() + .check( + CheckRouteRequest.builder() + .domain(domainName) + .path(path) + .build())) + .as(StepVerifier::create) + .expectNext(true) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -103,17 +106,21 @@ public void checkTrueSharedDomain() { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - createSharedDomainAndRoute(this.cloudFoundryOperations, this.spaceName, domainName, hostName, path) - .then(this.cloudFoundryOperations.routes() - .check(CheckRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .as(StepVerifier::create) - .expectNext(true) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSharedDomainAndRoute( + this.cloudFoundryOperations, this.spaceName, domainName, hostName, path) + .then( + this.cloudFoundryOperations + .routes() + .check( + CheckRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .as(StepVerifier::create) + .expectNext(true) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -122,17 +129,26 @@ public void create() { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path) - .then(this.cloudFoundryOperations.routes() - .check(CheckRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .as(StepVerifier::create) - .expectNext(true) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path) + .then( + this.cloudFoundryOperations + .routes() + .check( + CheckRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .as(StepVerifier::create) + .expectNext(true) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -141,13 +157,15 @@ public void createRouteTcpAssignedPort() { Integer port = this.nameFactory.getPort(); requestCreateSharedDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP) - .then(requestCreateRoute(this.cloudFoundryOperations, this.spaceName, domainName, port)) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(response -> domainName.equals(response.getDomain())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + requestCreateRoute( + this.cloudFoundryOperations, this.spaceName, domainName, port)) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(response -> domainName.equals(response.getDomain())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -155,13 +173,15 @@ public void createRouteTcpRandomPort() { String domainName = this.nameFactory.getDomainName(); requestCreateSharedDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP) - .then(requestCreateRoute(this.cloudFoundryOperations, this.spaceName, domainName, true)) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(response -> domainName.equals(response.getDomain())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + requestCreateRoute( + this.cloudFoundryOperations, this.spaceName, domainName, true)) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(response -> domainName.equals(response.getDomain())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -170,16 +190,22 @@ public void createRouteWithNonExistentDomain() { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - this.cloudFoundryOperations.routes() - .create(CreateRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .space(this.spaceName) - .build()) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("Domain %s does not exist", domainName)) - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .routes() + .create( + CreateRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .space(this.spaceName) + .build()) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Domain %s does not exist", domainName)) + .verify(Duration.ofMinutes(5)); } @Test @@ -188,23 +214,35 @@ public void delete() { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path) - .then(this.cloudFoundryOperations.routes() - .delete(DeleteRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .then(this.cloudFoundryOperations.routes() - .check(CheckRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .as(StepVerifier::create) - .expectNext(false) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path) + .then( + this.cloudFoundryOperations + .routes() + .delete( + DeleteRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .then( + this.cloudFoundryOperations + .routes() + .check( + CheckRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .as(StepVerifier::create) + .expectNext(false) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -213,15 +251,21 @@ public void deleteInvalidDomain() { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - this.cloudFoundryOperations.routes() - .delete(DeleteRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .build()) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("Domain %s does not exist", domainName)) - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .routes() + .delete( + DeleteRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .build()) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("Domain %s does not exist", domainName)) + .verify(Duration.ofMinutes(5)); } @Test @@ -230,20 +274,31 @@ public void deleteOrphanedRoutes() { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path) - .then(this.cloudFoundryOperations.routes() - .deleteOrphanedRoutes(DeleteOrphanedRoutesRequest.builder() - .build())) - .then(this.cloudFoundryOperations.routes() - .check(CheckRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .as(StepVerifier::create) - .expectNext(false) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path) + .then( + this.cloudFoundryOperations + .routes() + .deleteOrphanedRoutes( + DeleteOrphanedRoutesRequest.builder().build())) + .then( + this.cloudFoundryOperations + .routes() + .check( + CheckRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .as(StepVerifier::create) + .expectNext(false) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -251,17 +306,23 @@ public void deleteTcpRoute() { String domainName = this.nameFactory.getDomainName(); requestCreateSharedDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP) - .then(requestCreateRoute(this.cloudFoundryOperations, this.spaceName, domainName, true)) - .flatMap(port -> this.cloudFoundryOperations.routes() - .delete(DeleteRouteRequest.builder() - .domain(domainName) - .port(port) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(response -> domainName.equals(response.getDomain())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + requestCreateRoute( + this.cloudFoundryOperations, this.spaceName, domainName, true)) + .flatMap( + port -> + this.cloudFoundryOperations + .routes() + .delete( + DeleteRouteRequest.builder() + .domain(domainName) + .port(port) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(response -> domainName.equals(response.getDomain())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -270,16 +331,22 @@ public void listWithOrganizationLevel() { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path) - .thenMany(this.cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .level(ORGANIZATION) - .build())) - .filter(filterRoutes(domainName, hostName, path, null)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path) + .thenMany( + this.cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().level(ORGANIZATION).build())) + .filter(filterRoutes(domainName, hostName, path, null)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -289,19 +356,28 @@ public void listWithService() { String path = this.nameFactory.getPath(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - createSharedDomainAndRoute(this.cloudFoundryOperations, this.spaceName, domainName, hostName, path) - .then(requestCreateUserProvidedServiceInstance(this.cloudFoundryOperations, serviceInstanceName)) - .then(requestBindRouteServiceInstance(this.cloudFoundryOperations, domainName, hostName, path, serviceInstanceName)) - .thenMany(this.cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .level(SPACE) - .build())) - .filter(filterRoutes(domainName, hostName, path, null)) - .map(Route::getService) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createSharedDomainAndRoute( + this.cloudFoundryOperations, this.spaceName, domainName, hostName, path) + .then( + requestCreateUserProvidedServiceInstance( + this.cloudFoundryOperations, serviceInstanceName)) + .then( + requestBindRouteServiceInstance( + this.cloudFoundryOperations, + domainName, + hostName, + path, + serviceInstanceName)) + .thenMany( + this.cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().level(SPACE).build())) + .filter(filterRoutes(domainName, hostName, path, null)) + .map(Route::getService) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -310,16 +386,22 @@ public void listWithSpaceLevel() { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path) - .thenMany(this.cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .level(SPACE) - .build())) - .filter(filterRoutes(domainName, hostName, path, null)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path) + .thenMany( + this.cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().level(SPACE).build())) + .filter(filterRoutes(domainName, hostName, path, null)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -329,24 +411,35 @@ public void map() throws IOException { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - Mono - .when( - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path), - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - ) - .then(this.cloudFoundryOperations.routes() - .map(MapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(filterRoutes(domainName, hostName, path, applicationName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path), + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true)) + .then( + this.cloudFoundryOperations + .routes() + .map( + MapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(filterRoutes(domainName, hostName, path, applicationName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -356,24 +449,35 @@ public void mapNoHost() throws IOException { String hostName = null; String path = this.nameFactory.getPath(); - Mono - .when( - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path), - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - ) - .then(this.cloudFoundryOperations.routes() - .map(MapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(filterRoutes(domainName, hostName, path, applicationName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path), + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true)) + .then( + this.cloudFoundryOperations + .routes() + .map( + MapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(filterRoutes(domainName, hostName, path, applicationName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -383,24 +487,35 @@ public void mapNoPath() throws IOException { String hostName = this.nameFactory.getHostName(); String path = null; - Mono - .when( - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path), - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - ) - .then(this.cloudFoundryOperations.routes() - .map(MapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(filterRoutes(domainName, hostName, path, applicationName)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path), + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true)) + .then( + this.cloudFoundryOperations + .routes() + .map( + MapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(filterRoutes(domainName, hostName, path, applicationName)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -408,24 +523,30 @@ public void mapTcpRoute() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .when( - createSharedDomainAndTcpRoute(this.cloudFoundryOperations, domainName, this.spaceName), - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - ) - .then(this.cloudFoundryOperations.routes() - .map(MapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(response -> domainName.equals(response.getDomain())) - .single() - .map(route -> route.getApplications().size()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + createSharedDomainAndTcpRoute( + this.cloudFoundryOperations, domainName, this.spaceName), + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true)) + .then( + this.cloudFoundryOperations + .routes() + .map( + MapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(response -> domainName.equals(response.getDomain())) + .single() + .map(route -> route.getApplications().size()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -433,29 +554,38 @@ public void mapTcpRouteTwice() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - Mono - .when( - requestCreateSharedDomain(this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP), - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - ) - .then(this.cloudFoundryOperations.routes() - .map(MapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .randomPort(true) - .build())) - .then(this.cloudFoundryOperations.routes() - .map(MapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .randomPort(true) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(response -> domainName.equals(response.getDomain())) - .as(StepVerifier::create) - .expectNextCount(2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + requestCreateSharedDomain( + this.cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP), + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true)) + .then( + this.cloudFoundryOperations + .routes() + .map( + MapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .randomPort(true) + .build())) + .then( + this.cloudFoundryOperations + .routes() + .map( + MapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .randomPort(true) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(response -> domainName.equals(response.getDomain())) + .as(StepVerifier::create) + .expectNextCount(2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -465,24 +595,41 @@ public void unmap() throws IOException { String hostName = this.nameFactory.getHostName(); String path = this.nameFactory.getPath(); - Mono - .when( - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path), - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - ) - .then(requestMapRoute(this.cloudFoundryOperations, applicationName, domainName, hostName, path)) - .then(this.cloudFoundryOperations.routes() - .unmap(UnmapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(filterRoutes(domainName, hostName, path, applicationName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path), + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true)) + .then( + requestMapRoute( + this.cloudFoundryOperations, + applicationName, + domainName, + hostName, + path)) + .then( + this.cloudFoundryOperations + .routes() + .unmap( + UnmapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(filterRoutes(domainName, hostName, path, applicationName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -492,24 +639,41 @@ public void unmapNoPath() throws IOException { String hostName = this.nameFactory.getHostName(); String path = null; - Mono - .when( - createDomainAndRoute(this.cloudFoundryOperations, this.organizationName, this.spaceName, domainName, hostName, path), - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - ) - .then(requestMapRoute(this.cloudFoundryOperations, applicationName, domainName, hostName, path)) - .then(this.cloudFoundryOperations.routes() - .unmap(UnmapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .host(hostName) - .path(path) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(filterRoutes(domainName, hostName, path, applicationName)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + createDomainAndRoute( + this.cloudFoundryOperations, + this.organizationName, + this.spaceName, + domainName, + hostName, + path), + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true)) + .then( + requestMapRoute( + this.cloudFoundryOperations, + applicationName, + domainName, + hostName, + path)) + .then( + this.cloudFoundryOperations + .routes() + .unmap( + UnmapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .host(hostName) + .path(path) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(filterRoutes(domainName, hostName, path, applicationName)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -517,145 +681,236 @@ public void unmapTcpRoute() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String domainName = this.nameFactory.getDomainName(); - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName, true) - .then(createSharedDomainAndTcpRoute(this.cloudFoundryOperations, domainName, this.spaceName)) - .flatMap(port -> requestMapRoute(this.cloudFoundryOperations, applicationName, domainName, port)) - .flatMap(port -> this.cloudFoundryOperations.routes() - .unmap(UnmapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .port(port) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(response -> domainName.equals(response.getDomain())) - .map(route -> route.getApplications().size()) - .as(StepVerifier::create) - .expectNext(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono createDomainAndRoute(CloudFoundryOperations cloudFoundryOperations, String organizationName, String spaceName, String domainName, String hostName, String path) { + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName, + true) + .then( + createSharedDomainAndTcpRoute( + this.cloudFoundryOperations, domainName, this.spaceName)) + .flatMap( + port -> + requestMapRoute( + this.cloudFoundryOperations, + applicationName, + domainName, + port)) + .flatMap( + port -> + this.cloudFoundryOperations + .routes() + .unmap( + UnmapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .port(port) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(response -> domainName.equals(response.getDomain())) + .map(route -> route.getApplications().size()) + .as(StepVerifier::create) + .expectNext(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono createDomainAndRoute( + CloudFoundryOperations cloudFoundryOperations, + String organizationName, + String spaceName, + String domainName, + String hostName, + String path) { return requestCreateDomain(cloudFoundryOperations, organizationName, domainName) - .then(requestCreateRoute(cloudFoundryOperations, spaceName, domainName, hostName, path)); + .then( + requestCreateRoute( + cloudFoundryOperations, spaceName, domainName, hostName, path)); } - private static Mono createSharedDomainAndRoute(CloudFoundryOperations cloudFoundryOperations, String spaceName, String domainName, String hostName, String path) { + private static Mono createSharedDomainAndRoute( + CloudFoundryOperations cloudFoundryOperations, + String spaceName, + String domainName, + String hostName, + String path) { return requestCreateSharedDomain(cloudFoundryOperations, domainName, null) - .then(requestCreateRoute(cloudFoundryOperations, spaceName, domainName, hostName, path)); + .then( + requestCreateRoute( + cloudFoundryOperations, spaceName, domainName, hostName, path)); } - private static Mono createSharedDomainAndTcpRoute(CloudFoundryOperations cloudFoundryOperations, String domainName, String spaceName) { + private static Mono createSharedDomainAndTcpRoute( + CloudFoundryOperations cloudFoundryOperations, String domainName, String spaceName) { return requestCreateSharedDomain(cloudFoundryOperations, domainName, DEFAULT_ROUTER_GROUP) - .then(requestCreateRoute(cloudFoundryOperations, spaceName, domainName, true)); - } - - private static Predicate filterRoutes(String domainName, String host, String path, String applicationName) { - return route -> Optional.ofNullable(domainName).map(route.getDomain()::equals).orElse(true) - && Optional.ofNullable(host).map(route.getHost()::equals).orElse(true) - && Optional.ofNullable(applicationName).map(Collections::singletonList).map(route.getApplications()::equals).orElse(true) - && Optional.ofNullable(path).map(route.getPath()::equals).orElse(true); - } - - private static Mono requestBindRouteServiceInstance(CloudFoundryOperations cloudFoundryOperations, String domainName, String hostName, String path, String serviceInstanceName) { - return cloudFoundryOperations.services() - .bindRoute(BindRouteServiceInstanceRequest.builder() - .domainName(domainName) - .hostname(hostName) - .path(path) - .serviceInstanceName(serviceInstanceName) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryOperations cloudFoundryOperations, Path application, String name, Boolean noStart) { - return cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(application) - .healthCheckType(ApplicationHealthCheck.PORT) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .memory(64) - .name(name) - .noStart(noStart) - .build()); - } - - private static Mono requestCreateDomain(CloudFoundryOperations cloudFoundryOperations, String organizationName, String domainName) { - return cloudFoundryOperations.domains() - .create(CreateDomainRequest.builder() - .domain(domainName) - .organization(organizationName) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryOperations cloudFoundryOperations, String spaceName, String domainName, String hostName, String path) { - return cloudFoundryOperations.routes() - .create(CreateRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .space(spaceName) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryOperations cloudFoundryOperations, String spaceName, String domainName, Integer port) { - return cloudFoundryOperations.routes() - .create(CreateRouteRequest.builder() - .domain(domainName) - .port(port) - .space(spaceName) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryOperations cloudFoundryOperations, String spaceName, String domainName, Boolean randomPort) { - return cloudFoundryOperations.routes() - .create(CreateRouteRequest.builder() - .domain(domainName) - .randomPort(randomPort) - .space(spaceName) - .build()); - } - - private static Mono requestCreateSharedDomain(CloudFoundryOperations cloudFoundryOperations, String domainName, String routerGroup) { - return cloudFoundryOperations.domains() - .createShared(CreateSharedDomainRequest.builder() - .domain(domainName) - .routerGroup(routerGroup) - .build()); - } - - private static Mono requestCreateUserProvidedServiceInstance(CloudFoundryOperations cloudFoundryOperations, String name) { - return cloudFoundryOperations.services() - .createUserProvidedInstance(CreateUserProvidedServiceInstanceRequest.builder() - .name(name) - .routeServiceUrl("https://test.route.service") - .build()); + .then(requestCreateRoute(cloudFoundryOperations, spaceName, domainName, true)); + } + + private static Predicate filterRoutes( + String domainName, String host, String path, String applicationName) { + return route -> + Optional.ofNullable(domainName).map(route.getDomain()::equals).orElse(true) + && Optional.ofNullable(host).map(route.getHost()::equals).orElse(true) + && Optional.ofNullable(applicationName) + .map(Collections::singletonList) + .map(route.getApplications()::equals) + .orElse(true) + && Optional.ofNullable(path).map(route.getPath()::equals).orElse(true); + } + + private static Mono requestBindRouteServiceInstance( + CloudFoundryOperations cloudFoundryOperations, + String domainName, + String hostName, + String path, + String serviceInstanceName) { + return cloudFoundryOperations + .services() + .bindRoute( + BindRouteServiceInstanceRequest.builder() + .domainName(domainName) + .hostname(hostName) + .path(path) + .serviceInstanceName(serviceInstanceName) + .build()); + } + + private static Mono requestCreateApplication( + CloudFoundryOperations cloudFoundryOperations, + Path application, + String name, + Boolean noStart) { + return cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path(application) + .healthCheckType(ApplicationHealthCheck.PORT) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .memory(64) + .name(name) + .noStart(noStart) + .build()); + } + + private static Mono requestCreateDomain( + CloudFoundryOperations cloudFoundryOperations, + String organizationName, + String domainName) { + return cloudFoundryOperations + .domains() + .create( + CreateDomainRequest.builder() + .domain(domainName) + .organization(organizationName) + .build()); + } + + private static Mono requestCreateRoute( + CloudFoundryOperations cloudFoundryOperations, + String spaceName, + String domainName, + String hostName, + String path) { + return cloudFoundryOperations + .routes() + .create( + CreateRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .space(spaceName) + .build()); + } + + private static Mono requestCreateRoute( + CloudFoundryOperations cloudFoundryOperations, + String spaceName, + String domainName, + Integer port) { + return cloudFoundryOperations + .routes() + .create( + CreateRouteRequest.builder() + .domain(domainName) + .port(port) + .space(spaceName) + .build()); + } + + private static Mono requestCreateRoute( + CloudFoundryOperations cloudFoundryOperations, + String spaceName, + String domainName, + Boolean randomPort) { + return cloudFoundryOperations + .routes() + .create( + CreateRouteRequest.builder() + .domain(domainName) + .randomPort(randomPort) + .space(spaceName) + .build()); + } + + private static Mono requestCreateSharedDomain( + CloudFoundryOperations cloudFoundryOperations, String domainName, String routerGroup) { + return cloudFoundryOperations + .domains() + .createShared( + CreateSharedDomainRequest.builder() + .domain(domainName) + .routerGroup(routerGroup) + .build()); + } + + private static Mono requestCreateUserProvidedServiceInstance( + CloudFoundryOperations cloudFoundryOperations, String name) { + return cloudFoundryOperations + .services() + .createUserProvidedInstance( + CreateUserProvidedServiceInstanceRequest.builder() + .name(name) + .routeServiceUrl("https://test.route.service") + .build()); } private static Flux requestListRoutes(CloudFoundryOperations cloudFoundryOperations) { - return cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .level(SPACE) - .build()); - } - - private static Mono requestMapRoute(CloudFoundryOperations cloudFoundryOperations, String applicationName, String domainName, String hostName, String path) { - return cloudFoundryOperations.routes() - .map(MapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .host(hostName) - .path(path) - .build()); + return cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().level(SPACE).build()); + } + + private static Mono requestMapRoute( + CloudFoundryOperations cloudFoundryOperations, + String applicationName, + String domainName, + String hostName, + String path) { + return cloudFoundryOperations + .routes() + .map( + MapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .host(hostName) + .path(path) + .build()); + } + + private static Mono requestMapRoute( + CloudFoundryOperations cloudFoundryOperations, + String applicationName, + String domainName, + Integer port) { + return cloudFoundryOperations + .routes() + .map( + MapRouteRequest.builder() + .applicationName(applicationName) + .domain(domainName) + .port(port) + .build()); } - - private static Mono requestMapRoute(CloudFoundryOperations cloudFoundryOperations, String applicationName, String domainName, Integer port) { - return cloudFoundryOperations.routes() - .map(MapRouteRequest.builder() - .applicationName(applicationName) - .domain(domainName) - .port(port) - .build()); - } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/ServiceAdminTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/ServiceAdminTest.java index 3fb44a0eeba..890c4c09b76 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/ServiceAdminTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/ServiceAdminTest.java @@ -16,6 +16,10 @@ package org.cloudfoundry.operations; +import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; +import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.ServiceBrokerUtils; import org.cloudfoundry.client.CloudFoundryClient; @@ -27,38 +31,27 @@ import org.cloudfoundry.operations.serviceadmin.ListServiceAccessSettingsRequest; import org.cloudfoundry.operations.serviceadmin.ServiceAccess; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.ServiceBrokerUtils.createServiceBroker; -import static org.cloudfoundry.ServiceBrokerUtils.deleteServiceBroker; - public final class ServiceAdminTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; - @Autowired - private Mono organizationId; + @Autowired private Mono organizationId; - @Autowired - private String organizationName; + @Autowired private String organizationName; - @Autowired - private String planName; + @Autowired private String planName; - @Autowired - private String serviceBrokerName; + @Autowired private String serviceBrokerName; - @Autowired - private String serviceName; + @Autowired private String serviceName; @Test public void disableServiceAccess() { @@ -67,31 +60,51 @@ public void disableServiceAccess() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); resetToEnabled(this.cloudFoundryOperations, serviceName) - .then(this.cloudFoundryOperations.serviceAdmin() - .disableServiceAccess(DisableServiceAccessRequest.builder() - .serviceName(serviceName) - .build())) - .thenMany(requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) - .filter(response -> serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.NONE) - .brokerName(serviceBrokerName) - .organizationNames() - .planName(planName) - .serviceName(serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .serviceAdmin() + .disableServiceAccess( + DisableServiceAccessRequest.builder() + .serviceName(serviceName) + .build())) + .thenMany( + requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) + .filter(response -> serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.NONE) + .brokerName(serviceBrokerName) + .organizationNames() + .planName(planName) + .serviceName(serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -101,33 +114,53 @@ public void disableServiceAccessSpecifyAll() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); resetToEnabled(this.cloudFoundryOperations, serviceName) - .then(this.cloudFoundryOperations.serviceAdmin() - .disableServiceAccess(DisableServiceAccessRequest.builder() - .organizationName(this.organizationName) - .servicePlanName(planName) - .serviceName(serviceName) - .build())) - .thenMany(requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) - .filter(response -> serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(serviceBrokerName) - .organizationNames() - .planName(planName) - .serviceName(serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .serviceAdmin() + .disableServiceAccess( + DisableServiceAccessRequest.builder() + .organizationName(this.organizationName) + .servicePlanName(planName) + .serviceName(serviceName) + .build())) + .thenMany( + requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) + .filter(response -> serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(serviceBrokerName) + .organizationNames() + .planName(planName) + .serviceName(serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -137,32 +170,52 @@ public void disableServiceAccessSpecifyOrganization() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); resetToEnabled(this.cloudFoundryOperations, serviceName) - .then(this.cloudFoundryOperations.serviceAdmin() - .disableServiceAccess(DisableServiceAccessRequest.builder() - .organizationName(this.organizationName) - .serviceName(serviceName) - .build())) - .thenMany(requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) - .filter(response -> serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(serviceBrokerName) - .organizationNames() - .planName(planName) - .serviceName(serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .serviceAdmin() + .disableServiceAccess( + DisableServiceAccessRequest.builder() + .organizationName(this.organizationName) + .serviceName(serviceName) + .build())) + .thenMany( + requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) + .filter(response -> serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(serviceBrokerName) + .organizationNames() + .planName(planName) + .serviceName(serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -172,32 +225,52 @@ public void disableServiceAccessSpecifyServicePlan() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); resetToEnabled(this.cloudFoundryOperations, serviceName) - .then(this.cloudFoundryOperations.serviceAdmin() - .disableServiceAccess(DisableServiceAccessRequest.builder() - .servicePlanName(planName) - .serviceName(serviceName) - .build())) - .thenMany(requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) - .filter(response -> serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(serviceBrokerName) - .organizationNames() - .planName(planName) - .serviceName(serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .serviceAdmin() + .disableServiceAccess( + DisableServiceAccessRequest.builder() + .servicePlanName(planName) + .serviceName(serviceName) + .build())) + .thenMany( + requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) + .filter(response -> serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(serviceBrokerName) + .organizationNames() + .planName(planName) + .serviceName(serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -207,31 +280,51 @@ public void enableServiceAccess() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); resetToDisabled(this.cloudFoundryOperations, serviceName) - .then(this.cloudFoundryOperations.serviceAdmin() - .enableServiceAccess(EnableServiceAccessRequest.builder() - .serviceName(serviceName) - .build())) - .thenMany(requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) - .filter(response -> serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(serviceBrokerName) - .organizationNames() - .planName(planName) - .serviceName(serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .serviceAdmin() + .enableServiceAccess( + EnableServiceAccessRequest.builder() + .serviceName(serviceName) + .build())) + .thenMany( + requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) + .filter(response -> serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(serviceBrokerName) + .organizationNames() + .planName(planName) + .serviceName(serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -241,33 +334,53 @@ public void enableServiceAccessSpecifyAll() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); resetToDisabled(this.cloudFoundryOperations, serviceName) - .then(this.cloudFoundryOperations.serviceAdmin() - .enableServiceAccess(EnableServiceAccessRequest.builder() - .organizationName(this.organizationName) - .servicePlanName(planName) - .serviceName(serviceName) - .build())) - .thenMany(requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) - .filter(response -> serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.LIMITED) - .brokerName(serviceBrokerName) - .organizationName(this.organizationName) - .planName(planName) - .serviceName(serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .serviceAdmin() + .enableServiceAccess( + EnableServiceAccessRequest.builder() + .organizationName(this.organizationName) + .servicePlanName(planName) + .serviceName(serviceName) + .build())) + .thenMany( + requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) + .filter(response -> serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.LIMITED) + .brokerName(serviceBrokerName) + .organizationName(this.organizationName) + .planName(planName) + .serviceName(serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -277,32 +390,52 @@ public void enableServiceAccessSpecifyOrganization() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); resetToDisabled(this.cloudFoundryOperations, serviceName) - .then(this.cloudFoundryOperations.serviceAdmin() - .enableServiceAccess(EnableServiceAccessRequest.builder() - .organizationName(this.organizationName) - .serviceName(serviceName) - .build())) - .thenMany(requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) - .filter(response -> serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.LIMITED) - .brokerName(serviceBrokerName) - .organizationName(this.organizationName) - .planName(planName) - .serviceName(serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .serviceAdmin() + .enableServiceAccess( + EnableServiceAccessRequest.builder() + .organizationName(this.organizationName) + .serviceName(serviceName) + .build())) + .thenMany( + requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) + .filter(response -> serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.LIMITED) + .brokerName(serviceBrokerName) + .organizationName(this.organizationName) + .planName(planName) + .serviceName(serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test @@ -312,146 +445,189 @@ public void enableServiceAccessSpecifyServicePlan() { String serviceName = this.nameFactory.getServiceName(); String spaceName = this.nameFactory.getSpaceName(); - ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = this.organizationId - .flatMap(organizationId -> createSpaceId(this.cloudFoundryClient, organizationId, spaceName)) - .flatMap(spaceId -> createServiceBroker(this.cloudFoundryClient, this.nameFactory, planName, serviceBrokerName, serviceName, spaceId, false)) - .block(Duration.ofMinutes(5)); + ServiceBrokerUtils.ServiceBrokerMetadata serviceBrokerMetadata = + this.organizationId + .flatMap( + organizationId -> + createSpaceId( + this.cloudFoundryClient, organizationId, spaceName)) + .flatMap( + spaceId -> + createServiceBroker( + this.cloudFoundryClient, + this.nameFactory, + planName, + serviceBrokerName, + serviceName, + spaceId, + false)) + .block(Duration.ofMinutes(5)); resetToDisabled(this.cloudFoundryOperations, serviceName) - .then(this.cloudFoundryOperations.serviceAdmin() - .enableServiceAccess(EnableServiceAccessRequest.builder() - .servicePlanName(planName) - .serviceName(serviceName) - .build())) - .thenMany(requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) - .filter(response -> serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(serviceBrokerName) - .organizationNames() - .planName(planName) - .serviceName(serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); - - deleteServiceBroker(this.cloudFoundryClient, serviceBrokerMetadata.applicationMetadata.applicationId) - .block(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .serviceAdmin() + .enableServiceAccess( + EnableServiceAccessRequest.builder() + .servicePlanName(planName) + .serviceName(serviceName) + .build())) + .thenMany( + requestListServiceAccessSettings(this.cloudFoundryOperations, serviceName)) + .filter(response -> serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(serviceBrokerName) + .organizationNames() + .planName(planName) + .serviceName(serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); + + deleteServiceBroker( + this.cloudFoundryClient, + serviceBrokerMetadata.applicationMetadata.applicationId) + .block(Duration.ofMinutes(5)); } @Test public void listServiceAccessSettings() { resetToEnabled(this.cloudFoundryOperations, this.serviceName) - .thenMany(this.cloudFoundryOperations.serviceAdmin() - .listServiceAccessSettings(ListServiceAccessSettingsRequest.builder() - .build())) - .filter(response -> this.serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(this.serviceBrokerName) - .organizationNames() - .planName(this.planName) - .serviceName(this.serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + this.cloudFoundryOperations + .serviceAdmin() + .listServiceAccessSettings( + ListServiceAccessSettingsRequest.builder().build())) + .filter(response -> this.serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(this.serviceBrokerName) + .organizationNames() + .planName(this.planName) + .serviceName(this.serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServiceAccessSettingsSpecifyBroker() { resetToEnabled(this.cloudFoundryOperations, this.serviceName) - .thenMany(this.cloudFoundryOperations.serviceAdmin() - .listServiceAccessSettings(ListServiceAccessSettingsRequest.builder() - .brokerName(this.serviceBrokerName) - .build())) - .filter(serviceAccess -> this.serviceName.equals(serviceAccess.getServiceName())) - .single() - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(this.serviceBrokerName) - .organizationNames() - .planName(this.planName) - .serviceName(this.serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + this.cloudFoundryOperations + .serviceAdmin() + .listServiceAccessSettings( + ListServiceAccessSettingsRequest.builder() + .brokerName(this.serviceBrokerName) + .build())) + .filter(serviceAccess -> this.serviceName.equals(serviceAccess.getServiceName())) + .single() + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(this.serviceBrokerName) + .organizationNames() + .planName(this.planName) + .serviceName(this.serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServiceAccessSettingsSpecifyOrganization() { resetToEnabled(this.cloudFoundryOperations, this.serviceName) - .thenMany(this.cloudFoundryOperations.serviceAdmin() - .listServiceAccessSettings(ListServiceAccessSettingsRequest.builder() - .organizationName(this.organizationName) - .build())) - .filter(response -> this.serviceName.equals(response.getServiceName())) - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(this.serviceBrokerName) - .organizationNames() - .planName(this.planName) - .serviceName(this.serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + this.cloudFoundryOperations + .serviceAdmin() + .listServiceAccessSettings( + ListServiceAccessSettingsRequest.builder() + .organizationName(this.organizationName) + .build())) + .filter(response -> this.serviceName.equals(response.getServiceName())) + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(this.serviceBrokerName) + .organizationNames() + .planName(this.planName) + .serviceName(this.serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServiceAccessSettingsSpecifyService() { resetToEnabled(this.cloudFoundryOperations, this.serviceName) - .thenMany(this.cloudFoundryOperations.serviceAdmin() - .listServiceAccessSettings(ListServiceAccessSettingsRequest.builder() - .serviceName(this.serviceName) - .build())) - .single() - .as(StepVerifier::create) - .expectNext(ServiceAccess.builder() - .access(Access.ALL) - .brokerName(this.serviceBrokerName) - .organizationNames() - .planName(this.planName) - .serviceName(this.serviceName) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + this.cloudFoundryOperations + .serviceAdmin() + .listServiceAccessSettings( + ListServiceAccessSettingsRequest.builder() + .serviceName(this.serviceName) + .build())) + .single() + .as(StepVerifier::create) + .expectNext( + ServiceAccess.builder() + .access(Access.ALL) + .brokerName(this.serviceBrokerName) + .organizationNames() + .planName(this.planName) + .serviceName(this.serviceName) + .build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createSpaceId(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + private static Mono createSpaceId( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { return requestCreateSpace(cloudFoundryClient, organizationId, spaceName) - .map(ResourceUtils::getId); + .map(ResourceUtils::getId); } - private static Mono requestCreateSpace(CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { - return cloudFoundryClient.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organizationId(organizationId) - .build()); + private static Mono requestCreateSpace( + CloudFoundryClient cloudFoundryClient, String organizationId, String spaceName) { + return cloudFoundryClient + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organizationId(organizationId) + .build()); } - private static Flux requestListServiceAccessSettings(CloudFoundryOperations cloudFoundryOperations, String serviceName) { - return cloudFoundryOperations.serviceAdmin() - .listServiceAccessSettings(ListServiceAccessSettingsRequest.builder() - .serviceName(serviceName) - .build()); + private static Flux requestListServiceAccessSettings( + CloudFoundryOperations cloudFoundryOperations, String serviceName) { + return cloudFoundryOperations + .serviceAdmin() + .listServiceAccessSettings( + ListServiceAccessSettingsRequest.builder() + .serviceName(serviceName) + .build()); } - private static Mono resetToDisabled(CloudFoundryOperations cloudFoundryOperations, String serviceName) { - return cloudFoundryOperations.serviceAdmin() - .disableServiceAccess(DisableServiceAccessRequest.builder() - .serviceName(serviceName) - .build()); + private static Mono resetToDisabled( + CloudFoundryOperations cloudFoundryOperations, String serviceName) { + return cloudFoundryOperations + .serviceAdmin() + .disableServiceAccess( + DisableServiceAccessRequest.builder().serviceName(serviceName).build()); } - private static Mono resetToEnabled(CloudFoundryOperations cloudFoundryOperations, String serviceName) { - return cloudFoundryOperations.serviceAdmin() - .enableServiceAccess(EnableServiceAccessRequest.builder() - .serviceName(serviceName) - .build()); + private static Mono resetToEnabled( + CloudFoundryOperations cloudFoundryOperations, String serviceName) { + return cloudFoundryOperations + .serviceAdmin() + .enableServiceAccess( + EnableServiceAccessRequest.builder().serviceName(serviceName).build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/ServicesTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/ServicesTest.java index b55a3bd469f..1d3355a4ba2 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/ServicesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/ServicesTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.operations.routes.Level.SPACE; + +import java.io.IOException; +import java.nio.file.Path; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.servicebindings.ListServiceBindingsRequest; @@ -51,41 +57,28 @@ import org.cloudfoundry.operations.services.UpdateServiceInstanceRequest; import org.cloudfoundry.operations.services.UpdateUserProvidedServiceInstanceRequest; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.ClassPathResource; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.io.IOException; -import java.nio.file.Path; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.operations.routes.Level.SPACE; - public final class ServicesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; - @Autowired - private String organizationName; + @Autowired private String organizationName; - @Autowired - private String planName; + @Autowired private String planName; - @Autowired - private Mono serviceBrokerId; + @Autowired private Mono serviceBrokerId; - @Autowired - private String serviceName; + @Autowired private String serviceName; - @Autowired - private String spaceName; + @Autowired private String spaceName; @Test public void bindRoutePrivateDomain() { @@ -94,27 +87,39 @@ public void bindRoutePrivateDomain() { String path = this.nameFactory.getPath(); String userProvidedServiceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .when( - requestCreatePrivateDomain(this.cloudFoundryOperations, domainName, this.organizationName), - requestCreateUserProvidedServiceInstance(this.cloudFoundryOperations, userProvidedServiceInstanceName) - ) - .then(requestCreateRoute(this.cloudFoundryOperations, domainName, hostName, path, this.spaceName)) - .then(this.cloudFoundryOperations.services() - .bindRoute(BindRouteServiceInstanceRequest.builder() - .domainName(domainName) - .hostname(hostName) - .parameter("integration-test-key", "integration-test-value") - .path(path) - .serviceInstanceName(userProvidedServiceInstanceName) - .build())) - .thenMany(requestListRoutes(this.cloudFoundryOperations)) - .filter(response -> domainName.equals(response.getDomain())) - .map(Route::getHost) - .as(StepVerifier::create) - .expectNext(hostName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + requestCreatePrivateDomain( + this.cloudFoundryOperations, domainName, this.organizationName), + requestCreateUserProvidedServiceInstance( + this.cloudFoundryOperations, userProvidedServiceInstanceName)) + .then( + requestCreateRoute( + this.cloudFoundryOperations, + domainName, + hostName, + path, + this.spaceName)) + .then( + this.cloudFoundryOperations + .services() + .bindRoute( + BindRouteServiceInstanceRequest.builder() + .domainName(domainName) + .hostname(hostName) + .parameter( + "integration-test-key", + "integration-test-value") + .path(path) + .serviceInstanceName( + userProvidedServiceInstanceName) + .build())) + .thenMany(requestListRoutes(this.cloudFoundryOperations)) + .filter(response -> domainName.equals(response.getDomain())) + .map(Route::getHost) + .as(StepVerifier::create) + .expectNext(hostName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -122,41 +127,54 @@ public void bindService() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .when( - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName), - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - ) - .then(this.cloudFoundryOperations.services() - .bind(BindServiceInstanceRequest.builder() - .applicationName(applicationName) - .serviceInstanceName(serviceInstanceName) - .build())) - .then(getApplicationId(this.cloudFoundryOperations, applicationName)) - .flatMapMany(applicationId -> requestListServiceBindings(this.cloudFoundryClient, applicationId)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName), + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName)) + .then( + this.cloudFoundryOperations + .services() + .bind( + BindServiceInstanceRequest.builder() + .applicationName(applicationName) + .serviceInstanceName(serviceInstanceName) + .build())) + .then(getApplicationId(this.cloudFoundryOperations, applicationName)) + .flatMapMany( + applicationId -> + requestListServiceBindings(this.cloudFoundryClient, applicationId)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void create() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - this.cloudFoundryOperations.services() - .createInstance(CreateServiceInstanceRequest.builder() - .planName(this.planName) - .serviceName(this.serviceName) - .serviceInstanceName(serviceInstanceName) - .build()) - .thenMany(requestListServiceInstances(this.cloudFoundryOperations) - .map(ServiceInstanceSummary::getName)) - .filter(serviceInstanceName::equals) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .services() + .createInstance( + CreateServiceInstanceRequest.builder() + .planName(this.planName) + .serviceName(this.serviceName) + .serviceInstanceName(serviceInstanceName) + .build()) + .thenMany( + requestListServiceInstances(this.cloudFoundryOperations) + .map(ServiceInstanceSummary::getName)) + .filter(serviceInstanceName::equals) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @SuppressWarnings("unchecked") @@ -165,39 +183,53 @@ public void createServiceKey() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - .then(this.cloudFoundryOperations.services() - .createServiceKey(CreateServiceKeyRequest.builder() - .parameter("test-key", "test-value") - .serviceInstanceName(serviceInstanceName) - .serviceKeyName(serviceKeyName) - .build())) - .thenMany(requestGetServiceKey(this.cloudFoundryOperations, serviceInstanceName, serviceKeyName) - .map(ServiceKey::getName)) - .as(StepVerifier::create) - .expectNext(serviceKeyName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName) + .then( + this.cloudFoundryOperations + .services() + .createServiceKey( + CreateServiceKeyRequest.builder() + .parameter("test-key", "test-value") + .serviceInstanceName(serviceInstanceName) + .serviceKeyName(serviceKeyName) + .build())) + .thenMany( + requestGetServiceKey( + this.cloudFoundryOperations, + serviceInstanceName, + serviceKeyName) + .map(ServiceKey::getName)) + .as(StepVerifier::create) + .expectNext(serviceKeyName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void createUserProvidedServiceInstance() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - this.cloudFoundryOperations.services() - .createUserProvidedInstance(CreateUserProvidedServiceInstanceRequest.builder() - .credential("test-credential-key", "test-credential-value") - .name(serviceInstanceName) - .syslogDrainUrl("test.url") - .routeServiceUrl("https://test.url") - .build()) - .thenMany(requestListServiceInstances(this.cloudFoundryOperations) - .map(ServiceInstanceSummary::getName)) - .filter(serviceInstanceName::equals) - .as(StepVerifier::create) - .expectNext(serviceInstanceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .services() + .createUserProvidedInstance( + CreateUserProvidedServiceInstanceRequest.builder() + .credential("test-credential-key", "test-credential-value") + .name(serviceInstanceName) + .syslogDrainUrl("test.url") + .routeServiceUrl("https://test.url") + .build()) + .thenMany( + requestListServiceInstances(this.cloudFoundryOperations) + .map(ServiceInstanceSummary::getName)) + .filter(serviceInstanceName::equals) + .as(StepVerifier::create) + .expectNext(serviceInstanceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -205,17 +237,27 @@ public void delete() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName)) - .then(this.cloudFoundryOperations.services() - .deleteInstance(DeleteServiceInstanceRequest.builder() - .name(serviceInstanceName) - .build())) - .thenMany(requestListServiceInstances(this.cloudFoundryOperations) - .map(ServiceInstanceSummary::getName)) - .filter(serviceInstanceName::equals) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName)) + .then( + this.cloudFoundryOperations + .services() + .deleteInstance( + DeleteServiceInstanceRequest.builder() + .name(serviceInstanceName) + .build())) + .thenMany( + requestListServiceInstances(this.cloudFoundryOperations) + .map(ServiceInstanceSummary::getName)) + .filter(serviceInstanceName::equals) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -223,33 +265,56 @@ public void deleteServiceKey() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - .then(requestCreateServiceKey(this.cloudFoundryOperations, serviceKeyName, serviceInstanceName)) - .then(this.cloudFoundryOperations.services() - .deleteServiceKey(DeleteServiceKeyRequest.builder() - .serviceInstanceName(serviceInstanceName) - .serviceKeyName(serviceKeyName) - .build())) - .thenMany(requestGetServiceKey(this.cloudFoundryOperations, serviceInstanceName, serviceKeyName)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("Service key %s does not exist", serviceKeyName)) - .verify(Duration.ofMinutes(5)); + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName) + .then( + requestCreateServiceKey( + this.cloudFoundryOperations, serviceKeyName, serviceInstanceName)) + .then( + this.cloudFoundryOperations + .services() + .deleteServiceKey( + DeleteServiceKeyRequest.builder() + .serviceInstanceName(serviceInstanceName) + .serviceKeyName(serviceKeyName) + .build())) + .thenMany( + requestGetServiceKey( + this.cloudFoundryOperations, serviceInstanceName, serviceKeyName)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage( + "Service key %s does not exist", serviceKeyName)) + .verify(Duration.ofMinutes(5)); } @Test public void getManagedService() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - .then(this.cloudFoundryOperations.services() - .getInstance(GetServiceInstanceRequest.builder() - .name(serviceInstanceName) - .build()) - .map(ServiceInstance::getPlan)) - .as(StepVerifier::create) - .expectNext(this.planName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName) + .then( + this.cloudFoundryOperations + .services() + .getInstance( + GetServiceInstanceRequest.builder() + .name(serviceInstanceName) + .build()) + .map(ServiceInstance::getPlan)) + .as(StepVerifier::create) + .expectNext(this.planName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -257,18 +322,27 @@ public void getServiceKey() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - .then(requestCreateServiceKey(this.cloudFoundryOperations, serviceKeyName, serviceInstanceName)) - .thenMany(this.cloudFoundryOperations.services() - .getServiceKey(GetServiceKeyRequest.builder() - .serviceInstanceName(serviceInstanceName) - .serviceKeyName(serviceKeyName) - .build()) - .map(ServiceKey::getName)) - .as(StepVerifier::create) - .expectNext(serviceKeyName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName) + .then( + requestCreateServiceKey( + this.cloudFoundryOperations, serviceKeyName, serviceInstanceName)) + .thenMany( + this.cloudFoundryOperations + .services() + .getServiceKey( + GetServiceKeyRequest.builder() + .serviceInstanceName(serviceInstanceName) + .serviceKeyName(serviceKeyName) + .build()) + .map(ServiceKey::getName)) + .as(StepVerifier::create) + .expectNext(serviceKeyName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -276,33 +350,49 @@ public void listServiceKey() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); String serviceKeyName = this.nameFactory.getServiceKeyName(); - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - .then(requestCreateServiceKey(this.cloudFoundryOperations, serviceKeyName, serviceInstanceName)) - .thenMany(this.cloudFoundryOperations.services() - .listServiceKeys(ListServiceKeysRequest.builder() - .serviceInstanceName(serviceInstanceName) - .build()) - .map(ServiceKey::getName)) - .as(StepVerifier::create) - .expectNext(serviceKeyName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName) + .then( + requestCreateServiceKey( + this.cloudFoundryOperations, serviceKeyName, serviceInstanceName)) + .thenMany( + this.cloudFoundryOperations + .services() + .listServiceKeys( + ListServiceKeysRequest.builder() + .serviceInstanceName(serviceInstanceName) + .build()) + .map(ServiceKey::getName)) + .as(StepVerifier::create) + .expectNext(serviceKeyName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listServiceOfferings() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - .thenMany(this.cloudFoundryOperations.services() - .listServiceOfferings(ListServiceOfferingsRequest.builder() - .serviceName(this.serviceName) - .build()) - .map(ServiceOffering::getDescription)) - .as(StepVerifier::create) - .expectNext("test-service-description") - .expectComplete() - .verify(Duration.ofMinutes(5)); + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName) + .thenMany( + this.cloudFoundryOperations + .services() + .listServiceOfferings( + ListServiceOfferingsRequest.builder() + .serviceName(this.serviceName) + .build()) + .map(ServiceOffering::getDescription)) + .as(StepVerifier::create) + .expectNext("test-service-description") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -310,19 +400,27 @@ public void rename() { String serviceInstanceName1 = this.nameFactory.getServiceInstanceName(); String serviceInstanceName2 = this.nameFactory.getServiceInstanceName(); - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName1, this.serviceName) - .then(this.cloudFoundryOperations.services() - .renameInstance(RenameServiceInstanceRequest.builder() - .name(serviceInstanceName1) - .newName(serviceInstanceName2) - .build())) - .thenMany(requestListServiceInstances(this.cloudFoundryOperations) - .map(ServiceInstanceSummary::getName)) - .filter(serviceInstanceName2::equals) - .as(StepVerifier::create) - .expectNext(serviceInstanceName2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName1, + this.serviceName) + .then( + this.cloudFoundryOperations + .services() + .renameInstance( + RenameServiceInstanceRequest.builder() + .name(serviceInstanceName1) + .newName(serviceInstanceName2) + .build())) + .thenMany( + requestListServiceInstances(this.cloudFoundryOperations) + .map(ServiceInstanceSummary::getName)) + .filter(serviceInstanceName2::equals) + .as(StepVerifier::create) + .expectNext(serviceInstanceName2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -332,25 +430,40 @@ public void unbindRoute() { String path = this.nameFactory.getPath(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .when( - requestCreatePrivateDomain(this.cloudFoundryOperations, domainName, this.organizationName), - requestCreateUserProvidedServiceInstance(this.cloudFoundryOperations, serviceInstanceName) - ) - .then(requestCreateRoute(this.cloudFoundryOperations, domainName, hostName, path, this.spaceName)) - .then(requestBindRoute(this.cloudFoundryOperations, domainName, hostName, path, serviceInstanceName)) - .then(this.cloudFoundryOperations.services() - .unbindRoute(UnbindRouteServiceInstanceRequest.builder() - .domainName(domainName) - .hostname(hostName) - .path(path) - .serviceInstanceName(serviceInstanceName) - .build())) - .thenMany(requestGetInstance(this.cloudFoundryOperations, serviceInstanceName)) - .filter(response -> domainName.equals(response.getLastOperation())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + requestCreatePrivateDomain( + this.cloudFoundryOperations, domainName, this.organizationName), + requestCreateUserProvidedServiceInstance( + this.cloudFoundryOperations, serviceInstanceName)) + .then( + requestCreateRoute( + this.cloudFoundryOperations, + domainName, + hostName, + path, + this.spaceName)) + .then( + requestBindRoute( + this.cloudFoundryOperations, + domainName, + hostName, + path, + serviceInstanceName)) + .then( + this.cloudFoundryOperations + .services() + .unbindRoute( + UnbindRouteServiceInstanceRequest.builder() + .domainName(domainName) + .hostname(hostName) + .path(path) + .serviceInstanceName(serviceInstanceName) + .build())) + .thenMany(requestGetInstance(this.cloudFoundryOperations, serviceInstanceName)) + .filter(response -> domainName.equals(response.getLastOperation())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -358,22 +471,34 @@ public void unbindService() throws IOException { String applicationName = this.nameFactory.getApplicationName(); String serviceInstanceName = this.nameFactory.getServiceInstanceName(); - Mono - .when( - requestCreateApplication(this.cloudFoundryOperations, new ClassPathResource("test-application.zip").getFile().toPath(), applicationName), - requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName) - ) - .then(requestBindService(this.cloudFoundryOperations, applicationName, serviceInstanceName)) - .then(this.cloudFoundryOperations.services() - .unbind(UnbindServiceInstanceRequest.builder() - .applicationName(applicationName) - .serviceInstanceName(serviceInstanceName) - .build())) - .then(getApplicationId(this.cloudFoundryOperations, applicationName)) - .flatMapMany(applicationId -> requestListServiceBindings(this.cloudFoundryClient, applicationId)) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.when( + requestCreateApplication( + this.cloudFoundryOperations, + new ClassPathResource("test-application.zip").getFile().toPath(), + applicationName), + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName)) + .then( + requestBindService( + this.cloudFoundryOperations, applicationName, serviceInstanceName)) + .then( + this.cloudFoundryOperations + .services() + .unbind( + UnbindServiceInstanceRequest.builder() + .applicationName(applicationName) + .serviceInstanceName(serviceInstanceName) + .build())) + .then(getApplicationId(this.cloudFoundryOperations, applicationName)) + .flatMapMany( + applicationId -> + requestListServiceBindings(this.cloudFoundryClient, applicationId)) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -381,18 +506,28 @@ public void updateInstance() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> requestCreateServiceInstance(this.cloudFoundryOperations, this.planName, serviceInstanceName, this.serviceName)) - .then(this.cloudFoundryOperations.services() - .updateInstance(UpdateServiceInstanceRequest.builder() - .serviceInstanceName(serviceInstanceName) - .tag("test-tag") - .build())) - .then(requestGetInstance(this.cloudFoundryOperations, serviceInstanceName) - .map(serviceInstance -> serviceInstance.getTags().get(0))) - .as(StepVerifier::create) - .expectNext("test-tag") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + serviceBrokerId -> + requestCreateServiceInstance( + this.cloudFoundryOperations, + this.planName, + serviceInstanceName, + this.serviceName)) + .then( + this.cloudFoundryOperations + .services() + .updateInstance( + UpdateServiceInstanceRequest.builder() + .serviceInstanceName(serviceInstanceName) + .tag("test-tag") + .build())) + .then( + requestGetInstance(this.cloudFoundryOperations, serviceInstanceName) + .map(serviceInstance -> serviceInstance.getTags().get(0))) + .as(StepVerifier::create) + .expectNext("test-tag") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -400,149 +535,215 @@ public void updateUserProvidedInstance() { String serviceInstanceName = this.nameFactory.getServiceInstanceName(); this.serviceBrokerId - .flatMap(serviceBrokerId -> requestCreateUserProvidedServiceInstance(this.cloudFoundryOperations, serviceInstanceName)) - .then(this.cloudFoundryOperations.services() - .updateUserProvidedInstance(UpdateUserProvidedServiceInstanceRequest.builder() - .userProvidedServiceInstanceName(serviceInstanceName) - .syslogDrainUrl("test.url") - .build())) - .thenMany(requestListUserProvidedServiceInstances(this.cloudFoundryClient, serviceInstanceName) - .map(r -> r.getEntity().getSyslogDrainUrl())) - .as(StepVerifier::create) - .expectNext("test.url") - .expectComplete() - .verify(Duration.ofMinutes(5)); - } - - private static Mono getApplicationId(CloudFoundryOperations cloudFoundryOperations, String applicationName) { + .flatMap( + serviceBrokerId -> + requestCreateUserProvidedServiceInstance( + this.cloudFoundryOperations, serviceInstanceName)) + .then( + this.cloudFoundryOperations + .services() + .updateUserProvidedInstance( + UpdateUserProvidedServiceInstanceRequest.builder() + .userProvidedServiceInstanceName( + serviceInstanceName) + .syslogDrainUrl("test.url") + .build())) + .thenMany( + requestListUserProvidedServiceInstances( + this.cloudFoundryClient, serviceInstanceName) + .map(r -> r.getEntity().getSyslogDrainUrl())) + .as(StepVerifier::create) + .expectNext("test.url") + .expectComplete() + .verify(Duration.ofMinutes(5)); + } + + private static Mono getApplicationId( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { return requestGetApplication(cloudFoundryOperations, applicationName) - .map(ApplicationDetail::getId); - } - - private static Mono requestBindRoute(CloudFoundryOperations cloudFoundryOperations, String domainName, String hostName, String path, String userProvidedServiceInstanceName) { - return cloudFoundryOperations.services() - .bindRoute(BindRouteServiceInstanceRequest.builder() - .domainName(domainName) - .hostname(hostName) - .path(path) - .serviceInstanceName(userProvidedServiceInstanceName) - .build()); - } - - private static Mono requestBindService(CloudFoundryOperations cloudFoundryOperations, String applicationName, String serviceInstanceName) { - return cloudFoundryOperations.services() - .bind(BindServiceInstanceRequest.builder() - .applicationName(applicationName) - .serviceInstanceName(serviceInstanceName) - .build()); - } - - private static Mono requestCreateApplication(CloudFoundryOperations cloudFoundryOperations, Path application, String name) { - return cloudFoundryOperations.applications() - .push(PushApplicationRequest.builder() - .path(application) - .buildpack("staticfile_buildpack") - .diskQuota(512) - .healthCheckType(ApplicationHealthCheck.PORT) - .memory(64) - .name(name) - .noStart(true) - .build()); - } - - private static Mono requestCreatePrivateDomain(CloudFoundryOperations cloudFoundryOperations, String domainName, String organizationName) { - return cloudFoundryOperations.domains() - .create(CreateDomainRequest.builder() - .domain(domainName) - .organization(organizationName) - .build()); - } - - private static Mono requestCreateRoute(CloudFoundryOperations cloudFoundryOperations, String domainName, String hostName, String path, String spaceName) { - return cloudFoundryOperations.routes() - .create(CreateRouteRequest.builder() - .domain(domainName) - .host(hostName) - .path(path) - .space(spaceName) - .build()); - } - - private static Mono requestCreateServiceInstance(CloudFoundryOperations cloudFoundryOperations, String planName, String serviceInstanceName, String serviceName) { - return cloudFoundryOperations.services() - .createInstance(CreateServiceInstanceRequest.builder() - .planName(planName) - .serviceName(serviceName) - .serviceInstanceName(serviceInstanceName) - .build()); - } - - private static Mono requestCreateServiceKey(CloudFoundryOperations cloudFoundryOperations, String serviceKeyName, String serviceInstanceName) { - return cloudFoundryOperations.services() - .createServiceKey(CreateServiceKeyRequest.builder() - .serviceInstanceName(serviceInstanceName) - .serviceKeyName(serviceKeyName) - .build()); - } - - private static Mono requestCreateUserProvidedServiceInstance(CloudFoundryOperations cloudFoundryOperations, String userProvidedServiceInstanceName) { - return cloudFoundryOperations.services() - .createUserProvidedInstance(CreateUserProvidedServiceInstanceRequest.builder() - .name(userProvidedServiceInstanceName) - .routeServiceUrl("https://test.route.service.url") - .build()); - } - - private static Mono requestGetApplication(CloudFoundryOperations cloudFoundryOperations, String applicationName) { - return cloudFoundryOperations.applications() - .get(GetApplicationRequest.builder() - .name(applicationName) - .build()); - } - - private static Mono requestGetInstance(CloudFoundryOperations cloudFoundryOperations, String userProvidedServiceInstanceName) { - return cloudFoundryOperations.services() - .getInstance(GetServiceInstanceRequest.builder() - .name(userProvidedServiceInstanceName) - .build()); - } - - private static Mono requestGetServiceKey(CloudFoundryOperations cloudFoundryOperations, String serviceInstanceName, String serviceKeyName) { - return cloudFoundryOperations.services() - .getServiceKey(GetServiceKeyRequest.builder() - .serviceInstanceName(serviceInstanceName) - .serviceKeyName(serviceKeyName) - .build()); + .map(ApplicationDetail::getId); + } + + private static Mono requestBindRoute( + CloudFoundryOperations cloudFoundryOperations, + String domainName, + String hostName, + String path, + String userProvidedServiceInstanceName) { + return cloudFoundryOperations + .services() + .bindRoute( + BindRouteServiceInstanceRequest.builder() + .domainName(domainName) + .hostname(hostName) + .path(path) + .serviceInstanceName(userProvidedServiceInstanceName) + .build()); + } + + private static Mono requestBindService( + CloudFoundryOperations cloudFoundryOperations, + String applicationName, + String serviceInstanceName) { + return cloudFoundryOperations + .services() + .bind( + BindServiceInstanceRequest.builder() + .applicationName(applicationName) + .serviceInstanceName(serviceInstanceName) + .build()); + } + + private static Mono requestCreateApplication( + CloudFoundryOperations cloudFoundryOperations, Path application, String name) { + return cloudFoundryOperations + .applications() + .push( + PushApplicationRequest.builder() + .path(application) + .buildpack("staticfile_buildpack") + .diskQuota(512) + .healthCheckType(ApplicationHealthCheck.PORT) + .memory(64) + .name(name) + .noStart(true) + .build()); + } + + private static Mono requestCreatePrivateDomain( + CloudFoundryOperations cloudFoundryOperations, + String domainName, + String organizationName) { + return cloudFoundryOperations + .domains() + .create( + CreateDomainRequest.builder() + .domain(domainName) + .organization(organizationName) + .build()); + } + + private static Mono requestCreateRoute( + CloudFoundryOperations cloudFoundryOperations, + String domainName, + String hostName, + String path, + String spaceName) { + return cloudFoundryOperations + .routes() + .create( + CreateRouteRequest.builder() + .domain(domainName) + .host(hostName) + .path(path) + .space(spaceName) + .build()); + } + + private static Mono requestCreateServiceInstance( + CloudFoundryOperations cloudFoundryOperations, + String planName, + String serviceInstanceName, + String serviceName) { + return cloudFoundryOperations + .services() + .createInstance( + CreateServiceInstanceRequest.builder() + .planName(planName) + .serviceName(serviceName) + .serviceInstanceName(serviceInstanceName) + .build()); + } + + private static Mono requestCreateServiceKey( + CloudFoundryOperations cloudFoundryOperations, + String serviceKeyName, + String serviceInstanceName) { + return cloudFoundryOperations + .services() + .createServiceKey( + CreateServiceKeyRequest.builder() + .serviceInstanceName(serviceInstanceName) + .serviceKeyName(serviceKeyName) + .build()); + } + + private static Mono requestCreateUserProvidedServiceInstance( + CloudFoundryOperations cloudFoundryOperations, String userProvidedServiceInstanceName) { + return cloudFoundryOperations + .services() + .createUserProvidedInstance( + CreateUserProvidedServiceInstanceRequest.builder() + .name(userProvidedServiceInstanceName) + .routeServiceUrl("https://test.route.service.url") + .build()); + } + + private static Mono requestGetApplication( + CloudFoundryOperations cloudFoundryOperations, String applicationName) { + return cloudFoundryOperations + .applications() + .get(GetApplicationRequest.builder().name(applicationName).build()); + } + + private static Mono requestGetInstance( + CloudFoundryOperations cloudFoundryOperations, String userProvidedServiceInstanceName) { + return cloudFoundryOperations + .services() + .getInstance( + GetServiceInstanceRequest.builder() + .name(userProvidedServiceInstanceName) + .build()); + } + + private static Mono requestGetServiceKey( + CloudFoundryOperations cloudFoundryOperations, + String serviceInstanceName, + String serviceKeyName) { + return cloudFoundryOperations + .services() + .getServiceKey( + GetServiceKeyRequest.builder() + .serviceInstanceName(serviceInstanceName) + .serviceKeyName(serviceKeyName) + .build()); } private static Flux requestListRoutes(CloudFoundryOperations cloudFoundryOperations) { - return cloudFoundryOperations.routes() - .list(ListRoutesRequest.builder() - .level(SPACE) - .build()); - } - - private static Flux requestListServiceBindings(CloudFoundryClient cloudFoundryClient, String applicationId) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.serviceBindingsV2() - .list(ListServiceBindingsRequest.builder() - .applicationId(applicationId) - .page(page) - .build())); + return cloudFoundryOperations + .routes() + .list(ListRoutesRequest.builder().level(SPACE).build()); + } + + private static Flux requestListServiceBindings( + CloudFoundryClient cloudFoundryClient, String applicationId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .serviceBindingsV2() + .list( + ListServiceBindingsRequest.builder() + .applicationId(applicationId) + .page(page) + .build())); + } + + private static Flux requestListServiceInstances( + CloudFoundryOperations cloudFoundryOperations) { + return cloudFoundryOperations.services().listInstances(); + } + + private static Flux + requestListUserProvidedServiceInstances( + CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .userProvidedServiceInstances() + .list( + ListUserProvidedServiceInstancesRequest.builder() + .name(serviceInstanceName) + .page(page) + .build())); } - - private static Flux requestListServiceInstances(CloudFoundryOperations cloudFoundryOperations) { - return cloudFoundryOperations.services() - .listInstances(); - } - - private static Flux requestListUserProvidedServiceInstances(CloudFoundryClient cloudFoundryClient, String serviceInstanceName) { - return PaginationUtils - .requestClientV2Resources(page -> cloudFoundryClient.userProvidedServiceInstances() - .list(ListUserProvidedServiceInstancesRequest.builder() - .name(serviceInstanceName) - .page(page) - .build())); - } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/SpacesTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/SpacesTest.java index 73418136a84..fbb8dc765b3 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/SpacesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/SpacesTest.java @@ -16,72 +16,73 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.operations.spaces.CreateSpaceRequest; import org.cloudfoundry.operations.spaces.GetSpaceRequest; import org.cloudfoundry.operations.spaces.SpaceDetail; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class SpacesTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; - @Autowired - private String organizationName; + @Autowired private String organizationName; @Test public void create() { String spaceName = this.nameFactory.getSpaceName(); - this.cloudFoundryOperations.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organization(this.organizationName) - .build()) - .thenMany(this.cloudFoundryOperations.spaces() - .list()) - .filter(spaceSummary -> spaceName.equals(spaceSummary.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organization(this.organizationName) + .build()) + .thenMany(this.cloudFoundryOperations.spaces().list()) + .filter(spaceSummary -> spaceName.equals(spaceSummary.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getWithURLReservedCharacterInName() { String spaceName = this.nameFactory.getSpaceName() + "+test"; - this.cloudFoundryOperations.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organization(this.organizationName) - .build()) - .then(this.cloudFoundryOperations.spaces() - .get(GetSpaceRequest.builder() - .name(spaceName) - .build())) - .map(SpaceDetail::getName) - .as(StepVerifier::create) - .expectNext(spaceName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organization(this.organizationName) + .build()) + .then( + this.cloudFoundryOperations + .spaces() + .get(GetSpaceRequest.builder().name(spaceName).build())) + .map(SpaceDetail::getName) + .as(StepVerifier::create) + .expectNext(spaceName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void list() { - this.cloudFoundryOperations.spaces() - .list() - .count() - .as(StepVerifier::create) - .consumeNextWith(count -> assertThat(count).isGreaterThan(0)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .spaces() + .list() + .count() + .as(StepVerifier::create) + .consumeNextWith(count -> assertThat(count).isGreaterThan(0)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/operations/UserAdminTest.java b/integration-test/src/test/java/org/cloudfoundry/operations/UserAdminTest.java index 402017b47bc..b0c12b8ea3f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/operations/UserAdminTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/operations/UserAdminTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.operations; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.client.CloudFoundryClient; import org.cloudfoundry.client.v2.organizations.ListOrganizationAuditorsRequest; @@ -38,38 +41,37 @@ import org.cloudfoundry.operations.useradmin.UnsetSpaceRoleRequest; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class UserAdminTest extends AbstractIntegrationTest { - @Autowired - private CloudFoundryClient cloudFoundryClient; + @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired - private CloudFoundryOperations cloudFoundryOperations; + @Autowired private CloudFoundryOperations cloudFoundryOperations; @Test public void create() { String username = this.nameFactory.getUserName(); - this.cloudFoundryOperations.userAdmin() - .create(CreateUserRequest.builder() - .password("test-password") - .username(username) - .build()) - .thenMany(requestListUsers(this.cloudFoundryClient)) - .filter(response -> username.equals(ResourceUtils.getEntity(response).getUsername())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .userAdmin() + .create( + CreateUserRequest.builder() + .password("test-password") + .username(username) + .build()) + .thenMany(requestListUsers(this.cloudFoundryClient)) + .filter( + response -> + username.equals(ResourceUtils.getEntity(response).getUsername())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -77,10 +79,14 @@ public void createDuplicate() { String username = this.nameFactory.getUserName(); createUser(this.cloudFoundryOperations, username) - .then(createUser(this.cloudFoundryOperations, username)) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("User %s already exists", username)) - .verify(Duration.ofMinutes(5)); + .then(createUser(this.cloudFoundryOperations, username)) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("User %s already exists", username)) + .verify(Duration.ofMinutes(5)); } @Test @@ -88,26 +94,31 @@ public void delete() { String username = this.nameFactory.getUserName(); createUser(this.cloudFoundryOperations, username) - .then(this.cloudFoundryOperations.userAdmin() - .delete(DeleteUserRequest.builder() - .username(username) - .build())) - .thenMany(requestListUsers(this.cloudFoundryClient)) - .filter(response -> username.equals(ResourceUtils.getEntity(response).getUsername())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.cloudFoundryOperations + .userAdmin() + .delete(DeleteUserRequest.builder().username(username).build())) + .thenMany(requestListUsers(this.cloudFoundryClient)) + .filter( + response -> + username.equals(ResourceUtils.getEntity(response).getUsername())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void deleteNotFound() { - this.cloudFoundryOperations.userAdmin() - .delete(DeleteUserRequest.builder() - .username("not-found") - .build()) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(IllegalArgumentException.class).hasMessage("User not-found does not exist")) - .verify(Duration.ofMinutes(5)); + this.cloudFoundryOperations + .userAdmin() + .delete(DeleteUserRequest.builder().username("not-found").build()) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(IllegalArgumentException.class) + .hasMessage("User not-found does not exist")) + .verify(Duration.ofMinutes(5)); } @Test @@ -116,19 +127,26 @@ public void listOrganizationUsers() { String username = this.nameFactory.getUserName(); Mono.when( - createUser(this.cloudFoundryOperations, username), - createOrganization(this.cloudFoundryOperations, organizationName) - ) - .then(setOrganizationRole(this.cloudFoundryOperations, organizationName, OrganizationRole.BILLING_MANAGER, username)) - .then(this.cloudFoundryOperations.userAdmin() - .listOrganizationUsers(ListOrganizationUsersRequest.builder() - .organizationName(organizationName) - .build())) - .flatMapIterable(OrganizationUsers::getBillingManagers) - .as(StepVerifier::create) - .expectNext(username) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createUser(this.cloudFoundryOperations, username), + createOrganization(this.cloudFoundryOperations, organizationName)) + .then( + setOrganizationRole( + this.cloudFoundryOperations, + organizationName, + OrganizationRole.BILLING_MANAGER, + username)) + .then( + this.cloudFoundryOperations + .userAdmin() + .listOrganizationUsers( + ListOrganizationUsersRequest.builder() + .organizationName(organizationName) + .build())) + .flatMapIterable(OrganizationUsers::getBillingManagers) + .as(StepVerifier::create) + .expectNext(username) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -138,21 +156,29 @@ public void listSpaceUsers() { String username = this.nameFactory.getUserName(); Mono.when( - createUser(this.cloudFoundryOperations, username), - createOrganization(this.cloudFoundryOperations, organizationName) - ) - .then(createSpace(this.cloudFoundryOperations, organizationName, spaceName)) - .then(setSpaceRole(this.cloudFoundryOperations, organizationName, spaceName, SpaceRole.AUDITOR, username)) - .then(this.cloudFoundryOperations.userAdmin() - .listSpaceUsers(ListSpaceUsersRequest.builder() - .organizationName(organizationName) - .spaceName(spaceName) - .build())) - .flatMapIterable(SpaceUsers::getAuditors) - .as(StepVerifier::create) - .expectNext(username) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createUser(this.cloudFoundryOperations, username), + createOrganization(this.cloudFoundryOperations, organizationName)) + .then(createSpace(this.cloudFoundryOperations, organizationName, spaceName)) + .then( + setSpaceRole( + this.cloudFoundryOperations, + organizationName, + spaceName, + SpaceRole.AUDITOR, + username)) + .then( + this.cloudFoundryOperations + .userAdmin() + .listSpaceUsers( + ListSpaceUsersRequest.builder() + .organizationName(organizationName) + .spaceName(spaceName) + .build())) + .flatMapIterable(SpaceUsers::getAuditors) + .as(StepVerifier::create) + .expectNext(username) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -161,22 +187,27 @@ public void setOrganizationUser() { String username = this.nameFactory.getUserName(); Mono.when( - createUser(this.cloudFoundryOperations, username), - createOrganization(this.cloudFoundryOperations, organizationName) - ) - .then(this.cloudFoundryOperations.userAdmin() - .setOrganizationRole(SetOrganizationRoleRequest.builder() - .organizationName(organizationName) - .organizationRole(OrganizationRole.AUDITOR) - .username(username) - .build())) - .thenMany(getOrganizationId(this.cloudFoundryClient, organizationName)) - .flatMap(organizationId -> requestListOrganizationAuditors(this.cloudFoundryClient, organizationId)) - .map(resource -> ResourceUtils.getEntity(resource).getUsername()) - .as(StepVerifier::create) - .expectNext(username) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createUser(this.cloudFoundryOperations, username), + createOrganization(this.cloudFoundryOperations, organizationName)) + .then( + this.cloudFoundryOperations + .userAdmin() + .setOrganizationRole( + SetOrganizationRoleRequest.builder() + .organizationName(organizationName) + .organizationRole(OrganizationRole.AUDITOR) + .username(username) + .build())) + .thenMany(getOrganizationId(this.cloudFoundryClient, organizationName)) + .flatMap( + organizationId -> + requestListOrganizationAuditors( + this.cloudFoundryClient, organizationId)) + .map(resource -> ResourceUtils.getEntity(resource).getUsername()) + .as(StepVerifier::create) + .expectNext(username) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -186,23 +217,25 @@ public void setSpaceUser() { String username = this.nameFactory.getUserName(); Mono.when( - createUser(this.cloudFoundryOperations, username), - createOrganization(this.cloudFoundryOperations, organizationName) - ) - .then(createSpace(this.cloudFoundryOperations, organizationName, spaceName)) - .then(this.cloudFoundryOperations.userAdmin() - .setSpaceRole(SetSpaceRoleRequest.builder() - .organizationName(organizationName) - .spaceName(spaceName) - .spaceRole(SpaceRole.AUDITOR) - .username(username) - .build())) - .thenMany(listSpaceUsers(this.cloudFoundryOperations, organizationName, spaceName)) - .flatMapIterable(SpaceUsers::getAuditors) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createUser(this.cloudFoundryOperations, username), + createOrganization(this.cloudFoundryOperations, organizationName)) + .then(createSpace(this.cloudFoundryOperations, organizationName, spaceName)) + .then( + this.cloudFoundryOperations + .userAdmin() + .setSpaceRole( + SetSpaceRoleRequest.builder() + .organizationName(organizationName) + .spaceName(spaceName) + .spaceRole(SpaceRole.AUDITOR) + .username(username) + .build())) + .thenMany(listSpaceUsers(this.cloudFoundryOperations, organizationName, spaceName)) + .flatMapIterable(SpaceUsers::getAuditors) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -211,22 +244,29 @@ public void unsetOrganizationUser() { String username = this.nameFactory.getUserName(); Mono.when( - createUser(this.cloudFoundryOperations, username), - createOrganization(this.cloudFoundryOperations, organizationName) - ) - .then(setOrganizationRole(this.cloudFoundryOperations, organizationName, OrganizationRole.MANAGER, username)) - .then(this.cloudFoundryOperations.userAdmin() - .unsetOrganizationRole(UnsetOrganizationRoleRequest.builder() - .organizationName(organizationName) - .organizationRole(OrganizationRole.MANAGER) - .username(username) - .build())) - .thenMany(listOrganizationUsers(this.cloudFoundryOperations, organizationName)) - .flatMapIterable(OrganizationUsers::getManagers) - .filter(username::equals) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createUser(this.cloudFoundryOperations, username), + createOrganization(this.cloudFoundryOperations, organizationName)) + .then( + setOrganizationRole( + this.cloudFoundryOperations, + organizationName, + OrganizationRole.MANAGER, + username)) + .then( + this.cloudFoundryOperations + .userAdmin() + .unsetOrganizationRole( + UnsetOrganizationRoleRequest.builder() + .organizationName(organizationName) + .organizationRole(OrganizationRole.MANAGER) + .username(username) + .build())) + .thenMany(listOrganizationUsers(this.cloudFoundryOperations, organizationName)) + .flatMapIterable(OrganizationUsers::getManagers) + .filter(username::equals) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -236,106 +276,156 @@ public void unsetSpaceUser() { String username = this.nameFactory.getUserName(); Mono.when( - createUser(this.cloudFoundryOperations, username), - createOrganization(this.cloudFoundryOperations, organizationName) - ) - .then(createSpace(this.cloudFoundryOperations, organizationName, spaceName)) - .then(setSpaceRole(this.cloudFoundryOperations, organizationName, spaceName, SpaceRole.MANAGER, username)) - .then(this.cloudFoundryOperations.userAdmin() - .unsetSpaceRole(UnsetSpaceRoleRequest.builder() - .organizationName(organizationName) - .spaceName(spaceName) - .spaceRole(SpaceRole.MANAGER) - .username(username) - .build())) - .thenMany(listSpaceUsers(this.cloudFoundryOperations, organizationName, spaceName)) - .flatMapIterable(SpaceUsers::getManagers) - .filter(username::equals) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + createUser(this.cloudFoundryOperations, username), + createOrganization(this.cloudFoundryOperations, organizationName)) + .then(createSpace(this.cloudFoundryOperations, organizationName, spaceName)) + .then( + setSpaceRole( + this.cloudFoundryOperations, + organizationName, + spaceName, + SpaceRole.MANAGER, + username)) + .then( + this.cloudFoundryOperations + .userAdmin() + .unsetSpaceRole( + UnsetSpaceRoleRequest.builder() + .organizationName(organizationName) + .spaceName(spaceName) + .spaceRole(SpaceRole.MANAGER) + .username(username) + .build())) + .thenMany(listSpaceUsers(this.cloudFoundryOperations, organizationName, spaceName)) + .flatMapIterable(SpaceUsers::getManagers) + .filter(username::equals) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createOrganization(CloudFoundryOperations cloudFoundryOperations, String organizationName) { - return cloudFoundryOperations.organizations() - .create(CreateOrganizationRequest.builder() - .organizationName(organizationName) - .build()); + private static Mono createOrganization( + CloudFoundryOperations cloudFoundryOperations, String organizationName) { + return cloudFoundryOperations + .organizations() + .create( + CreateOrganizationRequest.builder() + .organizationName(organizationName) + .build()); } - private static Mono createSpace(CloudFoundryOperations cloudFoundryOperations, String organizationName, String spaceName) { - return cloudFoundryOperations.spaces() - .create(CreateSpaceRequest.builder() - .name(spaceName) - .organization(organizationName) - .build()); + private static Mono createSpace( + CloudFoundryOperations cloudFoundryOperations, + String organizationName, + String spaceName) { + return cloudFoundryOperations + .spaces() + .create( + CreateSpaceRequest.builder() + .name(spaceName) + .organization(organizationName) + .build()); } - private static Mono createUser(CloudFoundryOperations cloudFoundryOperations, String username) { - return cloudFoundryOperations.userAdmin() - .create(CreateUserRequest.builder() - .password("test-password") - .username(username) - .build()); + private static Mono createUser( + CloudFoundryOperations cloudFoundryOperations, String username) { + return cloudFoundryOperations + .userAdmin() + .create( + CreateUserRequest.builder() + .password("test-password") + .username(username) + .build()); } - private static Mono getOrganizationId(CloudFoundryClient cloudFoundryClient, String organizationName) { - return PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.organizations() - .list(ListOrganizationsRequest.builder() - .page(page) - .build())) - .filter(r -> organizationName.equals(ResourceUtils.getEntity(r).getName())) - .map(ResourceUtils::getId) - .singleOrEmpty(); + private static Mono getOrganizationId( + CloudFoundryClient cloudFoundryClient, String organizationName) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .list( + ListOrganizationsRequest.builder() + .page(page) + .build())) + .filter(r -> organizationName.equals(ResourceUtils.getEntity(r).getName())) + .map(ResourceUtils::getId) + .singleOrEmpty(); } - private static Mono listOrganizationUsers(CloudFoundryOperations cloudFoundryOperations, String organizationName) { - return cloudFoundryOperations.userAdmin() - .listOrganizationUsers(ListOrganizationUsersRequest.builder() - .organizationName(organizationName) - .build()); + private static Mono listOrganizationUsers( + CloudFoundryOperations cloudFoundryOperations, String organizationName) { + return cloudFoundryOperations + .userAdmin() + .listOrganizationUsers( + ListOrganizationUsersRequest.builder() + .organizationName(organizationName) + .build()); } - private static Mono listSpaceUsers(CloudFoundryOperations cloudFoundryOperations, String organizationName, String spaceName) { - return cloudFoundryOperations.userAdmin() - .listSpaceUsers(ListSpaceUsersRequest.builder() - .organizationName(organizationName) - .spaceName(spaceName) - .build()); + private static Mono listSpaceUsers( + CloudFoundryOperations cloudFoundryOperations, + String organizationName, + String spaceName) { + return cloudFoundryOperations + .userAdmin() + .listSpaceUsers( + ListSpaceUsersRequest.builder() + .organizationName(organizationName) + .spaceName(spaceName) + .build()); } - private static Flux requestListOrganizationAuditors(CloudFoundryClient cloudFoundryClient, String organizationId) { - return PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.organizations() - .listAuditors(ListOrganizationAuditorsRequest.builder() - .organizationId(organizationId) - .page(page) - .build())); + private static Flux requestListOrganizationAuditors( + CloudFoundryClient cloudFoundryClient, String organizationId) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .organizations() + .listAuditors( + ListOrganizationAuditorsRequest.builder() + .organizationId(organizationId) + .page(page) + .build())); } private static Flux requestListUsers(CloudFoundryClient cloudFoundryClient) { - return PaginationUtils.requestClientV2Resources(page -> cloudFoundryClient.users() - .list(ListUsersRequest.builder() - .page(page) - .build())); + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .users() + .list(ListUsersRequest.builder().page(page).build())); } - private static Mono setOrganizationRole(CloudFoundryOperations cloudFoundryOperations, String organizationName, OrganizationRole organizationRole, String username) { - return cloudFoundryOperations.userAdmin() - .setOrganizationRole(SetOrganizationRoleRequest.builder() - .organizationName(organizationName) - .organizationRole(organizationRole) - .username(username) - .build()); + private static Mono setOrganizationRole( + CloudFoundryOperations cloudFoundryOperations, + String organizationName, + OrganizationRole organizationRole, + String username) { + return cloudFoundryOperations + .userAdmin() + .setOrganizationRole( + SetOrganizationRoleRequest.builder() + .organizationName(organizationName) + .organizationRole(organizationRole) + .username(username) + .build()); } - private static Mono setSpaceRole(CloudFoundryOperations cloudFoundryOperations, String organizationName, String spaceName, SpaceRole spaceRole, String username) { - return cloudFoundryOperations.userAdmin() - .setSpaceRole(SetSpaceRoleRequest.builder() - .organizationName(organizationName) - .spaceName(spaceName) - .spaceRole(spaceRole) - .username(username) - .build()); + private static Mono setSpaceRole( + CloudFoundryOperations cloudFoundryOperations, + String organizationName, + String spaceName, + SpaceRole spaceRole, + String username) { + return cloudFoundryOperations + .userAdmin() + .setSpaceRole( + SetSpaceRoleRequest.builder() + .organizationName(organizationName) + .spaceName(spaceName) + .spaceRole(spaceRole) + .username(username) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/routing/v1/RouterGroupsTest.java b/integration-test/src/test/java/org/cloudfoundry/routing/v1/RouterGroupsTest.java index b46b38612c5..8253f29ad5a 100644 --- a/integration-test/src/test/java/org/cloudfoundry/routing/v1/RouterGroupsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/routing/v1/RouterGroupsTest.java @@ -16,6 +16,7 @@ package org.cloudfoundry.routing.v1; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.routing.RoutingClient; import org.cloudfoundry.routing.v1.routergroups.ListRouterGroupsRequest; @@ -23,60 +24,61 @@ import org.cloudfoundry.routing.v1.routergroups.RouterGroup; import org.cloudfoundry.routing.v1.routergroups.UpdateRouterGroupRequest; import org.cloudfoundry.routing.v1.routergroups.UpdateRouterGroupResponse; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - public final class RouterGroupsTest extends AbstractIntegrationTest { private static final String DEFAULT_ROUTER_GROUP = "default-tcp"; - @Autowired - private RoutingClient routingClient; + @Autowired private RoutingClient routingClient; @Test public void list() { - this.routingClient.routerGroups() - .list(ListRouterGroupsRequest.builder() - .build()) - .flatMapIterable(ListRouterGroupsResponse::getRouterGroups) - .map(RouterGroup::getName) - .filter(DEFAULT_ROUTER_GROUP::equals) - .as(StepVerifier::create) - .expectNext(DEFAULT_ROUTER_GROUP) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.routingClient + .routerGroups() + .list(ListRouterGroupsRequest.builder().build()) + .flatMapIterable(ListRouterGroupsResponse::getRouterGroups) + .map(RouterGroup::getName) + .filter(DEFAULT_ROUTER_GROUP::equals) + .as(StepVerifier::create) + .expectNext(DEFAULT_ROUTER_GROUP) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void update() { getRouterGroupId(this.routingClient, DEFAULT_ROUTER_GROUP) - .flatMap(routerGroupId -> this.routingClient.routerGroups() - .update(UpdateRouterGroupRequest.builder() - .reservablePorts("1025-1122") - .routerGroupId(routerGroupId) - .build())) - .map(UpdateRouterGroupResponse::getReservablePorts) - .as(StepVerifier::create) - .expectNext("1025-1122") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + routerGroupId -> + this.routingClient + .routerGroups() + .update( + UpdateRouterGroupRequest.builder() + .reservablePorts("1025-1122") + .routerGroupId(routerGroupId) + .build())) + .map(UpdateRouterGroupResponse::getReservablePorts) + .as(StepVerifier::create) + .expectNext("1025-1122") + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono getRouterGroupId(RoutingClient routingClient, String routerGroupName) { + private static Mono getRouterGroupId( + RoutingClient routingClient, String routerGroupName) { return requestListRouterGroups(routingClient) - .flatMapIterable(ListRouterGroupsResponse::getRouterGroups) - .filter(group -> routerGroupName.equals(group.getName())) - .single() - .map(RouterGroup::getRouterGroupId); + .flatMapIterable(ListRouterGroupsResponse::getRouterGroups) + .filter(group -> routerGroupName.equals(group.getName())) + .single() + .map(RouterGroup::getRouterGroupId); } - private static Mono requestListRouterGroups(RoutingClient routingClient) { - return routingClient.routerGroups() - .list(ListRouterGroupsRequest.builder() - .build()); + private static Mono requestListRouterGroups( + RoutingClient routingClient) { + return routingClient.routerGroups().list(ListRouterGroupsRequest.builder().build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/routing/v1/TcpRoutesTest.java b/integration-test/src/test/java/org/cloudfoundry/routing/v1/TcpRoutesTest.java index 5438c70535f..27852f13fcf 100644 --- a/integration-test/src/test/java/org/cloudfoundry/routing/v1/TcpRoutesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/routing/v1/TcpRoutesTest.java @@ -16,6 +16,7 @@ package org.cloudfoundry.routing.v1; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.NameFactory; import org.cloudfoundry.routing.RoutingClient; @@ -31,22 +32,19 @@ import org.cloudfoundry.routing.v1.tcproutes.TcpRoute; import org.cloudfoundry.routing.v1.tcproutes.TcpRouteConfiguration; import org.cloudfoundry.routing.v1.tcproutes.TcpRouteDeletion; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - public final class TcpRoutesTest extends AbstractIntegrationTest { private static final String DEFAULT_ROUTER_GROUP = "default-tcp"; - @Autowired - private NameFactory nameFactory; + @Autowired private NameFactory nameFactory; - @Autowired - private RoutingClient routingClient; + @Autowired private RoutingClient routingClient; @Test public void create() { @@ -55,25 +53,31 @@ public void create() { Integer port = this.nameFactory.getPort(); getRouterGroupId(this.routingClient, DEFAULT_ROUTER_GROUP) - .flatMap(routerGroupId -> this.routingClient.tcpRoutes() - .create(CreateTcpRoutesRequest.builder() - .tcpRoute(TcpRouteConfiguration.builder() - .backendIp(backendIp) - .backendPort(backendPort) - .port(port) - .routerGroupId(routerGroupId) - .ttl(59) - .build()) - .build())) - .then(requestListTcpRoutes(this.routingClient)) - .flatMapIterable(ListTcpRoutesResponse::getTcpRoutes) - .filter(route -> backendIp.equals(route.getBackendIp())) - .filter(route -> backendPort.equals(route.getBackendPort())) - .map(TcpRoute::getPort) - .as(StepVerifier::create) - .expectNext(port) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + routerGroupId -> + this.routingClient + .tcpRoutes() + .create( + CreateTcpRoutesRequest.builder() + .tcpRoute( + TcpRouteConfiguration.builder() + .backendIp(backendIp) + .backendPort(backendPort) + .port(port) + .routerGroupId( + routerGroupId) + .ttl(59) + .build()) + .build())) + .then(requestListTcpRoutes(this.routingClient)) + .flatMapIterable(ListTcpRoutesResponse::getTcpRoutes) + .filter(route -> backendIp.equals(route.getBackendIp())) + .filter(route -> backendPort.equals(route.getBackendPort())) + .map(TcpRoute::getPort) + .as(StepVerifier::create) + .expectNext(port) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -83,24 +87,37 @@ public void delete() { Integer port = this.nameFactory.getPort(); getRouterGroupId(this.routingClient, DEFAULT_ROUTER_GROUP) - .delayUntil(routerGroupId -> createTcpRoute(this.routingClient, backendIp, backendPort, port, routerGroupId)) - .flatMap(routerGroupId -> this.routingClient.tcpRoutes() - .delete(DeleteTcpRoutesRequest.builder() - .tcpRoute(TcpRouteDeletion.builder() - .backendIp(backendIp) - .backendPort(backendPort) - .port(port) - .routerGroupId(routerGroupId) - .build()) - .build())) - .then(requestListTcpRoutes(this.routingClient)) - .flatMapIterable(ListTcpRoutesResponse::getTcpRoutes) - .filter(route -> backendIp.equals(route.getBackendIp())) - .filter(route -> backendPort.equals(route.getBackendPort())) - .filter(route -> port.equals(route.getPort())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + routerGroupId -> + createTcpRoute( + this.routingClient, + backendIp, + backendPort, + port, + routerGroupId)) + .flatMap( + routerGroupId -> + this.routingClient + .tcpRoutes() + .delete( + DeleteTcpRoutesRequest.builder() + .tcpRoute( + TcpRouteDeletion.builder() + .backendIp(backendIp) + .backendPort(backendPort) + .port(port) + .routerGroupId( + routerGroupId) + .build()) + .build())) + .then(requestListTcpRoutes(this.routingClient)) + .flatMapIterable(ListTcpRoutesResponse::getTcpRoutes) + .filter(route -> backendIp.equals(route.getBackendIp())) + .filter(route -> backendPort.equals(route.getBackendPort())) + .filter(route -> port.equals(route.getPort())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -110,19 +127,33 @@ public void events() { Integer port = this.nameFactory.getPort(); Flux.firstWithSignal( - getRouterGroupId(this.routingClient, DEFAULT_ROUTER_GROUP) - .flatMapMany(routerGroupId -> Flux.interval(Duration.ofMillis(500)) - .flatMap(i -> createTcpRoute(this.routingClient, backendIp, backendPort, port, routerGroupId))) - .then(), - this.routingClient.tcpRoutes() - .events(EventsRequest.builder() - .build()) - .filter(event -> event.getBackendIp().equals(backendIp) && event.getBackendPort().equals(backendPort) && event.getPort().equals(port)) - .take(1)) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + getRouterGroupId(this.routingClient, DEFAULT_ROUTER_GROUP) + .flatMapMany( + routerGroupId -> + Flux.interval(Duration.ofMillis(500)) + .flatMap( + i -> + createTcpRoute( + this.routingClient, + backendIp, + backendPort, + port, + routerGroupId))) + .then(), + this.routingClient + .tcpRoutes() + .events(EventsRequest.builder().build()) + .filter( + event -> + event.getBackendIp().equals(backendIp) + && event.getBackendPort() + .equals(backendPort) + && event.getPort().equals(port)) + .take(1)) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -132,50 +163,60 @@ public void list() { Integer port = this.nameFactory.getPort(); getRouterGroupId(this.routingClient, DEFAULT_ROUTER_GROUP) - .flatMap(routerGroupId -> createTcpRoute(this.routingClient, backendIp, backendPort, port, routerGroupId)) - .then(this.routingClient.tcpRoutes() - .list(ListTcpRoutesRequest.builder() - .build())) - .flatMapIterable(ListTcpRoutesResponse::getTcpRoutes) - .filter(route -> backendIp.equals(route.getBackendIp())) - .map(TcpRoute::getPort) - .as(StepVerifier::create) - .expectNext(port) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + routerGroupId -> + createTcpRoute( + this.routingClient, + backendIp, + backendPort, + port, + routerGroupId)) + .then(this.routingClient.tcpRoutes().list(ListTcpRoutesRequest.builder().build())) + .flatMapIterable(ListTcpRoutesResponse::getTcpRoutes) + .filter(route -> backendIp.equals(route.getBackendIp())) + .map(TcpRoute::getPort) + .as(StepVerifier::create) + .expectNext(port) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono createTcpRoute(RoutingClient routingClient, String backendIp, Integer backendPort, Integer port, String routerGroupId) { - return routingClient.tcpRoutes() - .create(CreateTcpRoutesRequest.builder() - .tcpRoute(TcpRouteConfiguration.builder() - .backendIp(backendIp) - .backendPort(backendPort) - .port(port) - .routerGroupId(routerGroupId) - .ttl(59) - .build()) - .build()); + private static Mono createTcpRoute( + RoutingClient routingClient, + String backendIp, + Integer backendPort, + Integer port, + String routerGroupId) { + return routingClient + .tcpRoutes() + .create( + CreateTcpRoutesRequest.builder() + .tcpRoute( + TcpRouteConfiguration.builder() + .backendIp(backendIp) + .backendPort(backendPort) + .port(port) + .routerGroupId(routerGroupId) + .ttl(59) + .build()) + .build()); } - private static Mono getRouterGroupId(RoutingClient routingClient, String routerGroupName) { + private static Mono getRouterGroupId( + RoutingClient routingClient, String routerGroupName) { return requestListRouterGroups(routingClient) - .flatMapIterable(ListRouterGroupsResponse::getRouterGroups) - .filter(group -> routerGroupName.equals(group.getName())) - .single() - .map(RouterGroup::getRouterGroupId); + .flatMapIterable(ListRouterGroupsResponse::getRouterGroups) + .filter(group -> routerGroupName.equals(group.getName())) + .single() + .map(RouterGroup::getRouterGroupId); } - private static Mono requestListRouterGroups(RoutingClient routingClient) { - return routingClient.routerGroups() - .list(ListRouterGroupsRequest.builder() - .build()); + private static Mono requestListRouterGroups( + RoutingClient routingClient) { + return routingClient.routerGroups().list(ListRouterGroupsRequest.builder().build()); } private static Mono requestListTcpRoutes(RoutingClient routingClient) { - return routingClient.tcpRoutes() - .list(ListTcpRoutesRequest.builder() - .build()); + return routingClient.tcpRoutes().list(ListTcpRoutesRequest.builder().build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/uaa/AuthorizationsTest.java b/integration-test/src/test/java/org/cloudfoundry/uaa/AuthorizationsTest.java index 471391d133b..6480aef0b9c 100644 --- a/integration-test/src/test/java/org/cloudfoundry/uaa/AuthorizationsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/uaa/AuthorizationsTest.java @@ -16,6 +16,10 @@ package org.cloudfoundry.uaa; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; +import java.util.function.Consumer; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.uaa.authorizations.AuthorizeByAuthorizationCodeGrantApiRequest; import org.cloudfoundry.uaa.authorizations.AuthorizeByAuthorizationCodeGrantBrowserRequest; @@ -26,129 +30,137 @@ import org.cloudfoundry.uaa.authorizations.AuthorizeByOpenIdWithImplicitGrantRequest; import org.cloudfoundry.uaa.authorizations.GetOpenIdProviderConfigurationRequest; import org.cloudfoundry.uaa.authorizations.GetOpenIdProviderConfigurationResponse; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; - public final class AuthorizationsTest extends AbstractIntegrationTest { - @Autowired - private String clientId; + @Autowired private String clientId; - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; @Test public void authorizeByAuthorizationCodeGrantApi() { - this.uaaClient.authorizations() - .authorizationCodeGrantApi(AuthorizeByAuthorizationCodeGrantApiRequest.builder() - .clientId(this.clientId) - .build()) - .as(StepVerifier::create) - .consumeNextWith(actual -> assertThat(actual.length()).isGreaterThanOrEqualTo(6)) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .authorizations() + .authorizationCodeGrantApi( + AuthorizeByAuthorizationCodeGrantApiRequest.builder() + .clientId(this.clientId) + .build()) + .as(StepVerifier::create) + .consumeNextWith(actual -> assertThat(actual.length()).isGreaterThanOrEqualTo(6)) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void authorizeByAuthorizationCodeGrantBrowser() { - this.uaaClient.authorizations() - .authorizationCodeGrantBrowser(AuthorizeByAuthorizationCodeGrantBrowserRequest.builder() - .clientId(this.clientId) - .redirectUri("http://redirect.to/app") - .build()) - .as(StepVerifier::create) - .consumeNextWith(startsWithExpectation("https://uaa.")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .authorizations() + .authorizationCodeGrantBrowser( + AuthorizeByAuthorizationCodeGrantBrowserRequest.builder() + .clientId(this.clientId) + .redirectUri("http://redirect.to/app") + .build()) + .as(StepVerifier::create) + .consumeNextWith(startsWithExpectation("https://uaa.")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void authorizeByAuthorizationCodeGrantHybrid() { - this.uaaClient.authorizations() - .authorizationCodeGrantHybrid(AuthorizeByAuthorizationCodeGrantHybridRequest.builder() - .clientId(this.clientId) - .redirectUri("http://redirect.to/app") - .build()) - .as(StepVerifier::create) - .consumeNextWith(startsWithExpectation("https://uaa.")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .authorizations() + .authorizationCodeGrantHybrid( + AuthorizeByAuthorizationCodeGrantHybridRequest.builder() + .clientId(this.clientId) + .redirectUri("http://redirect.to/app") + .build()) + .as(StepVerifier::create) + .consumeNextWith(startsWithExpectation("https://uaa.")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void authorizeByImplicitGrantBrowser() { - this.uaaClient.authorizations() - .implicitGrantBrowser(AuthorizeByImplicitGrantBrowserRequest.builder() - .clientId(this.clientId) - .redirectUri("http://redirect.to/app") - .build()) - .as(StepVerifier::create) - .consumeNextWith(startsWithExpectation("https://uaa.")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .authorizations() + .implicitGrantBrowser( + AuthorizeByImplicitGrantBrowserRequest.builder() + .clientId(this.clientId) + .redirectUri("http://redirect.to/app") + .build()) + .as(StepVerifier::create) + .consumeNextWith(startsWithExpectation("https://uaa.")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void authorizeByOpenIdWithAuthorizationCodeGrant() { - this.uaaClient.authorizations() - .openIdWithAuthorizationCodeAndIdToken(AuthorizeByOpenIdWithAuthorizationCodeGrantRequest.builder() - .clientId("app") - .redirectUri("http://redirect.to/app") - .scope("openid") - .build()) - .as(StepVerifier::create) - .consumeNextWith(startsWithExpectation("https://uaa.")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .authorizations() + .openIdWithAuthorizationCodeAndIdToken( + AuthorizeByOpenIdWithAuthorizationCodeGrantRequest.builder() + .clientId("app") + .redirectUri("http://redirect.to/app") + .scope("openid") + .build()) + .as(StepVerifier::create) + .consumeNextWith(startsWithExpectation("https://uaa.")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void authorizeByOpenIdWithIdToken() { - this.uaaClient.authorizations() - .openIdWithIdToken(AuthorizeByOpenIdWithIdTokenRequest.builder() - .clientId("app") - .redirectUri("http://redirect.to/app") - .scope("open-id") - .build()) - .as(StepVerifier::create) - .consumeNextWith(startsWithExpectation("https://uaa.")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .authorizations() + .openIdWithIdToken( + AuthorizeByOpenIdWithIdTokenRequest.builder() + .clientId("app") + .redirectUri("http://redirect.to/app") + .scope("open-id") + .build()) + .as(StepVerifier::create) + .consumeNextWith(startsWithExpectation("https://uaa.")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void authorizeByOpenIdWithImplicitGrant() { - this.uaaClient.authorizations() - .openIdWithTokenAndIdToken(AuthorizeByOpenIdWithImplicitGrantRequest.builder() - .clientId("app") - .redirectUri("http://redirect.to/app") - .scope("openid") - .build()) - .as(StepVerifier::create) - .consumeNextWith(startsWithExpectation("https://uaa.")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .authorizations() + .openIdWithTokenAndIdToken( + AuthorizeByOpenIdWithImplicitGrantRequest.builder() + .clientId("app") + .redirectUri("http://redirect.to/app") + .scope("openid") + .build()) + .as(StepVerifier::create) + .consumeNextWith(startsWithExpectation("https://uaa.")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void openIdProviderConfiguration() { - this.uaaClient.authorizations() - .getOpenIdProviderConfiguration(GetOpenIdProviderConfigurationRequest.builder() - .build()) - .map(GetOpenIdProviderConfigurationResponse::getServiceDocumentation) - .as(StepVerifier::create) - .expectNext("http://docs.cloudfoundry.org/api/uaa/") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .authorizations() + .getOpenIdProviderConfiguration( + GetOpenIdProviderConfigurationRequest.builder().build()) + .map(GetOpenIdProviderConfigurationResponse::getServiceDocumentation) + .as(StepVerifier::create) + .expectNext("http://docs.cloudfoundry.org/api/uaa/") + .expectComplete() + .verify(Duration.ofMinutes(5)); } private static Consumer startsWithExpectation(String prefix) { return actual -> assertThat(actual).startsWith(prefix); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/uaa/ClientsTest.java b/integration-test/src/test/java/org/cloudfoundry/uaa/ClientsTest.java index 80e2489115b..4b52e9e1a6b 100644 --- a/integration-test/src/test/java/org/cloudfoundry/uaa/ClientsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/uaa/ClientsTest.java @@ -16,7 +16,15 @@ package org.cloudfoundry.uaa; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.uaa.tokens.GrantType.CLIENT_CREDENTIALS; +import static org.cloudfoundry.uaa.tokens.GrantType.IMPLICIT; +import static org.cloudfoundry.uaa.tokens.GrantType.PASSWORD; +import static org.cloudfoundry.uaa.tokens.GrantType.REFRESH_TOKEN; + import io.netty.util.AsciiString; +import java.time.Duration; +import java.util.Base64; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -51,27 +59,17 @@ import org.cloudfoundry.uaa.clients.UpdateSecretAction; import org.cloudfoundry.uaa.clients.UpdateSecretClientAction; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.Base64; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.uaa.tokens.GrantType.CLIENT_CREDENTIALS; -import static org.cloudfoundry.uaa.tokens.GrantType.IMPLICIT; -import static org.cloudfoundry.uaa.tokens.GrantType.PASSWORD; -import static org.cloudfoundry.uaa.tokens.GrantType.REFRESH_TOKEN; - public final class ClientsTest extends AbstractIntegrationTest { - @Autowired - private String clientId; + @Autowired private String clientId; - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; @Test public void batchChangeSecret() { @@ -82,25 +80,29 @@ public void batchChangeSecret() { String newClientSecret2 = this.nameFactory.getClientSecret(); requestCreateClient(this.uaaClient, clientId1, clientSecret) - .then(requestCreateClient(this.uaaClient, clientId2, clientSecret)) - .then(this.uaaClient.clients() - .batchChangeSecret(BatchChangeSecretRequest.builder() - .changeSecrets(ChangeSecret.builder() - .clientId(clientId1) - .oldSecret(clientSecret) - .secret(newClientSecret1) - .build(), - ChangeSecret.builder() - .clientId(clientId2) - .oldSecret(clientSecret) - .secret(newClientSecret2) - .build()) - .build())) - .flatMapIterable(BatchChangeSecretResponse::getClients) - .as(StepVerifier::create) - .expectNextCount(2) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(requestCreateClient(this.uaaClient, clientId2, clientSecret)) + .then( + this.uaaClient + .clients() + .batchChangeSecret( + BatchChangeSecretRequest.builder() + .changeSecrets( + ChangeSecret.builder() + .clientId(clientId1) + .oldSecret(clientSecret) + .secret(newClientSecret1) + .build(), + ChangeSecret.builder() + .clientId(clientId2) + .oldSecret(clientSecret) + .secret(newClientSecret2) + .build()) + .build())) + .flatMapIterable(BatchChangeSecretResponse::getClients) + .as(StepVerifier::create) + .expectNextCount(2) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -109,36 +111,43 @@ public void batchCreate() { String clientId2 = this.nameFactory.getClientId(); String clientSecret = this.nameFactory.getClientSecret(); - this.uaaClient.clients() - .batchCreate(BatchCreateClientsRequest.builder() - .client(CreateClient.builder() - .approvalsDeleted(true) - .authorizedGrantType(PASSWORD) - .clientId(clientId1) - .clientSecret(clientSecret) - .scopes("client.read", "client.write") - .tokenSalt("test-token-salt") - .build()) - .client(CreateClient.builder() - .approvalsDeleted(true) - .authorizedGrantTypes(PASSWORD, REFRESH_TOKEN) - .clientId(clientId2) - .clientSecret(clientSecret) - .scope("client.write") - .tokenSalt("filtered-test-token-salt") - .build()) - .build()) - .flatMapIterable(BatchCreateClientsResponse::getClients) - .filter(client -> clientId1.equals(client.getClientId())) - .as(StepVerifier::create) - .consumeNextWith(response -> { - assertThat(response.getAuthorizedGrantTypes()).containsExactly(PASSWORD, REFRESH_TOKEN); - assertThat(response.getClientId()).isEqualTo(clientId1); - assertThat(response.getScopes()).containsExactly("client.read", "client.write"); - assertThat(response.getTokenSalt()).isEqualTo("test-token-salt"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .clients() + .batchCreate( + BatchCreateClientsRequest.builder() + .client( + CreateClient.builder() + .approvalsDeleted(true) + .authorizedGrantType(PASSWORD) + .clientId(clientId1) + .clientSecret(clientSecret) + .scopes("client.read", "client.write") + .tokenSalt("test-token-salt") + .build()) + .client( + CreateClient.builder() + .approvalsDeleted(true) + .authorizedGrantTypes(PASSWORD, REFRESH_TOKEN) + .clientId(clientId2) + .clientSecret(clientSecret) + .scope("client.write") + .tokenSalt("filtered-test-token-salt") + .build()) + .build()) + .flatMapIterable(BatchCreateClientsResponse::getClients) + .filter(client -> clientId1.equals(client.getClientId())) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + assertThat(response.getAuthorizedGrantTypes()) + .containsExactly(PASSWORD, REFRESH_TOKEN); + assertThat(response.getClientId()).isEqualTo(clientId1); + assertThat(response.getScopes()) + .containsExactly("client.read", "client.write"); + assertThat(response.getTokenSalt()).isEqualTo("test-token-salt"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -148,18 +157,25 @@ public void batchDelete() { String clientSecret = this.nameFactory.getClientSecret(); batchCreateClients(this.uaaClient, clientId1, clientId2, clientSecret) - .flatMapIterable(BatchCreateClientsResponse::getClients) - .map(Client::getClientId) - .collectList() - .flatMap(clientIds -> this.uaaClient.clients() - .batchDelete(BatchDeleteClientsRequest.builder() - .clientIds(clientIds) - .build())) - .thenMany(requestListClients(this.uaaClient)) - .filter(client -> clientId1.equals(client.getClientId()) || clientId2.equals(client.getClientId())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMapIterable(BatchCreateClientsResponse::getClients) + .map(Client::getClientId) + .collectList() + .flatMap( + clientIds -> + this.uaaClient + .clients() + .batchDelete( + BatchDeleteClientsRequest.builder() + .clientIds(clientIds) + .build())) + .thenMany(requestListClients(this.uaaClient)) + .filter( + client -> + clientId1.equals(client.getClientId()) + || clientId2.equals(client.getClientId())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -169,37 +185,50 @@ public void batchUpdate() { String clientSecret = this.nameFactory.getClientSecret(); requestCreateClient(this.uaaClient, clientId1, clientSecret) - .then(requestCreateClient(this.uaaClient, clientId2, clientSecret)) - .then(this.uaaClient.clients() - .batchUpdate(BatchUpdateClientsRequest.builder() - .clients(UpdateClient.builder() - .authorizedGrantTypes(CLIENT_CREDENTIALS, IMPLICIT) - .clientId(clientId1) - .name("test-name") - .scopes("client.read", "client.write") - .redirectUriPattern("https://test.com/*") - .tokenSalt("test-token-salt") - .build(), - UpdateClient.builder() - .authorizedGrantType(PASSWORD) - .clientId(clientId2) - .name("filtered-test-name") - .scope("client.write") - .tokenSalt("filtered-test-token-salt") - .build()) - .build())) - .flatMapIterable(BatchUpdateClientsResponse::getClients) - .filter(client -> clientId1.equals(client.getClientId())) - .as(StepVerifier::create) - .consumeNextWith(response -> { - assertThat(response.getAuthorizedGrantTypes()).containsExactly(IMPLICIT, CLIENT_CREDENTIALS); - assertThat(response.getClientId()).isEqualTo(clientId1); - assertThat(response.getName()).isEqualTo("test-name"); - assertThat(response.getScopes()).containsExactly("client.read", "client.write"); - assertThat(response.getTokenSalt()).isEqualTo("test-token-salt"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then(requestCreateClient(this.uaaClient, clientId2, clientSecret)) + .then( + this.uaaClient + .clients() + .batchUpdate( + BatchUpdateClientsRequest.builder() + .clients( + UpdateClient.builder() + .authorizedGrantTypes( + CLIENT_CREDENTIALS, + IMPLICIT) + .clientId(clientId1) + .name("test-name") + .scopes( + "client.read", + "client.write") + .redirectUriPattern( + "https://test.com/*") + .tokenSalt("test-token-salt") + .build(), + UpdateClient.builder() + .authorizedGrantType(PASSWORD) + .clientId(clientId2) + .name("filtered-test-name") + .scope("client.write") + .tokenSalt( + "filtered-test-token-salt") + .build()) + .build())) + .flatMapIterable(BatchUpdateClientsResponse::getClients) + .filter(client -> clientId1.equals(client.getClientId())) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + assertThat(response.getAuthorizedGrantTypes()) + .containsExactly(IMPLICIT, CLIENT_CREDENTIALS); + assertThat(response.getClientId()).isEqualTo(clientId1); + assertThat(response.getName()).isEqualTo("test-name"); + assertThat(response.getScopes()) + .containsExactly("client.read", "client.write"); + assertThat(response.getTokenSalt()).isEqualTo("test-token-salt"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(lessThan = CloudFoundryVersion.PCF_2_8) @@ -210,15 +239,24 @@ public void changeSecret27() { String oldClientSecret = this.nameFactory.getClientSecret(); requestCreateClient(this.uaaClient, clientId, oldClientSecret) - .then(this.uaaClient.clients() - .changeSecret(ChangeSecretRequest.builder() - .clientId(clientId) - .oldSecret(oldClientSecret) - .secret(newClientSecret) - .build())) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(UaaException.class).hasMessage("invalid_client: Only a client can change client secret")) - .verify(Duration.ofMinutes(5)); + .then( + this.uaaClient + .clients() + .changeSecret( + ChangeSecretRequest.builder() + .clientId(clientId) + .oldSecret(oldClientSecret) + .secret(newClientSecret) + .build())) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(UaaException.class) + .hasMessage( + "invalid_client: Only a client can change client" + + " secret")) + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_2_8) @@ -229,19 +267,23 @@ public void changeSecret28() { String oldClientSecret = this.nameFactory.getClientSecret(); requestCreateClient(this.uaaClient, clientId, oldClientSecret) - .then(this.uaaClient.clients() - .changeSecret(ChangeSecretRequest.builder() - .clientId(clientId) - .oldSecret(oldClientSecret) - .secret(newClientSecret) - .build())) - .as(StepVerifier::create) - .assertNext(response -> { - assertThat(response.getMessage()).isEqualTo("secret updated"); - assertThat(response.getStatus()).isEqualTo("ok"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.uaaClient + .clients() + .changeSecret( + ChangeSecretRequest.builder() + .clientId(clientId) + .oldSecret(oldClientSecret) + .secret(newClientSecret) + .build())) + .as(StepVerifier::create) + .assertNext( + response -> { + assertThat(response.getMessage()).isEqualTo("secret updated"); + assertThat(response.getStatus()).isEqualTo("ok"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -249,24 +291,29 @@ public void create() { String clientId = this.nameFactory.getClientId(); String clientSecret = this.nameFactory.getClientSecret(); - this.uaaClient.clients() - .create(CreateClientRequest.builder() - .approvalsDeleted(true) - .authorizedGrantType(PASSWORD) - .clientId(clientId) - .clientSecret(clientSecret) - .scopes("client.read", "client.write") - .tokenSalt("test-token-salt") - .build()) - .as(StepVerifier::create) - .consumeNextWith(response -> { - assertThat(response.getAuthorizedGrantTypes()).containsExactly(PASSWORD, REFRESH_TOKEN); - assertThat(response.getClientId()).isEqualTo(clientId); - assertThat(response.getScopes()).containsExactly("client.read", "client.write"); - assertThat(response.getTokenSalt()).isEqualTo("test-token-salt"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .clients() + .create( + CreateClientRequest.builder() + .approvalsDeleted(true) + .authorizedGrantType(PASSWORD) + .clientId(clientId) + .clientSecret(clientSecret) + .scopes("client.read", "client.write") + .tokenSalt("test-token-salt") + .build()) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + assertThat(response.getAuthorizedGrantTypes()) + .containsExactly(PASSWORD, REFRESH_TOKEN); + assertThat(response.getClientId()).isEqualTo(clientId); + assertThat(response.getScopes()) + .containsExactly("client.read", "client.write"); + assertThat(response.getTokenSalt()).isEqualTo("test-token-salt"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -275,15 +322,15 @@ public void delete() { String clientSecret = this.nameFactory.getClientSecret(); requestCreateClient(this.uaaClient, clientId, clientSecret) - .then(this.uaaClient.clients() - .delete(DeleteClientRequest.builder() - .clientId(clientId) - .build())) - .thenMany(requestListClients(this.uaaClient)) - .filter(client -> clientId.equals(client.getClientId())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.uaaClient + .clients() + .delete(DeleteClientRequest.builder().clientId(clientId).build())) + .thenMany(requestListClients(this.uaaClient)) + .filter(client -> clientId.equals(client.getClientId())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -292,33 +339,39 @@ public void get() { String clientSecret = this.nameFactory.getClientSecret(); requestCreateClient(this.uaaClient, clientId, clientSecret) - .then(this.uaaClient.clients() - .get(GetClientRequest.builder() - .clientId(clientId) - .build())) - .as(StepVerifier::create) - .consumeNextWith(response -> { - assertThat(response.getAuthorizedGrantTypes()).containsExactly(PASSWORD, REFRESH_TOKEN); - assertThat(response.getClientId()).isEqualTo(clientId); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.uaaClient + .clients() + .get(GetClientRequest.builder().clientId(clientId).build())) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + assertThat(response.getAuthorizedGrantTypes()) + .containsExactly(PASSWORD, REFRESH_TOKEN); + assertThat(response.getClientId()).isEqualTo(clientId); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getMetadata() { requestUpdateMetadata(this.uaaClient, this.clientId, "http://test.get.url") - .then(this.uaaClient.clients() - .getMetadata(GetMetadataRequest.builder() - .clientId(this.clientId) - .build())) - .as(StepVerifier::create) - .consumeNextWith(metadata -> { - assertThat(metadata.getAppLaunchUrl()).isEqualTo("http://test.get.url"); - assertThat(metadata.getClientId()).isEqualTo(this.clientId); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.uaaClient + .clients() + .getMetadata( + GetMetadataRequest.builder() + .clientId(this.clientId) + .build())) + .as(StepVerifier::create) + .consumeNextWith( + metadata -> { + assertThat(metadata.getAppLaunchUrl()).isEqualTo("http://test.get.url"); + assertThat(metadata.getClientId()).isEqualTo(this.clientId); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -327,33 +380,41 @@ public void list() { String clientSecret = this.nameFactory.getClientSecret(); requestCreateClient(this.uaaClient, clientId, clientSecret) - .thenMany(PaginationUtils.requestUaaResources(startIndex -> this.uaaClient.clients() - .list(ListClientsRequest.builder() - .startIndex(startIndex) - .build()))) - .filter(client -> clientId.equals(client.getClientId())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .thenMany( + PaginationUtils.requestUaaResources( + startIndex -> + this.uaaClient + .clients() + .list( + ListClientsRequest.builder() + .startIndex(startIndex) + .build()))) + .filter(client -> clientId.equals(client.getClientId())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listMetadatas() { requestUpdateMetadata(this.uaaClient, this.clientId, "http://test.list.url") - .then(this.uaaClient.clients() - .listMetadatas(ListMetadatasRequest.builder() - .build())) - .flatMapIterable(ListMetadatasResponse::getMetadatas) - .filter(metadata -> this.clientId.equals(metadata.getClientId())) - .single() - .as(StepVerifier::create) - .consumeNextWith(metadata -> { - assertThat(metadata.getAppLaunchUrl()).isEqualTo("http://test.list.url"); - assertThat(metadata.getClientId()).isEqualTo(this.clientId); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.uaaClient + .clients() + .listMetadatas(ListMetadatasRequest.builder().build())) + .flatMapIterable(ListMetadatasResponse::getMetadatas) + .filter(metadata -> this.clientId.equals(metadata.getClientId())) + .single() + .as(StepVerifier::create) + .consumeNextWith( + metadata -> { + assertThat(metadata.getAppLaunchUrl()) + .isEqualTo("http://test.list.url"); + assertThat(metadata.getClientId()).isEqualTo(this.clientId); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -363,44 +424,49 @@ public void mixedActions() { String clientSecret = this.nameFactory.getClientSecret(); String newClientSecret = this.nameFactory.getClientSecret(); - this.uaaClient.clients() - .mixedActions(MixedActionsRequest.builder() - .action(CreateClientAction.builder() - .authorizedGrantType(PASSWORD) - .clientId(clientId1) - .clientSecret(clientSecret) - .name("test-name-old") - .build()) - .action(CreateClientAction.builder() - .authorizedGrantType(PASSWORD) - .clientId(clientId2) - .clientSecret(clientSecret) - .build()) - .action(UpdateClientAction.builder() - .authorizedGrantType(PASSWORD) - .clientId(clientId1) - .name("test-name-temporary") - .build()) - .action(UpdateSecretAction.builder() - .clientId(clientId2) - .secret(newClientSecret) - .build()) - .action(DeleteClientAction.builder() - .clientId(clientId2) - .build()) - .action(UpdateSecretClientAction.builder() - .authorizedGrantType(PASSWORD) - .name("test-name-new") - .clientId(clientId1) - .secret(newClientSecret) - .build()) - .build()) - .thenMany(requestListClients(this.uaaClient)) - .filter(client -> clientId1.equals(client.getClientId())) - .as(StepVerifier::create) - .consumeNextWith(client -> assertThat(client.getName()).isEqualTo("test-name-new")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .clients() + .mixedActions( + MixedActionsRequest.builder() + .action( + CreateClientAction.builder() + .authorizedGrantType(PASSWORD) + .clientId(clientId1) + .clientSecret(clientSecret) + .name("test-name-old") + .build()) + .action( + CreateClientAction.builder() + .authorizedGrantType(PASSWORD) + .clientId(clientId2) + .clientSecret(clientSecret) + .build()) + .action( + UpdateClientAction.builder() + .authorizedGrantType(PASSWORD) + .clientId(clientId1) + .name("test-name-temporary") + .build()) + .action( + UpdateSecretAction.builder() + .clientId(clientId2) + .secret(newClientSecret) + .build()) + .action(DeleteClientAction.builder().clientId(clientId2).build()) + .action( + UpdateSecretClientAction.builder() + .authorizedGrantType(PASSWORD) + .name("test-name-new") + .clientId(clientId1) + .secret(newClientSecret) + .build()) + .build()) + .thenMany(requestListClients(this.uaaClient)) + .filter(client -> clientId1.equals(client.getClientId())) + .as(StepVerifier::create) + .consumeNextWith(client -> assertThat(client.getName()).isEqualTo("test-name-new")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -409,102 +475,121 @@ public void update() { String clientSecret = this.nameFactory.getClientSecret(); requestCreateClient(this.uaaClient, clientId, clientSecret) - .then(this.uaaClient.clients() - .update(UpdateClientRequest.builder() - .authorizedGrantType(CLIENT_CREDENTIALS) - .clientId(clientId) - .name("test-name") - .build())) - .thenMany(requestListClients(this.uaaClient)) - .filter(client -> clientId.equals(client.getClientId())) - .as(StepVerifier::create) - .consumeNextWith(response -> { - assertThat(response.getAuthorizedGrantTypes()).containsExactly(CLIENT_CREDENTIALS); - assertThat(response.getClientId()).isEqualTo(clientId); - assertThat(response.getName()).isEqualTo("test-name"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.uaaClient + .clients() + .update( + UpdateClientRequest.builder() + .authorizedGrantType(CLIENT_CREDENTIALS) + .clientId(clientId) + .name("test-name") + .build())) + .thenMany(requestListClients(this.uaaClient)) + .filter(client -> clientId.equals(client.getClientId())) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + assertThat(response.getAuthorizedGrantTypes()) + .containsExactly(CLIENT_CREDENTIALS); + assertThat(response.getClientId()).isEqualTo(clientId); + assertThat(response.getName()).isEqualTo("test-name"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void updateMetadata() { - String appIcon = Base64.getEncoder().encodeToString(new AsciiString("test-image").toByteArray()); - - this.uaaClient.clients() - .updateMetadata(UpdateMetadataRequest.builder() - .appIcon(appIcon) - .appLaunchUrl("http://test.app.launch.url") - .clientId(this.clientId) - .showOnHomePage(true) - .clientName("test-name") - .build()) - .then(requestGetMetadata(this.uaaClient, this.clientId)) - .as(StepVerifier::create) - .consumeNextWith(metadata -> { - assertThat(metadata.getAppIcon()).isEqualTo(appIcon); - assertThat(metadata.getAppLaunchUrl()).isEqualTo("http://test.app.launch.url"); - assertThat(metadata.getClientId()).isEqualTo(this.clientId); - assertThat(metadata.getClientName()).isEqualTo("test-name"); - assertThat(metadata.getShowOnHomePage()).isTrue(); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + String appIcon = + Base64.getEncoder().encodeToString(new AsciiString("test-image").toByteArray()); + + this.uaaClient + .clients() + .updateMetadata( + UpdateMetadataRequest.builder() + .appIcon(appIcon) + .appLaunchUrl("http://test.app.launch.url") + .clientId(this.clientId) + .showOnHomePage(true) + .clientName("test-name") + .build()) + .then(requestGetMetadata(this.uaaClient, this.clientId)) + .as(StepVerifier::create) + .consumeNextWith( + metadata -> { + assertThat(metadata.getAppIcon()).isEqualTo(appIcon); + assertThat(metadata.getAppLaunchUrl()) + .isEqualTo("http://test.app.launch.url"); + assertThat(metadata.getClientId()).isEqualTo(this.clientId); + assertThat(metadata.getClientName()).isEqualTo("test-name"); + assertThat(metadata.getShowOnHomePage()).isTrue(); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono batchCreateClients(UaaClient uaaClient, String clientId1, String clientId2, String clientSecret) { - return uaaClient.clients() - .batchCreate(BatchCreateClientsRequest.builder() - .client(CreateClient.builder() - .approvalsDeleted(true) - .authorizedGrantType(PASSWORD) - .clientId(clientId1) - .clientSecret(clientSecret) - .scopes("client.read", "client.write") - .tokenSalt("test-token-salt") - .build()) - .client(CreateClient.builder() - .approvalsDeleted(true) - .authorizedGrantTypes(PASSWORD, REFRESH_TOKEN) - .clientId(clientId2) - .clientSecret(clientSecret) - .scope("client.write") - .tokenSalt("alternate-test-token-salt") - .build()) - .build()); + private static Mono batchCreateClients( + UaaClient uaaClient, String clientId1, String clientId2, String clientSecret) { + return uaaClient + .clients() + .batchCreate( + BatchCreateClientsRequest.builder() + .client( + CreateClient.builder() + .approvalsDeleted(true) + .authorizedGrantType(PASSWORD) + .clientId(clientId1) + .clientSecret(clientSecret) + .scopes("client.read", "client.write") + .tokenSalt("test-token-salt") + .build()) + .client( + CreateClient.builder() + .approvalsDeleted(true) + .authorizedGrantTypes(PASSWORD, REFRESH_TOKEN) + .clientId(clientId2) + .clientSecret(clientSecret) + .scope("client.write") + .tokenSalt("alternate-test-token-salt") + .build()) + .build()); } - private static Mono requestCreateClient(UaaClient uaaClient, String clientId, String clientSecret) { - return uaaClient.clients() - .create(CreateClientRequest.builder() - .authorizedGrantType(PASSWORD) - .clientId(clientId) - .clientSecret(clientSecret) - .build()); + private static Mono requestCreateClient( + UaaClient uaaClient, String clientId, String clientSecret) { + return uaaClient + .clients() + .create( + CreateClientRequest.builder() + .authorizedGrantType(PASSWORD) + .clientId(clientId) + .clientSecret(clientSecret) + .build()); } - private static Mono requestGetMetadata(UaaClient uaaClient, String clientId) { - return uaaClient.clients() - .getMetadata(GetMetadataRequest.builder() - .clientId(clientId) - .build()); + private static Mono requestGetMetadata( + UaaClient uaaClient, String clientId) { + return uaaClient + .clients() + .getMetadata(GetMetadataRequest.builder().clientId(clientId).build()); } private static Flux requestListClients(UaaClient uaaClient) { - return PaginationUtils - .requestUaaResources(startIndex -> uaaClient.clients() - .list(ListClientsRequest.builder() - .startIndex(startIndex) - .build())); - + return PaginationUtils.requestUaaResources( + startIndex -> + uaaClient + .clients() + .list(ListClientsRequest.builder().startIndex(startIndex).build())); } - private static Mono requestUpdateMetadata(UaaClient uaaClient, String clientId, String appLaunchUrl) { - return uaaClient.clients() - .updateMetadata(UpdateMetadataRequest.builder() - .appLaunchUrl(appLaunchUrl) - .clientId(clientId) - .build()); + private static Mono requestUpdateMetadata( + UaaClient uaaClient, String clientId, String appLaunchUrl) { + return uaaClient + .clients() + .updateMetadata( + UpdateMetadataRequest.builder() + .appLaunchUrl(appLaunchUrl) + .clientId(clientId) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/uaa/GroupsTest.java b/integration-test/src/test/java/org/cloudfoundry/uaa/GroupsTest.java index 6534aa199e9..99cf6d503f6 100644 --- a/integration-test/src/test/java/org/cloudfoundry/uaa/GroupsTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/uaa/GroupsTest.java @@ -16,6 +16,12 @@ package org.cloudfoundry.uaa; +import static org.assertj.core.api.Assertions.assertThat; +import static org.cloudfoundry.util.tuple.TupleUtils.consumer; +import static org.cloudfoundry.util.tuple.TupleUtils.function; + +import java.time.Duration; +import java.util.Optional; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.uaa.groups.AddMemberRequest; import org.cloudfoundry.uaa.groups.CheckMembershipRequest; @@ -47,52 +53,56 @@ import org.cloudfoundry.uaa.users.Email; import org.cloudfoundry.uaa.users.Name; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.Optional; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.cloudfoundry.util.tuple.TupleUtils.consumer; -import static org.cloudfoundry.util.tuple.TupleUtils.function; - - public final class GroupsTest extends AbstractIntegrationTest { - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; @Test public void addMemberGroup() { String baseDisplayName = this.nameFactory.getGroupName(); String memberDisplayName = this.nameFactory.getGroupName(); - Mono - .zip( - createGroupId(this.uaaClient, baseDisplayName), - createGroupId(this.uaaClient, memberDisplayName) - ) - .flatMap(function((baseGroupId, memberGroupId) -> Mono.zip( - this.uaaClient.groups() - .addMember(AddMemberRequest.builder() - .groupId(baseGroupId) - .origin(memberDisplayName + "-origin") - .type(MemberType.GROUP) - .memberId(memberGroupId) - .build()), - Mono.just(memberGroupId) - ))) - .as(StepVerifier::create) - .consumeNextWith(consumer((response, memberGroupId) -> { - assertThat(response.getMemberId()).isEqualTo(memberGroupId); - assertThat(response.getOrigin()).isEqualTo(Optional.of(String.format("%s-origin", memberDisplayName))); - assertThat(response.getType()).isEqualTo(Optional.of(MemberType.GROUP)); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip( + createGroupId(this.uaaClient, baseDisplayName), + createGroupId(this.uaaClient, memberDisplayName)) + .flatMap( + function( + (baseGroupId, memberGroupId) -> + Mono.zip( + this.uaaClient + .groups() + .addMember( + AddMemberRequest.builder() + .groupId(baseGroupId) + .origin( + memberDisplayName + + "-origin") + .type(MemberType.GROUP) + .memberId(memberGroupId) + .build()), + Mono.just(memberGroupId)))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (response, memberGroupId) -> { + assertThat(response.getMemberId()).isEqualTo(memberGroupId); + assertThat(response.getOrigin()) + .isEqualTo( + Optional.of( + String.format( + "%s-origin", + memberDisplayName))); + assertThat(response.getType()) + .isEqualTo(Optional.of(MemberType.GROUP)); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -100,29 +110,37 @@ public void addMemberUser() { String displayName = this.nameFactory.getGroupName(); String userName = this.nameFactory.getUserName(); - Mono. - zip( - createGroupId(this.uaaClient, displayName), - createUserId(this.uaaClient, userName) - ) - .flatMap(function((groupId, userId) -> Mono.zip( - this.uaaClient.groups() - .addMember(AddMemberRequest.builder() - .groupId(groupId) - .origin(userName + "-origin") - .type(MemberType.USER) - .memberId(userId) - .build()), - Mono.just(userId) - ))) - .as(StepVerifier::create) - .consumeNextWith(consumer((response, userId) -> { - assertThat(response.getMemberId()).isEqualTo(userId); - assertThat(response.getOrigin()).isEqualTo(Optional.of(String.format("%s-origin", userName))); - assertThat(response.getType()).isEqualTo(Optional.of(MemberType.USER)); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + Mono.zip(createGroupId(this.uaaClient, displayName), createUserId(this.uaaClient, userName)) + .flatMap( + function( + (groupId, userId) -> + Mono.zip( + this.uaaClient + .groups() + .addMember( + AddMemberRequest.builder() + .groupId(groupId) + .origin( + userName + + "-origin") + .type(MemberType.USER) + .memberId(userId) + .build()), + Mono.just(userId)))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (response, userId) -> { + assertThat(response.getMemberId()).isEqualTo(userId); + assertThat(response.getOrigin()) + .isEqualTo( + Optional.of( + String.format("%s-origin", userName))); + assertThat(response.getType()) + .isEqualTo(Optional.of(MemberType.USER)); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -131,26 +149,36 @@ public void checkMembership() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> Mono.zip( - createGroupIdWithMember(this.uaaClient, displayName, userId), - Mono.just(userId) - )) - .flatMap(function((groupId, userId) -> Mono.zip( - this.uaaClient.groups() - .checkMembership(CheckMembershipRequest.builder() - .groupId(groupId) - .memberId(userId) - .build()), - Mono.just(userId) - ))) - .as(StepVerifier::create) - .consumeNextWith(consumer((response, userId) -> { - assertThat(response.getMemberId()).isEqualTo(userId); - assertThat(response.getOrigin()).isEqualTo(Optional.of("test-origin")); - assertThat(response.getType()).isEqualTo(Optional.of(MemberType.USER)); - })) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + Mono.zip( + createGroupIdWithMember( + this.uaaClient, displayName, userId), + Mono.just(userId))) + .flatMap( + function( + (groupId, userId) -> + Mono.zip( + this.uaaClient + .groups() + .checkMembership( + CheckMembershipRequest.builder() + .groupId(groupId) + .memberId(userId) + .build()), + Mono.just(userId)))) + .as(StepVerifier::create) + .consumeNextWith( + consumer( + (response, userId) -> { + assertThat(response.getMemberId()).isEqualTo(userId); + assertThat(response.getOrigin()) + .isEqualTo(Optional.of("test-origin")); + assertThat(response.getType()) + .isEqualTo(Optional.of(MemberType.USER)); + })) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -159,20 +187,26 @@ public void create() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.groups() - .create(CreateGroupRequest.builder() - .displayName(displayName) - .member(MemberSummary.builder() - .memberId(userId) - .build()) - .build())) - .then(requestList(this.uaaClient) - .filter(resource -> displayName.equals(resource.getDisplayName())) - .single()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + this.uaaClient + .groups() + .create( + CreateGroupRequest.builder() + .displayName(displayName) + .member( + MemberSummary.builder() + .memberId(userId) + .build()) + .build())) + .then( + requestList(this.uaaClient) + .filter(resource -> displayName.equals(resource.getDisplayName())) + .single()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -180,15 +214,19 @@ public void delete() { String displayName = this.nameFactory.getGroupName(); createGroupId(this.uaaClient, displayName) - .flatMap(groupId -> this.uaaClient.groups() - .delete(DeleteGroupRequest.builder() - .groupId(groupId) - .build())) - .map(DeleteGroupResponse::getDisplayName) - .as(StepVerifier::create) - .expectNext(displayName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + groupId -> + this.uaaClient + .groups() + .delete( + DeleteGroupRequest.builder() + .groupId(groupId) + .build())) + .map(DeleteGroupResponse::getDisplayName) + .as(StepVerifier::create) + .expectNext(displayName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -196,15 +234,16 @@ public void get() { String displayName = this.nameFactory.getGroupName(); createGroupId(this.uaaClient, displayName) - .flatMap(groupId -> this.uaaClient.groups() - .get(GetGroupRequest.builder() - .groupId(groupId) - .build()) - .map(GetGroupResponse::getDisplayName)) - .as(StepVerifier::create) - .expectNext(displayName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + groupId -> + this.uaaClient + .groups() + .get(GetGroupRequest.builder().groupId(groupId).build()) + .map(GetGroupResponse::getDisplayName)) + .as(StepVerifier::create) + .expectNext(displayName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -212,18 +251,29 @@ public void list() { String displayName = this.nameFactory.getGroupName(); createGroupId(this.uaaClient, displayName) - .flatMap(groupId -> PaginationUtils - .requestUaaResources(startIndex -> this.uaaClient.groups() - .list(ListGroupsRequest.builder() - .filter(String.format("id eq \"%s\"", groupId)) - .startIndex(startIndex) - .build())) - .single()) - .map(Group::getDisplayName) - .as(StepVerifier::create) - .expectNext(displayName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + groupId -> + PaginationUtils.requestUaaResources( + startIndex -> + this.uaaClient + .groups() + .list( + ListGroupsRequest.builder() + .filter( + String + .format( + "id eq" + + " \"%s\"", + groupId)) + .startIndex( + startIndex) + .build())) + .single()) + .map(Group::getDisplayName) + .as(StepVerifier::create) + .expectNext(displayName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -231,18 +281,26 @@ public void listExternalGroupMappings() { String displayName = this.nameFactory.getGroupName(); createGroupId(this.uaaClient, displayName) - .flatMap(groupId -> requestMapExternalGroupResponse(this.uaaClient, displayName, groupId)) - .thenMany(PaginationUtils - .requestUaaResources(startIndex -> this.uaaClient.groups() - .listExternalGroupMappings(ListExternalGroupMappingsRequest.builder() - .startIndex(startIndex) - .build())) - .filter(group -> displayName.equals(group.getDisplayName()))) - .map(ExternalGroupResource::getExternalGroup) - .as(StepVerifier::create) - .expectNext(displayName + "-external-group") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + groupId -> + requestMapExternalGroupResponse( + this.uaaClient, displayName, groupId)) + .thenMany( + PaginationUtils.requestUaaResources( + startIndex -> + this.uaaClient + .groups() + .listExternalGroupMappings( + ListExternalGroupMappingsRequest + .builder() + .startIndex(startIndex) + .build())) + .filter(group -> displayName.equals(group.getDisplayName()))) + .map(ExternalGroupResource::getExternalGroup) + .as(StepVerifier::create) + .expectNext(displayName + "-external-group") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -251,25 +309,32 @@ public void listMembers() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> Mono.zip( - createGroupIdWithMember(this.uaaClient, displayName, userId), - Mono.just(userId) - )) - .flatMap(function((groupId, userId) -> Mono.zip( - this.uaaClient.groups() - .listMembers(ListMembersRequest.builder() - .groupId(groupId) - .returnEntities(false) - .build()) - .flatMapIterable(ListMembersResponse::getMembers) - .map(Member::getMemberId) - .single(), - Mono.just(userId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + Mono.zip( + createGroupIdWithMember( + this.uaaClient, displayName, userId), + Mono.just(userId))) + .flatMap( + function( + (groupId, userId) -> + Mono.zip( + this.uaaClient + .groups() + .listMembers( + ListMembersRequest.builder() + .groupId(groupId) + .returnEntities(false) + .build()) + .flatMapIterable( + ListMembersResponse::getMembers) + .map(Member::getMemberId) + .single(), + Mono.just(userId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -278,22 +343,26 @@ public void listMembersWithEntity() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> createGroupIdWithMember(this.uaaClient, displayName, userId)) - .flatMapMany(groupId -> this.uaaClient.groups() - .listMembers(ListMembersRequest.builder() - .groupId(groupId) - .returnEntities(true) - .build())) - .flatMapIterable(ListMembersResponse::getMembers) - .map(Member::getEntity) - .map(Optional::get) - .cast(UserEntity.class) - .single() - .map(UserEntity::getUserName) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap(userId -> createGroupIdWithMember(this.uaaClient, displayName, userId)) + .flatMapMany( + groupId -> + this.uaaClient + .groups() + .listMembers( + ListMembersRequest.builder() + .groupId(groupId) + .returnEntities(true) + .build())) + .flatMapIterable(ListMembersResponse::getMembers) + .map(Member::getEntity) + .map(Optional::get) + .cast(UserEntity.class) + .single() + .map(UserEntity::getUserName) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -301,21 +370,30 @@ public void mapExternalGroupMappings() { String displayName = this.nameFactory.getGroupName(); createGroupId(this.uaaClient, displayName) - .flatMap(groupId -> this.uaaClient.groups() - .mapExternalGroup(MapExternalGroupRequest.builder() - .externalGroup(displayName + "-external-group") - .groupId(groupId) - .origin(displayName + "-origin") - .build())) - .thenMany(requestListExternalGroupResource(this.uaaClient) - .filter(group -> displayName.equals(group.getDisplayName()))) - .as(StepVerifier::create) - .consumeNextWith(resource -> { - assertThat(resource.getExternalGroup()).isEqualTo(String.format("%s-external-group", displayName)); - assertThat(resource.getOrigin()).isEqualTo(String.format("%s-origin", displayName)); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + groupId -> + this.uaaClient + .groups() + .mapExternalGroup( + MapExternalGroupRequest.builder() + .externalGroup( + displayName + "-external-group") + .groupId(groupId) + .origin(displayName + "-origin") + .build())) + .thenMany( + requestListExternalGroupResource(this.uaaClient) + .filter(group -> displayName.equals(group.getDisplayName()))) + .as(StepVerifier::create) + .consumeNextWith( + resource -> { + assertThat(resource.getExternalGroup()) + .isEqualTo(String.format("%s-external-group", displayName)); + assertThat(resource.getOrigin()) + .isEqualTo(String.format("%s-origin", displayName)); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -324,23 +402,29 @@ public void removeMember() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> Mono.zip( - createGroupIdWithMember(this.uaaClient, displayName, userId), - Mono.just(userId) - )) - .flatMap(function((groupId, userId) -> Mono.zip( - this.uaaClient.groups() - .removeMember(RemoveMemberRequest.builder() - .groupId(groupId) - .memberId(userId) - .build()) - .map(RemoveMemberResponse::getMemberId), - Mono.just(userId) - ))) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + Mono.zip( + createGroupIdWithMember( + this.uaaClient, displayName, userId), + Mono.just(userId))) + .flatMap( + function( + (groupId, userId) -> + Mono.zip( + this.uaaClient + .groups() + .removeMember( + RemoveMemberRequest.builder() + .groupId(groupId) + .memberId(userId) + .build()) + .map(RemoveMemberResponse::getMemberId), + Mono.just(userId)))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -348,18 +432,24 @@ public void unmapExternalGroupMappingsByGroupDisplayName() { String displayName = this.nameFactory.getGroupName(); createGroupId(this.uaaClient, displayName) - .flatMap(groupId -> requestMapExternalGroupResponse(this.uaaClient, displayName, groupId)) - .then(this.uaaClient.groups() - .unmapExternalGroupByGroupDisplayName(UnmapExternalGroupByGroupDisplayNameRequest.builder() - .groupDisplayName(displayName) - .externalGroup(displayName + "-external-group") - .origin(displayName + "-origin") - .build())) - .thenMany(requestListExternalGroupResources(this.uaaClient)) - .filter(resource -> displayName.equals(resource.getDisplayName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + groupId -> + requestMapExternalGroupResponse( + this.uaaClient, displayName, groupId)) + .then( + this.uaaClient + .groups() + .unmapExternalGroupByGroupDisplayName( + UnmapExternalGroupByGroupDisplayNameRequest.builder() + .groupDisplayName(displayName) + .externalGroup(displayName + "-external-group") + .origin(displayName + "-origin") + .build())) + .thenMany(requestListExternalGroupResources(this.uaaClient)) + .filter(resource -> displayName.equals(resource.getDisplayName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -367,18 +457,27 @@ public void unmapExternalGroupMappingsByGroupId() { String displayName = this.nameFactory.getGroupName(); createGroupId(this.uaaClient, displayName) - .delayUntil(groupId -> requestMapExternalGroupResponse(this.uaaClient, displayName, groupId)) - .flatMap(groupId -> this.uaaClient.groups() - .unmapExternalGroupByGroupId(UnmapExternalGroupByGroupIdRequest.builder() - .groupId(groupId) - .externalGroup(displayName + "-external-group") - .origin(displayName + "-origin") - .build())) - .thenMany(requestListExternalGroupResources(this.uaaClient) - .filter(resource -> displayName.equals(resource.getDisplayName()))) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .delayUntil( + groupId -> + requestMapExternalGroupResponse( + this.uaaClient, displayName, groupId)) + .flatMap( + groupId -> + this.uaaClient + .groups() + .unmapExternalGroupByGroupId( + UnmapExternalGroupByGroupIdRequest.builder() + .groupId(groupId) + .externalGroup( + displayName + "-external-group") + .origin(displayName + "-origin") + .build())) + .thenMany( + requestListExternalGroupResources(this.uaaClient) + .filter(resource -> displayName.equals(resource.getDisplayName()))) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -387,102 +486,123 @@ public void update() { String newDisplayName = this.nameFactory.getGroupName(); createGroupId(this.uaaClient, baseDisplayName) - .flatMap(groupId -> this.uaaClient.groups() - .update(UpdateGroupRequest.builder() - .displayName(newDisplayName) - .groupId(groupId) - .version("*") - .build())) - .then(requestList(this.uaaClient) - .filter(resource -> newDisplayName.equals(resource.getDisplayName())) - .single()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + groupId -> + this.uaaClient + .groups() + .update( + UpdateGroupRequest.builder() + .displayName(newDisplayName) + .groupId(groupId) + .version("*") + .build())) + .then( + requestList(this.uaaClient) + .filter( + resource -> + newDisplayName.equals(resource.getDisplayName())) + .single()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } private static Mono createGroupId(UaaClient uaaClient, String displayName) { - return requestCreateGroup(uaaClient, displayName) - .map(CreateGroupResponse::getId); + return requestCreateGroup(uaaClient, displayName).map(CreateGroupResponse::getId); } - private static Mono createGroupIdWithMember(UaaClient uaaClient, String displayName, String userId) { + private static Mono createGroupIdWithMember( + UaaClient uaaClient, String displayName, String userId) { return requestCreateGroupWithMember(uaaClient, displayName, userId) - .map(CreateGroupResponse::getId); + .map(CreateGroupResponse::getId); } private static Mono createUserId(UaaClient uaaClient, String userName) { - return requestCreateUser(uaaClient, userName) - .map(CreateUserResponse::getId); + return requestCreateUser(uaaClient, userName).map(CreateUserResponse::getId); } - private static Mono requestCreateGroup(UaaClient uaaClient, String displayName) { - return uaaClient.groups() - .create(CreateGroupRequest.builder() - .displayName(displayName) - .build()); + private static Mono requestCreateGroup( + UaaClient uaaClient, String displayName) { + return uaaClient + .groups() + .create(CreateGroupRequest.builder().displayName(displayName).build()); } - private static Mono requestCreateGroupWithMember(UaaClient uaaClient, String displayName, String userId) { - return uaaClient.groups() - .create(CreateGroupRequest.builder() - .displayName(displayName) - .member(MemberSummary.builder() - .memberId(userId) - .origin("test-origin") - .type(MemberType.USER) - .build()) - .build()); + private static Mono requestCreateGroupWithMember( + UaaClient uaaClient, String displayName, String userId) { + return uaaClient + .groups() + .create( + CreateGroupRequest.builder() + .displayName(displayName) + .member( + MemberSummary.builder() + .memberId(userId) + .origin("test-origin") + .type(MemberType.USER) + .build()) + .build()); } - private static Mono requestCreateUser(UaaClient uaaClient, String userName) { - return uaaClient.users() - .create(CreateUserRequest.builder() - .email(Email.builder() - .value("test-email") - .primary(true) - .build()) - .name(Name.builder() - .familyName("test-family-name") - .givenName("test-given-name") - .build()) - .password("test-password") - .userName(userName) - .build()); + private static Mono requestCreateUser( + UaaClient uaaClient, String userName) { + return uaaClient + .users() + .create( + CreateUserRequest.builder() + .email(Email.builder().value("test-email").primary(true).build()) + .name( + Name.builder() + .familyName("test-family-name") + .givenName("test-given-name") + .build()) + .password("test-password") + .userName(userName) + .build()); } private static Flux requestList(UaaClient uaaClient) { - return PaginationUtils - .requestUaaResources(startIndex -> uaaClient.groups() - .list(ListGroupsRequest.builder() - .startIndex(startIndex) - .build())); + return PaginationUtils.requestUaaResources( + startIndex -> + uaaClient + .groups() + .list(ListGroupsRequest.builder().startIndex(startIndex).build())); } - private static Flux requestListExternalGroupResource(UaaClient uaaClient) { - return PaginationUtils - .requestUaaResources(startIndex -> uaaClient.groups() - .listExternalGroupMappings(ListExternalGroupMappingsRequest.builder() - .startIndex(startIndex) - .build())); + private static Flux requestListExternalGroupResource( + UaaClient uaaClient) { + return PaginationUtils.requestUaaResources( + startIndex -> + uaaClient + .groups() + .listExternalGroupMappings( + ListExternalGroupMappingsRequest.builder() + .startIndex(startIndex) + .build())); } - private static Flux requestListExternalGroupResources(UaaClient uaaClient) { - return PaginationUtils - .requestUaaResources(startIndex -> uaaClient.groups() - .listExternalGroupMappings(ListExternalGroupMappingsRequest.builder() - .startIndex(startIndex) - .build())); + private static Flux requestListExternalGroupResources( + UaaClient uaaClient) { + return PaginationUtils.requestUaaResources( + startIndex -> + uaaClient + .groups() + .listExternalGroupMappings( + ListExternalGroupMappingsRequest.builder() + .startIndex(startIndex) + .build())); } - private static Mono requestMapExternalGroupResponse(UaaClient uaaClient, String displayName, String groupId) { - return uaaClient.groups() - .mapExternalGroup(MapExternalGroupRequest.builder() - .externalGroup(displayName + "-external-group") - .groupId(groupId) - .origin(displayName + "-origin") - .build()); + private static Mono requestMapExternalGroupResponse( + UaaClient uaaClient, String displayName, String groupId) { + return uaaClient + .groups() + .mapExternalGroup( + MapExternalGroupRequest.builder() + .externalGroup(displayName + "-external-group") + .groupId(groupId) + .origin(displayName + "-origin") + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/uaa/IdentityProvidersTest.java b/integration-test/src/test/java/org/cloudfoundry/uaa/IdentityProvidersTest.java index 2be3d6cac3a..8b9afd5fc11 100644 --- a/integration-test/src/test/java/org/cloudfoundry/uaa/IdentityProvidersTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/uaa/IdentityProvidersTest.java @@ -16,6 +16,11 @@ package org.cloudfoundry.uaa; +import static org.cloudfoundry.uaa.identityproviders.Type.LDAP; +import static org.cloudfoundry.uaa.identityproviders.Type.OAUTH2; +import static org.cloudfoundry.uaa.identityproviders.Type.SAML; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.uaa.identityproviders.CreateIdentityProviderRequest; import org.cloudfoundry.uaa.identityproviders.CreateIdentityProviderResponse; @@ -33,23 +38,16 @@ import org.cloudfoundry.uaa.identityproviders.UpdateIdentityProviderRequest; import org.cloudfoundry.uaa.identityzones.CreateIdentityZoneRequest; import org.cloudfoundry.uaa.identityzones.CreateIdentityZoneResponse; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.cloudfoundry.uaa.identityproviders.Type.LDAP; -import static org.cloudfoundry.uaa.identityproviders.Type.OAUTH2; -import static org.cloudfoundry.uaa.identityproviders.Type.SAML; - public final class IdentityProvidersTest extends AbstractIntegrationTest { - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; - @Autowired - private Mono userId; + @Autowired private Mono userId; @Test public void createLdapSimpleBind() { @@ -58,37 +56,52 @@ public void createLdapSimpleBind() { String subdomainName = this.nameFactory.getDomainName(); this.userId - .flatMap(userId -> requestCreateIdentityZone(this.uaaClient, identityZoneName, subdomainName)) - .then(this.uaaClient.identityProviders() - .create(CreateIdentityProviderRequest.builder() - .active(true) - .configuration(LdapConfiguration.builder() - .addShadowUserOnLogin(true) - .autoAddGroups(true) - .baseUrl(String.format("ldap://%s.url", name)) - .groupSearchDepthLimit(10) - .groupSearchSubTree(true) - .ldapGroupFile(LdapGroupFile.NO_GROUP) - .ldapProfileFile(LdapProfileFile.SIMPLE_BIND) - .mailAttributeName("mail") - .mailSubstituteOverridesLdap(false) - .skipSSLVerification(false) - .tlsConfiguration(TlsConfiguration.NONE) - .userDistinguishedNamePattern("cn={0},ou=Users,dc=test,dc=com") - .userDistinguishedNamePatternDelimiter(";") - .build()) - .identityZoneId(identityZoneName) - .name(name) - .originKey("ldap") - .type(LDAP) - .build())) - .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) - .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) - .filter(provider -> LDAP.equals(provider.getType())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + requestCreateIdentityZone( + this.uaaClient, identityZoneName, subdomainName)) + .then( + this.uaaClient + .identityProviders() + .create( + CreateIdentityProviderRequest.builder() + .active(true) + .configuration( + LdapConfiguration.builder() + .addShadowUserOnLogin(true) + .autoAddGroups(true) + .baseUrl( + String.format( + "ldap://%s.url", + name)) + .groupSearchDepthLimit(10) + .groupSearchSubTree(true) + .ldapGroupFile( + LdapGroupFile.NO_GROUP) + .ldapProfileFile( + LdapProfileFile.SIMPLE_BIND) + .mailAttributeName("mail") + .mailSubstituteOverridesLdap(false) + .skipSSLVerification(false) + .tlsConfiguration( + TlsConfiguration.NONE) + .userDistinguishedNamePattern( + "cn={0},ou=Users,dc=test,dc=com") + .userDistinguishedNamePatternDelimiter( + ";") + .build()) + .identityZoneId(identityZoneName) + .name(name) + .originKey("ldap") + .type(LDAP) + .build())) + .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) + .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) + .filter(provider -> LDAP.equals(provider.getType())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -98,32 +111,39 @@ public void createOAuth() { String subdomainName = this.nameFactory.getDomainName(); this.userId - .flatMap(userId -> requestCreateIdentityZone(this.uaaClient, identityZoneName, subdomainName)) - .then(this.uaaClient.identityProviders() - .create(CreateIdentityProviderRequest.builder() - .active(true) - .configuration(OAuth2Configuration.builder() - .addShadowUserOnLogin(true) - .authUrl("http://auth.url") - .relyingPartyId("uaa") - .relyingPartySecret("secret") - .showLinkText(false) - .skipSslVerification(false) - .tokenKey("token-key") - .tokenUrl("http://token.url") - .build()) - .identityZoneId(identityZoneName) - .name(name) - .originKey("oauth2.0") - .type(OAUTH2) - .build())) - .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) - .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) - .filter(provider -> OAUTH2.equals(provider.getType())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + requestCreateIdentityZone( + this.uaaClient, identityZoneName, subdomainName)) + .then( + this.uaaClient + .identityProviders() + .create( + CreateIdentityProviderRequest.builder() + .active(true) + .configuration( + OAuth2Configuration.builder() + .addShadowUserOnLogin(true) + .authUrl("http://auth.url") + .relyingPartyId("uaa") + .relyingPartySecret("secret") + .showLinkText(false) + .skipSslVerification(false) + .tokenKey("token-key") + .tokenUrl("http://token.url") + .build()) + .identityZoneId(identityZoneName) + .name(name) + .originKey("oauth2.0") + .type(OAUTH2) + .build())) + .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) + .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) + .filter(provider -> OAUTH2.equals(provider.getType())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -133,46 +153,70 @@ public void createSaml() { String subdomainName = this.nameFactory.getDomainName(); this.userId - .flatMap(userId -> requestCreateIdentityZone(this.uaaClient, identityZoneName, subdomainName)) - .then(this.uaaClient.identityProviders() - .create(CreateIdentityProviderRequest.builder() - .active(true) - .configuration(SamlConfiguration.builder() - .addShadowUserOnLogin(true) - .metaDataLocation("MIICmTCCAgKgAwIBAgIGAUPATqmEMA0GCSqGSIb3DQEBBQUAMIGPMQswCQYDVQQGEwJVUzETMBEG" + - "\nA1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsGA1UECgwET2t0YTEU\nMBIGA1UECwwLU1NPUHJvdmlkZXIxEDAOBgNVBAMMB1Bpdm90YWwxHDAaBgkqhkiG9w0BCQEWDWlu" + - "\nZm9Ab2t0YS5jb20wHhcNMTQwMTIzMTgxMjM3WhcNNDQwMTIzMTgxMzM3WjCBjzELMAkGA1UEBhMC\nVVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoM" + - "\nBE9rdGExFDASBgNVBAsMC1NTT1Byb3ZpZGVyMRAwDgYDVQQDDAdQaXZvdGFsMRwwGgYJKoZIhvcN\nAQkBFg1pbmZvQG9rdGEuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCeil67/TLOiTZU" + - "\nWWgW2XEGgFZ94bVO90v5J1XmcHMwL8v5Z/8qjdZLpGdwI7Ph0CyXMMNklpaR/Ljb8fsls3amdT5O\nBw92Zo8ulcpjw2wuezTwL0eC0wY/GQDAZiXL59npE6U+fH1lbJIq92hx0HJSru/0O1q3+A/+jjZL\n3tL" + - "/SwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAI5BoWZoH6Mz9vhypZPOJCEKa/K+biZQsA4Zqsuk\nvvphhSERhqk/Nv76Vkl8uvJwwHbQrR9KJx4L3PRkGCG24rix71jEuXVGZUsDNM3CUKnARx4MEab6\nGFHNkZ6DmoT" + - "/PFagngecHu+EwmuDtaG0rEkFrARwe+d8Ru0BN558abFburn:oasis:names:tc:SAML:1.1:nameid" + - "-format:emailAddressurn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\n") - .nameId("urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress") - .assertionConsumerIndex(0) - .metadataTrustCheck(false) - .showSamlLink(false) - .socketFactoryClassName("org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory") - .linkText("IDPEndpointsMockTests Saml Provider:SAML") - .groupMappingMode(ExternalGroupMappingMode.EXPLICITLY_MAPPED) - .build()) - .identityZoneId(identityZoneName) - .name(name) - .originKey("SAML") - .type(SAML) - .build())) - .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) - .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) - .filter(provider -> SAML.equals(provider.getType())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + requestCreateIdentityZone( + this.uaaClient, identityZoneName, subdomainName)) + .then( + this.uaaClient + .identityProviders() + .create( + CreateIdentityProviderRequest.builder() + .active(true) + .configuration( + SamlConfiguration.builder() + .addShadowUserOnLogin(true) + .metaDataLocation( + "MIICmTCCAgKgAwIBAgIGAUPATqmEMA0GCSqGSIb3DQEBBQUAMIGPMQswCQYDVQQGEwJVUzETMBEG\n" + + "A1UECAwKQ2FsaWZvcm5pYTEWMBQGA1UEBwwNU2FuIEZyYW5jaXNjbzENMAsGA1UECgwET2t0YTEU\n" + + "MBIGA1UECwwLU1NPUHJvdmlkZXIxEDAOBgNVBAMMB1Bpdm90YWwxHDAaBgkqhkiG9w0BCQEWDWlu\n" + + "Zm9Ab2t0YS5jb20wHhcNMTQwMTIzMTgxMjM3WhcNNDQwMTIzMTgxMzM3WjCBjzELMAkGA1UEBhMC\n" + + "VVMxEzARBgNVBAgMCkNhbGlmb3JuaWExFjAUBgNVBAcMDVNhbiBGcmFuY2lzY28xDTALBgNVBAoM\n" + + "BE9rdGExFDASBgNVBAsMC1NTT1Byb3ZpZGVyMRAwDgYDVQQDDAdQaXZvdGFsMRwwGgYJKoZIhvcN\n" + + "AQkBFg1pbmZvQG9rdGEuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCeil67/TLOiTZU\n" + + "WWgW2XEGgFZ94bVO90v5J1XmcHMwL8v5Z/8qjdZLpGdwI7Ph0CyXMMNklpaR/Ljb8fsls3amdT5O\n" + + "Bw92Zo8ulcpjw2wuezTwL0eC0wY/GQDAZiXL59npE6U+fH1lbJIq92hx0HJSru/0O1q3+A/+jjZL\n" + + "3tL/SwIDAQABMA0GCSqGSIb3DQEBBQUAA4GBAI5BoWZoH6Mz9vhypZPOJCEKa/K+biZQsA4Zqsuk\n" + + "vvphhSERhqk/Nv76Vkl8uvJwwHbQrR9KJx4L3PRkGCG24rix71jEuXVGZUsDNM3CUKnARx4MEab6\n" + + "GFHNkZ6DmoT" + + "/PFagngecHu+EwmuDtaG0rEkFrARwe+d8Ru0BN558abFburn:oasis:names:tc:SAML:1.1:nameid-format:emailAddressurn:oasis:names:tc:SAML:1.1:nameid-format:unspecified\n") + .nameId( + "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress") + .assertionConsumerIndex(0) + .metadataTrustCheck(false) + .showSamlLink(false) + .socketFactoryClassName( + "org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory") + .linkText( + "IDPEndpointsMockTests Saml" + + " Provider:SAML") + .groupMappingMode( + ExternalGroupMappingMode + .EXPLICITLY_MAPPED) + .build()) + .identityZoneId(identityZoneName) + .name(name) + .originKey("SAML") + .type(SAML) + .build())) + .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) + .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) + .filter(provider -> SAML.equals(provider.getType())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -182,19 +226,27 @@ public void delete() { String subdomainName = this.nameFactory.getDomainName(); this.userId - .flatMap(userId -> requestCreateIdentityZone(this.uaaClient, identityZoneName, subdomainName)) - .then(requestCreateIdentityProvider(this.uaaClient, identityZoneName, name)) - .flatMap(response -> this.uaaClient.identityProviders() - .delete(DeleteIdentityProviderRequest.builder() - .identityProviderId(response.getId()) - .identityZoneId(response.getIdentityZoneId()) - .build())) - .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) - .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) - .filter(provider -> name.equals(provider.getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + requestCreateIdentityZone( + this.uaaClient, identityZoneName, subdomainName)) + .then(requestCreateIdentityProvider(this.uaaClient, identityZoneName, name)) + .flatMap( + response -> + this.uaaClient + .identityProviders() + .delete( + DeleteIdentityProviderRequest.builder() + .identityProviderId(response.getId()) + .identityZoneId( + response.getIdentityZoneId()) + .build())) + .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) + .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) + .filter(provider -> name.equals(provider.getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -204,17 +256,24 @@ public void get() { String subdomainName = this.nameFactory.getDomainName(); this.userId - .flatMap(userId -> requestCreateIdentityZone(this.uaaClient, identityZoneName, subdomainName)) - .then(requestCreateIdentityProvider(this.uaaClient, identityZoneName, name)) - .flatMap(response -> this.uaaClient.identityProviders() - .get(GetIdentityProviderRequest.builder() - .identityProviderId(response.getId()) - .identityZoneId(identityZoneName) - .build())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + requestCreateIdentityZone( + this.uaaClient, identityZoneName, subdomainName)) + .then(requestCreateIdentityProvider(this.uaaClient, identityZoneName, name)) + .flatMap( + response -> + this.uaaClient + .identityProviders() + .get( + GetIdentityProviderRequest.builder() + .identityProviderId(response.getId()) + .identityZoneId(identityZoneName) + .build())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -224,18 +283,24 @@ public void list() { String subdomainName = this.nameFactory.getDomainName(); this.userId - .flatMap(userId -> requestCreateIdentityZone(this.uaaClient, identityZoneName, subdomainName)) - .then(requestCreateIdentityProvider(this.uaaClient, identityZoneName, name)) - .then(this.uaaClient.identityProviders() - .list(ListIdentityProvidersRequest.builder() - .identityZoneId(identityZoneName) - .build())) - .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) - .filter(provider -> OAUTH2.equals(provider.getType())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + requestCreateIdentityZone( + this.uaaClient, identityZoneName, subdomainName)) + .then(requestCreateIdentityProvider(this.uaaClient, identityZoneName, name)) + .then( + this.uaaClient + .identityProviders() + .list( + ListIdentityProvidersRequest.builder() + .identityZoneId(identityZoneName) + .build())) + .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) + .filter(provider -> OAUTH2.equals(provider.getType())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -246,71 +311,90 @@ public void update() { String subdomainName = this.nameFactory.getDomainName(); this.userId - .flatMap(userId -> requestCreateIdentityZone(this.uaaClient, identityZoneName, subdomainName)) - .then(requestCreateIdentityProvider(this.uaaClient, identityZoneName, oldName)) - .flatMap(response -> this.uaaClient.identityProviders() - .update(UpdateIdentityProviderRequest.builder() - .configuration(OAuth2Configuration.builder() - .addShadowUserOnLogin(true) - .authUrl("http://auth.url") - .relyingPartyId("uaa") - .relyingPartySecret("secret") - .showLinkText(false) - .skipSslVerification(false) - .tokenKey("token-key") - .tokenUrl("http://token.url") - .build()) - .identityProviderId(response.getId()) - .identityZoneId(identityZoneName) - .name(newName) - .originKey("oauth2.0") - .type(OAUTH2) - .version(1) - .build())) - .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) - .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) - .filter(provider -> newName.equals(provider.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + requestCreateIdentityZone( + this.uaaClient, identityZoneName, subdomainName)) + .then(requestCreateIdentityProvider(this.uaaClient, identityZoneName, oldName)) + .flatMap( + response -> + this.uaaClient + .identityProviders() + .update( + UpdateIdentityProviderRequest.builder() + .configuration( + OAuth2Configuration.builder() + .addShadowUserOnLogin(true) + .authUrl("http://auth.url") + .relyingPartyId("uaa") + .relyingPartySecret( + "secret") + .showLinkText(false) + .skipSslVerification(false) + .tokenKey("token-key") + .tokenUrl( + "http://token.url") + .build()) + .identityProviderId(response.getId()) + .identityZoneId(identityZoneName) + .name(newName) + .originKey("oauth2.0") + .type(OAUTH2) + .version(1) + .build())) + .then(requestListIdentityProviders(this.uaaClient, identityZoneName)) + .flatMapIterable(ListIdentityProvidersResponse::getIdentityProviders) + .filter(provider -> newName.equals(provider.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono requestCreateIdentityProvider(UaaClient uaaClient, String identityZoneName, String name) { - return uaaClient.identityProviders() - .create(CreateIdentityProviderRequest.builder() - .active(true) - .configuration(OAuth2Configuration.builder() - .addShadowUserOnLogin(true) - .authUrl("http://auth.url") - .relyingPartyId("uaa") - .relyingPartySecret("secret") - .showLinkText(false) - .skipSslVerification(false) - .tokenKey("token-key") - .tokenUrl("http://token.url") - .build()) - .identityZoneId(identityZoneName) - .name(name) - .originKey("oauth2.0") - .type(OAUTH2) - .build()); + private static Mono requestCreateIdentityProvider( + UaaClient uaaClient, String identityZoneName, String name) { + return uaaClient + .identityProviders() + .create( + CreateIdentityProviderRequest.builder() + .active(true) + .configuration( + OAuth2Configuration.builder() + .addShadowUserOnLogin(true) + .authUrl("http://auth.url") + .relyingPartyId("uaa") + .relyingPartySecret("secret") + .showLinkText(false) + .skipSslVerification(false) + .tokenKey("token-key") + .tokenUrl("http://token.url") + .build()) + .identityZoneId(identityZoneName) + .name(name) + .originKey("oauth2.0") + .type(OAUTH2) + .build()); } - private static Mono requestCreateIdentityZone(UaaClient uaaClient, String identityZoneName, String subdomainName) { - return uaaClient.identityZones() - .create(CreateIdentityZoneRequest.builder() - .identityZoneId(identityZoneName) - .name(identityZoneName) - .subdomain(subdomainName) - .build()); + private static Mono requestCreateIdentityZone( + UaaClient uaaClient, String identityZoneName, String subdomainName) { + return uaaClient + .identityZones() + .create( + CreateIdentityZoneRequest.builder() + .identityZoneId(identityZoneName) + .name(identityZoneName) + .subdomain(subdomainName) + .build()); } - private static Mono requestListIdentityProviders(UaaClient uaaClient, String identityZoneName) { - return uaaClient.identityProviders() - .list(ListIdentityProvidersRequest.builder() - .identityZoneId(identityZoneName) - .build()); + private static Mono requestListIdentityProviders( + UaaClient uaaClient, String identityZoneName) { + return uaaClient + .identityProviders() + .list( + ListIdentityProvidersRequest.builder() + .identityZoneId(identityZoneName) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/uaa/IdentityZonesTest.java b/integration-test/src/test/java/org/cloudfoundry/uaa/IdentityZonesTest.java index 76a4f9d52f6..5837481254f 100644 --- a/integration-test/src/test/java/org/cloudfoundry/uaa/IdentityZonesTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/uaa/IdentityZonesTest.java @@ -16,6 +16,7 @@ package org.cloudfoundry.uaa; +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.uaa.identityzones.CreateIdentityZoneRequest; import org.cloudfoundry.uaa.identityzones.CreateIdentityZoneResponse; @@ -25,34 +26,34 @@ import org.cloudfoundry.uaa.identityzones.ListIdentityZonesRequest; import org.cloudfoundry.uaa.identityzones.ListIdentityZonesResponse; import org.cloudfoundry.uaa.identityzones.UpdateIdentityZoneRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - public final class IdentityZonesTest extends AbstractIntegrationTest { - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; @Test public void create() { String identityZoneName = this.nameFactory.getIdentityZoneName(); String subdomainName = this.nameFactory.getDomainName(); - this.uaaClient.identityZones() - .create(CreateIdentityZoneRequest.builder() - .subdomain(subdomainName) - .name(identityZoneName) - .build()) - .then(requestListIdentityZones(this.uaaClient)) - .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) - .filter(resource -> identityZoneName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .identityZones() + .create( + CreateIdentityZoneRequest.builder() + .subdomain(subdomainName) + .name(identityZoneName) + .build()) + .then(requestListIdentityZones(this.uaaClient)) + .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) + .filter(resource -> identityZoneName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -61,16 +62,20 @@ public void delete() { String subdomainName = this.nameFactory.getDomainName(); getIdentityZoneId(this.uaaClient, identityZoneName, subdomainName) - .flatMap(identityZoneId -> this.uaaClient.identityZones() - .delete(DeleteIdentityZoneRequest.builder() - .identityZoneId(identityZoneId) - .build())) - .then(requestListIdentityZones(this.uaaClient)) - .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) - .filter(resource -> identityZoneName.equals(resource.getName())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + identityZoneId -> + this.uaaClient + .identityZones() + .delete( + DeleteIdentityZoneRequest.builder() + .identityZoneId(identityZoneId) + .build())) + .then(requestListIdentityZones(this.uaaClient)) + .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) + .filter(resource -> identityZoneName.equals(resource.getName())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -79,15 +84,19 @@ public void get() { String subdomainName = this.nameFactory.getDomainName(); getIdentityZoneId(this.uaaClient, identityZoneName, subdomainName) - .flatMap(identityZoneId -> this.uaaClient.identityZones() - .get(GetIdentityZoneRequest.builder() - .identityZoneId(identityZoneId) - .build())) - .map(GetIdentityZoneResponse::getName) - .as(StepVerifier::create) - .expectNext(identityZoneName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + identityZoneId -> + this.uaaClient + .identityZones() + .get( + GetIdentityZoneRequest.builder() + .identityZoneId(identityZoneId) + .build())) + .map(GetIdentityZoneResponse::getName) + .as(StepVerifier::create) + .expectNext(identityZoneName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -96,15 +105,16 @@ public void list() { String subdomainName = this.nameFactory.getDomainName(); requestCreateIdentityZone(this.uaaClient, identityZoneName, subdomainName) - .then(this.uaaClient.identityZones() - .list(ListIdentityZonesRequest.builder() - .build())) - .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) - .filter(resource -> identityZoneName.equals(resource.getName())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .then( + this.uaaClient + .identityZones() + .list(ListIdentityZonesRequest.builder().build())) + .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) + .filter(resource -> identityZoneName.equals(resource.getName())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -114,38 +124,43 @@ public void update() { String newSubdomainName = this.nameFactory.getDomainName(); getIdentityZoneId(this.uaaClient, identityZoneName, baseSubdomainName) - .flatMap(identityZoneId -> this.uaaClient.identityZones() - .update(UpdateIdentityZoneRequest.builder() - .identityZoneId(identityZoneId) - .name(identityZoneName) - .subdomain(newSubdomainName) - .build())) - .then(requestListIdentityZones(this.uaaClient)) - .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) - .filter(resource -> newSubdomainName.equals(resource.getSubdomain())) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + identityZoneId -> + this.uaaClient + .identityZones() + .update( + UpdateIdentityZoneRequest.builder() + .identityZoneId(identityZoneId) + .name(identityZoneName) + .subdomain(newSubdomainName) + .build())) + .then(requestListIdentityZones(this.uaaClient)) + .flatMapIterable(ListIdentityZonesResponse::getIdentityZones) + .filter(resource -> newSubdomainName.equals(resource.getSubdomain())) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono getIdentityZoneId(UaaClient uaaClient, String identityZoneName, String subdomainName) { + private static Mono getIdentityZoneId( + UaaClient uaaClient, String identityZoneName, String subdomainName) { return requestCreateIdentityZone(uaaClient, identityZoneName, subdomainName) - .map(CreateIdentityZoneResponse::getId); + .map(CreateIdentityZoneResponse::getId); } - private static Mono requestCreateIdentityZone(UaaClient uaaClient, String identityZoneName, String subdomainName) { - return uaaClient.identityZones() - .create(CreateIdentityZoneRequest.builder() - .subdomain(subdomainName) - .name(identityZoneName) - .build()); + private static Mono requestCreateIdentityZone( + UaaClient uaaClient, String identityZoneName, String subdomainName) { + return uaaClient + .identityZones() + .create( + CreateIdentityZoneRequest.builder() + .subdomain(subdomainName) + .name(identityZoneName) + .build()); } private static Mono requestListIdentityZones(UaaClient uaaClient) { - return uaaClient.identityZones() - .list(ListIdentityZonesRequest.builder() - .build()); + return uaaClient.identityZones().list(ListIdentityZonesRequest.builder().build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/uaa/ServerInformationTest.java b/integration-test/src/test/java/org/cloudfoundry/uaa/ServerInformationTest.java index b0f8b6e61dd..d29256b2111 100644 --- a/integration-test/src/test/java/org/cloudfoundry/uaa/ServerInformationTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/uaa/ServerInformationTest.java @@ -16,95 +16,112 @@ package org.cloudfoundry.uaa; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; +import java.util.function.Consumer; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.uaa.serverinformation.AutoLoginRequest; import org.cloudfoundry.uaa.serverinformation.GetAutoLoginAuthenticationCodeRequest; import org.cloudfoundry.uaa.serverinformation.GetAutoLoginAuthenticationCodeResponse; import org.cloudfoundry.uaa.serverinformation.GetInfoRequest; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; -import java.util.function.Consumer; - -import static org.assertj.core.api.Assertions.assertThat; - public final class ServerInformationTest extends AbstractIntegrationTest { - @Autowired - private String clientId; + @Autowired private String clientId; - @Autowired - private String clientSecret; + @Autowired private String clientSecret; - @Autowired - private String password; + @Autowired private String password; - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; - @Autowired - private String username; + @Autowired private String username; @Test public void autoLogin() { - getAuthenticationCode(this.uaaClient, this.clientId, this.clientSecret, this.password, this.username) - .flatMap(code -> this.uaaClient.serverInformation() - .autoLogin(AutoLoginRequest.builder() - .clientId(this.clientId) - .code(code) - .build())) - .as(StepVerifier::create) - .expectComplete() - .verify(Duration.ofMinutes(5)); + getAuthenticationCode( + this.uaaClient, + this.clientId, + this.clientSecret, + this.password, + this.username) + .flatMap( + code -> + this.uaaClient + .serverInformation() + .autoLogin( + AutoLoginRequest.builder() + .clientId(this.clientId) + .code(code) + .build())) + .as(StepVerifier::create) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getAutoLoginAuthenticationCode() { - this.uaaClient.serverInformation() - .getAuthenticationCode(GetAutoLoginAuthenticationCodeRequest.builder() - .clientId(this.clientId) - .clientSecret(this.clientSecret) - .password(this.password) - .username(this.username) - .build()) - .map(GetAutoLoginAuthenticationCodeResponse::getPath) - .as(StepVerifier::create) - .expectNext("/oauth/authorize") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .serverInformation() + .getAuthenticationCode( + GetAutoLoginAuthenticationCodeRequest.builder() + .clientId(this.clientId) + .clientSecret(this.clientSecret) + .password(this.password) + .username(this.username) + .build()) + .map(GetAutoLoginAuthenticationCodeResponse::getPath) + .as(StepVerifier::create) + .expectNext("/oauth/authorize") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getInfo() { - this.uaaClient.serverInformation() - .getInfo(GetInfoRequest.builder() - .build()) - .map(response -> response.getLinks().getPassword()) - .as(StepVerifier::create) - .consumeNextWith(endsWithExpectation("password")) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .serverInformation() + .getInfo(GetInfoRequest.builder().build()) + .map(response -> response.getLinks().getPassword()) + .as(StepVerifier::create) + .consumeNextWith(endsWithExpectation("password")) + .expectComplete() + .verify(Duration.ofMinutes(5)); } private static Consumer endsWithExpectation(String suffix) { return actual -> assertThat(actual).endsWith(suffix); } - private static Mono getAuthenticationCode(UaaClient uaaClient, String clientId, String clientSecret, String password, String username) { + private static Mono getAuthenticationCode( + UaaClient uaaClient, + String clientId, + String clientSecret, + String password, + String username) { return requestAuthenticationCode(uaaClient, clientId, clientSecret, password, username) - .map(GetAutoLoginAuthenticationCodeResponse::getCode); + .map(GetAutoLoginAuthenticationCodeResponse::getCode); } - private static Mono requestAuthenticationCode(UaaClient uaaClient, String clientId, String clientSecret, String password, String username) { - return uaaClient.serverInformation() - .getAuthenticationCode(GetAutoLoginAuthenticationCodeRequest.builder() - .clientId(clientId) - .clientSecret(clientSecret) - .password(password) - .username(username) - .build()); + private static Mono requestAuthenticationCode( + UaaClient uaaClient, + String clientId, + String clientSecret, + String password, + String username) { + return uaaClient + .serverInformation() + .getAuthenticationCode( + GetAutoLoginAuthenticationCodeRequest.builder() + .clientId(clientId) + .clientSecret(clientSecret) + .password(password) + .username(username) + .build()); } - -} \ No newline at end of file +} diff --git a/integration-test/src/test/java/org/cloudfoundry/uaa/TokensTest.java b/integration-test/src/test/java/org/cloudfoundry/uaa/TokensTest.java index 76fd5e1afd1..40b02850f02 100644 --- a/integration-test/src/test/java/org/cloudfoundry/uaa/TokensTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/uaa/TokensTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.uaa; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.reactor.ConnectionContext; import org.cloudfoundry.reactor.TokenProvider; @@ -38,204 +41,245 @@ import org.cloudfoundry.uaa.tokens.RefreshTokenResponse; import org.cloudfoundry.uaa.tokens.TokenFormat; import org.cloudfoundry.uaa.tokens.TokenKey; -import org.junit.Ignore; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class TokensTest extends AbstractIntegrationTest { - @Autowired - private String clientId; + @Autowired private String clientId; - @Autowired - private String clientSecret; + @Autowired private String clientSecret; - @Autowired - private ConnectionContext connectionContext; + @Autowired private ConnectionContext connectionContext; - @Autowired - private String password; + @Autowired private String password; - @Autowired - private TokenProvider tokenProvider; + @Autowired private TokenProvider tokenProvider; - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; - @Autowired - private String username; + @Autowired private String username; @Test public void checkTokenNotAuthorized() { - this.tokenProvider.getToken(this.connectionContext) - .flatMap(token -> this.uaaClient.tokens() - .check(CheckTokenRequest.builder() - .token(token) - .clientId(this.clientId) - .clientSecret(this.clientSecret) - .scopes("password.write", "scim.userids") - .build())) - .as(StepVerifier::create) - .consumeErrorWith(t -> assertThat(t).isInstanceOf(UaaException.class).hasMessage("access_denied: Access is denied")) - .verify(Duration.ofMinutes(5)); + this.tokenProvider + .getToken(this.connectionContext) + .flatMap( + token -> + this.uaaClient + .tokens() + .check( + CheckTokenRequest.builder() + .token(token) + .clientId(this.clientId) + .clientSecret(this.clientSecret) + .scopes("password.write", "scim.userids") + .build())) + .as(StepVerifier::create) + .consumeErrorWith( + t -> + assertThat(t) + .isInstanceOf(UaaException.class) + .hasMessage("access_denied: Access is denied")) + .verify(Duration.ofMinutes(5)); } @Test public void getTokenByAuthorizationCode() { requestGetAuthorizationCode(this.uaaClient, this.clientId) - .flatMap(authorizationCode -> this.uaaClient.tokens() - .getByAuthorizationCode(GetTokenByAuthorizationCodeRequest.builder() - .authorizationCode(authorizationCode) - .clientId(this.clientId) - .clientSecret(this.clientSecret) - .build())) - .map(GetTokenByAuthorizationCodeResponse::getTokenType) - .as(StepVerifier::create) - .expectNext("bearer") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + authorizationCode -> + this.uaaClient + .tokens() + .getByAuthorizationCode( + GetTokenByAuthorizationCodeRequest.builder() + .authorizationCode(authorizationCode) + .clientId(this.clientId) + .clientSecret(this.clientSecret) + .build())) + .map(GetTokenByAuthorizationCodeResponse::getTokenType) + .as(StepVerifier::create) + .expectNext("bearer") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getTokenByClientCredentials() { - this.uaaClient.tokens() - .getByClientCredentials(GetTokenByClientCredentialsRequest.builder() - .clientId(this.clientId) - .clientSecret(this.clientSecret) - .tokenFormat(TokenFormat.OPAQUE) - .build()) - .map(GetTokenByClientCredentialsResponse::getTokenType) - .as(StepVerifier::create) - .expectNext("bearer") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .tokens() + .getByClientCredentials( + GetTokenByClientCredentialsRequest.builder() + .clientId(this.clientId) + .clientSecret(this.clientSecret) + .tokenFormat(TokenFormat.OPAQUE) + .build()) + .map(GetTokenByClientCredentialsResponse::getTokenType) + .as(StepVerifier::create) + .expectNext("bearer") + .expectComplete() + .verify(Duration.ofMinutes(5)); } - //TODO: Ready to Implement - Await https://github.com/cloudfoundry/cf-java-client/issues/862 to get passcode - @Ignore("Ready to Implement - Await https://github.com/cloudfoundry/cf-java-client/issues/862 to get passcode") + // TODO: Ready to Implement - Await https://github.com/cloudfoundry/cf-java-client/issues/862 to + // get passcode + @Disabled( + "Ready to Implement - Await https://github.com/cloudfoundry/cf-java-client/issues/862" + + " to get passcode") @Test public void getTokenByOneTimePasscode() { - this.uaaClient.tokens() - .getByOneTimePasscode(GetTokenByOneTimePasscodeRequest.builder() - .passcode("some passcode") - .clientId(this.clientId) - .clientSecret(this.clientSecret) - .tokenFormat(TokenFormat.OPAQUE) - .build()) - .map(GetTokenByOneTimePasscodeResponse::getAccessToken) - .as(StepVerifier::create) - .expectNext("bearer") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .tokens() + .getByOneTimePasscode( + GetTokenByOneTimePasscodeRequest.builder() + .passcode("some passcode") + .clientId(this.clientId) + .clientSecret(this.clientSecret) + .tokenFormat(TokenFormat.OPAQUE) + .build()) + .map(GetTokenByOneTimePasscodeResponse::getAccessToken) + .as(StepVerifier::create) + .expectNext("bearer") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getTokenByOpenId() { requestGetAuthorizationCode(this.uaaClient, this.clientId) - .flatMap(authorizationCode -> this.uaaClient.tokens() - .getByOpenId(GetTokenByOpenIdRequest.builder() - .authorizationCode(authorizationCode) - .clientId(this.clientId) - .clientSecret(this.clientSecret) - .tokenFormat(TokenFormat.OPAQUE) - .build())) - .map(GetTokenByOpenIdResponse::getTokenType) - .as(StepVerifier::create) - .expectNext("bearer") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + authorizationCode -> + this.uaaClient + .tokens() + .getByOpenId( + GetTokenByOpenIdRequest.builder() + .authorizationCode(authorizationCode) + .clientId(this.clientId) + .clientSecret(this.clientSecret) + .tokenFormat(TokenFormat.OPAQUE) + .build())) + .map(GetTokenByOpenIdResponse::getTokenType) + .as(StepVerifier::create) + .expectNext("bearer") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getTokenByPassword() { - this.uaaClient.tokens() - .getByPassword(GetTokenByPasswordRequest.builder() - .clientId(this.clientId) - .clientSecret(this.clientSecret) - .password(this.password) - .tokenFormat(TokenFormat.OPAQUE) - .username(this.username) - .build()) - .map(GetTokenByPasswordResponse::getTokenType) - .as(StepVerifier::create) - .expectNext("bearer") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .tokens() + .getByPassword( + GetTokenByPasswordRequest.builder() + .clientId(this.clientId) + .clientSecret(this.clientSecret) + .password(this.password) + .tokenFormat(TokenFormat.OPAQUE) + .username(this.username) + .build()) + .map(GetTokenByPasswordResponse::getTokenType) + .as(StepVerifier::create) + .expectNext("bearer") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void getTokenKey() { - this.uaaClient.tokens() - .getKey(GetTokenKeyRequest.builder() - .build()) - .as(StepVerifier::create) - .expectNextCount(1) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .tokens() + .getKey(GetTokenKeyRequest.builder().build()) + .as(StepVerifier::create) + .expectNextCount(1) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void listTokenKeys() { - this.uaaClient.tokens() - .getKey(GetTokenKeyRequest.builder() - .build()) - .flatMap(getKey -> Mono.zip( - this.uaaClient.tokens() - .listKeys(ListTokenKeysRequest.builder() - .build()) - .flatMapMany(response -> Flux.fromIterable(response.getKeys())) - .filter(tokenKey -> getKey.getValue().equals(tokenKey.getValue())) - .single() - .map(TokenKey::getId), - Mono.just(getKey) - .map(GetTokenKeyResponse::getId) - )) - .as(StepVerifier::create) - .consumeNextWith(tupleEquality()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .tokens() + .getKey(GetTokenKeyRequest.builder().build()) + .flatMap( + getKey -> + Mono.zip( + this.uaaClient + .tokens() + .listKeys(ListTokenKeysRequest.builder().build()) + .flatMapMany( + response -> + Flux.fromIterable( + response.getKeys())) + .filter( + tokenKey -> + getKey.getValue() + .equals( + tokenKey + .getValue())) + .single() + .map(TokenKey::getId), + Mono.just(getKey).map(GetTokenKeyResponse::getId))) + .as(StepVerifier::create) + .consumeNextWith(tupleEquality()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void refreshToken() { - getRequestToken(this.uaaClient, this.clientId, this.clientSecret, this.password, this.username) - .flatMap(refreshToken -> this.uaaClient.tokens() - .refresh(RefreshTokenRequest.builder() - .tokenFormat(TokenFormat.OPAQUE) - .clientId(this.clientId) - .clientSecret(this.clientSecret) - .refreshToken(refreshToken) - .build())) - .map(RefreshTokenResponse::getTokenType) - .as(StepVerifier::create) - .expectNext("bearer") - .expectComplete() - .verify(Duration.ofMinutes(5)); + getRequestToken( + this.uaaClient, + this.clientId, + this.clientSecret, + this.password, + this.username) + .flatMap( + refreshToken -> + this.uaaClient + .tokens() + .refresh( + RefreshTokenRequest.builder() + .tokenFormat(TokenFormat.OPAQUE) + .clientId(this.clientId) + .clientSecret(this.clientSecret) + .refreshToken(refreshToken) + .build())) + .map(RefreshTokenResponse::getTokenType) + .as(StepVerifier::create) + .expectNext("bearer") + .expectComplete() + .verify(Duration.ofMinutes(5)); } - private static Mono getRequestToken(UaaClient uaaClient, String clientId, String clientSecret, String password, String username) { - return uaaClient.tokens() - .getByPassword(GetTokenByPasswordRequest.builder() - .clientId(clientId) - .clientSecret(clientSecret) - .password(password) - .tokenFormat(TokenFormat.OPAQUE) - .username(username) - .build()) - .map(GetTokenByPasswordResponse::getRefreshToken); + private static Mono getRequestToken( + UaaClient uaaClient, + String clientId, + String clientSecret, + String password, + String username) { + return uaaClient + .tokens() + .getByPassword( + GetTokenByPasswordRequest.builder() + .clientId(clientId) + .clientSecret(clientSecret) + .password(password) + .tokenFormat(TokenFormat.OPAQUE) + .username(username) + .build()) + .map(GetTokenByPasswordResponse::getRefreshToken); } private static Mono requestGetAuthorizationCode(UaaClient uaaClient, String clientId) { - return uaaClient.authorizations() - .authorizationCodeGrantApi(AuthorizeByAuthorizationCodeGrantApiRequest.builder() - .clientId(clientId) - .build()); + return uaaClient + .authorizations() + .authorizationCodeGrantApi( + AuthorizeByAuthorizationCodeGrantApiRequest.builder() + .clientId(clientId) + .build()); } - } diff --git a/integration-test/src/test/java/org/cloudfoundry/uaa/UsersTest.java b/integration-test/src/test/java/org/cloudfoundry/uaa/UsersTest.java index 1eac301ac8c..0413b81b6fd 100644 --- a/integration-test/src/test/java/org/cloudfoundry/uaa/UsersTest.java +++ b/integration-test/src/test/java/org/cloudfoundry/uaa/UsersTest.java @@ -16,6 +16,9 @@ package org.cloudfoundry.uaa; +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; import org.cloudfoundry.AbstractIntegrationTest; import org.cloudfoundry.CloudFoundryVersion; import org.cloudfoundry.IfCloudFoundryVersion; @@ -43,66 +46,68 @@ import org.cloudfoundry.uaa.users.UserInfoResponse; import org.cloudfoundry.uaa.users.VerifyUserRequest; import org.cloudfoundry.uaa.users.VerifyUserResponse; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.test.StepVerifier; -import java.time.Duration; - -import static org.assertj.core.api.Assertions.assertThat; - public final class UsersTest extends AbstractIntegrationTest { - @Autowired - private UaaClient uaaClient; + @Autowired private UaaClient uaaClient; @Test public void changePassword() { String userName = this.nameFactory.getUserName(); requestCreateUser(this.uaaClient, userName) - .map(CreateUserResponse::getId) - .flatMap(userId -> this.uaaClient.users() - .changePassword(ChangeUserPasswordRequest.builder() - .oldPassword("test-password") - .password("test-new-password") - .userId(userId) - .build())) - .as(StepVerifier::create) - .consumeNextWith(response -> { - assertThat(response.getMessage()).isEqualTo("password updated"); - assertThat(response.getStatus()).isEqualTo("ok"); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .map(CreateUserResponse::getId) + .flatMap( + userId -> + this.uaaClient + .users() + .changePassword( + ChangeUserPasswordRequest.builder() + .oldPassword("test-password") + .password("test-new-password") + .userId(userId) + .build())) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + assertThat(response.getMessage()).isEqualTo("password updated"); + assertThat(response.getStatus()).isEqualTo("ok"); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void create() { String userName = this.nameFactory.getUserName(); - this.uaaClient.users() - .create(CreateUserRequest.builder() - .email(Email.builder() - .value("test-email") - .primary(true) - .build()) - .externalId("test-external-id") - .name(Name.builder() - .familyName("test-family-name") - .givenName("test-given-name") - .build()) - .password("test-password") - .userName(userName) - .build()) - .as(StepVerifier::create) - .consumeNextWith(response -> { - assertThat(response.getExternalId()).isEqualTo("test-external-id"); - assertThat(response.getUserName()).isEqualTo(userName); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .users() + .create( + CreateUserRequest.builder() + .email(Email.builder().value("test-email").primary(true).build()) + .externalId("test-external-id") + .name( + Name.builder() + .familyName("test-family-name") + .givenName("test-given-name") + .build()) + .password("test-password") + .userName(userName) + .build()) + .as(StepVerifier::create) + .consumeNextWith( + response -> { + assertThat(response.getExternalId()).isEqualTo("test-external-id"); + assertThat(response.getUserName()).isEqualTo(userName); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -110,17 +115,18 @@ public void delete() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.users() - .delete(DeleteUserRequest.builder() - .userId(userId) - .build())) - .map(DeleteUserResponse::getId) - .flatMap(userId -> requestListUsers(this.uaaClient, userId)) - .map(ListUsersResponse::getTotalResults) - .as(StepVerifier::create) - .expectNext(0) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + this.uaaClient + .users() + .delete(DeleteUserRequest.builder().userId(userId).build())) + .map(DeleteUserResponse::getId) + .flatMap(userId -> requestListUsers(this.uaaClient, userId)) + .map(ListUsersResponse::getTotalResults) + .as(StepVerifier::create) + .expectNext(0) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(greaterThanOrEqualTo = CloudFoundryVersion.PCF_1_10) @@ -129,17 +135,19 @@ public void expirePassword() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.users() - .expirePassword(ExpirePasswordRequest.builder() - .passwordChangeRequired(true) - .userId(userId) - .build())) - .as(StepVerifier::create) - .expectNext(ExpirePasswordResponse.builder() - .passwordChangeRequired(true) - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + this.uaaClient + .users() + .expirePassword( + ExpirePasswordRequest.builder() + .passwordChangeRequired(true) + .userId(userId) + .build())) + .as(StepVerifier::create) + .expectNext(ExpirePasswordResponse.builder().passwordChangeRequired(true).build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @IfCloudFoundryVersion(equalTo = CloudFoundryVersion.PCF_1_9) @@ -148,16 +156,19 @@ public void expirePassword19() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.users() - .expirePassword(ExpirePasswordRequest.builder() - .passwordChangeRequired(true) - .userId(userId) - .build())) - .as(StepVerifier::create) - .expectNext(ExpirePasswordResponse.builder() - .build()) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + this.uaaClient + .users() + .expirePassword( + ExpirePasswordRequest.builder() + .passwordChangeRequired(true) + .userId(userId) + .build())) + .as(StepVerifier::create) + .expectNext(ExpirePasswordResponse.builder().build()) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -165,34 +176,41 @@ public void getVerificationLink() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.users() - .getVerificationLink(GetUserVerificationLinkRequest.builder() - .redirectUri("test-redirect-uri") - .userId(userId) - .build())) - .map(GetUserVerificationLinkResponse::getVerifyLink) - .as(StepVerifier::create) - .consumeNextWith(location -> assertThat(location).contains("/verify_user?code=")) - .expectComplete(); + .flatMap( + userId -> + this.uaaClient + .users() + .getVerificationLink( + GetUserVerificationLinkRequest.builder() + .redirectUri("test-redirect-uri") + .userId(userId) + .build())) + .map(GetUserVerificationLinkResponse::getVerifyLink) + .as(StepVerifier::create) + .consumeNextWith(location -> assertThat(location).contains("/verify_user?code=")) + .expectComplete(); } @Test public void invite() { - this.uaaClient.users() - .invite(InviteUsersRequest.builder() - .email("test@email.address") - .redirectUri("test-redirect-uri") - .build()) - .flatMapIterable(InviteUsersResponse::getNewInvites) - .single() - .as(StepVerifier::create) - .consumeNextWith(invite -> { - assertThat(invite.getEmail()).isEqualTo("test@email.address"); - assertThat(invite.getErrorCode()).isNull(); - assertThat(invite.getSuccess()).isTrue(); - }) - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .users() + .invite( + InviteUsersRequest.builder() + .email("test@email.address") + .redirectUri("test-redirect-uri") + .build()) + .flatMapIterable(InviteUsersResponse::getNewInvites) + .single() + .as(StepVerifier::create) + .consumeNextWith( + invite -> { + assertThat(invite.getEmail()).isEqualTo("test@email.address"); + assertThat(invite.getErrorCode()).isNull(); + assertThat(invite.getSuccess()).isTrue(); + }) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -200,16 +218,22 @@ public void list() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.users() - .list(ListUsersRequest.builder() - .filter(String.format("id eq \"%s\"", userId)) - .build())) - .flatMapIterable(ListUsersResponse::getResources) - .map(User::getUserName) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + this.uaaClient + .users() + .list( + ListUsersRequest.builder() + .filter( + String.format( + "id eq \"%s\"", userId)) + .build())) + .flatMapIterable(ListUsersResponse::getResources) + .map(User::getUserName) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -217,16 +241,22 @@ public void lookup() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.users() - .lookup(LookupUserIdsRequest.builder() - .filter(String.format("id eq \"%s\"", userId)) - .build())) - .flatMapIterable(LookupUserIdsResponse::getResources) - .map(UserId::getUserName) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + this.uaaClient + .users() + .lookup( + LookupUserIdsRequest.builder() + .filter( + String.format( + "id eq \"%s\"", userId)) + .build())) + .flatMapIterable(LookupUserIdsResponse::getResources) + .map(UserId::getUserName) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -234,38 +264,46 @@ public void update() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.users() - .update(UpdateUserRequest.builder() - .email(Email.builder() - .value("test-email-2") - .primary(true) - .build()) - .id(userId) - .name(Name.builder() - .familyName("test-family-name") - .givenName("test-given-name") - .build()) - .userName(userName) - .version("0") - .build())) - .flatMapMany(response -> Flux.fromIterable(response.getEmail()) - .map(Email::getValue)) - .as(StepVerifier::create) - .expectNext("test-email-2") - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + this.uaaClient + .users() + .update( + UpdateUserRequest.builder() + .email( + Email.builder() + .value("test-email-2") + .primary(true) + .build()) + .id(userId) + .name( + Name.builder() + .familyName( + "test-family-name") + .givenName( + "test-given-name") + .build()) + .userName(userName) + .version("0") + .build())) + .flatMapMany( + response -> Flux.fromIterable(response.getEmail()).map(Email::getValue)) + .as(StepVerifier::create) + .expectNext("test-email-2") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test public void userInfo() { - this.uaaClient.users() - .userInfo(UserInfoRequest.builder() - .build()) - .map(UserInfoResponse::getName) - .as(StepVerifier::create) - .expectNext("Test User") - .expectComplete() - .verify(Duration.ofMinutes(5)); + this.uaaClient + .users() + .userInfo(UserInfoRequest.builder().build()) + .map(UserInfoResponse::getName) + .as(StepVerifier::create) + .expectNext("Test User") + .expectComplete() + .verify(Duration.ofMinutes(5)); } @Test @@ -273,44 +311,46 @@ public void verifyUser() { String userName = this.nameFactory.getUserName(); createUserId(this.uaaClient, userName) - .flatMap(userId -> this.uaaClient.users() - .verify(VerifyUserRequest.builder() - .userId(userId) - .build())) - .map(VerifyUserResponse::getUserName) - .as(StepVerifier::create) - .expectNext(userName) - .expectComplete() - .verify(Duration.ofMinutes(5)); + .flatMap( + userId -> + this.uaaClient + .users() + .verify(VerifyUserRequest.builder().userId(userId).build())) + .map(VerifyUserResponse::getUserName) + .as(StepVerifier::create) + .expectNext(userName) + .expectComplete() + .verify(Duration.ofMinutes(5)); } private static Mono createUserId(UaaClient uaaClient, String userName) { - return requestCreateUser(uaaClient, userName) - .map(CreateUserResponse::getId); + return requestCreateUser(uaaClient, userName).map(CreateUserResponse::getId); } - private static Mono requestCreateUser(UaaClient uaaClient, String userName) { - return uaaClient.users() - .create(CreateUserRequest.builder() - .email(Email.builder() - .value("test-email") - .primary(true) - .build()) - .name(Name.builder() - .familyName("test-family-name") - .givenName("test-given-name") - .build()) - .password("test-password") - .verified(false) - .userName(userName) - .build()); + private static Mono requestCreateUser( + UaaClient uaaClient, String userName) { + return uaaClient + .users() + .create( + CreateUserRequest.builder() + .email(Email.builder().value("test-email").primary(true).build()) + .name( + Name.builder() + .familyName("test-family-name") + .givenName("test-given-name") + .build()) + .password("test-password") + .verified(false) + .userName(userName) + .build()); } private static Mono requestListUsers(UaaClient uaaClient, String userId) { - return uaaClient.users() - .list(ListUsersRequest.builder() - .filter(String.format("id eq \"%s\"", userId)) - .build()); + return uaaClient + .users() + .list( + ListUsersRequest.builder() + .filter(String.format("id eq \"%s\"", userId)) + .build()); } - }