[jboss-cvs] jboss-portal/wsrp/src/main/org/jboss/portal/test/wsrp ...
Chris Laprun
chris.laprun at jboss.com
Thu Aug 24 20:54:54 EDT 2006
User: claprun
Date: 06/08/24 20:54:54
Added: wsrp/src/main/org/jboss/portal/test/wsrp
ProducerSessionInformationTestCase.java
Log:
- Re-wrote cookie/session management. Now handles cookies outside of initCookie calls. Still needs more testing.
- Added ProducerSessionInformationTestCase and other-tests in build.xml for WSRP.
- Minor improvements.
Revision Changes Path
1.1 date: 2006/08/25 00:54:54; author: claprun; state: Exp;jboss-portal/wsrp/src/main/org/jboss/portal/test/wsrp/ProducerSessionInformationTestCase.java
Index: ProducerSessionInformationTestCase.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.portal.test.wsrp;
import junit.framework.TestCase;
import org.apache.commons.httpclient.Cookie;
import org.jboss.portal.wsrp.WSRPConstants;
import org.jboss.portal.wsrp.WSRPTypeFactory;
import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
/**
* @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.ProducerSessionInformationTestCase">Chris
* Laprun</a>
* @version $Revision: 1.1 $
* @since 2.4
*/
public class ProducerSessionInformationTestCase extends TestCase
{
ProducerSessionInformation info;
protected void setUp() throws Exception
{
info = new ProducerSessionInformation();
}
public void testUserCookie() throws Exception
{
assertNull(info.getUserCookie());
Cookie[] cookies = new Cookie[]{createCookie("name", "value", 1)};
info.setUserCookie(cookies);
assertEquals("name=value", info.getUserCookie());
// wait for cookie expiration
Thread.sleep(1000);
assertNull(info.getUserCookie()); // we shouldn't have a cookie now
cookies = new Cookie[]{createCookie("name1", "value1", 1), createCookie("name2", "value2", 3)};
info.setUserCookie(cookies);
assertEquals("name1=value1;name2=value2", info.getUserCookie());
Thread.sleep(1000);
assertEquals("name2=value2", info.getUserCookie());
try
{
info.setUserCookie(null);
fail("Should have thrown an IllegalArgumentException");
}
catch (IllegalArgumentException e)
{
//expected
}
}
public void testGroupCookies() throws Exception
{
String groupId = "groupId";
try
{
info.setGroupCookieFor(groupId, new Cookie[]{createCookie("name1", "value1", 1), createCookie("name2", "value2", -1)});
fail("Cannot add group cookie if not perGroup");
}
catch (IllegalStateException e)
{
//expected
}
info.setPerGroupCookies(true);
info.setGroupCookieFor(groupId, new Cookie[]{createCookie("name1", "value1", 1),
createCookie("name2", "value2", WSRPConstants.SESSION_NEVER_EXPIRES)});
assertEquals("name1=value1;name2=value2", info.getGroupCookieFor(groupId));
Thread.sleep(1000);
assertEquals("name2=value2", info.getGroupCookieFor(groupId));
info.clearGroupCookies();
assertNull(info.getGroupCookieFor(groupId));
}
public void testSessionForPortlet() throws Exception
{
String handle = "handle";
String handle2 = "handle2";
String sid = "id";
String sid2 = "id2";
assertNull(info.getSessionIdForPortlet(handle));
assertEquals(0, info.getNumberOfSessions());
info.addSessionForPortlet(handle, WSRPTypeFactory.createSessionContext(sid, 1));
info.addSessionForPortlet(handle2, WSRPTypeFactory.createSessionContext(sid2, 3));
assertNull(info.getSessionIdForPortlet("unknown"));
assertEquals(sid, info.getSessionIdForPortlet(handle));
assertEquals(2, info.getNumberOfSessions());
Thread.sleep(1000);
assertNull(info.getSessionIdForPortlet(handle));
assertEquals(sid2, info.getSessionIdForPortlet(handle2));
assertEquals(1, info.getNumberOfSessions());
info.removeSessionIdForPortlet(handle2);
assertEquals(0, info.getNumberOfSessions());
}
public void testReplaceUserCookies() throws Exception
{
info.setUserCookie(new Cookie[]{createCookie("name", "value", 1)});
ProducerSessionInformation other = new ProducerSessionInformation();
info.replaceUserCookiesWith(other);
assertEquals("name=value", info.getUserCookie());
other.setUserCookie(new Cookie[]{createCookie("name2", "value2", 1)});
info.replaceUserCookiesWith(other);
assertEquals("name2=value2", info.getUserCookie());
Thread.sleep(1000);
info.replaceUserCookiesWith(other);
assertNull(info.getUserCookie());
}
private Cookie createCookie(String name, String value, int secondsBeforeExpiration)
{
return new Cookie("domain", name, value, "path", secondsBeforeExpiration, false);
}
}
More information about the jboss-cvs-commits
mailing list