Skip to content

Commit b00bb52

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

File tree

4 files changed

+80
-63
lines changed

4 files changed

+80
-63
lines changed

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

Lines changed: 35 additions & 14 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(name ->
537+
PaginationUtils.requestClientV2Resources(
538+
page ->
539+
cloudFoundryClient
540+
.stacks()
541+
.list(
542+
ListStacksRequest.builder()
543+
.name(name)
544+
.page(page)
545+
.build()))
546+
)
540547
.single()
541548
.map(ResourceUtils::getId)
542549
.doOnSubscribe(s -> this.logger.debug(">> STACK ({}) <<", stackName))
@@ -545,9 +552,23 @@ 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(page -> cloudFoundryClient
563+
.stacks()
564+
.list(ListStacksRequest.builder().page(page).build())
565+
)
566+
.map(StackResource::getEntity)
567+
.map(StackEntity::getName)
568+
.filter(s -> s.matches("^cflinuxfs\\d$"))
569+
.sort(Comparator.reverseOrder())
570+
.single()
571+
.cache();
551572
}
552573

553574
@Bean(initMethod = "block")
@@ -653,7 +674,7 @@ Mono<String> userId(@Qualifier("admin") UaaClient uaaClient, String password, St
653674
String
654675
.format(
655676
"displayName"
656-
+ " eq \"%s\"",
677+
+ " eq \"%s\"",
657678
group))
658679
.build())
659680
.flatMapIterable(

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

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.cloudfoundry.client.v2;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
20-
2119
import java.time.Duration;
2220
import org.cloudfoundry.AbstractIntegrationTest;
2321
import org.cloudfoundry.client.CloudFoundryClient;
@@ -31,17 +29,25 @@
3129
import org.cloudfoundry.util.JobUtils;
3230
import org.cloudfoundry.util.PaginationUtils;
3331
import org.cloudfoundry.util.ResourceUtils;
32+
import org.junit.jupiter.api.BeforeEach;
3433
import org.junit.jupiter.api.Test;
35-
import org.springframework.beans.factory.annotation.Autowired;
3634
import reactor.core.publisher.Flux;
3735
import reactor.core.publisher.Mono;
3836
import reactor.test.StepVerifier;
3937

38+
import org.springframework.beans.factory.annotation.Autowired;
39+
import static org.assertj.core.api.Assertions.assertThat;
40+
4041
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")
@@ -84,7 +90,7 @@ public void delete() {
8490
.isInstanceOf(ClientV2Exception.class)
8591
.hasMessageMatching(
8692
"CF-StackNotFound\\([0-9]+\\): The stack could not"
87-
+ " be found: .*"))
93+
+ " be found: .*"))
8894
.verify(Duration.ofMinutes(5));
8995
}
9096

@@ -116,13 +122,13 @@ public void deleteAsync() {
116122
.isInstanceOf(ClientV2Exception.class)
117123
.hasMessageMatching(
118124
"CF-StackNotFound\\([0-9]+\\): The stack could not"
119-
+ " be found: .*"))
125+
+ " be found: .*"))
120126
.verify(Duration.ofMinutes(5));
121127
}
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,10 @@ 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)
185+
.single()
186+
.map(ResourceUtils::getId);
188187
}
189188

190189
private static Mono<CreateStackResponse> requestCreateStack(
@@ -203,11 +202,10 @@ private static Mono<GetStackResponse> requestGetStack(
203202
return cloudFoundryClient.stacks().get(GetStackRequest.builder().stackId(stackId).build());
204203
}
205204

206-
private static Flux<StackResource> requestListStacks(
207-
CloudFoundryClient cloudFoundryClient, String stackName) {
205+
private Flux<StackResource> requestListStacks(String stackName) {
208206
return PaginationUtils.requestClientV2Resources(
209207
page ->
210-
cloudFoundryClient
208+
this.cloudFoundryClient
211209
.stacks()
212210
.list(
213211
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: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
package org.cloudfoundry.client.v3;
1818

19-
import static org.assertj.core.api.Assertions.assertThat;
20-
2119
import java.time.Duration;
2220
import org.cloudfoundry.AbstractIntegrationTest;
2321
import org.cloudfoundry.client.CloudFoundryClient;
@@ -30,17 +28,26 @@
3028
import org.cloudfoundry.client.v3.stacks.Stack;
3129
import org.cloudfoundry.client.v3.stacks.StackResource;
3230
import org.cloudfoundry.util.PaginationUtils;
31+
import org.junit.jupiter.api.BeforeEach;
3332
import org.junit.jupiter.api.Test;
34-
import org.springframework.beans.factory.annotation.Autowired;
3533
import reactor.core.publisher.Flux;
3634
import reactor.core.publisher.Mono;
3735
import reactor.test.StepVerifier;
3836

37+
import org.springframework.beans.factory.annotation.Autowired;
38+
import static org.assertj.core.api.Assertions.assertThat;
39+
3940
public final class StacksTest extends AbstractIntegrationTest {
4041

41-
@Autowired private CloudFoundryClient cloudFoundryClient;
42+
@Autowired
43+
private CloudFoundryClient cloudFoundryClient;
4244

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

4552
@Test
4653
public void create() {
@@ -53,7 +60,7 @@ public void create() {
5360
.description("Test stack description")
5461
.name(stackName)
5562
.build())
56-
.thenMany(requestListStacks(this.cloudFoundryClient, stackName))
63+
.thenMany(requestListStacks(stackName))
5764
.map(Stack::getDescription)
5865
.as(StepVerifier::create)
5966
.expectNext("Test stack description")
@@ -82,13 +89,13 @@ public void delete() {
8289
.isInstanceOf(ClientV3Exception.class)
8390
.hasMessageMatching(
8491
"CF-ResourceNotFound\\([0-9]+\\): Stack not"
85-
+ " found.*"))
92+
+ " found.*"))
8693
.verify(Duration.ofMinutes(5));
8794
}
8895

8996
@Test
9097
public void get() {
91-
getStackId(this.cloudFoundryClient, this.stackName)
98+
getStackId()
9299
.flatMap(
93100
stackId ->
94101
this.cloudFoundryClient
@@ -103,7 +110,7 @@ public void get() {
103110

104111
@Test
105112
public void list() {
106-
getStackId(this.cloudFoundryClient, this.stackName)
113+
getStackId()
107114
.flatMapMany(
108115
stackId ->
109116
PaginationUtils.requestClientV3Resources(
@@ -124,15 +131,7 @@ public void list() {
124131

125132
@Test
126133
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()))
134+
this.requestListStacks(this.stackName)
136135
.map(Stack::getName)
137136
.as(StepVerifier::create)
138137
.expectNext(this.stackName)
@@ -145,9 +144,10 @@ private static Mono<String> createStackId(
145144
return requestCreateStack(cloudFoundryClient, stackName).map(Stack::getId);
146145
}
147146

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

153153
private static Mono<CreateStackResponse> requestCreateStack(
@@ -168,11 +168,10 @@ private static Mono<GetStackResponse> requestGetStack(
168168
.get(GetStackRequest.builder().stackId(stackId).build());
169169
}
170170

171-
private static Flux<StackResource> requestListStacks(
172-
CloudFoundryClient cloudFoundryClient, String stackName) {
171+
private Flux<StackResource> requestListStacks(String stackName) {
173172
return PaginationUtils.requestClientV3Resources(
174173
page ->
175-
cloudFoundryClient
174+
this.cloudFoundryClient
176175
.stacksV3()
177176
.list(
178177
ListStacksRequest.builder()

0 commit comments

Comments
 (0)