diff --git a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java index 5aed533645..ff92d1d387 100644 --- a/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java +++ b/integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java @@ -34,6 +34,7 @@ import java.time.Duration; import java.util.Arrays; import java.util.Collections; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Random; @@ -44,6 +45,8 @@ import org.cloudfoundry.client.v2.organizations.CreateOrganizationRequest; import org.cloudfoundry.client.v2.spaces.CreateSpaceRequest; import org.cloudfoundry.client.v2.stacks.ListStacksRequest; +import org.cloudfoundry.client.v2.stacks.StackEntity; +import org.cloudfoundry.client.v2.stacks.StackResource; import org.cloudfoundry.client.v2.userprovidedserviceinstances.CreateUserProvidedServiceInstanceRequest; import org.cloudfoundry.doppler.DopplerClient; import org.cloudfoundry.logcache.v1.TestLogCacheEndpoints; @@ -527,16 +530,20 @@ 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())) + Mono stackId(CloudFoundryClient cloudFoundryClient, Mono stackName) { + return stackName + .flux() + .flatMap( + name -> + PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .stacks() + .list( + ListStacksRequest.builder() + .name(name) + .page(page) + .build()))) .single() .map(ResourceUtils::getId) .doOnSubscribe(s -> this.logger.debug(">> STACK ({}) <<", stackName)) @@ -545,9 +552,24 @@ Mono stackId(CloudFoundryClient cloudFoundryClient, String stackName) { .cache(); } - @Bean - String stackName() { - return "cflinuxfs3"; + /** + * Select the most recent stack available, matching {@code cflinuxfs*}, based + * on the stack number. + */ + @Bean(initMethod = "block") + @DependsOn("cloudFoundryCleaner") + Mono stackName(CloudFoundryClient cloudFoundryClient) { + return PaginationUtils.requestClientV2Resources( + page -> + cloudFoundryClient + .stacks() + .list(ListStacksRequest.builder().page(page).build())) + .map(StackResource::getEntity) + .map(StackEntity::getName) + .filter(s -> s.matches("^cflinuxfs\\d$")) + .sort(Comparator.reverseOrder()) + .single() + .cache(); } @Bean(initMethod = "block") 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 93b267adde..cbd3ac2d29 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 @@ -31,6 +31,7 @@ import org.cloudfoundry.util.JobUtils; import org.cloudfoundry.util.PaginationUtils; import org.cloudfoundry.util.ResourceUtils; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; @@ -41,7 +42,12 @@ public final class StacksTest extends AbstractIntegrationTest { @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired private String stackName; + private String stackName; + + @BeforeEach + void setUp(@Autowired Mono stackName) { + this.stackName = stackName.block(); + } @Test public void create() { @@ -54,7 +60,7 @@ public void create() { .description("Test stack description") .name(stackName) .build()) - .thenMany(requestListStacks(this.cloudFoundryClient, stackName)) + .thenMany(requestListStacks(stackName)) .map(response -> ResourceUtils.getEntity(response).getDescription()) .as(StepVerifier::create) .expectNext("Test stack description") @@ -122,7 +128,7 @@ public void deleteAsync() { @Test public void get() { - getStackId(this.cloudFoundryClient, this.stackName) + getStackId() .flatMap( stackId -> this.cloudFoundryClient @@ -137,7 +143,7 @@ public void get() { @Test public void list() { - getStackId(this.cloudFoundryClient, this.stackName) + getStackId() .flatMapMany( stackId -> PaginationUtils.requestClientV2Resources( @@ -161,15 +167,7 @@ public void list() { @Test public void listFilterByName() { - PaginationUtils.requestClientV2Resources( - page -> - this.cloudFoundryClient - .stacks() - .list( - ListStacksRequest.builder() - .name(this.stackName) - .page(page) - .build())) + this.requestListStacks(this.stackName) .map(resource -> resource.getEntity().getName()) .as(StepVerifier::create) .expectNext(this.stackName) @@ -182,9 +180,8 @@ private static Mono createStackId( return requestCreateStack(cloudFoundryClient, stackName).map(ResourceUtils::getId); } - private static Mono getStackId( - CloudFoundryClient cloudFoundryClient, String stackName) { - return requestListStacks(cloudFoundryClient, stackName).single().map(ResourceUtils::getId); + private Mono getStackId() { + return this.requestListStacks(this.stackName).single().map(ResourceUtils::getId); } private static Mono requestCreateStack( @@ -203,11 +200,10 @@ private static Mono requestGetStack( return cloudFoundryClient.stacks().get(GetStackRequest.builder().stackId(stackId).build()); } - private static Flux requestListStacks( - CloudFoundryClient cloudFoundryClient, String stackName) { + private Flux requestListStacks(String stackName) { return PaginationUtils.requestClientV2Resources( page -> - cloudFoundryClient + this.cloudFoundryClient .stacks() .list( ListStacksRequest.builder() 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 e8ef885c03..a6f1e733b5 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 @@ -248,7 +248,6 @@ private static Mono requestCreateBuildpack( .locked(false) .name(buildpackName) .position(3) - .stack("cflinuxfs3") .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 73f4493916..12d1564367 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 @@ -30,6 +30,7 @@ import org.cloudfoundry.client.v3.stacks.Stack; import org.cloudfoundry.client.v3.stacks.StackResource; import org.cloudfoundry.util.PaginationUtils; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import reactor.core.publisher.Flux; @@ -40,7 +41,12 @@ public final class StacksTest extends AbstractIntegrationTest { @Autowired private CloudFoundryClient cloudFoundryClient; - @Autowired private String stackName; + private String stackName; + + @BeforeEach + void setUp(@Autowired Mono stackName) { + this.stackName = stackName.block(); + } @Test public void create() { @@ -53,7 +59,7 @@ public void create() { .description("Test stack description") .name(stackName) .build()) - .thenMany(requestListStacks(this.cloudFoundryClient, stackName)) + .thenMany(requestListStacks(stackName)) .map(Stack::getDescription) .as(StepVerifier::create) .expectNext("Test stack description") @@ -88,7 +94,7 @@ public void delete() { @Test public void get() { - getStackId(this.cloudFoundryClient, this.stackName) + getStackId() .flatMap( stackId -> this.cloudFoundryClient @@ -103,7 +109,7 @@ public void get() { @Test public void list() { - getStackId(this.cloudFoundryClient, this.stackName) + getStackId() .flatMapMany( stackId -> PaginationUtils.requestClientV3Resources( @@ -124,15 +130,7 @@ public void list() { @Test public void listFilterByName() { - PaginationUtils.requestClientV3Resources( - page -> - this.cloudFoundryClient - .stacksV3() - .list( - ListStacksRequest.builder() - .name(this.stackName) - .page(page) - .build())) + this.requestListStacks(this.stackName) .map(Stack::getName) .as(StepVerifier::create) .expectNext(this.stackName) @@ -145,9 +143,8 @@ private static Mono createStackId( return requestCreateStack(cloudFoundryClient, stackName).map(Stack::getId); } - private static Mono getStackId( - CloudFoundryClient cloudFoundryClient, String stackName) { - return requestListStacks(cloudFoundryClient, stackName).single().map(Stack::getId); + private Mono getStackId() { + return this.requestListStacks(this.stackName).single().map(Stack::getId); } private static Mono requestCreateStack( @@ -168,11 +165,10 @@ private static Mono requestGetStack( .get(GetStackRequest.builder().stackId(stackId).build()); } - private static Flux requestListStacks( - CloudFoundryClient cloudFoundryClient, String stackName) { + private Flux requestListStacks(String stackName) { return PaginationUtils.requestClientV3Resources( page -> - cloudFoundryClient + this.cloudFoundryClient .stacksV3() .list( ListStacksRequest.builder()