use of groovy.util.ConfigObject 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 groovy.util.ConfigObject in project grails-core by grails.
the class ParseTests method testParseWithUTF8.
public void testParseWithUTF8() throws Exception {
// This is some unicode Chinese (who knows what it says!)
String src = "Chinese text: 㐡㐷㐿㑃㐐㐅㢳㢚㥞㥇㫛㭚㭧";
// Sanity check the string loaded OK as unicode - it won't look right if you output it, default stdout is not UTF-8
// on many OSes
assertEquals(src.indexOf('?'), -1);
ConfigObject config = new ConfigSlurper().parse("grails.views.gsp.encoding = \"UTF-8\"");
buildMockRequest(config);
ParsedResult output = null;
try {
output = parseCode("myTest4", src);
} finally {
RequestContextHolder.resetRequestAttributes();
}
String expected = makeImports() + "\n" + "class myTest4 extends org.grails.gsp.GroovyPage {\n" + "public String getGroovyPageFileName() { \"myTest4\" }\n" + "public Object run() {\n" + "Writer out = getOut()\n" + "Writer expressionOut = getExpressionOut()\n" + "registerSitemeshPreprocessMode()\n" + "printHtmlPart(0)\n" + "}\n" + GSP_FOOTER;
assertEquals(trimAndRemoveCR(expected), trimAndRemoveCR(output.generatedGsp));
assertEquals(src, output.htmlParts[0]);
}
use of groovy.util.ConfigObject in project wildfly-swarm by wildfly-swarm.
the class SwarmExtension method properties.
public void properties(Closure<Properties> closure) {
ConfigObject config = new ConfigObject();
closure.setResolveStrategy(Closure.DELEGATE_ONLY);
closure.setDelegate(config);
closure.call();
config.flatten(this.properties);
}
use of groovy.util.ConfigObject in project grails-core by grails.
the class PropertySourcesConfig method mergeEnumerablePropertySource.
private void mergeEnumerablePropertySource(EnumerablePropertySource enumerablePropertySource) {
if (enumerablePropertySource instanceof NavigableMapPropertySource) {
configMap.merge(((NavigableMapPropertySource) enumerablePropertySource).getSource(), false);
} else {
Map<String, Object> map = new LinkedHashMap<String, Object>();
final String[] propertyNames = enumerablePropertySource.getPropertyNames();
for (String propertyName : propertyNames) {
Object value = enumerablePropertySource.getProperty(propertyName);
if (value instanceof ConfigObject) {
if (((ConfigObject) value).isEmpty())
continue;
} else {
value = processAndEvaluate(value);
}
map.put(propertyName, value);
}
configMap.merge(map, true);
}
}
use of groovy.util.ConfigObject in project grails-core by grails.
the class AbstractGrailsMockTests method setUp.
@Override
protected final void setUp() throws Exception {
ExpandoMetaClass.enableGlobally();
super.setUp();
System.out.println("Setting up test");
ctx = new MockApplicationContext();
ctx.registerMockBean(GrailsApplication.CLASS_LOADER_BEAN, gcl);
onSetUp();
ga = new DefaultGrailsApplication(gcl.getLoadedClasses(), gcl);
if (ClassUtils.isPresent("Config", gcl)) {
ConfigObject config = new ConfigSlurper().parse(gcl.loadClass("Config"));
ga.setConfig(new PropertySourcesConfig(config));
}
ga.setApplicationContext(ctx);
ga.initialise();
ctx.registerMockBean(GrailsApplication.APPLICATION_ID, ga);
postSetUp();
}
Aggregations