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