[gatein-commits] gatein SVN: r6239 - in components/wsrp/trunk: consumer and 11 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Apr 15 09:26:57 EDT 2011


Author: chris.laprun at jboss.com
Date: 2011-04-15 09:26:57 -0400 (Fri, 15 Apr 2011)
New Revision: 6239

Modified:
   components/wsrp/trunk/consumer/pom.xml
   components/wsrp/trunk/pom.xml
   components/wsrp/trunk/producer/pom.xml
   components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
   components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceDescriptionHandler.java
   components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java
   components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v1/WSRP1Producer.java
   components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java
   components/wsrp/trunk/wsrp-producer-war/pom.xml
   components/wsrp/trunk/wsrp-producer-war/src/test/assembly/test-producer.xml
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java
   components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/V2ProducerBaseTest.java
Log:
- GTNWSRP-45: PortletDescriptions are now generated/updated when a portlet is deployed/removed instead of re-generating all the descriptions each time a service description is asked for.
  This required some changes in the test support to be able to trigger the appropriate events when a portlet is deployed/undeployed. Eventually, tests are still too tied one to another and will need to be cleaned up.

Modified: components/wsrp/trunk/consumer/pom.xml
===================================================================
--- components/wsrp/trunk/consumer/pom.xml	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/consumer/pom.xml	2011-04-15 13:26:57 UTC (rev 6239)
@@ -21,7 +21,8 @@
   ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
       <groupId>org.gatein.wsrp</groupId>
       <artifactId>wsrp-parent</artifactId>
@@ -117,7 +118,7 @@
       <dependency>
          <groupId>org.mockito</groupId>
          <artifactId>mockito-core</artifactId>
-         <version>1.8.5</version>
+         <version>${version.mockito}</version>
          <scope>test</scope>
       </dependency>
       <dependency>

Modified: components/wsrp/trunk/pom.xml
===================================================================
--- components/wsrp/trunk/pom.xml	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/pom.xml	2011-04-15 13:26:57 UTC (rev 6239)
@@ -59,6 +59,8 @@
       <version.javax.xml.soap.saaj>1.3</version.javax.xml.soap.saaj>
       <version.google-collections>1.0</version.google-collections>
       <version.chromattic>1.1.0-beta2</version.chromattic>
+      <version.arquillian>1.0.0.Alpha2</version.arquillian>
+      <version.mockito>1.8.5</version.mockito>
    </properties>
 
    <dependencyManagement>

Modified: components/wsrp/trunk/producer/pom.xml
===================================================================
--- components/wsrp/trunk/producer/pom.xml	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/producer/pom.xml	2011-04-15 13:26:57 UTC (rev 6239)
@@ -21,7 +21,8 @@
   ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
       <groupId>org.gatein.wsrp</groupId>
       <artifactId>wsrp-parent</artifactId>
@@ -98,10 +99,16 @@
       <dependency>
          <groupId>org.mockito</groupId>
          <artifactId>mockito-core</artifactId>
-         <version>1.8.5</version>
+         <version>${version.mockito}</version>
          <scope>test</scope>
       </dependency>
       <dependency>
+         <groupId>org.objenesis</groupId>
+         <artifactId>objenesis</artifactId>
+         <version>1.1</version>
+         <scope>test</scope>
+      </dependency>
+      <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <scope>test</scope>

Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/WSRPProducerImpl.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -492,11 +492,6 @@
       return serviceDescriptionHandler.getPortletDescription(portletContext, locales, registration);
    }
 
-   public PortletDescription getPortletDescription(Portlet portlet, List<String> locales)
-   {
-      return serviceDescriptionHandler.getPortletDescription(portlet, locales);
-   }
-
    public Registration getRegistrationOrFailIfInvalid(RegistrationContext registrationContext) throws InvalidRegistration, OperationFailed, ModifyRegistrationRequired
    {
       Registration registration = registrationHandler.getRegistrationFrom(registrationContext);
@@ -505,6 +500,11 @@
       return registration;
    }
 
+   public void reset()
+   {
+      serviceDescriptionHandler.reset();
+   }
+
    private Boolean remotableByDefault;
 
    public Boolean isRemotableByDefault()

Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceDescriptionHandler.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceDescriptionHandler.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/ServiceDescriptionHandler.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -75,7 +75,6 @@
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
@@ -93,10 +92,19 @@
    private static final CookieProtocol BEA_8_CONSUMER_FIX = CookieProtocol.PER_USER;
    private ServiceDescriptionInfo serviceDescription;
 
+   private static final List<String> OPTIONS = new ArrayList<String>(5);
+
+   static
+   {
+      OPTIONS.add(WSRP2Constants.OPTIONS_EVENTS);
+      OPTIONS.add(WSRP2Constants.OPTIONS_IMPORT);
+      OPTIONS.add(WSRP2Constants.OPTIONS_EXPORT);
+   }
+
    public ServiceDescriptionHandler(WSRPProducerImpl producer)
    {
       super(producer);
-      serviceDescription = new ServiceDescriptionInfo(producer);
+      reset();
    }
 
    public ServiceDescription getServiceDescription(GetServiceDescription gs)
@@ -126,20 +134,6 @@
          // if we allow sending portlet descriptions even when not registered
          boolean needsPortletDescriptions = !(registration == null && requirements.isRegistrationRequired()
             && requirements.isRegistrationRequiredForFullDescription());
-         if (needsPortletDescriptions)
-         {
-            Set<Portlet> portlets;
-            try
-            {
-               portlets = producer.getRemotablePortlets();
-            }
-            catch (PortletInvokerException e)
-            {
-               log.warn("Could not retrieve portlets. Reason:\n\t" + e.getLocalizedMessage());
-               portlets = Collections.emptySet();
-            }
-            serviceDescription.updatePortletDescriptions(portlets, gs.getDesiredLocales(), registration);
-         }
 
          return serviceDescription.getServiceDescription(needsRegistrationProperties, needsPortletDescriptions, gs.getPortletHandles());
       }
@@ -149,192 +143,21 @@
       }
    }
 
-   public PortletDescription getPortletDescription(PortletContext portletContext, List<String> desiredLocales, Registration registration) throws InvalidHandle, OperationFailed
-   {
-      ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "portlet context");
-      Portlet portlet;
-      try
-      {
-         portlet = producer.getPortletWith(WSRPUtils.convertToPortalPortletContext(portletContext), registration);
-         return getPortletDescription(portlet, desiredLocales);
-      }
-      catch (PortletInvokerException e)
-      {
-         throw WSRP2ExceptionFactory.throwWSException(OperationFailed.class, "Could not retrieve portlet '" + portletContext + "'", e);
-      }
-   }
-
    /**
     * Creates a PortletDescription based on the user desired locales (ordered according to user preferences) for the
     * specified component.
     *
-    * @param portlet
+    * @param portletContext the PortletContext of the portlet for which a PortletDescription is needed
     * @param desiredLocales the user desired locales (ordered according to user preferences) to use for the description
     * @return a PortletDescription describing the specified portlet
     */
-   public static PortletDescription getPortletDescription(Portlet portlet, List<String> desiredLocales)
+   public PortletDescription getPortletDescription(PortletContext portletContext, List<String> desiredLocales, Registration registration) throws InvalidHandle, OperationFailed
    {
-      return getPortletDescription(portlet, desiredLocales, null);
-   }
+      ParameterValidation.throwIllegalArgExceptionIfNull(portletContext, "portlet context");
 
-   /**
-    * Creates a PortletDescription based on the user desired locales (ordered according to user preferences) for the
-    * specified component.
-    *
-    * @param portlet
-    * @param desiredLocales the user desired locales (ordered according to user preferences) to use for the description
-    * @return a PortletDescription describing the specified portlet
-    */
-   static PortletDescription getPortletDescription(Portlet portlet, List<String> desiredLocales, ServiceDescriptionInfo sdi)
-   {
-      return getPortletDescription(portlet.getContext(), portlet.getInfo(), desiredLocales, sdi);
+      return serviceDescription.getPortletDescription(portletContext, desiredLocales, registration);
    }
 
