Search in sources :

Example 1 with MockEnvironment

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

the class SpringBootAdminClientEnabledConditionTest method test_nonEmptyUrl_enabled.

@Test
public void test_nonEmptyUrl_enabled() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("spring.boot.admin.url", "http://localhost:8080/management");
    BDDMockito.given(conditionContext.getEnvironment()).willReturn(environment);
    assertTrue(condition.getMatchOutcome(conditionContext, annotatedTypeMetadata).isMatch());
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 2 with MockEnvironment

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

the class SpringBootAdminClientEnabledConditionTest method test_emptyUrl_disabled.

@Test
public void test_emptyUrl_disabled() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("spring.boot.admin.client.enabled", "false");
    BDDMockito.given(conditionContext.getEnvironment()).willReturn(environment);
    assertFalse(condition.getMatchOutcome(conditionContext, annotatedTypeMetadata).isMatch());
}
Also used : MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 3 with MockEnvironment

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

the class LocalDebugPortAvailableConditionTests method getOutcome.

private ConditionOutcome getOutcome() {
    MockEnvironment environment = new MockEnvironment();
    EnvironmentTestUtils.addEnvironment(environment, "spring.devtools.remote.debug.local-port:" + this.port);
    ConditionContext context = mock(ConditionContext.class);
    given(context.getEnvironment()).willReturn(environment);
    ConditionOutcome outcome = this.condition.getMatchOutcome(context, null);
    return outcome;
}
Also used : ConditionContext(org.springframework.context.annotation.ConditionContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) ConditionOutcome(org.springframework.boot.autoconfigure.condition.ConditionOutcome)

Example 4 with MockEnvironment

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

the class DevToolsHomePropertiesPostProcessorTests method ignoresMissingHomeProperties.

@Test
public void ignoresMissingHomeProperties() throws Exception {
    ConfigurableEnvironment environment = new MockEnvironment();
    MockDevToolHomePropertiesPostProcessor postProcessor = new MockDevToolHomePropertiesPostProcessor();
    postProcessor.postProcessEnvironment(environment, null);
    assertThat(environment.getProperty("abc")).isNull();
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 5 with MockEnvironment

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

the class LocalHostWebClientTests method getPageWhenUrlIsRelativeAndNoPortWillUseLocalhost8080.

@Test
public void getPageWhenUrlIsRelativeAndNoPortWillUseLocalhost8080() throws Exception {
    MockEnvironment environment = new MockEnvironment();
    WebClient client = new LocalHostWebClient(environment);
    WebConnection connection = mockConnection();
    client.setWebConnection(connection);
    client.getPage("/test");
    verify(connection).getResponse(this.requestCaptor.capture());
    assertThat(this.requestCaptor.getValue().getUrl()).isEqualTo(new URL("http://localhost:8080/test"));
}
Also used : WebConnection(com.gargoylesoftware.htmlunit.WebConnection) MockEnvironment(org.springframework.mock.env.MockEnvironment) WebClient(com.gargoylesoftware.htmlunit.WebClient) URL(java.net.URL) 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