[jboss-cvs] jboss-portal/portlet/src/main/org/jboss/portal/portlet/test/support ...
Julien Viet
julien at jboss.com
Sun Jul 30 08:36:24 EDT 2006
User: julien
Date: 06/07/30 08:36:24
Added: portlet/src/main/org/jboss/portal/portlet/test/support
PortletInvokerSupport.java PortletSupport.java
Log:
JBPORTAL-973 : Portlet instance container integration testing
JBPORTAL-972 : Portlet stateful invoker testing
Revision Changes Path
1.1 date: 2006/07/30 12:36:24; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/test/support/PortletInvokerSupport.java
Index: PortletInvokerSupport.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., 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.portlet.test.support;
import org.jboss.portal.portlet.PortletInvoker;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.NoSuchPortletException;
import org.jboss.portal.portlet.InvalidPortletIdException;
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.info.PreferencesInfo;
import org.jboss.portal.portlet.info.PreferenceInfo;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.common.value.ValueMap;
import org.jboss.portal.common.value.SimpleValueMap;
import org.jboss.portal.common.system.AbstractJBossService;
import java.util.Map;
import java.util.HashMap;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class PortletInvokerSupport extends AbstractJBossService implements PortletInvoker
{
/** . */
private final Object invalidPortlet;
/** . */
private Map portlets;
public PortletInvokerSupport()
{
invalidPortlet = new Object();
this.portlets = new HashMap();
}
public PortletInvokerSupport addPortlet(PortletSupport info)
{
portlets.put(info.getId(), info);
return this;
}
public PortletInvokerSupport addInvalidPortlet(String portletId)
{
portlets.put(portletId, invalidPortlet);
return this;
}
public Set getPortlets()
{
return new HashSet(portlets.values());
}
public Portlet getPortlet(String portletId) throws PortletInvokerException
{
try
{
return internalGetPortlet(portletId);
}
catch (NoSuchPortletException e)
{
return null;
}
}
public void invoke(PortletInvocation invocation) throws PortletInvokerException
{
String portletId = (String)invocation.getAttribute(PortletInvocation.PORTLET_ID_ATTRIBUTE);
PortletSupport portlet = internalGetPortlet(portletId);
portlet.invoke(invocation);
}
public ValueMap getProperties(String portletId) throws PortletInvokerException
{
PortletSupport portlet = internalGetPortlet(portletId);
PortletInfo info = portlet.getInfo();
ValueMap values = new SimpleValueMap();
PreferencesInfo preferences = info.getPreferences();
for (Iterator i = preferences.getKeys().iterator(); i.hasNext();)
{
String key = (String)i.next();
PreferenceInfo preference = preferences.getPreference(key);
values.setValue(key, preference.getDefaultValue());
}
return values;
}
public String createClone(String portletId) throws NoSuchPortletException
{
throw new UnsupportedOperationException("Implement me");
}
public void destroyClone(String portletId)
{
throw new UnsupportedOperationException("Implement me");
}
public void setProperties(String portletId, ValueMap properties)
{
throw new UnsupportedOperationException("Implement me");
}
private PortletSupport internalGetPortlet(String portletId) throws IllegalArgumentException, PortletInvokerException
{
if (portletId == null)
{
throw new IllegalArgumentException();
}
Object portlet = portlets.get(portletId);
if (portlet == invalidPortlet)
{
throw new InvalidPortletIdException(portletId);
}
if (portlet == null)
{
throw new NoSuchPortletException(portletId);
}
return (PortletSupport)portlet;
}
}
1.1 date: 2006/07/30 12:36:24; author: julien; state: Exp;jboss-portal/portlet/src/main/org/jboss/portal/portlet/test/support/PortletSupport.java
Index: PortletSupport.java
===================================================================
/*
* JBoss, Home of Professional Open Source
* Copyright 2005, JBoss Inc., 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.portlet.test.support;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.portlet.info.PortletInfo;
import org.jboss.portal.portlet.test.support.info.PortletInfoSupport;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class PortletSupport implements Portlet
{
/** . */
protected final String id;
/** . */
protected final PortletInfoSupport info;
public PortletSupport(String id)
{
this.id = id;
this.info = new PortletInfoSupport();
}
public String getId()
{
return id;
}
public PortletInfo getInfo()
{
return info;
}
public boolean isRemote()
{
return false;
}
public void invoke(PortletInvocation invocation) throws PortletInvokerException
{
throw new PortletInvokerException("No implementations");
}
}
More information about the jboss-cvs-commits
mailing list