1 18 package org.apache.struts.taglib.bean; 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.WebResponse; 28 import org.apache.struts.Globals; 29 import org.apache.struts.taglib.SimpleBeanForTesting; 30 import org.apache.struts.taglib.TaglibTestBase; 31 32 43 public class TestMessageTag extends TaglibTestBase { 44 45 protected final static String TEST_KEY = "BeanKey"; 46 protected final static String TEST_VAL = "Testing Message"; 47 48 public TestMessageTag(String theName) { 49 super(theName); 50 } 51 52 57 public static void main(String [] theArgs) { 58 junit.awtui.TestRunner.main(new String [] {TestMessageTag.class.getName()}); 59 } 60 61 65 public static Test suite() { 66 return new TestSuite(TestMessageTag.class); 68 } 69 70 private void runMyTest(String whichTest, Locale locale) throws Exception { 71 pageContext.setAttribute(Globals.LOCALE_KEY, locale, PageContext.SESSION_SCOPE); 72 request.setAttribute("runTest", whichTest); 73 pageContext.forward("/test/org/apache/struts/taglib/bean/TestMessageTag.jsp"); 74 } 75 76 private void formatAndTest(String compare, String output) { 77 output = replace(output,"\r",""); 79 output = replace(output,"\n",""); 80 output = output.trim(); 81 assertEquals(compare, output); 83 } 84 85 94 95 96 public void testMessageTagNoArgKeyNoScopeDefaultBundle() throws Exception { 97 runMyTest("testMessageTagNoArgKeyNoScopeDefaultBundle", new Locale ("","")); 98 } 99 public void endMessageTagNoArgKeyNoScopeDefaultBundle(WebResponse response){ 100 formatAndTest(TEST_VAL, response.getText()); 101 } 102 103 public void testMessageTagNoArgKeyApplicationScopeDefaultBundle() throws Exception { 104 runMyTest("testMessageTagNoArgKeyApplicationScopeDefaultBundle", new Locale ("","")); 105 } 106 public void endMessageTagNoArgKeyApplicationScopeDefaultBundle(WebResponse response){ 107 formatAndTest(TEST_VAL, response.getText()); 108 } 109 110 public void testMessageTagNoArgKeySessionScopeDefaultBundle() throws Exception { 111 runMyTest("testMessageTagNoArgKeySessionScopeDefaultBundle", new Locale ("","")); 112 } 113 public void endMessageTagNoArgKeySessionScopeDefaultBundle(WebResponse response){ 114 formatAndTest(TEST_VAL, response.getText()); 115 } 116 117 public void testMessageTagNoArgKeyRequestScopeDefaultBundle() throws Exception { 118 runMyTest("testMessageTagNoArgKeyRequestScopeDefaultBundle", new Locale ("","")); 119 } 120 public void endMessageTagNoArgKeyRequestScopeDefaultBundle(WebResponse response){ 121 formatAndTest(TEST_VAL, response.getText()); 122 } 123 124 125 public void testMessageTagNoArgKeyNoScopeAlternateBundle() throws Exception { 126 runMyTest("testMessageTagNoArgKeyNoScopeAlternateBundle", new Locale ("","")); 127 } 128 public void endMessageTagNoArgKeyNoScopeAlternateBundle(WebResponse response){ 129 formatAndTest(TEST_VAL, response.getText()); 130 } 131 132 public void testMessageTagNoArgKeyApplicationScopeAlternateBundle() throws Exception { 133 runMyTest("testMessageTagNoArgKeyApplicationScopeAlternateBundle", new Locale ("","")); 134 } 135 public void endMessageTagNoArgKeyApplicationScopeAlternateBundle(WebResponse response){ 136 formatAndTest(TEST_VAL, response.getText()); 137 } 138 139 public void testMessageTagNoArgKeySessionScopeAlternateBundle() throws Exception { 140 runMyTest("testMessageTagNoArgKeySessionScopeAlternateBundle", new Locale ("","")); 141 } 142 public void endMessageTagNoArgKeySessionScopeAlternateBundle(WebResponse response){ 143 formatAndTest(TEST_VAL, response.getText()); 144 } 145 146 public void testMessageTagNoArgKeyRequestScopeAlternateBundle() throws Exception { 147 runMyTest("testMessageTagNoArgKeyRequestScopeAlternateBundle", new Locale ("","")); 148 } 149 public void endMessageTagNoArgKeyRequestScopeAlternateBundle(WebResponse response){ 150 formatAndTest(TEST_VAL, response.getText()); 151 } 152 153 154 155 public void testMessageTagNoArgNameNoScopeDefaultBundle() throws Exception { 156 runMyTest("testMessageTagNoArgNameNoScopeDefaultBundle", new Locale ("","")); 157 } 158 public void endMessageTagNoArgNameNoScopeDefaultBundle(WebResponse response){ 159 formatAndTest(TEST_VAL, response.getText()); 160 } 161 162 public void testMessageTagNoArgNameApplicationScopeDefaultBundle() throws Exception { 163 runMyTest("testMessageTagNoArgNameApplicationScopeDefaultBundle", new Locale ("","")); 164 } 165 public void endMessageTagNoArgNameApplicationScopeDefaultBundle(WebResponse response){ 166 formatAndTest(TEST_VAL, response.getText()); 167 } 168 169 public void testMessageTagNoArgNameSessionScopeDefaultBundle() throws Exception { 170 runMyTest("testMessageTagNoArgNameSessionScopeDefaultBundle", new Locale ("","")); 171 } 172 public void endMessageTagNoArgNameSessionScopeDefaultBundle(WebResponse response){ 173 formatAndTest(TEST_VAL, response.getText()); 174 } 175 176 public void testMessageTagNoArgNameRequestScopeDefaultBundle() throws Exception { 177 runMyTest("testMessageTagNoArgNameRequestScopeDefaultBundle", new Locale ("","")); 178 } 179 public void endMessageTagNoArgNameRequestScopeDefaultBundle(WebResponse response){ 180 formatAndTest(TEST_VAL, response.getText()); 181 } 182 183 184 public void testMessageTagNoArgNameNoScopeAlternateBundle() throws Exception { 185 runMyTest("testMessageTagNoArgNameNoScopeAlternateBundle", new Locale ("","")); 186 } 187 public void endMessageTagNoArgNameNoScopeAlternateBundle(WebResponse response){ 188 formatAndTest(TEST_VAL, response.getText()); 189 } 190 191 public void testMessageTagNoArgNameApplicationScopeAlternateBundle() throws Exception { 192 runMyTest("testMessageTagNoArgNameApplicationScopeAlternateBundle", new Locale ("","")); 193 } 194 public void endMessageTagNoArgNameApplicationScopeAlternateBundle(WebResponse response){ 195 formatAndTest(TEST_VAL, response.getText()); 196 } 197 198 public void testMessageTagNoArgNameSessionScopeAlternateBundle() throws Exception { 199 runMyTest("testMessageTagNoArgNameSessionScopeAlternateBundle", new Locale ("","")); 200 } 201 public void endMessageTagNoArgNameSessionScopeAlternateBundle(WebResponse response){ 202 formatAndTest(TEST_VAL, response.getText()); 203 } 204 205 public void testMessageTagNoArgNameRequestScopeAlternateBundle() throws Exception { 206 runMyTest("testMessageTagNoArgNameRequestScopeAlternateBundle", new Locale ("","")); 207 } 208 public void endMessageTagNoArgNameRequestScopeAlternateBundle(WebResponse response){ 209 formatAndTest(TEST_VAL, response.getText()); 210 } 211 212 213 214 215 public void testMessageTagNoArgNamePropertyNoScopeDefaultBundle() throws Exception { 216 pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message"), PageContext.REQUEST_SCOPE); 217 runMyTest("testMessageTagNoArgNamePropertyNoScopeDefaultBundle", new Locale ("","")); 218 } 219 public void endMessageTagNoArgNamePropertyNoScopeDefaultBundle(WebResponse response){ 220 formatAndTest(TEST_VAL, response.getText()); 221 } 222 223 public void testMessageTagNoArgNamePropertyApplicationScopeDefaultBundle() throws Exception { 224 pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message"), PageContext.APPLICATION_SCOPE); 225 runMyTest("testMessageTagNoArgNamePropertyApplicationScopeDefaultBundle", new Locale ("","")); 226 } 227 public void endMessageTagNoArgNamePropertyApplicationScopeDefaultBundle(WebResponse response){ 228 formatAndTest(TEST_VAL, response.getText()); 229 } 230 231 public void testMessageTagNoArgNamePropertySessionScopeDefaultBundle() throws Exception { 232 pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message"), PageContext.SESSION_SCOPE); 233 runMyTest("testMessageTagNoArgNamePropertySessionScopeDefaultBundle", new Locale ("","")); 234 } 235 public void endMessageTagNoArgNamePropertySessionScopeDefaultBundle(WebResponse response){ 236 formatAndTest(TEST_VAL, response.getText()); 237 } 238 239 public void testMessageTagNoArgNamePropertyRequestScopeDefaultBundle() throws Exception { 240 pageContext.setAttribute("key", new SimpleBeanForTesting("default.bundle.message"), PageContext.REQUEST_SCOPE); 241 runMyTest("testMessageTagNoArgNamePropertyRequestScopeDefaultBundle", new Locale ("","")); 242 } 243 public void endMessageTagNoArgNamePropertyRequestScopeDefaultBundle(WebResponse response){ 244 formatAndTest(TEST_VAL, response.getText()); 245 } 246 247 248 public void testMessageTagNoArgNamePropertyNoScopeAlternateBundle() throws Exception { 249 pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message"), PageContext.REQUEST_SCOPE); 250 runMyTest("testMessageTagNoArgNamePropertyNoScopeAlternateBundle", new Locale ("","")); 251 } 252 public void endMessageTagNoArgNamePropertyNoScopeAlternateBundle(WebResponse response){ 253 formatAndTest(TEST_VAL, response.getText()); 254 } 255 256 public void testMessageTagNoArgNamePropertyApplicationScopeAlternateBundle() throws Exception { 257 pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message"), PageContext.APPLICATION_SCOPE); 258 runMyTest("testMessageTagNoArgNamePropertyApplicationScopeAlternateBundle", new Locale ("","")); 259 } 260 public void endMessageTagNoArgNamePropertyApplicationScopeAlternateBundle(WebResponse response){ 261 formatAndTest(TEST_VAL, response.getText()); 262 } 263 264 public void testMessageTagNoArgNamePropertySessionScopeAlternateBundle() throws Exception { 265 pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message"), PageContext.SESSION_SCOPE); 266 runMyTest("testMessageTagNoArgNamePropertySessionScopeAlternateBundle", new Locale ("","")); 267 } 268 public void endMessageTagNoArgNamePropertySessionScopeAlternateBundle(WebResponse response){ 269 formatAndTest(TEST_VAL, response.getText()); 270 } 271 272 public void testMessageTagNoArgNamePropertyRequestScopeAlternateBundle() throws Exception { 273 pageContext.setAttribute("key", new SimpleBeanForTesting("alternate.bundle.message"), PageContext.REQUEST_SCOPE); 274 runMyTest("testMessageTagNoArgNamePropertyRequestScopeAlternateBundle", new Locale ("","")); 275 } 276 public void endMessageTagNoArgNamePropertyRequestScopeAlternateBundle(WebResponse response){ 277 formatAndTest(TEST_VAL, response.getText()); 278 } 279 280 281 282 283 284 285 286 287 } 288 | Popular Tags |