diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ApiDeploymentsResponse.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ApiDeploymentsResponse.java index dda5fae..f7b7ad2 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ApiDeploymentsResponse.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ApiDeploymentsResponse.java @@ -75,7 +75,7 @@ private boolean ProcessDeployment(HttpContentProvider contentProvider, Deploymen GetTask(contentProvider, result, deployment, environmentId, createdDate); - if (result.haveAllDeploymentsFinishedSuccessfully()) { + if (result.haveAllEnvironmentsHadAtLeastOneSuccessfulDeployment()) { LOG.debug("All deployments have finished successfully - no need to keep iterating"); return true; } diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ApiProgressionResponse.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ApiProgressionResponse.java index 4987f66..a4ac452 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ApiProgressionResponse.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ApiProgressionResponse.java @@ -62,7 +62,7 @@ private boolean Parse(String progressionResponse) throws java.text.ParseExceptio return true; } - if (deployments.haveAllDeploymentsFinishedSuccessfully()) { + if (deployments.haveAllEnvironmentsHadAtLeastOneSuccessfulDeployment()) { LOG.debug("All deployments have finished successfully - no need to parse deployment response"); return true; } diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/Deployment.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/Deployment.java index 51e563d..1cf5c15 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/Deployment.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/Deployment.java @@ -45,9 +45,11 @@ public boolean isLatestSuccessfulDeploymentOlderThen(OctopusDate compareDate) { } public boolean isSuccessful() { - OctopusDate testDate = new OctopusDate(2000, 1, 1); + return this.latestSuccessfulDeployment.compareTo(this.latestDeployment) == 0; + } - return this.latestSuccessfulDeployment.compareTo(testDate) > 0; + public boolean hasHadAtLeastOneSuccessfulDeployment() { + return this.latestSuccessfulDeployment.compareTo(new NullOctopusDate()) > 0; } @Override diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteAsyncBuildTrigger.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteAsyncBuildTrigger.java index a84e35c..8f2f3d3 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteAsyncBuildTrigger.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteAsyncBuildTrigger.java @@ -56,7 +56,10 @@ public int getPollInterval(@NotNull AsyncTriggerParameters parameters) { @NotNull public CheckJob createJob(@NotNull final AsyncTriggerParameters asyncTriggerParameters) throws CheckJobCreationException { - return new DeploymentCompleteCheckJob(asyncTriggerParameters, displayName); + return new DeploymentCompleteCheckJob(displayName, + asyncTriggerParameters.getBuildType().toString(), + asyncTriggerParameters.getCustomDataStorage(), + asyncTriggerParameters.getTriggerDescriptor().getProperties()); } @NotNull diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteCheckJob.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteCheckJob.java index eef62f3..10d24e5 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteCheckJob.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteCheckJob.java @@ -19,7 +19,6 @@ import com.intellij.openapi.diagnostic.Logger; import com.mjrichardson.teamCity.buildTriggers.OctopusBuildTriggerUtil; import jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor; -import jetbrains.buildServer.buildTriggers.async.AsyncTriggerParameters; import jetbrains.buildServer.buildTriggers.async.CheckJob; import jetbrains.buildServer.buildTriggers.async.CheckResult; import jetbrains.buildServer.serverSide.CustomDataStorage; @@ -35,12 +34,22 @@ class DeploymentCompleteCheckJob implements CheckJob { @NotNull private static final Logger LOG = Logger.getInstance(DeploymentCompleteBuildTrigger.class.getName()); - private final AsyncTriggerParameters asyncTriggerParameters; private final String displayName; + private final String buildType; + private final CustomDataStorage dataStorage; + private final Map props; + private final DeploymentsProviderFactory deploymentsProviderFactory; - public DeploymentCompleteCheckJob(AsyncTriggerParameters asyncTriggerParameters, String displayName) { - this.asyncTriggerParameters = asyncTriggerParameters; + public DeploymentCompleteCheckJob(String displayName, String buildType, CustomDataStorage dataStorage, Map properties) { + this(new DeploymentsProviderFactory(), displayName, buildType, dataStorage, properties); + } + + public DeploymentCompleteCheckJob(DeploymentsProviderFactory deploymentsProviderFactory, String displayName, String buildType, CustomDataStorage dataStorage, Map properties) { + this.deploymentsProviderFactory = deploymentsProviderFactory; this.displayName = displayName; + this.buildType = buildType; + this.dataStorage = dataStorage; + this.props = properties; } @NotNull @@ -52,9 +61,10 @@ CheckResult getCheckResult(String octopusUrl, String oct try { final String oldStoredData = dataStorage.getValue(dataStorageKey); final Deployments oldDeployments = new Deployments(oldStoredData); + final Integer connectionTimeout = OctopusBuildTriggerUtil.DEFAULT_CONNECTION_TIMEOUT;//triggerParameters.getConnectionTimeout(); //todo:fix + DeploymentsProvider provider = deploymentsProviderFactory.getProvider(octopusUrl, octopusApiKey, connectionTimeout); - DeploymentsProvider provider = new DeploymentsProvider(octopusUrl, octopusApiKey, connectionTimeout, LOG); final Deployments newDeployments = provider.getDeployments(octopusProject, oldDeployments); //only store that one deployment to one environment has happened here, not multiple environment. @@ -88,37 +98,34 @@ CheckResult getCheckResult(String octopusUrl, String oct return DeploymentCompleteSpecCheckResult.createEmptyResult(); } catch (Exception e) { - final DeploymentCompleteSpec deploymentCompleteSpec = new DeploymentCompleteSpec(octopusUrl, octopusProject); - return DeploymentCompleteSpecCheckResult.createThrowableResult(deploymentCompleteSpec, e); + return DeploymentCompleteSpecCheckResult.createThrowableResult(e); } } @NotNull public CheckResult perform() { - final Map props = asyncTriggerParameters.getTriggerDescriptor().getProperties(); final String octopusUrl = props.get(OCTOPUS_URL); if (StringUtil.isEmptyOrSpaces(octopusUrl)) { return DeploymentCompleteSpecCheckResult.createErrorResult(String.format("%s settings are invalid (empty url) in build configuration %s", - displayName, asyncTriggerParameters.getBuildType())); + displayName, this.buildType)); } final String octopusApiKey = props.get(OCTOPUS_APIKEY); if (StringUtil.isEmptyOrSpaces(octopusApiKey)) { return DeploymentCompleteSpecCheckResult.createErrorResult(String.format("%s settings are invalid (empty api key) in build configuration %s", - displayName, asyncTriggerParameters.getBuildType())); + displayName, this.buildType)); } final String octopusProject = props.get(OCTOPUS_PROJECT_ID); if (StringUtil.isEmptyOrSpaces(octopusProject)) { return DeploymentCompleteSpecCheckResult.createErrorResult(String.format("%s settings are invalid (empty project) in build configuration %s", - displayName, asyncTriggerParameters.getBuildType())); + displayName, this.buildType)); } final Boolean triggerOnlyOnSuccessfulDeployment = Boolean.parseBoolean(props.get(OCTOPUS_TRIGGER_ONLY_ON_SUCCESSFUL_DEPLOYMENT)); - return getCheckResult(octopusUrl, octopusApiKey, octopusProject, - triggerOnlyOnSuccessfulDeployment, asyncTriggerParameters.getCustomDataStorage()); + return getCheckResult(octopusUrl, octopusApiKey, octopusProject, triggerOnlyOnSuccessfulDeployment, dataStorage); } public boolean allowSchedule(@NotNull BuildTriggerDescriptor buildTriggerDescriptor) { diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteSpec.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteSpec.java index bffcd6b..1971924 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteSpec.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteSpec.java @@ -41,10 +41,10 @@ class DeploymentCompleteSpec { } public String getRequestorString() { - if (wasSuccessful == null) + if (environmentId == null || environmentId == null) return String.format("Unsuccessful attempt to get deployments for %s on %s", project, url); if (wasSuccessful) return String.format("Successful deployment of %s to %s on %s", project, environmentId, url); - return String.format("Deployment of %s on %s", project, url); + return String.format("Deployment of %s to %s on %s", project, environmentId, url); } } diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/Deployments.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/Deployments.java index e26b6f7..d63973e 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/Deployments.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/Deployments.java @@ -51,6 +51,11 @@ public Deployments() throws ParseException { this(""); } + public Deployments(Deployment deployment) throws ParseException { + this(""); + addOrUpdate(deployment); + } + @Override public String toString() { String result = ""; @@ -166,10 +171,10 @@ private void addOrUpdate(String environmentId, OctopusDate latestDeployment, Oct } } - public boolean haveAllDeploymentsFinishedSuccessfully() { + public boolean haveAllEnvironmentsHadAtLeastOneSuccessfulDeployment() { boolean result = true; for (Deployment deployment: statusMap) { - result = result & deployment.isSuccessful(); + result = result & deployment.hasHadAtLeastOneSuccessfulDeployment(); } return result; } diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProvider.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProvider.java index 84e6c45..8eefb23 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProvider.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProvider.java @@ -1,83 +1,11 @@ -/* - * Copyright 2000-2013 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete; - -import com.intellij.openapi.diagnostic.Logger; -import com.mjrichardson.teamCity.buildTriggers.*; - -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; - -//todo needs tests -public final class DeploymentsProvider { - - private final HttpContentProvider contentProvider; - private final Logger LOG; - - public DeploymentsProvider(String octopusUrl, String apiKey, Integer connectionTimeout, Logger log) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - this(new HttpContentProviderImpl(log, octopusUrl, apiKey, connectionTimeout), log); - } - - public DeploymentsProvider(HttpContentProvider contentProvider, Logger log) - { - this.contentProvider = contentProvider; - this.LOG = log; - } - - public Deployments getDeployments(String projectId, Deployments oldDeployments) throws DeploymentsProviderException, ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { - //get {octopusurl}/api - //parse out project url - //parse out progression url - //call project url - //parse id for project - //call progression url for project id - //return NewDeploymentStatus(responseBody); - - try { - LOG.debug("DeploymentCompleteBuildTrigger: Getting deployments from " + contentProvider.getUrl() + " for project id '" + projectId + "'"); - - final String apiResponse = contentProvider.getContent("/api"); - final ApiRootResponse apiRootResponse = new ApiRootResponse(apiResponse); - - final String progressionResponse = contentProvider.getContent(apiRootResponse.progressionApiLink + "/" + projectId); - final ApiProgressionResponse apiProgressionResponse = new ApiProgressionResponse(progressionResponse); - - if (apiProgressionResponse.haveCompleteInformation) - return apiProgressionResponse.deployments; - - final ApiDeploymentsResponse apiDeploymentsResponse = new ApiDeploymentsResponse( - contentProvider, apiRootResponse.deploymentsApiLink, projectId, - oldDeployments, apiProgressionResponse.deployments); - - return apiDeploymentsResponse.deployments; - } - catch (InvalidOctopusApiKeyException e) { - throw e; - } - catch (InvalidOctopusUrlException e) { - throw e; - } - catch (ProjectNotFoundException e) { - throw e; - } - catch (Throwable e) { - //todo: improve error message here - throw new DeploymentsProviderException("URL " + contentProvider.getUrl() + ": " + e, e); - } - } -} +package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete; + +import com.mjrichardson.teamCity.buildTriggers.InvalidOctopusApiKeyException; +import com.mjrichardson.teamCity.buildTriggers.InvalidOctopusUrlException; +import com.mjrichardson.teamCity.buildTriggers.ProjectNotFoundException; + +import java.text.ParseException; + +public interface DeploymentsProvider { + Deployments getDeployments(String octopusProject, Deployments oldDeployments) throws DeploymentsProviderException, ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException, ParseException; +} diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderFactory.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderFactory.java new file mode 100644 index 0000000..c402612 --- /dev/null +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderFactory.java @@ -0,0 +1,12 @@ +package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete; + +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; + + +public class DeploymentsProviderFactory { + public DeploymentsProvider getProvider(String octopusUrl, String octopusApiKey, Integer connectionTimeout) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + return new DeploymentsProviderImpl(octopusUrl, octopusApiKey, connectionTimeout); + } +} diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderImpl.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderImpl.java new file mode 100644 index 0000000..e2e8ad5 --- /dev/null +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderImpl.java @@ -0,0 +1,84 @@ +/* + * Copyright 2000-2013 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete; + +import com.intellij.openapi.diagnostic.Logger; +import com.mjrichardson.teamCity.buildTriggers.*; +import org.jetbrains.annotations.NotNull; + +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; + +//todo needs tests +public class DeploymentsProviderImpl implements DeploymentsProvider { + + private final HttpContentProvider contentProvider; + @NotNull + private static final Logger LOG = Logger.getInstance(DeploymentsProviderImpl.class.getName()); + + public DeploymentsProviderImpl(String octopusUrl, String apiKey, Integer connectionTimeout) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + this(new HttpContentProviderImpl(octopusUrl, apiKey, connectionTimeout)); + } + + public DeploymentsProviderImpl(HttpContentProvider contentProvider) + { + this.contentProvider = contentProvider; + } + + public Deployments getDeployments(String projectId, Deployments oldDeployments) throws DeploymentsProviderException, ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { + //get {octopusurl}/api + //parse out project url + //parse out progression url + //call project url + //parse id for project + //call progression url for project id + //return NewDeploymentStatus(responseBody); + + try { + LOG.debug("DeploymentCompleteBuildTrigger: Getting deployments from " + contentProvider.getUrl() + " for project id '" + projectId + "'"); + + final String apiResponse = contentProvider.getContent("/api"); + final ApiRootResponse apiRootResponse = new ApiRootResponse(apiResponse); + + final String progressionResponse = contentProvider.getContent(apiRootResponse.progressionApiLink + "/" + projectId); + final ApiProgressionResponse apiProgressionResponse = new ApiProgressionResponse(progressionResponse); + + if (apiProgressionResponse.haveCompleteInformation) + return apiProgressionResponse.deployments; + + final ApiDeploymentsResponse apiDeploymentsResponse = new ApiDeploymentsResponse( + contentProvider, apiRootResponse.deploymentsApiLink, projectId, + oldDeployments, apiProgressionResponse.deployments); + + return apiDeploymentsResponse.deployments; + } + catch (InvalidOctopusApiKeyException e) { + throw e; + } + catch (InvalidOctopusUrlException e) { + throw e; + } + catch (ProjectNotFoundException e) { + throw e; + } + catch (Throwable e) { + //todo: improve error message here + throw new DeploymentsProviderException("URL " + contentProvider.getUrl() + ": " + e, e); + } + } +} diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/HttpContentProviderImpl.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/HttpContentProviderImpl.java index 77047a4..0998626 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/HttpContentProviderImpl.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/HttpContentProviderImpl.java @@ -45,14 +45,15 @@ //todo: needs tests public class HttpContentProviderImpl implements HttpContentProvider { - private final Logger LOG; + @NotNull + private static final Logger LOG = Logger.getInstance(HttpContentProviderImpl.class.getName()); + private final String octopusUrl; CloseableHttpClient httpClient; @NotNull private String apiKey; - public HttpContentProviderImpl(@NotNull Logger log, @NotNull String octopusUrl, @NotNull String apiKey, @NotNull Integer connectionTimeout) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - this.LOG = log; + public HttpContentProviderImpl(@NotNull String octopusUrl, @NotNull String apiKey, @NotNull Integer connectionTimeout) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { this.octopusUrl = octopusUrl; this.apiKey = apiKey; this.init(connectionTimeout); diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/OctopusConnectivityChecker.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/OctopusConnectivityChecker.java index 7524eed..69eb705 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/OctopusConnectivityChecker.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/OctopusConnectivityChecker.java @@ -11,7 +11,7 @@ public class OctopusConnectivityChecker { private HttpContentProvider contentProvider; public OctopusConnectivityChecker(String octopusUrl, String apiKey, Integer connectionTimeout, Logger log) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - this(new HttpContentProviderImpl(log, octopusUrl, apiKey, connectionTimeout), log); + this(new HttpContentProviderImpl(octopusUrl, apiKey, connectionTimeout), log); } OctopusConnectivityChecker(HttpContentProvider contentProvider, Logger log) { diff --git a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ReleaseCreated/ReleasesProvider.java b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ReleaseCreated/ReleasesProvider.java index 60888dc..0d3c69b 100644 --- a/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ReleaseCreated/ReleasesProvider.java +++ b/octopus-build-trigger-server/src/main/java/com/mjrichardson/teamCity/buildTriggers/ReleaseCreated/ReleasesProvider.java @@ -13,7 +13,7 @@ public class ReleasesProvider { private final HttpContentProvider contentProvider; public ReleasesProvider(String octopusUrl, String apiKey, Integer connectionTimeout, Logger log) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { - this(new HttpContentProviderImpl(log, octopusUrl, apiKey, connectionTimeout), log); + this(new HttpContentProviderImpl(octopusUrl, apiKey, connectionTimeout), log); } public ReleasesProvider(HttpContentProvider contentProvider, Logger log) diff --git a/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteCheckJobTest.java b/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteCheckJobTest.java new file mode 100644 index 0000000..787e63c --- /dev/null +++ b/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteCheckJobTest.java @@ -0,0 +1,348 @@ +package com.mjrichardson.teamCity.buildTriggers.DeploymentComplete; + +import com.mjrichardson.teamCity.buildTriggers.*; +import jetbrains.buildServer.buildTriggers.BuildTriggerDescriptor; +import jetbrains.buildServer.buildTriggers.BuildTriggerService; +import jetbrains.buildServer.buildTriggers.async.CheckResult; +import jetbrains.buildServer.serverSide.CustomDataStorage; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.testng.Assert; +import org.testng.annotations.DataProvider; +import org.testng.annotations.Test; + +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.text.ParseException; +import java.util.HashMap; +import java.util.Map; + +import static com.mjrichardson.teamCity.buildTriggers.OctopusBuildTriggerUtil.*; + +@Test +public class DeploymentCompleteCheckJobTest { + + @DataProvider(name = "NullAndEmpty") + public static Object[][] NullAndEmpty() { + return new Object[][] {{""}, {null}}; + } + + @Test(dataProvider = "NullAndEmpty") + public void perform_returns_an_error_result_if_octopus_url_is_invalid(String value) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithNoDeployments()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage(); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, value); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertEquals(result.getGeneralError().getMessage(), "the-display-name settings are invalid (empty url) in build configuration the-build-type"); + Assert.assertFalse(result.updatesDetected()); + Assert.assertTrue(result.hasCheckErrors()); + } + + @Test(dataProvider = "NullAndEmpty") + public void perform_returns_an_error_result_if_octopus_apikey_is_invalid(String value) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithNoDeployments()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage(); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, value); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertEquals(result.getGeneralError().getMessage(), "the-display-name settings are invalid (empty api key) in build configuration the-build-type"); + Assert.assertFalse(result.updatesDetected()); + Assert.assertTrue(result.hasCheckErrors()); + } + + @Test(dataProvider = "NullAndEmpty") + public void perform_returns_an_error_result_if_octopus_project_id_is_invalid(String value) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithNoDeployments()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage(); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, "the-api-key"); + properties.put(OCTOPUS_PROJECT_ID, value); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertEquals(result.getGeneralError().getMessage(), "the-display-name settings are invalid (empty project) in build configuration the-build-type"); + Assert.assertFalse(result.updatesDetected()); + Assert.assertTrue(result.hasCheckErrors()); + } + + public void perform_returns_an_error_result_if_exception_occurs() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderThatThrowsExceptions()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage(); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, "the-api-key"); + properties.put(OCTOPUS_PROJECT_ID, "the-project-id"); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertFalse(result.updatesDetected()); + Assert.assertTrue(result.hasCheckErrors()); + Assert.assertNotNull(result.getGeneralError()); + } + + public void perform_returns_empty_result_if_no_new_deployments_available() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithOneDeployment()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage("Environments-1;2016-02-25T00:00:00.000+00:00;2016-02-25T00:00:00.000+00:00;"); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, "the-api-key"); + properties.put(OCTOPUS_PROJECT_ID, "the-project-id"); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertFalse(result.updatesDetected()); + Assert.assertFalse(result.hasCheckErrors()); + } + + public void perform_returns_empty_result_if_no_previous_data_stored() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + //this situation is when trigger is first setup + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithOneDeployment()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage(); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, "the-api-key"); + properties.put(OCTOPUS_PROJECT_ID, "the-project-id"); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertFalse(result.updatesDetected()); + Assert.assertFalse(result.hasCheckErrors()); + } + + public void perform_returns_empty_result_if_new_deployment_but_it_failed_when_only_triggering_on_successful_builds() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithOneFailedDeployment()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage("Environments-1;2016-02-01T00:00:00.000+00:00;2016-02-01T00:00:00.000+00:00;"); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, "the-api-key"); + properties.put(OCTOPUS_PROJECT_ID, "the-project-id"); + properties.put(OCTOPUS_TRIGGER_ONLY_ON_SUCCESSFUL_DEPLOYMENT, "true"); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertFalse(result.updatesDetected()); + Assert.assertFalse(result.hasCheckErrors()); + } + + public void perform_returns_updated_result_if_new_deployment_but_it_failed_when_triggering_on_all_builds() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithOneFailedDeployment()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage("Environments-1;2016-02-01T00:00:00.000+00:00;2016-02-01T00:00:00.000+00:00;"); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, "the-api-key"); + properties.put(OCTOPUS_PROJECT_ID, "the-project-id"); + properties.put(OCTOPUS_TRIGGER_ONLY_ON_SUCCESSFUL_DEPLOYMENT, "false"); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertTrue(result.updatesDetected()); + Assert.assertFalse(result.hasCheckErrors()); + Assert.assertEquals(result.getUpdated().size(), 1); + DeploymentCompleteSpec updated[] = result.getUpdated().toArray(new DeploymentCompleteSpec[0]); + Assert.assertEquals(updated[0].getRequestorString(), "Deployment of the-project-id to Environments-1 on the-url"); + } + + public void perform_returns_updated_result_if_new_deployment() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithOneDeployment()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage("Environments-1;2016-02-01T00:00:00.000+00:00;2016-02-01T00:00:00.000+00:00;"); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, "the-api-key"); + properties.put(OCTOPUS_PROJECT_ID, "the-project-id"); + properties.put(OCTOPUS_TRIGGER_ONLY_ON_SUCCESSFUL_DEPLOYMENT, "true"); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + CheckResultresult = sut.perform(); + Assert.assertTrue(result.updatesDetected()); + Assert.assertFalse(result.hasCheckErrors()); + Assert.assertEquals(result.getUpdated().size(), 1); + DeploymentCompleteSpec updated[] = result.getUpdated().toArray(new DeploymentCompleteSpec[0]); + Assert.assertEquals(updated[0].getRequestorString(), "Successful deployment of the-project-id to Environments-1 on the-url"); + } + + public void allow_schedule_returns_false() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + //from comments in CheckJob.java from Jetbrains + // * Current check job may not be allowed to start for some reason, + // * i.e. build is running that may affect results of quite long check + // * @return true is this task should not be scheduled just now + + DeploymentsProviderFactory deploymentsProviderFactory = new FakeDeploymentsProviderFactory(new FakeDeploymentsProviderWithNoDeployments()); + String displayName = "the-display-name"; + String buildType = "the-build-type"; + CustomDataStorage dataStorage = new FakeCustomDataStorage("Environments-1;2016-02-01T00:00:00.000+00:00;2016-02-01T00:00:00.000+00:00;"); + + Map properties = new HashMap<>(); + properties.put(OCTOPUS_URL, "the-url"); + properties.put(OCTOPUS_APIKEY, "the-api-key"); + properties.put(OCTOPUS_PROJECT_ID, "the-project-id"); + properties.put(OCTOPUS_TRIGGER_ONLY_ON_SUCCESSFUL_DEPLOYMENT, "true"); + DeploymentCompleteCheckJob sut = new DeploymentCompleteCheckJob(deploymentsProviderFactory, displayName, buildType, dataStorage, properties); + Assert.assertFalse(sut.allowSchedule(new FakeBuildTriggerDescriptor())); + } + + class FakeDeploymentsProviderFactory extends DeploymentsProviderFactory { + private final DeploymentsProvider deploymentsProvider; + + public FakeDeploymentsProviderFactory(DeploymentsProvider deploymentsProvider) { + + this.deploymentsProvider = deploymentsProvider; + } + + @Override + public DeploymentsProvider getProvider(String octopusUrl, String octopusApiKey, Integer connectionTimeout) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { + return deploymentsProvider; + } + } + + private class FakeCustomDataStorage implements CustomDataStorage { + private final String storedDataValue; + + public FakeCustomDataStorage() { + this(null); + } + + public FakeCustomDataStorage(String storedDataValue) { + this.storedDataValue = storedDataValue; + } + + @Override + public void putValues(@NotNull Map map) { + + } + + @Nullable + @Override + public Map getValues() { + return null; + } + + @Nullable + @Override + public String getValue(@NotNull String s) { + return storedDataValue; + } + + @Override + public void putValue(@NotNull String s, @Nullable String s1) { + + } + + @Override + public void flush() { + + } + + @Override + public void dispose() { + + } + } + + private class FakeDeploymentsProviderWithOneDeployment implements DeploymentsProvider { + public FakeDeploymentsProviderWithOneDeployment() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {} + + @Override + public Deployments getDeployments(String octopusProject, Deployments oldDeployments) throws DeploymentsProviderException, ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException, ParseException { + Deployment deployment = new Deployment("Environments-1", new OctopusDate(2016, 02, 25), new OctopusDate(2016, 02, 25)); + return new Deployments(deployment); + } + } + + private class FakeDeploymentsProviderWithOneFailedDeployment implements DeploymentsProvider { + public FakeDeploymentsProviderWithOneFailedDeployment() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {} + + @Override + public Deployments getDeployments(String octopusProject, Deployments oldDeployments) throws DeploymentsProviderException, ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException, ParseException { + Deployment deployment = new Deployment("Environments-1", new OctopusDate(2016, 2, 25), new OctopusDate(2016, 2, 1)); + return new Deployments(deployment); + } + } + + private class FakeDeploymentsProviderWithNoDeployments implements DeploymentsProvider { + public FakeDeploymentsProviderWithNoDeployments() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {} + + @Override + public Deployments getDeployments(String octopusProject, Deployments oldDeployments) throws DeploymentsProviderException, ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException, ParseException { + return new Deployments(""); + } + } + + private class FakeDeploymentsProviderThatThrowsExceptions implements DeploymentsProvider { + public FakeDeploymentsProviderThatThrowsExceptions() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException {} + + @Override + public Deployments getDeployments(String octopusProject, Deployments oldDeployments) throws DeploymentsProviderException, ProjectNotFoundException, InvalidOctopusApiKeyException, InvalidOctopusUrlException, ParseException { + throw new ProjectNotFoundException(octopusProject); + } + } + + private class FakeBuildTriggerDescriptor implements BuildTriggerDescriptor { + @NotNull + @Override + public String getTriggerName() { + return null; + } + + @NotNull + @Override + public Map getProperties() { + return null; + } + + @NotNull + @Override + public String getSignature() { + return null; + } + + @NotNull + @Override + public BuildTriggerService getBuildTriggerService() { + return null; + } + + @NotNull + @Override + public String getId() { + return null; + } + + @NotNull + @Override + public String getType() { + return null; + } + + @NotNull + @Override + public Map getParameters() { + return null; + } + } +} diff --git a/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteSpecTest.java b/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteSpecTest.java index 1ab937d..4d7c784 100644 --- a/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteSpecTest.java +++ b/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentCompleteSpecTest.java @@ -21,6 +21,6 @@ public void when_successful_returns_success_message() throws Exception { @Test public void when_unsuccessful_returns_success_message() throws Exception { DeploymentCompleteSpec sut = new DeploymentCompleteSpec("theurl", "theproject", "theenv", false); - Assert.assertEquals(sut.getRequestorString(), "Deployment of theproject on theurl"); + Assert.assertEquals(sut.getRequestorString(), "Deployment of theproject to theenv on theurl"); } } diff --git a/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderTest.java b/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderTest.java index 725ae07..549ee67 100644 --- a/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderTest.java +++ b/octopus-build-trigger-server/src/test/java/com/mjrichardson/teamCity/buildTriggers/DeploymentComplete/DeploymentsProviderTest.java @@ -47,9 +47,8 @@ public class DeploymentsProviderTest { @Test(enabled = false) public void testGetDeploymentsFromRealServer() throws Exception { - HttpContentProvider contentProvider = new HttpContentProviderImpl(LOG, realOctopusUrl, realOctopusApiKey, OctopusBuildTriggerUtil.DEFAULT_CONNECTION_TIMEOUT - ); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + HttpContentProvider contentProvider = new HttpContentProviderImpl(realOctopusUrl, realOctopusApiKey, OctopusBuildTriggerUtil.DEFAULT_CONNECTION_TIMEOUT); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments("Project with latest deployment successful", oldDeployments); Assert.assertNotNull(newDeployments); @@ -57,7 +56,7 @@ public void testGetDeploymentsFromRealServer() throws Exception { public void testGetDeploymentsFromEmptyStart() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithLatestDeploymentSuccessful, oldDeployments); Assert.assertEquals(newDeployments.length(), 1); @@ -77,7 +76,7 @@ public void testGetDeploymentsFromEmptyStart() throws Exception { public void testGetDeploymentsFromEmptyStartWithNoReleases() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithNoReleases, oldDeployments); Assert.assertEquals(newDeployments.length(), 1); @@ -88,7 +87,7 @@ public void testGetDeploymentsFromEmptyStartWithNoReleases() throws Exception { public void testGetDeploymentsFromEmptyStartWithNoDeployments() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithNoDeployments, oldDeployments); Assert.assertEquals(newDeployments.length(), 1); @@ -101,7 +100,7 @@ public void testGetDeploymentsFromEmptyStartWithNoDeployments() throws Exception public void testGetDeploymentsWithInvalidProject() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); deploymentsProvider.getDeployments(ProjectThatDoesNotExist, oldDeployments); @@ -110,7 +109,7 @@ public void testGetDeploymentsWithInvalidProject() throws Exception { @Test(expectedExceptions = InvalidOctopusUrlException.class) public void testGetDeploymentsWithOctopusUrlWithInvalidHost() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider("http://octopus.example.com", octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); //todo: need another test around HttpContentProviderImpl @@ -120,7 +119,7 @@ public void testGetDeploymentsWithOctopusUrlWithInvalidHost() throws Exception { @Test(expectedExceptions = InvalidOctopusUrlException.class) public void testGetDeploymentsWithOctopusUrlWithInvalidPath() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl + "/not-an-octopus-instance", octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); //todo: need another test around HttpContentProviderImpl @@ -130,7 +129,7 @@ public void testGetDeploymentsWithOctopusUrlWithInvalidPath() throws Exception { @Test(expectedExceptions = InvalidOctopusApiKeyException.class) public void testGetDeploymentsWithInvalidOctopusApiKey() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, "invalid-api-key"); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); //todo: need another test around HttpContentProviderImpl @@ -139,7 +138,7 @@ public void testGetDeploymentsWithInvalidOctopusApiKey() throws Exception { public void testGetDeploymentsWhenUpToDate() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments("Environments-1;2016-01-21T13:31:56.022+00:00;2016-01-21T13:31:56.022+00:00"); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithLatestDeploymentSuccessful, oldDeployments); Assert.assertEquals(newDeployments.length(), 1); @@ -150,7 +149,7 @@ public void testGetDeploymentsWhenUpToDate() throws Exception { public void testGetDeploymentsWhenNoSuccessfulDeploymentsHaveOccurred() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithNoSuccessfulDeployments, oldDeployments); Assert.assertEquals(newDeployments.length(), 1); @@ -161,7 +160,7 @@ public void testGetDeploymentsWhenNoSuccessfulDeploymentsHaveOccurred() throws E public void testGetDeploymentsWhenNoSuccessfulDeploymentsOnFirstPageOfResults() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithNoRecentSuccessfulDeployments, oldDeployments); Assert.assertEquals(newDeployments.length(), 1); @@ -173,7 +172,7 @@ public void testGetDeploymentsWhenNoSuccessfulDeploymentsOnFirstPageOfResults() public void testGetDeploymentsWhenMultipleEnvironments() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithMultipleEnvironments, oldDeployments); Assert.assertEquals(newDeployments.length(), 2); @@ -187,7 +186,7 @@ public void testGetDeploymentsWhenMultipleEnvironments() throws Exception { public void testGetDeploymentsWhenNoReleases() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithNoReleases, oldDeployments); Assert.assertEquals(newDeployments.length(), 1); @@ -198,7 +197,7 @@ public void testGetDeploymentsWhenNoReleases() throws Exception { public void testWhenThereAreTwoNewDeploymentsSinceLastCheckItReturnsOnlyOne() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); final String oldData = "Environments-1;2016-01-19T14:00:00.000+00:00;2016-01-19T00:00:00.000+00:00|Environments-21;2016-01-20T14:00:00.000+00:00;2016-01-20T14:00:00.000+00:00"; Deployments oldDeployments = new Deployments(oldData); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithMultipleEnvironments, oldDeployments); @@ -222,7 +221,7 @@ public void testWhenThereAreTwoNewDeploymentsSinceLastCheckItReturnsOnlyOne() th public void testGetDeploymentsWhenMultipleEnvironmentsWithMostRecentDeploymentSuccessful() throws Exception { HttpContentProvider contentProvider = new FakeContentProvider(octopusUrl, octopusApiKey); - DeploymentsProvider deploymentsProvider = new DeploymentsProvider(contentProvider, LOG); + DeploymentsProviderImpl deploymentsProvider = new DeploymentsProviderImpl(contentProvider); Deployments oldDeployments = new Deployments(); Deployments newDeployments = deploymentsProvider.getDeployments(ProjectWithMultipleEnvironmentsAndMostRecentDeploymentSuccessful, oldDeployments); Assert.assertEquals(newDeployments.length(), 2);