[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit HttpServletRequestTest.java,1.26,1.27
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2005-03-06 20:18:42
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5909/test/com/meterware/servletunit Modified Files: HttpServletRequestTest.java Log Message: bug #1151277: fix cookie parsing in ServletUnit Index: HttpServletRequestTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- HttpServletRequestTest.java 2 Dec 2004 02:07:10 -0000 1.26 +++ HttpServletRequestTest.java 6 Mar 2005 20:18:32 -0000 1.27 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000-2003 by Russell Gold +* Copyright (c) 2000-2005 by Russell Gold * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated * documentation files (the "Software"), to deal in the Software without restriction, including without limitation @@ -33,6 +33,7 @@ import javax.servlet.ServletException; import com.meterware.httpunit.*; +import com.meterware.httpunit.cookies.CookieProperties; import junit.framework.Test; import junit.framework.TestSuite; @@ -292,6 +293,36 @@ assertNull( "New request should still not have a request session ID", request.getRequestedSessionId() ); } + /** + * Test recognition of cookies defined on the client. + */ + public void testGetUserCookies() throws Exception { + String FIRST_COOKIE = "RANDOM_COOKIE"; + String SECOND_COOKIE = "ANOTHER_COOKIE"; + String FIRST_COOKIE_VALUE = "cookie1"; + String SECOND_COOKIE_VALUE = "cookie2"; + + ServletRunner sr = new ServletRunner(); + sr.registerServlet( "testServlet", "ServletName" ); + ServletUnitClient m_sc = sr.newClient(); + m_sc.putCookie( FIRST_COOKIE, FIRST_COOKIE_VALUE ); + m_sc.putCookie( SECOND_COOKIE, SECOND_COOKIE_VALUE ); + + InvocationContext invocation = m_sc.newInvocation( "http://localhost/testServlet" ); + HttpServletRequest requ = invocation.getRequest(); + + Cookie[] cookies = requ.getCookies(); + assertEquals( 2, cookies.length ); + Cookie firstActualCookie = cookies[0]; + Cookie secondActualCookie = cookies[1]; + + assertEquals( FIRST_COOKIE, firstActualCookie.getName() ); + assertEquals( SECOND_COOKIE, secondActualCookie.getName() ); + + assertEquals( FIRST_COOKIE_VALUE, firstActualCookie.getValue() ); + assertEquals( SECOND_COOKIE_VALUE, secondActualCookie.getValue() ); + } + /** * Verifies that even when session creation is not explicitly requested, the inclusion of a session cookie |