1 18 package org.apache.struts.taglib.bean; 19 20 import javax.servlet.jsp.PageContext ; 21 22 import junit.framework.Test; 23 import junit.framework.TestSuite; 24 25 import org.apache.cactus.WebResponse; 26 import org.apache.struts.util.LabelValueBean; 27 import org.apache.struts.taglib.TaglibTestBase; 28 29 34 public class TestDefineTag extends TaglibTestBase { 35 36 protected final static String TEST_KEY = "TestDefineTag"; 37 protected final static String TEST_VALUE = "Test Value"; 38 39 44 public TestDefineTag(String theName) { 45 super(theName); 46 } 47 48 53 public static void main(String [] theArgs) { 54 junit.awtui.TestRunner.main(new String [] {TestDefineTag.class.getName()}); 55 } 56 57 61 public static Test suite() { 62 return new TestSuite(TestDefineTag.class); 64 } 65 66 private void runMyTest(String whichTest) throws Exception { 67 request.setAttribute("runTest", whichTest); 68 pageContext.forward("/test/org/apache/struts/taglib/bean/TestDefineTag.jsp"); 69 } 70 71 private void formatAndTest(String compare, String output) { 72 output = replace(output,"\r",""); 74 output = replace(output,"\n",""); 75 output = output.trim(); 76 assertEquals(compare, output); 77 } 78 79 82 public void testDefineNameApplicationScope() throws Exception { 83 pageContext.setAttribute(TEST_KEY, TEST_VALUE, PageContext.APPLICATION_SCOPE); 84 runMyTest("testDefineNameApplicationScope"); 85 } 86 public void endDefineNameApplicationScope(WebResponse response){ 87 formatAndTest(TEST_VALUE, response.getText()); 88 } 89 90 public void testDefineNamePropertyApplicationScope() throws Exception { 91 LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE); 92 pageContext.setAttribute(TEST_KEY, lvb, PageContext.APPLICATION_SCOPE); 93 runMyTest("testDefineNamePropertyApplicationScope"); 94 } 95 public void endDefineNamePropertyApplicationScope(WebResponse response){ 96 formatAndTest(TEST_VALUE, response.getText()); 97 } 98 99 public void testDefineValueApplicationScope() throws Exception { 100 LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE + " this will be set to the correct value"); 101 pageContext.setAttribute(TEST_KEY, lvb, PageContext.APPLICATION_SCOPE); 102 runMyTest("testDefineValueApplicationScope"); 103 } 104 public void endDefineValueApplicationScope(WebResponse response){ 105 formatAndTest(TEST_VALUE, response.getText()); 106 } 107 108 public void testDefineBodyApplicationScope() throws Exception { 109 runMyTest("testDefineBodyApplicationScope"); 110 } 111 public void endDefineBodyApplicationScope(WebResponse response){ 112 formatAndTest(TEST_VALUE, response.getText()); 113 } 114 115 116 119 public void testDefineNameSessionScope() throws Exception { 120 pageContext.setAttribute(TEST_KEY, TEST_VALUE, PageContext.SESSION_SCOPE); 121 runMyTest("testDefineNameSessionScope"); 122 } 123 public void endDefineNameSessionScope(WebResponse response){ 124 formatAndTest(TEST_VALUE, response.getText()); 125 } 126 127 public void testDefineNamePropertySessionScope() throws Exception { 128 LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE); 129 pageContext.setAttribute(TEST_KEY, lvb, PageContext.SESSION_SCOPE); 130 runMyTest("testDefineNamePropertySessionScope"); 131 } 132 public void endDefineNamePropertySessionScope(WebResponse response){ 133 formatAndTest(TEST_VALUE, response.getText()); 134 } 135 136 public void testDefineValueSessionScope() throws Exception { 137 LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE + " this will be set to the correct value"); 138 pageContext.setAttribute(TEST_KEY, lvb, PageContext.SESSION_SCOPE); 139 runMyTest("testDefineValueSessionScope"); 140 } 141 public void endDefineValueSessionScope(WebResponse response){ 142 formatAndTest(TEST_VALUE, response.getText()); 143 } 144 145 public void testDefineBodySessionScope() throws Exception { 146 runMyTest("testDefineBodySessionScope"); 147 } 148 public void endDefineBodySessionScope(WebResponse response){ 149 formatAndTest(TEST_VALUE, response.getText()); 150 } 151 152 155 public void testDefineNameRequestScope() throws Exception { 156 pageContext.setAttribute(TEST_KEY, TEST_VALUE, PageContext.REQUEST_SCOPE); 157 runMyTest("testDefineNameRequestScope"); 158 } 159 public void endDefineNameRequestScope(WebResponse response){ 160 formatAndTest(TEST_VALUE, response.getText()); 161 } 162 163 public void testDefineNamePropertyRequestScope() throws Exception { 164 LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE); 165 pageContext.setAttribute(TEST_KEY, lvb, PageContext.REQUEST_SCOPE); 166 runMyTest("testDefineNamePropertyRequestScope"); 167 } 168 public void endDefineNamePropertyRequestScope(WebResponse response){ 169 formatAndTest(TEST_VALUE, response.getText()); 170 } 171 172 public void testDefineValueRequestScope() throws Exception { 173 LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE + " this will be set to the correct value"); 174 pageContext.setAttribute(TEST_KEY, lvb, PageContext.REQUEST_SCOPE); 175 runMyTest("testDefineValueRequestScope"); 176 } 177 public void endDefineValueRequestScope(WebResponse response){ 178 formatAndTest(TEST_VALUE, response.getText()); 179 } 180 181 public void testDefineBodyRequestScope() throws Exception { 182 runMyTest("testDefineBodyRequestScope"); 183 } 184 public void endDefineBodyRequestScope(WebResponse response){ 185 formatAndTest(TEST_VALUE, response.getText()); 186 } 187 188 191 public void testDefineNameNoScope() throws Exception { 192 request.setAttribute(TEST_KEY, TEST_VALUE); 193 runMyTest("testDefineNameNoScope"); 194 } 195 public void endDefineNameNoScope(WebResponse response){ 196 formatAndTest(TEST_VALUE, response.getText()); 197 } 198 199 public void testDefineNamePropertyNoScope() throws Exception { 200 LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE); 201 request.setAttribute(TEST_KEY, lvb); 202 runMyTest("testDefineNamePropertyNoScope"); 203 } 204 public void endDefineNamePropertyNoScope(WebResponse response){ 205 formatAndTest(TEST_VALUE, response.getText()); 206 } 207 208 public void testDefineValueNoScope() throws Exception { 209 LabelValueBean lvb = new LabelValueBean("key", TEST_VALUE + " this will be set to the correct value"); 210 request.setAttribute(TEST_KEY, lvb); 211 runMyTest("testDefineValueNoScope"); 212 } 213 public void endDefineValueNoScope(WebResponse response){ 214 formatAndTest(TEST_VALUE, response.getText()); 215 } 216 217 public void testDefineBodyNoScope() throws Exception { 218 runMyTest("testDefineBodyNoScope"); 219 } 220 public void endDefineBodyNoScope(WebResponse response){ 221 formatAndTest(TEST_VALUE, response.getText()); 222 } 223 224 225 226 227 } 228 | Popular Tags |