Search in sources :

Example 6 with GroovityBuilder

use of com.disney.groovity.GroovityBuilder in project groovity by disney.

the class TestCyclicGroovity method testNormalCode.

@Test
public void testNormalCode() throws Exception {
    groovity = new GroovityBuilder().setSourceLocations(Arrays.asList(new File("src/test/resources/static").toURI())).setSourcePhases(EnumSet.of(GroovityPhase.STARTUP)).build();
    Exception e = null;
    Binding binding = new Binding();
    StringWriter writer = new StringWriter();
    binding.setVariable("out", writer);
    binding.setVariable("request", "someRuntimeRequest");
    groovity.run("/static", binding);
    System.out.println("Result for /static is " + writer.toString());
    Assert.assertEquals("static|runtime", writer.toString());
}
Also used : Binding(groovy.lang.Binding) GroovityBuilder(com.disney.groovity.GroovityBuilder) StringWriter(java.io.StringWriter) File(java.io.File) Test(org.junit.Test)

Example 7 with GroovityBuilder

use of com.disney.groovity.GroovityBuilder in project groovity by disney.

the class TestCyclicGroovity method testCyclicLoadChecking.

@Test
public void testCyclicLoadChecking() throws Exception {
    groovity = new GroovityBuilder().setSourceLocations(Arrays.asList(new File("src/test/resources/cyclic").toURI())).setSourcePhases(EnumSet.of(GroovityPhase.STARTUP)).build();
    Binding binding = new Binding();
    StringWriter writer = new StringWriter();
    binding.setVariable("out", writer);
    Throwable e = null;
    try {
        groovity.run("/top", binding);
    } catch (Exception x) {
        e = x;
    }
    while (e != null && !(e instanceof InstantiationException)) {
        e = e.getCause();
    }
    Assert.assertNotNull("Expected InstantiationException", e);
    Assert.assertEquals("Expected InstantiationException", InstantiationException.class, e.getClass());
}
Also used : Binding(groovy.lang.Binding) GroovityBuilder(com.disney.groovity.GroovityBuilder) StringWriter(java.io.StringWriter) File(java.io.File) Test(org.junit.Test)

Aggregations

GroovityBuilder (com.disney.groovity.GroovityBuilder)7 File (java.io.File)6 Groovity (com.disney.groovity.Groovity)4 Binding (groovy.lang.Binding)3 Test (org.junit.Test)3 BindingDecorator (com.disney.groovity.BindingDecorator)2 StringWriter (java.io.StringWriter)2 URI (java.net.URI)2 Map (java.util.Map)2 ArgsLookup (com.disney.groovity.ArgsLookup)1 GroovityErrorHandlerChain (com.disney.groovity.servlet.error.GroovityErrorHandlerChain)1 GroovityErrorHandlerChainDecorator (com.disney.groovity.servlet.error.GroovityErrorHandlerChainDecorator)1 GroovitySourceLocator (com.disney.groovity.source.GroovitySourceLocator)1 JsonSlurper (groovy.json.JsonSlurper)1 Script (groovy.lang.Script)1 CharArrayWriter (java.io.CharArrayWriter)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1