[jboss-svn-commits] JBoss Portal SVN: r5475 - in trunk/wsrp: . src/main/org/jboss/portal/test/wsrp/framework src/main/org/jboss/portal/test/wsrp/framework/support src/main/org/jboss/portal/test/wsrp/v1/consumer src/main/org/jboss/portal/test/wsrp/v1/consumer/producer

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Oct 17 19:46:23 EDT 2006


Author: chris.laprun at jboss.com
Date: 2006-10-17 19:46:19 -0400 (Tue, 17 Oct 2006)
New Revision: 5475

Added:
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/BasicBehavior.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/EmptyMarkupBehavior.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/NullMarkupBehavior.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/SessionBehavior.java
Modified:
   trunk/wsrp/build.xml
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/ServiceObjectFactory.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/MarkupTestCase.java
   trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/ServiceDescriptionTestCase.java
Log:
- More refactorings: started extracting producer behavior into Command-like classes.

Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/build.xml	2006-10-17 23:46:19 UTC (rev 5475)
@@ -513,7 +513,7 @@
             <test todir="${test.reports}" name="org.jboss.portal.test.wsrp.v1.producer.PortletManagementTestCase"/>
             <test todir="${test.reports}" name="org.jboss.portal.test.wsrp.v1.producer.MarkupTestCase"/>
             <test todir="${test.reports}" name="org.jboss.portal.test.wsrp.v1.producer.ServiceDescriptionTestCase"/>
-            <!--<test name="org.jboss.portal.test.wsrp.v1.producer.RegistrationTestCase"/>-->
+            <!--<test todir="${test.reports}" name="org.jboss.portal.test.wsrp.v1.producer.RegistrationTestCase"/>-->
          </x-test>
          <x-sysproperty>
             <jvmarg value="-Xdebug"/>

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -0,0 +1,52 @@
+/******************************************************************************
+ * 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.framework;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.wsrp.core.GetMarkup;
+import org.jboss.portal.wsrp.core.MarkupResponse;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.framework.TestProducerBehavior">Chris
+ *         Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public abstract class TestProducerBehavior
+{
+   protected String portletHandle;
+
+   public String getPortletHandle()
+   {
+      return portletHandle;
+   }
+
+   public abstract String getMarkupString(Mode mode, WindowState windowState, String navigationalState, GetMarkup getMarkup);
+
+   public void modifyResponseIfNeeded(MarkupResponse markupResponse)
+   {
+      // default implementation does not nothing
+   }
+}

Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestWSRPProducerImpl.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -25,6 +25,10 @@
 import org.jboss.invocation.Invocation;
 import org.jboss.portal.jems.as.system.AbstractJBossService;
 import org.jboss.portal.test.wsrp.framework.support.ServiceObjectFactory;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.BasicBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.EmptyMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.NullMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.SessionBehavior;
 import org.jboss.portal.wsrp.WSRPConstants;
 import org.jboss.portal.wsrp.WSRPTypeFactory;
 import org.jboss.portal.wsrp.WSRPUtils;
@@ -70,7 +74,6 @@
 import org.jboss.portal.wsrp.core.ReleaseSessions;
 import org.jboss.portal.wsrp.core.ReturnAny;
 import org.jboss.portal.wsrp.core.ServiceDescription;
-import org.jboss.portal.wsrp.core.SessionContext;
 import org.jboss.portal.wsrp.core.SetPortletProperties;
 import org.jboss.portal.wsrp.core.UnsupportedLocaleFault;
 import org.jboss.portal.wsrp.core.UnsupportedMimeTypeFault;
@@ -82,6 +85,8 @@
 import javax.servlet.http.HttpServletResponse;
 import java.lang.reflect.Method;
 import java.rmi.RemoteException;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * This is dummy clone of org.jboss.portal.wsrp.producer.WSRPProducerImpl customizable from client side. Just for
@@ -119,12 +124,9 @@
    /** Required registration information to be provided by consumers to access this Producer's information and services. */
    private ModelDescription requiredRegistrationInfo;
 
-   private int count;
-
    /** Used to set the cookie in initCookie */
    private HttpServletResponse response;
 
-   public final static String SESSION_ID = "sessionID";
    public static final String USER_COOKIE = "cookie";
 
    public TestWSRPProducerImpl()
