You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by "Sharma, Harsh" <ha...@hp.com> on 2005/09/14 07:17:22 UTC

Cookies ???????

Hi All,

Situation : I have a Custom Tag which based on previously set Cookie
Value generates some tables Dynamically. I need to come up with a Unit
test for this Custom Tag. 

Problem : Since I don't have a actual session going Cookie are not set
to Values which are required to generate these tables, so how do I set
values for cookies to generate these tables.
 
Any help would be welcome...though a sample code would be more than
welcome....

Thanks in advance

Harsh Sharma

Re: Cookies ???????

Posted by Nicolas Chalumeau <ni...@gmail.com>.
I don't sample here but the beginXXX(...) is the good place for this

Nicolas,

2005/9/14, Sharma, Harsh <ha...@hp.com>:
> Hi All,
> 
> Situation : I have a Custom Tag which based on previously set Cookie
> Value generates some tables Dynamically. I need to come up with a Unit
> test for this Custom Tag.
> 
> Problem : Since I don't have a actual session going Cookie are not set
> to Values which are required to generate these tables, so how do I set
> values for cookies to generate these tables.
> 
> Any help would be welcome...though a sample code would be more than
> welcome....
> 
> Thanks in advance
> 
> Harsh Sharma
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 
>

Re: Cookies ???????

Posted by Kazuhito SUGURI <su...@lab.ntt.co.jp>.
Hi,

In article <42...@bgeexc04.asiapacific.cpqcorp.net>,
Wed, 14 Sep 2005 10:47:22 +0530,
"Sharma, Harsh" <ha...@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