@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 agentEmptySet() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, ""); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(not(""))); }
@Test public void agentNameIsCorrectIfThePatternIsAtTheEndOfTheNameAndItIsFromSystemProperties() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "agentName_${systemProperty}"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); properties.put("systemProperty", "systemPropertyValue"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("agentName_systemPropertyValue"))); }
@Test public void agentNameIsCorrectIfThePatternIsAtTheBeginningOfTheNameAndThereIsMoreThanOnePatternInTheArgumentWhenThePropertyIsNotTheFirstFound() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "${test}_agentName_${systemProperty}"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); properties.put("systemProperty", "systemPropertyValue"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("NA_agentName_${systemProperty}"))); }
@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 agentNameIsCorrectIfThePatternIsAtTheBeginningOfTheNameAndItIsNotRecognize() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "${test}_agentName"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("NA_agentName"))); }
@Test public void lineFeedIsRemovedFromAgentName() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "age\nntName\n"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("agentName"))); }
@Test public void agentNameIsCorrectIfThePatternIsInTheMiddleOfTheNameAndItIsNotRecognize() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "agent_${test}_Name"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("agent_NA_Name"))); }
@Test public void agentNameIsCorrectIfThePatternIsInTheMiddleOfTheNameAndItIsFromSystemProperties() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "agent_${systemProperty}_Name"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); properties.put("systemProperty", "systemPropertyValue"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("agent_systemPropertyValue_Name"))); }
@Test public void agentNameIsCorrectIfThePatternIsAtTheBeginningOfTheNameAndItIsFromSystemProperties() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "${systemProperty}_agentName"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); properties.put("systemProperty", "systemPropertyValue"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("systemPropertyValue_agentName"))); }
@Test public void agentNameIsCorrectIfThePatternIsAtTheBeginningOfTheNameAndThereIsMoreThanOnePatternInTheArgumentWhenThePropertyIsTheFirstFound() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "${systemProperty}_agent_${systemProperty}_Name_${test}"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); properties.put("systemProperty", "systemPropertyValue"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("systemPropertyValue_agent_${systemProperty}_Name_${test}"))); }
@Test public void carriageReturnIsRemovedFromAgentName() throws Exception { Properties properties = System.getProperties(); properties.put(ConfigurationStorage.AGENT_NAME_PROPERTY, "ag\rentNam\re"); properties.put(ConfigurationStorage.REPOSITORY_PROPERTY, "localhost:8000"); configurationStorage.afterPropertiesSet(); assertThat(configurationStorage.getAgentName(), is(("agentName"))); }
@Test() public void check() throws StorageException { configurationStorage.setAgentName("UnitTestAgent"); String agentName = configurationStorage.getAgentName(); assertThat(agentName, is(equalTo("UnitTestAgent"))); }
@Test public void resetNameNotAllowed() throws StorageException { configurationStorage.setAgentName("UnitTestAgent"); configurationStorage.setAgentName("agent1"); String agentName = configurationStorage.getAgentName(); assertThat(agentName, is(equalTo("UnitTestAgent"))); } }
@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()))); }
@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)); }