Package org.springframework.core.env

Examples of org.springframework.core.env.StandardEnvironment


  @Test
  public void commandLinePropertySource() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run("--foo=bar");
    assertTrue(hasPropertySource(environment, CommandLinePropertySource.class,
        "commandLineArgs"));
  }
View Full Code Here


  @Test
  public void commandLinePropertySourceEnhancesEnvironment() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    environment.getPropertySources().addFirst(
        new MapPropertySource("commandLineArgs", Collections
            .<String, Object> singletonMap("foo", "original")));
    application.setEnvironment(environment);
    application.run("--foo=bar", "--bar=foo");
    assertTrue(hasPropertySource(environment, CompositePropertySource.class,
        "commandLineArgs"));
    assertEquals("foo", environment.getProperty("bar"));
    // New command line properties take precedence
    assertEquals("bar", environment.getProperty("foo"));
  }
View Full Code Here

  @Test
  public void propertiesFileEnhancesEnvironment() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run();
    assertEquals("bucket", environment.getProperty("foo"));
  }
View Full Code Here

  @Test
  public void addProfiles() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    application.setAdditionalProfiles("foo");
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run();
    assertTrue(environment.acceptsProfiles("foo"));
  }
View Full Code Here

  @Test
  public void addProfilesOrder() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    application.setAdditionalProfiles("foo");
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run("--spring.profiles.active=bar,spam");
    // Command line should always come last
    assertArrayEquals(new String[] { "foo", "bar", "spam" },
        environment.getActiveProfiles());
  }
View Full Code Here

  @Test
  public void addProfilesOrderWithProperties() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    application.setAdditionalProfiles("other");
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run();
    // Active profile should win over default
    assertEquals("fromotherpropertiesfile", environment.getProperty("my.property"));
  }
View Full Code Here

  @Test
  public void emptyCommandLinePropertySourceNotAdded() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run();
    assertEquals("bucket", environment.getProperty("foo"));
  }
View Full Code Here

  @Test
  public void disableCommandLinePropertySource() throws Exception {
    SpringApplication application = new SpringApplication(ExampleConfig.class);
    application.setWebEnvironment(false);
    application.setAddCommandLineProperties(false);
    ConfigurableEnvironment environment = new StandardEnvironment();
    application.setEnvironment(environment);
    application.run("--foo=bar");
    assertFalse(hasPropertySource(environment, PropertySource.class,
        "commandLineArgs"));
  }
View Full Code Here

  }

  @Test
  public void parentFirstWithDifferentProfileAndExplicitEnvironment() throws Exception {
    SpringApplicationBuilder application = new SpringApplicationBuilder(
        ExampleConfig.class).environment(new StandardEnvironment())
        .profiles("node").properties("transport=redis").child(ChildConfig.class)
        .profiles("admin").web(false);
    this.context = application.run();
    assertThat(this.context.getEnvironment().acceptsProfiles("node", "admin"),
        is(true));
View Full Code Here

  private LinkedHashMap<String, Object> source;

  @Before
  public void setup() {
    this.environment = new StandardEnvironment();
    this.source = new LinkedHashMap<String, Object>();
    this.source.put("myString", "value");
    this.source.put("myobject", "object");
    this.source.put("myInteger", 123);
    this.source.put("myClass", "java.lang.String");
View Full Code Here

TOP

Related Classes of org.springframework.core.env.StandardEnvironment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.