1 18 package org.apache.struts.taglib.html; 19 20 import java.util.Locale ; 21 22 import javax.servlet.jsp.PageContext ; 23 24 import junit.framework.Test; 25 import junit.framework.TestSuite; 26 27 import org.apache.cactus.JspTestCase; 28 import org.apache.struts.Globals; 29 import org.apache.struts.taglib.SimpleBeanForTesting; 30 import org.apache.struts.util.LabelValueBean; 31 32 37 public class TestOptionsTag1 extends JspTestCase { 38 39 40 45 public TestOptionsTag1(String theName) { 46 super(theName); 47 } 48 49 54 public static void main(String [] theArgs) { 55 junit.awtui.TestRunner.main(new String [] {TestOptionsTag1.class.getName()}); 56 } 57 58 62 public static Test suite() { 63 return new TestSuite(TestOptionsTag1.class); 64 } 65 66 private void runTest(String whichTest, String locale) throws Exception { 67 pageContext.setAttribute(Globals.LOCALE_KEY, 68 new Locale (locale, locale), 69 PageContext.SESSION_SCOPE); 70 71 pageContext.setAttribute("runTest", whichTest, PageContext.REQUEST_SCOPE); 72 pageContext.forward("/test/org/apache/struts/taglib/html/TestOptionsTag1.jsp"); 73 } 74 75 private LabelValueBean[] createArrayOfLVB(){ 76 LabelValueBean[] labelValueBeans = new LabelValueBean[5]; 77 for (int i = 0; i < 5; i++){ 78 labelValueBeans[i] = 79 new LabelValueBean("key" + i, "Test Message " + i); 80 } 81 return labelValueBeans; 82 } 83 84 private String [] createArrayofStrings(){ 85 String [] stringValues = new String [5]; 86 for (int i = 0; i < 5; i++){ 87 stringValues[i] = "val" + i; 88 } 89 return stringValues; 90 } 91 92 93 public void testOptionsCollectionArrayItemValueInCollectionProperty() throws Exception { 94 pageContext.setAttribute("arrayOfLVB", createArrayOfLVB(), PageContext.REQUEST_SCOPE); 95 pageContext.setAttribute(Constants.BEAN_KEY, 96 new SimpleBeanForTesting("key1"), PageContext.REQUEST_SCOPE); 97 runTest("testOptionsCollectionArrayItemValueInCollectionProperty", ""); 98 } 99 100 public void testOptionsCollectionArrayItemValueNotInCollectionProperty() throws Exception { 101 pageContext.setAttribute("arrayOfLVB", createArrayOfLVB(), PageContext.REQUEST_SCOPE); 102 pageContext.setAttribute(Constants.BEAN_KEY, 103 new SimpleBeanForTesting("key15"), PageContext.REQUEST_SCOPE); 104 runTest("testOptionsCollectionArrayItemValueNotInCollectionProperty", ""); 105 } 106 107 108 public void testOptionsCollectionArrayItemValueInCollectionPropertyLabelProperty() throws Exception { 109 pageContext.setAttribute("arrayOfLVB", createArrayOfLVB(), PageContext.REQUEST_SCOPE); 110 pageContext.setAttribute(Constants.BEAN_KEY, 111 new SimpleBeanForTesting("key1"), PageContext.REQUEST_SCOPE); 112 runTest("testOptionsCollectionArrayItemValueInCollectionPropertyLabelProperty", ""); 113 } 114 115 public void testOptionsCollectionArrayItemValueNotInCollectionPropertyLabelProperty() throws Exception { 116 pageContext.setAttribute("arrayOfLVB", createArrayOfLVB(), PageContext.REQUEST_SCOPE); 117 pageContext.setAttribute(Constants.BEAN_KEY, 118 new SimpleBeanForTesting("key15"), PageContext.REQUEST_SCOPE); 119 runTest("testOptionsCollectionArrayItemValueNotInCollectionPropertyLabelProperty", ""); 120 } 121 122 123 public void testOptionsNameArrayItemValueInCollection() throws Exception { 124 pageContext.setAttribute("stringValues", createArrayofStrings(), PageContext.REQUEST_SCOPE); 125 pageContext.setAttribute(Constants.BEAN_KEY, 126 new SimpleBeanForTesting("val1"), PageContext.REQUEST_SCOPE); 127 runTest("testOptionsNameArrayItemValueInCollection", ""); 128 } 129 130 public void testOptionsNameArrayItemValueNotInCollection() throws Exception { 131 pageContext.setAttribute("stringValues", createArrayofStrings(), PageContext.REQUEST_SCOPE); 132 pageContext.setAttribute(Constants.BEAN_KEY, 133 new SimpleBeanForTesting("val15"), PageContext.REQUEST_SCOPE); 134 runTest("testOptionsNameArrayItemValueNotInCollection", ""); 135 } 136 137 138 public void testOptionsPropertyArrayItemValueInCollection() throws Exception { 139 SimpleBeanForTesting sbft = new SimpleBeanForTesting("val1"); 140 sbft.setStringArray(createArrayofStrings()); 141 pageContext.setAttribute(Constants.BEAN_KEY, 142 sbft, PageContext.REQUEST_SCOPE); 143 runTest("testOptionsPropertyArrayItemValueInCollection", ""); 144 } 145 146 public void testOptionsPropertyArrayItemValueNotInCollection() throws Exception { 147 SimpleBeanForTesting sbft = new SimpleBeanForTesting("val15"); 148 sbft.setStringArray(createArrayofStrings()); 149 pageContext.setAttribute(Constants.BEAN_KEY, 150 sbft, PageContext.REQUEST_SCOPE); 151 runTest("testOptionsPropertyArrayItemValueNotInCollection", ""); 152 } 153 154 155 public void testOptionsNamePropertyArrayItemValueInCollection() throws Exception { 156 pageContext.setAttribute("stringValues", 157 new SimpleBeanForTesting(createArrayofStrings()), PageContext.REQUEST_SCOPE); 158 pageContext.setAttribute(Constants.BEAN_KEY, 159 new SimpleBeanForTesting("val1"), PageContext.REQUEST_SCOPE); 160 runTest("testOptionsNamePropertyArrayItemValueInCollection", ""); 161 } 162 163 public void testOptionsNamePropertyArrayItemValueNotInCollection() throws Exception { 164 pageContext.setAttribute("stringValues", 165 new SimpleBeanForTesting(createArrayofStrings()), PageContext.REQUEST_SCOPE); 166 pageContext.setAttribute(Constants.BEAN_KEY, 167 new SimpleBeanForTesting("val15"), PageContext.REQUEST_SCOPE); 168 runTest("testOptionsNamePropertyArrayItemValueNotInCollection", ""); 169 } 170 } 171 | Popular Tags |