@@ -143,12 +145,10 @@
       serviceDescription = WSRPTypeFactory.createServiceDescription(requiresRegistration);
 
       //Prepare description of two portlets
-      PortletDescription pd1 = createPortletDescription(ServiceObjectFactory.PORTLET_HANDLE_1, "");
-      PortletDescription pd2 = createPortletDescription(ServiceObjectFactory.PORTLET_HANDLE_2, "2");
+      PortletDescription pd1 = createPortletDescription(BasicBehavior.PORTLET_HANDLE, "");
+      PortletDescription pd2 = createPortletDescription(SessionBehavior.PORTLET_HANDLE, "2");
       serviceDescription.setOfferedPortlets(new PortletDescription[]{pd1, pd2});
 
-      count = 0;
-
       if (response != null)
       {
          response.reset();
@@ -156,9 +156,26 @@
       response = null;
 
       requiresInitCookie = null;
+
+      register(new BasicBehavior());
+      register(new SessionBehavior());
+      register(new NullMarkupBehavior());
+      register(new EmptyMarkupBehavior());
    }
 
+   Map behaviors = new HashMap();
 
+   public void register(TestProducerBehavior behavior)
+   {
+      behaviors.put(behavior.getPortletHandle(), behavior);
+   }
+
+   public TestProducerBehavior getBehaviorFor(String portletHandle)
+   {
+      return (TestProducerBehavior)behaviors.get(portletHandle);
+   }
+
+
    public void setResponse(HttpServletResponse response)
    {
       this.response = response;
@@ -200,59 +217,22 @@
       UnsupportedMimeTypeFault, RemoteException
    {
       String handle = getMarkup.getPortletContext().getPortletHandle();
-      String markupString = null;
-      String sessionId = getMarkup.getRuntimeContext().getSessionID();
+      String markupString;
 
-      if (ServiceObjectFactory.PORTLET_HANDLE_1.equals(handle))
-      {
-         markupString = "portlet1:";
-      }
-      else
-      if (ServiceObjectFactory.PORTLET_HANDLE_2.equals(handle)) // markup for ServiceObjectFactory.PORTLET_HANDLE_2 simulates using the session
-      {
-         // if we have a session, increments count to simulate session usage
-         if (SESSION_ID.equals(sessionId))
-         {
-            count++;
-         }
-         markupString = "portlet2:" + count + ":";
-      }
-
       MarkupParams markupParams = getMarkup.getMarkupParams();
-      markupString += WSRPUtils.getJSR168PortletModeFromWSRPName(markupParams.getMode()) + ":";
-      markupString += WSRPUtils.getJSR168WindowStateFromWSRPName(markupParams.getWindowState());
-      String ns = markupParams.getNavigationalState();
-      if (ns != null)
-      {
-         markupString += ":" + ns;
-      }
 
-      if (ServiceObjectFactory.NULL_MARKUP_PORTLET_HANDLE.equals(handle))
-      {
-         markupString = null;
-      }
-      else if (ServiceObjectFactory.EMPTY_MARKUP_PORTLET_HANDLE.equals(handle))
-      {
-         markupString = "";
-      }
+      TestProducerBehavior behavior = getBehaviorFor(handle);
 
+      markupString = behavior.getMarkupString(WSRPUtils.getJSR168PortletModeFromWSRPName(markupParams.getMode()),
+         WSRPUtils.getJSR168WindowStateFromWSRPName(markupParams.getWindowState()), markupParams.getNavigationalState(),
+         getMarkup);
+
       MarkupContext markupContext = WSRPTypeFactory.createMarkupContext("text/html", markupString);
       markupContext.setRequiresUrlRewriting(Boolean.TRUE);
 
-      // fake markup caching
-      if (ServiceObjectFactory.PORTLET_HANDLE_1.equals(handle))
-      {
-         markupContext.setCacheControl(WSRPTypeFactory.createCacheControl(15, WSRPConstants.CACHE_PER_USER));
-      }
-
       MarkupResponse markupResponse = WSRPTypeFactory.createMarkupResponse(markupContext);
 
-      // fakes creation of a portlet session if not already present
-      if (count == 0 || SESSION_ID.equals(sessionId))
-      {
-         SessionContext sessionContext = WSRPTypeFactory.createSessionContext(SESSION_ID, 30);
-         markupResponse.setSessionContext(sessionContext);
-      }
+      behavior.modifyResponseIfNeeded(markupResponse);
 
       return markupResponse;
    }
@@ -270,11 +250,11 @@
          return WSRPTypeFactory.createBlockingInteractionResponse("http://jboss.com");
       }
 