-   private static PortletDescription getPortletDescription(org.gatein.pc.api.PortletContext context, PortletInfo info, List<String> desiredLocales, ServiceDescriptionInfo sdi)
-   {
-      String handle = context.getId();
-      if (log.isDebugEnabled())
-      {
-         log.debug("Constructing portlet description for: " + handle);
-      }
-
-      CapabilitiesInfo capInfo = info.getCapabilities();
-      Collection<MediaType> allMediaTypes = capInfo.getMediaTypes();
-      List<MarkupType> markupTypes = new ArrayList<MarkupType>(allMediaTypes.size());
-      for (MediaType mediaType : allMediaTypes)
-      {
-         MarkupType markupType = WSRPTypeFactory.createMarkupType(mediaType.getValue(),
-            getModeNamesFrom(capInfo.getModes(mediaType)), getWindowStateNamesFrom(capInfo.getWindowStates(mediaType)),
-            getLocaleNamesFrom(capInfo.getLocales(mediaType)));
-         markupTypes.add(markupType);
-      }
-
-      PortletDescription desc = WSRPTypeFactory.createPortletDescription(handle, markupTypes);
-
-      // group ID
-      desc.setGroupID(info.getApplicationName());
-
-      MetaInfo metaInfo = info.getMeta();
-
-      // description
-      desc.setDescription(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DESCRIPTION), desiredLocales));
-
-      // short title
-      desc.setShortTitle(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.SHORT_TITLE), desiredLocales));
-
-      // title
-      desc.setTitle(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.TITLE), desiredLocales));
-
-      // display name
-      desc.setDisplayName(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME), desiredLocales));
-
-      // keywords
-      // metaInfo contains comma-separated keywords: we need to extract them into a list
-      org.oasis.wsrp.v2.LocalizedString concatenatedKeywords =
-         Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.KEYWORDS), desiredLocales);
-      if (concatenatedKeywords != null)
-      {
-         String commaSeparatedKeywords = concatenatedKeywords.getValue();
-         if (commaSeparatedKeywords != null && commaSeparatedKeywords.length() > 0)
-         {
-            String lang = concatenatedKeywords.getLang();
-            String[] keywordArray = commaSeparatedKeywords.split(",");
-            for (String keyword : keywordArray)
-            {
-               // todo: fix resource name
-               desc.getKeywords().add(WSRPTypeFactory.createLocalizedString(lang, concatenatedKeywords.getResourceName(), keyword.trim()));
-            }
-         }
-      }
-
-      // events
-      EventingInfo eventsInfo = info.getEventing();
-      if (eventsInfo != null)
-      {
-         Map<QName, ? extends EventInfo> producedEvents = eventsInfo.getProducedEvents();
-         if (ParameterValidation.existsAndIsNotEmpty(producedEvents))
-         {
-            List<QName> publishedEvents = desc.getPublishedEvents();
-            for (Map.Entry<QName, ? extends EventInfo> entry : producedEvents.entrySet())
-            {
-               publishedEvents.add(entry.getKey());
-
-               // record event info in ServiceDescriptionInfo
-               if (sdi != null)
-               {
-                  sdi.addEventInfo(entry.getValue(), desiredLocales);
-               }
-            }
-         }
-         Map<QName, ? extends EventInfo> consumedEvents = eventsInfo.getConsumedEvents();
-         if (ParameterValidation.existsAndIsNotEmpty(consumedEvents))
-         {
-            List<QName> handledEvents = desc.getHandledEvents();
-            for (Map.Entry<QName, ? extends EventInfo> entry : consumedEvents.entrySet())
-            {
-               handledEvents.add(entry.getKey());
-
-               // record event info in ServiceDescriptionInfo
-               if (sdi != null)
-               {
-                  sdi.addEventInfo(entry.getValue(), desiredLocales);
-               }
-            }
-         }
-      }
-
-      // public parameters
-      NavigationInfo navigationInfo = info.getNavigation();
-      if (navigationInfo != null)
-      {
-         Collection<? extends ParameterInfo> parameterInfos = navigationInfo.getPublicParameters();
-         if (ParameterValidation.existsAndIsNotEmpty(parameterInfos))
-         {
-            List<ParameterDescription> publicValueDescriptions = desc.getNavigationalPublicValueDescriptions();
-            for (ParameterInfo parameterInfo : parameterInfos)
-            {
-               String id = parameterInfo.getId();
-               ParameterDescription paramDesc = WSRPTypeFactory.createParameterDescription(id);
-               paramDesc.setDescription(Utils.convertToWSRPLocalizedString(parameterInfo.getDescription(), desiredLocales));
-               paramDesc.setLabel(WSRPTypeFactory.createLocalizedString(id));
-               List<QName> names = paramDesc.getNames();
-               names.add(parameterInfo.getName());
-               Collection<QName> aliases = parameterInfo.getAliases();
-               if (ParameterValidation.existsAndIsNotEmpty(aliases))
-               {
-                  names.addAll(aliases);
-               }
-
-               publicValueDescriptions.add(paramDesc);
-            }
-         }
-      }
-
-      // security
-      SecurityInfo secInfo = info.getSecurity();
-      if (secInfo.containsTransportGuarantee(TransportGuarantee.INTEGRAL)
-         || secInfo.containsTransportGuarantee(TransportGuarantee.CONFIDENTIAL))
-      {
-         desc.setOnlySecure(true);
-      }
-
-      /* todo:
-      * [O] ID	portletID
-      * [O] string	userCategories[]
-      * [O] string	userProfileItems[]
-      * [O] string	portletManagedModes[]
-      * [O] boolean	usesMethodGet
-      * [O] boolean	defaultMarkupSecure
-      * [O] boolean	userContextStoredInSession
-      * [O] boolean	templatesStoredInSession
-      * [O] boolean	hasUserSpecificState
-      * [O] boolean	doesUrlTemplateProcessing
-      * [O] boolean	mayReturnPortletState
-      * [O] Extension	extensions[]
-      */
-      return desc;
-   }
-
    public void onEvent(ManagedObjectRegistryEvent event)
    {
       if (event instanceof ManagedObjectEvent)
@@ -347,22 +170,20 @@
             ManagedPortletContainer portletContainer = (ManagedPortletContainer)managedObject;
             String applicationId = portletContainer.getManagedPortletApplication().getId();
             String containerId = portletContainer.getId();
-            // need PC 2.2.0-Beta06 API support
-//            org.gatein.pc.api.PortletContext pc = org.gatein.pc.api.PortletContext.createPortletContext(applicationId, containerId);
 
-            // todo: GTNWSRP-45: implement refreshing of ServiceDescriptionInfo
+            org.gatein.pc.api.PortletContext pc = org.gatein.pc.api.PortletContext.createPortletContext(applicationId, containerId);
+
             if (managedObjectEvent instanceof ManagedObjectLifeCycleEvent)
             {
                ManagedObjectLifeCycleEvent lifeCycleEvent = (ManagedObjectLifeCycleEvent)managedObjectEvent;
                LifeCycleStatus status = lifeCycleEvent.getStatus();
                if (LifeCycleStatus.STARTED.equals(status))
                {
-                  // todo: add portlet description for newly started portlet container
-//                  getPortletDescription(pc, portletContainer.getInfo(), )
+                  serviceDescription.addPortletDescription(pc, portletContainer.getInfo());
                }
                else
                {
-                  // todo: remore portlet description for stopped portlet container
+                  serviceDescription.removePortletDescription(pc);
                }
             }
          }
@@ -404,50 +225,35 @@
       return result;
    }
 
-   private static class ServiceDescriptionInfo
+   public void reset()
    {
-      /** Empty service description: no registration properties, no offered portlets */
-      private ServiceDescription noRegistrationNoPortletsServiceDescription;
-      /** No registration properties, offered portles */
-      private ServiceDescription noRegistrationPortletsServiceDescription;
-      /** Registration properties, no offered portlets */
-      private ServiceDescription registrationNoPortletsServiceDescription;
-      /** Registration properties, offered portlets */
-      private ServiceDescription registrationPortletsServiceDescription;
+      serviceDescription = new ServiceDescriptionInfo();
+   }
 
+   private class ServiceDescriptionInfo
+   {
       private long lastGenerated;
       private Map<QName, EventDescription> eventDescriptions;
+      private Map<QName, Integer> eventReferenceCount;
+      private Map<String, PortletDescription> portletDescriptions;
+      private ModelDescription registrationProperties;
+      private boolean initialized = false;
+      private boolean requireRegistrations;
 
-      private static final List<String> OPTIONS = new ArrayList<String>(5);
-
-      static
+      private ServiceDescriptionInfo()
       {
-         OPTIONS.add(WSRP2Constants.OPTIONS_EVENTS);
-         OPTIONS.add(WSRP2Constants.OPTIONS_IMPORT);
-         OPTIONS.add(WSRP2Constants.OPTIONS_EXPORT);
+         reset();
       }
 
-      private ServiceDescriptionInfo(WSRPProducerImpl producer)
+      void reset()
       {
-         noRegistrationNoPortletsServiceDescription = WSRPTypeFactory.createServiceDescription(false);
-         noRegistrationNoPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
-         noRegistrationNoPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
-         noRegistrationNoPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
-
-         noRegistrationPortletsServiceDescription = WSRPTypeFactory.createServiceDescription(false);
-         noRegistrationPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
-         noRegistrationPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
-         noRegistrationPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
-
-         registrationNoPortletsServiceDescription = WSRPTypeFactory.createServiceDescription(false);
-         registrationNoPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
-         registrationNoPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
-         registrationNoPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
-
-         registrationPortletsServiceDescription = WSRPTypeFactory.createServiceDescription(false);
-         registrationPortletsServiceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
-         registrationPortletsServiceDescription.getLocales().addAll(producer.getSupportedLocales());
-         registrationPortletsServiceDescription.getSupportedOptions().addAll(OPTIONS);
+         lastGenerated = 0;
+         eventDescriptions = new HashMap<QName, EventDescription>(37);
+         eventReferenceCount = new HashMap<QName, Integer>(37);
+         portletDescriptions = new HashMap<String, PortletDescription>(37);
+         registrationProperties = null;
+         initialized = false;
+         requireRegistrations = false;
       }
 
       private void updateRegistrationProperties(ProducerRegistrationRequirements requirements)
@@ -462,123 +268,95 @@
 
             // do not create a ModelDescription if there is no registration properties
             Map<QName, RegistrationPropertyDescription> info = requirements.getRegistrationProperties();
-            ModelDescription registrationProperties = null;
             if (ParameterValidation.existsAndIsNotEmpty(info))
             {
                registrationProperties = Utils.convertRegistrationPropertiesToModelDescription(info);
             }
-            registrationNoPortletsServiceDescription.setRegistrationPropertyDescription(registrationProperties);
-            registrationPortletsServiceDescription.setRegistrationPropertyDescription(registrationProperties);
+            else
+            {
+               registrationProperties = null;
+            }
 
             // update need to register
-            noRegistrationNoPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
-            noRegistrationPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
-            registrationNoPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
-            registrationPortletsServiceDescription.setRequiresRegistration(requirements.isRegistrationRequired());
+            requireRegistrations = requirements.isRegistrationRequired();
 
             lastGenerated = System.nanoTime();
          }
       }
 
-      private void updatePortletDescriptions(Set<Portlet> portlets, List<String> desiredLocales, Registration registration)
+      private void updatePortletDescriptions()
       {
-         if (ParameterValidation.existsAndIsNotEmpty(portlets))
+         try
          {
-            Collection<PortletDescription> offeredPortletDescriptions = new ArrayList<PortletDescription>(portlets.size());
-
-            // reset event descriptions as they will be repopulated when we build the portlet descriptions
-            eventDescriptions = new HashMap<QName, EventDescription>(portlets.size());
-
-            for (Portlet portlet : portlets)
+            Set<Portlet> portlets = producer.getRemotablePortlets();
+            if (ParameterValidation.existsAndIsNotEmpty(portlets))
             {
-               PortletDescription desc = getPortletDescription(portlet, desiredLocales, this);
-               offeredPortletDescriptions.add(desc);
+               for (Portlet portlet : portlets)
+               {
+                  addPortletDescription(portlet.getContext(), portlet.getInfo());
+               }
             }
 
-            // events
-            Collection<EventDescription> events = eventDescriptions.values();
-            List<EventDescription> eventDescriptions = registrationPortletsServiceDescription.getEventDescriptions();
-            eventDescriptions.clear();
-            eventDescriptions.addAll(events);
-
-            eventDescriptions = registrationNoPortletsServiceDescription.getEventDescriptions();
-            eventDescriptions.clear();
-            eventDescriptions.addAll(events);
-
-            eventDescriptions = noRegistrationPortletsServiceDescription.getEventDescriptions();
-            eventDescriptions.clear();
-            eventDescriptions.addAll(events);
-
-            eventDescriptions = noRegistrationNoPortletsServiceDescription.getEventDescriptions();
-            eventDescriptions.clear();
-            eventDescriptions.addAll(events);
-
-            // portlets
-            List<PortletDescription> offeredPortlets = registrationPortletsServiceDescription.getOfferedPortlets();
-            offeredPortlets.clear();
-            offeredPortlets.addAll(offeredPortletDescriptions);
-
-            offeredPortlets = noRegistrationPortletsServiceDescription.getOfferedPortlets();
-            offeredPortlets.clear();
-            offeredPortlets.addAll(offeredPortletDescriptions);
+            initialized = true;
          }
+         catch (PortletInvokerException e)
+         {
+            log.warn("Couldn't get remotable portlets", e);
+         }
       }
 
       private ServiceDescription getServiceDescription(boolean needsRegistrationProperties, boolean needsPortletDescriptions, List<String> portletHandles)
       {
-         ServiceDescription serviceDescription;
-         if (needsRegistrationProperties)
-         {
-            serviceDescription = needsPortletDescriptions ? registrationPortletsServiceDescription : registrationNoPortletsServiceDescription;
-         }
-         else
-         {
-            serviceDescription = needsPortletDescriptions ? noRegistrationPortletsServiceDescription : noRegistrationNoPortletsServiceDescription;
-         }
+         initIfNeeded();
 
-         // if we have a list of portlet handles, filter the list of offered portlets
-         if (ParameterValidation.existsAndIsNotEmpty(portletHandles))
+         ModelDescription registrationProperties = needsRegistrationProperties ? this.registrationProperties : null;
+
+         ServiceDescription serviceDescription = WSRPTypeFactory.createServiceDescription(false);
+         serviceDescription.setRequiresInitCookie(BEA_8_CONSUMER_FIX);
+         serviceDescription.getLocales().addAll(producer.getSupportedLocales());
+         serviceDescription.getSupportedOptions().addAll(OPTIONS);
+         serviceDescription.setRegistrationPropertyDescription(registrationProperties);
+         serviceDescription.setRequiresRegistration(requireRegistrations);
+
+         Collection<PortletDescription> portlets;
+         if (needsPortletDescriptions)
          {
-            List<PortletDescription> offeredPortlets = serviceDescription.getOfferedPortlets();
-            List<PortletDescription> filteredPortlets = new ArrayList<PortletDescription>(offeredPortlets.size());
-            for (String handle : portletHandles)
+            // if we have a list of portlet handles, filter the list of offered portlets
+            if (ParameterValidation.existsAndIsNotEmpty(portletHandles))
             {
-               for (PortletDescription description : offeredPortlets)
+               portlets = new ArrayList<PortletDescription>(portletHandles.size());
+               for (String handle : portletHandles)
                {
-                  if (description.getPortletHandle().equals(handle))
+                  PortletDescription description = portletDescriptions.get(handle);
+                  if (description != null)
                   {
-                     filteredPortlets.add(description);
-                     break; // no need to continue looping over portlets for this particular handle
+                     portlets.add(description);
                   }
                }
             }
+            else
+            {
+               portlets = portletDescriptions.values();
+            }
+            serviceDescription.getOfferedPortlets().addAll(portlets);
+         }
 
-            // shallow-clone the existing service description since we're not modifying it apart from the offered portlets list
-            ServiceDescription filtered = WSRPTypeFactory.createServiceDescription(serviceDescription.isRequiresRegistration());
-            filtered.setExportDescription(serviceDescription.getExportDescription());
-            filtered.setMayReturnRegistrationState(serviceDescription.isMayReturnRegistrationState());
-            filtered.setRegistrationPropertyDescription(serviceDescription.getRegistrationPropertyDescription());
-            filtered.setRequiresInitCookie(serviceDescription.getRequiresInitCookie());
-            filtered.setResourceList(serviceDescription.getResourceList());
-            filtered.setSchemaType(serviceDescription.getSchemaType());
-            filtered.getCustomModeDescriptions().addAll(serviceDescription.getCustomModeDescriptions());
-            filtered.getCustomWindowStateDescriptions().addAll(serviceDescription.getCustomWindowStateDescriptions());
-            filtered.getEventDescriptions().addAll(serviceDescription.getEventDescriptions());
-            filtered.getExtensionDescriptions().addAll(serviceDescription.getExtensionDescriptions());
-            filtered.getExtensions().addAll(serviceDescription.getExtensions());
-            filtered.getLocales().addAll(serviceDescription.getLocales());
-            filtered.getSupportedOptions().addAll(serviceDescription.getSupportedOptions());
+         // events
+         Collection<EventDescription> events = eventDescriptions.values();
+         serviceDescription.getEventDescriptions().addAll(events);
 
-            // add filtered portlets
-            filtered.getOfferedPortlets().addAll(filteredPortlets);
+         return serviceDescription;
+      }
 
-            return filtered;
+      private void initIfNeeded()
+      {
+         if (!initialized)
+         {
+            updatePortletDescriptions();
          }
-
-         return serviceDescription;
       }
 
-      public void addEventInfo(EventInfo info, List<String> desiredLocales)
+      private void addEventInfo(EventInfo info, List<String> desiredLocales)
       {
          QName name = info.getName();
          if (!eventDescriptions.containsKey(name))
@@ -593,7 +371,240 @@
             }
             // todo: deal with type info...
             eventDescriptions.put(name, desc);
+            eventReferenceCount.put(name, 1);
          }
+         else
+         {
+            Integer current = eventReferenceCount.get(name);
+            eventReferenceCount.put(name, current + 1); // increase reference count
+         }
       }
