You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by MSD <ms...@rediffmail.com> on 2008/07/01 12:12:43 UTC

Servlet test case is returning Null all the time

Hi 

   I am new to cactus. Currently running the cactus test cases with the ant
build scripts... I am using JBoss as application server...

  I have written couple of  cactus test cases to check the a servlet. It is
giving the Null value for the session. getAttribute("parameter_name"). Hence
my tests are failing....


I have done all the configurations that are given in the Cactus How-TO...
Did Client-side and Server -side configurations....

My servlet class :  

/***********************************************************************************
 * This Servlet is used to Re-Authenticate the user whenever session-idle
timeout
 * is triggered
 * Created by : Srinivasan Keshavamurthy
 * Date Created : 19/07/2005

***********************************************************************************/

package com.logistics.ucl.admin.servlet;

import java.io.IOException;
import java.net.URLEncoder;

import .....


public class AuthenticateServlet extends HttpServlet 
{
	public void init(ServletConfig config) throws ServletException 
	{
		super.init(config);
	}

	public void doPost(HttpServletRequest request,HttpServletResponse response)
		throws IOException, ServletException 
	{
		doGet(request, response);
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
		throws IOException, ServletException 
	{
		String app = "ucl";
		String strUserName = request.getParameter(UCLConstants.UID);
		String strPassword = request.getParameter(UCLConstants.PASSWORD);
		
		HttpSession session = request.getSession(true);
		
		try 
		{
			session.setAttribute(UCLConstants.TIMER_KEY, new
Long(System.currentTimeMillis()));
			UCLAuthenticator authenticator = new UCLAuthenticator();
			boolean authenticated =
authenticator.authenticate(strUserName,strPassword);
			ClientTestLogger log2 = new ClientTestLogger();
			  
			log2.loggerConfiguration(
					"<-------Authentication servlet Attributes----->",
					"doGet method after uid and password fetch ");
			
			if (authenticated)
			{
			
response.sendRedirect((String)session.getAttribute(UCLConstants.APP_PREVIOUS_PAGE));
			}
			else
			{
				String fromuclflag = request.getParameter("fromucl");
				
				if (fromuclflag.equals("false"))
				{
					response.sendRedirect(
							ProtocolIdentifier.getProtocol("UCL")
						+	"://"
						+	UCLDef.UCL_HOSTNAME 
						+	":"
						+	UCLDef.UCL_PORT
						+	"/ucl/login/jsp/error_universal_login.jsp");					
				}
				else if (fromuclflag.equals("true"))
				{
					response.sendRedirect("/ucl/login/jsp/error_universal_login.jsp");
				}								
			}
		}
		catch (Exception e) 
		{	
			String msg = "GenericException caught in AuthenticateServlet.doGet : " +
e.getMessage() + " : "
					+ Misc.stackTraceToString(e);
			logHigh(msg);
			String errorMessage = URLEncoder.encode( Bundle.getMessage("Error:",
request, Bundle.UCL_BUNDLE) + " " + e.getMessage() );
			response.sendRedirect("/ucl/admin/jsp/ErrorPage.jsp?app=" + app +
"&errorMsg=" + errorMessage );					
		}			
	}

	private static boolean willLogHigh() 
	{
		return
UCLDebugLog.DEBUG_LOG.willBeLogged(UCLDebugLog.HIGH,UCLDebugLog.DEFAULT_CATEGORY);
	}

	private static void logHigh(String msg) 
	{
		if (willLogHigh() == true) 
		{
			UCLDebugLog.DEBUG_LOG.logHigh(UCLDebugLog.DEFAULT_CATEGORY,msg);
 }



My Servlet Test case :


public class AuthenticateServletTest extends ServletTestCase {
	
	
		public AuthenticateServletTest(String testfindById) {
		super(testfindById);
		}
     
		
		String userId = "system";
		HashMap userInfo = null;

		public static Test suite() {
		ServletTestSuite suite = new ServletTestSuite();
		suite.addTestSuite(AuthenticateServletTest.class);
		return suite;
		}
	
	
		public void beginAuthenticateServletTest(WebRequest theRequest)
		{
	      
	    
		theRequest.addParameter( "strUserName","system");
        theRequest.addParameter( "strPassword","password");
		
		}
    
	
		public void setup() {
			 try {
			
		 
		
			String userId = "system";
			UCLAbstractUtil.initializeUCLLibrary();
			if (userId != null && userId.length() != 0) {
				System.out.println("\n\n   Entered If \nString length = "
						+ userId.length());
				// LDAPUserDataSource ldapUserAccessSource = new
				// LDAPUserDataSource();
				UserRecord userRecord = UserManager.getPersonRecordByGUID(1);
				String userName = userRecord.getLoginName();
				System.out.println("   userRecord.getCommonName() ----> "
						+ userName);
				userInfo = UCLAbstractUtil.initUserInfo(new UserId(userName));
			}
			UCLHomeHolder.initialize();
			ClientTestLogger log = new ClientTestLogger();
			log.loggerConfiguration(
							"Setup",
							"Setup");
		
		 } catch (Exception e) {
			e.printStackTrace();
		 }
		}
	
	
		public void testAuthenticateServletTest() {
		
			try {
				AuthenticateServlet servlet = new AuthenticateServlet();
				servlet.init(config);
				config. setInitParameter(" ALL_ CAPS","true");			
	    // Call method to test
				servlet.doGet(request, response);
	    String val = (String) session. getAttribute("strUserName");
	    String val1 = (String) session. getAttribute("strPassword");

	    	        	 assertEquals("system", val); 
	     	    assertEquals("password", val1);
	         

	     	   ClientTestLogger log1 = new ClientTestLogger();
	   	    log1.loggerConfiguration(
	   				"<-------Authentication servlet Attributes----->",
	   				"doGet method ");
	   	    } catch (ServletException e) {
	   		   fail(" <---- testAuthenticateServletTest failed with exception --->
"
	   					+ e.getMessage());
	   	  }
	   	  
	   	  catch (IOException e) {
	   		  fail(" <---- testAuthenticateServletTest failed with exception --->
"
	   					+ e.getMessage());
	   	  
	}
		}   	  
	   	public void endAuthenticateServletTest(WebResponse response) throws
Exception {
	   		
	   		}

My error info :

<error message="expected:<system> but was:<null>"
type="org.apache.cactus.internal.client.ServletExceptionWrapper">junit.framework.ComparisonFailure:
expected:<system> but was:<null> at
com.manh.ucl.admin.servlet.AuthenticateServletTest.testAuthenticateServletTest(AuthenticateServletTest.java:108)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at
org.apache.cactus.internal.AbstractCactusTestCase.runBareServer(AbstractCactusTestCase.java:153)
at
org.apache.cactus.internal.server.AbstractWebTestCaller.doTest(AbstractWebTestCaller.java:119)
at
org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody0(AbstractWebTestController.java:93)
at
org.apache.cactus.internal.server.AbstractWebTestController.handleRequest_aroundBody1$advice(AbstractWebTestController.java:224)
at
org.apache.cactus.internal.server.AbstractWebTestController.handleRequest(AbstractWebTestController.java)
at
org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody2(ServletTestRedirector.java:101)
at
org.apache.cactus.server.ServletTestRedirector.doPost_aroundBody3$advice(ServletTestRedirector.java:224)
at
org.apache.cactus.server.ServletTestRedirector.doPost(ServletTestRedirector.java)
at
org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody0(ServletTestRedirector.java:72)
at
org.apache.cactus.server.ServletTestRedirector.doGet_aroundBody1$advice(ServletTestRedirector.java:224)
at
org.apache.cactus.server.ServletTestRedirector.doGet(ServletTestRedirector.java)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:697) at
javax.servlet.http.HttpServlet.service(HttpServlet.java:810) at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at
com.logistics.ucl.util.httpfilter.security.XScriptFilter.doFilter(XScriptFilter.java:78)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:432)
at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at
org.jboss.web.tomcat.tc5.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:156)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at
org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
at java.lang.Thread.run(Thread.java:595)</error> 


  I have creates cactus.properties and placed it in the web-inf>classes
folder etc..


 Can any one please help me to overcome this issue...

regards
MSD


-- 
View this message in context: http://www.nabble.com/Servlet-test-case-is-returning-Null-all-the-time-tp18213163p18213163.html
Sent from the Cactus - Dev mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: cactus-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: cactus-dev-help@jakarta.apache.org