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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations