KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > freemarker > FreemarkerTest


1 /*
2  * Copyright (c) 2002-2003 by OpenSymphony
3  * All rights reserved.
4  */

5 /*
6  * Created on 1/10/2003
7  *
8  */

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 JavaDoc;
20
21
22 /**
23  * @author CameronBraid
24  */

25 public class FreemarkerTest extends TestCase {
26     //~ Instance fields ////////////////////////////////////////////////////////
27

28     TestAction testAction = null;
29
30     //~ Constructors ///////////////////////////////////////////////////////////
31

32     /**
33      *
34      */

35     public FreemarkerTest(String JavaDoc name) {
36         super(name);
37     }
38
39     //~ Methods ////////////////////////////////////////////////////////////////
40

41     public void testSelectHelper() {
42         WebWorkUtil wwUtil = new WebWorkUtil(ActionContext.getContext().getValueStack(), null, null);
43
44         List JavaDoc 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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
78         super.tearDown();
79         ActionContext.setContext(null);
80     }
81 }
82
Popular Tags