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);
}
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;
}
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);
}
Aggregations