+
+      private void removeEvent(QName name)
+      {
+         Integer current = eventReferenceCount.get(name);
+         if (current != null)
+         {
+            if (current == 1)
+            {
+               eventDescriptions.remove(name);
+               eventReferenceCount.remove(name);
+            }
+            else
+            {
+               eventReferenceCount.put(name, current - 1);
+            }
+         }
+      }
+
+      private void addPortletDescription(org.gatein.pc.api.PortletContext context, PortletInfo info)
+      {
+         List<String> locales = producer.getSupportedLocales();
+
+         String handle = context.getId();
+         PortletDescription desc = createPortletDescription(info, locales, handle);
+
+         portletDescriptions.put(handle, desc);
+      }
+
+      private PortletDescription createPortletDescription(PortletInfo info, List<String> locales, String handle)
+      {
+         if (log.isDebugEnabled())
+         {
+            log.debug("Constructing portlet description for: " + handle);
+         }
+
+         CapabilitiesInfo capInfo = info.getCapabilities();
+         Collection<MediaType> allMediaTypes = capInfo.getMediaTypes();
+         List<MarkupType> markupTypes = new ArrayList<MarkupType>(allMediaTypes.size());
+         for (MediaType mediaType : allMediaTypes)
+         {
+            MarkupType markupType = WSRPTypeFactory.createMarkupType(mediaType.getValue(),
+               getModeNamesFrom(capInfo.getModes(mediaType)), getWindowStateNamesFrom(capInfo.getWindowStates(mediaType)),
+               getLocaleNamesFrom(capInfo.getLocales(mediaType)));
+            markupTypes.add(markupType);
+         }
+
+         PortletDescription desc = WSRPTypeFactory.createPortletDescription(handle, markupTypes);
+
+         // group ID
+         desc.setGroupID(info.getApplicationName());
+
+         MetaInfo metaInfo = info.getMeta();
+
+         // description
+         desc.setDescription(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DESCRIPTION), locales));
+
+         // short title
+         desc.setShortTitle(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.SHORT_TITLE), locales));
+
+         // title
+         desc.setTitle(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.TITLE), locales));
+
+         // display name
+         desc.setDisplayName(Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME), locales));
+
+         // keywords
+         // metaInfo contains comma-separated keywords: we need to extract them into a list
+         org.oasis.wsrp.v2.LocalizedString concatenatedKeywords =
+            Utils.convertToWSRPLocalizedString(metaInfo.getMetaValue(MetaInfo.KEYWORDS), locales);
+         if (concatenatedKeywords != null)
+         {
+            String commaSeparatedKeywords = concatenatedKeywords.getValue();
+            if (commaSeparatedKeywords != null && commaSeparatedKeywords.length() > 0)
+            {
+               String lang = concatenatedKeywords.getLang();
+               String[] keywordArray = commaSeparatedKeywords.split(",");
+               for (String keyword : keywordArray)
+               {
+                  // todo: fix resource name
+                  desc.getKeywords().add(WSRPTypeFactory.createLocalizedString(lang, concatenatedKeywords.getResourceName(), keyword.trim()));
+               }
+            }
+         }
+
+         // events
+         EventingInfo eventsInfo = info.getEventing();
+         if (eventsInfo != null)
+         {
+            Map<QName, ? extends EventInfo> producedEvents = eventsInfo.getProducedEvents();
+            if (ParameterValidation.existsAndIsNotEmpty(producedEvents))
+            {
+               List<QName> publishedEvents = desc.getPublishedEvents();
+               for (Map.Entry<QName, ? extends EventInfo> entry : producedEvents.entrySet())
+               {
+                  publishedEvents.add(entry.getKey());
+                  addEventInfo(entry.getValue(), locales);
+               }
+            }
+            Map<QName, ? extends EventInfo> consumedEvents = eventsInfo.getConsumedEvents();
+            if (ParameterValidation.existsAndIsNotEmpty(consumedEvents))
+            {
+               List<QName> handledEvents = desc.getHandledEvents();
+               for (Map.Entry<QName, ? extends EventInfo> entry : consumedEvents.entrySet())
+               {
+                  handledEvents.add(entry.getKey());
+                  addEventInfo(entry.getValue(), locales);
+               }
+            }
+         }
+
+         // public parameters
+         NavigationInfo navigationInfo = info.getNavigation();
+         if (navigationInfo != null)
+         {
+            Collection<? extends ParameterInfo> parameterInfos = navigationInfo.getPublicParameters();
+            if (ParameterValidation.existsAndIsNotEmpty(parameterInfos))
+            {
+               List<ParameterDescription> publicValueDescriptions = desc.getNavigationalPublicValueDescriptions();
+               for (ParameterInfo parameterInfo : parameterInfos)
+               {
+                  String id = parameterInfo.getId();
+                  ParameterDescription paramDesc = WSRPTypeFactory.createParameterDescription(id);
+                  paramDesc.setDescription(Utils.convertToWSRPLocalizedString(parameterInfo.getDescription(), locales));
+                  paramDesc.setLabel(WSRPTypeFactory.createLocalizedString(id));
+                  List<QName> names = paramDesc.getNames();
+                  names.add(parameterInfo.getName());
+                  Collection<QName> aliases = parameterInfo.getAliases();
+                  if (ParameterValidation.existsAndIsNotEmpty(aliases))
+                  {
+                     names.addAll(aliases);
+                  }
+
+                  publicValueDescriptions.add(paramDesc);
+               }
+            }
+         }
+
+         // security
+         SecurityInfo secInfo = info.getSecurity();
+         if (secInfo.containsTransportGuarantee(TransportGuarantee.INTEGRAL)
+            || secInfo.containsTransportGuarantee(TransportGuarantee.CONFIDENTIAL))
+         {
+            desc.setOnlySecure(true);
+         }
+
+         /* todo:
+         *[O]ID portletID
+         *[O]string userCategories[]
+         *[O]string userProfileItems[]
+         *[O]string portletManagedModes[]
+         *[O]boolean usesMethodGet
+         *[O]boolean defaultMarkupSecure
+         *[O]boolean userContextStoredInSession
+         *[O]boolean templatesStoredInSession
+         *[O]boolean hasUserSpecificState
+         *[O]boolean doesUrlTemplateProcessing
+         *[O]boolean mayReturnPortletState
+         *[O]Extension extensions[]
+         */
+         return desc;
+      }
+
+      /**
+       * TODO: Adapt to desired locales
+       *
+       * @param context
+       * @param desiredLocales
+       * @param registration
+       * @return
+       */
+      public PortletDescription getPortletDescription(PortletContext context, List<String> desiredLocales, Registration registration)
+      {
+         initIfNeeded();
+
+         org.gatein.pc.api.PortletContext pcContext = WSRPUtils.convertToPortalPortletContext(context);
+         if (producer.getRegistrationManager().getPolicy().allowAccessTo(pcContext, registration, "getPortletDescription"))
+         {
+            PortletDescription description = portletDescriptions.get(context.getPortletHandle());
+
+            if (description == null)
+            {
+               // check if we asked for the description of a clone
+               if (registration.knows(pcContext))
+               {
+                  try
+                  {
+                     // retrieve initial context from portlet info and get description from it
+                     Portlet portlet = producer.getPortletWith(pcContext, registration);
+                     PortletInfo info = portlet.getInfo();
+                     org.gatein.pc.api.PortletContext original = org.gatein.pc.api.PortletContext.createPortletContext(info.getApplicationName(), info.getName());
+                     return portletDescriptions.get(original.getId());
+                  }
+                  catch (Exception e)
+                  {
+                     log.debug("Couldn't retrieve portlet " + pcContext, e);
+                     return null;
+                  }
+               }
+            }
+            return description;
+         }
+         else
+         {
+            return null;
+         }
+      }
+
+      public void removePortletDescription(org.gatein.pc.api.PortletContext pc)
+      {
+         String handle = WSRPUtils.convertToWSRPPortletContext(pc).getPortletHandle();
+
+         PortletDescription description = portletDescriptions.get(handle);
+         if (description != null)
+         {
+            // deal with events
+            for (QName event : description.getHandledEvents())
+            {
+               removeEvent(event);
+            }
+            for (QName event : description.getPublishedEvents())
+            {
+               removeEvent(event);
+            }
+
+            portletDescriptions.remove(handle);
+         }
+      }
    }
 }

Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/handlers/processors/ProducerHelper.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -47,4 +47,6 @@
    PortletDescription getPortletDescription(PortletContext portletContext, List<String> locales, Registration registration) throws InvalidHandle, OperationFailed;
 
    Registration getRegistrationOrFailIfInvalid(RegistrationContext registrationContext) throws InvalidRegistration, OperationFailed, ModifyRegistrationRequired;
+
+   void reset();
 }

Modified: components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v1/WSRP1Producer.java
===================================================================
--- components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v1/WSRP1Producer.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/v1/WSRP1Producer.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -24,13 +24,18 @@
 package org.gatein.wsrp.producer.v1;
 
 import org.gatein.exports.ExportManager;
