Author: chris.laprun(a)jboss.com
Date: 2007-02-21 15:37:57 -0500 (Wed, 21 Feb 2007)
New Revision: 6369
Added:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java
Removed:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/ProducerSessionInformationTestCase.java
Modified:
branches/JBoss_Portal_Branch_2_4/wsrp/build.xml
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
Log:
- Backported fix for JBPORTAL-1260
- Moved ProducerSessionInformationTestCase to new other directory.
- Added UserContextConverterTestCase.
Modified: branches/JBoss_Portal_Branch_2_4/wsrp/build.xml
===================================================================
--- branches/JBoss_Portal_Branch_2_4/wsrp/build.xml 2007-02-21 20:24:08 UTC (rev 6368)
+++ branches/JBoss_Portal_Branch_2_4/wsrp/build.xml 2007-02-21 20:37:57 UTC (rev 6369)
@@ -337,7 +337,7 @@
<target name="package-other-test" description="Generates the test
artifacts" depends="init">
<jar jarfile="${build.lib}/test-other-lib.jar">
<fileset dir="${build.classes}/">
- <include
name="org/jboss/portal/test/wsrp/*TestCase.class"/>
+ <include
name="org/jboss/portal/test/wsrp/other/*TestCase.class"/>
</fileset>
</jar>
</target>
@@ -588,7 +588,8 @@
<target name="other-test" depends="package-other-test">
<execute-tests>
<x-test>
- <test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.ProducerSessionInformationTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.ProducerSessionInformationTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.UserContextConverterTestCase"/>
</x-test>
<x-sysproperty>
<sysproperty key="test.root"
value="${build.lib}"/>
Deleted:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/ProducerSessionInformationTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/ProducerSessionInformationTestCase.java 2007-02-21
20:24:08 UTC (rev 6368)
+++
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/ProducerSessionInformationTestCase.java 2007-02-21
20:37:57 UTC (rev 6369)
@@ -1,157 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2006, Red Hat Middleware, LLC, 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@jboss.com?subject=org.jboss.portal.test.wsrp.ProducerSessionInformationTestCase">Chris
- * Laprun</a>
- * @version $Revision$
- * @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)});
-
- info.replaceUserCookiesWith(null);
- assertEquals("name=value", info.getUserCookie());
-
- 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);
- }
-}
Copied:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
(from rev 6363,
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/ProducerSessionInformationTestCase.java)
===================================================================
---
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java 2007-02-21
20:37:57 UTC (rev 6369)
@@ -0,0 +1,157 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, 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.other;
+
+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@jboss.com?subject=org.jboss.portal.test.wsrp.other.ProducerSessionInformationTestCase">Chris
+ * Laprun</a>
+ * @version $Revision$
+ * @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)});
+
+ info.replaceUserCookiesWith(null);
+ assertEquals("name=value", info.getUserCookie());
+
+ 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);
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerSessionInformationTestCase.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java
(rev 0)
+++
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java 2007-02-21
20:37:57 UTC (rev 6369)
@@ -0,0 +1,47 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2007, Red Hat Middleware, LLC, 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.other;
+
+import junit.framework.TestCase;
+import org.jboss.xb.binding.SimpleTypeBindings;
+
+import java.util.Calendar;
+
+/**
+ * Needs more complete tests!!
+ *
+ * @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
+ * @version $Revision$
+ * @since 2.4
+ */
+public class UserContextConverterTestCase extends TestCase
+{
+ public void testDateFormat()
+ {
+ String dateAsString = "1983-12-11T00:00:00.000+01:00";
+ Calendar bdate = SimpleTypeBindings.unmarshalDateTime(dateAsString);
+ String result = SimpleTypeBindings.marshalDateTime(bdate);
+ assertEquals(dateAsString, result);
+ }
+}
Property changes on:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/test/wsrp/other/UserContextConverterTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified:
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java
===================================================================
---
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java 2007-02-21
20:24:08 UTC (rev 6368)
+++
branches/JBoss_Portal_Branch_2_4/wsrp/src/main/org/jboss/portal/wsrp/UserContextConverter.java 2007-02-21
20:37:57 UTC (rev 6369)
@@ -34,14 +34,11 @@
import org.jboss.portal.wsrp.core.Telecom;
import org.jboss.portal.wsrp.core.TelephoneNum;
import org.jboss.portal.wsrp.core.UserProfile;
+import org.jboss.xb.binding.SimpleTypeBindings;
-import java.text.DateFormat;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
-import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@@ -54,8 +51,6 @@
*/
public class UserContextConverter
{
- public static final String XSD_DATETIME_FORMAT =
"yyy-MM-dd'T'HH:mm:ss";
-
public static UserContext
createPortalUserContextFrom(org.jboss.portal.wsrp.core.UserContext userContext,
String[] desiredLocales, String
preferredLocale)
{
@@ -87,19 +82,7 @@
String bdateAsString = (String)userInfos.get(P3PConstants.INFO_USER_BDATE);
if (bdateAsString != null)
{
- Locale locale = userContext.getLocale();
- SimpleDateFormat format = new SimpleDateFormat(XSD_DATETIME_FORMAT, locale);
- format.setLenient(false); // should maybe make it lenient?
- try
- {
- Date date = format.parse(bdateAsString);
- bdate = Calendar.getInstance(locale);
- bdate.setTime(date);
- }
- catch (ParseException e)
- {
- throw new IllegalArgumentException(bdateAsString + " is not a valid
birthday date!");
- }
+ bdate = SimpleTypeBindings.unmarshalDateTime(bdateAsString);
}
EmployerInfo employerInfo = new
EmployerInfo((String)userInfos.get(P3PConstants.INFO_USER_EMPLOYER),
@@ -185,8 +168,7 @@
Calendar bdate = profile.getBdate();
if (bdate != null)
{
- DateFormat dateFormat = new SimpleDateFormat(XSD_DATETIME_FORMAT,
getLocale());
- infos.put(P3PConstants.INFO_USER_BDATE, dateFormat.format(bdate));
+ infos.put(P3PConstants.INFO_USER_BDATE,
SimpleTypeBindings.marshalDateTime(bdate));
}
infos.put(P3PConstants.INFO_USER_GENDER, profile.getGender());