1 5 9 package com.opensymphony.webwork.views.freemarker; 10 11 import com.opensymphony.webwork.util.ListEntry; 12 import com.opensymphony.webwork.util.WebWorkUtil; 13 import com.opensymphony.xwork.ActionContext; 14 import com.opensymphony.xwork.util.OgnlValueStack; 15 import freemarker.ext.beans.CollectionModel; 16 import freemarker.template.ObjectWrapper; 17 import junit.framework.TestCase; 18 19 import java.util.List ; 20 21 22 25 public class FreemarkerTest extends TestCase { 26 28 TestAction testAction = null; 29 30 32 35 public FreemarkerTest(String name) { 36 super(name); 37 } 38 39 41 public void testSelectHelper() { 42 WebWorkUtil wwUtil = new WebWorkUtil(ActionContext.getContext().getValueStack(), null, null); 43 44 List selectList = null; 45 46 selectList = wwUtil.makeSelectList("ignored", "stringList", null, null); 47 assertEquals("one", ((ListEntry) selectList.get(0)).getKey()); 48 assertEquals("one", ((ListEntry) selectList.get(0)).getValue()); 49 50 selectList = wwUtil.makeSelectList("ignored", "beanList", "name", "value"); 51 assertEquals("one", ((ListEntry) selectList.get(0)).getKey()); 52 assertEquals("1", ((ListEntry) selectList.get(0)).getValue()); 53 } 54 55 public void testValueStackMode() throws Exception { 56 ScopesHashModel model = new ScopesHashModel(ObjectWrapper.BEANS_WRAPPER, null, null, ActionContext.getContext().getValueStack()); 57 58 CollectionModel stringList = null; 59 60 stringList = (CollectionModel) model.get("stringList"); 61 assertEquals("one", stringList.get(0).toString()); 62 63 assertEquals("one", model.get("stringList[0]").toString()); 64 assertEquals("one", model.get("beanList[0].name").toString()); 65 } 66 67 protected void setUp() throws Exception { 68 super.setUp(); 69 70 OgnlValueStack stack = new OgnlValueStack(); 71 ActionContext.setContext(new ActionContext(stack.getContext())); 72 73 testAction = new TestAction(); 74 ActionContext.getContext().getValueStack().push(testAction); 75 } 76 77 protected void tearDown() throws Exception { 78 super.tearDown(); 79 ActionContext.setContext(null); 80 } 81 } 82 | Popular Tags |