Search in sources :

Example 6 with Template

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

the class CommentTypeTest method testTypel.

@Test
public void testTypel() throws Exception {
    User user = User.getTestUser();
    List list = User.getTestUsers();
    Template t = gt.getTemplate("/type/commenttype_template.html");
    this.bind(t, "me", user, "list", list);
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/type/commenttype_expected.html"), str);
    t = gt.getTemplate("/type/commenttype_template.html");
    this.bind(t, "me", user, "list", list);
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/type/commenttype_expected.html"), str);
}
Also used : User(org.beetl.core.User) List(java.util.List) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 7 with Template

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

the class DynamicTest method testDynamicUser.

@Test
public void testDynamicUser() throws Exception {
    Map map = new HashMap();
    map.put("name", "joelli");
    map.put("age", 36);
    Template t = gt.getTemplate("/type/dynamic_user_template.html");
    this.bind(t, "user", map);
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/type/dynamic_user_expected.html"), str);
    User user = User.getTestUser();
    t = gt.getTemplate("/type/dynamic_user_template.html");
    this.bind(t, "user", user);
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/type/dynamic_user_expected.html"), str);
}
Also used : User(org.beetl.core.User) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 8 with Template

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

the class SimpleVATest method testMapAttribute.

@Test
public void testMapAttribute() throws Exception {
    User user = User.getTestUser();
    Map map = new HashMap();
    map.put("name", "joelli");
    map.put("salary", 10000.01);
    Template t = gt.getTemplate("/va/va_map_template.html");
    this.bind(t, "user", user, "map", map);
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/va/va_map_expected.html"), str);
    t = gt.getTemplate("/va/va_map_template.html");
    this.bind(t, "user", user, "map", map);
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/va/va_map_expected.html"), str);
}
Also used : User(org.beetl.core.User) HashMap(java.util.HashMap) Map(java.util.Map) HashMap(java.util.HashMap) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 9 with Template

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

the class VirtualAttributeTest method testVirtualAttribute.

@Test
public void testVirtualAttribute() throws Exception {
    gt.registerVirtualAttributeEval(new VirtualAttributeEval() {

        @Override
        public Object eval(Object o, String attributeName, Context ctx) {
            // TODO Auto-generated method stub
            return attributeName;
        }

        @Override
        public boolean isSupport(Class c, String attributeName) {
            if (attributeName.equals("hello"))
                return true;
            else
                return false;
        }
    });
    List list = User.getTestUsers();
    Template t = gt.getTemplate("/va/va_virtual_template.html");
    this.bind(t, "list", list, "user", new Object());
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/va/va_virtual_expected.html"), str);
    t = gt.getTemplate("/va/va_virtual_template.html");
    this.bind(t, "list", list, "user", new Object());
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/va/va_virtual_expected.html"), str);
}
Also used : Context(org.beetl.core.Context) VirtualAttributeEval(org.beetl.core.VirtualAttributeEval) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Example 10 with Template

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

the class VirtualAttributeTest method testVirtualClasAttribute.

@Test
public void testVirtualClasAttribute() throws Exception {
    gt.registerVirtualAttributeClass(User.class, new VirtualClassAttribute() {

        @Override
        public String eval(Object o, String attributeName, Context ctx) {
            User user = (User) o;
            if (user.getAge() < 10) {
                return "young";
            } else {
                return "old";
            }
        }
    });
    List list = User.getTestUsers();
    User user = User.getTestUser();
    Template t = gt.getTemplate("/va/class_virtual_template.html");
    this.bind(t, "list", list, "user", user);
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/va/class_virtual_expected.html"), str);
    t = gt.getTemplate("/va/class_virtual_template.html");
    this.bind(t, "list", list, "user", user);
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/va/class_virtual_expected.html"), str);
}
Also used : Context(org.beetl.core.Context) User(org.beetl.core.User) VirtualClassAttribute(org.beetl.core.VirtualClassAttribute) JSONObject(com.alibaba.fastjson.JSONObject) List(java.util.List) 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