protected String getIdentification() { return getIdentificationHandler().getAgentId(); }
private String getTargetID() { IdentificationHandler idHandler = m_agentContext.getHandler(IdentificationHandler.class); return idHandler.getAgentId(); }
@Override public String getAgentId() { return m_agentContext.getHandler(IdentificationHandler.class).getAgentId(); }
private String getIdentification() { return m_agentContext.getHandler(IdentificationHandler.class).getAgentId(); }
protected void sendDeploymentInstallEvent(UpdateInfo updateInfo) { Map<String, String> eventProps = new HashMap<>(); eventProps.put("type", updateInfo.m_type); eventProps.put("name", getIdentificationHandler().getAgentId()); eventProps.put("fromVersion", updateInfo.m_from.toString()); eventProps.put("toVersion", updateInfo.m_to.toString()); eventProps.put("fixPackage", Boolean.toString(updateInfo.m_fixPackage)); getEventsHandler().postEvent(AGENT_INSTALLATION_START, eventProps); }
protected void sendDeploymentCompletedEvent(UpdateInfo updateInfo, boolean success, Throwable throwable) { Map<String, String> eventProps = new HashMap<>(); eventProps.put("type", updateInfo.m_type); eventProps.put("name", getIdentificationHandler().getAgentId()); eventProps.put("fromVersion", updateInfo.m_from.toString()); eventProps.put("toVersion", updateInfo.m_to.toString()); eventProps.put("fixPackage", Boolean.toString(updateInfo.m_fixPackage)); eventProps.put("successful", Boolean.toString(success)); if (throwable != null) { eventProps.put("exception", throwable.getMessage()); } getEventsHandler().postEvent(AGENT_INSTALLATION_COMPLETE, eventProps); }
@Test public void testNoIdentification() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); reset(configurationHandler); expect(configurationHandler.get(eq(AgentConstants.CONFIG_IDENTIFICATION_AGENTID), anyObject(String.class))) .andReturn(null).once(); replay(configurationHandler); IdentificationHandler identificationHandler = m_agentContext.getHandler(IdentificationHandler.class); assertNull(identificationHandler.getAgentId()); }
@Test public void testUpdatedIdentification() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); reset(configurationHandler); expect(configurationHandler.get(eq(AgentConstants.CONFIG_IDENTIFICATION_AGENTID), anyObject(String.class))) .andReturn("qqq").once(); expect(configurationHandler.get(eq(AgentConstants.CONFIG_IDENTIFICATION_AGENTID), anyObject(String.class))) .andReturn("yyy").once(); replay(configurationHandler); IdentificationHandler identificationHandler = m_agentContext.getHandler(IdentificationHandler.class); assertEquals(identificationHandler.getAgentId(), "qqq"); assertEquals(identificationHandler.getAgentId(), "yyy"); }
@Test public void testEmptyIdentification() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); reset(configurationHandler); expect(configurationHandler.get(eq(AgentConstants.CONFIG_IDENTIFICATION_AGENTID), anyObject(String.class))) .andReturn(null).once(); replay(configurationHandler); IdentificationHandler identificationHandler = m_agentContext.getHandler(IdentificationHandler.class); assertNull(identificationHandler.getAgentId()); } }
@Test public void testAvailableIdentification() throws Exception { ConfigurationHandler configurationHandler = m_agentContext.getHandler(ConfigurationHandler.class); reset(configurationHandler); expect(configurationHandler.get(eq(AgentConstants.CONFIG_IDENTIFICATION_AGENTID), anyObject(String.class))) .andReturn("qqq").once(); replay(configurationHandler); IdentificationHandler identificationHandler = m_agentContext.getHandler(IdentificationHandler.class); assertEquals(identificationHandler.getAgentId(), "qqq"); }
@BeforeMethod public void setUpAgain(Method method) throws Exception { // this setup is needed because a real Feedbackstore is initialized in the constructor. m_agentContext = mockAgentContext(); URL serverURL = new URL("http://localhost:" + PORT + "/"); m_webServer = new TestWebServer(PORT, "/", "generated"); m_webServer.start(); DiscoveryHandler discoveryHandler = addTestMock(DiscoveryHandler.class); expect(discoveryHandler.getServerUrl()).andReturn(serverURL).anyTimes(); IdentificationHandler identificationHandler = addTestMock(IdentificationHandler.class); expect(identificationHandler.getAgentId()).andReturn("identification").anyTimes(); replayTestMocks(); m_agentContext.setHandler(DiscoveryHandler.class, discoveryHandler); m_agentContext.setHandler(IdentificationHandler.class, identificationHandler); m_agentContext.setHandler(ConnectionHandler.class, new ConnectionHandlerImpl()); m_feedbackChannelImpl = new FeedbackChannelImpl(m_agentContext, "test"); m_agentContext.start(); }
expect(identificationHandler.getAgentId()).andReturn(identification).anyTimes();