Examples of MockEnvironment


Examples of org.springframework.mock.env.MockEnvironment

    bf.registerBeanDefinition("testBean",
        genericBeanDefinition(TestBean.class)
          .addPropertyValue("name", "${my.name}")
          .getBeanDefinition());

    MockEnvironment env = new MockEnvironment();
    env.setProperty("my.name", "myValue");

    PropertySourcesPlaceholderConfigurer ppc =
      new PropertySourcesPlaceholderConfigurer();
    ppc.setEnvironment(env);
    ppc.postProcessBeanFactory(bf);
View Full Code Here

Examples of org.springframework.mock.env.MockEnvironment

    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MockPropertySource());

    PropertySourcesPlaceholderConfigurer pc = new PropertySourcesPlaceholderConfigurer();
    pc.setPropertySources(propertySources);
    pc.setEnvironment(new MockEnvironment().withProperty("my.name", "env"));
    pc.setIgnoreUnresolvablePlaceholders(true);
    pc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), equalTo("${my.name}"));
    assertEquals(pc.getAppliedPropertySources().iterator().next(), propertySources.iterator().next());
  }
View Full Code Here

Examples of org.springframework.mock.env.MockEnvironment

      public Object getProperty(String key) {
        return "bar";
      }
    };

    MockEnvironment env = new MockEnvironment();
    env.getPropertySources().addFirst(ps);
    ppc.setEnvironment(env);

    ppc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), equalTo("bar"));
  }
View Full Code Here

Examples of org.springframework.mock.env.MockEnvironment

    PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();

    ppc.setLocalOverride(override);
    ppc.setProperties(new Properties() {{ setProperty("foo", "local"); }});
    ppc.setEnvironment(new MockEnvironment().withProperty("foo", "enclosing"));
    ppc.postProcessBeanFactory(bf);
    if (override) {
      assertThat(bf.getBean(TestBean.class).getName(), equalTo("local"));
    }
    else {
View Full Code Here

Examples of org.springframework.mock.env.MockEnvironment

    ppc.setNullValue("customNull");
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class)
        .addPropertyValue("name", "${my.name}")
        .getBeanDefinition());
    ppc.setEnvironment(new MockEnvironment().withProperty("my.name", "customNull"));
    ppc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), nullValue());
  }
View Full Code Here

Examples of org.springframework.mock.env.MockEnvironment

  public void testDefaultContainerAttributes() {

    final String defaultIp = RuntimeUtils.getIpAddress();
    final String defaultHostname = RuntimeUtils.getHost();

    MockEnvironment environment = new MockEnvironment();

    final ContainerServerApplication containerServerApplication = new ContainerServerApplication();
    containerServerApplication.setEnvironment(environment);

    final ContainerAttributes containerAttributes = containerServerApplication.containerAttributes();
View Full Code Here

Examples of org.springframework.mock.env.MockEnvironment

  public void testContainerAttributesWithCustomContainerIpAndHostname() {

    final String customIp = "123.123.123.123";
    final String customHostname = "testhost";

    MockEnvironment environment = new MockEnvironment();
    environment.setProperty(CONTAINER_IP_KEY, customIp);
    environment.setProperty(CONTAINER_HOST_KEY, customHostname);

    final ContainerServerApplication containerServerApplication = new ContainerServerApplication();
    containerServerApplication.setEnvironment(environment);

    final ContainerAttributes containerAttributes = containerServerApplication.containerAttributes();
View Full Code Here

Examples of org.springframework.mock.env.MockEnvironment

    final String defaultHostname = RuntimeUtils.getHost();

    final String customIp = "";
    final String customHostname = "";

    MockEnvironment environment = new MockEnvironment();
    environment.setProperty(CONTAINER_IP_KEY, customIp);
    environment.setProperty(CONTAINER_HOST_KEY, customHostname);

    final ContainerServerApplication containerServerApplication = new ContainerServerApplication();
    containerServerApplication.setEnvironment(environment);

    final ContainerAttributes containerAttributes = containerServerApplication.containerAttributes();
View Full Code Here

Examples of org.springframework.mock.env.MockEnvironment

  @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

Examples of org.springframework.mock.env.MockEnvironment

    }
  }

  @Test
  public void testSuccessfulValidationWithJSR303() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("test.foo", "123456");
    env.setProperty("test.bar", "654321");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfigurationWithJSR303.class);
    this.context.refresh();
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.