Search in sources :

Example 36 with MockEnvironment

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

the class CoffeeNetDiscoveryInstancePropertiesTest method applicationName.

@Test
public void applicationName() {
    String brandNewApplicationName = "BrandNewApplicationName";
    CoffeeNetConfigurationProperties coffeeNetConfigurationProperties = new CoffeeNetConfigurationProperties();
    coffeeNetConfigurationProperties.setApplicationName(brandNewApplicationName);
    CoffeeNetDiscoveryInstanceProperties sut = new CoffeeNetDiscoveryInstanceProperties(new InetUtils(new InetUtilsProperties()), new ServerProperties(), coffeeNetConfigurationProperties);
    sut.setEnvironment(new MockEnvironment());
    assertThat(sut.getAppname(), is(brandNewApplicationName));
    assertThat(sut.getVirtualHostName(), is(brandNewApplicationName));
    assertThat(sut.getSecureVirtualHostName(), is(brandNewApplicationName));
}
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 37 with MockEnvironment

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

the class CoffeeNetDiscoveryInstancePropertiesTest method allowedAuthoritiesNotProvided.

@Test
public void allowedAuthoritiesNotProvided() {
    CoffeeNetDiscoveryInstanceProperties sut = new CoffeeNetDiscoveryInstanceProperties(new InetUtils(new InetUtilsProperties()), new ServerProperties(), new CoffeeNetConfigurationProperties());
    sut.getMetadataMap().put("allowedAuthorities", "alreadySetAndNoneFromCoffeeNet");
    sut.setEnvironment(new MockEnvironment());
    assertThat(sut.getMetadataMap().get("allowedAuthorities"), is("alreadySetAndNoneFromCoffeeNet"));
}
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 38 with MockEnvironment

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

the class SpringBootAdminClientEnabledConditionTest method test_nonEmptyUrl_disabled.

@Test
public void test_nonEmptyUrl_disabled() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("spring.boot.admin.client.enabled", "false");
    environment.setProperty("spring.boot.admin.url", "http://localhost:8080/management");
    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 39 with MockEnvironment

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

the class SpringBootAdminClientEnabledConditionTest method test_emptyUrl_enabled.

@Test
public void test_emptyUrl_enabled() {
    MockEnvironment environment = new MockEnvironment();
    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 40 with MockEnvironment

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

the class DefaultApplicationFactoryTest method publishApplicationReadyEvent.

private void publishApplicationReadyEvent(DefaultApplicationFactory factory, Integer serverport, Integer managementport) {
    MockEnvironment env = new MockEnvironment();
    if (serverport != null) {
        env.setProperty("local.server.port", serverport.toString());
    }
    if (managementport != null) {
        env.setProperty("local.management.port", managementport.toString());
    }
    ConfigurableWebApplicationContext context = mock(ConfigurableWebApplicationContext.class);
    when(context.getEnvironment()).thenReturn(env);
    factory.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), new String[] {}, context));
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) MockEnvironment(org.springframework.mock.env.MockEnvironment) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

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