+import org.gatein.pc.api.Portlet;
 import org.gatein.pc.api.PortletInvoker;
+import org.gatein.pc.api.PortletInvokerException;
 import org.gatein.pc.portlet.container.managed.ManagedObjectRegistryEvent;
+import org.gatein.registration.Registration;
 import org.gatein.registration.RegistrationManager;
 import org.gatein.wsrp.api.context.ProducerContext;
 import org.gatein.wsrp.producer.ProducerHolder;
 import org.gatein.wsrp.producer.WSRPProducer;
+import org.gatein.wsrp.producer.WSRPProducerImpl;
 import org.gatein.wsrp.producer.config.ProducerConfigurationService;
+import org.gatein.wsrp.producer.handlers.processors.ProducerHelper;
 import org.gatein.wsrp.producer.v2.WSRP2Producer;
 import org.gatein.wsrp.spec.v1.V1ToV2Converter;
 import org.gatein.wsrp.spec.v1.V2ToV1Converter;
@@ -88,6 +93,7 @@
 import org.oasis.wsrp.v2.OperationFailed;
 import org.oasis.wsrp.v2.OperationNotSupported;
 import org.oasis.wsrp.v2.PortletContext;
+import org.oasis.wsrp.v2.PortletDescription;
 import org.oasis.wsrp.v2.PortletDescriptionResponse;
 import org.oasis.wsrp.v2.PortletPropertyDescriptionResponse;
 import org.oasis.wsrp.v2.PortletStateChangeRequired;
@@ -101,14 +107,35 @@
 import org.oasis.wsrp.v2.UnsupportedMode;
 import org.oasis.wsrp.v2.UnsupportedWindowState;
 
+import java.util.List;
+
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
  * @version $Revision$
  */
 public class WSRP1Producer implements WSRPProducer, V1MarkupInterface, V1PortletManagementInterface,
-   V1RegistrationInterface, V1ServiceDescriptionInterface
+   V1RegistrationInterface, V1ServiceDescriptionInterface, ProducerHelper
 {
+   public Portlet getPortletWith(org.gatein.pc.api.PortletContext portletContext, Registration registration) throws InvalidHandle, PortletInvokerException
+   {
+      return ((ProducerHelper)producer).getPortletWith(portletContext, registration);
+   }
 
+   public PortletDescription getPortletDescription(PortletContext portletContext, List<String> locales, Registration registration) throws InvalidHandle, OperationFailed
+   {
+      return ((ProducerHelper)producer).getPortletDescription(portletContext, locales, registration);
+   }
+
+   public Registration getRegistrationOrFailIfInvalid(RegistrationContext registrationContext) throws InvalidRegistration, OperationFailed, ModifyRegistrationRequired
+   {
+      return ((ProducerHelper)producer).getRegistrationOrFailIfInvalid(registrationContext);
+   }
+
+   public void reset()
+   {
+      ((ProducerHelper)producer).reset();
+   }
+
    // On-demand class holder Singleton pattern (multi-thread safe)
 
    private static final class InstanceHolder

Modified: components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java
===================================================================
--- components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/producer/src/test/java/org/gatein/wsrp/producer/handlers/processors/MimeResponseProcessorTestCase.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -200,5 +200,10 @@
          return null;  //To change body of implemented methods use File | Settings | File Templates.
       }
 
+      public void reset()
+      {
+         //To change body of implemented methods use File | Settings | File Templates.
+      }
+
    }
 }

Modified: components/wsrp/trunk/wsrp-producer-war/pom.xml
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/pom.xml	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/pom.xml	2011-04-15 13:26:57 UTC (rev 6239)
@@ -22,7 +22,8 @@
   ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
   -->
 
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
       <groupId>org.gatein.wsrp</groupId>
       <artifactId>wsrp-parent</artifactId>
@@ -336,27 +337,27 @@
       </dependency>
 
       <dependency>
-         <groupId>org.jboss.arquillian</groupId>
-         <artifactId>arquillian-api</artifactId>
-         <version>1.0.0.Alpha2</version>
+         <groupId>junit</groupId>
+         <artifactId>junit</artifactId>
+         <version>4.8.1</version>
          <scope>test</scope>
       </dependency>
       <dependency>
-         <groupId>junit</groupId>
-         <artifactId>junit</artifactId>
-         <version>4.6</version>
+         <groupId>org.jboss.arquillian</groupId>
+         <artifactId>arquillian-api</artifactId>
+         <version>${version.arquillian}</version>
          <scope>test</scope>
       </dependency>
       <dependency>
          <groupId>org.jboss.arquillian</groupId>
          <artifactId>arquillian-junit</artifactId>
-         <version>1.0.0.Alpha2</version>
+         <version>${version.arquillian}</version>
          <scope>test</scope>
       </dependency>
       <dependency>
          <groupId>org.jboss.arquillian.container</groupId>
          <artifactId>arquillian-jbossas-remote-51</artifactId>
-         <version>1.0.0.Alpha2</version>
+         <version>${version.arquillian}</version>
          <scope>test</scope>
       </dependency>
       <dependency>
@@ -426,6 +427,12 @@
          <version>1.0.3.GA</version>
          <scope>test</scope>
       </dependency>
+      <dependency>
+         <groupId>org.mockito</groupId>
+         <artifactId>mockito-core</artifactId>
+         <version>1.8.5</version>
+         <scope>test</scope>
+      </dependency>
    </dependencies>
 
    <build>

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/assembly/test-producer.xml
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/assembly/test-producer.xml	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/assembly/test-producer.xml	2011-04-15 13:26:57 UTC (rev 6239)
@@ -64,6 +64,10 @@
 
             <include>com.google.collections:google-collections</include>
 
+            <!-- mockito and related dependencies -->
+            <include>org.mockito:mockito-core</include>
+            <include>org.objenesis:objenesis</include>
+
          </includes>
       </dependencySet>
    </dependencySets>

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/producer/WSRPProducerBaseTest.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -24,14 +24,28 @@
 package org.gatein.wsrp.producer;
 
 import junit.framework.TestCase;
+import org.gatein.pc.api.Portlet;
+import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.portlet.container.managed.LifeCycleStatus;
+import org.gatein.pc.portlet.container.managed.ManagedObjectLifeCycleEvent;
+import org.gatein.pc.portlet.container.managed.ManagedPortletApplication;
+import org.gatein.pc.portlet.container.managed.ManagedPortletContainer;
 import org.gatein.registration.RegistrationException;
 import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.producer.handlers.processors.ProducerHelper;
