DeploymentProcessProviderImpl implements DeploymentProcessProvider { public String getDeploymentProcessVersion(String projectId, UUID correlationId) throws ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException, DeploymentProcessProviderException { 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 getDeploymentProcessVersion(project, contentProvider, correlationId); } catch (ProjectNotFoundException | InvalidOctopusApiKeyException | InvalidOctopusUrlException e) { throw e; } catch (Throwable e) { throw new DeploymentProcessProviderException(String.format("Unexpected exception in DeploymentsProviderImpl, while attempting to get deployments from %s: %s", url, e), e); } } DeploymentProcessProviderImpl(HttpContentProviderFactory httpContentProviderFactory, AnalyticsTracker analyticsTracker); String getDeploymentProcessVersion(String projectId, UUID correlationId);  }
@Test(groups = {"needs-real-server"}) public void get_deployment_process_version_from_real_server() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, ProjectNotFoundException, DeploymentProcessProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new HttpContentProviderFactory(realOctopusUrl, realOctopusApiKey, new FakeBuildTriggerProperties(), new FakeCacheManager(), new FakeMetricRegistry()); DeploymentProcessProviderImpl deploymentProcessProviderImpl = new DeploymentProcessProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); String newVersion = deploymentProcessProviderImpl.getDeploymentProcessVersion(ProjectWithLatestDeploymentSuccessful, correlationId); Assert.assertNotNull(newVersion); }
@Test(expectedExceptions = ProjectNotFoundException.class) public void get_deployment_process_version_with_invalid_project() throws ProjectNotFoundException, DeploymentProcessProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey); DeploymentProcessProviderImpl deploymentProcessProviderImpl = new DeploymentProcessProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); deploymentProcessProviderImpl.getDeploymentProcessVersion(ProjectThatDoesNotExist, correlationId); }
@Test(expectedExceptions = InvalidOctopusUrlException.class) public void get_deployment_process_version_with_octopus_url_with_invalid_host() throws ProjectNotFoundException, DeploymentProcessProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory("http: DeploymentProcessProviderImpl deploymentProcessProviderImpl = new DeploymentProcessProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); deploymentProcessProviderImpl.getDeploymentProcessVersion(ProjectWithLatestDeploymentSuccessful, correlationId); }
@Test(expectedExceptions = InvalidOctopusUrlException.class) public void get_deployment_process_version_with_octopus_url_with_invalid_path() throws ProjectNotFoundException, DeploymentProcessProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl + "/not-an-octopus-instance", octopusApiKey); DeploymentProcessProviderImpl deploymentProcessProviderImpl = new DeploymentProcessProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); deploymentProcessProviderImpl.getDeploymentProcessVersion(ProjectWithLatestDeploymentSuccessful, correlationId); }
@Test(expectedExceptions = InvalidOctopusApiKeyException.class) public void get_deployment_process_version_with_invalid_octopus_api_key() throws ProjectNotFoundException, DeploymentProcessProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, "invalid-api-key"); DeploymentProcessProviderImpl deploymentProcessProviderImpl = new DeploymentProcessProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); deploymentProcessProviderImpl.getDeploymentProcessVersion(ProjectWithLatestDeploymentSuccessful, correlationId); }
@Test(expectedExceptions = DeploymentProcessProviderException.class) public void rethrows_throwable_exceptions_as_deployment_process_provider_exception() throws ProjectNotFoundException, DeploymentProcessProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(new OutOfMemoryError()); DeploymentProcessProviderImpl deploymentProcessProviderImpl = new DeploymentProcessProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); deploymentProcessProviderImpl.getDeploymentProcessVersion(ProjectWithLatestDeploymentSuccessful, correlationId); }