01: /*
02: * $Id: FreemarkerTest.java 471756 2006-11-06 15:01:43Z husted $
03: *
04: * Licensed to the Apache Software Foundation (ASF) under one
05: * or more contributor license agreements. See the NOTICE file
06: * distributed with this work for additional information
07: * regarding copyright ownership. The ASF licenses this file
08: * to you under the Apache License, Version 2.0 (the
09: * "License"); you may not use this file except in compliance
10: * with the License. You may obtain a copy of the License at
11: *
12: * http://www.apache.org/licenses/LICENSE-2.0
13: *
14: * Unless required by applicable law or agreed to in writing,
15: * software distributed under the License is distributed on an
16: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17: * KIND, either express or implied. See the License for the
18: * specific language governing permissions and limitations
19: * under the License.
20: */
21: package org.apache.struts2.views.freemarker;
22:
23: import java.util.List;
24:
25: import junit.framework.TestCase;
26:
27: import org.apache.struts2.util.ListEntry;
28: import org.apache.struts2.util.StrutsUtil;
29:
30: import com.opensymphony.xwork2.ActionContext;
31: import com.opensymphony.xwork2.util.ValueStack;
32: import com.opensymphony.xwork2.util.ValueStackFactory;
33:
34: import freemarker.ext.beans.CollectionModel;
35: import freemarker.template.ObjectWrapper;
36:
37: /**
38: */
39: public class FreemarkerTest extends TestCase {
40:
41: TestAction testAction = null;
42:
43: /**
44: *
45: */
46: public FreemarkerTest(String name) {
47: super (name);
48: }
49:
50: public void testSelectHelper() {
51: StrutsUtil wwUtil = new StrutsUtil(ActionContext.getContext()
52: .getValueStack(), null, null);
53:
54: List selectList = null;
55:
56: selectList = wwUtil.makeSelectList("ignored", "stringList",
57: null, null);
58: assertEquals("one", ((ListEntry) selectList.get(0)).getKey());
59: assertEquals("one", ((ListEntry) selectList.get(0)).getValue());
60:
61: selectList = wwUtil.makeSelectList("ignored", "beanList",
62: "name", "value");
63: assertEquals("one", ((ListEntry) selectList.get(0)).getKey());
64: assertEquals("1", ((ListEntry) selectList.get(0)).getValue());
65: }
66:
67: public void testValueStackMode() throws Exception {
68: ScopesHashModel model = new ScopesHashModel(
69: ObjectWrapper.BEANS_WRAPPER, null, null, ActionContext
70: .getContext().getValueStack());
71:
72: CollectionModel stringList = null;
73:
74: stringList = (CollectionModel) model.get("stringList");
75: assertEquals("one", stringList.get(0).toString());
76:
77: assertEquals("one", model.get("stringList[0]").toString());
78: assertEquals("one", model.get("beanList[0].name").toString());
79: }
80:
81: protected void setUp() throws Exception {
82: super .setUp();
83:
84: ValueStack stack = ValueStackFactory.getFactory()
85: .createValueStack();
86: ActionContext.setContext(new ActionContext(stack.getContext()));
87:
88: testAction = new TestAction();
89: ActionContext.getContext().getValueStack().push(testAction);
90: }
91:
92: protected void tearDown() throws Exception {
93: super.tearDown();
94: ActionContext.setContext(null);
95: }
96: }
|