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