@Test void getLatestUnusedPackageWithNoPackagesNoDroplet() { Mockito.when(client.getCurrentDropletForApplication(APPLICATION_GUID)) .thenThrow(getNotFoundCloudOperationException()); Optional<CloudPackage> latestUnusedPackage = cloudPackagesGetter.getLatestUnusedPackage(client, APPLICATION_GUID); assertFalse(latestUnusedPackage.isPresent()); }
public Optional<CloudPackage> getLatestUnusedPackage(CloudControllerClient client, UUID applicationGuid) { Optional<DropletInfo> currentDropletForApplication = findOrReturnEmpty(() -> client.getCurrentDropletForApplication(applicationGuid)); if (!currentDropletForApplication.isPresent()) { return getMostRecentCloudPackage(client, applicationGuid); } Optional<CloudPackage> currentCloudPackage = findOrReturnEmpty(() -> client.getPackage(currentDropletForApplication.get() .getPackageGuid())); if (!currentCloudPackage.isPresent()) { return Optional.empty(); } LOGGER.info(MessageFormat.format(Messages.CURRENTLY_USED_PACKAGE_0, SecureSerialization.toJson(currentCloudPackage.get()))); Optional<CloudPackage> mostRecentApplicationPackage = getMostRecentCloudPackage(client, applicationGuid); if (!mostRecentApplicationPackage.isPresent()) { return Optional.empty(); } if (!isCurrentCloudPackageUpToDate(currentCloudPackage.get(), mostRecentApplicationPackage.get())) { return mostRecentApplicationPackage; } return Optional.empty(); }
CloudPackagesGetter { public Optional<CloudPackage> getLatestUnusedPackage(CloudControllerClient client, UUID applicationGuid) { Optional<DropletInfo> currentDropletForApplication = findOrReturnEmpty(() -> client.getCurrentDropletForApplication(applicationGuid)); if (!currentDropletForApplication.isPresent()) { return getMostRecentCloudPackage(client, applicationGuid); } Optional<CloudPackage> currentCloudPackage = findOrReturnEmpty(() -> client.getPackage(currentDropletForApplication.get() .getPackageGuid())); if (!currentCloudPackage.isPresent()) { return Optional.empty(); } LOGGER.info(MessageFormat.format(Messages.CURRENTLY_USED_PACKAGE_0, SecureSerialization.toJson(currentCloudPackage.get()))); Optional<CloudPackage> mostRecentApplicationPackage = getMostRecentCloudPackage(client, applicationGuid); if (!mostRecentApplicationPackage.isPresent()) { return Optional.empty(); } if (!isCurrentCloudPackageUpToDate(currentCloudPackage.get(), mostRecentApplicationPackage.get())) { return mostRecentApplicationPackage; } return Optional.empty(); } }
CloudPackagesGetter { public Optional<CloudPackage> getLatestUnusedPackage(CloudControllerClient client, UUID applicationGuid) { Optional<DropletInfo> currentDropletForApplication = findOrReturnEmpty(() -> client.getCurrentDropletForApplication(applicationGuid)); if (!currentDropletForApplication.isPresent()) { return getMostRecentCloudPackage(client, applicationGuid); } Optional<CloudPackage> currentCloudPackage = findOrReturnEmpty(() -> client.getPackage(currentDropletForApplication.get() .getPackageGuid())); if (!currentCloudPackage.isPresent()) { return Optional.empty(); } LOGGER.info(MessageFormat.format(Messages.CURRENTLY_USED_PACKAGE_0, SecureSerialization.toJson(currentCloudPackage.get()))); Optional<CloudPackage> mostRecentApplicationPackage = getMostRecentCloudPackage(client, applicationGuid); if (!mostRecentApplicationPackage.isPresent()) { return Optional.empty(); } if (!isCurrentCloudPackageUpToDate(currentCloudPackage.get(), mostRecentApplicationPackage.get())) { return mostRecentApplicationPackage; } return Optional.empty(); }  }
CloudPackagesGetter { public Optional<CloudPackage> getLatestUnusedPackage(CloudControllerClient client, UUID applicationGuid) { Optional<DropletInfo> currentDropletForApplication = findOrReturnEmpty(() -> client.getCurrentDropletForApplication(applicationGuid)); if (!currentDropletForApplication.isPresent()) { return getMostRecentCloudPackage(client, applicationGuid); } Optional<CloudPackage> currentCloudPackage = findOrReturnEmpty(() -> client.getPackage(currentDropletForApplication.get() .getPackageGuid())); if (!currentCloudPackage.isPresent()) { return Optional.empty(); } LOGGER.info(MessageFormat.format(Messages.CURRENTLY_USED_PACKAGE_0, SecureSerialization.toJson(currentCloudPackage.get()))); Optional<CloudPackage> mostRecentApplicationPackage = getMostRecentCloudPackage(client, applicationGuid); if (!mostRecentApplicationPackage.isPresent()) { return Optional.empty(); } if (!isCurrentCloudPackageUpToDate(currentCloudPackage.get(), mostRecentApplicationPackage.get())) { return mostRecentApplicationPackage; } return Optional.empty(); }  Optional<CloudPackage> getLatestUnusedPackage(CloudControllerClient client, UUID applicationGuid); }
CloudPackagesGetter { public Optional<CloudPackage> getLatestUnusedPackage(CloudControllerClient client, UUID applicationGuid) { Optional<DropletInfo> currentDropletForApplication = findOrReturnEmpty(() -> client.getCurrentDropletForApplication(applicationGuid)); if (!currentDropletForApplication.isPresent()) { return getMostRecentCloudPackage(client, applicationGuid); } Optional<CloudPackage> currentCloudPackage = findOrReturnEmpty(() -> client.getPackage(currentDropletForApplication.get() .getPackageGuid())); if (!currentCloudPackage.isPresent()) { return Optional.empty(); } LOGGER.info(MessageFormat.format(Messages.CURRENTLY_USED_PACKAGE_0, SecureSerialization.toJson(currentCloudPackage.get()))); Optional<CloudPackage> mostRecentApplicationPackage = getMostRecentCloudPackage(client, applicationGuid); if (!mostRecentApplicationPackage.isPresent()) { return Optional.empty(); } if (!isCurrentCloudPackageUpToDate(currentCloudPackage.get(), mostRecentApplicationPackage.get())) { return mostRecentApplicationPackage; } return Optional.empty(); }  Optional<CloudPackage> getLatestUnusedPackage(CloudControllerClient client, UUID applicationGuid);  }