You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by "Parmley, Scott C." <sp...@p2es.com> on 2003/06/17 17:31:02 UTC
Configuration Problem?
Hello Everyone.
I've run into a problem involving Cactus tests and JSPs. First,
let
me supply you with the scenerio:
I have a multitiered server/client application with Cocoon XSP
documents
as an interface to the EJB/Business logic tier. I have written a
Cactus
test case that is designed to perform a login and logout procedure. I
am
using the Cocoon security facility to test if a client has an
HttpSession
and if there is a particular value in that session.
So, my test needs to be able to log a user in, check that the login
succeeded by checking out the session attribute mentioned above, and
finally to log the user out, which is dependent on a valid session.
If
the login succeeds, then the session attribute "LoginConfig" is set.
Here is my dilema. I have created a RequestDispatcher to forward my
request to the appropriate URL. I forward the request. Then I test
for
the session attribute "LoginConfig". I always recieve a null pointer
exception when trying to look at session. I am certain that this
process
works, and I picked a userid and password that always succeeds.
Is there a wrapper or method I can use to grab the session and perform
this test? Sorry if this question is very elementary. See my source
below:
Thank you in advance.
-Scott Parmley
[...]
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 myrequest) {
myrequest.addParameter("host","SomeHost");
myrequest.addParameter("username","SomeUser");
myrequest.addParameter("password","SomePassword");
System.out.println("Completed pre-login phase.");
}
public void testLogin() {
try {
RequestDispatcher rdis =
config.getServletContext().getRequestDispatcher("/myurl/do-login");
System.out.println("RequestDispatcher setup complete.");
rdis.forward(request, response);
System.out.println("Forward finished.");
System.out.println("Testing assertion.");
// This fails every time. //
assertNotNull(session.getAttribute("LoginConfig"));
}
catch(IOException e) {
e.printStackTrace();
}
catch(ServletException e) {
e.printStackTrace();
}
}
[...]