use of org.springframework.core.env.Environment in project java-chassis by ServiceComb.
the class TestSpringConfiguration method should_resolve_placeholder_in_list_by_spring_environment.
@Test
public void should_resolve_placeholder_in_list_by_spring_environment() {
Environment environment = BeanUtils.getContext().getEnvironment();
String value = environment.getProperty("placeholder");
assertThat(value).isEqualTo("actual-value1,actual-value2");
@SuppressWarnings("unchecked") List<String> list = environment.getProperty("placeholder", List.class);
assertThat(list).containsExactly("actual-value1", "actual-value2");
}
use of org.springframework.core.env.Environment in project xm-ms-entity by xm-online.
the class EntityApp method main.
/**
* Main method, used to run the application.
*
* @param args the command line arguments
* @throws UnknownHostException if the local host name could not be resolved into an address
*/
public static void main(String[] args) throws UnknownHostException {
MdcUtils.putRid();
SpringApplication app = new SpringApplication(EntityApp.class);
DefaultProfileUtil.addDefaultProfile(app);
Environment env = app.run(args).getEnvironment();
String protocol = "http";
if (env.getProperty("server.ssl.key-store") != null) {
protocol = "https";
}
log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getActiveProfiles());
String configServerStatus = env.getProperty("configserver.status");
log.info("\n----------------------------------------------------------\n\t" + "Config Server: \t{}\n----------------------------------------------------------", configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
}
use of org.springframework.core.env.Environment in project spring-framework by spring-projects.
the class BeanDefinitionRegistrarTests method registerWithInjectedMethod.
@Test
void registerWithInjectedMethod() {
Environment environment = mock(Environment.class);
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("environment", environment);
BeanDefinitionRegistrar.of("test", InjectionSample.class).instanceSupplier(instanceContext -> {
InjectionSample bean = new InjectionSample();
instanceContext.method("setEnvironment", Environment.class).invoke(beanFactory, attributes -> bean.setEnvironment(attributes.get(0)));
return bean;
}).register(beanFactory);
assertBeanFactory(beanFactory, () -> {
assertThat(beanFactory.containsBean("test")).isTrue();
assertThat(beanFactory.getBean(InjectionSample.class).environment).isEqualTo(environment);
});
}
use of org.springframework.core.env.Environment in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTestIT method testCleanEnvironment.
@Test
void testCleanEnvironment() {
Environment environment = setupMockedEnvironment();
EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
EnvironmentVariableHandlerFactory factory = new EmailEnvironmentVariableHandlerFactory(emailGlobalConfigAccessor, environmentVariableUtility, validator);
EnvironmentVariableHandler handler = factory.build();
EnvironmentProcessingResult result = handler.updateFromEnvironment();
assertEquals(ChannelKeys.EMAIL.getDisplayName(), handler.getName());
assertTrue(result.hasValues());
assertEquals(TEST_AUTH_REQUIRED, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_REQUIRED_KEY).orElse("Auth required value missing"));
assertEquals(TEST_FROM, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_FROM_KEY).orElse("SMTP from value missing"));
assertEquals(TEST_SMTP_HOST, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_HOST_KEY).orElse("SMTP host value missing"));
assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_PASSWORD_KEY).orElse("Auth password value missing"));
assertEquals(TEST_PORT, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.EMAIL_PORT_KEY).orElse("SMTP port value missing"));
assertEquals(TEST_USER, result.getVariableValue(EmailEnvironmentVariableHandlerFactory.AUTH_USER_KEY).orElse("Auth user value missing"));
}
use of org.springframework.core.env.Environment in project hub-alert by blackducksoftware.
the class EmailEnvironmentHandlerFactoryTestIT method setupMockedEnvironment.
private Environment setupMockedEnvironment() {
Environment environment = Mockito.mock(Environment.class);
Predicate<String> hasEnvVarCheck = (variableName) -> !EmailEnvironmentVariableHandlerFactory.OLD_ADDITIONAL_PROPERTY_KEYSET.contains(variableName);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_REQUIRED_KEY, TEST_AUTH_REQUIRED);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_FROM_KEY, TEST_FROM);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_HOST_KEY, TEST_SMTP_HOST);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_PASSWORD_KEY, TEST_PASSWORD);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.EMAIL_PORT_KEY, TEST_PORT);
EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, hasEnvVarCheck, EmailEnvironmentVariableHandlerFactory.AUTH_USER_KEY, TEST_USER);
return environment;
}
Aggregations