@Before
 public void createApplicationId() throws Exception {
   this.applicationId =
       this.spaceId
           .then(
               spaceId ->
                   this.cloudFoundryClient
                       .applicationsV2()
                       .create(
                           CreateApplicationRequest.builder()
                               .buildpack("staticfile_buildpack")
                               .diego(true)
                               .diskQuota(512)
                               .memory(64)
                               .name(TEST_APPLICATION_NAME)
                               .spaceId(spaceId)
                               .build()))
           .map(ResourceUtils::getId)
           .as(Promise::from);
 }
 @Test
 public void copy() {
   Mono.when(this.applicationId, this.spaceId)
       .then(
           function(
               (sourceId, spaceId) ->
                   this.cloudFoundryClient
                       .applicationsV2()
                       .create(
                           CreateApplicationRequest.builder()
                               .name("copy-application")
                               .spaceId(spaceId)
                               .build())
                       .map(ResourceUtils::getId)
                       .and(Mono.just(sourceId))))
       .then(
           function(
               (targetId, sourceId) ->
                   this.cloudFoundryClient
                       .applicationsV2()
                       .copy(
                           CopyApplicationRequest.builder()
                               .applicationId(targetId)
                               .sourceApplicationId(sourceId)
                               .build())
                       .map(ResourceUtils::getId)))
       .flatMap(
           applicationCopyId ->
               Stream.from(
                       this.cloudFoundryClient
                           .applicationsV2()
                           .list(ListApplicationsRequest.builder().build()))
                   .flatMap(ResourceUtils::getResources)
                   .filter(
                       r -> {
                         String name = ResourceUtils.getEntity(r).getName();
                         return TEST_APPLICATION_NAME.equals(name)
                             || "copy-application".equals(name);
                       }))
       .subscribe(testSubscriber().assertCount(2));
 }
 @Test
 public void create() {
   this.spaceId
       .then(
           spaceId ->
               Mono.when(
                   Mono.just(spaceId),
                   this.cloudFoundryClient
                       .applicationsV2()
                       .create(
                           CreateApplicationRequest.builder()
                               .name("test-application-2")
                               .spaceId(spaceId)
                               .build())
                       .map(ResourceUtils::getEntity)))
       .subscribe(
           this.<Tuple2<String, ApplicationEntity>>testSubscriber()
               .assertThat(
                   consumer(
                       (spaceId, entity) -> {
                         assertEquals(spaceId, entity.getSpaceId());
                         assertEquals("test-application-2", entity.getName());
                       })));
 }