Skip to content

Commit 20ec669

Browse files
committed
Cleaning Up Test Names
Previously the knowledge of how test names were structured was spread across two different components, requiring coordination between them. This change moves all of that knowledge into a single component.
1 parent 23f8255 commit 20ec669

27 files changed

+889
-585
lines changed

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

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public abstract class AbstractIntegrationTest {
5454
.setPerformanceLoggerName(this::getTestName);
5555

5656
@Autowired
57-
private NameFactory nameFactory;
57+
protected NameFactory nameFactory;
5858

5959
@Before
6060
public void testEntry() {
@@ -102,58 +102,6 @@ protected final <T> void assertTupleEquality(Tuple2<T, T> tuple) {
102102
assertEquals("tuple components not equal", expected, actual);
103103
}
104104

105-
protected final String getApplicationName() {
106-
return this.nameFactory.getName("test-application-");
107-
}
108-
109-
protected final String getBuildpackName() {
110-
return this.nameFactory.getName("test-buildpack-");
111-
}
112-
113-
protected final String getDomainName() {
114-
return this.nameFactory.getName("test.domain.");
115-
}
116-
117-
protected final String getGroupName() {
118-
return this.nameFactory.getName("test-group-");
119-
}
120-
121-
protected final String getHostName() {
122-
return this.nameFactory.getName("test-host-");
123-
}
124-
125-
protected final String getIdentityZoneName() {
126-
return this.nameFactory.getName("test-identity-zone-");
127-
}
128-
129-
protected final String getOrganizationName() {
130-
return this.nameFactory.getName("test-organization-");
131-
}
132-
133-
protected final String getPath() {
134-
return this.nameFactory.getName("/test-path-");
135-
}
136-
137-
protected final String getServiceInstanceName() {
138-
return this.nameFactory.getName("test-service-instance-");
139-
}
140-
141-
protected final String getSpaceName() {
142-
return this.nameFactory.getName("test-space-");
143-
}
144-
145-
protected final String getUserName() {
146-
return this.nameFactory.getName("test-user-");
147-
}
148-
149-
protected final String getVariableName() {
150-
return this.nameFactory.getName("test-variable-name-");
151-
}
152-
153-
protected final String getVariableValue() {
154-
return this.nameFactory.getName("test-variable-value-");
155-
}
156-
157105
@SuppressWarnings("unchecked")
158106
protected final <T> TestSubscriber<T> testSubscriber() {
159107
return (TestSubscriber<T>) this.testSubscriber;

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

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -89,30 +89,33 @@ final class CloudFoundryCleaner {
8989

9090
private final CloudFoundryClient cloudFoundryClient;
9191

92+
private final NameFactory nameFactory;
93+
9294
private final UaaClient uaaAdminClient;
9395

94-
CloudFoundryCleaner(CloudFoundryClient cloudFoundryClient, UaaClient uaaAdminClient) {
96+
CloudFoundryCleaner(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory, UaaClient uaaAdminClient) {
9597
this.cloudFoundryClient = cloudFoundryClient;
98+
this.nameFactory = nameFactory;
9699
this.uaaAdminClient = uaaAdminClient;
97100
}
98101

99102
void clean() {
100103
Flux.empty()
101-
.thenMany(cleanBuildpacks(this.cloudFoundryClient))
104+
.thenMany(cleanBuildpacks(this.cloudFoundryClient, this.nameFactory))
102105
.thenMany(cleanFeatureFlags(this.cloudFoundryClient))
103-
.thenMany(cleanRoutes(this.cloudFoundryClient))
104-
.thenMany(cleanApplicationsV2(this.cloudFoundryClient))
105-
.thenMany(cleanApplicationsV3(this.cloudFoundryClient))
106+
.thenMany(cleanRoutes(this.cloudFoundryClient, this.nameFactory))
107+
.thenMany(cleanApplicationsV2(this.cloudFoundryClient, this.nameFactory))
108+
.thenMany(cleanApplicationsV3(this.cloudFoundryClient, this.nameFactory))
106109
.thenMany(cleanPackages(this.cloudFoundryClient))
107-
.thenMany(cleanServiceInstances(this.cloudFoundryClient))
108-
.thenMany(cleanUserProvidedServiceInstances(this.cloudFoundryClient))
109-
.thenMany(cleanDomains(this.cloudFoundryClient))
110-
.thenMany(cleanPrivateDomains(this.cloudFoundryClient))
111-
.thenMany(cleanUaaGroups(this.uaaAdminClient))
112-
.thenMany(cleanUaaUsers(this.uaaAdminClient))
113-
.thenMany(cleanUaaClients(this.uaaAdminClient))
114-
.thenMany(cleanSpaces(this.cloudFoundryClient))
115-
.thenMany(cleanOrganizations(this.cloudFoundryClient))
110+
.thenMany(cleanServiceInstances(this.cloudFoundryClient, this.nameFactory))
111+
.thenMany(cleanUserProvidedServiceInstances(this.cloudFoundryClient, this.nameFactory))
112+
.thenMany(cleanDomains(this.cloudFoundryClient, this.nameFactory))
113+
.thenMany(cleanPrivateDomains(this.cloudFoundryClient, this.nameFactory))
114+
.thenMany(cleanUaaGroups(this.uaaAdminClient, this.nameFactory))
115+
.thenMany(cleanUaaUsers(this.uaaAdminClient, this.nameFactory))
116+
.thenMany(cleanUaaClients(this.uaaAdminClient, this.nameFactory))
117+
.thenMany(cleanSpaces(this.cloudFoundryClient, this.nameFactory))
118+
.thenMany(cleanOrganizations(this.cloudFoundryClient, this.nameFactory))
116119
.retry(5, t -> t instanceof SSLException)
117120
.doOnSubscribe(s -> this.logger.debug(">> CLEANUP <<"))
118121
.doOnError(Throwable::printStackTrace)
@@ -121,13 +124,13 @@ void clean() {
121124
.block(Duration.ofMinutes(30));
122125
}
123126

124-
private static Flux<Void> cleanApplicationsV2(CloudFoundryClient cloudFoundryClient) {
127+
private static Flux<Void> cleanApplicationsV2(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
125128
return PaginationUtils.
126129
requestClientV2Resources(page -> cloudFoundryClient.applicationsV2()
127130
.list(ListApplicationsRequest.builder()
128131
.page(page)
129132
.build()))
130-
.filter(application -> ResourceUtils.getEntity(application).getName().startsWith("test-application-"))
133+
.filter(application -> nameFactory.isApplicationName(ResourceUtils.getEntity(application).getName()))
131134
.map(ResourceUtils::getId)
132135
.flatMap(applicationId -> removeServiceBindings(cloudFoundryClient, applicationId)
133136
.thenMany(Flux.just(applicationId)))
@@ -137,27 +140,27 @@ private static Flux<Void> cleanApplicationsV2(CloudFoundryClient cloudFoundryCli
137140
.build()));
138141
}
139142

140-
private static Flux<Void> cleanApplicationsV3(CloudFoundryClient cloudFoundryClient) {
143+
private static Flux<Void> cleanApplicationsV3(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
141144
return PaginationUtils
142145
.requestClientV3Resources(page -> cloudFoundryClient.applicationsV3()
143146
.list(org.cloudfoundry.client.v3.applications.ListApplicationsRequest.builder()
144147
.page(page)
145148
.build()))
146-
.filter(application -> application.getName().startsWith("test-application-"))
149+
.filter(application -> nameFactory.isApplicationName(application.getName()))
147150
.map(Application::getId)
148151
.flatMap(applicationId -> cloudFoundryClient.applicationsV3()
149152
.delete(org.cloudfoundry.client.v3.applications.DeleteApplicationRequest.builder()
150153
.applicationId(applicationId)
151154
.build()));
152155
}
153156

154-
private static Flux<Void> cleanBuildpacks(CloudFoundryClient cloudFoundryClient) {
157+
private static Flux<Void> cleanBuildpacks(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
155158
return PaginationUtils
156159
.requestClientV2Resources(page -> cloudFoundryClient.buildpacks()
157160
.list(ListBuildpacksRequest.builder()
158161
.page(page)
159162
.build()))
160-
.filter(buildpack -> ResourceUtils.getEntity(buildpack).getName().startsWith("test-buildpack-"))
163+
.filter(buildpack -> nameFactory.isBuildpackName(ResourceUtils.getEntity(buildpack).getName()))
161164
.map(ResourceUtils::getId)
162165
.flatMap(buildpackId -> cloudFoundryClient.buildpacks()
163166
.delete(DeleteBuildpackRequest.builder()
@@ -167,13 +170,13 @@ private static Flux<Void> cleanBuildpacks(CloudFoundryClient cloudFoundryClient)
167170
.flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, job));
168171
}
169172

170-
private static Flux<Void> cleanDomains(CloudFoundryClient cloudFoundryClient) {
173+
private static Flux<Void> cleanDomains(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
171174
return PaginationUtils.
172175
requestClientV2Resources(page -> cloudFoundryClient.domains()
173176
.list(ListDomainsRequest.builder()
174177
.page(page)
175178
.build()))
176-
.filter(domain -> ResourceUtils.getEntity(domain).getName().startsWith("test.domain."))
179+
.filter(domain -> nameFactory.isDomainName(ResourceUtils.getEntity(domain).getName()))
177180
.map(ResourceUtils::getId)
178181
.flatMap(domainId -> cloudFoundryClient.domains()
179182
.delete(DeleteDomainRequest.builder()
@@ -198,13 +201,13 @@ private static Flux<Void> cleanFeatureFlags(CloudFoundryClient cloudFoundryClien
198201
.then());
199202
}
200203

201-
private static Flux<Void> cleanOrganizations(CloudFoundryClient cloudFoundryClient) {
204+
private static Flux<Void> cleanOrganizations(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
202205
return PaginationUtils.
203206
requestClientV2Resources(page -> cloudFoundryClient.organizations()
204207
.list(ListOrganizationsRequest.builder()
205208
.page(page)
206209
.build()))
207-
.filter(organization -> ResourceUtils.getEntity(organization).getName().startsWith("test-organization-"))
210+
.filter(organization -> nameFactory.isOrganizationName(ResourceUtils.getEntity(organization).getName()))
208211
.map(ResourceUtils::getId)
209212
.flatMap(organizationId -> cloudFoundryClient.organizations()
210213
.delete(DeleteOrganizationRequest.builder()
@@ -228,13 +231,13 @@ private static Flux<Void> cleanPackages(CloudFoundryClient cloudFoundryClient) {
228231
.build()));
229232
}
230233

231-
private static Flux<Void> cleanPrivateDomains(CloudFoundryClient cloudFoundryClient) {
234+
private static Flux<Void> cleanPrivateDomains(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
232235
return PaginationUtils.
233236
requestClientV2Resources(page -> cloudFoundryClient.privateDomains()
234237
.list(ListPrivateDomainsRequest.builder()
235238
.page(page)
236239
.build()))
237-
.filter(domain -> ResourceUtils.getEntity(domain).getName().startsWith("test.domain."))
240+
.filter(domain -> nameFactory.isDomainName(ResourceUtils.getEntity(domain).getName()))
238241
.map(ResourceUtils::getId)
239242
.flatMap(privateDomainId -> cloudFoundryClient.privateDomains()
240243
.delete(DeletePrivateDomainRequest.builder()
@@ -244,7 +247,7 @@ private static Flux<Void> cleanPrivateDomains(CloudFoundryClient cloudFoundryCli
244247
.flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, job));
245248
}
246249

247-
private static Flux<Void> cleanRoutes(CloudFoundryClient cloudFoundryClient) {
250+
private static Flux<Void> cleanRoutes(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
248251
return PaginationUtils.
249252
requestClientV2Resources(page -> cloudFoundryClient.routes()
250253
.list(ListRoutesRequest.builder()
@@ -257,9 +260,9 @@ private static Flux<Void> cleanRoutes(CloudFoundryClient cloudFoundryClient) {
257260
.domainId(ResourceUtils.getEntity(route).getDomainId())
258261
.build())
259262
))
260-
.filter(predicate((route, domain) -> ResourceUtils.getEntity(domain).getName().startsWith("test.domain.") ||
261-
ResourceUtils.getEntity(route).getHost().startsWith("test-application-") ||
262-
ResourceUtils.getEntity(route).getHost().startsWith("test-host-")))
263+
.filter(predicate((route, domain) -> nameFactory.isDomainName(ResourceUtils.getEntity(domain).getName()) ||
264+
nameFactory.isApplicationName(ResourceUtils.getEntity(route).getHost()) ||
265+
nameFactory.isHostName(ResourceUtils.getEntity(route).getHost())))
263266
.map(function((route, domain) -> ResourceUtils.getId(route)))
264267
.flatMap(routeId -> cloudFoundryClient.routes()
265268
.delete(DeleteRouteRequest.builder()
@@ -269,13 +272,13 @@ private static Flux<Void> cleanRoutes(CloudFoundryClient cloudFoundryClient) {
269272
.flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, job));
270273
}
271274

272-
private static Flux<Void> cleanServiceInstances(CloudFoundryClient cloudFoundryClient) {
275+
private static Flux<Void> cleanServiceInstances(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
273276
return PaginationUtils.
274277
requestClientV2Resources(page -> cloudFoundryClient.serviceInstances()
275278
.list(ListServiceInstancesRequest.builder()
276279
.page(page)
277280
.build()))
278-
.filter(serviceInstance -> ResourceUtils.getEntity(serviceInstance).getName().startsWith("test-service-instance-"))
281+
.filter(serviceInstance -> nameFactory.isServiceInstanceName(ResourceUtils.getEntity(serviceInstance).getName()))
279282
.map(ResourceUtils::getId)
280283
.flatMap(serviceInstanceId -> cloudFoundryClient.serviceInstances()
281284
.delete(DeleteServiceInstanceRequest.builder()
@@ -285,13 +288,13 @@ private static Flux<Void> cleanServiceInstances(CloudFoundryClient cloudFoundryC
285288
.flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, job));
286289
}
287290

288-
private static Flux<Void> cleanSpaces(CloudFoundryClient cloudFoundryClient) {
291+
private static Flux<Void> cleanSpaces(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
289292
return PaginationUtils.
290293
requestClientV2Resources(page -> cloudFoundryClient.spaces()
291294
.list(ListSpacesRequest.builder()
292295
.page(page)
293296
.build()))
294-
.filter(space -> ResourceUtils.getEntity(space).getName().startsWith("test-space-"))
297+
.filter(space -> nameFactory.isSpaceName(ResourceUtils.getEntity(space).getName()))
295298
.map(ResourceUtils::getId)
296299
.flatMap(spaceId -> cloudFoundryClient.spaces()
297300
.delete(DeleteSpaceRequest.builder()
@@ -301,13 +304,13 @@ private static Flux<Void> cleanSpaces(CloudFoundryClient cloudFoundryClient) {
301304
.flatMap(job -> JobUtils.waitForCompletion(cloudFoundryClient, job));
302305
}
303306

304-
private static Flux<Void> cleanUaaClients(UaaClient uaaAdminClient) {
307+
private static Flux<Void> cleanUaaClients(UaaClient uaaAdminClient, NameFactory nameFactory) {
305308
return PaginationUtils
306309
.requestUaaResources(startIndex -> uaaAdminClient.clients()
307310
.list(ListClientsRequest.builder()
308311
.startIndex(startIndex)
309312
.build()))
310-
.filter(client -> client.getClientId().startsWith("test-client-id-"))
313+
.filter(client -> nameFactory.isClientId(client.getClientId()))
311314
.map(Client::getClientId)
312315
.flatMap(clientId -> uaaAdminClient.clients()
313316
.delete(DeleteClientRequest.builder()
@@ -316,13 +319,13 @@ private static Flux<Void> cleanUaaClients(UaaClient uaaAdminClient) {
316319
.then());
317320
}
318321

319-
private static Flux<Void> cleanUaaGroups(UaaClient uaaClient) {
322+
private static Flux<Void> cleanUaaGroups(UaaClient uaaClient, NameFactory nameFactory) {
320323
return PaginationUtils
321324
.requestUaaResources(startIndex -> uaaClient.groups()
322325
.list(ListGroupsRequest.builder()
323326
.startIndex(startIndex)
324327
.build()))
325-
.filter(group -> group.getDisplayName().startsWith("test-group-"))
328+
.filter(group -> nameFactory.isGroupName(group.getDisplayName()))
326329
.map(Group::getId)
327330
.flatMap(groupId -> uaaClient.groups()
328331
.delete(DeleteGroupRequest.builder()
@@ -332,13 +335,13 @@ private static Flux<Void> cleanUaaGroups(UaaClient uaaClient) {
332335
.then());
333336
}
334337

335-
private static Flux<Void> cleanUaaUsers(UaaClient uaaClient) {
338+
private static Flux<Void> cleanUaaUsers(UaaClient uaaClient, NameFactory nameFactory) {
336339
return PaginationUtils
337340
.requestUaaResources(startIndex -> uaaClient.users()
338341
.list(ListUsersRequest.builder()
339342
.startIndex(startIndex)
340343
.build()))
341-
.filter(user -> user.getUserName().startsWith("test-user-"))
344+
.filter(user -> nameFactory.isUserName(user.getUserName()))
342345
.map(User::getId)
343346
.flatMap(userId -> uaaClient.users()
344347
.delete(DeleteUserRequest.builder()
@@ -348,13 +351,13 @@ private static Flux<Void> cleanUaaUsers(UaaClient uaaClient) {
348351
.then());
349352
}
350353

351-
private static Flux<Void> cleanUserProvidedServiceInstances(CloudFoundryClient cloudFoundryClient) {
354+
private static Flux<Void> cleanUserProvidedServiceInstances(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
352355
return PaginationUtils.
353356
requestClientV2Resources(page -> cloudFoundryClient.userProvidedServiceInstances()
354357
.list(ListUserProvidedServiceInstancesRequest.builder()
355358
.page(page)
356359
.build()))
357-
.filter(userProvidedServiceInstance -> ResourceUtils.getEntity(userProvidedServiceInstance).getName().startsWith("test-service-instance-"))
360+
.filter(userProvidedServiceInstance -> nameFactory.isServiceInstanceName(ResourceUtils.getEntity(userProvidedServiceInstance).getName()))
358361
.map(ResourceUtils::getId)
359362
.flatMap(userProvidedServiceInstanceId -> cloudFoundryClient.userProvidedServiceInstances()
360363
.delete(DeleteUserProvidedServiceInstanceRequest.builder()

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,17 +146,17 @@ Mono<Tuple2<String, String>> client(@Qualifier("admin") UaaClient adminUaaClient
146146

147147
@Bean
148148
String clientId(NameFactory nameFactory) {
149-
return nameFactory.getName("test-client-id-");
149+
return nameFactory.getClientId();
150150
}
151151

152152
@Bean
153153
String clientSecret(NameFactory nameFactory) {
154-
return nameFactory.getName("test-client-secret-");
154+
return nameFactory.getClientSecret();
155155
}
156156

157157
@Bean(initMethod = "clean", destroyMethod = "clean")
158-
CloudFoundryCleaner cloudFoundryCleaner(@Qualifier("admin") CloudFoundryClient adminCloudFoundryClient, @Qualifier("admin") UaaClient adminUaaClient) {
159-
return new CloudFoundryCleaner(adminCloudFoundryClient, adminUaaClient);
158+
CloudFoundryCleaner cloudFoundryCleaner(@Qualifier("admin") CloudFoundryClient adminCloudFoundryClient, NameFactory nameFactory, @Qualifier("admin") UaaClient adminUaaClient) {
159+
return new CloudFoundryCleaner(adminCloudFoundryClient, nameFactory, adminUaaClient);
160160
}
161161

162162
@Bean(initMethod = "checkCompatibility")
@@ -238,12 +238,12 @@ Mono<String> organizationId(CloudFoundryClient cloudFoundryClient, String organi
238238

239239
@Bean
240240
String organizationName(NameFactory nameFactory) {
241-
return nameFactory.getName("test-organization-");
241+
return nameFactory.getOrganizationName();
242242
}
243243

244244
@Bean
245245
String password(NameFactory nameFactory) {
246-
return nameFactory.getName("test-password-");
246+
return nameFactory.getPassword();
247247
}
248248

249249
@Bean
@@ -269,7 +269,7 @@ Mono<String> spaceId(CloudFoundryClient cloudFoundryClient, Mono<String> organiz
269269

270270
@Bean
271271
String spaceName(NameFactory nameFactory) {
272-
return nameFactory.getName("test-space-");
272+
return nameFactory.getSpaceName();
273273
}
274274

275275
@Bean(initMethod = "block")
@@ -360,7 +360,7 @@ Mono<String> userId(@Qualifier("admin") UaaClient adminUaaClient, String passwor
360360

361361
@Bean
362362
String username(NameFactory nameFactory) {
363-
return nameFactory.getName("test-user-");
363+
return nameFactory.getUserName();
364364
}
365365

366366
}

0 commit comments

Comments
 (0)