Author: chris.laprun(a)jboss.com
Date: 2009-10-07 11:32:46 -0400 (Wed, 07 Oct 2009)
New Revision: 311
Modified:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/FederatingPortletInvoker.java
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java
components/pc/trunk/federation/src/test/java/org/gatein/pc/federation/FederatingPortletInvokerTestCase.java
Log:
- Added getLocalPortlets and getRemotePortlets methods.
- Improved test case.
Modified:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/FederatingPortletInvoker.java
===================================================================
---
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/FederatingPortletInvoker.java 2009-10-07
07:32:15 UTC (rev 310)
+++
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/FederatingPortletInvoker.java 2009-10-07
15:32:46 UTC (rev 311)
@@ -22,9 +22,12 @@
******************************************************************************/
package org.gatein.pc.federation;
+import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletInvoker;
+import org.gatein.pc.api.PortletInvokerException;
import java.util.Collection;
+import java.util.Set;
/**
* A portlet invoker that federates other invokers.
@@ -69,4 +72,18 @@
* @since 2.6
*/
void unregisterInvoker(String federatedId);
+
+ /**
+ * Return only the portlets from local federated invokers.
+ *
+ * @return a Set containing only the portlets from local federated invokers.
+ */
+ Set<Portlet> getLocalPortlets() throws PortletInvokerException;
+
+ /**
+ * Return only the portlets from remote federated invokers.
+ *
+ * @return a Set containing only the portlets from remote federated invokers.
+ */
+ Set<Portlet> getRemotePortlets() throws PortletInvokerException;
}
Modified:
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java
===================================================================
---
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java 2009-10-07
07:32:15 UTC (rev 310)
+++
components/pc/trunk/federation/src/main/java/org/gatein/pc/federation/impl/FederatingPortletInvokerService.java 2009-10-07
15:32:46 UTC (rev 311)
@@ -22,21 +22,21 @@
******************************************************************************/
package org.gatein.pc.federation.impl;
+import org.apache.log4j.Logger;
import org.gatein.pc.api.InvokerUnavailableException;
import org.gatein.pc.api.NoSuchPortletException;
import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvoker;
import org.gatein.pc.api.PortletInvokerException;
-import org.gatein.pc.api.PortletInvoker;
import org.gatein.pc.api.PortletStateType;
+import org.gatein.pc.api.invocation.PortletInvocation;
+import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
+import org.gatein.pc.api.state.DestroyCloneFailure;
+import org.gatein.pc.api.state.PropertyChange;
import org.gatein.pc.api.state.PropertyMap;
import org.gatein.pc.federation.FederatedPortletInvoker;
import org.gatein.pc.federation.FederatingPortletInvoker;
-import org.gatein.pc.api.invocation.PortletInvocation;
-import org.gatein.pc.api.invocation.response.PortletInvocationResponse;
-import org.gatein.pc.api.state.PropertyChange;
-import org.gatein.pc.api.state.DestroyCloneFailure;
-import org.apache.log4j.Logger;
import java.util.Collection;
import java.util.Collections;
@@ -118,9 +118,20 @@
public Set<Portlet> getPortlets() throws PortletInvokerException
{
+ return getPortlets(false);
+ }
+
+ private Set<Portlet> getPortlets(boolean remoteOnly) throws
PortletInvokerException
+ {
LinkedHashSet<Portlet> portlets = new LinkedHashSet<Portlet>();
for (FederatedPortletInvoker federated : registry.values())
{
+ // if we're only interested in remote portlets, skip the local invoker.
+ if (remoteOnly && LOCAL_PORTLET_INVOKER_ID.equals(federated.getId()))
+ {
+ continue;
+ }
+
try
{
Set<Portlet> offeredPortlets = federated.getPortlets();
@@ -137,6 +148,18 @@
return portlets;
}
+ public Set<Portlet> getLocalPortlets() throws PortletInvokerException
+ {
+ PortletInvoker local = registry.get(PortletInvoker.LOCAL_PORTLET_INVOKER_ID);
+
+ return local.getPortlets();
+ }
+
+ public Set<Portlet> getRemotePortlets() throws PortletInvokerException
+ {
+ return getPortlets(true);
+ }
+
public Portlet getPortlet(PortletContext compoundPortletContext) throws
IllegalArgumentException, PortletInvokerException
{
FederatedPortletInvoker federated =
getFederatedPortletInvokerFor(compoundPortletContext);
@@ -212,7 +235,7 @@
* @param compoundPortletContext the portlet context for which the invoker is to be
retrieved
* @return the portlet invoker associated with the specified compound portlet id
* @throws IllegalArgumentException if the compound portlet id is not well formed or
null
- * @throws NoSuchPortletException if not such portlet exist
+ * @throws NoSuchPortletException if not such portlet exist
*/
private FederatedPortletInvoker getFederatedPortletInvokerFor(PortletContext
compoundPortletContext) throws IllegalArgumentException, NoSuchPortletException
{
Modified:
components/pc/trunk/federation/src/test/java/org/gatein/pc/federation/FederatingPortletInvokerTestCase.java
===================================================================
---
components/pc/trunk/federation/src/test/java/org/gatein/pc/federation/FederatingPortletInvokerTestCase.java 2009-10-07
07:32:15 UTC (rev 310)
+++
components/pc/trunk/federation/src/test/java/org/gatein/pc/federation/FederatingPortletInvokerTestCase.java 2009-10-07
15:32:46 UTC (rev 311)
@@ -22,28 +22,25 @@
******************************************************************************/
package org.gatein.pc.federation;
-import org.gatein.pc.federation.FederatedPortletInvoker;
-import org.gatein.pc.federation.FederatingPortletInvoker;
-import org.gatein.pc.federation.impl.FederatingPortletInvokerService;
-import org.gatein.pc.portlet.support.PortletInvokerSupport;
-import org.gatein.pc.portlet.support.PortletSupport;
-import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.common.i18n.LocalizedString;
import org.gatein.pc.api.Portlet;
import org.gatein.pc.api.PortletContext;
+import org.gatein.pc.api.PortletInvoker;
+import org.gatein.pc.api.PortletInvokerException;
+import org.gatein.pc.api.info.MetaInfo;
import org.gatein.pc.api.info.PortletInfo;
-import org.gatein.pc.api.info.MetaInfo;
+import org.gatein.pc.federation.impl.FederatingPortletInvokerService;
+import org.gatein.pc.portlet.support.PortletInvokerSupport;
import org.gatein.pc.portlet.support.info.PortletInfoSupport;
-import org.gatein.common.i18n.LocalizedString;
-
-import java.util.Collection;
-import java.util.Set;
-import java.util.Locale;
-
import static org.jboss.unit.api.Assert.*;
import org.jboss.unit.api.pojo.annotations.Create;
import org.jboss.unit.api.pojo.annotations.Destroy;
import org.jboss.unit.api.pojo.annotations.Test;
+import java.util.Collection;
+import java.util.Locale;
+import java.util.Set;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
@@ -56,11 +53,9 @@
/** . */
private PortletInvokerSupport federatedInvoker;
+ private PortletInvokerSupport localInvoker;
/** . */
- private PortletSupport federatedPortlet;
-
- /** . */
private Portlet portlet;
/** . */
@@ -70,46 +65,67 @@
public void setUp() throws Exception
{
federatingInvoker = new FederatingPortletInvokerService();
+
+ // Invokers
federatedInvoker = new PortletInvokerSupport();
+ localInvoker = new PortletInvokerSupport();
- // Configure
+ // Add portlets to invokers
PortletInfoSupport fooInfo = new PortletInfoSupport();
fooInfo.getMeta().setDisplayName("FooPortlet");
+ portlet = federatedInvoker.addPortlet("MyPortlet", fooInfo);
+ portletContext = portlet.getContext();
- // Wire
- federatedPortlet = federatedInvoker.addPortlet("MyPortlet", fooInfo);
+ PortletInfoSupport localInfo = new PortletInfoSupport();
+ fooInfo.getMeta().setDisplayName("LocalPortlet");
+ localInvoker.addPortlet("MyLocalPortlet", localInfo);
+
+ // Register invokers with federating service
federatingInvoker.registerInvoker("foo", federatedInvoker);
-
- // Basic setup
- Set portlets = federatingInvoker.getPortlets();
- assertNotNull(portlets);
- assertEquals(1, portlets.size());
- portlet = (Portlet)portlets.iterator().next();
- assertNotNull(portlet);
- portletContext = portlet.getContext();
- assertNotNull(portletContext);
+ federatingInvoker.registerInvoker(PortletInvoker.LOCAL_PORTLET_INVOKER_ID,
localInvoker);
}
@Destroy
public void tearDown() throws Exception
{
- federatedPortlet = null;
federatedInvoker = null;
+ localInvoker = null;
federatingInvoker = null;
portlet = null;
portletContext = null;
}
@Test
+ public void testGetPortlets() throws PortletInvokerException
+ {
+ Set<Portlet> portlets = federatingInvoker.getPortlets();
+ assertNotNull(portlets);
+ assertEquals(2, portlets.size());
+
+ for (Portlet portlet : portlets)
+ {
+ PortletContext context = portlet.getContext();
+ String id = context.getId();
+ assertTrue("MyPortlet".equals(id) ||
"MyLocalPortlet".equals(id));
+ }
+ }
+
+ @Test
public void testFederation() throws PortletInvokerException
{
Collection federateds = federatingInvoker.getFederatedInvokers();
assertNotNull(federateds);
- assertEquals(1, federateds.size());
- FederatedPortletInvoker federated =
(FederatedPortletInvoker)federateds.iterator().next();
+ assertEquals(2, federateds.size());
+
+ FederatedPortletInvoker federated =
federatingInvoker.getFederatedInvoker("foo");
assertNotNull(federated);
assertEquals("foo", federated.getId());
assertEquals(federatedInvoker, federated.getPortletInvoker());
+
+ federated =
federatingInvoker.getFederatedInvoker(PortletInvoker.LOCAL_PORTLET_INVOKER_ID);
+ assertNotNull(federated);
+ assertEquals(PortletInvoker.LOCAL_PORTLET_INVOKER_ID, federated.getId());
+ assertEquals(localInvoker, federated.getPortletInvoker());
}
@Test
@@ -133,6 +149,26 @@
assertEquals(samePortlet.getContext(), portletContext);
}
+ @Test
+ public void testGetLocalPortlets() throws PortletInvokerException
+ {
+ Set<Portlet> localPortlets = federatingInvoker.getLocalPortlets();
+ assertEquals(1, localPortlets.size());
+ Portlet localPortlet = localPortlets.iterator().next();
+ assertNotNull(localPortlet);
+ assertEquals("MyLocalPortlet", localPortlet.getContext().getId());
+ }
+
+ @Test
+ public void testGetRemotePortlets() throws PortletInvokerException
+ {
+ Set<Portlet> portlets = federatingInvoker.getRemotePortlets();
+ assertEquals(1, portlets.size());
+ Portlet portlet = portlets.iterator().next();
+ assertNotNull(portlet);
+ assertEquals("MyPortlet", portlet.getContext().getId());
+ }
+
public void testInvoke() throws PortletInvokerException
{
}
Show replies by date