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.taglib.TaglibTestBase; 27 28 33 public class TestPageTag extends TaglibTestBase { 34 35 protected final static String PAGETAG_KEY = "PAGETAG_KEY"; 36 protected final static String PAGETAG_VAL = "PAGETAG_VAL"; 37 38 43 public TestPageTag(String theName) { 44 super(theName); 45 } 46 47 52 public static void main(String [] theArgs) { 53 junit.awtui.TestRunner.main(new String [] {TestPageTag.class.getName()}); 54 } 55 56 60 public static Test suite() { 61 return new TestSuite(TestPageTag.class); 63 } 64 65 private void runMyTest(String whichTest) throws Exception { 66 request.setAttribute("runTest", whichTest); 67 pageContext.forward("/test/org/apache/struts/taglib/bean/TestPageTag.jsp"); 68 } 69 70 private void formatAndTest(String compare, String output) { 71 output = replace(output,"\r",""); 73 output = replace(output,"\n",""); 74 output = output.trim(); 75 assertEquals(compare, output); 77 } 78 79 public void testPageTagApplication() throws Exception { 80 pageContext.setAttribute(PAGETAG_KEY, PAGETAG_VAL, PageContext.APPLICATION_SCOPE); 81 runMyTest("testPageTagApplication"); 82 } 83 public void endPageTagApplication(WebResponse response){ 84 formatAndTest(PAGETAG_VAL, response.getText()); 85 } 86 87 public void testPageTagSession() throws Exception { 88 pageContext.setAttribute(PAGETAG_KEY, PAGETAG_VAL, PageContext.SESSION_SCOPE); 89 runMyTest("testPageTagSession"); 90 } 91 public void endPageTagSession(WebResponse response){ 92 formatAndTest(PAGETAG_VAL, response.getText()); 93 } 94 95 public void testPageTagRequest() throws Exception { 96 pageContext.setAttribute(PAGETAG_KEY, PAGETAG_VAL, PageContext.REQUEST_SCOPE); 97 runMyTest("testPageTagRequest"); 98 } 99 public void endPageTagRequest(WebResponse response){ 100 formatAndTest(PAGETAG_VAL, response.getText()); 101 } 102 103 public void testPageTagResponse() throws Exception { 104 pageContext.setAttribute(PAGETAG_KEY, PAGETAG_VAL, PageContext.APPLICATION_SCOPE); 105 runMyTest("testPageTagResponse"); 106 } 107 public void endPageTagResponse(WebResponse response){ 108 formatAndTest(PAGETAG_VAL, response.getText()); 109 } 110 111 public void testPageTagConfig() throws Exception { 112 config.getServletContext().setAttribute(PAGETAG_KEY, PAGETAG_VAL); 113 runMyTest("testPageTagConfig"); 114 } 115 public void endPageTagConfig(WebResponse response){ 116 formatAndTest(PAGETAG_VAL, response.getText()); 117 } 118 119 120 } 121 | Popular Tags |