Search in sources :

Example 91 with Template

use of org.beetl.core.Template in project beetl2.0 by javamonkey.

the class NativeTest method testObjectReturn.

@Test
public void testObjectReturn() throws Exception {
    NativeTest test = new NativeTest();
    Template t = gt.getTemplate("/nat/object_template.html");
    this.bind(t, "test", test);
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/nat/object_expected.html"), str);
    t = gt.getTemplate("/nat/object_template.html");
    this.bind(t, "test", test);
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/nat/object_expected.html"), str);
}
Also used : GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 92 with Template

use of org.beetl.core.Template in project beetl2.0 by javamonkey.

the class NativeTest method testPrivateMethodCall.

@Test
public void testPrivateMethodCall() throws Exception {
    Template t = gt.getTemplate("/nat/nat_private_method_template.html");
    this.bind(t, "test", Request.getRequest());
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/nat/nat_private_method_expected.html"), str);
    t = gt.getTemplate("/nat/nat_private_method_template.html");
    this.bind(t, "test", Request.getRequest());
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/nat/nat_private_method_expected.html"), str);
}
Also used : GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 93 with Template

use of org.beetl.core.Template in project beetl2.0 by javamonkey.

the class CompositeResourceLoaderTest method testSimple.

@Test
public void testSimple() throws Exception {
    Configuration conf = Configuration.defaultConfiguration();
    CompositeResourceLoader loader = new CompositeResourceLoader();
    String home = System.getProperty("user.dir");
    String path1 = home + "/src/test/resources/template/resourceloader/var1";
    String path2 = home + "/src/test/resources/template/resourceloader/var2";
    FileResourceLoader fileLoader1 = new FileResourceLoader(path1);
    FileResourceLoader fileLoader2 = new FileResourceLoader(path2);
    Map data = getData();
    // 根据id加载
    MapResourceLoader mapLoader = new MapResourceLoader(data);
    loader.addResourceLoader(new StartsWithMatcher("http:").withoutPrefix(), fileLoader2);
    loader.addResourceLoader(new StartsWithMatcher("db:").withoutPrefix(), mapLoader);
    loader.addResourceLoader(new AllowAllMatcher(), fileLoader1);
    GroupTemplate gt = new GroupTemplate(loader, conf);
    Template t = gt.getTemplate("/xxx.html");
    t.binding("a", "hello");
    String result = t.render();
    ;
    AssertJUnit.assertEquals("hellohello--file2:hello--db=hello", result);
}
Also used : StartsWithMatcher(org.beetl.core.resource.StartsWithMatcher) Configuration(org.beetl.core.Configuration) AllowAllMatcher(org.beetl.core.resource.AllowAllMatcher) FileResourceLoader(org.beetl.core.resource.FileResourceLoader) GroupTemplate(org.beetl.core.GroupTemplate) CompositeResourceLoader(org.beetl.core.resource.CompositeResourceLoader) Map(java.util.Map) HashMap(java.util.HashMap) GroupTemplate(org.beetl.core.GroupTemplate) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 94 with Template

use of org.beetl.core.Template in project beetl2.0 by javamonkey.

the class JsonTest method testSimple.

@Test
public void testSimple() throws Exception {
    Template t = gt.getTemplate("/exp/json/json_template.html");
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/exp/json/json_expected.html"), str);
    t = gt.getTemplate("/exp/json/json_template.html");
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/exp/json/json_expected.html"), str);
}
Also used : Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 95 with Template

use of org.beetl.core.Template in project beetl2.0 by javamonkey.

the class PriorityTest method testAll.

@Test
public void testAll() throws Exception {
    Template t = gt.getTemplate("/exp/priority_all_template.html");
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/exp/priority_all_expected.html"), str);
    t = gt.getTemplate("/exp/priority_all_template.html");
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/exp/priority_all_expected.html"), str);
}
Also used : Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Aggregations

Template (org.beetl.core.Template)122 Test (org.testng.annotations.Test)96 GroupTemplate (org.beetl.core.GroupTemplate)41 Map (java.util.Map)15 User (org.beetl.core.User)14 HashMap (java.util.HashMap)13 Configuration (org.beetl.core.Configuration)13 FileResourceLoader (org.beetl.core.resource.FileResourceLoader)6 StringTemplateResourceLoader (org.beetl.core.resource.StringTemplateResourceLoader)6 Context (org.beetl.core.Context)5 JSONObject (com.alibaba.fastjson.JSONObject)4 List (java.util.List)4 ClasspathResourceLoader (org.beetl.core.resource.ClasspathResourceLoader)4 VirtualAttributeEval (org.beetl.core.VirtualAttributeEval)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 BodyContent (org.beetl.core.BodyContent)2 BeetlException (org.beetl.core.exception.BeetlException)2 WebRender (org.beetl.ext.web.WebRender)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1