Search in sources :

Example 11 with DefaultGrailsApplication

use of grails.core.DefaultGrailsApplication in project grails-core by grails.

the class DefaultGrailsPluginManagerTests method testLoadPlugins.

@Test
@SuppressWarnings("rawtypes")
public void testLoadPlugins() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    first = gcl.parseClass("class FirstGrailsPlugin {\n" + "def version = 1.0\n" + "}");
    second = gcl.parseClass("class SecondGrailsPlugin {\n" + "def version = 1.0\n" + "def dependsOn = [first:version]\n" + "}");
    third = gcl.parseClass("import grails.util.GrailsUtil\n" + "class ThirdGrailsPlugin {\n" + "def version = GrailsUtil.getGrailsVersion()\n" + "def dependsOn = [i18n:version]\n" + "}");
    fourth = gcl.parseClass("class FourthGrailsPlugin {\n" + "def version = 1.0\n" + "def dependsOn = [second:version, third:version]\n" + "}");
    GrailsApplication app = new DefaultGrailsApplication(new Class[] {}, gcl);
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.getDefaultListableBeanFactory().registerSingleton(GrailsApplication.APPLICATION_ID, app);
    DefaultGrailsPluginManager manager = new DefaultGrailsPluginManager(new Class[] { first, second, third, fourth }, app);
    manager.setParentApplicationContext(parent);
    manager.setPluginFilter(new IncludingPluginFilter("dataSource", "first", "third"));
    manager.loadPlugins();
    List pluginList = manager.getPluginList();
    assertNotNull(manager.getGrailsPlugin("dataSource"));
    assertNotNull(manager.getGrailsPlugin("first"));
    assertNotNull(manager.getGrailsPlugin("third"));
    // dataSource depends on core
    assertNotNull(manager.getGrailsPlugin("core"));
    // third depends on i18n
    assertNotNull(manager.getGrailsPlugin("third"));
    assertEquals(5, pluginList.size(), "Expected plugins not loaded. Expected " + 5 + " but got " + pluginList);
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IncludingPluginFilter(org.grails.plugins.IncludingPluginFilter) GrailsApplication(grails.core.GrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) List(java.util.List) ArrayList(java.util.ArrayList) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) Test(org.junit.jupiter.api.Test)

Example 12 with DefaultGrailsApplication

use of grails.core.DefaultGrailsApplication in project grails-core by grails.

the class DefaultGrailsPluginManagerTests method loadPlugins.

DefaultGrailsPluginManager loadPlugins(String firstClassString, String secondClassString, String thirdClassString, String fourthClassString) {
    GroovyClassLoader gcl = new GroovyClassLoader();
    first = gcl.parseClass(firstClassString);
    second = gcl.parseClass(secondClassString);
    third = gcl.parseClass(thirdClassString);
    fourth = gcl.parseClass(fourthClassString);
    GrailsApplication app = new DefaultGrailsApplication(new Class[] {}, gcl);
    GenericApplicationContext parent = new GenericApplicationContext();
    parent.getDefaultListableBeanFactory().registerSingleton(GrailsApplication.APPLICATION_ID, app);
    DefaultGrailsPluginManager manager = new DefaultGrailsPluginManager(new Class[] { first, second, third, fourth }, app);
    manager.setParentApplicationContext(parent);
    manager.setPluginFilter(new IncludingPluginFilter("first", "second", "third", "fourth"));
    manager.loadPlugins();
    return manager;
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IncludingPluginFilter(org.grails.plugins.IncludingPluginFilter) GrailsApplication(grails.core.GrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication)

Example 13 with DefaultGrailsApplication

use of grails.core.DefaultGrailsApplication in project grails-core by grails.

the class GrailsApplicationAttributesTests method getAttributesForClasses.

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);
}
Also used : GrailsClass(grails.core.GrailsClass) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) GrailsApplication(grails.core.GrailsApplication) DefaultGrailsApplication(grails.core.DefaultGrailsApplication) MockServletContext(org.springframework.mock.web.MockServletContext) MockApplicationContext(org.grails.support.MockApplicationContext)

Aggregations

DefaultGrailsApplication (grails.core.DefaultGrailsApplication)13 GrailsApplication (grails.core.GrailsApplication)9 GroovyClassLoader (groovy.lang.GroovyClassLoader)8 GrailsDomainClass (grails.core.GrailsDomainClass)5 Map (java.util.Map)5 MockApplicationContext (org.grails.support.MockApplicationContext)4 ArrayList (java.util.ArrayList)3 IncludingPluginFilter (org.grails.plugins.IncludingPluginFilter)3 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)3 Collection (java.util.Collection)2 List (java.util.List)2 Test (org.junit.jupiter.api.Test)2 GrailsApplicationClass (grails.core.GrailsApplicationClass)1 GrailsClass (grails.core.GrailsClass)1 grails.gorm.validation (grails.gorm.validation)1 Constrained (grails.gorm.validation.Constrained)1 GroovyObject (groovy.lang.GroovyObject)1 ConfigObject (groovy.util.ConfigObject)1 ConfigSlurper (groovy.util.ConfigSlurper)1 File (java.io.File)1