001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp.ui;
006:
007: import com.opensymphony.webwork.TestAction;
008: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
009:
010: import java.util.HashMap;
011: import java.util.LinkedHashMap;
012:
013: /**
014: * @author Matt Ho <a href="mailto:matt@enginegreen.com"><matt@enginegreen.com></a>
015: * @version $Id: RadioTest.java 2731 2006-11-07 16:51:39Z tmjee $
016: */
017: public class RadioTest extends AbstractUITagTest {
018:
019: public void testMapWithBooleanAsKey() throws Exception {
020: TestAction testAction = (TestAction) action;
021:
022: HashMap map = new LinkedHashMap();
023: map.put(Boolean.TRUE, "male");
024: map.put(Boolean.FALSE, "female");
025: testAction.setMap(map);
026:
027: RadioTag tag = new RadioTag();
028: tag.setPageContext(pageContext);
029: tag.setLabel("mylabel");
030: tag.setName("myname");
031: tag.setValue("%{true}");
032: tag.setList("map");
033:
034: tag.doStartTag();
035: tag.doEndTag();
036:
037: verify(RadioTag.class.getResource("Radio-3.txt"));
038: }
039:
040: public void testMapChecked() throws Exception {
041: TestAction testAction = (TestAction) action;
042: testAction.setFoo("bar");
043:
044: HashMap map = new HashMap();
045: map.put("1", "One");
046: map.put("2", "Two");
047: testAction.setMap(map);
048:
049: RadioTag tag = new RadioTag();
050: tag.setPageContext(pageContext);
051: tag.setLabel("mylabel");
052: tag.setName("myname");
053: tag.setValue("\"1\"");
054: tag.setList("map");
055: tag.setListKey("key");
056: tag.setListValue("value");
057:
058: tag.doStartTag();
059: tag.doEndTag();
060:
061: verify(RadioTag.class.getResource("Radio-2.txt"));
062: }
063:
064: public void testSimple() throws Exception {
065: TestAction testAction = (TestAction) action;
066: testAction.setFoo("bar");
067: testAction.setList(new String[][] { { "hello", "world" },
068: { "foo", "bar" } });
069:
070: RadioTag tag = new RadioTag();
071: tag.setPageContext(pageContext);
072: tag.setLabel("mylabel");
073: tag.setName("myname");
074: tag.setValue("");
075: tag.setList("list");
076: tag.setListKey("top[0]");
077: tag.setListValue("top[1]");
078:
079: tag.doStartTag();
080: tag.doEndTag();
081:
082: verify(RadioTag.class.getResource("Radio-1.txt"));
083: }
084:
085: public void testGenericSimple() throws Exception {
086: RadioTag tag = new RadioTag();
087: prepareTagGeneric(tag);
088: verifyGenericProperties(tag, "simple", new String[] { "id",
089: "value" });
090: }
091:
092: public void testGenericXhtml() throws Exception {
093: RadioTag tag = new RadioTag();
094: prepareTagGeneric(tag);
095: verifyGenericProperties(tag, "xhtml", new String[] { "id",
096: "value" });
097: }
098:
099: public void testGenericAjax() throws Exception {
100: RadioTag tag = new RadioTag();
101: prepareTagGeneric(tag);
102: verifyGenericProperties(tag, "ajax", new String[] { "id",
103: "value" });
104: }
105:
106: private void prepareTagGeneric(RadioTag tag) {
107: TestAction testAction = (TestAction) action;
108: testAction.setFoo("bar");
109: testAction.setList(new String[][] { { "hello", "world" },
110: { "foo", "bar" } });
111: tag.setList("list");
112: tag.setListKey("top[0]");
113: tag.setListValue("top[1]");
114: }
115:
116: }
|