Search in sources :

Example 46 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project grails-core by grails.

the class GroovyPagesUriSupportTests method testGetViewURIForController.

@Test
public void testGetViewURIForController() throws IllegalAccessException, InstantiationException {
    GroovyObject controller = (GroovyObject) new GroovyClassLoader().parseClass("class FooController { }").newInstance();
    GroovyPagesUriSupport uriSupport = new GroovyPagesUriSupport();
    assertEquals("/foo/bar.gsp", uriSupport.getViewURI(controller, "bar"));
    assertEquals("/bar.gsp", uriSupport.getViewURI(controller, "../bar"));
    assertEquals("/bar/foo.gsp", uriSupport.getViewURI(controller, "/bar/foo"));
    assertEquals("/foo/bar/foo.gsp", uriSupport.getViewURI(controller, "bar/foo"));
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) GroovyObject(groovy.lang.GroovyObject) Test(org.junit.jupiter.api.Test)

Example 47 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project grails-core by grails.

the class DefaultGrailsPluginManagerTests method testDependenciesWithDelayedLoadingWithVersionRangeStrings.

/**
 * Test the known 1.0.2 failure where:
 *
 * mail 0.3 = has no deps
 * quartz 0.3-SNAPSHOT: loadAfter = ['core', 'hibernate']
 * emailconfirmation 0.4: dependsOn = [quartz:'0.3 > *', mail: '0.2 > *']
 *
 * ...and emailconfirmation is NOT loaded first.
 */
@Test
@SuppressWarnings("rawtypes")
public void testDependenciesWithDelayedLoadingWithVersionRangeStrings() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    // These are defined in a specific order so that the one with the range dependencies
    // is the first in the list, and its dependencies load after
    first = gcl.parseClass("class FirstGrailsPlugin {\n" + "def version = \"0.4\"\n" + "def dependsOn = [second:'0.3 > *', third:'0.2 > *']\n" + "}");
    second = gcl.parseClass("class SecondGrailsPlugin {\n" + "def version = \"0.3\"\n" + "def dependsOn = [:]\n" + "}");
    third = gcl.parseClass("class ThirdGrailsPlugin {\n" + "def version = \"0.3-SNAPSHOT\"\n" + "def loadAfter = ['core', 'hibernate']\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 }, app);
    manager.setParentApplicationContext(parent);
    manager.setPluginFilter(new IncludingPluginFilter("dataSource", "first", "second", "third"));
    manager.loadPlugins();
    List pluginList = manager.getPluginList();
    assertNotNull(manager.getGrailsPlugin("first"));
    assertNotNull(manager.getGrailsPlugin("second"));
    // 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 48 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project grails-core by grails.

the class GrailsClassTests method testAbstractGrailsClassNoPackage.

@Test
public void testAbstractGrailsClassNoPackage() throws Exception {
    GroovyClassLoader cl = new GroovyClassLoader();
    Class<?> clazz = cl.parseClass("class TestService { }");
    GrailsClass grailsClass = new AbstractGrailsClass(clazz, "Service") {
    };
    assertEquals("TestService", clazz.getName());
    assertEquals("Test", grailsClass.getName());
    assertEquals("TestService", grailsClass.getFullName());
    assertNotNull(grailsClass.newInstance());
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) AbstractGrailsClass(org.grails.core.AbstractGrailsClass) GrailsClass(grails.core.GrailsClass) AbstractGrailsClass(org.grails.core.AbstractGrailsClass) Test(org.junit.jupiter.api.Test)

Example 49 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project grails-core by grails.

the class GrailsClassTests method testAbstractGrailsClassPackage.

@Test
public void testAbstractGrailsClassPackage() throws Exception {
    GroovyClassLoader cl = new GroovyClassLoader();
    Class<?> clazz = cl.parseClass("package test.casey; class TestService { }");
    GrailsClass grailsClass = new AbstractGrailsClass(clazz, "Service") {
    };
    assertEquals("test.casey.TestService", clazz.getName());
    assertEquals("Test", grailsClass.getName());
    assertEquals("test.casey.TestService", grailsClass.getFullName());
    assertNotNull(grailsClass.newInstance());
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) AbstractGrailsClass(org.grails.core.AbstractGrailsClass) GrailsClass(grails.core.GrailsClass) AbstractGrailsClass(org.grails.core.AbstractGrailsClass) Test(org.junit.jupiter.api.Test)

Example 50 with GroovyClassLoader

use of groovy.lang.GroovyClassLoader in project grails-core by grails.

the class CodecArtefactHandlerTests method testDomainClassWithNameEndingInCodecIsNotACodec.

@Test
public void testDomainClassWithNameEndingInCodecIsNotACodec() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> c = gcl.parseClass("@grails.persistence.Entity\nclass MySpecialCodec { Long id;Long version;}\n");
    ArtefactHandler domainClassHandler = new DomainClassArtefactHandler();
    assertTrue(domainClassHandler.isArtefact(c));
    ArtefactHandler codecHandler = new CodecArtefactHandler();
    assertFalse(codecHandler.isArtefact(c));
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) ArtefactHandler(grails.core.ArtefactHandler) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) Test(org.junit.jupiter.api.Test)

Aggregations

GroovyClassLoader (groovy.lang.GroovyClassLoader)126 File (java.io.File)26 GroovyObject (groovy.lang.GroovyObject)17 Test (org.junit.jupiter.api.Test)17 CompilerConfiguration (org.codehaus.groovy.control.CompilerConfiguration)13 IOException (java.io.IOException)11 Binding (groovy.lang.Binding)10 URL (java.net.URL)10 HashMap (java.util.HashMap)10 CompilationFailedException (org.codehaus.groovy.control.CompilationFailedException)10 Map (java.util.Map)9 DefaultGrailsApplication (grails.core.DefaultGrailsApplication)8 GrailsApplication (grails.core.GrailsApplication)8 BuildException (org.apache.tools.ant.BuildException)8 ArtefactHandler (grails.core.ArtefactHandler)7 GroovyShell (groovy.lang.GroovyShell)7 CompilationUnit (org.codehaus.groovy.control.CompilationUnit)7 SimpleMessage (org.codehaus.groovy.control.messages.SimpleMessage)7 Script (groovy.lang.Script)6 Decorator (com.opensymphony.module.sitemesh.Decorator)5