KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > webwork > views > jsp > ui > SelectTest


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

5 package com.opensymphony.webwork.views.jsp.ui;
6
7 import com.opensymphony.webwork.TestAction;
8 import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
9
10 import java.math.BigDecimal JavaDoc;
11 import java.util.ArrayList JavaDoc;
12 import java.util.Collection JavaDoc;
13 import java.util.List JavaDoc;
14
15
16 /**
17  * @author Matt Ho <a HREF="mailto:matt@enginegreen.com">&lt;matt@enginegreen.com&gt;</a>
18  * @version $Id: SelectTest.java,v 1.23 2005/07/20 15:30:03 plightbo Exp $
19  */

20 public class SelectTest extends AbstractUITagTest {
21     //~ Methods ////////////////////////////////////////////////////////////////
22

23     /** Tests WW-455: Select tag template does not work properly for Object like BigDecimal. */
24     public void testBigDecimal() throws Exception JavaDoc {
25         BigDecimalObject hello = new BigDecimalObject("hello", new BigDecimal JavaDoc(1));
26         BigDecimalObject foo = new BigDecimalObject("foo", new BigDecimal JavaDoc(2));
27
28         TestAction testAction = (TestAction) action;
29
30         Collection JavaDoc collection = new ArrayList JavaDoc(2);
31         // expect strings to be returned, we're still dealing with HTTP here!
32
collection.add("hello");
33         collection.add("foo");
34         testAction.setCollection(collection);
35
36         List JavaDoc list2 = new ArrayList JavaDoc();
37         list2.add(hello);
38         list2.add(foo);
39         list2.add(new BigDecimalObject("<cat>", new BigDecimal JavaDoc(1.500)));
40         testAction.setList2(list2);
41
42         SelectTag tag = new SelectTag();
43         tag.setPageContext(pageContext);
44         tag.setLabel("mylabel");
45         tag.setName("collection");
46         tag.setList("list2");
47         tag.setListKey("name");
48         tag.setListValue("bigDecimal");
49         tag.setMultiple("true");
50         tag.setOnmousedown("alert('onmousedown');");
51         tag.setOnmousemove("alert('onmousemove');");
52         tag.setOnmouseout("alert('onmouseout');");
53         tag.setOnmouseover("alert('onmouseover');");
54         tag.setOnmouseup("alert('onmouseup');");
55
56         tag.doStartTag();
57         tag.doEndTag();
58
59         verify(SelectTag.class.getResource("Select-3.txt"));
60     }
61
62     public class BigDecimalObject {
63         private String JavaDoc name;
64         private BigDecimal JavaDoc bigDecimal;
65
66         public BigDecimalObject(String JavaDoc name, BigDecimal JavaDoc bigDecimal) {
67             this.name = name;
68             this.bigDecimal = bigDecimal;
69         }
70
71         public String JavaDoc getName() {
72             return name;
73         }
74
75         public BigDecimal JavaDoc getBigDecimal() {
76             return bigDecimal;
77         }
78     }
79
80     public void testMultiple() throws Exception JavaDoc {
81         TestAction testAction = (TestAction) action;
82         Collection JavaDoc collection = new ArrayList JavaDoc(2);
83         collection.add("hello");
84         collection.add("foo");
85         testAction.setCollection(collection);
86         testAction.setList(new String JavaDoc[][]{
87             {"hello", "world"},
88             {"foo", "bar"},
89             {"cat", "dog"}
90         });
91
92         SelectTag tag = new SelectTag();
93         tag.setPageContext(pageContext);
94         tag.setLabel("mylabel");
95         tag.setName("collection");
96         tag.setList("list");
97         tag.setListKey("top[0]");
98         tag.setListValue("top[1]");
99         tag.setMultiple("true");
100         tag.setOnmousedown("alert('onmousedown');");
101         tag.setOnmousemove("alert('onmousemove');");
102         tag.setOnmouseout("alert('onmouseout');");
103         tag.setOnmouseover("alert('onmouseover');");
104         tag.setOnmouseup("alert('onmouseup');");
105
106         tag.doStartTag();
107         tag.doEndTag();
108
109         verify(SelectTag.class.getResource("Select-2.txt"));
110     }
111
112     public void testSimple() throws Exception JavaDoc {
113         TestAction testAction = (TestAction) action;
114         testAction.setFoo("hello");
115         testAction.setList(new String JavaDoc[][]{
116             {"hello", "world"},
117             {"foo", "bar"}
118         });
119
120         SelectTag tag = new SelectTag();
121         tag.setPageContext(pageContext);
122         tag.setEmptyOption("true");
123         tag.setLabel("mylabel");
124         tag.setName("foo");
125         tag.setList("list");
126         tag.setListKey("top[0]");
127         tag.setListValue("top[1]");
128
129         // header stuff
130
tag.setHeaderKey("headerKey");
131         tag.setHeaderValue("headerValue");
132
133         // empty option
134
tag.setEmptyOption("true");
135
136         tag.doStartTag();
137         tag.doEndTag();
138
139         verify(SelectTag.class.getResource("Select-1.txt"));
140     }
141 }
142
Popular Tags