Package org.springframework.mock.env

Examples of org.springframework.mock.env.MockPropertySource


  }

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


  }

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

  }

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

  }

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

  }

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

  }

  @Test
  public void resolveNestedPropertyPlaceholders() {
    MutablePropertySources ps = new MutablePropertySources();
    ps.addFirst(new MockPropertySource()
      .withProperty("p1", "v1")
      .withProperty("p2", "v2")
      .withProperty("p3", "${p1}:${p2}")              // nested placeholders
      .withProperty("p4", "${p3}")                    // deeply nested placeholders
      .withProperty("p5", "${p1}:${p2}:${bogus}")     // unresolvable placeholder
View Full Code Here

  }

  @Test
  public void ignoreUnresolvableNestedPlaceholdersIsConfigurable() {
    MutablePropertySources ps = new MutablePropertySources();
    ps.addFirst(new MockPropertySource()
      .withProperty("p1", "v1")
      .withProperty("p2", "v2")
      .withProperty("p3", "${p1}:${p2}:${bogus:def}") // unresolvable w/ default
      .withProperty("p4", "${p1}:${p2}:${bogus}")     // unresolvable placeholder
    );
View Full Code Here

  @Test
  public void merge() {
    ConfigurableEnvironment child = new StandardEnvironment();
    child.setActiveProfiles("c1", "c2");
    child.getPropertySources().addLast(
        new MockPropertySource("childMock")
            .withProperty("childKey", "childVal")
            .withProperty("bothKey", "childBothVal"));

    ConfigurableEnvironment parent = new StandardEnvironment();
    parent.setActiveProfiles("p1", "p2");
    parent.getPropertySources().addLast(
        new MockPropertySource("parentMock")
            .withProperty("parentKey", "parentVal")
            .withProperty("bothKey", "parentBothVal"));

    assertThat(child.getProperty("childKey"), is("childVal"));
    assertThat(child.getProperty("parentKey"), nullValue());
View Full Code Here

  @Test
  public void addActiveProfile_whenActiveProfilesPropertyIsAlreadySet() {
    ConfigurableEnvironment env = new StandardEnvironment();
    assertThat(env.getProperty(ACTIVE_PROFILES_PROPERTY_NAME), nullValue());
    env.getPropertySources().addFirst(new MockPropertySource().withProperty(ACTIVE_PROFILES_PROPERTY_NAME, "p1"));
    assertThat(env.getProperty(ACTIVE_PROFILES_PROPERTY_NAME), equalTo("p1"));
    env.addActiveProfile("p2");
    assertThat(env.getActiveProfiles(), arrayContaining("p1", "p2"));
  }
View Full Code Here

  }

  @Test
  public void getDefaultProfiles() {
    assertThat(environment.getDefaultProfiles(), equalTo(new String[] {RESERVED_DEFAULT_PROFILE_NAME}));
    environment.getPropertySources().addFirst(new MockPropertySource().withProperty(DEFAULT_PROFILES_PROPERTY_NAME, "pd1"));
    assertThat(environment.getDefaultProfiles().length, is(1));
    assertThat(Arrays.asList(environment.getDefaultProfiles()), hasItem("pd1"));
  }
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.