use of org.springframework.core.env.StandardEnvironment in project chassis by Kixeye.
the class SharedTest method testProperties.
@Test
public void testProperties() throws Exception {
Map<String, Object> properties = new HashMap<String, Object>();
properties.put("admin.enabled", "true");
properties.put("admin.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("admin.hostname", "localhost");
properties.put("websocket.enabled", "true");
properties.put("websocket.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("websocket.hostname", "localhost");
properties.put("http.enabled", "true");
properties.put("http.port", "" + SocketUtils.findAvailableTcpPort());
properties.put("http.hostname", "localhost");
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new MapPropertySource("default", properties));
context.setEnvironment(environment);
context.register(PropertySourcesPlaceholderConfigurer.class);
context.register(TransportConfiguration.class);
context.register(MetricsConfiguration.class);
RestTemplate httpClient = new RestTemplate();
try {
context.refresh();
httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR));
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
for (MessageSerDe messageSerDe : context.getBeansOfType(MessageSerDe.class).values()) {
messageConverters.add(new SerDeHttpMessageConverter(messageSerDe));
}
messageConverters.add(new StringHttpMessageConverter(StandardCharsets.UTF_8));
httpClient.setMessageConverters(messageConverters);
ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("admin.port") + "/admin/properties"), String.class);
logger.info("Got response: [{}]", response);
Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value());
Assert.assertTrue(response.getBody().contains("user.dir=" + System.getProperty("user.dir")));
} finally {
context.close();
}
}
use of org.springframework.core.env.StandardEnvironment in project chassis by Kixeye.
the class MetadataCollectorTest method setup.
@Before
public void setup() {
ConfigurationManager.getConfigInstance().setProperty("chassis.eureka.disable", "true");
ConfigurationManager.getConfigInstance().setProperty("eureka.metadata.prop1", "propValue");
ConfigurationManager.getConfigInstance().setProperty("eureka.datacenter", "default");
StandardEnvironment environment = new StandardEnvironment();
environment.getPropertySources().addFirst(new ArchaiusSpringPropertySource());
context = new AnnotationConfigApplicationContext();
context.setEnvironment(environment);
context.register(MetadataCollectorConfiguration.class);
context.refresh();
context.start();
}
Aggregations