Search in sources :

Example 26 with MockEnvironment

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

the class TestPropertySourceUtilsTests method addInlinedPropertiesToEnvironmentWithMultipleKeyValuePairsInSingleInlinedProperty.

@Test
public void addInlinedPropertiesToEnvironmentWithMultipleKeyValuePairsInSingleInlinedProperty() {
    expectedException.expect(IllegalStateException.class);
    expectedException.expectMessage("Failed to load exactly one test environment property");
    addInlinedPropertiesToEnvironment(new MockEnvironment(), asArray("a=b\nx=y"));
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 27 with MockEnvironment

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

the class TestPropertySourceUtilsTests method addPropertiesFilesToEnvironmentWithEnvironmentAndNullLocations.

@Test
public void addPropertiesFilesToEnvironmentWithEnvironmentAndNullLocations() {
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("must not be null");
    addPropertiesFilesToEnvironment(new MockEnvironment(), mock(ResourceLoader.class), (String[]) null);
}
Also used : ResourceLoader(org.springframework.core.io.ResourceLoader) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 28 with MockEnvironment

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

the class EndpointMBeanExportAutoConfigurationTests method testEndpointMBeanExporterWithProperties.

@Test
public void testEndpointMBeanExporterWithProperties() throws IntrospectionException, InstanceNotFoundException, MalformedObjectNameException, ReflectionException {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("endpoints.jmx.domain", "test-domain");
    environment.setProperty("endpoints.jmx.unique_names", "true");
    environment.setProperty("endpoints.jmx.static_names", "key1=value1, key2=value2");
    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);
    MBeanExporter mbeanExporter = this.context.getBean(EndpointMBeanExporter.class);
    assertThat(mbeanExporter.getServer().getMBeanInfo(ObjectNameManager.getInstance(getObjectName("test-domain", "healthEndpoint", this.context).toString() + ",key1=value1,key2=value2"))).isNotNull();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) EndpointMBeanExporter(org.springframework.boot.actuate.endpoint.jmx.EndpointMBeanExporter) MBeanExporter(org.springframework.jmx.export.MBeanExporter) Test(org.junit.Test)

Example 29 with MockEnvironment

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

the class DefaultServletWebServerFactoryCustomizerTests method deduceUseForwardHeadersJetty.

@Test
public void deduceUseForwardHeadersJetty() throws Exception {
    this.customizer.setEnvironment(new MockEnvironment().withProperty("DYNO", "-"));
    JettyServletWebServerFactory factory = spy(new JettyServletWebServerFactory());
    this.customizer.customize(factory);
    verify(factory).setUseForwardHeaders(true);
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) JettyServletWebServerFactory(org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory) Test(org.junit.Test)

Example 30 with MockEnvironment

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

the class LogFileMvcEndpointTests method before.

@Before
public void before() throws IOException {
    this.logFile = this.temp.newFile();
    FileCopyUtils.copy("--TEST--".getBytes(), this.logFile);
    this.environment = new MockEnvironment();
    this.mvc = new LogFileMvcEndpoint();
    this.mvc.setEnvironment(this.environment);
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Before(org.junit.Before)

Aggregations

MockEnvironment (org.springframework.mock.env.MockEnvironment)63 Test (org.junit.Test)53 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 LoggingInitializationContext (org.springframework.boot.logging.LoggingInitializationContext)5 CoffeeNetConfigurationProperties (coffee.synyx.autoconfigure.CoffeeNetConfigurationProperties)4 URL (java.net.URL)4 Before (org.junit.Before)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 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 WebWindow (com.gargoylesoftware.htmlunit.WebWindow)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2