Skip to content

Commit 1b130c3

Browse files
committed
integration tests: use the Reactive stackName bean
1 parent d87f470 commit 1b130c3

File tree

4 files changed

+65
-52
lines changed

4 files changed

+65
-52
lines changed

integration-test/src/test/java/org/cloudfoundry/IntegrationTestConfiguration.java

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.time.Duration;
3535
import java.util.Arrays;
3636
import java.util.Collections;
37+
import java.util.Comparator;
3738
import java.util.HashMap;
3839
import java.util.List;
3940
import java.util.Random;
@@ -44,6 +45,8 @@
4445
import org.cloudfoundry.client.v2.organizations.CreateOrganizationRequest;
4546
import org.cloudfoundry.client.v2.spaces.CreateSpaceRequest;
4647
import org.cloudfoundry.client.v2.stacks.ListStacksRequest;
48+
import org.cloudfoundry.client.v2.stacks.StackEntity;
49+
import org.cloudfoundry.client.v2.stacks.StackResource;
4750
import org.cloudfoundry.client.v2.userprovidedserviceinstances.CreateUserProvidedServiceInstanceRequest;
4851
import org.cloudfoundry.doppler.DopplerClient;
4952
import org.cloudfoundry.logcache.v1.TestLogCacheEndpoints;
@@ -527,16 +530,20 @@ String spaceName(NameFactory nameFactory) {
527530

528531
@Bean(initMethod = "block")
529532
@DependsOn("cloudFoundryCleaner")
530-
Mono<String> stackId(CloudFoundryClient cloudFoundryClient, String stackName) {
531-
return PaginationUtils.requestClientV2Resources(
532-
page ->
533-
cloudFoundryClient
534-
.stacks()
535-
.list(
536-
ListStacksRequest.builder()
537-
.name(stackName)
538-
.page(page)
539-
.build()))
533+
Mono<String> stackId(CloudFoundryClient cloudFoundryClient, Mono<String> stackName) {
534+
return stackName
535+
.flux()
536+
.flatMap(
537+
name ->
538+
PaginationUtils.requestClientV2Resources(
539+
page ->
540+
cloudFoundryClient
541+
.stacks()
542+
.list(
543+
ListStacksRequest.builder()
544+
.name(name)
545+
.page(page)
546+
.build())))
540547
.single()
541548
.map(ResourceUtils::getId)
542549
.doOnSubscribe(s -> this.logger.debug(">> STACK ({}) <<", stackName))
@@ -545,9 +552,24 @@ Mono<String> stackId(CloudFoundryClient cloudFoundryClient, String stackName) {
545552
.cache();
546553
}
547554

548-
@Bean
549-
String stackName() {
550-
return "cflinuxfs3";
555+
/**
556+
* Select the most recent stack available, matching {@code cflinuxfs*}, based
557+
* on the stack number.
558+
*/
559+
@Bean(initMethod = "block")
560+
@DependsOn("cloudFoundryCleaner")
561+
Mono<String> stackName(CloudFoundryClient cloudFoundryClient) {
562+
return PaginationUtils.requestClientV2Resources(
563+
page ->
564+
cloudFoundryClient
565+
.stacks()
566+
.list(ListStacksRequest.builder().page(page).build()))
567+
.map(StackResource::getEntity)
568+
.map(StackEntity::getName)
569+
.filter(s -> s.matches("^cflinuxfs\\d$"))
570+
.sort(Comparator.reverseOrder())
571+
.single()
572+
.cache();
551573
}
552574

553575
@Bean(initMethod = "block")

integration-test/src/test/java/org/cloudfoundry/client/v2/StacksTest.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.cloudfoundry.util.JobUtils;
3232
import org.cloudfoundry.util.PaginationUtils;
3333
import org.cloudfoundry.util.ResourceUtils;
34+
import org.junit.jupiter.api.BeforeEach;
3435
import org.junit.jupiter.api.Test;
3536
import org.springframework.beans.factory.annotation.Autowired;
3637
import reactor.core.publisher.Flux;
@@ -41,7 +42,12 @@ public final class StacksTest extends AbstractIntegrationTest {
4142

4243
@Autowired private CloudFoundryClient cloudFoundryClient;
4344

44-
@Autowired private String stackName;
45+
private String stackName;
46+
47+
@BeforeEach
48+
void setUp(@Autowired Mono<String> stackName) {
49+
this.stackName = stackName.block();
50+
}
4551

4652
@Test
4753
public void create() {
@@ -54,7 +60,7 @@ public void create() {
5460
.description("Test stack description")
5561
.name(stackName)
5662
.build())
57-
.thenMany(requestListStacks(this.cloudFoundryClient, stackName))
63+
.thenMany(requestListStacks(stackName))
5864
.map(response -> ResourceUtils.getEntity(response).getDescription())
5965
.as(StepVerifier::create)
6066
.expectNext("Test stack description")
@@ -122,7 +128,7 @@ public void deleteAsync() {
122128

123129
@Test
124130
public void get() {
125-
getStackId(this.cloudFoundryClient, this.stackName)
131+
getStackId()
126132
.flatMap(
127133
stackId ->
128134
this.cloudFoundryClient
@@ -137,7 +143,7 @@ public void get() {
137143

138144
@Test
139145
public void list() {
140-
getStackId(this.cloudFoundryClient, this.stackName)
146+
getStackId()
141147
.flatMapMany(
142148
stackId ->
143149
PaginationUtils.requestClientV2Resources(
@@ -161,15 +167,7 @@ public void list() {
161167

162168
@Test
163169
public void listFilterByName() {
164-
PaginationUtils.requestClientV2Resources(
165-
page ->
166-
this.cloudFoundryClient
167-
.stacks()
168-
.list(
169-
ListStacksRequest.builder()
170-
.name(this.stackName)
171-
.page(page)
172-
.build()))
170+
this.requestListStacks(this.stackName)
173171
.map(resource -> resource.getEntity().getName())
174172
.as(StepVerifier::create)
175173
.expectNext(this.stackName)
@@ -182,9 +180,8 @@ private static Mono<String> createStackId(
182180
return requestCreateStack(cloudFoundryClient, stackName).map(ResourceUtils::getId);
183181
}
184182

185-
private static Mono<String> getStackId(
186-
CloudFoundryClient cloudFoundryClient, String stackName) {
187-
return requestListStacks(cloudFoundryClient, stackName).single().map(ResourceUtils::getId);
183+
private Mono<String> getStackId() {
184+
return this.requestListStacks(this.stackName).single().map(ResourceUtils::getId);
188185
}
189186

190187
private static Mono<CreateStackResponse> requestCreateStack(
@@ -203,11 +200,10 @@ private static Mono<GetStackResponse> requestGetStack(
203200
return cloudFoundryClient.stacks().get(GetStackRequest.builder().stackId(stackId).build());
204201
}
205202

206-
private static Flux<StackResource> requestListStacks(
207-
CloudFoundryClient cloudFoundryClient, String stackName) {
203+
private Flux<StackResource> requestListStacks(String stackName) {
208204
return PaginationUtils.requestClientV2Resources(
209205
page ->
210-
cloudFoundryClient
206+
this.cloudFoundryClient
211207
.stacks()
212208
.list(
213209
ListStacksRequest.builder()

integration-test/src/test/java/org/cloudfoundry/client/v3/BuildpacksTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,6 @@ private static Mono<CreateBuildpackResponse> requestCreateBuildpack(
248248
.locked(false)
249249
.name(buildpackName)
250250
.position(3)
251-
.stack("cflinuxfs3")
252251
.build());
253252
}
254253

integration-test/src/test/java/org/cloudfoundry/client/v3/StacksTest.java

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.cloudfoundry.client.v3.stacks.Stack;
3131
import org.cloudfoundry.client.v3.stacks.StackResource;
3232
import org.cloudfoundry.util.PaginationUtils;
33+
import org.junit.jupiter.api.BeforeEach;
3334
import org.junit.jupiter.api.Test;
3435
import org.springframework.beans.factory.annotation.Autowired;
3536
import reactor.core.publisher.Flux;
@@ -40,7 +41,12 @@ public final class StacksTest extends AbstractIntegrationTest {
4041

4142
@Autowired private CloudFoundryClient cloudFoundryClient;
4243

43-
@Autowired private String stackName;
44+
private String stackName;
45+
46+
@BeforeEach
47+
void setUp(@Autowired Mono<String> stackName) {
48+
this.stackName = stackName.block();
49+
}
4450

4551
@Test
4652
public void create() {
@@ -53,7 +59,7 @@ public void create() {
5359
.description("Test stack description")
5460
.name(stackName)
5561
.build())
56-
.thenMany(requestListStacks(this.cloudFoundryClient, stackName))
62+
.thenMany(requestListStacks(stackName))
5763
.map(Stack::getDescription)
5864
.as(StepVerifier::create)
5965
.expectNext("Test stack description")
@@ -88,7 +94,7 @@ public void delete() {
8894

8995
@Test
9096
public void get() {
91-
getStackId(this.cloudFoundryClient, this.stackName)
97+
getStackId()
9298
.flatMap(
9399
stackId ->
94100
this.cloudFoundryClient
@@ -103,7 +109,7 @@ public void get() {
103109

104110
@Test
105111
public void list() {
106-
getStackId(this.cloudFoundryClient, this.stackName)
112+
getStackId()
107113
.flatMapMany(
108114
stackId ->
109115
PaginationUtils.requestClientV3Resources(
@@ -124,15 +130,7 @@ public void list() {
124130

125131
@Test
126132
public void listFilterByName() {
127-
PaginationUtils.requestClientV3Resources(
128-
page ->
129-
this.cloudFoundryClient
130-
.stacksV3()
131-
.list(
132-
ListStacksRequest.builder()
133-
.name(this.stackName)
134-
.page(page)
135-
.build()))
133+
this.requestListStacks(this.stackName)
136134
.map(Stack::getName)
137135
.as(StepVerifier::create)
138136
.expectNext(this.stackName)
@@ -145,9 +143,8 @@ private static Mono<String> createStackId(
145143
return requestCreateStack(cloudFoundryClient, stackName).map(Stack::getId);
146144
}
147145

148-
private static Mono<String> getStackId(
149-
CloudFoundryClient cloudFoundryClient, String stackName) {
150-
return requestListStacks(cloudFoundryClient, stackName).single().map(Stack::getId);
146+
private Mono<String> getStackId() {
147+
return this.requestListStacks(this.stackName).single().map(Stack::getId);
151148
}
152149

153150
private static Mono<CreateStackResponse> requestCreateStack(
@@ -168,11 +165,10 @@ private static Mono<GetStackResponse> requestGetStack(
168165
.get(GetStackRequest.builder().stackId(stackId).build());
169166
}
170167

171-
private static Flux<StackResource> requestListStacks(
172-
CloudFoundryClient cloudFoundryClient, String stackName) {
168+
private Flux<StackResource> requestListStacks(String stackName) {
173169
return PaginationUtils.requestClientV3Resources(
174170
page ->
175-
cloudFoundryClient
171+
this.cloudFoundryClient
176172
.stacksV3()
177173
.list(
178174
ListStacksRequest.builder()

0 commit comments

Comments
 (0)