HI,

we are new to cactus and have installed cactus in our system using the steps mentioned 
in the link



http://approximity.com/testing/cactus.html



we have set the classs path as mentioned in the link

our class path came to be like this after we made modifications



c:\iic\web2mart\WEB-INF\lib\cactus.jar;c:\iic\web2mart\WEB-INF\lib\junit.jar;c:\tomcat\lib;c:\tomcat\lib\common\servlet.jar;c:\jdk1.3.1\jre\lib\rt.jar;.;c:\jdk1.3.1\jre\lib\ext;c:\tomcat\webapps\root\Web-inf\classes;c:\tomcat\lib\JSQLConnect.jar;



we have also changed our web.xml file as mentioned in the link



we have written a simple servlet called SimpleServlet which is as follows and we are 
ableto compile this servlet



import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;



public class SimpleServlet extends HttpServlet
{
  public void doGet(HttpServletRequest theRequest, HttpServletResponse theResponse)
    throws IOException
 {
    PrintWriter pw = theResponse.getWriter();
    theResponse.setContentType("text/html");
    pw.print("<html><head/><body><h1>Your name is " + 
    registerUser(theRequest, theResponse) + "</h1></body></html>");
 }



 public String registerUser(HttpServletRequest theRequest, HttpServletResponse 
theResponse)
 {
   // Get the user name from the HTTP request's parameter
   String name = theRequest.getParameter("USER_NAME");
   // Save it in the session
   HttpSession session = theRequest.getSession();
   session.putValue("NAME", name);



   // And return a cookie
   Cookie cookie = new Cookie("ID", name);
  theResponse.addCookie(cookie);



  return name;
 }
}



but we are not able to compile the Servlet that is given below





//import org.apache.commons.cactus.*;
//import org.apache.commons.cactus.util.*;
import org.apache.cactus.*;
import junit.framework.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.net.*;



public class TestSimpleServlet extends ServletTestCase
{
 //standard JUnit code.



  /**
   * Sets the HTTP request parameter that will be available in the test
   * method.
   */
  public void beginRegisterUser(ServletTestRequest theRequest)
  {
    theRequest.addParameter("USER_NAME", "Vincent");
  }



  /**
   * Unit test the registerUSer method.
   */
  public void testRegisterUser()
  {
    // Instantiate the class to test
    SimpleServlet servlet = new SimpleServlet();
    // Call the method to test
    String name = servlet.registerUser(request, response);
    // Verify that it returns the correct name
    assertEquals("Vincent", name);
    // Verify that the name has been put in the session
    assertEquals("Vincent", (String)session.getValue("NAME"));
  }



 /**
  * Verify that a cookie has been returned
  */
  public void endRegisterUser(HttpURLConnection theConnection)
  {
    Hashtable cookies = AssertUtils.getCookies(theConnection);
    Vector list = (Vector)cookies.get("ID");
    assert(list.size() == 1);



    ClientCookie cookie = (ClientCookie)list.elementAt(0);
    assertEquals("ID", cookie.getName());
    assertEquals("Vincent", cookie.getValue());
  }



 /**
  * Test the output stream returned by the <code>doGet()</code> method.
  */
  public void testDoGet()
  {
    SimpleServlet servlet = new SimpleServlet();
    servlet.doGet(request, response);
  }



 /**
  * Test the output stream returned by the <code>doGet()</code> method.
  */
  public void endDoGet(HttpURLConnection theConnection)
  {
   assertEquals("<html><head/><body><h1>Your name is Vincent</h1></body></html>",
   AssertUtils.getResponseAsString(theConnection));
  }
}



when we compile this code we are getting the following errors





C:\iic\web2mart\test\TestSimpleServlet.java:11: cannot resolve symbol
symbol  : constructor ServletTestCase  ()
location: class org.apache.cactus.ServletTestCase
public class TestSimpleServlet extends ServletTestCase
       ^
C:\iic\web2mart\test\TestSimpleServlet.java:44: cannot resolve symbol
symbol  : variable AssertUtils  
location: class TestSimpleServlet
    Hashtable cookies = AssertUtils.getCookies(theConnection);
                        ^
C:\iic\web2mart\test\TestSimpleServlet.java:48: cannot resolve symbol
symbol  : class ClientCookie  
location: class TestSimpleServlet
    ClientCookie cookie = (ClientCookie)list.elementAt(0);
    ^
C:\iic\web2mart\test\TestSimpleServlet.java:48: cannot resolve symbol
symbol  : class ClientCookie  
location: class TestSimpleServlet
    ClientCookie cookie = (ClientCookie)list.elementAt(0);
                           ^
C:\iic\web2mart\test\TestSimpleServlet.java:68: cannot resolve symbol
symbol  : variable AssertUtils  
location: class TestSimpleServlet
   AssertUtils.getResponseAsString(theConnection));
   ^
Note: C:\iic\web2mart\test\TestSimpleServlet.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
5 errors



Tool completed with exit code 1



Sir in this regard can you please guide us in detail as in  which diectory we will 
have to place the test servlets

and also on how to run our first tests



Thanking you

Regards

Krishna Prasad Kakaumanu

Reply via email to