jeudi 15 octobre 2015

how to know where HttpServletResponse is redirecting?

I'm taking Software Testing because I'm majoring in CS. The professor gave us the source code of a program made in Java to test it. I'm testing right now this method:

    public static void createPanel(HttpServletRequest req, HttpServletResponse res, HttpSession hs) throws IOException
{
    String panelName = req.getParameter("panelName");
    String panelDescription = req.getParameter("panelDescription");
    int employeeID = ((EmployeeProfile)hs.getAttribute("User Profile")).EmployeeID;
    boolean result;

    //Let's validate our fields
    if(panelName.equals("") || panelDescription.equals(""))
        result =  false;
    else
        result = DBManager.createPanel(panelName, panelDescription, employeeID);
    b = result;

    //We'll now display a message indicating the success of the operation to the user
    if(result)
        res.sendRedirect("messagePage?messageCode=Panel has been successfully created.");
    else
        res.sendRedirect("errorPage?errorCode=There was an error creating the panel. Please try again.");

}

I'm using Eclipse with JUnit and mockito to test all the methods including this one. For this specific method, I want to check if the program redirects to one location or another, but I don't know how to do it. Do you have any idea? Thanks.

Aucun commentaire:

Enregistrer un commentaire