Search in sources :

Example 1 with User

use of org.beetl.core.User 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 2 with User

use of org.beetl.core.User 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 3 with User

use of org.beetl.core.User 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 4 with User

use of org.beetl.core.User 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)

Example 5 with User

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

the class SafeOutputTest method testSafeExp.

@Test
public void testSafeExp() throws Exception {
    Template t = gt.getTemplate("/safe/safe_exp_template.html");
    t.binding("test", new User("joel"));
    String str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/safe/safe_exp_expected.html"), str);
    t = gt.getTemplate("/safe/safe_exp_template.html");
    t.binding("test", new User("joel"));
    str = t.render();
    AssertJUnit.assertEquals(this.getFileContent("/safe/safe_exp_expected.html"), str);
}
Also used : User(org.beetl.core.User) Template(org.beetl.core.Template) Test(org.testng.annotations.Test)

Aggregations

User (org.beetl.core.User)16 Template (org.beetl.core.Template)14 Test (org.testng.annotations.Test)14 HashMap (java.util.HashMap)5 Map (java.util.Map)5 List (java.util.List)2 JSONObject (com.alibaba.fastjson.JSONObject)1 Context (org.beetl.core.Context)1 VirtualClassAttribute (org.beetl.core.VirtualClassAttribute)1