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");
}
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;
}
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);
}
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);
}
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();
}
Aggregations