[jboss-svn-commits] JBoss Portal SVN: r5546 - in trunk/wsrp/src: main/org/jboss/portal/test/wsrp/v1/producer main/org/jboss/portal/wsrp main/org/jboss/portal/wsrp/producer resources/tests/test-wsrp-producer-markup-sar/META-INF

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Oct 31 20:29:40 EST 2006


Author: chris.laprun at jboss.com
Date: 2006-10-31 20:29:37 -0500 (Tue, 31 Oct 2006)
New Revision: 5546

Added:
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/ReleaseSessionTestCase.java
Modified:
   trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java
   trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
   trunk/wsrp/src/resources/tests/test-wsrp-producer-markup-sar/META-INF/jboss-service.xml
Log:
- Added ReleaseSessionTestCase (Matt's code, sightly modified) though the test is not currently activated in the test suite.
- Added support for RegistrationContext in WSRPTypeFactory and use it where appropriate.
- Minor other fixes from Matt.

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/ReleaseSessionTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/ReleaseSessionTestCase.java	2006-11-01 00:03:22 UTC (rev 5545)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/producer/ReleaseSessionTestCase.java	2006-11-01 01:29:37 UTC (rev 5546)
@@ -0,0 +1,280 @@
+/******************************************************************************
+ * 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.v1.producer;
+
+import org.jboss.logging.Logger;
+import org.jboss.portal.common.junit.ExtendedAssert;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
+import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.MissingParametersFault;
+import org.jboss.portal.wsrp.core.OperationFailedFault;
+import org.jboss.portal.wsrp.core.RegistrationContext;
+import org.jboss.portal.wsrp.core.ReleaseSessions;
+import org.jboss.portal.wsrp.handler.RequestHeaderClientHandler;
+
+/**
+ * Tests the behavior of the ReleaseSession method.
+ *
+ * @author Matt Wringe
+ */
+public class ReleaseSessionTestCase extends NeedPortletHandleTest
+{
+
+   // default portlet war used in this test
+   private static final String DEFAULT_SESSION_PORTLET_WAR = "test-session-portlet.war";
+
+   Logger log = Logger.getLogger(ReleaseSessionTestCase.class);
+
+   public ReleaseSessionTestCase() throws Exception
+   {
+      super("SessionWar", DEFAULT_SESSION_PORTLET_WAR);
+      //super("SessionWar");
+      log.debug("Instantiating ReleaseSessionTestCase");
+   }
+
+   public void testNullRegistrationContextWithRegistration() throws Exception
+   {
+
+      RegistrationContext regContext = null;
+
+      Class exceptionClass = InvalidRegistrationFault.class;
+      String message = "A null RegistrationContext when a registration is required should produce an InvalidRegistrationFault";
+
+      releaseSessionsWithRegistration(regContext, getSessionIDs(), exceptionClass, message);
+   }
+
+   public void testNullRegistrationContext() throws Exception
+   {
+      RegistrationContext regContext = null;
+
+      // Since no registration is required, a null RegistrationContext should be acceptable
+      releaseSessions(regContext, getSessionIDs(), null, null);
+   }
+
+   public void testNullSessionIDWithRegistration() throws Exception
+   {
+
+      RegistrationContext regContext = getRegistrationContext();
+      String[] sessionIDs = null;
+
+      Class exceptionClass = MissingParametersFault.class;
+      String message = "SessionIDs are required. Null SessionIDs should produce a MissingParameterFault";
+
+      releaseSessionsWithRegistration(regContext, sessionIDs, exceptionClass, message);
+   }
+
+   public void testNullSessionID() throws Exception
+   {
+
+      RegistrationContext regContext = getRegistrationContext();
+      String[] sessionIDs = null;
+
+      Class exceptionClass = MissingParametersFault.class;
+      String message = "SessionIDs are required. Null SessionIDs should produce a MissingParameterFault";
+
+      releaseSessions(regContext, sessionIDs, exceptionClass, message);
+   }
+
+   public void testInvalidRegistrationContextWithRegistration() throws Exception
+   {
+      RegistrationContext regContext = WSRPTypeFactory.createRegistrationContext("Fake Registration Handle");
+
+      Class exceptionClass = InvalidRegistrationFault.class;
+      String message = "An invalid RegistrationContext when a registration is required should produce an InvalidRegistrationFault";
+
+      releaseSessionsWithRegistration(regContext, getSessionIDs(), exceptionClass, message);
+   }
+
+   public void testInvalidRegistrationContext() throws Exception
+   {
+      RegistrationContext regContext = WSRPTypeFactory.createRegistrationContext("Fake Registration Handle");
+
+      Class exceptionClass = InvalidRegistrationFault.class;
+      String message = "An invalid RegistrationContext when a registration is not required should still produce an InvalidRegistrationFault";
+
+      releaseSessions(regContext, getSessionIDs(), exceptionClass, message);
+   }
+
+   public void testInvalidSessionIDsWithRegistration() throws Exception
+   {
+      RegistrationContext regContext = getRegistrationContext();
+      String[] sessionIDs = new String[]
+         {"fake session id"};
+
+      Class exceptionClass = OperationFailedFault.class;
+      String message = "An invalid SessionIDs should produce an OperationFailedFault";
+
+      releaseSessionsWithRegistration(regContext, sessionIDs, exceptionClass, message);
+   }
+
+   public void testInvalidSessionIDs() throws Exception
+   {
+      RegistrationContext regContext = getRegistrationContext();
+      String[] sessionIDs = new String[]
+         {"fake session id"};
+
+      Class exceptionClass = OperationFailedFault.class;
+      String message = "An invalid SessionIDs should produce an OperationFailedFault";
+
+      releaseSessions(regContext, sessionIDs, exceptionClass, message);
+   }
+
+   public void testNullParametersWithRegistration() throws Exception
+   {
+      RegistrationContext regContext = null;
+      String[] sessionIDs = null;
+
+      // This method can potentially throw two different fault methods
+      // (InvalidRegistration and MissingParameters) for the given parameters.
+      Class exceptionClass = InvalidRegistrationFault.class;
+      String message = "Null RegistrationContext when registration is reguired should produce an InvalidRegistrationFault";
+
+      releaseSessionsWithRegistration(regContext, sessionIDs, exceptionClass, message);
+   }
+
+   public void testNullParameters() throws Exception
+   {
+      RegistrationContext regContext = null;
+      String[] sessionIDs = null;
+
+      Class exceptionClass = MissingParametersFault.class;
+      String message = "Null SessionIDs should produce a MissingParameterFault";
+
+      releaseSessions(regContext, sessionIDs, exceptionClass, message);
+   }
+
+   public void testValidParametersWithRegistration() throws Exception
+   {
+      RegistrationContext regContext = getRegistrationContext();
+      String[] sessionIDs = getSessionIDs();
+      releaseSessionsWithRegistration(regContext, sessionIDs, null, null);
+   }
+
+   public void testValidParameters() throws Exception
+   {
+      RegistrationContext regContext = getRegistrationContext();
+      String[] sessionIDs = getSessionIDs();
+      releaseSessions(regContext, sessionIDs, null, null);
+   }
+
+   public void testReleasedSession() throws Exception
+   {
+      RegistrationContext regContext = getRegistrationContext();
+      String[] sessionIDs = getSessionIDs();
+
+      ReleaseSessions relSession = new ReleaseSessions(regContext, sessionIDs);
+
+      markupService.releaseSessions(relSession);
+
+      try
+      {
+         markupService.releaseSessions(relSession);
+         ExtendedAssert.fail("Trying to release an already released session should produce an OperationFailedFault");
+      }
+      catch (OperationFailedFault operationFailedFault)
+      {
+         // expected failure
+      }
+
+   }
+
+   public void testReleasedSessionWithRegistration() throws Exception
+   {
+      initRegistrationInfo();
+      testReleasedSession();
+      registrationService.deregister(getRegistrationContext());
+   }
+
+   public void testNullReleaseSessions() throws Exception
+   {
+      ReleaseSessions relSession = null;
+      try
+      {
+         markupService.releaseSessions(relSession);
+         ExtendedAssert.fail("A null ReleaseSessions should produce an OperationFailedFault");
+      }
+      catch (OperationFailedFault operationFailedFault)
+      {
+         // expected
+      }
+   }
+
+   public void testNullReleaseSessionsWithRegistration() throws Exception
+   {
+      initRegistrationInfo();
+      testNullReleaseSessions();
+      registrationService.deregister(getRegistrationContext());
+   }
+
+   //*************************************************************************************************
+
+
+   private String[] getSessionIDs()
+   {
+      ProducerSessionInformation sessionInfo = RequestHeaderClientHandler.getCurrentProducerSessionInformation();
+      String sessionID = (sessionInfo.getUserCookie()).substring("JSESSIONID=".length());
+      return new String[]
+         {sessionID};
+   }
+
+   private RegistrationContext getRegistrationContext() throws Exception
+   {
+      return registerConsumer();
+   }
+
+   private void releaseSessions(RegistrationContext regContext, String[] sessionIDs, Class exceptionClass,
+                                String message) throws Exception
+   {
+      ReleaseSessions relSession = new ReleaseSessions(regContext, sessionIDs);
+      try
+      {
+         markupService.releaseSessions(relSession);
+         if (exceptionClass != null)
+         {
+            ExtendedAssert.fail(message);
+         }
+      }
+      catch (Exception e)
+      {
+         if (e.getClass() == exceptionClass && exceptionClass != null)
+         {
+            //expected exception
+         }
+         else
+         {
+            throw e;
+         }
+      }
+   }
+
+   private void releaseSessionsWithRegistration(RegistrationContext regContext, String[] sessionIDs,
+                                                Class exceptionClass, String message) throws Exception
+   {
+      initRegistrationInfo();
+      releaseSessions(regContext, sessionIDs, exceptionClass, message);
+      registrationService.deregister(regContext);
+   }
+
+}

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java	2006-11-01 00:03:22 UTC (rev 5545)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/WSRPTypeFactory.java	2006-11-01 01:29:37 UTC (rev 5546)
@@ -607,4 +607,15 @@
 
       return new CacheControl(expires, userScope, null, null);
    }
