Search in sources :

Example 6 with MockEnvironment

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

the class LocalHostUriTemplateHandlerTests method getRootUriShouldUseContextPath.

@Test
public void getRootUriShouldUseContextPath() throws Exception {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("server.servlet.context-path", "/foo");
    LocalHostUriTemplateHandler handler = new LocalHostUriTemplateHandler(environment);
    assertThat(handler.getRootUri()).isEqualTo("http://localhost:8080/foo");
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 7 with MockEnvironment

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

the class CloudPlatformTests method getActiveWhenHasVcapServicesShouldReturnCloudFoundry.

@Test
public void getActiveWhenHasVcapServicesShouldReturnCloudFoundry() throws Exception {
    Environment environment = new MockEnvironment().withProperty("VCAP_SERVICES", "---");
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isEqualTo(CloudPlatform.CLOUD_FOUNDRY);
    assertThat(platform.isActive(environment)).isTrue();
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 8 with MockEnvironment

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

the class CloudPlatformTests method getActiveWhenHasDynoShouldReturnHeroku.

@Test
public void getActiveWhenHasDynoShouldReturnHeroku() throws Exception {
    Environment environment = new MockEnvironment().withProperty("DYNO", "---");
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isEqualTo(CloudPlatform.HEROKU);
    assertThat(platform.isActive(environment)).isTrue();
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 9 with MockEnvironment

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

the class CloudPlatformTests method getActiveWhenHasVcapApplicationShouldReturnCloudFoundry.

@Test
public void getActiveWhenHasVcapApplicationShouldReturnCloudFoundry() throws Exception {
    Environment environment = new MockEnvironment().withProperty("VCAP_APPLICATION", "---");
    CloudPlatform platform = CloudPlatform.getActive(environment);
    assertThat(platform).isEqualTo(CloudPlatform.CLOUD_FOUNDRY);
    assertThat(platform.isActive(environment)).isTrue();
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Environment(org.springframework.core.env.Environment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 10 with MockEnvironment

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

the class ConfigurationPropertiesBindingPostProcessorTests method testSuccessfulValidationWithInterface.

@Test
public void testSuccessfulValidationWithInterface() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("test.foo", "bar");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfigurationWithValidationAndInterface.class);
    this.context.refresh();
    assertThat(this.context.getBean(ValidatedPropertiesImpl.class).getFoo()).isEqualTo("bar");
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) 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