+import org.mockito.Mockito;
 
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.InputStreamReader;
 import java.net.URL;
 import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 /**
  * @author <a href="mailto:boleslaw.dawidowicz at jboss.org">Boleslaw Dawidowicz</a>
@@ -39,6 +53,9 @@
  */
 public abstract class WSRPProducerBaseTest extends TestCase
 {
+   protected Map<String, List<String>> war2Handles = new HashMap<String, List<String>>(7);
+   protected String currentlyDeployedArchiveName;
+
    protected WSRPProducerBaseTest(String name) throws Exception
    {
       super(name);
@@ -46,6 +63,8 @@
 
    protected abstract WSRPProducer getProducer();
 
+   protected abstract ProducerHelper getProducerHelper();
+
    public void deploy(String warFileName) throws Exception
    {
       String deployURLPrefix = System.getProperty("jboss.deploy.url.prefix");
@@ -62,6 +81,60 @@
          BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
          reader.readLine();
          reader.close();
+
+         WSRPProducer producer = getProducer();
+         Set<Portlet> portlets = producer.getPortletInvoker().getPortlets();
+         for (Portlet portlet : portlets)
+         {
+            // trigger management events so that the service description is properly updated
+            org.gatein.pc.api.PortletContext context = portlet.getContext();
+            if (!war2Handles.containsKey(getWarName(context.getId())))
+            {
+               ManagedPortletApplication portletApplication = Mockito.mock(ManagedPortletApplication.class);
+               PortletContext.PortletContextComponents components = context.getComponents();
+               Mockito.stub(portletApplication.getId()).toReturn(components.getApplicationName());
+
+               ManagedPortletContainer portletContainer = Mockito.mock(ManagedPortletContainer.class);
+               Mockito.stub(portletContainer.getManagedPortletApplication()).toReturn(portletApplication);
+               Mockito.stub(portletContainer.getId()).toReturn(components.getPortletName());
+               Mockito.stub(portletContainer.getInfo()).toReturn(portlet.getInfo());
+
+               ManagedObjectLifeCycleEvent lifeCycleEvent = Mockito.mock(ManagedObjectLifeCycleEvent.class);
+               Mockito.stub(lifeCycleEvent.getManagedObject()).toReturn(portletContainer);
+               Mockito.stub(lifeCycleEvent.getStatus()).toReturn(LifeCycleStatus.STARTED);
+
+               producer.onEvent(lifeCycleEvent);
+            }
+         }
+
+         currentlyDeployedArchiveName = warFileName;
+
+         if (!war2Handles.containsKey(warFileName))
+         {
+            Collection<String> portletHandles = getPortletHandles();
+            if (portletHandles != null)
+            {
+               for (String handle : portletHandles)
+               {
+                  String warName = getWarName(handle);
+                  if (warName.equals(warFileName))
+                  {
+                     List<String> handles = war2Handles.get(warName);
+                     if (handles == null)
+                     {
+                        handles = new ArrayList<String>(3);
+                        war2Handles.put(warName, handles);
+                     }
+
+                     handles.add(handle);
+                  }
+               }
+            }
+            else
+            {
+               throw new IllegalArgumentException(warFileName + " didn't contain any portlets...");
+            }
+         }
       }
       else
       {
@@ -74,6 +147,48 @@
       String undeployURLPrefix = System.getProperty("jboss.undeploy.url.prefix");
       if (undeployURLPrefix != null)
       {
+         currentlyDeployedArchiveName = null;
+
+         List<String> handles = war2Handles.get(warFileName);
+         WSRPProducer producer = getProducer();
+         if (handles != null)
+         {
+            for (String handle : handles)
+            {
+               // trigger management events so that the service description is properly updated
+               PortletContext context = PortletContext.createPortletContext(handle);
+
+               try
+               {
+                  Portlet portlet = producer.getPortletInvoker().getPortlet(context);
+                  ManagedPortletApplication portletApplication = Mockito.mock(ManagedPortletApplication.class);
+                  PortletContext.PortletContextComponents components = context.getComponents();
+                  Mockito.stub(portletApplication.getId()).toReturn(components.getApplicationName());
+
+                  ManagedPortletContainer portletContainer = Mockito.mock(ManagedPortletContainer.class);
+                  Mockito.stub(portletContainer.getManagedPortletApplication()).toReturn(portletApplication);
+                  Mockito.stub(portletContainer.getId()).toReturn(components.getPortletName());
+                  Mockito.stub(portletContainer.getInfo()).toReturn(portlet.getInfo());
+
+                  ManagedObjectLifeCycleEvent lifeCycleEvent = Mockito.mock(ManagedObjectLifeCycleEvent.class);
+                  Mockito.stub(lifeCycleEvent.getManagedObject()).toReturn(portletContainer);
+                  Mockito.stub(lifeCycleEvent.getStatus()).toReturn(LifeCycleStatus.STOPPED);
+
+                  producer.onEvent(lifeCycleEvent);
+               }
+               catch (Exception e)
+               {
+                  // do nothing the portlet is already undeployed
+               }
+            }
+         }
+
+         // only remove the mapping if we're not undeploying the most used portlet (optimization, as it avoids parsing the SD)
+         if (removeCurrent(warFileName))
+         {
+            war2Handles.remove(warFileName);
+         }
+
          File archiveDirectory = getDirectory("test.deployables.dir");
          File archiveFile = getArchive(warFileName, archiveDirectory);
 
@@ -92,6 +207,8 @@
       }
    }
 
+   protected abstract boolean removeCurrent(String archiveName);
+
    protected void resetRegistrationInfo() throws RegistrationException
    {
       WSRPProducer producer = getProducer();
@@ -150,6 +267,7 @@
       super.setUp();
 
       resetRegistrationInfo();
+      getProducerHelper().reset();
    }
 
    public void tearDown() throws Exception
@@ -157,4 +275,12 @@
       resetRegistrationInfo();
       super.tearDown();
    }
+
+   protected String getWarName(String handle)
+   {
+      org.gatein.pc.api.PortletContext context = org.gatein.pc.api.PortletContext.createPortletContext(handle);
+      return context.getComponents().getApplicationName() + ".war";
+   }
+
+   protected abstract Collection<String> getPortletHandles() throws Exception;
 }

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/MarkupTestCase.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -130,25 +130,25 @@
       V1GetMarkup getMarkup = createMarkupRequest();
       getMarkup.getRuntimeContext().setNamespacePrefix(null);
       getMarkup.getRuntimeContext().setPortletInstanceKey(null);
-      
+
       assertNull(getMarkup.getRuntimeContext().getNamespacePrefix());
       assertNull(getMarkup.getRuntimeContext().getPortletInstanceKey());
-      
+
       V1MarkupResponse response = producer.getMarkup(getMarkup);
-      
+
       checkMarkupResponse(response, DEFAULT_VIEW_MARKUP);
-      
+
       getMarkup.getRuntimeContext().setNamespacePrefix("");
       getMarkup.getRuntimeContext().setPortletInstanceKey("");
-      
+
       assertSame("", getMarkup.getRuntimeContext().getNamespacePrefix());
       assertSame("", getMarkup.getRuntimeContext().getPortletInstanceKey());
-      
+
       response = producer.getMarkup(getMarkup);
-      
+
       checkMarkupResponse(response, DEFAULT_VIEW_MARKUP);
    }
-   
+
    @Test
    public void testInvalidGetMarkup() throws Exception
    {
@@ -671,14 +671,6 @@
       }
    }
 
-   private V1NamedString createNamedString(String name, String value)
-   {
-      V1NamedString namedString = new V1NamedString();
-      namedString.setName(name);
-      namedString.setValue(value);
-      return namedString;
-   }
-
    @Test
    public void testGetMarkupWithResource() throws Exception
    {
@@ -823,6 +815,14 @@
       }
    }
 
+   private V1NamedString createNamedString(String name, String value)
+   {
+      V1NamedString namedString = new V1NamedString();
+      namedString.setName(name);
+      namedString.setValue(value);
+      return namedString;
+   }
+
    private String checkPBIAndGetNavigationalState(String symbol) throws Exception
    {
       V1PerformBlockingInteraction performBlockingInteraction =

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/NeedPortletHandleTest.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -24,22 +24,15 @@
 package org.gatein.wsrp.protocol.v1;
 
 import org.gatein.wsrp.WSRPConstants;
-import org.gatein.wsrp.spec.v1.WSRP1TypeFactory;
 import org.oasis.wsrp.v1.V1GetMarkup;
-import org.oasis.wsrp.v1.V1GetServiceDescription;
 import org.oasis.wsrp.v1.V1InvalidRegistration;
 import org.oasis.wsrp.v1.V1InvalidRegistrationFault;
 import org.oasis.wsrp.v1.V1MarkupResponse;
 import org.oasis.wsrp.v1.V1OperationFailed;
 import org.oasis.wsrp.v1.V1OperationFailedFault;
-import org.oasis.wsrp.v1.V1PortletDescription;
-import org.oasis.wsrp.v1.V1ServiceDescription;
 
 import java.rmi.RemoteException;
-import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
-import java.util.Map;
 
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
@@ -49,8 +42,6 @@
 public abstract class NeedPortletHandleTest extends V1ProducerBaseTest
 {
    private String mostUsedPortletWARFileName;
-   private String currentlyDeployedArchiveName;
-   private Map<String, List<String>> war2Handles = new HashMap<String, List<String>>(7);
 
 
    public NeedPortletHandleTest(String portletWARFileName)
@@ -96,71 +87,11 @@
       return war2Handles.get(currentlyDeployedArchiveName);
    }
 
-   /**
-    * Each time we deploy a new archive, check to see if the service description has changed and add any new portlet
-    * handles found.
-    *
-    * @param archiveName
-    * @throws Exception
-    */
-   public void deploy(String archiveName) throws Exception
+   protected boolean removeCurrent(String archiveName)
    {
-      super.deploy(archiveName);
-      currentlyDeployedArchiveName = archiveName;
-
-      if (!war2Handles.containsKey(archiveName))
-      {
-         V1GetServiceDescription getServiceDescription = WSRP1TypeFactory.createGetServiceDescription();
-         V1ServiceDescription serviceDescription = producer.getServiceDescription(getServiceDescription);
-         List<V1PortletDescription> offered = serviceDescription.getOfferedPortlets();
-         if (offered != null)
-         {
-            for (V1PortletDescription portletDescription : offered)
-            {
-               String handle = portletDescription.getPortletHandle();
-               String warName = handle.substring(1, handle.indexOf('.')) + ".war";
-               if (warName.equals(archiveName))
-               {
-                  List<String> handles = war2Handles.get(warName);
-                  if (handles == null)
-                  {
-                     handles = new ArrayList<String>(3);
-                     war2Handles.put(warName, handles);
-                  }
-
-                  handles.add(handle);
-               }
-            }
-         }
-         else
-         {
-            throw new IllegalArgumentException(archiveName + " didn't contain any portlets...");
-         }
-      }
+      return !mostUsedPortletWARFileName.equals(archiveName);
    }
 
-   public void undeploy(String archiveName) throws Exception
-   {
-      try
-      {
-         super.undeploy(archiveName);
-      }
-      catch (Exception e)
-      {
-         // if an exception occurred the portlet is still probably deployed, so just exit
-         e.printStackTrace();
-         return;
-      }
-
-      currentlyDeployedArchiveName = null;
-
-      // only remove the mapping if we're not undeploying the most used portlet (optimization, as it avoids parsing the SD)
-      if (!mostUsedPortletWARFileName.equals(archiveName))
-      {
-         war2Handles.remove(archiveName);
-      }
-   }
-
    public void setUp() throws Exception
    {
       super.setUp();

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/RegistrationTestCase.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -80,29 +80,35 @@
       jar.addClass(WSRPProducerBaseTest.class);
       return jar;
    }
-   
+
+   @Override
+   protected boolean removeCurrent(String archiveName)
+   {
+      return true;
+   }
+
    @Before
    public void setUp() throws Exception
    {
       if (System.getProperty("test.deployables.dir") != null)
       {
-       super.setUp();
-       //hack to get around having to have a httpservletrequest when accessing the producer services
-       //I don't know why its really needed, seems to be a dependency where wsrp connects with the pc module
-       ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null), MockHttpServletResponse.createMockResponse());
+         super.setUp();
+         //hack to get around having to have a httpservletrequest when accessing the producer services
+         //I don't know why its really needed, seems to be a dependency where wsrp connects with the pc module
+         ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null), MockHttpServletResponse.createMockResponse());
       }
    }
