Search in sources :

Example 1 with MockEnvironment

use of cn.taketoday.context.support.MockEnvironment in project today-infrastructure by TAKETODAY.

the class EnvironmentConverterTests method convertedEnvironmentHasSameActiveProfiles.

@Test
void convertedEnvironmentHasSameActiveProfiles() {
    AbstractEnvironment originalEnvironment = new MockEnvironment();
    originalEnvironment.setActiveProfiles("activeProfile1", "activeProfile2");
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), originalEnvironment, StandardEnvironment.class);
    assertThat(convertedEnvironment.getActiveProfiles()).containsExactly("activeProfile1", "activeProfile2");
}
Also used : MockEnvironment(cn.taketoday.context.support.MockEnvironment) AbstractEnvironment(cn.taketoday.core.env.AbstractEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 2 with MockEnvironment

use of cn.taketoday.context.support.MockEnvironment in project today-framework by TAKETODAY.

the class EnableMBeanExportConfigurationTests method testPlaceholderBased.

@Test
public void testPlaceholderBased() throws Exception {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("serverName", "server");
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
    context.setEnvironment(env);
    context.register(PlaceholderBasedConfiguration.class);
    context.refresh();
    this.ctx = context;
    validateAnnotationTestBean();
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(cn.taketoday.context.support.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 3 with MockEnvironment

use of cn.taketoday.context.support.MockEnvironment in project today-framework by TAKETODAY.

the class EnvironmentConverterTests method convertedEnvironmentHasSameConversionService.

@Test
void convertedEnvironmentHasSameConversionService() {
    AbstractEnvironment originalEnvironment = new MockEnvironment();
    ConfigurableConversionService conversionService = mock(ConfigurableConversionService.class);
    originalEnvironment.setConversionService(conversionService);
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), originalEnvironment, StandardEnvironment.class);
    assertThat(convertedEnvironment.getConversionService()).isEqualTo(conversionService);
}
Also used : MockEnvironment(cn.taketoday.context.support.MockEnvironment) AbstractEnvironment(cn.taketoday.core.env.AbstractEnvironment) ConfigurableConversionService(cn.taketoday.core.conversion.support.ConfigurableConversionService) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Example 4 with MockEnvironment

use of cn.taketoday.context.support.MockEnvironment in project today-framework by TAKETODAY.

the class EnableCachingIntegrationTests method beanConditionOn.

@Test
public void beanConditionOn() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.setEnvironment(new MockEnvironment().withProperty("bar.enabled", "true"));
    ctx.register(BeanConditionConfig.class);
    ctx.refresh();
    this.context = ctx;
    FooService service = this.context.getBean(FooService.class);
    Cache cache = getCache();
    Object key = new Object();
    Object value = service.getWithCondition(key);
    assertCacheHit(key, value, cache);
    value = service.getWithCondition(key);
    assertCacheHit(key, value, cache);
    assertThat(this.context.getBean(BeanConditionConfig.Bar.class).count).isEqualTo(2);
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) MockEnvironment(cn.taketoday.context.support.MockEnvironment) Cache(cn.taketoday.cache.Cache) Test(org.junit.jupiter.api.Test)

Example 5 with MockEnvironment

use of cn.taketoday.context.support.MockEnvironment in project today-framework by TAKETODAY.

the class EnvironmentConverterTests method convertedEnvironmentHasSameActiveProfiles.

@Test
void convertedEnvironmentHasSameActiveProfiles() {
    AbstractEnvironment originalEnvironment = new MockEnvironment();
    originalEnvironment.setActiveProfiles("activeProfile1", "activeProfile2");
    StandardEnvironment convertedEnvironment = EnvironmentConverter.convertIfNecessary(getClass().getClassLoader(), originalEnvironment, StandardEnvironment.class);
    assertThat(convertedEnvironment.getActiveProfiles()).containsExactly("activeProfile1", "activeProfile2");
}
Also used : MockEnvironment(cn.taketoday.context.support.MockEnvironment) AbstractEnvironment(cn.taketoday.core.env.AbstractEnvironment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

MockEnvironment (cn.taketoday.context.support.MockEnvironment)8 Test (org.junit.jupiter.api.Test)8 AnnotationConfigApplicationContext (cn.taketoday.context.annotation.AnnotationConfigApplicationContext)4 AbstractEnvironment (cn.taketoday.core.env.AbstractEnvironment)4 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)4 Cache (cn.taketoday.cache.Cache)2 ConfigurableConversionService (cn.taketoday.core.conversion.support.ConfigurableConversionService)2