@Override public void doRender(TemplateRenderContext renderContext) throws TemplateExecutionException, IOException { Binding binding = new BindingImpl(renderContext); // Script script = InvokerHelper.createScript(scriptClass, binding); // try { script.run(); } catch (Exception e) { if (e instanceof IOException) { throw (IOException)e; } else { throw buildRuntimeException(e); } } catch (Throwable e) { if (e instanceof Error) { throw ((Error)e); } throw buildRuntimeException(e); } }
@Test public void testSiblingClosures() throws IOException, TemplateException { GroovyTemplateStub template = template("#{title value=a/}#{title value=b/}"); template.getClassName(); }
String script = getScript(loader, fqn); GroovyCodeSource gcs = new GroovyCodeSource(new String(script.getBytes()), "myscript", "/groovy/shell"); GroovyClassLoader gcl = new GroovyClassLoader(loader, config);
@Test public void testCarriageReturn() throws Exception { GroovyTemplateStub s = template("a\r\nb"); s.init(); StringWriter out = new StringWriter(); new TemplateRenderContext(s, Collections.<String, Object>emptyMap()).render(OutputStream.create(Tools.UTF_8, out)); assertEquals("a\nb", out.toString()); } }
@Test public void testFoo() throws Exception { GroovyTemplateStub s = template("a<%=foo%>c"); s.init(); StringWriter out = new StringWriter(); new TemplateRenderContext(s, Collections.<String, Object>singletonMap("foo", "b")).render(OutputStream.create(Tools.UTF_8, out)); assertEquals("abc", out.toString()); }
@Test public void testCarriageReturn() throws Exception { GroovyTemplateStub s = template("a\r\nb"); s.init(); StringWriter out = new StringWriter(); new TemplateRenderContext(s, Collections.<String, Object>emptyMap()).render(OutputStream.create(Tools.UTF_8, out)); assertEquals("a\nb", out.toString()); } }
@Test public void testSiblingClosures() throws IOException, TemplateException { GroovyTemplateStub template = template("#{title value=a/}#{title value=b/}"); template.getClassName(); }
@Override public void doRender(TemplateRenderContext renderContext) throws TemplateExecutionException, IOException { Binding binding = new BindingImpl(renderContext); // Script script = InvokerHelper.createScript(scriptClass, binding); // try { script.run(); } catch (Exception e) { if (e instanceof IOException) { throw (IOException)e; } else { throw buildRuntimeException(e); } } catch (Throwable e) { if (e instanceof Error) { throw ((Error)e); } throw buildRuntimeException(e); } }
String script = getScript(loader, fqn); GroovyCodeSource gcs = new GroovyCodeSource(new String(script.getBytes()), "myscript", "/groovy/shell"); GroovyClassLoader gcl = new GroovyClassLoader(loader, config);
@Test public void testFoo() throws Exception { GroovyTemplateStub s = template("a<%=foo%>c"); s.init(); StringWriter out = new StringWriter(); new TemplateRenderContext(s, Collections.<String, Object>singletonMap("foo", "b")).render(OutputStream.create(Tools.UTF_8, out)); assertEquals("abc", out.toString()); }
private void assertLineNumber(int expectedLineNumber, String expectedText, String script) throws IOException, TemplateException { GroovyTemplateStub template = template(script); try { new TemplateRenderContext(template).render(OutputStream.create()); fail(); } catch (TemplateExecutionException t) { assertEquals(expectedText, t.getText()); assertEquals(expectedLineNumber, (Object)t.getLineNumber()); StackTraceElement scriptElt = null; for (StackTraceElement elt : t.getCause().getStackTrace()) { if (elt.getClassName().equals(template.getClassName())) { scriptElt = elt; break; } } assertEquals(expectedLineNumber, scriptElt.getLineNumber()); } } }
stub.init(); return stub;
private void assertLineNumber(int expectedLineNumber, String expectedText, String script) throws IOException, TemplateException { GroovyTemplateStub template = template(script); try { new TemplateRenderContext(template).render(OutputStream.create()); fail(); } catch (TemplateExecutionException t) { assertEquals(expectedText, t.getText()); assertEquals(expectedLineNumber, (Object)t.getLineNumber()); StackTraceElement scriptElt = null; for (StackTraceElement elt : t.getCause().getStackTrace()) { if (elt.getClassName().equals(template.getClassName())) { scriptElt = elt; break; } } assertEquals(expectedLineNumber, scriptElt.getLineNumber()); } } }
stub.init(); return stub;