Author: chris.laprun(a)jboss.com
Date: 2011-09-15 07:00:59 -0400 (Thu, 15 Sep 2011)
New Revision: 7436
Modified:
components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java
Log:
- Make PortletContext components Serializable.
- Added test case to make sure PortletContext stays Serializable regardless of internal
changes.
Modified: components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java
===================================================================
--- components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java 2011-09-15
09:05:50 UTC (rev 7435)
+++ components/pc/trunk/api/src/main/java/org/gatein/pc/api/PortletContext.java 2011-09-15
11:00:59 UTC (rev 7436)
@@ -389,7 +389,7 @@
return components;
}
- public static interface PortletContextComponents
+ public static interface PortletContextComponents extends Serializable
{
String getApplicationName();
@@ -410,14 +410,14 @@
boolean isInterpreted();
}
- protected static interface Components extends PortletContextComponents
+ protected static interface Components extends PortletContextComponents, Serializable
{
Components createCopyWithoutInvoker();
Components createCopyWithInvoker(String invoker);
}
- private static class InterpretedPortletContextComponents implements Components
+ private static class InterpretedPortletContextComponents implements Components,
Serializable
{
private final String applicationName;
private final String portletName;
@@ -499,7 +499,7 @@
}
}
- private static class UninterpretedPortletContextComponents implements Components
+ private static class UninterpretedPortletContextComponents implements Components,
Serializable
{
private static final String ERROR = "This PortletContext was not intepreted,
only the portlet name is available!";
private final String portletName;
Modified:
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java
===================================================================
---
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java 2011-09-15
09:05:50 UTC (rev 7435)
+++
components/pc/trunk/api/src/test/java/org/gatein/pc/api/PortletContextTestCase.java 2011-09-15
11:00:59 UTC (rev 7436)
@@ -25,6 +25,12 @@
import junit.framework.TestCase;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -445,4 +451,27 @@
final PortletContext referencedContext =
PortletContext.reference("invoker", context);
assertEquals(context, PortletContext.dereference(referencedContext));
}
+
+ public void testSerializationRoundtrip()
+ {
+ final PortletContext context = PortletContext.createPortletContext(" local\t
" + PortletContext.INVOKER_SEPARATOR + " / foo \t. \t\n bar");
+
+ try
+ {
+ final File tempFile = File.createTempFile("pc-serialized", null, new
File("/tmp"));
+ tempFile.deleteOnExit();
+ ObjectOutputStream out = new ObjectOutputStream(new
FileOutputStream(tempFile.getName()));
+ out.writeObject(context);
+ out.close();
+
+ final ObjectInputStream in = new ObjectInputStream(new
FileInputStream(tempFile.getName()));
+ final Object fromSerialization = in.readObject();
+
+ assertEquals(context, fromSerialization);
+ }
+ catch (Exception ex)
+ {
+ fail(ex.getMessage());
+ }
+ }
}
Show replies by date