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