Search in sources :

Example 6 with Groovity

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

the class HttpLocatorTest method testHTTPCompile.

@Test
public void testHTTPCompile() throws Exception {
    stubFor(get(urlEqualTo("/")).willReturn(aResponse().withStatus(200).withHeader("Last-Modified", "100").withBody("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">\r\n" + "<html>\r\n" + " <head>\r\n" + "  <title>Index of /groovy/nwsDynGroovy</title>\r\n" + " </head>\r\n" + " <body>\r\n" + "<h1>Index of /groovy/nwsDynGroovy</h1>\r\n" + "<ul><li><a href=\"/groovy/\"> Parent Directory</a></li>\r\n" + "<li><a href=\"test.grvt\"> test.grvt</a></li>\r\n" + "</ul>\r\n" + "</body></html>")));
    String lmod = DateUtils.formatDate(new Date());
    stubFor(head(urlEqualTo("/test.grvt")).willReturn(aResponse().withStatus(200).withHeader("Last-Modified", lmod)));
    stubFor(get(urlEqualTo("/test.grvt")).willReturn(aResponse().withStatus(200).withHeader("Last-Modified", lmod).withBody(" out << \"hello\" ")));
    Groovity groovity = new GroovityBuilder().setSourcePhases(EnumSet.of(GroovityPhase.STARTUP)).setSourceLocations(Arrays.asList(new URI("http://localhost:28187"))).build();
    CharArrayWriter writer = new CharArrayWriter();
    Binding binding = new Binding();
    Script script = groovity.load("/test", binding);
    binding.setProperty("out", writer);
    script.run();
    Assert.assertEquals("hello", writer.toString());
}
Also used : Binding(groovy.lang.Binding) Script(groovy.lang.Script) GroovityBuilder(com.disney.groovity.GroovityBuilder) Groovity(com.disney.groovity.Groovity) URI(java.net.URI) Date(java.util.Date) CharArrayWriter(java.io.CharArrayWriter) Test(org.junit.Test)

Example 7 with Groovity

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

the class TestCoreGroovity method testCaseInsensitive.

@Test
public void testCaseInsensitive() throws Exception {
    Groovity cig = setupGroovity(false, new StringWriter());
    Binding binding = new Binding();
    StringWriter writer = new StringWriter();
    binding.setVariable("out", writer);
    cig.run("/mixedcase", binding);
    Assert.assertEquals("OK", writer.toString().trim());
}
Also used : Binding(groovy.lang.Binding) Groovity(com.disney.groovity.Groovity) StringWriter(java.io.StringWriter) Test(org.junit.Test)

Example 8 with Groovity

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

the class TestCoreGroovity method setupGroovity.

private static Groovity setupGroovity(boolean caseSensitive, final Writer out) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IOException, URISyntaxException {
    Map<String, Object> defaultBinding = new HashMap<>();
    defaultBinding.put("hello", "world");
    defaultBinding.put("extensions", "overrideMe");
    Groovity groovity = new GroovityBuilder().setSourceLocations(Arrays.asList(new File("src/test/resources/core").toURI())).setSourcePhases(EnumSet.of(GroovityPhase.STARTUP)).setCaseSensitive(caseSensitive).setDefaultBinding(defaultBinding).setBindingDecorator(new BindingDecorator() {

        @SuppressWarnings({ "rawtypes", "unchecked" })
        @Override
        public void decorate(Map binding) {
            binding.put("extensions", Arrays.asList("antivirus", "firewall"));
            binding.put("whatToSay", "Orange you glad I didn't say banana?");
            if (!binding.containsKey("out")) {
                binding.put("out", out);
            }
        }
    }).build();
    return groovity;
}
Also used : GroovityBuilder(com.disney.groovity.GroovityBuilder) Groovity(com.disney.groovity.Groovity) HashMap(java.util.HashMap) BindingDecorator(com.disney.groovity.BindingDecorator) File(java.io.File) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Groovity (com.disney.groovity.Groovity)8 File (java.io.File)5 GroovityBuilder (com.disney.groovity.GroovityBuilder)4 Binding (groovy.lang.Binding)3 Script (groovy.lang.Script)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 ArgsLookup (com.disney.groovity.ArgsLookup)2 BindingDecorator (com.disney.groovity.BindingDecorator)2 GroovityServletContainer (com.disney.groovity.servlet.container.GroovityServletContainer)2 GroovityServletContainerBuilder (com.disney.groovity.servlet.container.GroovityServletContainerBuilder)2 GroovitySourceLocator (com.disney.groovity.source.GroovitySourceLocator)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 Test (org.junit.Test)2 GatherStatistics (com.disney.groovity.compile.GatherStatistics)1 GroovityClassLoader (com.disney.groovity.compile.GroovityClassLoader)1 GroovityErrorHandlerChain (com.disney.groovity.servlet.error.GroovityErrorHandlerChain)1 GroovityErrorHandlerChainDecorator (com.disney.groovity.servlet.error.GroovityErrorHandlerChainDecorator)1