Search in sources :

Example 1 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ConditionalOnExpressionTests method expressionEvaluationWithNoBeanFactoryDoesNotMatch.

@Test
void expressionEvaluationWithNoBeanFactoryDoesNotMatch() {
    OnExpressionCondition condition = new OnExpressionCondition();
    MockEnvironment environment = new MockEnvironment();
    ConditionEvaluationContext evaluationContext = mock(ConditionEvaluationContext.class);
    given(evaluationContext.getEnvironment()).willReturn(environment);
    ConditionOutcome outcome = condition.getMatchOutcome(evaluationContext, mockMetaData("invalid-spel"));
    assertThat(outcome.isMatch()).isFalse();
    assertThat(outcome.getMessage()).contains("invalid-spel").contains("no BeanFactory available");
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) ConditionEvaluationContext(cn.taketoday.context.annotation.ConditionEvaluationContext) Test(org.junit.jupiter.api.Test)

Example 2 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ConfigDataActivationContextTests method createKubernetesEnvironment.

private MockEnvironment createKubernetesEnvironment() {
    MockEnvironment environment = new MockEnvironment();
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("KUBERNETES_SERVICE_HOST", "host");
    map.put("KUBERNETES_SERVICE_PORT", "port");
    PropertySource<?> propertySource = new MapPropertySource(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, map);
    environment.getPropertySources().addLast(propertySource);
    return environment;
}
Also used : MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MapPropertySource(cn.taketoday.core.env.MapPropertySource) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ConfigDataActivationContextTests method getCloudPlatformWhenCloudPropertyInEnvironmentDeducesCloudPlatform.

@Test
void getCloudPlatformWhenCloudPropertyInEnvironmentDeducesCloudPlatform() {
    MockEnvironment environment = createKubernetesEnvironment();
    Binder binder = Binder.get(environment);
    ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
    assertThat(context.getCloudPlatform()).isEqualTo(CloudPlatform.KUBERNETES);
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 4 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ConfigDataActivationContextTests method getProfilesWhenWithProfilesReturnsProfiles.

@Test
void getProfilesWhenWithProfilesReturnsProfiles() {
    MockEnvironment environment = new MockEnvironment();
    environment.setActiveProfiles("a", "b", "c");
    Binder binder = Binder.get(environment);
    ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
    Profiles profiles = new Profiles(environment, binder, null);
    context = context.withProfiles(profiles);
    assertThat(context.getProfiles()).isEqualTo(profiles);
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Test(org.junit.jupiter.api.Test)

Example 5 with MockEnvironment

use of cn.taketoday.mock.env.MockEnvironment in project today-infrastructure by TAKETODAY.

the class ConfigDataActivationContextTests method getCloudPlatformWhenCloudPropertyNotPresentDeducesCloudPlatform.

@Test
void getCloudPlatformWhenCloudPropertyNotPresentDeducesCloudPlatform() {
    Environment environment = new MockEnvironment();
    Binder binder = Binder.get(environment);
    ConfigDataActivationContext context = new ConfigDataActivationContext(environment, binder);
    assertThat(context.getCloudPlatform()).isNull();
}
Also used : Binder(cn.taketoday.context.properties.bind.Binder) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) MockEnvironment(cn.taketoday.mock.env.MockEnvironment) Environment(cn.taketoday.core.env.Environment) StandardEnvironment(cn.taketoday.core.env.StandardEnvironment) Test(org.junit.jupiter.api.Test)

Aggregations

MockEnvironment (cn.taketoday.mock.env.MockEnvironment)132 Test (org.junit.jupiter.api.Test)118 Binder (cn.taketoday.context.properties.bind.Binder)84 Environment (cn.taketoday.core.env.Environment)24 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)16 MapConfigurationPropertySource (cn.taketoday.context.properties.source.MapConfigurationPropertySource)12 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)8 MapPropertySource (cn.taketoday.core.env.MapPropertySource)6 SystemEnvironmentPropertySource (cn.taketoday.core.env.SystemEnvironmentPropertySource)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6 ConfigurationPropertySource (cn.taketoday.context.properties.source.ConfigurationPropertySource)4 PropertySources (cn.taketoday.core.env.PropertySources)4 TestPropertySourceUtils.buildMergedTestPropertySources (cn.taketoday.test.context.support.TestPropertySourceUtils.buildMergedTestPropertySources)4 ArrayList (java.util.ArrayList)4 LinkedHashMap (java.util.LinkedHashMap)4 ConditionEvaluationContext (cn.taketoday.context.annotation.ConditionEvaluationContext)2 ByteArrayResource (cn.taketoday.core.io.ByteArrayResource)2 DefaultResourceLoader (cn.taketoday.core.io.DefaultResourceLoader)2 ResourceLoader (cn.taketoday.core.io.ResourceLoader)2 ApplicationBuilder (cn.taketoday.framework.builder.ApplicationBuilder)2