DeploymentProcessChangedCheckJob extends CustomCheckJob<DeploymentProcessChangedSpec> { @NotNull public CheckResult<DeploymentProcessChangedSpec> perform(UUID correlationId) { final String octopusUrl = props.get(OCTOPUS_URL); if (StringUtil.isEmptyOrSpaces(octopusUrl)) { return DeploymentProcessChangedSpecCheckResult.createErrorResult(String.format("%s settings are invalid (empty url) in build configuration %s", displayName, this.buildType), correlationId); } final String octopusApiKey = props.get(OCTOPUS_APIKEY); if (StringUtil.isEmptyOrSpaces(octopusApiKey)) { return DeploymentProcessChangedSpecCheckResult.createErrorResult(String.format("%s settings are invalid (empty api key) in build configuration %s", displayName, this.buildType), correlationId); } final String octopusProject = props.get(OCTOPUS_PROJECT_ID); if (StringUtil.isEmptyOrSpaces(octopusProject)) { return DeploymentProcessChangedSpecCheckResult.createErrorResult(String.format("%s settings are invalid (empty project) in build configuration %s", displayName, this.buildType), correlationId); } return getCheckResult(octopusUrl, octopusApiKey, octopusProject, dataStorage, correlationId); } DeploymentProcessChangedCheckJob(String displayName, String buildType, CustomDataStorage dataStorage, Map<String, String> properties, AnalyticsTracker analyticsTracker, CacheManager cacheManager, MetricRegistry metricRegistry, BuildTriggerProperties buildTriggerProperties);  DeploymentProcessChangedCheckJob(DeploymentProcessProviderFactory deploymentProcessProviderFactory, String displayName, String buildType, CustomDataStorage dataStorage, Map<String, String> properties, AnalyticsTracker analyticsTracker, BuildTriggerProperties buildTriggerProperties); @NotNull CheckResult<DeploymentProcessChangedSpec> perform(UUID correlationId);  }
@Test(dataProvider = "NullAndEmpty") public void perform_returns_an_error_result_if_octopus_url_is_invalid(String value) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { DeploymentProcessProviderFactory DeploymentProcessProviderFactory = new FakeDeploymentProcessProviderFactory(new FakeDeploymentProcessProvider()); String displayName = "the-display-name"; String buildType = "the-build-type"; CustomDataStorage dataStorage = new FakeCustomDataStorage(); Map<String, String> properties = new HashMap<>(); properties.put(OCTOPUS_URL, value); DeploymentProcessChangedCheckJob sut = new DeploymentProcessChangedCheckJob(DeploymentProcessProviderFactory, displayName, buildType, dataStorage, properties, new FakeAnalyticsTracker(), new FakeBuildTriggerProperties()); UUID correlationId = UUID.randomUUID(); CheckResult<DeploymentProcessChangedSpec> result = sut.perform(correlationId); 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 { DeploymentProcessProviderFactory DeploymentProcessProviderFactory = new FakeDeploymentProcessProviderFactory(new FakeDeploymentProcessProvider()); String displayName = "the-display-name"; String buildType = "the-build-type"; CustomDataStorage dataStorage = new FakeCustomDataStorage(); Map<String, String> properties = new HashMap<>(); properties.put(OCTOPUS_URL, "the-url"); properties.put(OCTOPUS_APIKEY, value); DeploymentProcessChangedCheckJob sut = new DeploymentProcessChangedCheckJob(DeploymentProcessProviderFactory, displayName, buildType, dataStorage, properties, new FakeAnalyticsTracker(), new FakeBuildTriggerProperties()); UUID correlationId = UUID.randomUUID(); CheckResult<DeploymentProcessChangedSpec> result = sut.perform(correlationId); 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 { DeploymentProcessProviderFactory DeploymentProcessProviderFactory = new FakeDeploymentProcessProviderFactory(new FakeDeploymentProcessProvider()); String displayName = "the-display-name"; String buildType = "the-build-type"; CustomDataStorage dataStorage = new FakeCustomDataStorage(); Map<String, String> properties = new HashMap<>(); properties.put(OCTOPUS_URL, "the-url"); properties.put(OCTOPUS_APIKEY, "the-api-key"); properties.put(OCTOPUS_PROJECT_ID, value); DeploymentProcessChangedCheckJob sut = new DeploymentProcessChangedCheckJob(DeploymentProcessProviderFactory, displayName, buildType, dataStorage, properties, new FakeAnalyticsTracker(), new FakeBuildTriggerProperties()); UUID correlationId = UUID.randomUUID(); CheckResult<DeploymentProcessChangedSpec> result = sut.perform(correlationId); 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()); }