1 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 ; 11 import java.util.ArrayList ; 12 import java.util.Collection ; 13 import java.util.List ; 14 15 16 20 public class SelectTest extends AbstractUITagTest { 21 23 24 public void testBigDecimal() throws Exception { 25 BigDecimalObject hello = new BigDecimalObject("hello", new BigDecimal (1)); 26 BigDecimalObject foo = new BigDecimalObject("foo", new BigDecimal (2)); 27 28 TestAction testAction = (TestAction) action; 29 30 Collection collection = new ArrayList (2); 31 collection.add("hello"); 33 collection.add("foo"); 34 testAction.setCollection(collection); 35 36 List list2 = new ArrayList (); 37 list2.add(hello); 38 list2.add(foo); 39 list2.add(new BigDecimalObject("<cat>", new BigDecimal (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 name; 64 private BigDecimal bigDecimal; 65 66 public BigDecimalObject(String name, BigDecimal bigDecimal) { 67 this.name = name; 68 this.bigDecimal = bigDecimal; 69 } 70 71 public String getName() { 72 return name; 73 } 74 75 public BigDecimal getBigDecimal() { 76 return bigDecimal; 77 } 78 } 79 80 public void testMultiple() throws Exception { 81 TestAction testAction = (TestAction) action; 82 Collection collection = new ArrayList (2); 83 collection.add("hello"); 84 collection.add("foo"); 85 testAction.setCollection(collection); 86 testAction.setList(new String [][]{ 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 { 113 TestAction testAction = (TestAction) action; 114 testAction.setFoo("hello"); 115 testAction.setList(new String [][]{ 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 tag.setHeaderKey("headerKey"); 131 tag.setHeaderValue("headerValue"); 132 133 tag.setEmptyOption("true"); 135 136 tag.doStartTag(); 137 tag.doEndTag(); 138 139 verify(SelectTag.class.getResource("Select-1.txt")); 140 } 141 } 142 | Popular Tags |