Author: julien(a)jboss.com
Date: 2008-01-14 19:57:45 -0500 (Mon, 14 Jan 2008)
New Revision: 9501
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/EventPayloadTypeConformanceTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/JAXBSerializable.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/NonJAXBSerializable.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/base/AbstractUniversalTestPortlet.java
modules/portlet/trunk/test/src/test/build.xml
modules/portlet/trunk/test/src/test/resources/jsr286/tck/event-war/WEB-INF/portlet.xml
modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml
Log:
added TCK assertion for event payload type validation with respect to JAXB
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java 2008-01-14
17:36:22 UTC (rev 9500)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/jsr168/api/StateAwareResponseImpl.java 2008-01-15
00:57:45 UTC (rev 9501)
@@ -45,10 +45,6 @@
import javax.portlet.PortletModeException;
import javax.xml.namespace.QName;
import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.datatype.XMLGregorianCalendar;
-import javax.xml.datatype.Duration;
-import javax.xml.transform.Source;
-import javax.activation.DataHandler;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
@@ -58,7 +54,7 @@
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
-import java.awt.*;
+import java.lang.annotation.Annotation;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -216,8 +212,8 @@
}
}
- private static final Set<? extends Class<? extends Serializable>> blah =
Tools.toSet(
- Boolean.class, Byte.class, Long.class, Float.class, Double.class, String.class,
URI.class, UUID.class
+ private static final Set<? extends Class<? extends Serializable>>
acceptedFinalClasses = Tools.toSet(
+ Boolean.class, Integer.class, Byte.class, Long.class, Float.class, Double.class,
String.class, URI.class, UUID.class
);
/**
@@ -228,7 +224,8 @@
*/
private boolean requiresJAXBAnnotation(Class<? extends Serializable> clazz)
{
- if (blah.contains(clazz))
+ // Since they are final a equals should be enough
+ if (acceptedFinalClasses.contains(clazz))
{
return false;
}
@@ -236,48 +233,26 @@
//
if (clazz.getName().startsWith("java"))
{
- if (clazz.getName().startsWith("java."))
+ if (BigInteger.class.isAssignableFrom(clazz))
{
- if (BigInteger.class.isAssignableFrom(clazz))
- {
- return false;
- }
- else if (BigDecimal.class.isAssignableFrom(clazz))
- {
- return false;
- }
- else if (Calendar.class.isAssignableFrom(clazz))
- {
- return false;
- }
- else if (Date.class.isAssignableFrom(clazz))
- {
- return false;
- }
+ return false;
}
- else if (clazz.getName().startsWith("javax."))
+ else if (BigDecimal.class.isAssignableFrom(clazz))
{
- if (QName.class.isAssignableFrom(clazz))
- {
- return false;
- }
- else if (XMLGregorianCalendar.class.isAssignableFrom(clazz))
- {
- return false;
- }
- else if (Duration.class.isAssignableFrom(clazz))
- {
- return false;
- }
- else if (DataHandler.class.isAssignableFrom(clazz))
- {
- return false;
- }
- else if (Source.class.isAssignableFrom(clazz))
- {
- return false;
- }
+ return false;
}
+ else if (Calendar.class.isAssignableFrom(clazz))
+ {
+ return false;
+ }
+ else if (Date.class.isAssignableFrom(clazz))
+ {
+ return false;
+ }
+ else if (QName.class.isAssignableFrom(clazz))
+ {
+ return false;
+ }
}
//
@@ -299,9 +274,13 @@
// Check jaxb annotation
if (requiresJAXBAnnotation(valueType))
{
- XmlRootElement annotation = valueType.getAnnotation(XmlRootElement.class);
- if (annotation == null)
+ for (Annotation a : value.getClass().getAnnotations())
{
+ System.out.println("a = " + a);
+ }
+ boolean b = value.getClass().isAnnotationPresent(XmlRootElement.class);
+ if (!b)
+ {
throw new IllegalArgumentException("The provided event value type
" + value.getClass().getName() +
" does not have a valid jaxb annotation");
}
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/EventPayloadTypeConformanceTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/EventPayloadTypeConformanceTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/EventPayloadTypeConformanceTestCase.java 2008-01-15
00:57:45 UTC (rev 9501)
@@ -0,0 +1,148 @@
+/******************************************************************************
+ * 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.jsr286.tck.event;
+
+import org.jboss.portal.unit.annotations.TestCase;
+import org.jboss.portal.unit.Assertion;
+import org.jboss.portal.unit.PortletTestCase;
+import org.jboss.portal.unit.PortletTestContext;
+import org.jboss.portal.unit.actions.PortletRenderTestAction;
+import org.jboss.portal.unit.actions.PortletActionTestAction;
+import org.jboss.portal.unit.actions.PortletEventTestAction;
+import org.jboss.portal.test.portlet.framework.UTP6;
+import org.jboss.unit.driver.DriverResponse;
+import org.jboss.unit.driver.response.EndTestResponse;
+import static org.jboss.unit.api.Assert.*;
+import org.jboss.unit.remote.driver.handler.http.response.InvokeGetResponse;
+
+import javax.portlet.RenderRequest;
+import javax.portlet.Portlet;
+import javax.portlet.RenderResponse;
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletException;
+import javax.portlet.EventRequest;
+import javax.portlet.EventResponse;
+import javax.portlet.Event;
+import javax.xml.namespace.QName;
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.IOException;
+import java.io.File;
+import java.io.Serializable;
+import java.util.Date;
+import java.util.UUID;
+import java.util.Calendar;
+import java.util.List;
+import java.util.ArrayList;
+import java.net.URI;
+import java.math.BigInteger;
+import java.math.BigDecimal;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+(a)TestCase({Assertion.JSR286_139})
+public class EventPayloadTypeConformanceTestCase
+{
+
+ private static final URI uri = new File("").toURI();
+ private static final UUID uuid = UUID.randomUUID();
+ private static final Calendar calendar = Calendar.getInstance();
+ private static final Date date = new Date();
+ private static final QName name = new QName("foons",
"foolocalname");
+
+ private static final List<Serializable> payloads = new
ArrayList<Serializable>();
+
+ static
+ {
+ payloads.add(true);
+ payloads.add(1); // int
+ payloads.add((byte)2);
+ payloads.add((long)3);
+ payloads.add((float)4);
+ payloads.add((double)5);
+ payloads.add("somestring");
+ payloads.add(uri);
+ payloads.add(uuid);
+ payloads.add(new BigInteger("6"));
+ payloads.add(new BigDecimal("7"));
+ payloads.add(calendar);
+ payloads.add(date);
+ payloads.add(name);
+ payloads.add(new JAXBSerializable());
+ }
+
+ public EventPayloadTypeConformanceTestCase(PortletTestCase seq)
+ {
+ seq.bindAction(0, UTP6.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context)
+ {
+ return new InvokeGetResponse(response.createActionURL().toString());
+ }
+ });
+ seq.bindAction(1, UTP6.ACTION_JOIN_POINT, new PortletActionTestAction()
+ {
+ protected void run(Portlet portlet, ActionRequest request, ActionResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ // Now try with a non JAXB serializable class
+ try
+ {
+ response.setEvent("Bar", new Serializable()
+ {
+ });
+ fail("Was expecting an IAE");
+ }
+ catch (IllegalArgumentException ignore)
+ {
+ }
+
+ // Now try a bunch of classes
+ for (Serializable payload : payloads)
+ {
+ response.setEvent("Bar", payload);
+ }
+ }
+ });
+ seq.bindAction(1, UTP6.EVENT_JOIN_POINT, new PortletEventTestAction()
+ {
+ protected void run(Portlet portlet, EventRequest request, EventResponse
response, PortletTestContext context) throws PortletException, IOException
+ {
+ Event event = request.getEvent();
+ if ("Bar".equals(event.getName()) && event.getValue() !=
null)
+ {
+ payloads.remove(event.getValue());
+ }
+ }
+ });
+ seq.bindAction(1, UTP6.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context)
+ {
+ assertEquals(0, payloads.size());
+ return new EndTestResponse();
+ }
+ });
+ }
+}
\ No newline at end of file
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/JAXBSerializable.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/JAXBSerializable.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/JAXBSerializable.java 2008-01-15
00:57:45 UTC (rev 9501)
@@ -0,0 +1,35 @@
+/******************************************************************************
+ * 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.jsr286.tck.event;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@XmlRootElement
+public class JAXBSerializable implements Serializable
+{
+}
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/NonJAXBSerializable.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/NonJAXBSerializable.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/jsr286/tck/event/NonJAXBSerializable.java 2008-01-15
00:57:45 UTC (rev 9501)
@@ -0,0 +1,33 @@
+/******************************************************************************
+ * 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.jsr286.tck.event;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+public class NonJAXBSerializable implements Serializable
+{
+}
\ No newline at end of file
Modified:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/base/AbstractUniversalTestPortlet.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/base/AbstractUniversalTestPortlet.java 2008-01-14
17:36:22 UTC (rev 9500)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/unit/base/AbstractUniversalTestPortlet.java 2008-01-15
00:57:45 UTC (rev 9501)
@@ -187,19 +187,22 @@
TestAction action = portletTestCase.getAction(ctx.getRequestCount(),
NodeId.locate(), eventJoinPoint);
//
- if (action instanceof PortletEventTestAction == false)
+ if (action != null)
{
- ctx.setResponse(new
FailureResponse(Failure.createAssertionFailure("Action for " +
ctx.getRequestCount() + " " + NodeId.locate() + " " + actionJoinPoint
+ " is not an instance of " + PortletEventTestAction.class.getName() + "
but is " + action.getClass().getName())));
- }
- else
- {
- log.debug("Found action for jointpoint " + eventJoinPoint +
" : " + action);
+ if (!(action instanceof PortletEventTestAction))
+ {
+ ctx.setResponse(new
FailureResponse(Failure.createAssertionFailure("Action for " +
ctx.getRequestCount() + " " + NodeId.locate() + " " + actionJoinPoint
+ " is not an instance of " + PortletEventTestAction.class.getName() + "
but is " + action.getClass().getName())));
+ }
+ else
+ {
+ log.debug("Found action for jointpoint " + eventJoinPoint +
" : " + action);
- //
- DriverResponse response = ((PortletEventTestAction)action).execute(this,
req, resp, ctx);
+ //
+ DriverResponse response =
((PortletEventTestAction)action).execute(this, req, resp, ctx);
- //
- ctx.setResponse(response);
+ //
+ ctx.setResponse(response);
+ }
}
}
}
Modified: modules/portlet/trunk/test/src/test/build.xml
===================================================================
--- modules/portlet/trunk/test/src/test/build.xml 2008-01-14 17:36:22 UTC (rev 9500)
+++ modules/portlet/trunk/test/src/test/build.xml 2008-01-15 00:57:45 UTC (rev 9501)
@@ -374,7 +374,6 @@
<path refid="mc.jboss_xb"/>
<path refid="mc.jboss_aop"/>
<path refid="mc.jboss_microcontainer"/>
- <path refid="mc.jaxb-api"/>
</copy>
<mkdir dir="${test.temp.lib}/tomcat-6.0"/>
@@ -522,6 +521,7 @@
<path location="${dependency.log4j.jar}"/>
<path location="${dependency.concurrent.jar}"/>
<path location="${dependency.activation.jar}"/>
+ <path location="${dependency.jaxb-api.jar}"/>
</sharedClasspath>
<configuration>
Modified:
modules/portlet/trunk/test/src/test/resources/jsr286/tck/event-war/WEB-INF/portlet.xml
===================================================================
---
modules/portlet/trunk/test/src/test/resources/jsr286/tck/event-war/WEB-INF/portlet.xml 2008-01-14
17:36:22 UTC (rev 9500)
+++
modules/portlet/trunk/test/src/test/resources/jsr286/tck/event-war/WEB-INF/portlet.xml 2008-01-15
00:57:45 UTC (rev 9501)
@@ -109,6 +109,20 @@
</supported-publishing-event>
</portlet>
+ <portlet>
+ <portlet-name>UniversalTestPortletF</portlet-name>
+
<portlet-class>org.jboss.portal.test.portlet.framework.UTP6</portlet-class>
+ <supports>
+ <mime-type>text/html</mime-type>
+ </supports>
+ <supported-processing-event>
+ <name>Bar</name>
+ </supported-processing-event>
+ <supported-publishing-event>
+ <name>Bar</name>
+ </supported-publishing-event>
+ </portlet>
+
<default-namespace>urn:default-namespace</default-namespace>
<event-definition>
@@ -121,4 +135,8 @@
<value-type>java.lang.String</value-type>
</event-definition>
+ <event-definition>
+ <name>Bar</name>
+ </event-definition>
+
</portlet-app>
Modified: modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml
===================================================================
--- modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml 2008-01-14
17:36:22 UTC (rev 9500)
+++ modules/portlet/trunk/test/src/test/resources/test/remote-jboss-unit.xml 2008-01-15
00:57:45 UTC (rev 9501)
@@ -4,7 +4,10 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:jboss:jboss-unit:1.0 jboss-unit_1_0.xsd">
- <!--Spec TCK Assertions tests-->
+<!--
+ -->
+<!--Spec TCK Assertions tests-->
+<!--
<generic>
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr168-tck-dispatcher.war"/>
@@ -50,7 +53,9 @@
<property name="archiveId"
value="test-jsr168-tck-windowstates.war"/>
</generic>
- <!--API Tests-->
+ -->
+<!--API Tests-->
+<!--
<generic>
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr168-api-actionrequest.war"/>
@@ -104,7 +109,9 @@
<property name="archiveId"
value="test-jsr168-api-windowstate.war"/>
</generic>
- <!--Ext Tests-->
+ -->
+<!--Ext Tests-->
+<!--
<generic>
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr168-ext-dispatcher.war"/>
@@ -146,7 +153,9 @@
<property name="archiveId"
value="test-jsr168-ext-nocache.war"/>
</generic>
- <!--Spec TCK Assertions tests-->
+ -->
+<!--Spec TCK Assertions tests-->
+<!--
<generic>
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr286-tck-portletconfig.war"/>
@@ -155,14 +164,17 @@
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr286-tck-portletconfignonamespace.war"/>
</generic>
+-->
<generic>
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr286-tck-event.war"/>
</generic>
+<!--
<generic>
<class
name="org.jboss.unit.remote.driver.RemoteTestDriverClient"/>
<property name="archiveId"
value="test-jsr286-tck-eventnonamespace.war"/>
</generic>
+-->
<!--Misc Tests-->
<!--