@Test public void testInclude() throws Exception { MockApplication<?> app = application("plugin.template.tag.include").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String out = render.assertStringResponse(); assertEquals("foo", out); }
@Test public void testNotFound() throws Exception { List<CompilationError> errors = compiler("plugin.template.tag.notfound").formalErrorReporting(true).failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertTrue(error.getSource().endsWith("template/tag/notfound/A.java")); assertEquals(TemplateMetaModel.UNKNOWN_TAG, error.getCode()); assertEquals(Arrays.asList("notfound"), error.getArguments()); }
@Test public void testParam() throws Exception { if (getDI() != InjectorProvider.GUICE) { MockApplication<?> app = application("plugin.template.tag.param").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String content = render.assertStringResponse(); assertEquals("foo_value", content); } }
@Test public void testIncludeCircular() throws Exception { List<CompilationError> errors = compiler("plugin.template.tag.includecircular").formalErrorReporting(true).failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(TemplateMetaModel.TEMPLATE_CYCLE, error.getCode()); assertEquals(Arrays.asList( "Path[/plugin/template/tag/includecircular/templates/index.gtmpl]", "/plugin/template/tag/includecircular/templates/index.gtmpl->/plugin/template/tag/includecircular/templates/foo.gtmpl"), error.getArguments()); }
@Test public void testRecompileTemplate() throws Exception { MockApplication<?> app = application("plugin.template.tag.decorate").init(); assertNotNull(desc); TemplateModel<?> foo = new TemplateModel<ASTNode.Template>( new ASTNode.Template(), assertNotNull(template);
@Test public void testIncludeCircular() throws Exception { List<CompilationError> errors = compiler("plugin.template.tag.includecircular").formalErrorReporting(true).failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertEquals(TemplateMetaModel.TEMPLATE_CYCLE, error.getCode()); assertEquals(Arrays.asList( "Path[/plugin/template/tag/includecircular/templates/index.gtmpl]", "/plugin/template/tag/includecircular/templates/index.gtmpl->/plugin/template/tag/includecircular/templates/foo.gtmpl"), error.getArguments()); }
@Test public void testRecompileTemplate() throws Exception { MockApplication<?> app = application("plugin.template.tag.decorate").init(); assertNotNull(desc); TemplateModel<?> foo = new TemplateModel<ASTNode.Template>( new ASTNode.Template(), assertNotNull(template);
@Test public void testSimpleNested() throws Exception { MockApplication<?> app = application("plugin.template.tag.simple.nested").init(); MockClient client = app.client(); MockViewBridge render = client.render(); String out = render.assertStringResponse(); assertEquals("<index><foo><bar>foo_content</bar></foo></index>", out); }
@Test public void testNotFound() throws Exception { List<CompilationError> errors = compiler("plugin.template.tag.notfound").formalErrorReporting(true).failCompile(); assertEquals(1, errors.size()); CompilationError error = errors.get(0); assertTrue(error.getSource().endsWith("template/tag/notfound/A.java")); assertEquals(TemplateMetaModel.UNKNOWN_TAG, error.getCode()); assertEquals(Arrays.asList("notfound"), error.getArguments()); }
@Test public void testIncludeExternal() throws Exception { CompilerAssert<File, File> simpleHelper = compiler("plugin.template.simple"); simpleHelper.assertCompile(); CompilerAssert<File, File> helper = compiler("plugin.template.tag.includeexternal"); helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockApplication<?> app = new MockApplication<File>( helper, di, Name.parse("plugin.template.tag.includeexternal")); app.init(); MockClient client = app.client(); assertEquals("hello", client.render().assertStringResponse()); }
@Test public void testParam() throws Exception { if (getDI() != InjectorProvider.GUICE) { MockApplication<?> app = application("plugin.template.tag.param").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String content = render.assertStringResponse(); assertEquals("foo_value", content); } }
@Test public void testDecorateNested() throws Exception { MockApplication<?> app = application("plugin.template.tag.decoratenested").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String out = render.assertStringResponse(); assertEquals("<juu><foo>bar</foo></juu>", out); }
@Test public void testSimpleTagReuse() throws Exception { CompilerAssert<File, File> simpleHelper = compiler("plugin.template.tag.simple.render"); simpleHelper.assertCompile(); File classes = simpleHelper.getClassOutput().getRoot(); File services = new File(classes, "META-INF/services"); assertTrue(services.mkdirs()); File tagHandler = new File(services, "juzu.template.TagHandler"); FileWriter writer = new FileWriter(tagHandler); CompilerAssert<File, File> helper = compiler("plugin.template.tag.simple.reuse"); helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockViewBridge render = client.render(); String out = render.assertStringResponse(); assertEquals("foothe_tagbar", out);
@Test public void testDecorateExternal() throws Exception { CompilerAssert<File, File> simpleHelper = compiler("plugin.template.tag.decorate"); simpleHelper.assertCompile(); CompilerAssert<File, File> helper = compiler("plugin.template.tag.decorateexternal"); helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockApplication<?> app = new MockApplication<File>( helper, di, Name.parse("plugin.template.tag.decorateexternal")); app.init(); MockClient client = app.client(); assertEquals("<foo>bar</foo>", client.render().assertStringResponse()); }
@Test public void testIncludeDouble() throws Exception { MockApplication<?> app = application("plugin.template.tag.includedouble").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String out = render.assertStringResponse(); assertEquals("foobar", out); }
@Test public void testSimpleTagReuse() throws Exception { CompilerAssert<File, File> simpleHelper = compiler("plugin.template.tag.simple.render"); simpleHelper.assertCompile(); File classes = simpleHelper.getClassOutput().getRoot(); File services = new File(classes, "META-INF/services"); assertTrue(services.mkdirs()); File tagHandler = new File(services, "juzu.template.TagHandler"); FileWriter writer = new FileWriter(tagHandler); CompilerAssert<File, File> helper = compiler("plugin.template.tag.simple.reuse"); helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockViewBridge render = client.render(); String out = render.assertStringResponse(); assertEquals("foothe_tagbar", out);
@Test public void testDecorateExternal() throws Exception { CompilerAssert<File, File> simpleHelper = compiler("plugin.template.tag.decorate"); simpleHelper.assertCompile(); CompilerAssert<File, File> helper = compiler("plugin.template.tag.decorateexternal"); helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockApplication<?> app = new MockApplication<File>( helper, di, Name.parse("plugin.template.tag.decorateexternal")); app.init(); MockClient client = app.client(); assertEquals("<foo>bar</foo>", client.render().assertStringResponse()); }
@Test public void testSimpleNested() throws Exception { MockApplication<?> app = application("plugin.template.tag.simple.nested").init(); MockClient client = app.client(); MockViewBridge render = client.render(); String out = render.assertStringResponse(); assertEquals("<index><foo><bar>foo_content</bar></foo></index>", out); }
@Test public void testIncludeExternal() throws Exception { CompilerAssert<File, File> simpleHelper = compiler("plugin.template.simple"); simpleHelper.assertCompile(); CompilerAssert<File, File> helper = compiler("plugin.template.tag.includeexternal"); helper.addClassPath(simpleHelper.getClassOutput()); helper.assertCompile(); MockApplication<?> app = new MockApplication<File>( helper, di, Name.parse("plugin.template.tag.includeexternal")); app.init(); MockClient client = app.client(); assertEquals("hello", client.render().assertStringResponse()); }
@Test public void testIncludeTwice() throws Exception { MockApplication<?> app = application("plugin.template.tag.includetwice").init(); // MockClient client = app.client(); MockViewBridge render = client.render(); String out = render.assertStringResponse(); assertEquals("foofoo", out); }