Search in sources :

Example 31 with MockEnvironment

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

the class HealthMvcEndpointTests method init.

@Before
public void init() {
    this.endpoint = mock(HealthEndpoint.class);
    given(this.endpoint.isEnabled()).willReturn(true);
    this.mvc = new HealthMvcEndpoint(this.endpoint);
    this.environment = new MockEnvironment();
    this.mvc.setEnvironment(this.environment);
}
Also used : HealthEndpoint(org.springframework.boot.actuate.endpoint.HealthEndpoint) MockEnvironment(org.springframework.mock.env.MockEnvironment) Before(org.junit.Before)

Example 32 with MockEnvironment

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

the class JmxAutoConfigurationTests method testEnabledMBeanExport.

@Test
public void testEnabledMBeanExport() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("spring.jmx.enabled", "true");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(JmxAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(MBeanExporter.class)).isNotNull();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 33 with MockEnvironment

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

the class JmxAutoConfigurationTests method testDisabledMBeanExport.

@Test(expected = NoSuchBeanDefinitionException.class)
public void testDisabledMBeanExport() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("spring.jmx.enabled", "false");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
    this.context.refresh();
    this.context.getBean(MBeanExporter.class);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) Test(org.junit.Test)

Example 34 with MockEnvironment

use of org.springframework.mock.env.MockEnvironment in project coffeenet-starter by coffeenet.

the class CoffeeNetDiscoveryInstancePropertiesTest method allowedAuthorities.

@Test
public void allowedAuthorities() {
    String allowedAuthorities = "COFFEENET-ADMIN,COFFEENET-USER";
    CoffeeNetConfigurationProperties coffeeNetConfigurationProperties = new CoffeeNetConfigurationProperties();
    coffeeNetConfigurationProperties.setAllowedAuthorities(allowedAuthorities);
    CoffeeNetDiscoveryInstanceProperties sut = new CoffeeNetDiscoveryInstanceProperties(new InetUtils(new InetUtilsProperties()), new ServerProperties(), coffeeNetConfigurationProperties);
    sut.setEnvironment(new MockEnvironment());
    assertThat(sut.getMetadataMap().get("allowedAuthorities"), is(allowedAuthorities));
}
Also used : InetUtilsProperties(org.springframework.cloud.commons.util.InetUtilsProperties) MockEnvironment(org.springframework.mock.env.MockEnvironment) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) CoffeeNetConfigurationProperties(coffee.synyx.autoconfigure.CoffeeNetConfigurationProperties) InetUtils(org.springframework.cloud.commons.util.InetUtils) Test(org.junit.Test)

Example 35 with MockEnvironment

use of org.springframework.mock.env.MockEnvironment in project coffeenet-starter by coffeenet.

the class CoffeeNetDiscoveryInstancePropertiesTest method applicationNameIsUnknown.

@Test
public void applicationNameIsUnknown() {
    CoffeeNetConfigurationProperties coffeeNetConfigurationProperties = new CoffeeNetConfigurationProperties();
    coffeeNetConfigurationProperties.setApplicationName("");
    CoffeeNetDiscoveryInstanceProperties sut = new CoffeeNetDiscoveryInstanceProperties(new InetUtils(new InetUtilsProperties()), new ServerProperties(), coffeeNetConfigurationProperties);
    sut.setEnvironment(new MockEnvironment());
    String unknownApplicationName = "unknown";
    assertThat(sut.getAppname(), is(unknownApplicationName));
    assertThat(sut.getVirtualHostName(), is(unknownApplicationName));
    assertThat(sut.getSecureVirtualHostName(), is(unknownApplicationName));
}
Also used : InetUtilsProperties(org.springframework.cloud.commons.util.InetUtilsProperties) MockEnvironment(org.springframework.mock.env.MockEnvironment) ServerProperties(org.springframework.boot.autoconfigure.web.ServerProperties) CoffeeNetConfigurationProperties(coffee.synyx.autoconfigure.CoffeeNetConfigurationProperties) InetUtils(org.springframework.cloud.commons.util.InetUtils) 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