@Test public void testLoadServletConfiguredFilename() throws Exception { Mockito.when(servletConfig.getInitParameter("APPLICATION_CONFIG_FILE")).thenReturn("/config/path/foo.yml"); Mockito.when(context.getResource(ArgumentMatchers.eq("file:/config/path/foo.yml"))).thenReturn( new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes())); initializer.initialize(context); assertEquals("bar", environment.getProperty("foo")); assertEquals("baz", environment.getProperty("spam.foo")); }
assertEquals("-Djava.util.logging.config=/some/path/logging.properties", environment.getProperty("logging.config")); Mockito.verify(servletContext,atLeastOnce()).log(servletLogCaptor.capture()); boolean logEntryFound = false;
@Test public void testLoadContextConfiguredResource() throws Exception { Mockito.when(servletContext.getInitParameter("environmentConfigLocations")).thenReturn("foo.yml"); Mockito.when(context.getResource(ArgumentMatchers.eq("foo.yml"))).thenReturn( new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes())); initializer.initialize(context); assertEquals("bar", environment.getProperty("foo")); assertEquals("baz", environment.getProperty("spam.foo")); }
@Test public void testLoadReplacedResourceFromFileLocation() throws Exception { System.setProperty("APPLICATION_CONFIG_FILE", "foo/uaa.yml"); Mockito.when(context.getResource(ArgumentMatchers.eq("file:foo/uaa.yml"))).thenReturn( new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes())); initializer.initialize(context); assertEquals("bar", environment.getProperty("foo")); assertEquals("baz", environment.getProperty("spam.foo")); }
@Test public void testLoadServletConfiguredResource() throws Exception { Mockito.when(servletConfig.getInitParameter("environmentConfigLocations")).thenReturn("foo.yml"); Mockito.when(context.getResource(ArgumentMatchers.eq("foo.yml"))).thenReturn( new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes())); initializer.initialize(context); assertEquals("bar", environment.getProperty("foo")); assertEquals("baz", environment.getProperty("spam.foo")); }
@Test public void testLoggingConfigVariableWorks() throws Exception { System.setProperty("APPLICATION_CONFIG_FILE", "foo/uaa.yml"); Mockito.when(context.getResource(ArgumentMatchers.eq("file:foo/uaa.yml"))).thenReturn( new ByteArrayResource("logging:\n config: /some/path".getBytes())); initializer.initialize(context); assertEquals("/some/path", environment.getProperty("logging.config")); assertNull(environment.getProperty("smtp.host")); assertNull(environment.getProperty("smtp.port")); }
@Test public void testLoadReplacedResource() throws Exception { System.setProperty("APPLICATION_CONFIG_URL", "file:foo/uaa.yml"); Mockito.when(context.getResource(ArgumentMatchers.eq("file:foo/uaa.yml"))).thenReturn( new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes())); initializer.initialize(context); assertEquals("bar", environment.getProperty("foo")); assertEquals("baz", environment.getProperty("spam.foo")); }
public void testReadingYamlFromEnvironment(String variableName) throws Exception { if (hasText(variableName)) { initializer.setYamlEnvironmentVariableName(variableName); } SystemEnvironmentAccessor env = new SystemEnvironmentAccessor() { @Override public String getEnvironmentVariable(String name) { return name.equals(initializer.getYamlEnvironmentVariableName()) ? "uaa.url: http://uaa.test.url/\n" + "login.url: http://login.test.url/\n" + "smtp:\n" + " host: mail.server.host\n" + " port: 3535\n" : null; } }; initializer.setEnvironmentAccessor(env); initializer.initialize(context); assertEquals("mail.server.host", environment.getProperty("smtp.host")); assertEquals("3535", environment.getProperty("smtp.port")); assertEquals("http://uaa.test.url/", environment.getProperty("uaa.url")); assertEquals("http://login.test.url/", environment.getProperty("login.url")); }
@Test public void testLoadDefaultResource() throws Exception { Mockito.when(context.getResource(ArgumentMatchers.contains("${APPLICATION_CONFIG_URL}"))).thenReturn( new ByteArrayResource("foo: bar\nspam:\n foo: baz".getBytes())); initializer.initialize(context); assertEquals("bar", environment.getProperty("foo")); assertEquals("baz", environment.getProperty("spam.foo")); }
CharsetEnum.UTF_8.getCharset()); } else { val = ConfigProperties.localenv.getProperty(name, defaultVal); val = ConfigProperties.localenv.getProperty(name, defaultVal); if (("${" + name + "}").equals(val)) { val = null;