Search in sources :

Example 11 with MockEnvironment

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

the class ConfigurationPropertiesBindingPostProcessorTests method testValidationWithCustomValidatorNotSupported.

@Test
public void testValidationWithCustomValidatorNotSupported() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("test.foo", "bar");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfigurationWithCustomValidator.class, PropertyWithValidatingSetter.class);
    assertBindingFailure(1);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 12 with MockEnvironment

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

the class SpringBootJoranConfiguratorTests method setup.

@Before
public void setup() {
    this.environment = new MockEnvironment();
    this.initializationContext = new LoggingInitializationContext(this.environment);
    this.configurator = new SpringBootJoranConfigurator(this.initializationContext);
    StaticLoggerBinder binder = StaticLoggerBinder.getSingleton();
    this.context = (LoggerContext) binder.getLoggerFactory();
    this.logger = this.context.getLogger(getClass());
}
Also used : LoggingInitializationContext(org.springframework.boot.logging.LoggingInitializationContext) StaticLoggerBinder(org.slf4j.impl.StaticLoggerBinder) MockEnvironment(org.springframework.mock.env.MockEnvironment) Before(org.junit.Before)

Example 13 with MockEnvironment

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

the class LogbackLoggingSystemTests method setup.

@Before
public void setup() {
    this.loggingSystem.cleanUp();
    this.logger = new SLF4JLogFactory().getInstance(getClass().getName());
    this.environment = new MockEnvironment();
    this.initializationContext = new LoggingInitializationContext(this.environment);
}
Also used : LoggingInitializationContext(org.springframework.boot.logging.LoggingInitializationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) SLF4JLogFactory(org.apache.commons.logging.impl.SLF4JLogFactory) Before(org.junit.Before)

Example 14 with MockEnvironment

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

the class LogbackLoggingSystemTests method testConsolePatternProperty.

@Test
public void testConsolePatternProperty() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.console", "%logger %msg");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(environment);
    this.loggingSystem.initialize(loggingInitializationContext, null, null);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertThat(getLineWithText(output, "Hello world")).doesNotContain("INFO");
}
Also used : LoggingInitializationContext(org.springframework.boot.logging.LoggingInitializationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 15 with MockEnvironment

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

the class LogbackLoggingSystemTests method testFilePatternProperty.

@Test
public void testFilePatternProperty() throws Exception {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("logging.pattern.file", "%logger %msg");
    LoggingInitializationContext loggingInitializationContext = new LoggingInitializationContext(environment);
    File file = new File(tmpDir(), "logback-test.log");
    LogFile logFile = getLogFile(file.getPath(), null);
    this.loggingSystem.initialize(loggingInitializationContext, null, logFile);
    this.logger.info("Hello world");
    String output = this.output.toString().trim();
    assertThat(getLineWithText(output, "Hello world")).contains("INFO");
    assertThat(getLineWithText(file, "Hello world")).doesNotContain("INFO");
}
Also used : LogFile(org.springframework.boot.logging.LogFile) LoggingInitializationContext(org.springframework.boot.logging.LoggingInitializationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) Matchers.containsString(org.hamcrest.Matchers.containsString) LogFile(org.springframework.boot.logging.LogFile) File(java.io.File) Test(org.junit.Test)

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