1 20 package org.apache.cactus.sample.servlet.unit; 21 22 import java.io.IOException ; 23 24 import javax.servlet.RequestDispatcher ; 25 import javax.servlet.ServletException ; 26 27 import org.apache.cactus.ServletTestCase; 28 import org.apache.cactus.WebRequest; 29 import org.apache.cactus.WebResponse; 30 31 36 public class TestRequestDispatcher extends ServletTestCase 37 { 38 44 public void testGetRequestDispatcherFromNamedDispatcherOK() 45 throws ServletException , IOException 46 { 47 RequestDispatcher rd = config.getServletContext().getNamedDispatcher( 48 "TestJsp"); 49 50 assertNotNull("Missing configuration for \"TestJsp\" in web.xml", rd); 51 rd.forward(request, response); 52 } 53 54 61 public void endGetRequestDispatcherFromNamedDispatcherOK( 62 WebResponse theResponse) throws IOException 63 { 64 String result = theResponse.getText(); 65 66 assertTrue("Page not found, got [" + result + "]", 67 result.indexOf("Hello !") > 0); 68 } 69 70 72 79 public void testGetRequestDispatcherFromNamedDispatcherInvalid() 80 throws ServletException , IOException 81 { 82 RequestDispatcher rd = config.getServletContext().getNamedDispatcher( 83 "invalid name"); 84 85 assertNull(rd); 86 } 87 88 90 97 public void testGetRequestDispatcherFromRequest1() 98 throws ServletException , IOException 99 { 100 RequestDispatcher rd = request.getRequestDispatcher("/test/test.jsp"); 101 102 rd.include(request, response); 103 } 104 105 113 public void endGetRequestDispatcherFromRequest1(WebResponse theResponse) 114 throws IOException 115 { 116 String result = theResponse.getText(); 117 118 assertTrue("Page not found, got [" + result + "]", 119 result.indexOf("Hello !") > 0); 120 } 121 122 124 131 public void beginGetRequestDispatcherFromRequest2(WebRequest theRequest) 132 { 133 theRequest.setURL(null, "/test", "/anything.jsp", null, null); 134 } 135 136 143 public void testGetRequestDispatcherFromRequest2() 144 throws ServletException , IOException 145 { 146 RequestDispatcher rd = request.getRequestDispatcher("test/test.jsp"); 147 148 rd.include(request, response); 149 } 150 151 159 public void endGetRequestDispatcherFromRequest2(WebResponse theResponse) 160 throws IOException 161 { 162 String result = theResponse.getText(); 163 164 assertTrue("Page not found, got [" + result + "]", 165 result.indexOf("Hello !") > 0); 166 } 167 168 } 169 | Popular Tags |