@Test public void shouldFindAgentsByItHostName() throws Exception { AgentInstance idle = AgentInstanceMother.idle(new Date(), "ghost-name"); AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, idle, AgentInstanceMother.building()); AgentInstance byHostname = agentInstances.findFirstByHostname("ghost-name"); assertThat(byHostname, is(idle)); }
@Test public void shouldReturnNullAgentsWhenHostNameIsNotFound() throws Exception { AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, AgentInstanceMother.building()); agentInstances.add(idle); agentInstances.add(building); AgentInstance byHostname = agentInstances.findFirstByHostname("not-exist"); assertThat(byHostname, is(instanceOf(NullAgentInstance.class))); }
@Test public void shouldReturnFirstMatchedAgentsWhenHostNameHasMoreThanOneMatch() throws Exception { AgentInstance agent = AgentInstance.createFromConfig(new AgentConfig("uuid20", "CCeDev01", "10.18.5.20"), systemEnvironment, null); AgentInstance duplicatedAgent = AgentInstance.createFromConfig(new AgentConfig("uuid21", "CCeDev01", "10.18.5.20"), systemEnvironment, null); AgentInstances agentInstances = new AgentInstances(systemEnvironment, agentStatusChangeListener, agent, duplicatedAgent); AgentInstance byHostname = agentInstances.findFirstByHostname("CCeDev01"); assertThat(byHostname, is(agent)); }