You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Lois GreeneHernandez <lg...@knoa.com> on 2015/12/10 20:50:37 UTC

Jsession Test Question

Hi All,

Is it possible to write a unit test or a pojo that tests an request url for the presence of a jsessionid?  My application Is java/wicket.  Our test system is testNG and wicket tester.

Thanks

Lois

Re: Jsession Test Question

Posted by "Richard W. Adams" <RW...@UP.COM>.
The short answer is no. The session ID is not part of the URL.

The long answer is, you can test for the session ID if you have access to 
the HTTP request object.




From:   Lois GreeneHernandez <lg...@knoa.com>
To:     "users@wicket.apache.org" <us...@wicket.apache.org>
Date:   12/10/2015 01:50 PM
Subject:        Jsession Test Question



This email originated from outside of the company.  Please use discretion 
if opening attachments or clicking on links.

Hi All,

Is it possible to write a unit test or a pojo that tests an request url 
for the presence of a jsessionid?  My application Is java/wicket.  Our 
test system is testNG and wicket tester.

Thanks

Lois



**

This email and any attachments may contain information that is confidential and/or privileged for the sole use of the intended recipient.  Any use, review, disclosure, copying, distribution or reliance by others, and any forwarding of this email or its contents, without the express permission of the sender is strictly prohibited by law.  If you are not the intended recipient, please contact the sender immediately, delete the e-mail and destroy all copies.
**

Re: Jsession Test Question

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

WicketTester *simulates* a browser and a web server.
In a normal setup the web server (like Tomcat) generates and encodes the
jsessionid in the url.
WicketTester creates a Wicket Session for the test(s) and there is no need
of transferring jsessionid in the url/cookie.
You can use tester.executeUrl("....;jsessionid=123456") and assert for it
in your server code by using getWebRequest().getUrl().toString() but this
is very artificial.

In your application code you can use
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#getRequestedSessionId()
and
http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletRequest.html#isRequestedSessionIdFromURL()
Maybe WicketTester should add support for those.
Currently the code in MockHttpServletRequest looks like:


/**
 * Check whether session id is from a cookie. Always returns true.
 *
 * @return Always true
 */
@Override
public boolean isRequestedSessionIdFromCookie()
{
   return true;
}

/**
 * Check whether session id is from a url rewrite. Always returns false.
 *
 * @return Always false
 */
@Override
public boolean isRequestedSessionIdFromUrl()
{
   return false;
}



Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Thu, Dec 10, 2015 at 8:50 PM, Lois GreeneHernandez <
lgreenehernandez@knoa.com> wrote:

> Hi All,
>
> Is it possible to write a unit test or a pojo that tests an request url
> for the presence of a jsessionid?  My application Is java/wicket.  Our test
> system is testNG and wicket tester.
>
> Thanks
>
> Lois
>

RE: Jsession Test Question

Posted by Ephraim Rosenfeld <er...@knoa.com>.
I would have to do further research, but some ideas:
*       This example shows how to simulate putting a URL in browser, which is helpful for mounted pages: https://ci.apache.org/projects/wicket/guide/6.x/guide/testing.html#testing_1<https://ci.apache.org/projects/wicket/guide/6.x/guide/testing.html%23testing_1>
*       The WicketTester<https://ci.apache.org/projects/wicket/apidocs/6.x/org/apache/wicket/util/tester/BaseWicketTester.html> class has some useful methods, like getHttpSession, getLastRequest, getLastResponse. These may allow you to find some information regarding the URL

I would try the latter first, just printing out what the request and response data have.

- Ephraim

-----Original Message-----
From: Lois GreeneHernandez [mailto:lgreenehernandez@knoa.com]
Sent: Thursday, December 10, 2015 2:51 PM
To: users@wicket.apache.org
Subject: Jsession Test Question

Hi All,

Is it possible to write a unit test or a pojo that tests an request url for the presence of a jsessionid?  My application Is java/wicket.  Our test system is testNG and wicket tester.

Thanks

Lois