Author: chris.laprun(a)jboss.com
Date: 2010-06-18 09:30:33 -0400 (Fri, 18 Jun 2010)
New Revision: 3385
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.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/test-portlets/test-basic-portlet-war/WEB-INF/portlet.xml
Log:
- Fixed ServiceDescriptionHandler: event descriptions were not properly reset, and now,
make sure that we don't have duplicates.
- Added EventDescription testing.
- Added events and public render parameters in BasicPortlet for testing purposes.
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java 2010-06-18
13:25:58 UTC (rev 3384)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/wsrp/producer/ServiceDescriptionHandler.java 2010-06-18
13:30:33 UTC (rev 3385)
@@ -63,6 +63,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@@ -357,7 +358,7 @@
private ServiceDescription registrationPortletsServiceDescription;
private long lastGenerated;
- private List<EventDescription> eventDescriptions;
+ private Map<QName, EventDescription> eventDescriptions;
private static final List<String> OPTIONS = new ArrayList<String>(5);
@@ -428,20 +429,33 @@
Collection<PortletDescription> offeredPortletDescriptions = new
ArrayList<PortletDescription>(portlets.size());
// reset event descriptions as they will be repopulated when we build the
portlet descriptions
- eventDescriptions = new ArrayList<EventDescription>(portlets.size());
+ eventDescriptions = new HashMap<QName,
EventDescription>(portlets.size());
for (Portlet portlet : portlets)
{
- PortletDescription desc = getPortletDescription(portlet, desiredLocales);
+ PortletDescription desc = getPortletDescription(portlet, desiredLocales,
this);
offeredPortletDescriptions.add(desc);
}
// events
-
registrationPortletsServiceDescription.getEventDescriptions().addAll(eventDescriptions);
-
registrationNoPortletsServiceDescription.getEventDescriptions().addAll(eventDescriptions);
-
noRegistrationPortletsServiceDescription.getEventDescriptions().addAll(eventDescriptions);
-
noRegistrationNoPortletsServiceDescription.getEventDescriptions().addAll(eventDescriptions);
+ 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);
@@ -466,16 +480,20 @@
public void addEventInfo(EventInfo info, List<String> desiredLocales)
{
- EventDescription desc = WSRPTypeFactory.createEventDescription(info.getName());
- desc.setDescription(Utils.convertToWSRPLocalizedString(info.getDescription(),
desiredLocales));
- desc.setLabel(Utils.convertToWSRPLocalizedString(info.getDisplayName(),
desiredLocales));
- Collection<QName> aliases = info.getAliases();
- if (ParameterValidation.existsAndIsNotEmpty(aliases))
+ QName name = info.getName();
+ if (!eventDescriptions.containsKey(name))
{
- desc.getAliases().addAll(aliases);
+ EventDescription desc = WSRPTypeFactory.createEventDescription(name);
+ desc.setDescription(Utils.convertToWSRPLocalizedString(info.getDescription(),
desiredLocales));
+ desc.setLabel(Utils.convertToWSRPLocalizedString(info.getDisplayName(),
desiredLocales));
+ Collection<QName> aliases = info.getAliases();
+ if (ParameterValidation.existsAndIsNotEmpty(aliases))
+ {
+ desc.getAliases().addAll(aliases);
+ }
+ // todo: deal with type info...
+ eventDescriptions.put(name, desc);
}
- // todo: deal with type info...
- eventDescriptions.add(desc);
}
}
}
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 2010-06-18
13:25:58 UTC (rev 3384)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/java/org/gatein/wsrp/protocol/v2/ServiceDescriptionTestCase.java 2010-06-18
13:30:33 UTC (rev 3385)
@@ -37,10 +37,13 @@
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.oasis.wsrp.v2.EventDescription;
import org.oasis.wsrp.v2.InvalidRegistration;
import org.oasis.wsrp.v2.OperationFailed;
+import org.oasis.wsrp.v2.PortletDescription;
import org.oasis.wsrp.v2.ServiceDescription;
+import javax.xml.namespace.QName;
import java.util.List;
/**
@@ -94,4 +97,112 @@
ExtendedAssert.assertTrue(options.contains(WSRP2Constants.OPTIONS_IMPORT));
ExtendedAssert.assertTrue(options.contains(WSRP2Constants.OPTIONS_EXPORT));
}
+
+ @Test
+ public void testEventDescriptions() throws Exception
+ {
+ try
+ {
+ deploy("google-portlet.war");
+
+ ServiceDescription description =
producer.getServiceDescription(getNoRegistrationServiceDescriptionRequest());
+
+ List<EventDescription> eventDescriptions =
description.getEventDescriptions();
+ ExtendedAssert.assertNotNull(eventDescriptions);
+ ExtendedAssert.assertEquals(1, eventDescriptions.size());
+
+ QName zip = new QName("urn:jboss:portal:samples:event",
"ZipEvent");
+ EventDescription event = eventDescriptions.get(0);
+ ExtendedAssert.assertEquals(zip, event.getName());
+ ExtendedAssert.assertTrue(event.getAliases().isEmpty());
+
ExtendedAssert.assertTrue(event.getLabel().getValue().contains(zip.toString()));
+
+ List<PortletDescription> portlets = description.getOfferedPortlets();
+ ExtendedAssert.assertEquals(2, portlets.size());
+
+ // get GoogleMap portlet description
+ for (PortletDescription portlet : portlets)
+ {
+ if (portlet.getPortletHandle().contains("GoogleMap"))
+ {
+ List<QName> publishedEvents = portlet.getPublishedEvents();
+ ExtendedAssert.assertEquals(1, publishedEvents.size());
+ ExtendedAssert.assertEquals(zip, publishedEvents.get(0));
+
+ ExtendedAssert.assertTrue(portlet.getHandledEvents().isEmpty());
+ }
+ }
+
+ deploy("test-basic-portlet.war");
+
+ // reload service description
+ description =
producer.getServiceDescription(getNoRegistrationServiceDescriptionRequest());
+ eventDescriptions = description.getEventDescriptions();
+ portlets = description.getOfferedPortlets();
+
+ QName foo = new QName("urn:jboss:gatein", "foo");
+ ExtendedAssert.assertEquals(2, eventDescriptions.size());
+ for (EventDescription eventDesc : eventDescriptions)
+ {
+ QName name = eventDesc.getName();
+ boolean isZip = zip.equals(name);
+ boolean isFoo = foo.equals(name);
+ if (isZip || isFoo)
+ {
+ if (isFoo)
+ {
+ ExtendedAssert.assertEquals(foo, eventDesc.getName());
+
ExtendedAssert.assertTrue(eventDesc.getLabel().getValue().contains(foo.toString()));
+ List<QName> aliases = eventDesc.getAliases();
+ ExtendedAssert.assertEquals(2, aliases.size());
+ ExtendedAssert.assertTrue(aliases.contains(new
QName("urn:jboss:gatein", "bar")));
+ ExtendedAssert.assertTrue(aliases.contains(new
QName("urn:jboss:gatein", "baz")));
+ }
+ }
+ else
+ {
+ ExtendedAssert.fail("Only 2 events should be ZipEvent or
foo!");
+ }
+ }
+
+ for (PortletDescription portlet : portlets)
+ {
+ if (portlet.getPortletHandle().contains("Simple Test Portlet"))
+ {
+ List<QName> events = portlet.getPublishedEvents();
+ ExtendedAssert.assertEquals(2, events.size());
+ ExtendedAssert.assertTrue(events.contains(zip));
+ ExtendedAssert.assertTrue(events.contains(foo));
+
+ events = portlet.getHandledEvents();
+ ExtendedAssert.assertEquals(1, events.size());
+ ExtendedAssert.assertTrue(events.contains(zip));
+ }
+ }
+ }
+ finally
+ {
+ undeploy("google-portlet.war");
+ undeploy("test-basic-portlet.war");
+ }
+
+ }
+
+ /*@Test
+ public void testParameterDescriptions() throws Exception
+ {
+ try
+ {
+ deploy("google-portlet.war");
+
+ ServiceDescription description =
producer.getServiceDescription(getNoRegistrationServiceDescriptionRequest());
+
+ description.get
+ }
+ finally
+ {
+ undeploy("google-portlet.war");
+ }
+
+ }*/
}
Modified:
components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-basic-portlet-war/WEB-INF/portlet.xml
===================================================================
---
components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-basic-portlet-war/WEB-INF/portlet.xml 2010-06-18
13:25:58 UTC (rev 3384)
+++
components/wsrp/trunk/wsrp-producer-war/src/test/test-portlets/test-basic-portlet-war/WEB-INF/portlet.xml 2010-06-18
13:30:33 UTC (rev 3385)
@@ -1,27 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?>
-<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- ~ 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. ~
- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->
-<portlet-app
xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://java.sun.com/xml/ns/portlet/portlet-app_2_...
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd' version='2.0'>
+<!--
+ ~ JBoss, a division of Red Hat
+ ~ Copyright 2010, 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.
+ -->
+<portlet-app
xmlns='http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd'
+
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+
xsi:schemaLocation='http://java.sun.com/xml/ns/portlet/portlet-app_2_...
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd'
+ version='2.0'>
<portlet>
<portlet-name>Simple Test Portlet</portlet-name>
<portlet-class>org.gatein.wsrp.portlet.BasicPortlet</portlet-class>
@@ -47,10 +50,40 @@
<value>prefValue2</value>
</preference>
</portlet-preferences>
+ <supported-publishing-event>
+ <qname
xmlns:jbp='urn:jboss:portal:samples:event'>jbp:ZipEvent</qname>
+ </supported-publishing-event>
+ <supported-publishing-event>
+ <qname xmlns:gtn='urn:jboss:gatein'>gtn:foo</qname>
+ </supported-publishing-event>
+ <supported-processing-event>
+ <qname
xmlns:jbp='urn:jboss:portal:samples:event'>jbp:ZipEvent</qname>
+ </supported-processing-event>
+
<supported-public-render-parameter>zipcode</supported-public-render-parameter>
</portlet>
- <container-runtime-option>
+ <event-definition>
+ <qname
xmlns:jbp='urn:jboss:portal:samples:event'>jbp:ZipEvent</qname>
+ <value-type>java.lang.String</value-type>
+ </event-definition>
+ <event-definition>
+ <qname xmlns:gtn='urn:jboss:gatein'>gtn:foo</qname>
+ <value-type>java.lang.String</value-type>
+ <alias xmlns:gtn='urn:jboss:gatein'>gtn:bar</alias>
+ <alias xmlns:gtn='urn:jboss:gatein'>gtn:baz</alias>
+ </event-definition>
+
+ <public-render-parameter>
+ <identifier>zipcode</identifier>
+ <qname
xmlns:g='urn:jboss:portal:simple:google'>g:zipcode</qname>
+ </public-render-parameter>
+ <public-render-parameter>
+ <identifier>foo</identifier>
+ <qname xmlns:gtn='urn:jboss:gatein'>gtn:foo</qname>
+ </public-render-parameter>
+
+ <container-runtime-option>
<name>org.gatein.pc.remotable</name>
<value>true</value>
- </container-runtime-option>
+ </container-runtime-option>
</portlet-app>
\ No newline at end of file