Search in sources :

Example 1 with DefaultCodecLookup

use of org.grails.plugins.codecs.DefaultCodecLookup in project grails-core by grails.

the class GrailsLayoutDecoratorMapperTests method buildMockRequest.

private GrailsWebRequest buildMockRequest(Config config) throws Exception {
    MockApplicationContext appCtx = new MockApplicationContext();
    appCtx.registerMockBean(GroovyPagesUriService.BEAN_ID, new DefaultGroovyPagesUriService());
    DefaultGrailsApplication grailsApplication = new DefaultGrailsApplication();
    grailsApplication.setConfig(config);
    Holders.setConfig(config);
    appCtx.registerMockBean(GrailsApplication.APPLICATION_ID, grailsApplication);
    GrailsConventionGroovyPageLocator pageLocator = new GrailsConventionGroovyPageLocator();
    pageLocator.setApplicationContext(appCtx);
    GroovyPagesTemplateEngine gpte = new GroovyPagesTemplateEngine();
    gpte.setResourceLoader(appCtx);
    gpte.setApplicationContext(appCtx);
    gpte.afterPropertiesSet();
    GroovyPageViewResolver grailsViewResolver = new GroovyPageViewResolver();
    grailsViewResolver.setApplicationContext(appCtx);
    grailsViewResolver.setGroovyPageLocator(pageLocator);
    grailsViewResolver.setTemplateEngine(gpte);
    GroovyPageLayoutFinder layoutFinder = new GroovyPageLayoutFinder();
    layoutFinder.setViewResolver(grailsViewResolver);
    @SuppressWarnings("rawtypes") Map flat = config != null ? config.flatten() : Collections.emptyMap();
    layoutFinder.setDefaultDecoratorName(flat.get("grails.sitemesh.default.layout") != null ? flat.get("grails.sitemesh.default.layout").toString() : "application");
    appCtx.registerMockBean("groovyPageLocator", pageLocator);
    appCtx.registerMockBean("groovyPageLayoutFinder", layoutFinder);
    DefaultCodecLookup codecLookup = new DefaultCodecLookup();
    codecLookup.setGrailsApplication(grailsApplication);
    codecLookup.afterPropertiesSet();
    appCtx.registerMockBean("codecLookup", codecLookup);
    appCtx.getServletContext().setAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT, appCtx);
    appCtx.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx);
    grailsApplication.setMainContext(appCtx);
    return GrailsWebMockUtil.bindMockWebRequest(appCtx, new MockHttpServletRequest(appCtx.getServletContext()) {

        @Override
        public RequestDispatcher getRequestDispatcher(String path) {
            return null;
        }
    }, new MockHttpServletResponse());
}
Also used : GrailsConventionGroovyPageLocator(org.grails.web.gsp.io.GrailsConventionGroovyPageLocator) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) DefaultGroovyPagesUriService(org.grails.web.pages.DefaultGroovyPagesUriService) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) GroovyPagesTemplateEngine(org.grails.gsp.GroovyPagesTemplateEngine) RequestDispatcher(javax.servlet.RequestDispatcher) MockApplicationContext(org.grails.support.MockApplicationContext) DefaultCodecLookup(org.grails.plugins.codecs.DefaultCodecLookup) GroovyPageViewResolver(org.grails.web.servlet.view.GroovyPageViewResolver) Map(java.util.Map) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Aggregations

DefaultGrailsApplication (grails.core.DefaultGrailsApplication)1 Map (java.util.Map)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 GroovyPagesTemplateEngine (org.grails.gsp.GroovyPagesTemplateEngine)1 DefaultCodecLookup (org.grails.plugins.codecs.DefaultCodecLookup)1 MockApplicationContext (org.grails.support.MockApplicationContext)1 GrailsConventionGroovyPageLocator (org.grails.web.gsp.io.GrailsConventionGroovyPageLocator)1 DefaultGroovyPagesUriService (org.grails.web.pages.DefaultGroovyPagesUriService)1 GroovyPageViewResolver (org.grails.web.servlet.view.GroovyPageViewResolver)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1