/** * {@inheritDoc} */ @Override public boolean isEnhancedExceptionSensorActivated() throws StorageException { ensureConfigurationExists(); if (isExceptionSensorActivated()) { return agentConfiguration.getExceptionSensorTypeConfig().isEnhanced(); } return false; }
try { int port = Integer.parseInt(repositoryPort); setRepository(repositoryIp, port); } catch (Exception e) { log.warn("Repository could not be defined from the data in the JVM parameters", e); String newAgentName = checkPatternAgentName(agentName).replaceAll("(\r|\n)", ""); try { log.info("Agent name found in the JVM parameters: AgentName=" + newAgentName); setAgentName(newAgentName); } catch (Exception e) { log.warn("Agent name could not be defined from the data in the JVM parameters", e); try { log.info("Agent name set by default: AgentName = " + DEFAULT_AGENT_NAME); setAgentName(DEFAULT_AGENT_NAME); } catch (StorageException e) { log.warn("Agent name could not be defined from default agent name", e);
@Test public void resetNameNotAllowed() throws StorageException { configurationStorage.setAgentName("UnitTestAgent"); configurationStorage.setAgentName("agent1"); String agentName = configurationStorage.getAgentName(); assertThat(agentName, is(equalTo("UnitTestAgent"))); } }
@Test public void agentNameIsCorrectIfThePatternIsAtTheEndOfTheNameAndItIsNotRecognize() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "agentName_${test}"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("agentName_NA"))); }
@Test public void resetNotAllowed() throws StorageException { configurationStorage.setRepository("localhost", 1099); configurationStorage.setRepository("localhost1", 1200); String host = configurationStorage.getRepositoryConfig().getHost(); int port = configurationStorage.getRepositoryConfig().getPort(); assertThat(host, is(equalTo("localhost"))); assertThat(port, is(equalTo(1099))); } }
@Test public void repositoryAndAgentNameSet() throws Exception { String agentName = "agentName"; Properties properties = System.getProperties(); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, agentName); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getRepositoryConfig().getHost(), is("localhost")); assertThat(configurationStorage.getRepositoryConfig().getPort(), is(8000)); assertThat(configurationStorage.getAgentName(), is(agentName)); }
/** * {@inheritDoc} */ @Override public AgentEndUserMonitoringConfig getEndUserMonitoringConfig() throws StorageException { ensureConfigurationExists(); return agentConfiguration.getEumConfig(); }
@Test public void notDefined() throws StorageException { when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(null); boolean exceptionSensorActivated = configurationStorage.isExceptionSensorActivated(); assertThat(exceptionSensorActivated, is(false)); }
@Test(expectedExceptions = { StorageException.class }) public void setNullName() throws StorageException { configurationStorage.setAgentName(null); }
@Test(expectedExceptions = { StorageException.class }) public void setNullHost() throws StorageException { configurationStorage.setRepository(null, 1099); }
@Test public void strategyCheck() throws StorageException { StrategyConfig strategyConfig = mock(StrategyConfig.class); when(agentConfiguration.getDisruptorStrategyConfig()).thenReturn(strategyConfig); StrategyConfig config = configurationStorage.getDisruptorStrategyConfig(); assertThat(config, is(strategyConfig)); }
@Test(expectedExceptions = BeanInitializationException.class) public void agentOnlySet() throws Exception { String agentName = "agentName"; Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, agentName); properties.remove(ConfigurationStorage.REPOSITORY_PROPERTY); configurationStorage.afterPropertiesSet(); }
@Test public void notDefined() throws StorageException { when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(null); ExceptionSensorTypeConfig config = configurationStorage.getExceptionSensorType(); assertThat(config, is(nullValue())); } }
@Test public void check() throws StorageException { IMatchPattern pattern = mock(IMatchPattern.class); when(agentConfiguration.getExcludeClassesPatterns()).thenReturn(Collections.singleton(pattern)); Collection<IMatchPattern> ignorePatterns = configurationStorage.getIgnoreClassesPatterns(); assertThat(ignorePatterns, is(notNullValue())); assertThat(ignorePatterns, hasItem(pattern)); } }
@Test public void lineFeedAndCarriageReturnIsRemovedFromAgentName() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "agent\n\rName"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("agentName"))); }
@Test public void check() throws StorageException { configurationStorage.setRepository("localhost", 1099); String host = configurationStorage.getRepositoryConfig().getHost(); int port = configurationStorage.getRepositoryConfig().getPort(); assertThat(host, is(equalTo("localhost"))); assertThat(port, is(equalTo(1099))); }
@Test public void repositoryOnlySet() throws Exception { Properties properties = System.getProperties(); properties.remove(ConfigurationStorage.AGENT_NAME_PROPERTY); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getRepositoryConfig().getHost(), is("localhost")); assertThat(configurationStorage.getRepositoryConfig().getPort(), is(8000)); assertThat(configurationStorage.getAgentName(), is(not(nullValue()))); }
/** * {@inheritDoc} */ @Override public boolean isClassCacheExistsOnCmr() throws StorageException { ensureConfigurationExists(); return agentConfiguration.isClassCacheExistsOnCmr(); }
@Test public void defined() throws StorageException { ExceptionSensorTypeConfig exceptionSensorTypeConfig = mock(ExceptionSensorTypeConfig.class); when(agentConfiguration.getExceptionSensorTypeConfig()).thenReturn(exceptionSensorTypeConfig); boolean exceptionSensorActivated = configurationStorage.isExceptionSensorActivated(); assertThat(exceptionSensorActivated, is(true)); }
@Test(expectedExceptions = { StorageException.class }) public void setEmptyName() throws StorageException { configurationStorage.setAgentName(""); }