Author: chris.laprun(a)jboss.com
Date: 2007-03-30 19:58:02 -0400 (Fri, 30 Mar 2007)
New Revision: 6890
Modified:
trunk/portlet/src/main/org/jboss/portal/portlet/PortletContext.java
trunk/portlet/src/main/org/jboss/portal/portlet/StatefulPortletContext.java
trunk/wsrp/build.xml
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/PortletManagementBehavior.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/RegistrationBehavior.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/ServiceDescriptionBehavior.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerInfoTestCase.java
Log:
- More ProducerInfo tests.
- Added toString and hashCode implementation on PortletContext and
StatefulPortletContext.
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/PortletContext.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/PortletContext.java 2007-03-30
23:45:46 UTC (rev 6889)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/PortletContext.java 2007-03-30
23:58:02 UTC (rev 6890)
@@ -44,6 +44,28 @@
this.id = id;
}
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+
+ PortletContext that = (PortletContext)o;
+
+ return id.equals(that.id);
+ }
+
+ public int hashCode()
+ {
+ return id.hashCode();
+ }
+
public String getId()
{
return id;
Modified: trunk/portlet/src/main/org/jboss/portal/portlet/StatefulPortletContext.java
===================================================================
--- trunk/portlet/src/main/org/jboss/portal/portlet/StatefulPortletContext.java 2007-03-30
23:45:46 UTC (rev 6889)
+++ trunk/portlet/src/main/org/jboss/portal/portlet/StatefulPortletContext.java 2007-03-30
23:58:02 UTC (rev 6890)
@@ -24,6 +24,8 @@
import org.jboss.portal.common.util.ParameterValidation;
+import java.util.Arrays;
+
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
@@ -45,6 +47,34 @@
this.marshalledState = marshalledState;
}
+
+ public boolean equals(Object o)
+ {
+ if (this == o)
+ {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass())
+ {
+ return false;
+ }
+ if (!super.equals(o))
+ {
+ return false;
+ }
+
+ StatefulPortletContext that = (StatefulPortletContext)o;
+
+ return Arrays.equals(marshalledState, that.marshalledState);
+ }
+
+ public int hashCode()
+ {
+ int result = super.hashCode();
+ result = 31 * result + (marshalledState != null ? marshalledState.hashCode() : 0);
+ return result;
+ }
+
public byte[] getState()
{
return marshalledState;
Modified: trunk/wsrp/build.xml
===================================================================
--- trunk/wsrp/build.xml 2007-03-30 23:45:46 UTC (rev 6889)
+++ trunk/wsrp/build.xml 2007-03-30 23:58:02 UTC (rev 6890)
@@ -424,8 +424,8 @@
<target name="package-other-test" description="Generates the test
artifacts" depends="compile">
<jar jarfile="${build.lib.test}/test-other-lib.jar">
<fileset dir="${build.classes}/">
- <include
name="org/jboss/portal/test/wsrp/framework/support/*.class"/>
- <include
name="org/jboss/portal/test/wsrp/other/*TestCase.class"/>
+ <include name="org/jboss/portal/test/wsrp/framework/**"/>
+ <include name="org/jboss/portal/test/wsrp/other/*.class"/>
<include
name="org/jboss/portal/test/wsrp/handler/*.class"/>
</fileset>
</jar>
@@ -752,6 +752,7 @@
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.WSRPPortletURLTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.UserContextConverterTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.EndpointConfigurationInfoTestCase"/>
+ <test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.other.ProducerInfoTestCase"/>
<test todir="${test.reports}"
name="org.jboss.portal.test.wsrp.handler.RequestHeaderClientHandlerTestCase"/>
</x-test>
<x-sysproperty>
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/PortletManagementBehavior.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/PortletManagementBehavior.java 2007-03-30
23:45:46 UTC (rev 6889)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/PortletManagementBehavior.java 2007-03-30
23:58:02 UTC (rev 6890)
@@ -58,6 +58,7 @@
throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault,
InconsistentParametersFault,
MissingParametersFault, InvalidRegistrationFault, OperationFailedFault,
RemoteException
{
+ incrementCallCount();
return null;
}
@@ -65,6 +66,7 @@
throws InvalidUserCategoryFault, AccessDeniedFault, OperationFailedFault,
InvalidHandleFault,
InvalidRegistrationFault, InconsistentParametersFault, MissingParametersFault,
RemoteException
{
+ incrementCallCount();
return null;
}
@@ -72,6 +74,7 @@
throws InconsistentParametersFault, MissingParametersFault,
InvalidRegistrationFault, OperationFailedFault,
RemoteException
{
+ incrementCallCount();
return null;
}
@@ -79,6 +82,7 @@
throws OperationFailedFault, InvalidHandleFault, MissingParametersFault,
InconsistentParametersFault,
InvalidUserCategoryFault, AccessDeniedFault, InvalidRegistrationFault,
RemoteException
{
+ incrementCallCount();
return null;
}
@@ -86,6 +90,7 @@
throws InvalidHandleFault, MissingParametersFault, InvalidRegistrationFault,
AccessDeniedFault,
OperationFailedFault, InconsistentParametersFault, InvalidUserCategoryFault,
RemoteException
{
+ incrementCallCount();
return null;
}
@@ -93,6 +98,7 @@
throws MissingParametersFault, InconsistentParametersFault,
InvalidUserCategoryFault, InvalidRegistrationFault,
AccessDeniedFault, InvalidHandleFault, OperationFailedFault, RemoteException
{
+ incrementCallCount();
return WSRPTypeFactory.createPortletPropertyDescriptionResponse(null);
}
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/RegistrationBehavior.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/RegistrationBehavior.java 2007-03-30
23:45:46 UTC (rev 6889)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/RegistrationBehavior.java 2007-03-30
23:58:02 UTC (rev 6890)
@@ -23,6 +23,7 @@
package org.jboss.portal.test.wsrp.framework;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
import org.jboss.portal.wsrp.core.MissingParametersFault;
import org.jboss.portal.wsrp.core.ModifyRegistration;
@@ -43,21 +44,26 @@
*/
public class RegistrationBehavior extends TestProducerBehavior implements
WSRP_v1_Registration_PortType
{
+ public static final String REGISTRATION_HANDLE = "registration";
+
public RegistrationContext register(RegistrationData register)
throws MissingParametersFault, OperationFailedFault, RemoteException
{
- return null;
+ incrementCallCount();
+ return WSRPTypeFactory.createRegistrationContext(REGISTRATION_HANDLE);
}
public ReturnAny deregister(RegistrationContext deregister)
throws OperationFailedFault, InvalidRegistrationFault, RemoteException
{
+ incrementCallCount();
return null;
}
public RegistrationState modifyRegistration(ModifyRegistration modifyRegistration)
throws MissingParametersFault, OperationFailedFault, InvalidRegistrationFault,
RemoteException
{
+ incrementCallCount();
return null;
}
}
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/ServiceDescriptionBehavior.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/ServiceDescriptionBehavior.java 2007-03-30
23:45:46 UTC (rev 6889)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/ServiceDescriptionBehavior.java 2007-03-30
23:58:02 UTC (rev 6890)
@@ -57,6 +57,7 @@
public ServiceDescription getServiceDescription(GetServiceDescription
getServiceDescription) throws
OperationFailedFault, InvalidRegistrationFault, RemoteException
{
+ incrementCallCount();
return serviceDescription;
}
@@ -75,7 +76,7 @@
return DEFAULT_SERVICE_DESCRIPTION;
}
- void addPortletDescription(PortletDescription portletDescription)
+ public void addPortletDescription(PortletDescription portletDescription)
{
PortletDescription[] initial = serviceDescription.getOfferedPortlets();
if (initial == null || initial.length == 0)
Modified:
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java 2007-03-30
23:45:46 UTC (rev 6889)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/framework/TestProducerBehavior.java 2007-03-30
23:58:02 UTC (rev 6890)
@@ -50,8 +50,13 @@
callCount++;
}
- protected PortletDescription createPortletDescription(String portletHandle, String
suffix)
+ public int getCallCount()
{
+ return callCount;
+ }
+
+ public PortletDescription createPortletDescription(String portletHandle, String
suffix)
+ {
PortletDescription portletDesc = new PortletDescription();
portletDesc.setPortletHandle(portletHandle);
portletDesc.setMarkupTypes(new MarkupType[]{new MarkupType("text/html",
new String[]{WSRPConstants.NORMAL_WINDOW_STATE},
Modified: trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerInfoTestCase.java
===================================================================
---
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerInfoTestCase.java 2007-03-30
23:45:46 UTC (rev 6889)
+++
trunk/wsrp/src/main/org/jboss/portal/test/wsrp/other/ProducerInfoTestCase.java 2007-03-30
23:58:02 UTC (rev 6890)
@@ -24,12 +24,28 @@
package org.jboss.portal.test.wsrp.other;
import junit.framework.TestCase;
+import org.jboss.portal.portlet.Portlet;
+import org.jboss.portal.portlet.PortletContext;
+import org.jboss.portal.test.wsrp.framework.PortletManagementBehavior;
+import org.jboss.portal.test.wsrp.framework.RegistrationBehavior;
import org.jboss.portal.test.wsrp.framework.ServiceDescriptionBehavior;
import org.jboss.portal.test.wsrp.framework.support.BehaviorBackedServiceFactory;
import org.jboss.portal.test.wsrp.framework.support.MockConsumerRegistry;
+import org.jboss.portal.wsrp.WSRPTypeFactory;
import org.jboss.portal.wsrp.consumer.EndpointConfigurationInfo;
import org.jboss.portal.wsrp.consumer.ProducerInfo;
+import org.jboss.portal.wsrp.core.AccessDeniedFault;
+import org.jboss.portal.wsrp.core.GetPortletDescription;
+import org.jboss.portal.wsrp.core.InconsistentParametersFault;
+import org.jboss.portal.wsrp.core.InvalidHandleFault;
+import org.jboss.portal.wsrp.core.InvalidRegistrationFault;
+import org.jboss.portal.wsrp.core.InvalidUserCategoryFault;
+import org.jboss.portal.wsrp.core.MissingParametersFault;
+import org.jboss.portal.wsrp.core.OperationFailedFault;
+import org.jboss.portal.wsrp.core.PortletDescriptionResponse;
+import java.rmi.RemoteException;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -52,20 +68,80 @@
public void testRefreshAndCache() throws Exception
{
- serviceFactory.getRegistry().setServiceDescriptionBehavior(new
ServiceDescriptionBehavior());
+ ServiceDescriptionBehavior behavior = new ServiceDescriptionBehavior();
+ serviceFactory.getRegistry().setServiceDescriptionBehavior(behavior);
assertNull(info.getExpirationCacheSeconds());
assertTrue(info.refresh(false));
assertTrue(info.refresh(false));
+ assertEquals(2, behavior.getCallCount());
info.setExpirationCacheSeconds(new Integer(1));
assertEquals(new Integer(1), info.getExpirationCacheSeconds());
assertTrue(info.refresh(false));
assertFalse(info.refresh(false));
+ assertEquals(3, behavior.getCallCount());
// wait for cache expiration
Thread.sleep(1500);
assertTrue(info.refresh(false));
+ assertFalse(info.refresh(false));
+ assertTrue(info.refresh(true));
+ assertEquals(5, behavior.getCallCount());
}
+
+ public void testGetPortlet() throws Exception
+ {
+ ServiceDescriptionBehavior behavior = new ServiceDescriptionBehavior();
+ behavior.addPortletDescription(behavior.createPortletDescription("test",
null));
+ serviceFactory.getRegistry().setServiceDescriptionBehavior(behavior);
+
+ PortletContext portletContext =
PortletContext.createPortletContext("test");
+ Portlet portlet = info.getPortlet(portletContext);
+ assertNotNull(portlet);
+ assertEquals(portletContext, portlet.getContext());
+
+ // test2 is not in the service description, so it should be looked up via Portlet
Management...
+ portletContext = PortletContext.createPortletContext("test2");
+ // add portlet management behavior
+ TestPortletManagementBehavior pmBehavior = new TestPortletManagementBehavior();
+ serviceFactory.getRegistry().setPortletManagementBehavior(pmBehavior);
+ portlet = info.getPortlet(portletContext);
+ assertEquals(1, pmBehavior.getCallCount());
+ assertNotNull(portlet);
+ assertEquals(portletContext, portlet.getContext());
+ }
+
+ public void testRefreshAndRegistration() throws Exception
+ {
+ assertFalse(info.isRegistered());
+ assertNull(info.getRegistrationInfo());
+
+ ServiceDescriptionBehavior sd = new ServiceDescriptionBehavior();
+ sd.setRequiresRegistration(true);
+ serviceFactory.getRegistry().setServiceDescriptionBehavior(sd);
+ RegistrationBehavior regBehavior = new RegistrationBehavior();
+ serviceFactory.getRegistry().setRegistrationBehavior(regBehavior);
+
+ assertTrue(info.refresh(false));
+ assertEquals(1, regBehavior.getCallCount());
+ assertTrue(info.isRegistered());
+ assertNotNull(info.getRegistrationInfo());
+ assertEquals(RegistrationBehavior.REGISTRATION_HANDLE,
info.getRegistrationInfo().getRegistrationContext().getRegistrationHandle());
+
+ assertTrue(info.refresh(true));
+ assertEquals(1, regBehavior.getCallCount());
+ }
+
+ private static class TestPortletManagementBehavior extends PortletManagementBehavior
+ {
+ public PortletDescriptionResponse getPortletDescription(GetPortletDescription
getPortletDescription)
+ throws AccessDeniedFault, InvalidHandleFault, InvalidUserCategoryFault,
InconsistentParametersFault,
+ MissingParametersFault, InvalidRegistrationFault, OperationFailedFault,
RemoteException
+ {
+ incrementCallCount();
+ return
WSRPTypeFactory.createPortletDescriptionResponse(createPortletDescription("test2",
null));
+ }
+ }
}