-      if (ServiceObjectFactory.PORTLET_HANDLE_1.equals(handle))
+      if (BasicBehavior.PORTLET_HANDLE.equals(handle))
       {
          ns = "ns1";
       }
-      if (ServiceObjectFactory.PORTLET_HANDLE_2.equals(handle))
+      if (SessionBehavior.PORTLET_HANDLE.equals(handle))
       {
          ns = "ns2";
       }
@@ -390,11 +370,11 @@
       }
 
       PortletDescription[] offeredPortlets = serviceDescription.getOfferedPortlets();
-      if (ServiceObjectFactory.PORTLET_HANDLE_1.equals(handle))
+      if (BasicBehavior.PORTLET_HANDLE.equals(handle))
       {
          return offeredPortlets[0];
       }
-      if (ServiceObjectFactory.PORTLET_HANDLE_2.equals(handle))
+      if (SessionBehavior.PORTLET_HANDLE.equals(handle))
       {
          return offeredPortlets[1];
       }

Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/ServiceObjectFactory.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/ServiceObjectFactory.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/support/ServiceObjectFactory.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -40,10 +40,6 @@
 
    public static final String SAMPLE_DISPLAYNAME = "SampleDisplayName";
    public static final String SAMPLE_KEYWORD = "keyword";
-   public static final String PORTLET_HANDLE_1 = "SamplePortletHandle";
-   public static final String PORTLET_HANDLE_2 = "SecondPortletHandle";
-   public static final String EMPTY_MARKUP_PORTLET_HANDLE = "empty";
-   public static final String NULL_MARKUP_PORTLET_HANDLE = "null";
 
    /**
     * Create the dummiest form of LocalizedString

Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/MarkupTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/MarkupTestCase.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/MarkupTestCase.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -32,12 +32,14 @@
 import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
 import org.jboss.portal.portlet.invocation.response.RenderResponse;
 import org.jboss.portal.portlet.spi.WindowContext;
-import org.jboss.portal.test.wsrp.framework.TestWSRPProducerImpl;
 import org.jboss.portal.test.wsrp.framework.support.BasicInstanceContext;
 import org.jboss.portal.test.wsrp.framework.support.BasicSecurityContext;
 import org.jboss.portal.test.wsrp.framework.support.BasicUserContext;
-import org.jboss.portal.test.wsrp.framework.support.ServiceObjectFactory;
 import org.jboss.portal.test.wsrp.framework.support.TestPortletInvocationContext;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.BasicBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.EmptyMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.NullMarkupBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.SessionBehavior;
 import org.jboss.portal.wsrp.consumer.ProducerSessionInformation;
 import org.jboss.portal.wsrp.core.CookieProtocol;
 
@@ -56,31 +58,26 @@
       super();
    }
 
-   public void testEmptyAndNullRender() throws Exception
+   public void testEmptyRender() throws Exception
    {
-      RenderInvocation render = createRenderInvocation(ServiceObjectFactory.NULL_MARKUP_PORTLET_HANDLE);
+      checkRenderResult(consumer.invoke(createRenderInvocation(EmptyMarkupBehavior.PORTLET_HANDLE)), "");
+   }
 
-      PortletInvocationResponse response = consumer.invoke(render);
-
-      assertTrue(response instanceof ErrorResponse);
-
-      render = createRenderInvocation(ServiceObjectFactory.EMPTY_MARKUP_PORTLET_HANDLE);
-
-      response = consumer.invoke(render);
-
-      checkRenderResult(response, "");
+   public void testNullRender() throws Exception
+   {
+      assertTrue(consumer.invoke(createRenderInvocation(NullMarkupBehavior.PORTLET_HANDLE)) instanceof ErrorResponse);
    }
 
    public void testRender() throws Exception
    {
-      RenderInvocation render = createRenderInvocation(ServiceObjectFactory.PORTLET_HANDLE_1);
+      RenderInvocation render = createRenderInvocation(BasicBehavior.PORTLET_HANDLE);
 
       PortletInvocationResponse response = consumer.invoke(render);
 
       FragmentResponse result = checkRenderResult(response, "portlet1:view:maximized");
       assertEquals(15, result.getExpirationSecs());
 
-      render = createRenderInvocation(ServiceObjectFactory.PORTLET_HANDLE_2);
+      render = createRenderInvocation(SessionBehavior.PORTLET_HANDLE);
 
       response = consumer.invoke(render);
 
@@ -92,10 +89,10 @@
    {
       TestPortletInvocationContext ac = new TestPortletInvocationContext();
       ActionInvocation action = new ActionInvocation(ac);
-      action.setInstanceContext(new BasicInstanceContext(ServiceObjectFactory.PORTLET_HANDLE_1));
+      action.setInstanceContext(new BasicInstanceContext(BasicBehavior.PORTLET_HANDLE));
       action.setSecurityContext(new BasicSecurityContext());
       action.setUserContext(new BasicUserContext());
-      action.setAttribute(PortletInvocation.REQUEST_SCOPE, PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, new PortletContext(ServiceObjectFactory.PORTLET_HANDLE_1));
+      action.setAttribute(PortletInvocation.REQUEST_SCOPE, PortletInvocation.PORTLET_CONTEXT_ATTRIBUTE, new PortletContext(BasicBehavior.PORTLET_HANDLE));
 
       PortletInvocationResponse response = consumer.invoke(action);
       assertNotNull(response);
@@ -103,7 +100,7 @@
       RenderResponse render = (RenderResponse)response;
       assertEquals("ns1", render.getNavigationalState().getStringValue());
 
-      RenderInvocation renderInvocation = createRenderInvocation(ServiceObjectFactory.PORTLET_HANDLE_1);
+      RenderInvocation renderInvocation = createRenderInvocation(BasicBehavior.PORTLET_HANDLE);
       ((TestPortletInvocationContext)renderInvocation.getContext()).setNs("ns1");
 
       response = consumer.invoke(renderInvocation);
@@ -112,7 +109,7 @@
 
    public void testSessionHandling() throws Exception
    {
-      RenderInvocation render = createRenderInvocation(ServiceObjectFactory.PORTLET_HANDLE_2);
+      RenderInvocation render = createRenderInvocation(SessionBehavior.PORTLET_HANDLE);
 
       PortletInvocationResponse response = consumer.invoke(render);
 
@@ -120,9 +117,9 @@
 
       // checking session information
       ProducerSessionInformation sessionInfo = consumer.getProducerSessionInformationFrom(render);
-      String sessionId = sessionInfo.getSessionIdForPortlet(ServiceObjectFactory.PORTLET_HANDLE_2);
+      String sessionId = sessionInfo.getSessionIdForPortlet(SessionBehavior.PORTLET_HANDLE);
       assertNotNull(sessionId);
-      assertEquals(TestWSRPProducerImpl.SESSION_ID, sessionId);
+      assertEquals(SessionBehavior.SESSION_ID, sessionId);
       assertNotNull(sessionInfo.getUserCookie());
       assertFalse(sessionInfo.isPerGroupCookies());
       assertFalse(sessionInfo.isInitCookieDone());
@@ -134,7 +131,7 @@
    public void testInitCookie() throws Exception
    {
       // first test that we don't initialize cookies if we don't need it
-      RenderInvocation render = createRenderInvocation(ServiceObjectFactory.PORTLET_HANDLE_1);
+      RenderInvocation render = createRenderInvocation(BasicBehavior.PORTLET_HANDLE);
       TestPortletInvocationContext invocationContext = (TestPortletInvocationContext)render.getContext();
       HttpSession session = invocationContext.getClientRequest().getSession();
       producer.setResponse(invocationContext.getClientResponse());
@@ -147,7 +144,7 @@
 
       // now require cookie initialization and check that everything went well
       producer.setRequiresInitCookie(CookieProtocol.perUser);
-      render = createRenderInvocation(ServiceObjectFactory.PORTLET_HANDLE_1);
+      render = createRenderInvocation(BasicBehavior.PORTLET_HANDLE);
       invocationContext = (TestPortletInvocationContext)render.getContext();
       session = invocationContext.getClientRequest().getSession();
       producer.setResponse(invocationContext.getClientResponse());
@@ -163,7 +160,7 @@
    private FragmentResponse checkRenderResult(PortletInvocationResponse response, String markup)
    {
       assertNotNull(response);
-      assertTrue(response instanceof FragmentResponse);
+      assertTrue("Was expecting a FragmentResponse. Got: " + response, response instanceof FragmentResponse);
       FragmentResponse fragment = (FragmentResponse)response;
       assertEquals(markup, fragment.getChars().toString());
       return fragment;

Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/ServiceDescriptionTestCase.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/ServiceDescriptionTestCase.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/ServiceDescriptionTestCase.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -24,7 +24,8 @@
 
 import org.jboss.portal.portlet.Portlet;
 import org.jboss.portal.portlet.PortletContext;
-import org.jboss.portal.test.wsrp.framework.support.ServiceObjectFactory;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.BasicBehavior;
+import org.jboss.portal.test.wsrp.v1.consumer.producer.SessionBehavior;
 
 import java.util.Set;
 
@@ -53,17 +54,17 @@
       Portlet p1 = portletArray[0];
       Portlet p2 = portletArray[1];
 
-      assertTrue((p1.getContext().getId().equals(ServiceObjectFactory.PORTLET_HANDLE_1) && p2.getContext().getId().equals(ServiceObjectFactory.PORTLET_HANDLE_2)) ||
-         (p2.getContext().getId().equals(ServiceObjectFactory.PORTLET_HANDLE_1) && p1.getContext().getId().equals(ServiceObjectFactory.PORTLET_HANDLE_2)));
+      assertTrue((p1.getContext().getId().equals(BasicBehavior.PORTLET_HANDLE) && p2.getContext().getId().equals(SessionBehavior.PORTLET_HANDLE)) ||
+         (p2.getContext().getId().equals(BasicBehavior.PORTLET_HANDLE) && p1.getContext().getId().equals(SessionBehavior.PORTLET_HANDLE)));
    }
 
    public void testGetPortlet() throws Exception
    {
       //obtain one portlet
-      Portlet portlet = consumer.getPortlet(new PortletContext(ServiceObjectFactory.PORTLET_HANDLE_1));
-      checkPortlet(portlet, "", ServiceObjectFactory.PORTLET_HANDLE_1);
+      Portlet portlet = consumer.getPortlet(new PortletContext(BasicBehavior.PORTLET_HANDLE));
+      checkPortlet(portlet, "", BasicBehavior.PORTLET_HANDLE);
 
-      portlet = consumer.getPortlet(new PortletContext(ServiceObjectFactory.PORTLET_HANDLE_2));
-      checkPortlet(portlet, "2", ServiceObjectFactory.PORTLET_HANDLE_2);
+      portlet = consumer.getPortlet(new PortletContext(SessionBehavior.PORTLET_HANDLE));
+      checkPortlet(portlet, "2", SessionBehavior.PORTLET_HANDLE);
    }
 }

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/BasicBehavior.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/BasicBehavior.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/BasicBehavior.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -0,0 +1,69 @@
+/******************************************************************************
+ * 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.consumer.producer;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.test.wsrp.framework.TestProducerBehavior;
+import org.jboss.portal.wsrp.WSRPConstants;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.core.GetMarkup;
+import org.jboss.portal.wsrp.core.MarkupResponse;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.v1.consumer.producer.BasicProducer">Chris
+ *         Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class BasicBehavior extends TestProducerBehavior
+{
+   public static final String PORTLET_HANDLE = "SamplePortletHandle";
+
+
+   public BasicBehavior()
+   {
+      portletHandle = PORTLET_HANDLE;
+   }
+
+   public String getMarkupString(Mode mode, WindowState windowState, String navigationalState, GetMarkup getMarkup)
+   {
+      StringBuffer markupString = new StringBuffer("portlet1:");
+
+      markupString.append(mode).append(":").append(windowState);
+      if (navigationalState != null)
+      {
+         markupString.append(":").append(navigationalState);
+      }
+
+      return markupString.toString();
+   }
+
+
+   public void modifyResponseIfNeeded(MarkupResponse markupResponse)
+   {
+      // fake markup caching
+      markupResponse.getMarkupContext().setCacheControl(WSRPTypeFactory.createCacheControl(15, WSRPConstants.CACHE_PER_USER));
+   }
+}

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/EmptyMarkupBehavior.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/EmptyMarkupBehavior.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/EmptyMarkupBehavior.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * 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.consumer.producer;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.test.wsrp.framework.TestProducerBehavior;
+import org.jboss.portal.wsrp.core.GetMarkup;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.v1.consumer.producer.EmptyMarkupBehavior">Chris
+ *         Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class EmptyMarkupBehavior extends TestProducerBehavior
+{
+   public static final String PORTLET_HANDLE = "EmptyMarkup";
+
+
+   public EmptyMarkupBehavior()
+   {
+      portletHandle = PORTLET_HANDLE;
+   }
+
+   public String getMarkupString(Mode mode, WindowState windowState, String navigationalState, GetMarkup getMarkup)
+   {
+      return "";
+   }
+}

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/NullMarkupBehavior.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/NullMarkupBehavior.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/NullMarkupBehavior.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -0,0 +1,51 @@
+/******************************************************************************
+ * 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.consumer.producer;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.test.wsrp.framework.TestProducerBehavior;
+import org.jboss.portal.wsrp.core.GetMarkup;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.v1.consumer.producer.NullMarkupBehavior">Chris
+ *         Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class NullMarkupBehavior extends TestProducerBehavior
+{
+   public static final String PORTLET_HANDLE = "NullMarkup";
+
+
+   public NullMarkupBehavior()
+   {
+      portletHandle = PORTLET_HANDLE;
+   }
+
+   public String getMarkupString(Mode mode, WindowState windowState, String navigationalState, GetMarkup getMarkup)
+   {
+      return null;
+   }
+}

Added: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/SessionBehavior.java
===================================================================
--- trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/SessionBehavior.java	2006-10-17 20:28:05 UTC (rev 5474)
+++ trunk/wsrp/src/main/org/jboss/portal/test/wsrp/v1/consumer/producer/SessionBehavior.java	2006-10-17 23:46:19 UTC (rev 5475)
@@ -0,0 +1,84 @@
+/******************************************************************************
+ * 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.consumer.producer;
+
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.test.wsrp.framework.TestProducerBehavior;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
+import org.jboss.portal.wsrp.core.GetMarkup;
+import org.jboss.portal.wsrp.core.MarkupResponse;
+import org.jboss.portal.wsrp.core.SessionContext;
+
+/**
+ * @author <a href="mailto:chris.laprun at jboss.com?subject=org.jboss.portal.test.wsrp.v1.consumer.producer.SessionBehavior">Chris
+ *         Laprun</a>
+ * @version $Revision$
+ * @since 2.6
+ */
+public class SessionBehavior extends TestProducerBehavior
+{
+   public static final String PORTLET_HANDLE = "SecondPortletHandle";
+   public static final String SESSION_ID = "sessionID";
+
+   private int count = 0;
+   private String sessionId;
+
+   public SessionBehavior()
+   {
+      portletHandle = PORTLET_HANDLE;
+   }
+
+   public String getMarkupString(Mode mode, WindowState windowState, String navigationalState, GetMarkup getMarkup)
+   {
+      StringBuffer markupString = new StringBuffer("portlet2:");
+      sessionId = getMarkup.getRuntimeContext().getSessionID();
+
+      // if we have a session, increments count to simulate session usage
+      if (SESSION_ID.equals(sessionId))
+      {
+         count++;
+      }
+      markupString.append(count).append(":");
+
+      markupString.append(mode).append(":").append(windowState);
+      if (navigationalState != null)
+      {
+         markupString.append(":").append(navigationalState);
+      }
+
+      return markupString.toString();
+   }
+
+
+   public void modifyResponseIfNeeded(MarkupResponse markupResponse)
+   {
+      // fakes creation of a portlet session if not already present
+      if (count == 0 || SESSION_ID.equals(sessionId))
+      {
+         SessionContext sessionContext = WSRPTypeFactory.createSessionContext(SESSION_ID, 30);
+         markupResponse.setSessionContext(sessionContext);
+      }
+   }
+}




More information about the jboss-svn-commits mailing list