Search in sources :

Example 16 with MapPropertySource

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

the class AbstractEndpointTests method isExplicitlyEnabled.

@Test
@SuppressWarnings("rawtypes")
public void isExplicitlyEnabled() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    PropertySource<?> propertySource = new MapPropertySource("test", Collections.<String, Object>singletonMap(this.property + ".enabled", false));
    this.context.getEnvironment().getPropertySources().addFirst(propertySource);
    this.context.register(this.configClass);
    this.context.refresh();
    ((AbstractEndpoint) getEndpointBean()).setEnabled(true);
    assertThat(getEndpointBean().isEnabled()).isTrue();
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Example 17 with MapPropertySource

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

the class AbstractEndpointTests method isSensitiveOverrideWithGlobal.

@Test
public void isSensitiveOverrideWithGlobal() throws Exception {
    this.context = new AnnotationConfigApplicationContext();
    Map<String, Object> properties = new HashMap<>();
    properties.put("endpoint.sensitive", this.sensitive);
    properties.put(this.property + ".sensitive", String.valueOf(!this.sensitive));
    PropertySource<?> propertySource = new MapPropertySource("test", properties);
    this.context.getEnvironment().getPropertySources().addFirst(propertySource);
    this.context.register(this.configClass);
    this.context.refresh();
    assertThat(getEndpointBean().isSensitive()).isEqualTo(!this.sensitive);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Example 18 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project spring-framework by spring-projects.

the class EvalTagTests method environmentAccess.

@Test
public void environmentAccess() throws Exception {
    Map<String, Object> map = new HashMap<>();
    map.put("key.foo", "value.foo");
    GenericApplicationContext wac = (GenericApplicationContext) context.getRequest().getAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE);
    wac.getEnvironment().getPropertySources().addFirst(new MapPropertySource("mapSource", map));
    wac.getDefaultListableBeanFactory().registerSingleton("bean2", context.getRequest().getAttribute("bean"));
    tag.setExpression("@environment['key.foo']");
    int action = tag.doStartTag();
    assertEquals(Tag.EVAL_BODY_INCLUDE, action);
    action = tag.doEndTag();
    assertEquals(Tag.EVAL_PAGE, action);
    assertEquals("value.foo", ((MockHttpServletResponse) context.getResponse()).getContentAsString());
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) HashMap(java.util.HashMap) MapPropertySource(org.springframework.core.env.MapPropertySource) Test(org.junit.Test)

Example 19 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project grails-core by grails.

the class GrailsLayoutDecoratorMapperTests method testOverridingDefaultTemplateViaConfig.

public void testOverridingDefaultTemplateViaConfig() throws Exception {
    ConfigObject config = new ConfigSlurper().parse("grails.sitemesh.default.layout='otherApplication'");
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addLast(new MapPropertySource("grails", config));
    GrailsWebRequest webRequest = buildMockRequest(new PropertySourcesConfig(propertySources));
    webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
    MockApplicationContext appCtx = (MockApplicationContext) webRequest.getApplicationContext();
    appCtx.registerMockResource("/grails-app/views/layouts/application.gsp", "<html><body><h1>Default Layout</h1><g:layoutBody /></body></html>");
    appCtx.registerMockResource("/grails-app/views/layouts/otherApplication.gsp", "<html><body><h1>Other Default Layout</h1><g:layoutBody /></body></html>");
    MockHttpServletRequest request = (MockHttpServletRequest) webRequest.getCurrentRequest();
    request.setMethod("GET");
    request.setRequestURI("orders/list");
    ServletContext context = webRequest.getServletContext();
    GroovyClassLoader gcl = new GroovyClassLoader();
    // create mock controller
    GroovyObject controller = (GroovyObject) gcl.parseClass("class FooController {\n" + "def controllerName = 'foo'\n" + "def actionUri = '/foo/fooAction'\n" + "}").newInstance();
    request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controller);
    GrailsLayoutDecoratorMapper m = new GrailsLayoutDecoratorMapper();
    com.opensymphony.module.sitemesh.Config c = new com.opensymphony.module.sitemesh.Config(new MockServletConfig(context));
    m.init(c, null, null);
    HTMLPageParser parser = new HTMLPageParser();
    String html = "<html><head><title>Foo title</title></head><body>here is the body</body></html>";
    Page page = parser.parse(html.toCharArray());
    Decorator d = m.getDecorator(request, page);
    assertNotNull(d);
    assertEquals("/layouts/otherApplication.gsp", d.getPage());
    assertEquals("otherApplication", d.getName());
}
Also used : PropertySourcesConfig(org.grails.config.PropertySourcesConfig) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) Config(grails.config.Config) MockServletConfig(org.springframework.mock.web.MockServletConfig) PropertySourcesConfig(org.grails.config.PropertySourcesConfig) MockServletConfig(org.springframework.mock.web.MockServletConfig) Page(com.opensymphony.module.sitemesh.Page) HTMLPageParser(com.opensymphony.module.sitemesh.parser.HTMLPageParser) MockApplicationContext(org.grails.support.MockApplicationContext) GroovyObject(groovy.lang.GroovyObject) GroovyClassLoader(groovy.lang.GroovyClassLoader) Decorator(com.opensymphony.module.sitemesh.Decorator) MapPropertySource(org.springframework.core.env.MapPropertySource) ServletContext(javax.servlet.ServletContext) MutablePropertySources(org.springframework.core.env.MutablePropertySources) GrailsWebRequest(org.grails.web.servlet.mvc.GrailsWebRequest) ConfigObject(groovy.util.ConfigObject) ConfigSlurper(groovy.util.ConfigSlurper)

Example 20 with MapPropertySource

use of org.springframework.core.env.MapPropertySource in project libresonic by Libresonic.

the class LoggingFileOverrideListener method onApplicationEvent.

@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
    PropertySource ps = new MapPropertySource("LogFileLocationPS", Collections.singletonMap(LogFile.FILE_PROPERTY, getLogFile().getAbsolutePath()));
    event.getEnvironment().getPropertySources().addLast(ps);
}
Also used : MapPropertySource(org.springframework.core.env.MapPropertySource) PropertySource(org.springframework.core.env.PropertySource) MapPropertySource(org.springframework.core.env.MapPropertySource)

Aggregations

MapPropertySource (org.springframework.core.env.MapPropertySource)72 Test (org.junit.Test)52 HashMap (java.util.HashMap)35 StandardEnvironment (org.springframework.core.env.StandardEnvironment)26 URI (java.net.URI)24 AnnotationConfigWebApplicationContext (org.springframework.web.context.support.AnnotationConfigWebApplicationContext)23 MessageSerDe (com.kixeye.chassis.transport.serde.MessageSerDe)21 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 MutablePropertySources (org.springframework.core.env.MutablePropertySources)10 QueuingWebSocketListener (com.kixeye.chassis.transport.websocket.QueuingWebSocketListener)9 WebSocketMessageRegistry (com.kixeye.chassis.transport.websocket.WebSocketMessageRegistry)9 ArrayList (java.util.ArrayList)9 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)9