Package org.grails.support

Examples of org.grails.support.MockApplicationContext$MockResource


    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);
        ga.getMetadata().getConfigMap().put(Metadata.APPLICATION_NAME, getClass().getName());
View Full Code Here


    protected MockServletContext createMockServletContext() {
        return new MockServletContext();
    }

    protected MockApplicationContext createMockApplicationContext() {
        return new MockApplicationContext();
    }
View Full Code Here

        assertEquals(trimAndRemoveCR(expected), trimAndRemoveCR(output.generatedGsp));
        assertEquals(src, output.htmlParts[0]);
    }

    private GrailsWebRequest buildMockRequest(ConfigObject config) throws Exception {
        MockApplicationContext appCtx = new MockApplicationContext();
        appCtx.registerMockBean(GroovyPagesUriService.BEAN_ID, new DefaultGroovyPagesUriService());

        DefaultGrailsApplication grailsApplication = new DefaultGrailsApplication();
        grailsApplication.setConfig(config);
        Holders.setConfig(new PropertySourcesConfig().merge(config));
        appCtx.registerMockBean(GrailsApplication.APPLICATION_ID, grailsApplication);
        appCtx.getServletContext().setAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT, appCtx);
        appCtx.getServletContext().setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, appCtx);
        return GrailsWebMockUtil.bindMockWebRequest(appCtx);
    }
View Full Code Here

import com.opensymphony.module.sitemesh.parser.HTMLPageParser;

public class GrailsLayoutDecoratorMapperTests extends TestCase {

    private GrailsWebRequest buildMockRequest(grails.config.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.setServletContext(appCtx.getServletContext());
        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());
View Full Code Here

     * Test method for 'GrailsLayoutDecoratorMapper.getDecorator(HttpServletRequest, Page)'
     */
    public void testGetDecoratorHttpServletRequestPage() throws Exception {
        GrailsWebRequest webRequest = buildMockRequest(null);
        webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
        MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
        appCtx.registerMockResource("/grails-app/views/layouts/test.gsp", "<html><body><g:layoutBody /></body></html>");

        MockHttpServletRequest request = (MockHttpServletRequest)webRequest.getCurrentRequest();
        request.setMethod("GET");
        request.setRequestURI("orders/list");
        ServletContext context = webRequest.getServletContext();
View Full Code Here

    }

    public void testDecoratedByApplicationConventionForViewsNotRenderedByAController() throws Exception {
        GrailsWebRequest webRequest = buildMockRequest(null);
        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>");

        MockHttpServletRequest request = (MockHttpServletRequest)webRequest.getCurrentRequest();
        request.setMethod("GET");
        request.setRequestURI("/");
View Full Code Here

    }

    public void testDecoratedByApplicationConvention() throws Exception {
        GrailsWebRequest webRequest = buildMockRequest(null);
        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>");

        MockHttpServletRequest request = (MockHttpServletRequest)webRequest.getCurrentRequest();
        request.setMethod("GET");
        request.setRequestURI("orders/list");
        ServletContext context = webRequest.getServletContext();
View Full Code Here

            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();
View Full Code Here

    }

    public void testDecoratedByControllerConvention() throws Exception {
        GrailsWebRequest webRequest = buildMockRequest(null);
        webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
        MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
        appCtx.registerMockResource("/grails-app/views/layouts/test.gsp", "<html><body><g:layoutBody /></body></html>");

        MockHttpServletRequest request = (MockHttpServletRequest)webRequest.getCurrentRequest();
        request.setMethod("GET");
        request.setRequestURI("orders/list");
        ServletContext context = webRequest.getServletContext();
View Full Code Here

    }

    public void testDecoratedByActionConvention() throws Exception {
        GrailsWebRequest webRequest = buildMockRequest(null);
        webRequest.setAttribute(GrailsLayoutDecoratorMapper.RENDERING_VIEW, Boolean.TRUE, RequestAttributes.SCOPE_REQUEST);
        MockApplicationContext appCtx = (MockApplicationContext)webRequest.getApplicationContext();
        appCtx.registerMockResource("/grails-app/views/layouts/test2/testAction.gsp", "<html><body><g:layoutBody /></body></html>");

        MockHttpServletRequest request = (MockHttpServletRequest)webRequest.getCurrentRequest();
        request.setMethod("GET");
        request.setRequestURI("orders/list");
        ServletContext context = webRequest.getServletContext();
View Full Code Here

TOP

Related Classes of org.grails.support.MockApplicationContext$MockResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.