Package grails.core

Examples of grails.core.DefaultGrailsApplication


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

        ga.setApplicationContext(ctx);
        ga.initialise();
        ctx.registerMockBean(GrailsApplication.APPLICATION_ID, ga);
View Full Code Here


    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

        super(application);
        loadPlugins();
    }

    public MockGrailsPluginManager() {
        this(new DefaultGrailsApplication(new Class[0], new GroovyClassLoader()));
    }
View Full Code Here

        gcl.parseClass("class Super { Long id;Long version;}\n" +
                       "class Sub extends Super { }\n" +
                       "class Sub2 extends Sub { }");

        GrailsApplication ga = new DefaultGrailsApplication(gcl.getLoadedClasses(),gcl);
        ga.initialise();

        GrailsDomainClass gdc1 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Super");
        assertNotNull(gdc1);
        assertTrue(gdc1.isRoot());
        assertEquals(2,gdc1.getSubClasses().size());
        assertFalse(gdc1.getPropertyByName("id").isInherited());

        GrailsDomainClass gdc2 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Sub");

        assertFalse(gdc2.isRoot());
        assertEquals(1,gdc2.getSubClasses().size());
        assertTrue(gdc2.getPropertyByName("id").isInherited());

        GrailsDomainClass gdc3 = (GrailsDomainClass) ga.getArtefact(DomainClassArtefactHandler.TYPE, "Sub2");

        assertFalse(gdc3.isRoot());
        assertEquals(0,gdc3.getSubClasses().size());
        assertTrue(gdc3.getPropertyByName("id").isInherited());
    }
View Full Code Here

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

    private List getPluginList() {

        GroovyClassLoader gcl = new GroovyClassLoader();

        GrailsApplication app = new DefaultGrailsApplication(new Class[0], gcl);
        MockApplicationContext parent = new MockApplicationContext();
        parent.registerMockBean(GrailsApplication.APPLICATION_ID, app);

        GrailsRuntimeConfigurator conf = new GrailsRuntimeConfigurator(app,
                parent);
View Full Code Here

    private GrailsApplicationAttributes getAttributesForClasses(Class<?>[] classes, GroovyClassLoader gcl) {
        MockApplicationContext context = new MockApplicationContext();
        MockServletContext servletContext = new MockServletContext();
        servletContext.setAttribute(GrailsApplicationAttributes.APPLICATION_CONTEXT,context);

        GrailsApplication app = new DefaultGrailsApplication(classes,gcl);
        app.initialise();
        context.registerMockBean(GrailsApplication.APPLICATION_ID,app);

        GrailsClass[] controllers = app.getArtefacts(ControllerArtefactHandler.TYPE);
        for (int i = 0; i < controllers.length; i++) {
            context.registerMockBean(controllers[i].getFullName(), controllers[i].newInstance());
        }

        GrailsClass[] taglibs = app.getArtefacts(TagLibArtefactHandler.TYPE);
        for (int i = 0; i < taglibs.length; i++) {
            context.registerMockBean(taglibs[i].getFullName(), taglibs[i].newInstance());
        }
        return new DefaultGrailsApplicationAttributes(servletContext);
    }
View Full Code Here

        GroovyClassLoader gcl = new GroovyClassLoader();
        Class<?> dc = gcl.parseClass("class Test { Long id; Long version; }");

        Class<?> c = gcl.parseClass("class TestController { def list = {} }");

        GrailsApplication app = new DefaultGrailsApplication(new Class[]{dc,c}, gcl);

        MockApplicationContext parent = new MockApplicationContext();
        parent.registerMockBean(GrailsApplication.APPLICATION_ID, app);
        parent.registerMockBean("classLoader", gcl);

        app.setApplicationContext(parent);

        GrailsRuntimeConfigurator conf = new GrailsRuntimeConfigurator(app,parent);
        DefaultGrailsPluginManager manager = new DefaultGrailsPluginManager(new Class[0], app);
        manager.setParentApplicationContext(parent);
        parent.registerMockBean("manager",manager);
View Full Code Here

        GroovyClassLoader gcl = new GroovyClassLoader();
        Class<?> dc = gcl.parseClass("class Test { Long id; Long version; }");

        Class<?> c = gcl.parseClass("class TestController { def scaffold = Test }");

        GrailsApplication app = new DefaultGrailsApplication(new Class[]{dc,c}, gcl);
        app.getMetadata().getConfigMap().put(Metadata.APPLICATION_NAME, getClass().getName());
        MockApplicationContext parent = new MockApplicationContext();
        parent.registerMockBean(GrailsApplication.APPLICATION_ID, app);

        GrailsRuntimeConfigurator conf = new GrailsRuntimeConfigurator(app,parent);
        ApplicationContext ctx = conf.configure(new MockServletContext());
View Full Code Here

    public void testRegisterAdditionalBean() {
        GroovyClassLoader gcl = new GroovyClassLoader();
        Class<?> dc = gcl.parseClass("class Test { Long id; Long version; }");

        GrailsApplication app = new DefaultGrailsApplication(new Class[0], gcl);
        MockApplicationContext parent = new MockApplicationContext();
        parent.registerMockBean(GrailsApplication.APPLICATION_ID, app);

        GrailsRuntimeConfigurator conf = new GrailsRuntimeConfigurator(app,parent);
        GrailsApplicationContext ctx = (GrailsApplicationContext)conf.configure(new MockServletContext());
View Full Code Here

TOP

Related Classes of grails.core.DefaultGrailsApplication

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.