01: /*
02: * Copyright (c) 2002-2003 by OpenSymphony
03: * All rights reserved.
04: */
05: /*
06: * Created on 1/10/2003
07: *
08: */
09: 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: * @author CameronBraid
23: */
24: public class FreemarkerTest extends TestCase {
25:
26: TestAction testAction = null;
27:
28: /**
29: *
30: */
31: public FreemarkerTest(String name) {
32: super (name);
33: }
34:
35: public void testSelectHelper() {
36: WebWorkUtil wwUtil = new WebWorkUtil(ActionContext.getContext()
37: .getValueStack(), null, null);
38:
39: List selectList = null;
40:
41: selectList = wwUtil.makeSelectList("ignored", "stringList",
42: null, null);
43: assertEquals("one", ((ListEntry) selectList.get(0)).getKey());
44: assertEquals("one", ((ListEntry) selectList.get(0)).getValue());
45:
46: selectList = wwUtil.makeSelectList("ignored", "beanList",
47: "name", "value");
48: assertEquals("one", ((ListEntry) selectList.get(0)).getKey());
49: assertEquals("1", ((ListEntry) selectList.get(0)).getValue());
50: }
51:
52: public void testValueStackMode() throws Exception {
53: ScopesHashModel model = new ScopesHashModel(
54: ObjectWrapper.BEANS_WRAPPER, null, null, ActionContext
55: .getContext().getValueStack());
56:
57: CollectionModel stringList = null;
58:
59: stringList = (CollectionModel) model.get("stringList");
60: assertEquals("one", stringList.get(0).toString());
61:
62: assertEquals("one", model.get("stringList[0]").toString());
63: assertEquals("one", model.get("beanList[0].name").toString());
64: }
65:
66: protected void setUp() throws Exception {
67: super .setUp();
68:
69: OgnlValueStack stack = new OgnlValueStack();
70: ActionContext.setContext(new ActionContext(stack.getContext()));
71:
72: testAction = new TestAction();
73: ActionContext.getContext().getValueStack().push(testAction);
74: }
75:
76: protected void tearDown() throws Exception {
77: super.tearDown();
78: ActionContext.setContext(null);
79: }
80: }
|