Package org.springframework.mock.env

Examples of org.springframework.mock.env.MockPropertySource


  @Test
  public void getPropertySources_replacePropertySource() {
    propertySources = new MutablePropertySources();
    propertyResolver = new PropertySourcesPropertyResolver(propertySources);
    propertySources.addLast(new MockPropertySource("local").withProperty("foo", "localValue"));
    propertySources.addLast(new MockPropertySource("system").withProperty("foo", "systemValue"));

    // 'local' was added first so has precedence
    assertThat(propertyResolver.getProperty("foo"), equalTo("localValue"));

    // replace 'local' with new property source
    propertySources.replace("local", new MockPropertySource("new").withProperty("foo", "newValue"));

    // 'system' now has precedence
    assertThat(propertyResolver.getProperty("foo"), equalTo("newValue"));

    assertThat(propertySources.size(), is(2));
View Full Code Here


  }

  @Test
  public void resolvePlaceholders() {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    assertThat(resolver.resolvePlaceholders("Replace this ${key}"), equalTo("Replace this value"));
  }
View Full Code Here

  }

  @Test
  public void resolvePlaceholders_withUnresolvable() {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    assertThat(resolver.resolvePlaceholders("Replace this ${key} plus ${unknown}"),
        equalTo("Replace this value plus ${unknown}"));
  }
View Full Code Here

  }

  @Test
  public void resolvePlaceholders_withDefaultValue() {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    assertThat(resolver.resolvePlaceholders("Replace this ${key} plus ${unknown:defaultValue}"),
        equalTo("Replace this value plus defaultValue"));
  }
View Full Code Here

  }

  @Test
  public void resolveRequiredPlaceholders() {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    assertThat(resolver.resolveRequiredPlaceholders("Replace this ${key}"), equalTo("Replace this value"));
  }
View Full Code Here

  }

  @Test(expected=IllegalArgumentException.class)
  public void resolveRequiredPlaceholders_withUnresolvable() {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    resolver.resolveRequiredPlaceholders("Replace this ${key} plus ${unknown}");
  }
View Full Code Here

  }

  @Test
  public void resolveRequiredPlaceholders_withDefaultValue() {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("key", "value"));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    assertThat(resolver.resolveRequiredPlaceholders("Replace this ${key} plus ${unknown:defaultValue}"),
        equalTo("Replace this value plus defaultValue"));
  }
View Full Code Here

  }

  @Test
  public void getPropertyAsClass() throws ClassNotFoundException, LinkageError {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("some.class", SpecificType.class.getName()));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    assertTrue(resolver.getPropertyAsClass("some.class", SomeType.class).equals(SpecificType.class));
  }
View Full Code Here

  }

  @Test
  public void getPropertyAsClass_withInterfaceAsTarget() throws ClassNotFoundException, LinkageError {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("some.class", SomeType.class.getName()));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    assertTrue(resolver.getPropertyAsClass("some.class", SomeType.class).equals(SomeType.class));
  }
View Full Code Here

  }

  @Test(expected=ConversionException.class)
  public void getPropertyAsClass_withMismatchedTypeForValue() {
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(new MockPropertySource().withProperty("some.class", "java.lang.String"));
    PropertyResolver resolver = new PropertySourcesPropertyResolver(propertySources);
    resolver.getPropertyAsClass("some.class", SomeType.class);
  }
View Full Code Here

TOP

Related Classes of org.springframework.mock.env.MockPropertySource

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.