Search in sources :

Example 36 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class SpringApplicationTests method commandLinePropertySourceEnhancesEnvironment.

@Test
public void commandLinePropertySourceEnhancesEnvironment() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableEnvironment environment = new StandardEnvironment();
    environment.getPropertySources().addFirst(new MapPropertySource("commandLineArgs", Collections.<String, Object>singletonMap("foo", "original")));
    application.setEnvironment(environment);
    this.context = application.run("--foo=bar", "--bar=foo");
    assertThat(environment).has(matchingPropertySource(CompositePropertySource.class, "commandLineArgs"));
    assertThat(environment.getProperty("bar")).isEqualTo("foo");
    // New command line properties take precedence
    assertThat(environment.getProperty("foo")).isEqualTo("bar");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) CompositePropertySource(org.springframework.core.env.CompositePropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 37 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class SpringApplicationTests method emptyCommandLinePropertySourceNotAdded.

@Test
public void emptyCommandLinePropertySourceNotAdded() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run();
    assertThat(environment.getProperty("foo")).isEqualTo("bucket");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 38 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class SpringApplicationTests method commandLinePropertySource.

@Test
public void commandLinePropertySource() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run("--foo=bar");
    assertThat(environment).has(matchingPropertySource(CommandLinePropertySource.class, "commandLineArgs"));
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) CommandLinePropertySource(org.springframework.core.env.CommandLinePropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 39 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class SpringApplicationTests method propertiesFileEnhancesEnvironment.

@Test
public void propertiesFileEnhancesEnvironment() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebApplicationType(WebApplicationType.NONE);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    this.context = application.run();
    assertThat(environment.getProperty("foo")).isEqualTo("bucket");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 40 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-framework by spring-projects.

the class NestedBeansElementTests method getBean_withActiveProfile.

@Test
public void getBean_withActiveProfile() {
    ConfigurableEnvironment env = new StandardEnvironment();
    env.setActiveProfiles("dev");
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(bf);
    reader.setEnvironment(env);
    reader.loadBeanDefinitions(XML);
    // should not throw NSBDE
    bf.getBean("devOnlyBean");
    Object foo = bf.getBean("foo");
    assertThat(foo, instanceOf(Integer.class));
    bf.getBean("devOnlyBean");
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Aggregations

StandardEnvironment (org.springframework.core.env.StandardEnvironment)55 Test (org.junit.Test)41 MapPropertySource (org.springframework.core.env.MapPropertySource)28 URI (java.net.URI)23 HashMap (java.util.HashMap)23 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)18 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9 Envelope (com.kixeye.chassis.transport.dto.Envelope)7 ArrayList (java.util.ArrayList)7