Search in sources :

Example 1 with ConfigObject

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());
}
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 2 with ConfigObject

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]);
}
Also used : ConfigObject(groovy.util.ConfigObject) ConfigSlurper(groovy.util.ConfigSlurper)

Example 3 with ConfigObject

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);
}
Also used : ConfigObject(groovy.util.ConfigObject)

Example 4 with ConfigObject

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);
    }
}
Also used : ConfigObject(groovy.util.ConfigObject) ConfigObject(groovy.util.ConfigObject) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with ConfigObject

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();
}
Also used : PropertySourcesConfig(org.grails.config.PropertySourcesConfig) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) ConfigObject(groovy.util.ConfigObject) MockApplicationContext(org.grails.support.MockApplicationContext) ConfigSlurper(groovy.util.ConfigSlurper)

Aggregations

ConfigObject (groovy.util.ConfigObject)6 ConfigSlurper (groovy.util.ConfigSlurper)4 PropertySourcesConfig (org.grails.config.PropertySourcesConfig)2 MockApplicationContext (org.grails.support.MockApplicationContext)2 Decorator (com.opensymphony.module.sitemesh.Decorator)1 Page (com.opensymphony.module.sitemesh.Page)1 HTMLPageParser (com.opensymphony.module.sitemesh.parser.HTMLPageParser)1 Enhanced (grails.artefact.Enhanced)1 Config (grails.config.Config)1 DefaultGrailsApplication (grails.core.DefaultGrailsApplication)1 GrailsPlugin (grails.plugins.GrailsPlugin)1 PluginException (grails.plugins.exceptions.PluginException)1 ExpandoMetaClass (groovy.lang.ExpandoMetaClass)1 GroovyClassLoader (groovy.lang.GroovyClassLoader)1 GroovyObject (groovy.lang.GroovyObject)1 MetaClassRegistry (groovy.lang.MetaClassRegistry)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1