-   
-   
+
+
    @After
    public void tearDown() throws Exception
    {
-       if (System.getProperty("test.deployables.dir") != null)
-       {
-          super.tearDown();
-       }
+      if (System.getProperty("test.deployables.dir") != null)
+      {
+         super.tearDown();
+      }
    }
-   
+
    /**
     * R355: The portal MUST pass a name for itself that uniquely identifies it.
     *
@@ -151,23 +157,23 @@
    {
       try
       {
-      // check that a registration handle was created
-      V1RegistrationContext rc = registerConsumer();
-      String registrationHandle = rc.getRegistrationHandle();
-      assertNotNull(registrationHandle);
+         // check that a registration handle was created
+         V1RegistrationContext rc = registerConsumer();
+         String registrationHandle = rc.getRegistrationHandle();
+         assertNotNull(registrationHandle);
 
-      // check that a registration was created with that handle
-      RegistrationManager registrationManager = producer.getRegistrationManager();
-      Registration registration = registrationManager.getRegistration(registrationHandle);
-      assertNotNull(registration);
+         // check that a registration was created with that handle
+         RegistrationManager registrationManager = producer.getRegistrationManager();
+         Registration registration = registrationManager.getRegistration(registrationHandle);
+         assertNotNull(registration);
 
-      // check that the registration was persisted...
-      String key = registration.getPersistentKey();
-      assertNotNull(key);
+         // check that the registration was persisted...
+         String key = registration.getPersistentKey();
+         assertNotNull(key);
 
-      // ... and that the handle was created by the policy based on the registration key
-      String expectedHandle = registrationManager.getPolicy().createRegistrationHandleFor(key);
-      assertEquals(expectedHandle, registrationHandle);
+         // ... and that the handle was created by the policy based on the registration key
+         String expectedHandle = registrationManager.getPolicy().createRegistrationHandleFor(key);
+         assertEquals(expectedHandle, registrationHandle);
       }
       catch (Exception e)
       {

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/ServiceDescriptionTestCase.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -78,26 +78,26 @@
       jar.addClass(WSRPProducerBaseTest.class);
       return jar;
    }
-   
+
    @Before
    public void setUp() throws Exception
    {
       if (System.getProperty("test.deployables.dir") != null)
       {
-       super.setUp();
-       //hack to get around having to have a httpservletrequest when accessing the producer services
-       //I don't know why its really needed, seems to be a dependency where wsrp connects with the pc module
-       ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null), MockHttpServletResponse.createMockResponse());
+         super.setUp();
+         //hack to get around having to have a httpservletrequest when accessing the producer services
+         //I don't know why its really needed, seems to be a dependency where wsrp connects with the pc module
+         ServletAccess.setRequestAndResponse(MockHttpServletRequest.createMockRequest(null), MockHttpServletResponse.createMockResponse());
       }
    }
-     
+
    @After
    public void tearDown() throws Exception
    {
-       if (System.getProperty("test.deployables.dir") != null)
-       {
-          super.tearDown();
-       }
+      if (System.getProperty("test.deployables.dir") != null)
+      {
+         super.tearDown();
+      }
    }
 
    @Test
@@ -115,11 +115,11 @@
       // No registration properties
       ExtendedAssert.assertNull(sd.getRegistrationPropertyDescription());
    }
-   
+
    /**
-    * Test to make sure that when switching from required to not-required (and vise-versa) that
-    * the change properly persists to the service description.
-    * 
+    * Test to make sure that when switching from required to not-required (and vise-versa) that the change properly
+    * persists to the service description.
+    *
     * @throws Throwable
     */
    @Test
@@ -128,20 +128,20 @@
       producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(false);
       V1GetServiceDescription gs = getNoRegistrationServiceDescriptionRequest();
       V1ServiceDescription sd = producer.getServiceDescription(gs);
-      
+
       // registration is not required
       ExtendedAssert.assertFalse(sd.isRequiresRegistration());
-      
+
       producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(true);
       gs = getNoRegistrationServiceDescriptionRequest();
       sd = producer.getServiceDescription(gs);
-      
+
       ExtendedAssert.assertTrue(sd.isRequiresRegistration());
-      
+
       producer.getConfigurationService().getConfiguration().getRegistrationRequirements().setRegistrationRequired(false);
       gs = getNoRegistrationServiceDescriptionRequest();
       sd = producer.getServiceDescription(gs);
-      
+
       ExtendedAssert.assertFalse(sd.isRequiresRegistration());
    }
 
@@ -229,4 +229,10 @@
       ExtendedAssert.assertEquals(1, propertyDescriptions.size());
       assertEquals(V2ToV1Converter.toV1PropertyDescription(WSRPUtils.convertToPropertyDescription(regProp)), propertyDescriptions.get(0));
    }
+
+   @Override
+   protected boolean removeCurrent(String archiveName)
+   {
+      return true;
+   }
 }
\ No newline at end of file

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v1/V1ProducerBaseTest.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -23,6 +23,8 @@
 
 package org.gatein.wsrp.protocol.v1;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
 import org.gatein.registration.RegistrationException;
 import org.gatein.registration.RegistrationManager;
 import org.gatein.registration.policies.DefaultRegistrationPolicy;
@@ -32,6 +34,7 @@
 import org.gatein.wsrp.producer.WSRPProducer;
 import org.gatein.wsrp.producer.WSRPProducerBaseTest;
 import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.producer.handlers.processors.ProducerHelper;
 import org.gatein.wsrp.producer.v1.WSRP1Producer;
 import org.gatein.wsrp.registration.RegistrationPropertyDescription;
 import org.gatein.wsrp.spec.v1.WSRP1TypeFactory;
@@ -53,6 +56,7 @@
 
 import javax.xml.namespace.QName;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 
@@ -64,6 +68,13 @@
 public abstract class V1ProducerBaseTest extends WSRPProducerBaseTest
 {
    private static final String CONSUMER = "test-consumer";
+   private static final Function<V1PortletDescription, String> PORTLET_DESCRIPTION_TO_HANDLE = new Function<V1PortletDescription, String>()
+   {
+      public String apply(V1PortletDescription from)
+      {
+         return from.getPortletHandle();
+      }
+   };
    protected WSRP1Producer producer = ProducerHolder.getV1Producer();
 
 
@@ -83,6 +94,12 @@
       return producer;
    }
 
