
package com.cisco.salesit.tests.ppm.struts;

import java.util.*;
import java.text.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
import java.io.*;
import servletunit.struts.CactusStrutsTestCase;

import junit.framework.*;
import org.apache.log4j.*;
import org.apache.cactus.*;
import com.cisco.salesit.ppm.dataaccessclasses.DBUser;
import com.cisco.salesit.ppm.dataaccessclasses.BusinessEntityDAO;
import com.cisco.salesit.ppm.IConstants;
import com.cisco.salesit.ppm.BusinessEntity;
/**
 * Cactus unit tests for testing exception handling of
 * <code>ServletTestCase</code>.
 *
 * These tests should not really be part of the sample application functional
 * tests as they are unit tests for Cactus. However, they are unit tests that
 * need a servlet environment running for their execution, so they have been
 * package here for convenience. They can also be read by end-users to
 * understand how Cactus work.
 * <br><br>
 * Note : This class extends
 * <code>TestLoginAction_InterceptorServletTestCase</code> (which itself
 * extends <code>ServletTestCase</code>) because we need to be able to verify
 * exception handling in our unit test cases so we must not let these exceptions
 * get through to JUnit (otherwise the test will appear as failed).
 *
 * @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
 *
 * @version $Id: TestLoginAction.java,v 1.5 2001/09/14 20:24:13 pier Exp $
 */
public class TestViewHQDetailsAction
    extends CactusStrutsTestCase
{
	private Category  cat = Category.getInstance(TestViewHQDetailsAction.class.getName());

    /**
     * Defines the testcase name for JUnit.
     *
     * @param theName the testcase's name.
     */
    public TestViewHQDetailsAction(String theName)
    {
        super(theName);
    }

    /**
     * Start the tests.
     *
     * @param theArgs the arguments. Not used
     */
    public static void main(String[] theArgs)
    {
        junit.ui.TestRunner.main(new String[] {
            TestViewHQDetailsAction.class.getName()});
    }

    /**
     * @return a test suite (<code>TestSuite</code>) that includes all methods
     *         starting with "test"
     */
    public static Test suite()
    {
        // All methods starting with "test" will be executed in the test suite.
        return new TestSuite(TestViewHQDetailsAction.class);
    }


	public void beginViewHQDetailsAction(WebRequest theRequest)
		{
			//HttpSession session=theRequest.getSession();


			theRequest.addParameter("BEId","13003");
	        theRequest.addParameter("countryCode","AUSTRIA");


		}
		public void setUp()
		{
			super.setUp();
			DBUser user=new DBUser();
			user.setUserId("ppeault");
			cat.debug("Saving to Session");
			session.setAttribute(IConstants.SESSION.IDBUSER,user);
			try
			{
			BusinessEntityDAO beDAO=new BusinessEntityDAO(request);
			cat.debug("Going for user names");
        	BusinessEntity be=beDAO.getUserNames();
        	be.loadHQLocations(request);
        	cat.debug("Map is "+be.getHQLocationsMap());
			session.setAttribute(IConstants.SESSION.HQLOCATIONSMAP,be.getHQLocationsMap());

			}
			catch(Exception e)
			{
				cat.debug("setUP failed "+e.getMessage());
			}
		}
		public void testViewHQDetailsAction()
		{
				setRequestPathInfo("/viewhqdetails");//?BEId=56860&countryCode=USA");
			    actionPerform();
				verifyForward("success");
				verifyNoActionErrors();
		}
		public void endViewHQDetailsAction(com.meterware.httpunit.WebResponse response)throws Exception
		{
			try
			{

			String title=response.getTitle();
			System.out.println("Title is "+title);
			System.out.println(""+(response.getLinks()).length);
			System.out.println("Charset is "+response.getCharacterSet());
			org.w3c.dom.Document dom=response.getDOM();
			System.out.println("DOM is "+dom.toString());
			//assertEquals("Page has wrong title","View HQ Details",title);
			}
			catch(Exception e)
			{
				System.out.println("Exception in end method "+e.getMessage());
			}
			System.out.println(response.getText());
			System.out.println("Response Object is "+response.toString());

		}
		public void tearDown()
		{
			cat.debug("Tear down running");
		}

}