Author: julien(a)jboss.com
Date: 2008-02-07 11:47:40 -0500 (Thu, 07 Feb 2008)
New Revision: 9835
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/StateStringTestCase.java
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/StateControllerContextTestCase.java
Removed:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/response/portlet/PortletChunk.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/MarkupTag.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/TitleTag.java
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/OpaqueStateString.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/ParametersStateString.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/StateString.java
modules/portlet/trunk/portlet/src/test/resources/local-jboss-unit.xml
modules/portlet/trunk/test/pom.xml
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/impl/state/StateControllerContextImpl.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/state/PageNavigationalState.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java
modules/portlet/trunk/test/src/test/resources/test/local-jboss-unit.xml
Log:
- rewrote PageNavigationalState marshalling to be optimized in size
- added test cases for PageNavigationalState marshalling
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/OpaqueStateString.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/OpaqueStateString.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/OpaqueStateString.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -22,6 +22,9 @@
******************************************************************************/
package org.jboss.portal.portlet;
+import java.io.DataOutputStream;
+import java.io.IOException;
+
/**
* An opaque implementation of the navigational state.
*
@@ -31,6 +34,7 @@
public class OpaqueStateString extends StateString
{
+ /** . */
private String value;
public OpaqueStateString(String value)
@@ -47,6 +51,12 @@
return value;
}
+ public void writeTo(DataOutputStream out) throws IOException
+ {
+ out.writeByte(2);
+ out.writeUTF(value);
+ }
+
public int hashCode()
{
return value.hashCode();
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/ParametersStateString.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/ParametersStateString.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/ParametersStateString.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -31,6 +31,9 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.io.DataOutputStream;
+import java.io.InputStream;
+import java.io.DataInputStream;
import java.util.HashMap;
import java.util.Map;
@@ -63,6 +66,36 @@
}
/**
+ * Factory method that will create the most appropriate form from the byte
representation.
+ *
+ * @param in the inputstream to read from
+ * @return a new state string
+ * @throws IOException any IOException
+ */
+ public static StateString create(DataInputStream in) throws IOException
+ {
+ if (in == null)
+ {
+ throw new IllegalArgumentException();
+ }
+
+ //
+ byte b = in.readByte();
+ switch (b)
+ {
+ case 0:
+ return new ParametersStateString();
+ case 1:
+ return new ParametersStateString(in);
+ case 2:
+ return new OpaqueStateString(in.readUTF());
+ }
+
+ //
+ throw new IllegalArgumentException("Wrong format unrecognized header " +
b);
+ }
+
+ /**
* Factory method that will create the most appropriate form from the string
representation.
*
* @param opaqueValue the opaque value
@@ -116,16 +149,34 @@
/** The underlying map that does not have a copy read/write access mode. */
private ParameterMap parameters;
- private ParametersStateString(String opaqueValue)
+ private ParametersStateString(DataInputStream in) throws IOException
{
- if (opaqueValue == null)
+ int size = in.readInt();
+ Map<String, String[]> tmp = new HashMap<String, String[]>(size);
+ while (size-- > 0)
{
- throw new IllegalArgumentException("No navigational state provided");
+ String name = in.readUTF();
+ int length = in.readInt();
+ String[] values = new String[length];
+ for (int i = 0;i < length;i++)
+ {
+ values[i] = in.readUTF();
+ }
+ tmp.put(name, values);
}
+
+ //
+ parameters = ParameterMap.wrap(tmp);
+ }
+
+ private ParametersStateString(String opaqueValue)
+ {
if (!opaqueValue.startsWith(JBPNS_PREFIX))
{
throw new IllegalArgumentException("Bad format");
}
+
+ //
opaqueValue = opaqueValue.substring(JBPNS_PREFIX.length());
if (opaqueValue.length() > 0)
{
@@ -166,7 +217,7 @@
}
catch (Exception e)
{
- throw new RuntimeException(e);
+ throw new Error(e);
}
}
else
@@ -329,6 +380,31 @@
}
}
+ public void writeTo(DataOutputStream out) throws IOException
+ {
+ if (parameters.isEmpty())
+ {
+ out.writeByte(0);
+ }
+ else
+ {
+ out.writeByte(1);
+ out.writeInt(parameters.size());
+ for (Map.Entry entry : parameters.entrySet())
+ {
+ String name = (String)entry.getKey();
+ out.writeUTF(name);
+ String[] values = (String[])entry.getValue();
+ int length = values.length;
+ out.writeInt(length);
+ for (String value : values)
+ {
+ out.writeUTF(value);
+ }
+ }
+ }
+ }
+
public String toString()
{
return "StateString[" + parameters + "]";
Modified:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/StateString.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/StateString.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/StateString.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -23,6 +23,10 @@
package org.jboss.portal.portlet;
import java.io.Serializable;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.util.zip.GZIPOutputStream;
/**
* Encapsulate state as a string.
@@ -39,13 +43,6 @@
*/
public abstract String getStringValue();
- public static StateString createFrom(String opaqueValue)
- {
- if (opaqueValue == null)
- {
- return null;
- }
- return new OpaqueStateString(opaqueValue);
- }
+ public abstract void writeTo(DataOutputStream out) throws IOException;
}
Added:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/StateStringTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/StateStringTestCase.java
(rev 0)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/StateStringTestCase.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -0,0 +1,74 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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;
+
+import org.jboss.unit.api.pojo.annotations.Test;
+import org.jboss.portal.portlet.ParametersStateString;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.OpaqueStateString;
+import org.jboss.portal.common.util.MapBuilder;
+import static org.jboss.unit.api.Assert.*;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.util.zip.GZIPOutputStream;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@Test
+public class StateStringTestCase
+{
+
+ @Test
+ public void testMarshalling() throws IOException
+ {
+ check(new OpaqueStateString("blah"));
+ check(ParametersStateString.create());
+ check(MapBuilder.hashMap("foo", new String[]{"bar"}).get());
+ check(MapBuilder.hashMap("foo", new
String[]{"foo_1"}).put("bar", new String[]{"bar_1",
"bar_2"}).get());
+ }
+
+ private void check(Map<String, String[]> parameters) throws IOException
+ {
+ check(ParametersStateString.create(parameters));
+ }
+
+ private void check(StateString parameters) throws IOException
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream(baos);
+ parameters.writeTo(out);
+ out.close();
+ byte[] bytes = baos.toByteArray();
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ DataInputStream in = new DataInputStream(bais);
+ StateString copy = ParametersStateString.create(in);
+ assertEquals(parameters, copy);
+ }
+}
Modified: modules/portlet/trunk/portlet/src/test/resources/local-jboss-unit.xml
===================================================================
--- modules/portlet/trunk/portlet/src/test/resources/local-jboss-unit.xml 2008-02-07
12:22:13 UTC (rev 9834)
+++ modules/portlet/trunk/portlet/src/test/resources/local-jboss-unit.xml 2008-02-07
16:47:40 UTC (rev 9835)
@@ -34,5 +34,8 @@
<test>
<class
name="org.jboss.portal.test.portlet.ContentBufferTestCase"/>
</test>
+ <test>
+ <class
name="org.jboss.portal.test.portlet.StateStringTestCase"/>
+ </test>
</pojo>
</jboss-unit>
Modified: modules/portlet/trunk/test/pom.xml
===================================================================
--- modules/portlet/trunk/test/pom.xml 2008-02-07 12:22:13 UTC (rev 9834)
+++ modules/portlet/trunk/test/pom.xml 2008-02-07 16:47:40 UTC (rev 9835)
@@ -206,6 +206,11 @@
</execution>
</executions>
<configuration>
+ <!--<jpda>false</jpda>-->
+ <!--<jpdaPort>9000</jpdaPort>-->
+ <!--<jpdaSuspend>true</jpdaSuspend>-->
+ <!--<failOnError>false</failOnError>-->
+ <!--<assertions>true</assertions>-->
<testsuites>
<testsuite>
<config>test/local-jboss-unit.xml</config>
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/impl/state/PageNavigationalStateImpl.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -33,6 +33,7 @@
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
+import java.util.Set;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -42,7 +43,7 @@
{
/** We don't save it. */
- protected transient StateControllerContextImpl context;
+ protected final StateControllerContextImpl context;
/** . */
protected final Map<String, WindowNavigationalState> windows;
@@ -64,6 +65,11 @@
this.page = new HashMap<QName, String[]>(original.page);
}
+ public Set<String> getWindowIds()
+ {
+ return windows.keySet();
+ }
+
public WindowNavigationalState getWindowNavigationalState(String windowId)
{
return windows.get(windowId);
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/impl/state/StateControllerContextImpl.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/impl/state/StateControllerContextImpl.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/impl/state/StateControllerContextImpl.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -25,14 +25,22 @@
import org.jboss.portal.portlet.controller.PortletControllerContext;
import org.jboss.portal.portlet.controller.state.PageNavigationalState;
import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.ParametersStateString;
+import org.jboss.portal.WindowState;
+import org.jboss.portal.Mode;
+import org.jboss.portal.common.io.UndeclaredIOException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.DataOutputStream;
+import java.io.DataInputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
+import java.util.Map;
+import java.util.HashMap;
/**
* @author <a href="mailto:julien@jboss.org">Julien Viet</a>
@@ -42,10 +50,44 @@
{
/** . */
+ private static final Map<WindowState, Integer> windowStateToCode = new
HashMap<WindowState, Integer>();
+
+ /** . */
+ private static final Map<Mode, Integer> modeToCode = new HashMap<Mode,
Integer>();
+
+ /** . */
+ private static final Map<Integer, WindowState> codeToWindowState = new
HashMap<Integer, WindowState>();
+
+ /** . */
+ private static final Map<Integer, Mode> codeToMode = new HashMap<Integer,
Mode>();
+
+ static
+ {
+ windowStateToCode.put(WindowState.NORMAL, 1);
+ windowStateToCode.put(WindowState.MINIMIZED, 2);
+ windowStateToCode.put(WindowState.MAXIMIZED, 3);
+ codeToWindowState.put(1, WindowState.NORMAL);
+ codeToWindowState.put(2, WindowState.MINIMIZED);
+ codeToWindowState.put(3, WindowState.MAXIMIZED);
+ modeToCode.put(Mode.VIEW, 1);
+ modeToCode.put(Mode.EDIT, 2);
+ modeToCode.put(Mode.HELP, 3);
+ codeToMode.put(1, Mode.VIEW);
+ codeToMode.put(2, Mode.EDIT);
+ codeToMode.put(3, Mode.HELP);
+ }
+
+ /** . */
protected final PortletControllerContext portletControllerContext;
public StateControllerContextImpl(PortletControllerContext portletControllerContext)
{
+ if (portletControllerContext == null)
+ {
+ throw new IllegalArgumentException("No portlet controller context
available");
+ }
+
+ //
this.portletControllerContext = portletControllerContext;
}
@@ -59,23 +101,127 @@
return new MutablePageNavigationalState(this);
}
- public byte[] serialize(PageNavigationalState object) throws IOException
+ public byte[] serialize(PageNavigationalState object)
{
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- GZIPOutputStream zos = new GZIPOutputStream(baos);
- ObjectOutputStream oos = new ObjectOutputStream(zos);
- oos.writeObject(object);
- oos.close();
- return baos.toByteArray();
+ try
+ {
+ PageNavigationalStateImpl pageState = (PageNavigationalStateImpl)object;
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ GZIPOutputStream zos = new GZIPOutputStream(baos);
+ DataOutputStream out = new DataOutputStream(zos);
+ out.writeInt(pageState.windows.size());
+ for (Map.Entry<String, WindowNavigationalState> entry :
pageState.windows.entrySet())
+ {
+ out.writeUTF(entry.getKey());
+ WindowNavigationalState windowNS = entry.getValue();
+ byte header = 0;
+ int decision = 0;
+ if (windowNS.getPortletNavigationalState() != null)
+ {
+ header |= 1;
+ decision |= 1;
+ }
+ if (windowNS.getWindowState() != null)
+ {
+ Integer value = windowStateToCode.get(windowNS.getWindowState());
+ if (value != null)
+ {
+ header |= value << 1;
+ }
+ else
+ {
+ header |= 4 << 1;
+ decision |= 2;
+ }
+ }
+ if (windowNS.getMode() != null)
+ {
+ Integer value = modeToCode.get(windowNS.getMode());
+ if (value != null)
+ {
+ header |= value << 4;
+ }
+ else
+ {
+ header |= 4 << 4;
+ decision |= 4;
+ }
+ }
+ out.writeByte(header);
+ if ((decision & 1) != 0)
+ {
+ windowNS.getPortletNavigationalState().writeTo(out);
+ }
+ if ((decision & 2) != 0)
+ {
+ out.writeUTF(windowNS.getWindowState().toString());
+ }
+ if ((decision & 4) != 0)
+ {
+ out.writeUTF(windowNS.getMode().toString());
+ }
+ }
+ out.close();
+ return baos.toByteArray();
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
}
- public PageNavigationalState unserialize(byte[] bytes) throws IOException,
ClassNotFoundException
+ public PageNavigationalState unserialize(byte[] bytes)
{
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- GZIPInputStream zis = new GZIPInputStream(bais);
- ObjectInputStream ois = new ObjectInputStream(zis);
- PageNavigationalStateImpl state = (PageNavigationalStateImpl)ois.readObject();
- state.context = this;
- return state;
+ try
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ GZIPInputStream zis = new GZIPInputStream(bais);
+ DataInputStream in = new DataInputStream(zis);
+ PageNavigationalStateImpl pageState = new MutablePageNavigationalState(this);
+ int size = in.readInt();
+ while (size-- > 0)
+ {
+ String windowId = in.readUTF();
+ byte header = in.readByte();
+ StateString portletNS = null;
+ if ((header & 1) != 0)
+ {
+ portletNS = ParametersStateString.create(in);
+ }
+ WindowState windowState = null;
+ int windowStateHeader = (header & (7 << 1)) >> 1;
+ switch (windowStateHeader)
+ {
+ case 0:
+ break;
+ case 4:
+ windowState = WindowState.create(in.readUTF());
+ break;
+ default:
+ windowState = codeToWindowState.get(windowStateHeader);
+ }
+ Mode mode = null;
+ int modeStateHeader = (header & (7 << (1 + 3))) >> (1 + 3);
+ switch (modeStateHeader)
+ {
+ case 0:
+ break;
+ case 4:
+ mode = Mode.create(in.readUTF());
+ break;
+ default:
+ mode = codeToMode.get(modeStateHeader);
+ }
+ WindowNavigationalState windowNS = new WindowNavigationalState(portletNS,
mode, windowState);
+ pageState.setWindowNavigationalState(windowId, windowNS);
+ }
+
+ //
+ return pageState;
+ }
+ catch (IOException e)
+ {
+ throw new UndeclaredIOException(e);
+ }
}
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/state/PageNavigationalState.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/state/PageNavigationalState.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/controller/state/PageNavigationalState.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -26,6 +26,7 @@
import javax.xml.namespace.QName;
import java.util.Map;
+import java.util.Set;
/**
* Defines the page navigational state that the controller needs.
@@ -36,6 +37,8 @@
public interface PageNavigationalState
{
+ Set<String> getWindowIds();
+
/**
* Returns the navigational state of a window or null if it does not exist.
*
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/AbstractPortletControllerContext.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -30,6 +30,7 @@
import org.jboss.portal.common.util.MediaType;
import org.jboss.portal.common.util.ParameterMap;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.util.Base64;
import org.jboss.portal.portlet.ParametersStateString;
import org.jboss.portal.portlet.Portlet;
import org.jboss.portal.portlet.PortletInvokerException;
@@ -131,7 +132,7 @@
String context = req.getParameter(PAGE_STATE);
if (context != null)
{
- byte[] bytes = Tools.fromHexString(context);
+ byte[] bytes = Base64.decode(context, true);
pageState = tmp.unserialize(bytes);
}
Modified:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/controller/PortletURLRenderer.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -27,6 +27,7 @@
import org.jboss.portal.common.text.CharBuffer;
import org.jboss.portal.common.text.FastURLEncoder;
import org.jboss.portal.common.util.Tools;
+import org.jboss.portal.common.util.Base64;
import org.jboss.portal.portlet.ActionURL;
import org.jboss.portal.portlet.ContainerURL;
import org.jboss.portal.portlet.PortletURL;
@@ -126,18 +127,11 @@
//
String pageState = null;
- try
+ if (pageNS != null)
{
- if (pageNS != null)
- {
- byte[] bytes = stateContext.serialize(pageNS);
- pageState = Tools.toHexString(bytes);
- }
+ byte[] bytes = stateContext.serialize(pageNS);
+ pageState = Base64.encodeBytes(bytes, true);
}
- catch (IOException e)
- {
- throw new Error(e); //
- }
//
if (containerURL instanceof PortletURL)
Deleted:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/response/portlet/PortletChunk.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/response/portlet/PortletChunk.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/response/portlet/PortletChunk.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -1,86 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.portlet.test.jsp.response.portlet;
-
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.portlet.test.jsp.response.Chunk;
-
-import java.util.Set;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class PortletChunk extends Chunk
-{
-
- /** . */
- private final String portletName;
-
- /** . */
- private final String applicationName;
-
- /** . */
- private final Mode initialMode;
-
- /** . */
- private final Set<Mode> supportedModes;
-
- /** . */
- private final Set<WindowState> supportedWindowStates;
-
- public PortletChunk(String portletName, String applicationName, Mode initialMode,
Set<Mode> supportedModes, Set<WindowState> supportedWindowStates)
- {
- this.portletName = portletName;
- this.applicationName = applicationName;
- this.initialMode = initialMode;
- this.supportedModes = supportedModes;
- this.supportedWindowStates = supportedWindowStates;
- }
-
- public String getPortletName()
- {
- return portletName;
- }
-
- public String getApplicationName()
- {
- return applicationName;
- }
-
- public Mode getInitialMode()
- {
- return initialMode;
- }
-
- public Set<Mode> getSupportedModes()
- {
- return supportedModes;
- }
-
- public Set<WindowState> getSupportedWindowStates()
- {
- return supportedWindowStates;
- }
-}
Deleted:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/MarkupTag.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/MarkupTag.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/MarkupTag.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -1,38 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.portlet.test.jsp.taglib;
-
-import org.jboss.portal.portlet.test.jsp.response.Chunk;
-import org.jboss.portal.portlet.test.jsp.response.portlet.PortletMarkupChunk;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class MarkupTag extends SimpleChunkTagSupport
-{
- protected Chunk doChunkTag()
- {
- return new PortletMarkupChunk();
- }
-}
Deleted:
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/TitleTag.java
===================================================================
---
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/TitleTag.java 2008-02-07
12:22:13 UTC (rev 9834)
+++
modules/portlet/trunk/test/src/main/java/org/jboss/portal/portlet/test/jsp/taglib/TitleTag.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -1,38 +0,0 @@
-/******************************************************************************
- * JBoss, a division of Red Hat *
- * Copyright 2008, 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.portlet.test.jsp.taglib;
-
-import org.jboss.portal.portlet.test.jsp.response.Chunk;
-import org.jboss.portal.portlet.test.jsp.response.portlet.StartPortletTitleChunk;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 630 $
- */
-public class TitleTag extends SimpleChunkTagSupport
-{
- protected Chunk doChunkTag()
- {
- return new StartPortletTitleChunk();
- }
-}
Added:
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/StateControllerContextTestCase.java
===================================================================
---
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/StateControllerContextTestCase.java
(rev 0)
+++
modules/portlet/trunk/test/src/test/java/org/jboss/portal/portlet/controller/StateControllerContextTestCase.java 2008-02-07
16:47:40 UTC (rev 9835)
@@ -0,0 +1,165 @@
+/******************************************************************************
+ * JBoss, a division of Red Hat *
+ * Copyright 2008, 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.portlet.controller;
+
+import org.jboss.unit.api.pojo.annotations.Test;
+import org.jboss.portal.portlet.controller.impl.state.StateControllerContextImpl;
+import org.jboss.portal.portlet.controller.state.PageNavigationalState;
+import org.jboss.portal.portlet.controller.state.StateControllerContext;
+import org.jboss.portal.portlet.controller.state.WindowNavigationalState;
+import org.jboss.portal.portlet.controller.event.EventControllerContext;
+import org.jboss.portal.portlet.info.PortletInfo;
+import org.jboss.portal.portlet.PortletInvokerException;
+import org.jboss.portal.portlet.ParametersStateString;
+import org.jboss.portal.portlet.StateString;
+import org.jboss.portal.portlet.invocation.response.PortletInvocationResponse;
+import org.jboss.portal.portlet.invocation.ActionInvocation;
+import org.jboss.portal.portlet.invocation.EventInvocation;
+import org.jboss.portal.portlet.invocation.ResourceInvocation;
+import org.jboss.portal.portlet.spi.PortletInvocationContext;
+import org.jboss.portal.common.NotYetImplemented;
+import org.jboss.portal.Mode;
+import org.jboss.portal.WindowState;
+import static org.jboss.unit.api.Assert.*;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.Cookie;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
+ * @version $Revision: 630 $
+ */
+@Test
+public class StateControllerContextTestCase
+{
+
+ /** . */
+ private StateControllerContextImpl cc = new StateControllerContextImpl(dummyContext);
+
+ @Test
+ public void testMarshalling1()
+ {
+ PageNavigationalState pageNS = cc.createPageState();
+ assertMarshallable(pageNS);
+ }
+
+ @Test
+ public void testMarshalling2()
+ {
+ ParametersStateString params = ParametersStateString.create();
+ params.setValue("foo", "bar");
+ test(null, null, null);
+ test(null, Mode.VIEW, null);
+ test(null, null, WindowState.NORMAL);
+ test(null, Mode.VIEW, WindowState.NORMAL);
+ test(null, Mode.create("foo"), null);
+ test(null, null, WindowState.create("bar"));
+ test(null, Mode.create("foo"), WindowState.create("bar"));
+ test(params, null, null);
+ test(params, Mode.VIEW, null);
+ test(params, null, WindowState.NORMAL);
+ test(params, Mode.VIEW, WindowState.NORMAL);
+ test(params, Mode.create("foo"), null);
+ test(params, null, WindowState.create("bar"));
+ test(params, Mode.create("foo"), WindowState.create("bar"));
+ }
+
+ private void test(StateString portletNavigationalState, Mode mode, WindowState
windowState)
+ {
+ PageNavigationalState pageNS = cc.createPageState();
+ pageNS.setWindowNavigationalState("foo", new
WindowNavigationalState(portletNavigationalState, mode, windowState));
+ assertMarshallable(pageNS);
+ }
+
+ private void assertMarshallable(PageNavigationalState pageNS)
+ {
+ byte[] bytes = cc.serialize(pageNS);
+ PageNavigationalState expectedPageNS = cc.unserialize(bytes);
+ assertEquals(expectedPageNS.getWindowIds(), pageNS.getWindowIds());
+ for (String windowId : expectedPageNS.getWindowIds())
+ {
+ WindowNavigationalState windowNS =
expectedPageNS.getWindowNavigationalState(windowId);
+ WindowNavigationalState expectedWindowNS =
pageNS.getWindowNavigationalState(windowId);
+ assertEquals(windowNS.getPortletNavigationalState(),
expectedWindowNS.getPortletNavigationalState());
+ assertEquals(windowNS.getMode(), expectedWindowNS.getMode());
+ assertEquals(windowNS.getWindowState(), expectedWindowNS.getWindowState());
+ }
+ }
+
+ private static final PortletControllerContext dummyContext = new
PortletControllerContext()
+ {
+ public ServletContext getServletContext()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public HttpServletRequest getClientRequest()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public HttpServletResponse getClientResponse()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletInfo getPortletInfo(String windowId) throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletInvocationContext createPortletInvocationContext(String windowId,
PageNavigationalState pageState)
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletInvocationResponse invoke(String windowId, ActionInvocation
actionInvocation) throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletInvocationResponse invoke(String windowId, List<Cookie>
requestCookies, EventInvocation eventInvocation) throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public PortletInvocationResponse invoke(String windowId, ResourceInvocation
resourceInvocation) throws PortletInvokerException
+ {
+ throw new NotYetImplemented();
+ }
+
+ public EventControllerContext getEventControllerContext()
+ {
+ throw new NotYetImplemented();
+ }
+
+ public StateControllerContext getStateControllerContext()
+ {
+ throw new NotYetImplemented();
+ }
+ };
+
+}
Modified: modules/portlet/trunk/test/src/test/resources/test/local-jboss-unit.xml
===================================================================
--- modules/portlet/trunk/test/src/test/resources/test/local-jboss-unit.xml 2008-02-07
12:22:13 UTC (rev 9834)
+++ modules/portlet/trunk/test/src/test/resources/test/local-jboss-unit.xml 2008-02-07
16:47:40 UTC (rev 9835)
@@ -83,5 +83,9 @@
<value>factory</value>
</parameter>
</test>
+ <test>
+ <class
name="org.jboss.portal.portlet.controller.StateControllerContextTestCase">
+ </class>
+ </test>
</pojo>
</jboss-unit>