Package org.springframework.mock.env

Examples of org.springframework.mock.env.MockEnvironment


    }
  }

  @Test
  public void propertyPlaceholderEnvironmentProperties() throws Exception {
    MockEnvironment env = new MockEnvironment().withProperty("foo", "spam");
    GenericXmlApplicationContext applicationContext = new GenericXmlApplicationContext();
    applicationContext.setEnvironment(env);
    applicationContext.load(new ClassPathResource("contextNamespaceHandlerTests-simple.xml", getClass()));
    applicationContext.refresh();
    Map<String, PlaceholderConfigurerSupport> beans = applicationContext
View Full Code Here


    }

    {
      ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext();
      ctx.getEnvironment().setRequiredProperties("foo");
      ctx.setEnvironment(new MockEnvironment().withProperty("foo", "fooValue"));
      ctx.refresh(); // should succeed
    }
  }
View Full Code Here

    }
  }

  @Test
  public void testPlaceholderBased() throws Exception {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("serverName", "server");
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.setEnvironment(env);
    ctx.register(PlaceholderBasedConfiguration.class);
    ctx.refresh();
    try {
View Full Code Here

    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

    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

      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

    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

    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

  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

  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

TOP

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

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.