1 18 package org.apache.struts.taglib.bean; 19 20 import junit.framework.Test; 21 import junit.framework.TestSuite; 22 23 import org.apache.cactus.WebRequest; 24 import org.apache.cactus.WebResponse; 25 import org.apache.struts.taglib.TaglibTestBase; 26 27 32 public class TestHeaderTag extends TaglibTestBase { 33 34 protected final static String HEADER_KEY = "HEADER_KEY"; 35 protected final static String HEADER_VAL = "HEADER_VAL"; 36 37 42 public TestHeaderTag(String theName) { 43 super(theName); 44 } 45 46 51 public static void main(String [] theArgs) { 52 junit.awtui.TestRunner.main(new String [] {TestHeaderTag.class.getName()}); 53 } 54 55 59 public static Test suite() { 60 return new TestSuite(TestHeaderTag.class); 62 } 63 64 private void runMyTest(String whichTest) throws Exception { 65 request.setAttribute("runTest", whichTest); 66 pageContext.forward("/test/org/apache/struts/taglib/bean/TestHeaderTag.jsp"); 67 } 68 69 private void formatAndTest(String compare, String output) { 70 output = replace(output,"\r",""); 72 output = replace(output,"\n",""); 73 output = output.trim(); 74 assertEquals(compare, output); 75 } 76 77 78 81 public void beginHeaderTagName(WebRequest webRequest) { 82 webRequest.addHeader(HEADER_KEY, HEADER_VAL); 83 webRequest.addParameter("cacheId", "1"); 84 } 85 public void testHeaderTagName() throws Exception { 86 runMyTest("testHeaderTagName"); 87 } 88 public void endHeaderTagName(WebResponse response){ 89 formatAndTest(HEADER_VAL, response.getText()); 90 } 91 92 93 96 public void beginHeaderTagNameMultiple(WebRequest webRequest) { 97 for (int i = 0; i < 10; i++) { 98 webRequest.addHeader(HEADER_KEY, HEADER_VAL + i); 99 } 100 webRequest.addParameter("cacheId", "1"); 101 } 102 public void testHeaderTagNameMultiple() throws Exception { 103 runMyTest("testHeaderTagNameMultiple"); 104 } 105 public void endHeaderTagNameMultiple(WebResponse response){ 106 String compareTo = ""; 107 for (int i = 0; i < 10; i++) { 109 compareTo += HEADER_VAL + i + ","; 110 } 111 compareTo = compareTo.substring(0, compareTo.length() - 1); 113 formatAndTest(compareTo, response.getText()); 114 } 115 116 119 public void beginHeaderTagNameValue(WebRequest webRequest) { 120 webRequest.addParameter("cacheId", "1"); 121 } 122 public void testHeaderTagNameValue() throws Exception { 123 runMyTest("testHeaderTagNameValue"); 124 } 125 public void endHeaderTagNameValue(WebResponse response){ 126 formatAndTest(HEADER_VAL, response.getText()); 127 } 128 129 130 131 132 133 } 134 | Popular Tags |