DeploymentsProviderImpl implements DeploymentsProvider { public Environments getDeployments(String projectId, Environments oldEnvironments, UUID correlationId) throws DeploymentsProviderException, ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { String url = null; try { HttpContentProvider contentProvider = httpContentProviderFactory.getContentProvider(); url = contentProvider.getUrl(); LOG.debug(String.format("%s: Getting deployments 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 getDeployments(projectId, oldEnvironments, contentProvider, apiRootResponse, project, correlationId); } catch (ProjectNotFoundException | InvalidOctopusApiKeyException | InvalidOctopusUrlException e) { throw e; } catch (Throwable e) { throw new DeploymentsProviderException(String.format("Unexpected exception in DeploymentsProviderImpl, while attempting to get deployments from %s: %s", url, e), e); } } DeploymentsProviderImpl(HttpContentProviderFactory httpContentProviderFactory, AnalyticsTracker analyticsTracker); Environments getDeployments(String projectId, Environments oldEnvironments, UUID correlationId);  }
@Test(groups = {"needs-real-server"}) public void get_deployments_from_real_server() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, ProjectNotFoundException, DeploymentsProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new HttpContentProviderFactory(realOctopusUrl, realOctopusApiKey, new FakeBuildTriggerProperties(), new FakeCacheManager(), new FakeMetricRegistry()); DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Environments oldEnvironments = new Environments(); UUID correlationId = UUID.randomUUID(); Environments newEnvironments = deploymentsProviderImpl.getDeployments(ProjectWithLatestDeploymentSuccessful, oldEnvironments, correlationId); Assert.assertNotNull(newEnvironments); }
@Test(expectedExceptions = ProjectNotFoundException.class) public void get_deployments_with_invalid_project() throws ProjectNotFoundException, DeploymentsProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey); DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Environments oldEnvironments = new Environments(); UUID correlationId = UUID.randomUUID(); deploymentsProviderImpl.getDeployments(ProjectThatDoesNotExist, oldEnvironments, correlationId); }
@Test(expectedExceptions = InvalidOctopusUrlException.class) public void get_deployments_with_octopus_url_with_invalid_host() throws ProjectNotFoundException, DeploymentsProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory("http: DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Environments oldEnvironments = new Environments(); UUID correlationId = UUID.randomUUID(); deploymentsProviderImpl.getDeployments(ProjectWithLatestDeploymentSuccessful, oldEnvironments, correlationId); }
@Test(expectedExceptions = InvalidOctopusUrlException.class) public void get_deployments_with_octopus_url_with_invalid_path() throws ProjectNotFoundException, DeploymentsProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl + "/not-an-octopus-instance", octopusApiKey); DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Environments oldEnvironments = new Environments(); UUID correlationId = UUID.randomUUID(); deploymentsProviderImpl.getDeployments(ProjectWithLatestDeploymentSuccessful, oldEnvironments, correlationId); }
@Test(expectedExceptions = InvalidOctopusApiKeyException.class) public void get_deployments_with_invalid_octopus_api_key() throws ProjectNotFoundException, DeploymentsProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, "invalid-api-key"); DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Environments oldEnvironments = new Environments(); UUID correlationId = UUID.randomUUID(); deploymentsProviderImpl.getDeployments(ProjectWithLatestDeploymentSuccessful, oldEnvironments, correlationId); }
@Test(expectedExceptions = DeploymentsProviderException.class) public void rethrows_throwable_exceptions_as_deployment_provider_exception() throws ProjectNotFoundException, DeploymentsProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(new OutOfMemoryError()); DeploymentsProviderImpl deploymentsProviderImpl = new DeploymentsProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Environments oldEnvironments = new Environments(); UUID correlationId = UUID.randomUUID(); deploymentsProviderImpl.getDeployments(ProjectWithLatestDeploymentSuccessful, oldEnvironments, correlationId); }