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