+   @Override
+   protected ProducerHelper getProducerHelper()
+   {
+      return producer;
+   }
+
    /**
     * Checks that the specified portlet description corresponds to the expected description of test-basic-portlet. If
     * the handle parameter is not null, checks that it corresponds to the specified portlet decription.
@@ -269,23 +286,74 @@
 //      ExtendedAssert.assertTrue(cause instanceof SOAPFaultException);
 //      ExtendedAssert.assertEquals(errorCode, ((SOAPFaultException)cause).getFault().getLocalPart());
    }
-   
-   
+
+
    protected V1GetMarkup createDefaultMarkupRequest(String handle)
    {
       V1PortletContext portletContext = WSRP1TypeFactory.createPortletContext(handle);
       return WSRP1TypeFactory.createMarkupRequest(portletContext, createDefaultRuntimeContext(), WSRP1TypeFactory.createDefaultMarkupParams());
    }
-   
+
    protected V1PerformBlockingInteraction createDefaultPerformBlockingInteraction(String handle)
    {
       V1PortletContext portletContext = WSRP1TypeFactory.createPortletContext(handle);
       return WSRP1TypeFactory.createPerformBlockingInteraction(portletContext, createDefaultRuntimeContext(), WSRP1TypeFactory.createDefaultMarkupParams(),
-            WSRP1TypeFactory.createDefaultInteractionParams());
+         WSRP1TypeFactory.createDefaultInteractionParams());
    }
-   
+
    protected V1RuntimeContext createDefaultRuntimeContext()
    {
       return WSRP1TypeFactory.createRuntimeContext(WSRPConstants.NONE_USER_AUTHENTICATION, "foo", "bar");
    }
+
+   /**
+    * Each time we deploy a new archive, check to see if the service description has changed and add any new portlet
+    * handles found.
+    *
+    * @param archiveName
+    * @throws Exception
+    */
+   /*public void deploy(String archiveName) throws Exception
+   {
+      super.deploy(archiveName);
+      currentlyDeployedArchiveName = archiveName;
+
+      if (!war2Handles.containsKey(archiveName))
+      {
+         V1GetServiceDescription getServiceDescription = WSRP1TypeFactory.createGetServiceDescription();
+         V1ServiceDescription serviceDescription = producer.getServiceDescription(getServiceDescription);
+         List<V1PortletDescription> offered = serviceDescription.getOfferedPortlets();
+         if (offered != null)
+         {
+            for (V1PortletDescription portletDescription : offered)
+            {
+               String handle = portletDescription.getPortletHandle();
+               String warName = getWarName(handle);
+               if (warName.equals(archiveName))
+               {
+                  List<String> handles = war2Handles.get(warName);
+                  if (handles == null)
+                  {
+                     handles = new ArrayList<String>(3);
+                     war2Handles.put(warName, handles);
+                  }
+
+                  handles.add(handle);
+               }
+            }
+         }
+         else
+         {
+            throw new IllegalArgumentException(archiveName + " didn't contain any portlets...");
+         }
+      }
+   }*/
+   @Override
+   protected Collection<String> getPortletHandles() throws Exception
+   {
+      V1GetServiceDescription getServiceDescription = WSRP1TypeFactory.createGetServiceDescription();
+      V1ServiceDescription serviceDescription = producer.getServiceDescription(getServiceDescription);
+      List<V1PortletDescription> offered = serviceDescription.getOfferedPortlets();
+      return Collections2.transform(offered, PORTLET_DESCRIPTION_TO_HANDLE);
+   }
 }

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/NeedPortletHandleTest.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -40,6 +40,7 @@
 
 import java.rmi.RemoteException;
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -51,8 +52,6 @@
 public abstract class NeedPortletHandleTest extends V2ProducerBaseTest
 {
    private String mostUsedPortletWARFileName;
-   private String currentlyDeployedArchiveName;
-   private Map<String, List<String>> war2Handles = new HashMap<String, List<String>>(7);
 
 
    public NeedPortletHandleTest(String portletWARFileName)
@@ -98,71 +97,12 @@
       return war2Handles.get(currentlyDeployedArchiveName);
    }
 
-   /**
-    * Each time we deploy a new archive, check to see if the service description has changed and add any new portlet
-    * handles found.
-    *
-    * @param archiveName
-    * @throws Exception
-    */
-   public void deploy(String archiveName) throws Exception
+   @Override
+   protected boolean removeCurrent(String archiveName)
    {
-      super.deploy(archiveName);
-      currentlyDeployedArchiveName = archiveName;
-
-      if (!war2Handles.containsKey(archiveName))
-      {
-         GetServiceDescription getServiceDescription = WSRPTypeFactory.createGetServiceDescription(null, null);
-         ServiceDescription serviceDescription = producer.getServiceDescription(getServiceDescription);
-         List<PortletDescription> offered = serviceDescription.getOfferedPortlets();
-         if (offered != null)
-         {
-            for (PortletDescription portletDescription : offered)
-            {
-               String handle = portletDescription.getPortletHandle();
-               String warName = handle.substring(1, handle.indexOf('.')) + ".war";
-               if (warName.equals(archiveName))
-               {
-                  List<String> handles = war2Handles.get(warName);
-                  if (handles == null)
-                  {
-                     handles = new ArrayList<String>(3);
-                     war2Handles.put(warName, handles);
-                  }
-
-                  handles.add(handle);
-               }
-            }
-         }
-         else
-         {
-            throw new IllegalArgumentException(archiveName + " didn't contain any portlets...");
-         }
-      }
+      return !mostUsedPortletWARFileName.equals(archiveName);
    }
 
-   public void undeploy(String archiveName) throws Exception
-   {
-      try
-      {
-         super.undeploy(archiveName);
-      }
-      catch (Exception e)
-      {
-         // if an exception occurred the portlet is still probably deployed, so just exit
-         e.printStackTrace();
-         return;
-      }
-
-      currentlyDeployedArchiveName = null;
-
-      // only remove the mapping if we're not undeploying the most used portlet (optimization, as it avoids parsing the SD)
-      if (!mostUsedPortletWARFileName.equals(archiveName))
-      {
-         war2Handles.remove(archiveName);
-      }
-   }
-
    public void setUp() throws Exception
    {
       super.setUp();

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -77,6 +77,12 @@
       return jar;
    }
 
+   @Override
+   protected boolean removeCurrent(String archiveName)
+   {
+      return true;
+   }
+
    @Before
    public void setUp() throws Exception
    {
@@ -107,9 +113,10 @@
 
       gsd.getPortletHandles().clear();
 
-      assertEquals(original, producer.getServiceDescription(gsd));
+      assertEquals(original.getOfferedPortlets(), producer.getServiceDescription(gsd).getOfferedPortlets());
    }
 
+   @Test
    public void testServiceDescriptionFilterInexistentFilter() throws Exception
    {
       GetServiceDescription gsd = getNoRegistrationServiceDescriptionRequest();
@@ -122,7 +129,7 @@
          deploy("test-session-portlet.war");
 
          ServiceDescription sd = producer.getServiceDescription(gsd);
-         assertEquals(3, sd.getOfferedPortlets().size());
+         assertEquals(0, sd.getOfferedPortlets().size());
       }
       finally
       {

Modified: components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/V2ProducerBaseTest.java
===================================================================
--- components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/V2ProducerBaseTest.java	2011-04-15 10:02:15 UTC (rev 6238)
+++ components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/V2ProducerBaseTest.java	2011-04-15 13:26:57 UTC (rev 6239)
@@ -23,6 +23,8 @@
 
 package org.gatein.wsrp.protocol.v2;
 
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
 import org.gatein.registration.RegistrationException;
 import org.gatein.registration.RegistrationManager;
 import org.gatein.registration.policies.DefaultRegistrationPolicy;
@@ -32,19 +34,32 @@
 import org.gatein.wsrp.producer.WSRPProducer;
 import org.gatein.wsrp.producer.WSRPProducerBaseTest;
 import org.gatein.wsrp.producer.config.ProducerRegistrationRequirements;
+import org.gatein.wsrp.producer.handlers.processors.ProducerHelper;
 import org.gatein.wsrp.producer.v2.WSRP2Producer;
 import org.gatein.wsrp.registration.RegistrationPropertyDescription;
 import org.gatein.wsrp.test.ExtendedAssert;
 import org.oasis.wsrp.v2.GetServiceDescription;
+import org.oasis.wsrp.v2.PortletDescription;
+import org.oasis.wsrp.v2.ServiceDescription;
 
 import javax.xml.namespace.QName;
+import java.util.Collection;
+import java.util.List;
 
 /**
  * @author <a href="mailto:chris.laprun at jboss.com">Chris Laprun</a>
  * @version $Revision$
  */
-public class V2ProducerBaseTest extends WSRPProducerBaseTest
+public abstract class V2ProducerBaseTest extends WSRPProducerBaseTest
 {
+   private static final Function<PortletDescription, String> PORTLET_DESCRIPTION_TO_HANDLE = new Function<PortletDescription, String>()
+   {
+      public String apply(PortletDescription from)
+      {
+         return from.getPortletHandle();
+      }
+   };
+
    protected WSRP2Producer producer = ProducerHolder.getProducer(true);
 
    private static final String CONSUMER = "test-consumer";
@@ -65,6 +80,21 @@
       return producer;
    }
 
+   @Override
+   protected ProducerHelper getProducerHelper()
+   {
+      return (ProducerHelper)producer;
+   }
+
+   @Override
+   protected Collection<String> getPortletHandles() throws Exception
+   {
+      GetServiceDescription getServiceDescription = WSRPTypeFactory.createGetServiceDescription(null, null);
+      ServiceDescription serviceDescription = producer.getServiceDescription(getServiceDescription);
+      List<PortletDescription> offered = serviceDescription.getOfferedPortlets();
+      return Collections2.transform(offered, PORTLET_DESCRIPTION_TO_HANDLE);
+   }
+
    protected GetServiceDescription getNoRegistrationServiceDescriptionRequest()
    {
       GetServiceDescription gs = WSRPTypeFactory.createGetServiceDescription(null, null);



More information about the gatein-commits mailing list