----- Original Message ----- From: "Karthik Kumar" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; "Vincent Massol" <[EMAIL PROTECTED]> Sent: Friday, September 28, 2001 2:21 PM Subject: WebResponse.loadResponseText throws NullPointerException ...
> Hello, > Sorry for my previous mail with the wrong subject. > > I was looking for a server-side testing tool to test my JSP pages, and then > I came across Cactus. First of all, let me tell you Vincent, it is really kool > and simple. I could immediately jump-start on testing my very trivial JSP > pages. cool :) but the full Cactus team is to be thanked, not only myself ... :-) > I encountered a problem when I used the jsp:useBean tag. I don't see the link between the error you're getting and the fact that you're using a jsp:useBean tag ? > I am just pasting a page fragement here. > > FetchEmp.jsp: > > <jsp:useBean id = "empBean" class = "myapp.Employee" scope = "page"/> > <html> > <head><title>Hello World</title></head> > <body> > <tr><td> > <% out.print(empBean.getSalary().toString() ); %> > </tr></td> > </body> > </html> > > > I am using WebLogic v 6.1 . I run the server under default context and this, > JSP has been deployed such a way that we can refer to it as, > > http://localhost:7001/employee/FetchEmp.jsp > > Employee.java: > ============== > > package myapp; > public class Employee { > static int Salary; //Should be double.. > > static { > Salary = 6000; > } > > public static String getSalary() { > return Salary; > } > } > > Now my test case is something like this. > > < --- > > import org.apache.cactus.JspTestCase; > import com.meterware.httpunit.WebTable; > > import java.io.IOException; > import javax.servlet.ServletException; > import org.xml.sax.SAXException; > > public class TestBeanCase extends JspTestCase > { > public TestBeanCase(String theName) > { > super(theName); > } > > > public void testOut() throws IOException, ServletException > { > pageContext.forward("/employee/FetchEmp.jsp"); > } > > public void endOut(com.meterware.httpunit.WebResponse resp) > throws IOException , ServletException, > ParserConfigurationException, > SAXException { > System.out.println( resp.getText() ); > } > } > everything seems correct so far ... > ------- -------------------- > When I run the JUnit task I get, > > java.lang.NullPointerException > > at com.meterware.httpunit.WebResponse.loadResponseText(WebResponse.java:472) > at com.meterware.httpunit.WebResponse.getText(WebResponse.java:186) > at TestBeanCase.endOut(TestBeanCase.java:50) > at org.apache.cactus.AbstractTestCase.callEndMethod(AbstractTestCase.java:304) > at org.apache.cactus.AbstractTestCase.runGenericTest(AbstractTestCase.java:425) > at org.apache.cactus.JspTestCase.runTest(JspTestCase.java:107) > at org.apache.cactus.AbstractTestCase.runBare(AbstractTestCase.java:371) > > Actually the line, > TestBeanCase.java : 50 is > > System.out.println( resp.getText() ); > > mentioned above. > > Can anybody help me? hum ... This might well be a bug ... it has the smell of it at least ... I have made a big mistake when doing HttpUnit integration and I should have known better .... I have not written any functional test sample. I wanted to write a few tests and I didn't rigth away because it would have meant distributing them to the Cactus sample application and there are users who do not want to use HttpUnit and they shouldn't be bothered to have to download the HttpUnit jars ... Basically I postponed the writing of theses tests till I had improved the build mechanism so that not all Cactus tests would be packaged as part of the sample application or until I had found another way of doing it, like offering several sample applications for different needs. We still need to think about that. And of course, the writing of test cases for HttpUnit then slipped out of my mind ... and now I pay the price ... :) I have to try it on my computer. Give me one day and I'll get back to you and include the needed tests so that it does not happen again (if it is a bug). In the meantime, if you simply want to get the returned text (but I guessed if you used HttpUnit that was to do more complex stuff), use : public void endOut(org.apache.cactus.WebResponse resp) throws IOException { System.out.println( resp.getText() ); } > > Thanks. > Karthik Kumar. > thanks -Vincent