+
+   /**
+    * registrationHandle(xsd:string), registrationState(xsd:base64Binary)?, extensions(Extension)*
+    *
+    * @param registrationHandle
+    * @return
+    */
+   public static RegistrationContext createRegistrationContext(String registrationHandle)
+   {
+      return new RegistrationContext(registrationHandle, null, null);
+   }
 }

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java	2006-11-01 00:03:22 UTC (rev 5545)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/MarkupHandler.java	2006-11-01 01:29:37 UTC (rev 5546)
@@ -446,8 +446,17 @@
 
       RegistrationContext rc = releaseSessions.getRegistrationContext();
       producer.checkRegistration(rc);
-      String regHandle = rc.getRegistrationHandle();
 
+      String regHandle;
+      if (rc == null)
+      {
+         regHandle = null;
+      }
+      else
+      {
+         regHandle = rc.getRegistrationHandle();
+      }
+
       String[] sessionIDs = releaseSessions.getSessionIDs();
       WSRPUtils.throwMissingParametersFaultIfValueIsMissing(sessionIDs, "session IDs", "ReleaseSessions");
 
@@ -474,7 +483,7 @@
     * @param sessionID          the id of the session which resources are to be released
     * @throws IllegalStateException if the specified session had already been released
     */
-   private void releaseSession(String registrationHandle, String sessionID) throws IllegalStateException
+   private void releaseSession(String registrationHandle, String sessionID) throws IllegalStateException, OperationFailedFault
    {
       //fix-me: do we need to pass registration handle?
       producer.releaseSession(sessionID);

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java	2006-11-01 00:03:22 UTC (rev 5545)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/RegistrationHandler.java	2006-11-01 01:29:37 UTC (rev 5546)
@@ -24,6 +24,7 @@
 package org.jboss.portal.wsrp.producer;
 
 import org.apache.log4j.Logger;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
 import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
 import org.jboss.portal.wsrp.core.MissingParametersFault;
 import org.jboss.portal.wsrp.core.ModifyRegistration;
@@ -55,7 +56,7 @@
       RemoteException
    {
       // todo: compute registration handle, record registration handle in registry
-      return new RegistrationContext(register.getConsumerName(), null, null);
+      return WSRPTypeFactory.createRegistrationContext(register.getConsumerName());
    }
 
    public ReturnAny deregister(RegistrationContext deregister) throws OperationFailedFault, InvalidRegistrationFault,

Modified: trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java	2006-11-01 00:03:22 UTC (rev 5545)
+++ trunk/wsrp/src/main/org/jboss/portal/wsrp/producer/WSRPProducerImpl.java	2006-11-01 01:29:37 UTC (rev 5546)
@@ -361,7 +361,7 @@
       return ServletAccess.getRequest().getSession(false);
    }
 
