Search in sources :

Example 51 with GroovyClassLoader

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

the class CodecArtefactHandlerTests method testIsCodecClass.

@Test
public void testIsCodecClass() {
    ArtefactHandler handler = new CodecArtefactHandler();
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> fullCodecClass = gcl.parseClass("class FullCodec {\n" + "static def encode = { str -> }\n" + "static def decode = { str -> }\n" + "}\n");
    assertTrue(handler.isArtefact(fullCodecClass), "class was an encoder/decoder");
    Class<?> decodeOnlyCodecClass = gcl.parseClass("class DecodeOnlyCodec {\n" + "static def decode = { str -> }\n" + "}\n");
    assertTrue(handler.isArtefact(decodeOnlyCodecClass), "class was a decoder");
    Class<?> encodeOnlyCodecClass = gcl.parseClass("class EncodeOnlyCodec {\n" + "static def encode = { str -> }\n" + "}\n");
    assertTrue(handler.isArtefact(encodeOnlyCodecClass), "class was an encoder");
    Class<?> nonCodecClass = gcl.parseClass("class SomeFoo {\n" + "static def encode = { str -> }\n" + "}\n");
    assertFalse(handler.isArtefact(nonCodecClass), "class was not a codec");
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) DomainClassArtefactHandler(org.grails.core.artefact.DomainClassArtefactHandler) ArtefactHandler(grails.core.ArtefactHandler) Test(org.junit.jupiter.api.Test)

Example 52 with GroovyClassLoader

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

the class DomainClassArtefactHandlerTests method testIsDomainClass.

@Test
public void testIsDomainClass() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> c = gcl.parseClass("@grails.persistence.Entity\nclass Test { Long id;Long version;}\n");
    ArtefactHandler handler = new DomainClassArtefactHandler();
    assertTrue(handler.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)

Example 53 with GroovyClassLoader

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

the class TagLibArtefactHandlerTests method testIsTagLibClass.

@Test
public void testIsTagLibClass() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> c = gcl.parseClass("class TestTagLib { }\n");
    ArtefactHandler handler = new TagLibArtefactHandler();
    assertTrue(handler.isArtefact(c));
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) TagLibArtefactHandler(org.grails.core.artefact.TagLibArtefactHandler) TagLibArtefactHandler(org.grails.core.artefact.TagLibArtefactHandler) ArtefactHandler(grails.core.ArtefactHandler) Test(org.junit.jupiter.api.Test)

Example 54 with GroovyClassLoader

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

the class ServiceArtefactHandlerTests method testIsServiceClass.

@Test
public void testIsServiceClass() {
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> c = gcl.parseClass("class TestService { }\n");
    ArtefactHandler handler = new ServiceArtefactHandler();
    assertTrue(handler.isArtefact(c));
}
Also used : GroovyClassLoader(groovy.lang.GroovyClassLoader) ServiceArtefactHandler(org.grails.core.artefact.ServiceArtefactHandler) ArtefactHandler(grails.core.ArtefactHandler) ServiceArtefactHandler(org.grails.core.artefact.ServiceArtefactHandler) Test(org.junit.jupiter.api.Test)

Example 55 with GroovyClassLoader

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

the class GrailsApplicationAttributesTests method testGetViewUri.

/*
     * Test method for 'org.grails.web.servlet.DefaultGrailsApplicationAttributes.getViewUri(String, ServletRequest)'
     */
@Test
public void testGetViewUri() throws Exception {
    GrailsApplicationAttributes attrs = new DefaultGrailsApplicationAttributes(new MockServletContext());
    GroovyClassLoader gcl = new GroovyClassLoader();
    Class<?> controllerClass = gcl.parseClass("class TestController {\n" + "def controllerUri = '/test'\n" + "def controllerName = 'test'\n" + "}");
    MockHttpServletRequest request = new MockHttpServletRequest();
    request.setAttribute(GrailsApplicationAttributes.CONTROLLER, controllerClass.newInstance());
    assertEquals("/WEB-INF/grails-app/views/test/aView.gsp", attrs.getViewUri("aView", request));
    assertEquals("/WEB-INF/grails-app/views/shared.gsp", attrs.getViewUri("/shared", request));
}
Also used : GrailsApplicationAttributes(org.grails.web.util.GrailsApplicationAttributes) GroovyClassLoader(groovy.lang.GroovyClassLoader) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockServletContext(org.springframework.mock.web.MockServletContext) 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