ReleasesProviderImpl implements ReleasesProvider { public Releases getReleases(String projectId, Release oldRelease, UUID correlationId) throws InvalidOctopusApiKeyException, InvalidOctopusUrlException, ProjectNotFoundException, ReleasesProviderException { String url = null; try { HttpContentProvider contentProvider = httpContentProviderFactory.getContentProvider(); url = contentProvider.getUrl(); LOG.debug(String.format("%s: Getting releases from %s for project id '%s'", correlationId, contentProvider.getUrl(), projectId)); final ApiRootResponse apiRootResponse = getApiRootResponse(contentProvider, correlationId); final Project project = getProject(projectId, contentProvider, apiRootResponse, correlationId); return getReleases(oldRelease, contentProvider, project, correlationId); } catch (InvalidOctopusApiKeyException | InvalidOctopusUrlException | ProjectNotFoundException e) { throw e; } catch (Throwable e) { throw new ReleasesProviderException(String.format("Unexpected exception in ReleasesProviderImpl, while attempting to get releases from %s: %s", url, e), e); } } ReleasesProviderImpl(HttpContentProviderFactory httpContentProviderFactory, AnalyticsTracker analyticsTracker); Releases getReleases(String projectId, Release oldRelease, UUID correlationId);  }
@Test(groups = {"needs-real-server"}) public void get_releases_from_real_server() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, ProjectNotFoundException, ReleasesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new HttpContentProviderFactory(realOctopusUrl, realOctopusApiKey, new FakeBuildTriggerProperties(), new FakeCacheManager(), new FakeMetricRegistry()); ReleasesProviderImpl ReleasesProviderImpl = new ReleasesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Release oldRelease = new NullRelease(); UUID correlationId = UUID.randomUUID(); Releases newReleases = ReleasesProviderImpl.getReleases(ProjectWithLatestReleaseSuccessful, oldRelease, correlationId); Assert.assertNotNull(newReleases); }
@Test(expectedExceptions = ProjectNotFoundException.class) public void get_releases_with_invalid_project() throws ProjectNotFoundException, ReleasesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey); ReleasesProviderImpl ReleasesProviderImpl = new ReleasesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Release oldRelease = new NullRelease(); UUID correlationId = UUID.randomUUID(); ReleasesProviderImpl.getReleases(ProjectThatDoesNotExist, oldRelease, correlationId); }
@Test(expectedExceptions = InvalidOctopusUrlException.class) public void get_releases_with_octopus_url_with_invalid_host() throws ProjectNotFoundException, ReleasesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory("http: ReleasesProviderImpl ReleasesProviderImpl = new ReleasesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Release oldRelease = new NullRelease(); UUID correlationId = UUID.randomUUID(); ReleasesProviderImpl.getReleases(ProjectWithLatestReleaseSuccessful, oldRelease, correlationId); }
@Test(expectedExceptions = InvalidOctopusUrlException.class) public void get_releases_with_octopus_url_with_invalid_path() throws ProjectNotFoundException, ReleasesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl + "/not-an-octopus-instance", octopusApiKey); ReleasesProviderImpl ReleasesProviderImpl = new ReleasesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Release oldRelease = new NullRelease(); UUID correlationId = UUID.randomUUID(); ReleasesProviderImpl.getReleases(ProjectWithLatestReleaseSuccessful, oldRelease, correlationId); }
@Test(expectedExceptions = InvalidOctopusApiKeyException.class) public void get_releases_with_invalid_octopus_api_key() throws ProjectNotFoundException, ReleasesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, "invalid-api-key"); ReleasesProviderImpl ReleasesProviderImpl = new ReleasesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Release oldRelease = new NullRelease(); UUID correlationId = UUID.randomUUID(); ReleasesProviderImpl.getReleases(ProjectWithLatestReleaseSuccessful, oldRelease, correlationId); }
@Test(expectedExceptions = ReleasesProviderException.class) public void rethrows_throwable_exceptions_as_deployment_provider_exception() throws ProjectNotFoundException, ReleasesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(new OutOfMemoryError()); ReleasesProviderImpl ReleasesProviderImpl = new ReleasesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Release oldRelease = new NullRelease(); UUID correlationId = UUID.randomUUID(); ReleasesProviderImpl.getReleases(ProjectWithLatestReleaseSuccessful, oldRelease, correlationId); }