Search in sources :

Example 46 with MockEnvironment

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

the class TestPropertySourceUtilsTests method addInlinedPropertiesToEnvironmentWithEmptyProperty.

@Test
@SuppressWarnings("rawtypes")
public void addInlinedPropertiesToEnvironmentWithEmptyProperty() {
    ConfigurableEnvironment environment = new MockEnvironment();
    MutablePropertySources propertySources = environment.getPropertySources();
    propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
    assertEquals(0, propertySources.size());
    addInlinedPropertiesToEnvironment(environment, asArray("  "));
    assertEquals(1, propertySources.size());
    assertEquals(0, ((Map) propertySources.iterator().next().getSource()).size());
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockEnvironment(org.springframework.mock.env.MockEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Test(org.junit.Test)

Example 47 with MockEnvironment

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

the class EndpointMBeanExportAutoConfigurationTests method testEndpointMBeanExporterIsNotInstalled.

@Test(expected = NoSuchBeanDefinitionException.class)
public void testEndpointMBeanExporterIsNotInstalled() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("endpoints.jmx.enabled", "false");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(environment);
    this.context.register(JmxAutoConfiguration.class, EndpointAutoConfiguration.class, EndpointMBeanExportAutoConfiguration.class);
    this.context.refresh();
    this.context.getBean(EndpointMBeanExporter.class);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 48 with MockEnvironment

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

the class JmxAutoConfigurationTests method testDefaultDomainConfiguredOnMBeanExport.

@Test
public void testDefaultDomainConfiguredOnMBeanExport() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("spring.jmx.enabled", "true");
    env.setProperty("spring.jmx.default-domain", "my-test-domain");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
    this.context.refresh();
    MBeanExporter mBeanExporter = this.context.getBean(MBeanExporter.class);
    assertThat(mBeanExporter).isNotNull();
    MetadataNamingStrategy naming = (MetadataNamingStrategy) ReflectionTestUtils.getField(mBeanExporter, "namingStrategy");
    assertThat(ReflectionTestUtils.getField(naming, "defaultDomain")).isEqualTo("my-test-domain");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) IntegrationMBeanExporter(org.springframework.integration.monitor.IntegrationMBeanExporter) MBeanExporter(org.springframework.jmx.export.MBeanExporter) MetadataNamingStrategy(org.springframework.jmx.export.naming.MetadataNamingStrategy) Test(org.junit.Test)

Example 49 with MockEnvironment

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

the class ResourceBannerTests method printBanner.

private String printBanner(Resource resource, String bootVersion, String applicationVersion, String applicationTitle) {
    ResourceBanner banner = new MockResourceBanner(resource, bootVersion, applicationVersion, applicationTitle);
    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));
    return out.toString();
}
Also used : PrintStream(java.io.PrintStream) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockEnvironment(org.springframework.mock.env.MockEnvironment) MapPropertySource(org.springframework.core.env.MapPropertySource) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 50 with MockEnvironment

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

the class ImageBannerTests method printBanner.

private String printBanner(String path, String... properties) {
    ImageBanner banner = new ImageBanner(new ClassPathResource(path, getClass()));
    ConfigurableEnvironment environment = new MockEnvironment();
    TestPropertySourceUtils.addInlinedPropertiesToEnvironment(environment, properties);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    banner.printBanner(environment, getClass(), new PrintStream(out));
    return out.toString();
}
Also used : PrintStream(java.io.PrintStream) ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockEnvironment(org.springframework.mock.env.MockEnvironment) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ClassPathResource(org.springframework.core.io.ClassPathResource)

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