MachineAddedCheckJob extends CustomCheckJob<MachineAddedSpec> { @NotNull public CheckResult<MachineAddedSpec> perform(UUID correlationId) { final String octopusUrl = props.get(OCTOPUS_URL); if (StringUtil.isEmptyOrSpaces(octopusUrl)) { return MachineAddedSpecCheckResult.createErrorResult(String.format("%s settings are invalid (empty url) in build configuration %s", displayName, buildType), correlationId); } final String octopusApiKey = props.get(OCTOPUS_APIKEY); if (StringUtil.isEmptyOrSpaces(octopusApiKey)) { return MachineAddedSpecCheckResult.createErrorResult(String.format("%s settings are invalid (empty api key) in build configuration %s", displayName, buildType), correlationId); } return getCheckResult(octopusUrl, octopusApiKey, dataStorage, correlationId); } MachineAddedCheckJob(String displayName, String buildType, CustomDataStorage dataStorage, Map<String, String> properties, AnalyticsTracker analyticsTracker, CacheManager cacheManager, MetricRegistry metricRegistry, BuildTriggerProperties buildTriggerProperties);  MachineAddedCheckJob(MachinesProviderFactory MachinesProviderFactory, String displayName, String buildType, CustomDataStorage dataStorage, Map<String, String> properties, AnalyticsTracker analyticsTracker, BuildTriggerProperties buildTriggerProperties); @NotNull CheckResult<MachineAddedSpec> perform(UUID correlationId);  }
@Test(dataProvider = "NullAndEmpty") public void perform_returns_an_error_result_if_octopus_url_is_invalid(String value) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { MachinesProviderFactory machinesProviderFactory = new FakeMachinesProviderFactory(new FakeMachinesProviderWithNoMachines()); 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); MachineAddedCheckJob sut = new MachineAddedCheckJob(machinesProviderFactory, displayName, buildType, dataStorage, properties, new FakeAnalyticsTracker(), new FakeBuildTriggerProperties()); UUID correlationId = UUID.randomUUID(); CheckResult<MachineAddedSpec> 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_api_key_is_invalid(String value) throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException { MachinesProviderFactory machinesProviderFactory = new FakeMachinesProviderFactory(new FakeMachinesProviderWithNoMachines()); 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); MachineAddedCheckJob sut = new MachineAddedCheckJob(machinesProviderFactory, displayName, buildType, dataStorage, properties, new FakeAnalyticsTracker(), new FakeBuildTriggerProperties()); UUID correlationId = UUID.randomUUID(); CheckResult<MachineAddedSpec> 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()); }