@Override public String getAgentId() { return getConfigurationHandler().get(CONFIG_IDENTIFICATION_AGENTID, CONFIG_DEFAULT_AGENTID); } }
@Override protected void onInit() throws Exception { String urls = getConfigurationHandler().get(CONFIG_DISCOVERY_SERVERURLS, mergeUrls(m_defaultServerURLs)); boolean checkServerURLs = getConfigurationHandler().getBoolean(CONFIG_DISCOVERY_CHECKING, DEFAULT_CHECK_SERVER_URLS); m_defaultServerURLs = m_serverURLs = splitUrls(urls); // ACE-520 - checking URLs only makes sense if there is more than one URL available... m_defaultCheckURLs = m_checkURLs = checkServerURLs && m_defaultServerURLs.size() > 1; getEventsHandler().addListener(this); }
assertEquals(configurationHandler.get(systemKey1, "default1"), "value1"); assertEquals(configurationHandler.get(systemKey2, "default2"), "value2"); assertEquals(configurationHandler.get(systemKey1, "qux"), "qux"); assertEquals(configurationHandler.get(systemKey2, "quu"), "quu"); assertEquals(configurationHandler.get(systemKey1, "qux"), "newvalue1"); assertEquals(configurationHandler.get(systemKey2, "quu"), "newvalue2"); assertEquals(configurationHandler.get(systemKey1, "qqq"), "newvalue1"); assertEquals(configurationHandler.get(systemKey2, "qqq"), "newvalue2");
@Test public void testConfigClean() throws Exception { ConfigurationHandler configurationHandler = new ConfigurationHandlerImpl(m_context); resetConfigurationHandler(configurationHandler); configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); assertEquals(configurationHandler.get("key1", "default1"), "default1"); // should be persisted configurationHandler = new ConfigurationHandlerImpl(m_context); resetConfigurationHandler(configurationHandler); configurationHandler = m_agentContextImpl.getHandler(ConfigurationHandler.class); assertEquals(configurationHandler.get("key1", "default1"), "default1"); }
@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 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 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 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"); }
expect(configurationHandler.get(notNull(String.class), anyObject(String.class))).andReturn(null).anyTimes();