Package org.springframework.core.env

Examples of org.springframework.core.env.MapPropertySource


    this.source.put("myString", "value");
    this.source.put("myobject", "object");
    this.source.put("myInteger", 123);
    this.source.put("myClass", "java.lang.String");
    this.environment.getPropertySources().addFirst(
        new MapPropertySource("test", this.source));
    this.resolver = new RelaxedPropertyResolver(this.environment);
  }
View Full Code Here


  public void defaultPropertyAsFallback() throws Exception {
    this.event
        .getEnvironment()
        .getPropertySources()
        .addLast(
            new MapPropertySource("defaultProperties", Collections
                .singletonMap("my.fallback", (Object) "foo")));
    this.initializer.onApplicationEvent(this.event);
    String property = this.environment.getProperty("my.fallback");
    assertThat(property, equalTo("foo"));
  }
View Full Code Here

  public void defaultPropertyAsFallbackDuringFileParsing() throws Exception {
    this.event
        .getEnvironment()
        .getPropertySources()
        .addLast(
            new MapPropertySource("defaultProperties", Collections
                .singletonMap("spring.config.name",
                    (Object) "testproperties")));
    this.initializer.onApplicationEvent(this.event);
    String property = this.environment.getProperty("the.property");
    assertThat(property, equalTo("frompropertiesfile"));
View Full Code Here

      String... pairs) {
    MutablePropertySources sources = environment.getPropertySources();
    Map<String, Object> map;
    if (!sources.contains(name)) {
      map = new HashMap<String, Object>();
      MapPropertySource source = new MapPropertySource(name, map);
      sources.addFirst(source);
    }
    else {
      @SuppressWarnings("unchecked")
      Map<String, Object> value = (Map<String, Object>) sources.get(name)
View Full Code Here

        }
        return null;
      }

    });
    this.propertySources.addFirst(new MapPropertySource("map", Collections
        .<String, Object> singletonMap("name", "${foo}")));
  }
View Full Code Here

    assertEquals("bar", propertyValues.getPropertyValue("baz").getValue());
  }

  @Test
  public void testOverriddenValue() {
    this.propertySources.addFirst(new MapPropertySource("new", Collections
        .<String, Object> singletonMap("name", "spam")));
    PropertySourcesPropertyValues propertyValues = new PropertySourcesPropertyValues(
        this.propertySources);
    assertEquals("spam", propertyValues.getPropertyValue("name").getValue());
  }
View Full Code Here

  @Test
  public void testPlaceholdersBindingWithError() {
    TestBean target = new TestBean();
    DataBinder binder = new DataBinder(target);
    this.propertySources.addFirst(new MapPropertySource("another", Collections
        .<String, Object> singletonMap("something", "${nonexistent}")));
    binder.bind(new PropertySourcesPropertyValues(this.propertySources));
    assertEquals("bar", target.getName());
  }
View Full Code Here

    }
    // 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);
    List<ApplicationContextInitializer<?>> initializers = getInitializers(config,
        application);
    if (config instanceof WebMergedContextConfiguration) {
View Full Code Here

  @SuppressWarnings("unchecked")
  @Test
  public void testCompositeSource() throws Exception {
    EnvironmentEndpoint report = getEndpointBean();
    CompositePropertySource source = new CompositePropertySource("composite");
    source.addPropertySource(new MapPropertySource("one", Collections.singletonMap(
        "foo", (Object) "bar")));
    source.addPropertySource(new MapPropertySource("two", Collections.singletonMap(
        "foo", (Object) "spam")));
    this.context.getEnvironment().getPropertySources().addFirst(source);
    Map<String, Object> env = report.invoke();
    assertEquals("bar", ((Map<String, Object>) env.get("composite:one")).get("foo"));
  }
View Full Code Here

  }

  @Test
  public void isSensitiveOverride() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    PropertySource<?> propertySource = new MapPropertySource("test",
        Collections.<String, Object> singletonMap(this.property + ".sensitive",
            String.valueOf(!this.sensitive)));
    this.context.getEnvironment().getPropertySources().addFirst(propertySource);
    this.context.register(this.configClass);
    this.context.refresh();
View Full Code Here

TOP

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

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.