Skip to content

Commit 97d78a0

Browse files
committed
Cleanup resources left by V3 API tests
1 parent 43ded5d commit 97d78a0

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

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

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818

1919
import com.github.zafarkhaja.semver.Version;
2020
import org.cloudfoundry.client.CloudFoundryClient;
21-
import org.cloudfoundry.client.v2.applications.ApplicationResource;
22-
import org.cloudfoundry.client.v2.applications.DeleteApplicationRequest;
2321
import org.cloudfoundry.client.v2.applications.ListApplicationServiceBindingsRequest;
24-
import org.cloudfoundry.client.v2.applications.ListApplicationsRequest;
2522
import org.cloudfoundry.client.v2.applications.RemoveApplicationServiceBindingRequest;
2623
import org.cloudfoundry.client.v2.buildpacks.DeleteBuildpackRequest;
2724
import org.cloudfoundry.client.v2.buildpacks.ListBuildpacksRequest;
@@ -69,6 +66,9 @@
6966
import org.cloudfoundry.client.v2.users.UserResource;
7067
import org.cloudfoundry.client.v3.Metadata;
7168
import org.cloudfoundry.client.v3.Relationship;
69+
import org.cloudfoundry.client.v3.applications.Application;
70+
import org.cloudfoundry.client.v3.applications.DeleteApplicationRequest;
71+
import org.cloudfoundry.client.v3.applications.ListApplicationsRequest;
7272
import org.cloudfoundry.client.v3.serviceinstances.ListSharedSpacesRelationshipRequest;
7373
import org.cloudfoundry.client.v3.serviceinstances.ListSharedSpacesRelationshipResponse;
7474
import org.cloudfoundry.client.v3.serviceinstances.UnshareServiceInstanceRequest;
@@ -179,7 +179,7 @@ void clean() {
179179
cleanUsers(this.cloudFoundryClient, this.nameFactory)
180180
))
181181
.thenMany(Mono.when(
182-
cleanApplicationsV2(this.cloudFoundryClient, this.nameFactory), // After Routes, cannot run with other cleanApps
182+
cleanApplicationsV3(this.cloudFoundryClient, this.nameFactory), // After Routes, cannot run with other cleanApps
183183
cleanUsers(this.uaaClient, this.nameFactory) // After CF Users
184184
))
185185
.thenMany(Mono.when( // After Routes/Applications
@@ -196,19 +196,20 @@ void clean() {
196196
.block(Duration.ofMinutes(30));
197197
}
198198

199-
private static Flux<Void> cleanApplicationsV2(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
199+
private static Flux<Void> cleanApplicationsV3(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
200200
return PaginationUtils
201-
.requestClientV2Resources(page -> cloudFoundryClient.applicationsV2()
201+
.requestClientV3Resources(page -> cloudFoundryClient.applicationsV3()
202202
.list(ListApplicationsRequest.builder()
203203
.page(page)
204204
.build()))
205-
.filter(application -> nameFactory.isApplicationName(ResourceUtils.getEntity(application).getName()))
205+
.filter(application -> nameFactory.isApplicationName(application.getName()))
206206
.delayUntil(application -> removeApplicationServiceBindings(cloudFoundryClient, application))
207-
.flatMap(application -> cloudFoundryClient.applicationsV2()
207+
.flatMap(application -> cloudFoundryClient.applicationsV3()
208208
.delete(DeleteApplicationRequest.builder()
209-
.applicationId(ResourceUtils.getId(application))
209+
.applicationId(application.getId())
210210
.build())
211-
.doOnError(t -> LOGGER.error("Unable to delete V2 application {}", ResourceUtils.getEntity(application).getName(), t)));
211+
.then()
212+
.doOnError(t -> LOGGER.error("Unable to delete V3 application {}", application.getName(), t)));
212213
}
213214

214215
private static Flux<Void> cleanBuildpacks(CloudFoundryClient cloudFoundryClient, NameFactory nameFactory) {
@@ -513,6 +514,7 @@ private static Flux<Void> cleanSpaces(CloudFoundryClient cloudFoundryClient, Nam
513514
.flatMap(space -> cloudFoundryClient.spaces()
514515
.delete(DeleteSpaceRequest.builder()
515516
.async(true)
517+
.recursive(true)
516518
.spaceId(ResourceUtils.getId(space))
517519
.build())
518520
.flatMapMany(job -> JobUtils.waitForCompletion(cloudFoundryClient, Duration.ofMinutes(5), job))
@@ -614,15 +616,15 @@ private static boolean isCleanable(NameFactory nameFactory, UserResource resourc
614616
return nameFactory.isUserId(ResourceUtils.getId(resource)) || nameFactory.isUserName(ResourceUtils.getEntity(resource).getUsername());
615617
}
616618

617-
private static Flux<Void> removeApplicationServiceBindings(CloudFoundryClient cloudFoundryClient, ApplicationResource application) {
619+
private static Flux<Void> removeApplicationServiceBindings(CloudFoundryClient cloudFoundryClient, Application application) {
618620
return PaginationUtils
619621
.requestClientV2Resources(page -> cloudFoundryClient.applicationsV2()
620622
.listServiceBindings(ListApplicationServiceBindingsRequest.builder()
621623
.page(page)
622-
.applicationId(ResourceUtils.getId(application))
624+
.applicationId(application.getId())
623625
.build()))
624-
.flatMap(serviceBinding -> requestRemoveServiceBinding(cloudFoundryClient, ResourceUtils.getId(application), ResourceUtils.getId(serviceBinding))
625-
.doOnError(t -> LOGGER.error("Unable to remove service binding from {}", ResourceUtils.getEntity(application).getName(), t)));
626+
.flatMap(serviceBinding -> requestRemoveServiceBinding(cloudFoundryClient, application.getId(), ResourceUtils.getId(serviceBinding))
627+
.doOnError(t -> LOGGER.error("Unable to remove service binding from {}", application.getName(), t)));
626628
}
627629

628630
private static Flux<Void> removeRouteAssociations(CloudFoundryClient cloudFoundryClient, ServiceInstanceResource serviceInstance) {

0 commit comments

Comments
 (0)