jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kazuhito SUGURI <suguri.kazuh...@lab.ntt.co.jp>
Subject Re: Cookies ???????
Date Wed, 14 Sep 2005 08:05:44 GMT
Hi,

In article <4221C1B21C20854291E185D1243EA8F302B9A18B@bgeexc04.asiapacific.cpqcorp.net>,
Wed, 14 Sep 2005 10:47:22 +0530,
"Sharma, Harsh" <harshs@hp.com> wrote: 
harshs> Situation : I have a Custom Tag which based on previously set Cookie
harshs> Value generates some tables Dynamically. I need to come up with a Unit
harshs> test for this Custom Tag. 
harshs> 
harshs> Problem : Since I don't have a actual session going Cookie are not set
harshs> to Values which are required to generate these tables, so how do I set
harshs> values for cookies to generate these tables.

You can add cookies at beginXXX method:
	public void beginXXX(WebRequest theRequest)
	{
	    theRequest.addCookie("name1", "value1");
	    ...
	}

Then, you can refer cookie(s) at the corresponding testXXX method:
	public void testXXX()
	{
	    Cookie[] cookies = request.getCookies();
	    ...
	}

If you have to set-up an object as a session attribute
for your custom tag, you can do so:
	public void testXXX()
	{
	    ...
	    String cookieValue = getCookieValueByName("name1");
	    session.setAttribute(cookieValue,
	                         someObjectAssociatedWithCookieName1);
	    ...
	    // instantiate and test the target class.
	}
	private String getCookieValueByName(String theName)
	{
	    ...
	}

Hope this helps,
----
Kazuhito SUGURI

Mime
View raw message