001: /*
002: * $Id: RadioTest.java 572220 2007-09-03 02:46:43Z mrdon $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import java.util.HashMap;
024: import java.util.LinkedHashMap;
025:
026: import org.apache.struts2.TestAction;
027: import org.apache.struts2.views.jsp.AbstractUITagTest;
028:
029: /**
030: */
031: public class RadioTest extends AbstractUITagTest {
032:
033: public void testMapWithBooleanAsKey() throws Exception {
034: TestAction testAction = (TestAction) action;
035:
036: HashMap map = new LinkedHashMap();
037: map.put(Boolean.TRUE, "male");
038: map.put(Boolean.FALSE, "female");
039: testAction.setMap(map);
040:
041: RadioTag tag = new RadioTag();
042: tag.setPageContext(pageContext);
043: tag.setLabel("mylabel");
044: tag.setName("myname");
045: tag.setValue("%{true}");
046: tag.setList("map");
047:
048: tag.doStartTag();
049: tag.doEndTag();
050:
051: verify(RadioTag.class.getResource("Radio-3.txt"));
052: }
053:
054: public void testMapChecked() throws Exception {
055: TestAction testAction = (TestAction) action;
056: testAction.setFoo("bar");
057:
058: HashMap map = new HashMap();
059: map.put("1", "One");
060: map.put("2", "Two");
061: testAction.setMap(map);
062:
063: RadioTag tag = new RadioTag();
064: tag.setPageContext(pageContext);
065: tag.setLabel("mylabel");
066: tag.setName("myname");
067: tag.setValue("\"1\"");
068: tag.setList("map");
069: tag.setListKey("key");
070: tag.setListValue("value");
071:
072: tag.doStartTag();
073: tag.doEndTag();
074:
075: verify(RadioTag.class.getResource("Radio-2.txt"));
076: }
077:
078: public void testMapCheckedNull() throws Exception {
079: TestAction testAction = (TestAction) action;
080: testAction.setFoo("bar");
081:
082: HashMap map = new HashMap();
083: map.put("1", "One");
084: map.put("2", "Two");
085: testAction.setMap(map);
086:
087: RadioTag tag = new RadioTag();
088: tag.setPageContext(pageContext);
089: tag.setLabel("mylabel");
090: tag.setName("myname");
091: tag.setValue("%{map['3']}");
092: tag
093: .setList("#@java.util.TreeMap@{\"1\":\"One\", \"2\":\"Two\", \"\":\"N/A\"}");
094:
095: tag.doStartTag();
096: tag.doEndTag();
097:
098: verify(RadioTag.class.getResource("Radio-4.txt"));
099: }
100:
101: public void testSimple() throws Exception {
102: TestAction testAction = (TestAction) action;
103: testAction.setFoo("bar");
104: testAction.setList(new String[][] { { "hello", "world" },
105: { "foo", "bar" } });
106:
107: RadioTag tag = new RadioTag();
108: tag.setPageContext(pageContext);
109: tag.setLabel("mylabel");
110: tag.setName("myname");
111: tag.setValue("");
112: tag.setList("list");
113: tag.setListKey("top[0]");
114: tag.setListValue("top[1]");
115:
116: tag.doStartTag();
117: tag.doEndTag();
118:
119: verify(RadioTag.class.getResource("Radio-1.txt"));
120: }
121:
122: public void testGenericSimple() throws Exception {
123: RadioTag tag = new RadioTag();
124: prepareTagGeneric(tag);
125: verifyGenericProperties(tag, "simple", new String[] { "id",
126: "value" });
127: }
128:
129: public void testGenericXhtml() throws Exception {
130: RadioTag tag = new RadioTag();
131: prepareTagGeneric(tag);
132: verifyGenericProperties(tag, "xhtml", new String[] { "id",
133: "value" });
134: }
135:
136: public void testGenericAjax() throws Exception {
137: RadioTag tag = new RadioTag();
138: prepareTagGeneric(tag);
139: verifyGenericProperties(tag, "ajax", new String[] { "id",
140: "value" });
141: }
142:
143: private void prepareTagGeneric(RadioTag tag) {
144: TestAction testAction = (TestAction) action;
145: testAction.setFoo("bar");
146: testAction.setList(new String[][] { { "hello", "world" },
147: { "foo", "bar" } });
148: tag.setList("list");
149: tag.setListKey("top[0]");
150: tag.setListValue("top[1]");
151: }
152:
153: }
|