Hi Scott, I've just spent about half an hour trying to decide if you had found a bug... :-) The answer is no...
Simply replace getAttributeNames() by getParameterNames() -Vincent > -----Original Message----- > From: Parmley, Scott C. [mailto:[EMAIL PROTECTED] > Sent: 01 July 2003 19:21 > To: [EMAIL PROTECTED] > Subject: RequestDispatcher question > > Hello everyone, > > I have a question reguarding testing XSP pages. My test scenerio is this: > > 1. Submit some login data to an XSP page whose URI is "/myapp/login". > 2. Test that a login was successful by looking for an attribute called > "LoginConfig" in HttpSession. > 3. Fail/Succeed test if session attribute is present. > > > The test I have written extends ServletTestCase is recommended by the > Cactus documentation. The problem I am running into is it seems as though > "request" is not populated with the request data the redirectory proxy > recieved via WebRequest. > The forward from RequestDispatcher doesn't seem > to work here. The "request" object being passed into the dispatcher is > empty from what I can tell, and in addition, I am not convinced that > RequestDispatcher is actually forwarding to the given URI. Am I missing > something obvious here? I have included a sample of code below. > > Thanks in advance, > -Scott > > > [...] > public class LoginTest extends ServletTestCase { > private RequestDispatcher rdis; > > public LoginTest(String testName) { > super(testName); > } > > public static Test suite() { > return new TestSuite(LoginTest.class); > } > > public static void main(String[] args) { > TestRunner.main(new String[]{LoginTest.class.getName()}); > } > > public void beginLogin(WebRequest theRequest) { > theRequest.addParameter("host","Demo"); > theRequest.addParameter("username","someuser"); > theRequest.addParameter("password","XXXX"); > System.out.println("Completed pre-login phase."); > } > > public void testLogin() { > try { > if(config == null) { > System.out.println("Servlet not initialized! config(null)"); > } > if(config.getServletContext() == null) { > System.out.println("Context is null!"); > } > if(config.getServletContext().getRequestDispatcher("/myapp/login") > == null) { > System.out.println("RequestDispatcher is null or not valid!"); > } > > rdis = > config.getServletContext().getRequestDispatcher("/myapp/login"); > System.out.println("RequestDispatcher setup complete."); > > System.out.println("Reading request."); > Enumeration rattributes = request.getAttributeNames(); > while(rattributes.hasMoreElements()){ > System.out.println("Request Attribute: > "+rattributes.nextElement()); > } > > > //request is empty!// > rdis.forward(request, response); > System.out.println("Forward finished."); > > System.out.println("Testing assertion."); > System.out.println("SESSION ID: "+session.getId()); > > assertNotNull(session.getAttribute("LoginConfig")); > } > catch(IOException e) { > e.printStackTrace(); > } > catch(ServletException e) { > e.printStackTrace(); > } > } > } > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
