Search in sources :

Example 41 with MockEnvironment

use of org.springframework.mock.env.MockEnvironment in project spring-boot-admin by codecentric.

the class DefaultApplicationFactoryTest method publishApplicationReadyEvent.

private void publishApplicationReadyEvent(DefaultApplicationFactory factory, Integer serverport, Integer managementport) {
    MockEnvironment env = new MockEnvironment();
    if (serverport != null) {
        env.setProperty("local.server.port", serverport.toString());
    }
    if (managementport != null) {
        env.setProperty("local.management.port", managementport.toString());
    }
    ConfigurableWebApplicationContext context = mock(ConfigurableWebApplicationContext.class);
    when(context.getEnvironment()).thenReturn(env);
    factory.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), new String[] {}, context));
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 42 with MockEnvironment

use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.

the class TestPropertySourceUtilsTests method addInlinedPropertiesToEnvironmentWithEnvironmentAndNullInlinedProperties.

@Test
public void addInlinedPropertiesToEnvironmentWithEnvironmentAndNullInlinedProperties() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("inlined");
    addInlinedPropertiesToEnvironment(new MockEnvironment(), (String[]) null);
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 43 with MockEnvironment

use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.

the class PropertySourcesPlaceholderConfigurerTests method trimValuesIsApplied.

@Test
public void trimValuesIsApplied() {
    PropertySourcesPlaceholderConfigurer ppc = new PropertySourcesPlaceholderConfigurer();
    ppc.setTrimValues(true);
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
    ppc.setEnvironment(new MockEnvironment().withProperty("my.name", " myValue  "));
    ppc.postProcessBeanFactory(bf);
    assertThat(bf.getBean(TestBean.class).getName(), equalTo("myValue"));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) MockEnvironment(org.springframework.mock.env.MockEnvironment) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 44 with MockEnvironment

use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.

the class PropertySourcesPlaceholderConfigurerTests method replacementFromEnvironmentProperties.

@Test
public void replacementFromEnvironmentProperties() {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    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);
    assertThat(bf.getBean(TestBean.class).getName(), equalTo("myValue"));
    assertThat(ppc.getAppliedPropertySources(), not(nullValue()));
}
Also used : TestBean(org.springframework.tests.sample.beans.TestBean) MockEnvironment(org.springframework.mock.env.MockEnvironment) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Test(org.junit.Test)

Example 45 with MockEnvironment

use of org.springframework.mock.env.MockEnvironment in project spring-framework by spring-projects.

the class TestPropertySourceUtilsTests method addInlinedPropertiesToEnvironmentWithMalformedUnicodeInValue.

@Test
public void addInlinedPropertiesToEnvironmentWithMalformedUnicodeInValue() {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Failed to load test environment property");
    addInlinedPropertiesToEnvironment(new MockEnvironment(), asArray("key = \\uZZZZ"));
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Aggregations

MockEnvironment (org.springframework.mock.env.MockEnvironment)65 Test (org.junit.Test)54 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)10 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)9 TestBean (org.springframework.tests.sample.beans.TestBean)7 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)6 Before (org.junit.Before)5 LoggingInitializationContext (org.springframework.boot.logging.LoggingInitializationContext)5 CoffeeNetConfigurationProperties (coffee.synyx.autoconfigure.CoffeeNetConfigurationProperties)4 URL (java.net.URL)4 ServerProperties (org.springframework.boot.autoconfigure.web.ServerProperties)4 InetUtils (org.springframework.cloud.commons.util.InetUtils)4 InetUtilsProperties (org.springframework.cloud.commons.util.InetUtilsProperties)4 Environment (org.springframework.core.env.Environment)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 PrintStream (java.io.PrintStream)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 MutablePropertySources (org.springframework.core.env.MutablePropertySources)3 WebClient (com.gargoylesoftware.htmlunit.WebClient)2 WebConnection (com.gargoylesoftware.htmlunit.WebConnection)2