Hi , I have a simple servlet file.I want to build a Junit test case.
When i create a junit test file using ecplise i will get some
methods.But i dont know what exactly code should be there in that.
This is my servlet file
package com.glan.login;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class LoginSuccess extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/
html;charset=UTF-8");
String uname=request.getParameter("user");
String upass=request.getParameter("pass");
if(uname.equals("admin")&& upass.equals("admin")){
request.getRequestDispatcher("loginSuccess.jsp").forward(request,
response);
}
else{
request.setAttribute("errormessage", "Sorry !!!
Invalid Credentials.");
request.getRequestDispatcher("index.jsp").forward(request, response);
}
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
System.out.println("**************** Servlet called.");
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
This is test file genetated.
package com.glan.login;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
/**
* @author
*
*/
public class LoginSuccessTest {
private LoginSuccess success;
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@AfterClass
public static void tearDownAfterClass() throws Exception {
}
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
success=new LoginSuccess();
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
}
}
please help me with this test case file