Search in sources :

Example 26 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project chassis by Kixeye.

the class SharedTest method testAdminLinks.

@Test
public void testAdminLinks() 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/index.html"), String.class);
        logger.info("Got response: [{}]", response);
        Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value());
        Assert.assertTrue(response.getBody().contains("<a href=\"/metrics/ping\">Ping</a>"));
        Assert.assertTrue(response.getBody().contains("<a href=\"/healthcheck\">Healthcheck</a>"));
        Assert.assertTrue(response.getBody().contains("<a href=\"/metrics/metrics?pretty=true\">Metrics</a>"));
        Assert.assertTrue(response.getBody().contains("<a href=\"/admin/properties\">Properties</a>"));
        Assert.assertTrue(response.getBody().contains("<a href=\"/metrics/threads\">Threads</a>"));
        Assert.assertTrue(response.getBody().contains("<a href=\"/admin/classpath\">Classpath</a>"));
    } finally {
        context.close();
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MessageSerDe(com.kixeye.chassis.transport.serde.MessageSerDe) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) URI(java.net.URI) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) MapPropertySource(org.springframework.core.env.MapPropertySource) SerDeHttpMessageConverter(com.kixeye.chassis.transport.http.SerDeHttpMessageConverter) RestTemplate(org.springframework.web.client.RestTemplate) SerDeHttpMessageConverter(com.kixeye.chassis.transport.http.SerDeHttpMessageConverter) StringHttpMessageConverter(org.springframework.http.converter.StringHttpMessageConverter) HttpMessageConverter(org.springframework.http.converter.HttpMessageConverter) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 27 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project chassis by Kixeye.

the class WebSocketDocsTest method testProtobufMessagesSchema.

@Test
public void testProtobufMessagesSchema() 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", "false");
    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);
    RestTemplate httpClient = new RestTemplate();
    try {
        context.refresh();
        httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR));
        ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("admin.port") + "/schema/messages/protobuf"), String.class);
        logger.info("Got response: [{}]", response);
        Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value());
        Assert.assertTrue(response.getBody().contains("message error"));
    } finally {
        context.close();
    }
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) RestTemplate(org.springframework.web.client.RestTemplate) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) URI(java.net.URI) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 28 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project chassis by Kixeye.

the class WebSocketDocsTest method testProtobufMessagesEnvelope.

@Test
public void testProtobufMessagesEnvelope() 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", "false");
    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);
    RestTemplate httpClient = new RestTemplate();
    try {
        context.refresh();
        httpClient.setInterceptors(Lists.newArrayList(LOGGING_INTERCEPTOR));
        ResponseEntity<String> response = httpClient.getForEntity(new URI("http://localhost:" + properties.get("admin.port") + "/schema/envelope/protobuf"), String.class);
        logger.info("Got response: [{}]", response);
        Assert.assertEquals(response.getStatusCode().value(), HttpStatus.OK.value());
        Assert.assertTrue(response.getBody().contains("message Envelope"));
    } finally {
        context.close();
    }
}
Also used : HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) RestTemplate(org.springframework.web.client.RestTemplate) AnnotationConfigWebApplicationContext(org.springframework.web.context.support.AnnotationConfigWebApplicationContext) URI(java.net.URI) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 29 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class SpringApplication method convertToStandardEnvironment.

private ConfigurableEnvironment convertToStandardEnvironment(ConfigurableEnvironment environment) {
    StandardEnvironment result = new StandardEnvironment();
    removeAllPropertySources(result.getPropertySources());
    result.setActiveProfiles(environment.getActiveProfiles());
    for (PropertySource<?> propertySource : environment.getPropertySources()) {
        if (!SERVLET_ENVIRONMENT_SOURCE_NAMES.contains(propertySource.getName())) {
            result.getPropertySources().addLast(propertySource);
        }
    }
    return result;
}
Also used : StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Example 30 with StandardEnvironment

use of org.springframework.core.env.StandardEnvironment in project spring-boot by spring-projects.

the class ApplicationPidFileWriterTests method createEnvironment.

private ConfigurableEnvironment createEnvironment(String propName, String propValue) {
    MockPropertySource propertySource = mockPropertySource(propName, propValue);
    ConfigurableEnvironment environment = new StandardEnvironment();
    environment.getPropertySources().addLast(propertySource);
    return environment;
}
Also used : ConfigurableEnvironment(org.springframework.core.env.ConfigurableEnvironment) MockPropertySource(org.springframework.mock.env.MockPropertySource) StandardEnvironment(org.springframework.core.env.StandardEnvironment)

Aggregations

StandardEnvironment (org.springframework.core.env.StandardEnvironment)52 Test (org.junit.Test)41 MapPropertySource (org.springframework.core.env.MapPropertySource)27 URI (java.net.URI)23 HashMap (java.util.HashMap)23 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)18 ProtobufMessageSerDe (com.kixeye.chassis.transport.serde.converter.ProtobufMessageSerDe)15 RestTemplate (org.springframework.web.client.RestTemplate)15 ServiceError (com.kixeye.chassis.transport.dto.ServiceError)14 JsonJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.JsonJacksonMessageSerDe)14 XmlMessageSerDe (com.kixeye.chassis.transport.serde.converter.XmlMessageSerDe)14 YamlJacksonMessageSerDe (com.kixeye.chassis.transport.serde.converter.YamlJacksonMessageSerDe)14 SerDeHttpMessageConverter (com.kixeye.chassis.transport.http.SerDeHttpMessageConverter)13 HttpMessageConverter (org.springframework.http.converter.HttpMessageConverter)13 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9 Envelope (com.kixeye.chassis.transport.dto.Envelope)7 ArrayList (java.util.ArrayList)7