Package org.springframework.core.env

Examples of org.springframework.core.env.MapPropertySource


  public void testhandlerWithExpression() {

    @SuppressWarnings("resource")
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

    MapPropertySource propertiesSource = new MapPropertySource("test", Collections.singletonMap("valueExpression",
        (Object) "payload.get('price').asDouble()"));

    applicationContext.getEnvironment().getPropertySources().addLast(propertiesSource);

    applicationContext.register(RichGaugeHandlerTestsConfig.class);
View Full Code Here


    @Autowired
    public void setEnvironment(Environment environment) {
      Map<String, Object> map = new HashMap<String, Object>();
      map.put("xd.config.home", "file:../config");
      ((ConfigurableEnvironment) environment).getPropertySources().addFirst(new MapPropertySource("foo", map));
    }
View Full Code Here

    @Autowired
    public void setEnvironment(Environment environment) {
      Map<String, Object> map = new HashMap<String, Object>();
      map.put("xd.config.home", "file:../config");
      ((ConfigurableEnvironment) environment).getPropertySources().addFirst(new MapPropertySource("foo", map));
    }
View Full Code Here

  }

  private EnumerablePropertySource<?> singleton(String key, Object value) {
    Map<String, Object> map = Collections.singletonMap(key, value);
    return new MapPropertySource("ps-" + random.nextInt(), map);
  }
View Full Code Here

   */
  protected void configurePropertySources(ConfigurableEnvironment environment,
      String[] args) {
    MutablePropertySources sources = environment.getPropertySources();
    if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
      sources.addLast(new MapPropertySource("defaultProperties",
          this.defaultProperties));
    }
    if (this.addCommandLineProperties && args.length > 0) {
      String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME;
      if (sources.contains(name)) {
View Full Code Here

    return resolvers;
  }

  private PropertyResolver getVersionResolver(Class<?> sourceClass) {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MapPropertySource("version",
        getVersionsMap(sourceClass)));
    return new PropertySourcesPropertyResolver(propertySources);
  }
View Full Code Here

  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"));
View Full Code Here

  @Test
  public void testBindFromPropertySource() throws Exception {
    this.targetName = "foo";
    setupFactory();
    MutablePropertySources sources = new MutablePropertySources();
    sources.addFirst(new MapPropertySource("map", Collections.singletonMap(
        "foo.map.name", (Object) "blah")));
    this.factory.setPropertySources(sources);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
    assertEquals("blah", foo.map.get("name"));
View Full Code Here

  public void testBindFromCompositePropertySource() throws Exception {
    this.targetName = "foo";
    setupFactory();
    MutablePropertySources sources = new MutablePropertySources();
    CompositePropertySource composite = new CompositePropertySource("composite");
    composite.addPropertySource(new MapPropertySource("map", Collections
        .singletonMap("foo.map.name", (Object) "blah")));
    sources.addFirst(composite);
    this.factory.setPropertySources(sources);
    this.factory.afterPropertiesSet();
    Foo foo = this.factory.getObject();
View Full Code Here

    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

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.