-   public void releaseSession(String sessionID) throws IllegalStateException
+   public void releaseSession(String sessionID) throws IllegalStateException, OperationFailedFault
    {
       sessionManager.invalidateSession(sessionID);
    }
@@ -607,7 +607,7 @@
          return (HttpSession)sessions.get(sessionId);
       }
 
-      void invalidateSession(String sessionId) throws IllegalStateException
+      void invalidateSession(String sessionId) throws IllegalStateException, OperationFailedFault
       {
          HttpSession session = getSession(sessionId);
          if (session != null)
@@ -618,6 +618,11 @@
                session.invalidate();
             }
          }
+         else
+         {
+            //the sessionID does not exist for any session
+            throw WSRPUtils.createOperationFailedFault(new IllegalArgumentException("'" + sessionId + "' is not a valid session id!"));
+         }
       }
 
       private boolean hasSessionExpired(HttpSession session)

Modified: trunk/wsrp/src/resources/tests/test-wsrp-producer-markup-sar/META-INF/jboss-service.xml
===================================================================
--- trunk/wsrp/src/resources/tests/test-wsrp-producer-markup-sar/META-INF/jboss-service.xml	2006-11-01 00:03:22 UTC (rev 5545)
+++ trunk/wsrp/src/resources/tests/test-wsrp-producer-markup-sar/META-INF/jboss-service.xml	2006-11-01 01:29:37 UTC (rev 5546)
@@ -30,7 +30,18 @@
       xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
       <xmbean/>
       <depends optional-attribute-name="TestDriverRegistry" proxy-type="attribute">portal.test:service=HttpTestDriverServer</depends>
+      <depends optional-attribute-name="ServiceFactory"
+               proxy-type="attribute">portal.wsrp:service=CachingServiceFactory</depends>
+      <depends optional-attribute-name="Producer" proxy-type="attribute">portal.wsrp:service=WSRPProducer</depends>
+   </mbean>
+   <!--<mbean
+      code="org.jboss.portal.test.wsrp.v1.producer.ReleaseSessionTestCase"
+      name="portal.test:test=ReleaseSession"
+      xmbean-dd=""
+      xmbean-code="org.jboss.portal.jems.as.system.JBossServiceModelMBean">
+      <xmbean/>
+      <depends optional-attribute-name="TestDriverRegistry" proxy-type="attribute">portal.test:service=HttpTestDriverServer</depends>
       <depends optional-attribute-name="ServiceFactory" proxy-type="attribute">portal.wsrp:service=CachingServiceFactory</depends>
       <depends optional-attribute-name="Producer" proxy-type="attribute">portal.wsrp:service=WSRPProducer</depends>
-   </mbean>
+   </mbean>-->
 </server>




More information about the jboss-svn-commits mailing list