Package org.springframework.core.env

Examples of org.springframework.core.env.ConfigurableEnvironment


   * @see PropertySourceUtils#getSubProperties(PropertySources, String, String)
   */
  public Map<String, Object> getSubProperties(String keyPrefix) {
    Assert.isInstanceOf(ConfigurableEnvironment.class, this.resolver,
        "SubProperties not available.");
    ConfigurableEnvironment env = (ConfigurableEnvironment) this.resolver;
    return PropertySourceUtils.getSubProperties(env.getPropertySources(),
        this.prefix, keyPrefix);
  }
View Full Code Here


    private void flattenPropertySources(PropertySource<?> propertySource,
        MutablePropertySources result) {
      Object source = propertySource.getSource();
      if (source instanceof ConfigurableEnvironment) {
        ConfigurableEnvironment environment = (ConfigurableEnvironment) source;
        for (PropertySource<?> childSource : environment.getPropertySources()) {
          flattenPropertySources(childSource, result);
        }
      }
      else {
        result.addLast(propertySource);
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 renderWithReplacement() throws Exception {
    Resource resource = new ByteArrayResource(
        "banner ${a} ${spring-boot.version} ${application.version}".getBytes());
    ResourceBanner banner = new ResourceBanner(resource);
    ConfigurableEnvironment environment = new MockEnvironment();
    Map<String, Object> source = Collections.<String, Object> singletonMap("a", "1");
    environment.getPropertySources().addLast(new MapPropertySource("map", source));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    banner.printBanner(environment, getClass(), new PrintStream(out));
    assertThat(out.toString(), startsWith("banner 1"));
    assertThat(out.toString(), not(containsString("$")));
  }
View Full Code Here

  @Override
  public ApplicationContext loadContext(MergedContextConfiguration config)
      throws Exception {
    SpringApplication application = getSpringApplication();
    application.setSources(getSources(config));
    ConfigurableEnvironment environment = new StandardEnvironment();
    if (!ObjectUtils.isEmpty(config.getActiveProfiles())) {
      String profiles = StringUtils.arrayToCommaDelimitedString(config
          .getActiveProfiles());
      EnvironmentTestUtils.addEnvironment(environment, "spring.profiles.active="
          + profiles);
    }
    // Ensure @IntegrationTest properties go before external config and after system
    environment.getPropertySources()
        .addAfter(
            StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME,
            new MapPropertySource("integrationTest",
                getEnvironmentProperties(config)));
    application.setEnvironment(environment);
View Full Code Here

    assertThat(AnsiOutputEnabledValue.get(), equalTo(Enabled.NEVER));
  }

  @Test
  public void disabledViaApplcationProperties() throws Exception {
    ConfigurableEnvironment environment = new StandardEnvironment();
    EnvironmentTestUtils.addEnvironment(environment, "spring.config.name:ansi");
    SpringApplication application = new SpringApplication(Config.class);
    application.setWebEnvironment(false);
    application.setEnvironment(environment);
    application.run();
View Full Code Here

TOP

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

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.