Author: julien(a)jboss.com
Date: 2007-01-29 20:16:36 -0500 (Mon, 29 Jan 2007)
New Revision: 6116
Added:
trunk/federation/src/main/org/jboss/portal/test/
trunk/federation/src/main/org/jboss/portal/test/portlet/
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/FederatingPortletInvokerTestCase.java
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/NoInvokersTestCase.java
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/OneInvokerNoPortletsTestCase.java
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/PortletInvokerRegistrationImpl.java
Modified:
trunk/federation/build.xml
trunk/federation/src/main/org/jboss/portal/federation/impl/FederatingPortletInvokerService.java
trunk/portlet/src/main/org/jboss/portal/portlet/test/support/PortletInvokerSupport.java
trunk/portlet/src/main/org/jboss/portal/portlet/test/support/PortletSupport.java
Log:
started to add basic test for portlet invoker federation
Modified: trunk/federation/build.xml
===================================================================
--- trunk/federation/build.xml 2007-01-29 23:54:59 UTC (rev 6115)
+++ trunk/federation/build.xml 2007-01-30 01:16:36 UTC (rev 6116)
@@ -196,4 +196,29 @@
<target name="all" depends="_default:all"/>
<target name="most" depends="_default:most"/>
<target name="help" depends="_default:help"/>
+
+ <target name="package-tests" depends="init">
+ <jar jarfile="${build.lib}/portal-federation-test-lib.jar">
+ <fileset dir="${build.classes}"
includes="org/jboss/portal/test/**"/>
+ </jar>
+ </target>
+
+ <target name="tests" depends="init,
_buildmagic:configure:deployment">
+ <execute-tests>
+ <x-test>
+ <test todir="${test.reports}"
+
name="org.jboss.portal.test.portlet.federation.OneInvokerNoPortletsTestCase"/>
+ <test todir="${test.reports}"
+
name="org.jboss.portal.test.portlet.federation.NoInvokersTestCase"/>
+ <test todir="${test.reports}"
+
name="org.jboss.portal.test.portlet.federation.FederatingPortletInvokerTestCase"/>
+ </x-test>
+ <x-classpath>
+ <pathelement
location="${build.lib}/portal-federation-lib.jar"/>
+ <pathelement
location="${build.lib}/portal-federation-test-lib.jar"/>
+ <path refid="library.classpath"/>
+ <path refid="dependentmodule.classpath"/>
+ </x-classpath>
+ </execute-tests>
+ </target>
</project>
Modified:
trunk/federation/src/main/org/jboss/portal/federation/impl/FederatingPortletInvokerService.java
===================================================================
---
trunk/federation/src/main/org/jboss/portal/federation/impl/FederatingPortletInvokerService.java 2007-01-29
23:54:59 UTC (rev 6115)
+++
trunk/federation/src/main/org/jboss/portal/federation/impl/FederatingPortletInvokerService.java 2007-01-30
01:16:36 UTC (rev 6116)
@@ -35,14 +35,13 @@
import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
import org.jboss.portal.portlet.state.PropertyChange;
import org.jboss.portal.portlet.state.PropertyMap;
+import org.jboss.portal.common.util.CopyOnWriteRegistry;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
-import java.util.Map;
import java.util.Set;
/**
@@ -58,27 +57,24 @@
static final String SEPARATOR = ".";
/** The registred FederatedPortletInvokers. */
- private Map registry = new HashMap();
+ private CopyOnWriteRegistry registry = new CopyOnWriteRegistry();
- public synchronized FederatedPortletInvoker registerInvoker(PortletInvokerRegistration
registration)
+ public FederatedPortletInvoker registerInvoker(PortletInvokerRegistration
registration)
{
if (registration == null)
{
throw new IllegalArgumentException("No null invoker");
}
String id = registration.getId();
- if (registry.containsKey(id))
+ FederatedPortletInvokerService invoker = new FederatedPortletInvokerService(this,
registration);
+ if (registry.register(id, invoker) == false)
{
throw new IllegalArgumentException("Attempting dual registration of "
+ id);
}
- Map copy = new HashMap(registry);
- FederatedPortletInvokerService invoker = new FederatedPortletInvokerService(this,
registration);
- copy.put(id, invoker);
- registry = copy;
return invoker;
}
- public synchronized void unregisterInvoker(PortletInvokerRegistration registration)
+ public void unregisterInvoker(PortletInvokerRegistration registration)
{
if (registration == null)
{
@@ -89,27 +85,20 @@
{
throw new IllegalArgumentException("No null id accepted");
}
- if (!registry.containsKey(id))
+ if (registry.unregister(id) == false)
{
throw new IllegalArgumentException("Attempting to unregister unknown
invoker " + id);
}
- Map copy = new HashMap(registry);
- copy.remove(id);
- registry = copy;
}
public FederatedPortletInvoker getFederatedInvoker(String id) throws
IllegalArgumentException
{
- if (id == null)
- {
- throw new IllegalArgumentException("No null id provided");
- }
return (FederatedPortletInvoker)registry.get(id);
}
public Collection getFederatedInvokers()
{
- return registry.values();
+ return registry.getRegistrations();
}
// PortletInvoker implementation
************************************************************************************
@@ -117,7 +106,7 @@
public Set getPortlets() throws PortletInvokerException
{
LinkedHashSet portlets = new LinkedHashSet();
- for (Iterator iterator = registry.values().iterator(); iterator.hasNext();)
+ for (Iterator iterator = registry.getRegistrations().iterator();
iterator.hasNext();)
{
FederatedPortletInvoker federated = (FederatedPortletInvoker)iterator.next();
try
@@ -127,6 +116,7 @@
}
catch (InvokerUnavailableException e)
{
+ // When an invoker is unavailable it does not participate in the set of
returned portlets.
Throwable cause = e.getCause();
log.debug(e.fillInStackTrace());
log.warn("PortletInvoker with id: " + federated.getId() + " is
not available.\nReason: " + e.getMessage()
Added:
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/FederatingPortletInvokerTestCase.java
===================================================================
---
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/FederatingPortletInvokerTestCase.java
(rev 0)
+++
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/FederatingPortletInvokerTestCase.java 2007-01-30
01:16:36 UTC (rev 6116)
@@ -0,0 +1,132 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.portlet.federation;
+
+import junit.framework.TestCase;
+import org.jboss.portal.federation.FederatedPortletInvoker;
+import org.jboss.portal.federation.FederatingPortletInvoker;
+import org.jboss.portal.federation.impl.FederatingPortletInvokerService;
+import org.jboss.portal.portlet.test.support.PortletInvokerSupport;
+import org.jboss.portal.portlet.test.support.PortletSupport;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.info.MetaInfo;
+import org.jboss.portal.portlet.support.info.PortletInfoSupport;
+import org.jboss.portal.common.util.LocalizedString;
+
+import java.util.Collection;
+import java.util.Set;
+import java.util.Locale;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class FederatingPortletInvokerTestCase extends TestCase
+{
+
+ /** . */
+ private FederatingPortletInvoker federatingInvoker;
+
+ /** . */
+ private PortletInvokerSupport federatedInvoker;
+
+ /** . */
+ private PortletSupport federatedPortlet;
+
+ /** . */
+ private Portlet portlet;
+
+ /** . */
+ private PortletContext portletContext;
+
+ protected void setUp() throws Exception
+ {
+ federatingInvoker = new FederatingPortletInvokerService();
+ federatedInvoker = new PortletInvokerSupport();
+ federatedPortlet = new PortletSupport();
+
+ // Configure
+ PortletInfoSupport fooInfo = federatedPortlet.getInfoSupport();
+ fooInfo.getMetaSupport().setDisplayName("FooPortlet");
+
+ // Wire
+ federatedInvoker.addPortlet("MyPortlet", federatedPortlet);
+ federatingInvoker.registerInvoker(new
PortletInvokerRegistrationImpl("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);
+ }
+
+
+ protected void tearDown() throws Exception
+ {
+ federatedPortlet = null;
+ federatedInvoker = null;
+ federatingInvoker = null;
+ portlet = null;
+ portletContext = null;
+ }
+
+ public void testFederation() throws PortletInvokerException
+ {
+ Collection federateds = federatingInvoker.getFederatedInvokers();
+ assertNotNull(federateds);
+ assertEquals(1, federateds.size());
+ FederatedPortletInvoker federated =
(FederatedPortletInvoker)federateds.iterator().next();
+ assertNotNull(federated);
+ assertEquals("foo", federated.getId());
+ assertEquals(federatedInvoker, federated.getPortletInvoker());
+ }
+
+ public void testInfo() throws PortletInvokerException
+ {
+ PortletInfo info = portlet.getInfo();
+ assertNotNull(info);
+ MetaInfo metaInfo = info.getMeta();
+ assertNotNull(metaInfo);
+ LocalizedString description = metaInfo.getMetaValue(MetaInfo.DISPLAY_NAME);
+ assertNotNull(description);
+ assertEquals(Locale.ENGLISH, description.getDefaultLocale());
+ assertEquals("FooPortlet", description.getDefaultString());
+ }
+
+ public void testGetPortlet() throws PortletInvokerException
+ {
+ Portlet samePortlet = federatingInvoker.getPortlet(portletContext);
+ assertNotNull(samePortlet);
+ assertEquals(samePortlet.getContext(), portletContext);
+ }
+
+ public void testInvoke() throws PortletInvokerException
+ {
+ }
+}
Added:
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/NoInvokersTestCase.java
===================================================================
---
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/NoInvokersTestCase.java
(rev 0)
+++
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/NoInvokersTestCase.java 2007-01-30
01:16:36 UTC (rev 6116)
@@ -0,0 +1,49 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.portlet.federation;
+
+import junit.framework.TestCase;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.federation.FederatingPortletInvoker;
+import org.jboss.portal.federation.impl.FederatingPortletInvokerService;
+
+import java.util.HashSet;
+import java.util.ArrayList;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class NoInvokersTestCase extends TestCase
+{
+ public void testNoFederated() throws PortletInvokerException
+ {
+ FederatingPortletInvoker federating = new FederatingPortletInvokerService();
+
+ //
+ assertEquals(new HashSet(), federating.getPortlets());
+
+ //
+ assertEquals(new ArrayList(), new ArrayList(federating.getFederatedInvokers()));
+ }
+}
Added:
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/OneInvokerNoPortletsTestCase.java
===================================================================
---
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/OneInvokerNoPortletsTestCase.java
(rev 0)
+++
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/OneInvokerNoPortletsTestCase.java 2007-01-30
01:16:36 UTC (rev 6116)
@@ -0,0 +1,59 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.portlet.federation;
+
+import junit.framework.TestCase;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.test.support.PortletInvokerSupport;
+import org.jboss.portal.federation.FederatingPortletInvoker;
+import org.jboss.portal.federation.FederatedPortletInvoker;
+import org.jboss.portal.federation.impl.FederatingPortletInvokerService;
+
+import java.util.HashSet;
+import java.util.Collection;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class OneInvokerNoPortletsTestCase extends TestCase
+{
+
+ public void testOneFederatedWithNoPortlets() throws PortletInvokerException
+ {
+ FederatingPortletInvoker federating = new FederatingPortletInvokerService();
+ PortletInvokerSupport support = new PortletInvokerSupport();
+ federating.registerInvoker(new PortletInvokerRegistrationImpl("foo",
support));
+
+ //
+ assertEquals(new HashSet(), federating.getPortlets());
+
+ //
+ Collection federateds = federating.getFederatedInvokers();
+ assertNotNull(federateds);
+ assertEquals(1, federateds.size());
+ FederatedPortletInvoker federated =
(FederatedPortletInvoker)federateds.iterator().next();
+ assertEquals("foo", federated.getId());
+ assertEquals(support, federated.getPortletInvoker());
+ }
+}
Added:
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/PortletInvokerRegistrationImpl.java
===================================================================
---
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/PortletInvokerRegistrationImpl.java
(rev 0)
+++
trunk/federation/src/main/org/jboss/portal/test/portlet/federation/PortletInvokerRegistrationImpl.java 2007-01-30
01:16:36 UTC (rev 6116)
@@ -0,0 +1,56 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2006, Red Hat Middleware, LLC, and individual *
+ * contributors as indicated by the @authors tag. See the *
+ * copyright.txt in the distribution for a full listing of *
+ * individual contributors. *
+ * *
+ * This is free software; you can redistribute it and/or modify it *
+ * under the terms of the GNU Lesser General Public License as *
+ * published by the Free Software Foundation; either version 2.1 of *
+ * the License, or (at your option) any later version. *
+ * *
+ * This software is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
+ * Lesser General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU Lesser General Public *
+ * License along with this software; if not, write to the Free *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org. *
+ ******************************************************************************/
+package org.jboss.portal.test.portlet.federation;
+
+import org.jboss.portal.federation.spi.PortletInvokerRegistration;
+import org.jboss.portal.portlet.PortletInvoker;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 1.1 $
+ */
+public class PortletInvokerRegistrationImpl implements PortletInvokerRegistration
+{
+
+ /** . */
+ private final String id;
+
+ /** . */
+ private final PortletInvoker portletInvoker;
+
+ public PortletInvokerRegistrationImpl(String id, PortletInvoker portletInvoker)
+ {
+ this.id = id;
+ this.portletInvoker = portletInvoker;
+ }
+
+ public String getId()
+ {
+ return id;
+ }
+
+ public PortletInvoker getPortletInvoker()
+ {
+ return portletInvoker;
+ }
+}
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/test/support/PortletInvokerSupport.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/test/support/PortletInvokerSupport.java 2007-01-29
23:54:59 UTC (rev 6115)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/test/support/PortletInvokerSupport.java 2007-01-30
01:16:36 UTC (rev 6116)
@@ -173,7 +173,7 @@
public PortletInfo getInfo()
{
- return support.getInfo();
+ return support.getInfoSupport();
}
public boolean isRemote()
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/test/support/PortletSupport.java
===================================================================
---
trunk/portlet/src/main/org/jboss/portal/portlet/test/support/PortletSupport.java 2007-01-29
23:54:59 UTC (rev 6115)
+++
trunk/portlet/src/main/org/jboss/portal/portlet/test/support/PortletSupport.java 2007-01-30
01:16:36 UTC (rev 6116)
@@ -56,7 +56,7 @@
this(new PortletInfoSupport());
}
- public PortletInfo getInfo()
+ public PortletInfoSupport getInfoSupport()
{
return info;
}