MachinesProviderImpl implements MachinesProvider { public Machines getMachines(UUID correlationId) throws InvalidOctopusApiKeyException, InvalidOctopusUrlException, MachinesProviderException { String url = null; try { HttpContentProvider contentProvider = httpContentProviderFactory.getContentProvider(); url = contentProvider.getUrl(); LOG.debug(String.format("%s: Getting machines from %s", correlationId, contentProvider.getUrl())); final ApiRootResponse apiRootResponse = getApiRootResponse(contentProvider, correlationId); return getMachines(contentProvider, apiRootResponse, correlationId); } catch (InvalidOctopusApiKeyException | InvalidOctopusUrlException e) { throw e; } catch (Throwable e) { throw new MachinesProviderException(String.format("Unexpected exception in MachinesProviderImpl, while attempting to get Machines from %s: %s", url, e), e); } } MachinesProviderImpl(HttpContentProviderFactory httpContentProviderFactory, AnalyticsTracker analyticsTracker); Machines getMachines(UUID correlationId);  }
@Test(groups = {"needs-real-server"}) public void get_machines_from_real_server() throws NoSuchAlgorithmException, KeyStoreException, KeyManagementException, ProjectNotFoundException, MachinesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new HttpContentProviderFactory(realOctopusUrl, realOctopusApiKey, new FakeBuildTriggerProperties(), new FakeCacheManager(), new FakeMetricRegistry()); MachinesProviderImpl MachinesProviderImpl = new MachinesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); Machines newMachines = MachinesProviderImpl.getMachines(correlationId); Assert.assertNotNull(newMachines); }
@Test(enabled = false) public void get_machines_from_empty_start_with_no_machines() throws ProjectNotFoundException, MachinesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey); MachinesProviderImpl MachinesProviderImpl = new MachinesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); Machines newMachines = MachinesProviderImpl.getMachines(correlationId); Assert.assertEquals(newMachines.size(), 0); }
@Test(expectedExceptions = InvalidOctopusUrlException.class) public void get_machines_with_octopus_url_with_invalid_host() throws ProjectNotFoundException, MachinesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory("http: MachinesProviderImpl MachinesProviderImpl = new MachinesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); MachinesProviderImpl.getMachines(correlationId); }
@Test(expectedExceptions = InvalidOctopusUrlException.class) public void get_machines_with_octopus_url_with_invalid_path() throws ProjectNotFoundException, MachinesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl + "/not-an-octopus-instance", octopusApiKey); MachinesProviderImpl MachinesProviderImpl = new MachinesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); MachinesProviderImpl.getMachines(correlationId); }
@Test(expectedExceptions = InvalidOctopusApiKeyException.class) public void get_machines_with_invalid_octopus_api_key() throws ProjectNotFoundException, MachinesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, "invalid-api-key"); MachinesProviderImpl MachinesProviderImpl = new MachinesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); MachinesProviderImpl.getMachines(correlationId); }
@Test(expectedExceptions = MachinesProviderException.class) public void rethrows_throwable_exceptions_as_deployment_provider_exception() throws ProjectNotFoundException, MachinesProviderException, InvalidOctopusApiKeyException, InvalidOctopusUrlException { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(new OutOfMemoryError()); MachinesProviderImpl MachinesProviderImpl = new MachinesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); UUID correlationId = UUID.randomUUID(); MachinesProviderImpl.getMachines(correlationId); }
@Test(enabled = false) public void get_machines_when_more_than_one_page_of_machines() throws Exception { HttpContentProviderFactory contentProviderFactory = new FakeContentProviderFactory(octopusUrl, octopusApiKey); MachinesProviderImpl MachinesProviderImpl = new MachinesProviderImpl(contentProviderFactory, new FakeAnalyticsTracker()); Machines oldMachines = Machines.Parse((new Machine("Machines-1", "Octopus Server", new String[] { "env-id" }, new String[]{ "role-name" }).toString())); UUID correlationId = UUID.randomUUID(); Machines newMachines = MachinesProviderImpl.getMachines(correlationId); Assert.assertEquals(newMachines.size(), 1); Machine machine = newMachines.getNextMachine(oldMachines); Assert.assertNotNull(machine); Assert.assertEquals(machine.id, "Machines-1"); Assert.assertEquals(machine.name, "Octopus Server"); }