Author: julien(a)jboss.com
Date: 2008-04-14 12:33:27 -0400 (Mon, 14 Apr 2008)
New Revision: 10582
Removed:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/PortletRequestDecoder.java
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/PortletRequestEncoder.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/PortletRequestDecoderTestCase.java
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/PortletRequestEncoderTestCase.java
Modified:
modules/portlet/trunk/portlet/src/test/resources/local-jboss-unit.xml
Log:
remove PortletRequestDecoder and PortletRequestEncoder
Deleted:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/PortletRequestDecoder.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/PortletRequestDecoder.java 2008-04-14
13:48:45 UTC (rev 10581)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/PortletRequestDecoder.java 2008-04-14
16:33:27 UTC (rev 10582)
@@ -1,324 +0,0 @@
-/******************************************************************************
- * 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.portlet.impl;
-
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.ParametersStateString;
-import org.jboss.portal.portlet.OpaqueStateString;
-
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * This class is a possible implementation for the behavior of a request made to a
portlet. Which means that this
- * implementation does not preclude other implementations.
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 6549 $
- */
-public class PortletRequestDecoder
-{
-
- /** The mask for action. */
- public static final int ACTION_MASK = 0x00000001;
-
- /** The mask for render. */
- public static final int RENDER_MASK = 0x00000002;
-
- /** The mask for mode. */
- public static final int MODE_MASK = 0x00000004;
-
- /** The mask for window state. */
- public static final int WINDOW_STATE_MASK = 0x00000008;
-
- /** The mask for opacity. */
- public static final int OPAQUE_MASK = 0x00000010;
-
- /** The name of the URL parameter containing the mode. */
- public static final String MODE_PARAMETER = "mode";
-
- /** The name of the URL parameter containing the window state. */
- public static final String WINDOW_STATE_PARAMETER = "windowstate";
-
- /** The name of the URL parameter containing the interaction state. */
- public static final String INTERACTION_STATE_PARAMETER = "is";
-
- /** The name of the URL parameter containing the navigational state. */
- public static final String NAVIGATIONAL_STATE_PARAMETER = "ns";
-
- /** The name of the URL parameter containing the meta information. */
- public static final String META_PARAMETER = "action";
-
- /** . */
- public static final int ACTION_TYPE = 0;
-
- /** . */
- public static final int RENDER_TYPE = 1;
-
- /** . */
- public static final int NAV_TYPE = 2;
-
- /** . */
- private Mode mode;
-
- /** . */
- private WindowState windowState;
-
- /** . */
- private StateString navigationalstate;
-
- /** . */
- private StateString interactionState;
-
- /** . */
- private ParameterMap form;
-
- /** . */
- private int type;
-
- public void decode(Map queryParams, Map bodyParams) throws IllegalArgumentException
- {
- // The meta info from the URL
- int meta = 0;
- String[] metaParam = (String[])queryParams.get(META_PARAMETER);
- if (metaParam != null)
- {
- try
- {
- meta = Integer.parseInt(metaParam[0], 16);
- }
- catch (NumberFormatException ignore)
- {
- // If mask is not present then we assume that it can only be a navigation URL
(NAV_TYPE)
- }
- }
-
- //
- if ((meta & (ACTION_MASK | RENDER_MASK)) != 0)
- {
- // Check validity
- if ((meta & (ACTION_MASK | RENDER_MASK)) == (ACTION_MASK | RENDER_MASK))
- {
- throw new IllegalArgumentException("Cannot have both action and render
in the mask at the same time");
- }
-
- //
- if ((meta & ACTION_MASK) != 0)
- {
- type = ACTION_TYPE;
- }
- else
- {
- type = RENDER_TYPE;
- }
-
- // Get the mode from the parameters if it exists
- if ((meta & MODE_MASK) != 0)
- {
- String[] modeParam = (String[])queryParams.get(MODE_PARAMETER);
- if (modeParam == null)
- {
- throw new IllegalArgumentException();
- }
- mode = Mode.create(modeParam[0]);
- }
- else
- {
- mode = null;
- }
-
- // Get the window state from the parameters if it exists
- if ((meta & WINDOW_STATE_MASK) != 0)
- {
- String[] windowStateParam =
(String[])queryParams.get(WINDOW_STATE_PARAMETER);
- if (windowStateParam == null)
- {
- throw new IllegalArgumentException();
- }
- windowState = WindowState.create(windowStateParam[0]);
- }
- else
- {
- windowState = null;
- }
-
- //
- boolean opaque = (meta & OPAQUE_MASK) != 0;
- if (!opaque)
- {
- // Compute the parameters skipping the portlet navigational state that may be
encoded as well
- ParametersStateString query = ParametersStateString.create();
- for (Iterator i = queryParams.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- int index = 0;
- String name = (String)entry.getKey();
- String[] queryValues = (String[])entry.getValue();
-
- //
- if (META_PARAMETER.equals(name))
- {
- index = 1;
- }
- else if ((meta & MODE_MASK) != 0 &&
MODE_PARAMETER.equals(name))
- {
- index = 1;
- }
- else if ((meta & WINDOW_STATE_MASK) != 0 &&
WINDOW_STATE_PARAMETER.equals(name))
- {
- index = 1;
- }
-
- // We have interaction param(s) in the query string
- if (index < queryValues.length)
- {
- String[] values = new String[queryValues.length - index];
- System.arraycopy(queryValues, index, values, 0, values.length);
- query.setValues(name, values);
- }
- }
-
- // Julien :
- ParameterMap form = new ParameterMap();
- if (bodyParams != null)
- {
- form.putAll(bodyParams);
- }
-
- //
- if (type == ACTION_TYPE)
- {
- this.navigationalstate = null;
- this.interactionState = query;
- this.form = form;
- }
- else
- {
- this.navigationalstate = query;
- this.interactionState = null;
- this.form = null;
- }
- }
- else
- {
- // Decode the navigational state
- String[] ns = (String[])queryParams.get(NAVIGATIONAL_STATE_PARAMETER);
- if (ns != null)
- {
- navigationalstate = new OpaqueStateString(ns[0]);
- }
- else
- {
- navigationalstate = null;
- }
-
- // Decode more if we have an action
- if (type == ACTION_TYPE)
- {
- // Decode the interaction state
- String[] is = (String[])queryParams.get(INTERACTION_STATE_PARAMETER);
- if (is != null)
- {
- interactionState = new OpaqueStateString(is[0]);
- }
- else
- {
- interactionState = null;
- }
-
- //
- form = new ParameterMap();
- if (bodyParams != null)
- {
- form.putAll(bodyParams);
- }
- }
- else
- {
- interactionState = null;
- form = null;
- }
- }
- }
- else
- {
- // Set to nav type
- type = NAV_TYPE;
-
- // Get the mode from the parameters if it exists
- String[] modeParam = (String[])queryParams.get(MODE_PARAMETER);
- if (modeParam != null)
- {
- mode = Mode.create(modeParam[0]);
- }
- else
- {
- mode = null;
- }
-
- // Get the window state from the parameters if it exists
- String[] windowStateParam = (String[])queryParams.get(WINDOW_STATE_PARAMETER);
- if (windowStateParam != null)
- {
- windowState = WindowState.create(windowStateParam[0]);
- }
- else
- {
- windowState = null;
- }
- }
- }
-
- public Mode getMode()
- {
- return mode;
- }
-
- public WindowState getWindowState()
- {
- return windowState;
- }
-
- public StateString getNavigationalState()
- {
- return navigationalstate;
- }
-
- public StateString getInteractionState()
- {
- return interactionState;
- }
-
- public ParameterMap getForm()
- {
- return form;
- }
-
- public int getType()
- {
- return type;
- }
-}
Deleted:
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/PortletRequestEncoder.java
===================================================================
---
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/PortletRequestEncoder.java 2008-04-14
13:48:45 UTC (rev 10581)
+++
modules/portlet/trunk/portlet/src/main/java/org/jboss/portal/portlet/impl/PortletRequestEncoder.java 2008-04-14
16:33:27 UTC (rev 10582)
@@ -1,207 +0,0 @@
-/******************************************************************************
- * 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.portlet.impl;
-
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.portlet.StateString;
-import org.jboss.portal.portlet.ParametersStateString;
-import org.jboss.portal.portlet.PortletURL;
-import org.jboss.portal.portlet.RenderURL;
-import org.jboss.portal.portlet.ActionURL;
-
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * This class is designed to provide the encoding in the query string of a URL of the
following state :
- * <ul>
- * <li>A set of parameters</li>
- * <li>A mode value</li>
- * <li>A window state value</li>
- * <li>A invocation type (action or render)</li>
- * </ul>
- *
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletRequestEncoder
-{
-
- /** . */
- private ParameterMap queryParameters;
-
- public PortletRequestEncoder(ParameterMap queryParameters)
- {
- if (queryParameters == null)
- {
- throw new IllegalArgumentException();
- }
-
- //
- this.queryParameters = queryParameters;
- }
-
- public PortletRequestEncoder()
- {
- this(new ParameterMap());
- }
-
- public void encodeAction(
- StateString navigationalState,
- StateString interactionState,
- Mode mode,
- WindowState windowState) throws IllegalArgumentException
- {
- queryParameters.clear();
-
- //
- int meta = PortletRequestDecoder.ACTION_MASK;
-
- //
- if (interactionState != null)
- {
- if (interactionState instanceof ParametersStateString)
- {
- if (navigationalState != null)
- {
- throw new IllegalArgumentException("Cannot handle case with both non
opaque interaction and navigational state");
- }
-
- // Add the parameters
- Map<String, String[]> parameters =
((ParametersStateString)interactionState).getParameters();
- configure(parameters);
- }
- else
- {
- meta |= PortletRequestDecoder.OPAQUE_MASK;
-
- // Set interaction state
- queryParameters.setValue(PortletRequestDecoder.INTERACTION_STATE_PARAMETER,
interactionState.getStringValue());
-
- // We may have navigational state
- if (navigationalState != null)
- {
-
queryParameters.setValue(PortletRequestDecoder.NAVIGATIONAL_STATE_PARAMETER,
navigationalState.getStringValue());
- }
- }
- }
-
- //
- configure(meta, mode, windowState);
- }
-
- public void encodeRender(
- StateString navigationalState,
- Mode mode,
- WindowState windowState)
- {
- queryParameters.clear();
-
- //
- if (navigationalState != null)
- {
- int meta = PortletRequestDecoder.RENDER_MASK;
-
- //
- if (navigationalState instanceof ParametersStateString)
- {
- // Add the parameters
- Map<String, String[]> parameters =
((ParametersStateString)navigationalState).getParameters();
- configure(parameters);
- }
- else
- {
- meta |= PortletRequestDecoder.OPAQUE_MASK;
-
- //
- queryParameters.setValue(PortletRequestDecoder.NAVIGATIONAL_STATE_PARAMETER,
navigationalState.getStringValue());
- }
-
- //
- configure(meta, mode, windowState);
- }
- else
- {
- if (mode != null)
- {
- queryParameters.setValue(PortletRequestDecoder.MODE_PARAMETER,
mode.toString());
- }
-
- //
- if (windowState != null)
- {
- queryParameters.setValue(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
windowState.toString());
- }
- }
- }
-
- public ParameterMap getQueryParameters()
- {
- return queryParameters;
- }
-
- private void configure(Map<String, String[]> parameters)
- {
- for (Iterator i = parameters.entrySet().iterator(); i.hasNext();)
- {
- Map.Entry entry = (Map.Entry)i.next();
- String name = (String)entry.getKey();
- String[] values = (String[])entry.getValue();
- queryParameters.setValues(name, values);
- }
- }
-
- private void configure(int meta, Mode mode, WindowState windowState)
- {
- if (mode != null)
- {
- meta |= PortletRequestDecoder.MODE_MASK;
- setMetaParameter(PortletRequestDecoder.MODE_PARAMETER, mode.toString());
- }
- if (windowState != null)
- {
- meta |= PortletRequestDecoder.WINDOW_STATE_MASK;
- setMetaParameter(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
windowState.toString());
- }
- setMetaParameter(PortletRequestDecoder.META_PARAMETER, Integer.toHexString(meta));
- }
-
- private void setMetaParameter(String name, String value)
- {
- String[] values = queryParameters.getValues(name);
- if (values == null)
- {
- values = new String[]{value};
- }
- else
- {
- String[] tmp = new String[values.length + 1];
- System.arraycopy(values, 0, tmp, 1, values.length);
- tmp[0] = value;
- values = tmp;
- }
- queryParameters.setValues(name, values);
- }
-}
Deleted:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/PortletRequestDecoderTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/PortletRequestDecoderTestCase.java 2008-04-14
13:48:45 UTC (rev 10581)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/PortletRequestDecoderTestCase.java 2008-04-14
16:33:27 UTC (rev 10582)
@@ -1,680 +0,0 @@
-/******************************************************************************
- * 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;
-
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.portlet.OpaqueStateString;
-import org.jboss.portal.portlet.ParametersStateString;
-import org.jboss.portal.portlet.impl.PortletRequestDecoder;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-import static org.jboss.unit.api.Assert.*;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 6549 $
- */
-@Test
-public class PortletRequestDecoderTestCase
-{
-
- public PortletRequestDecoderTestCase()
- {
- }
-
- private String[] asStringArray(String s)
- {
- return new String[]{s};
- }
-
- @Test
- public void testCorruped()
- {
- Map queryParams = new HashMap();
- Map bodyParams = new HashMap();
- PortletRequestDecoder o = new PortletRequestDecoder();
-
- // Action + Render
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.ACTION_MASK)));
- o.decode(queryParams, null);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- }
-
- // Action + Mode
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.MODE_MASK |
PortletRequestDecoder.ACTION_MASK)));
- o.decode(queryParams, null);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- }
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.MODE_MASK |
PortletRequestDecoder.ACTION_MASK)));
- bodyParams.put(PortletRequestDecoder.MODE_PARAMETER,
asStringArray(Mode.VIEW.toString()));
- o.decode(queryParams, bodyParams);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- bodyParams.clear();
- }
-
- // Action + WindowState
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.WINDOW_STATE_MASK |
PortletRequestDecoder.ACTION_MASK)));
- o.decode(queryParams, null);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- }
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.WINDOW_STATE_MASK |
PortletRequestDecoder.ACTION_MASK)));
- bodyParams.put(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
asStringArray(WindowState.NORMAL.toString()));
- o.decode(queryParams, bodyParams);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- bodyParams.clear();
- }
-
- // Render + Mode
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.MODE_MASK |
PortletRequestDecoder.RENDER_MASK)));
- o.decode(queryParams, null);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- }
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.MODE_MASK |
PortletRequestDecoder.ACTION_MASK)));
- bodyParams.put(PortletRequestDecoder.MODE_PARAMETER,
asStringArray(Mode.VIEW.toString()));
- o.decode(queryParams, bodyParams);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- bodyParams.clear();
- }
-
- // Render + WindowState
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.WINDOW_STATE_MASK |
PortletRequestDecoder.RENDER_MASK)));
- o.decode(queryParams, bodyParams);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- }
- try
- {
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.WINDOW_STATE_MASK |
PortletRequestDecoder.ACTION_MASK)));
- bodyParams.put(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
asStringArray(WindowState.NORMAL.toString()));
- o.decode(queryParams, bodyParams);
- fail();
- }
- catch (IllegalArgumentException expected)
- {
- queryParams.clear();
- bodyParams.clear();
- }
- }
-
- @Test
- public void testNav()
- {
- Map queryParams = new HashMap();
- Map bodyParams = new HashMap();
- PortletRequestDecoder o = new PortletRequestDecoder();
-
- // Empty
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.NAV_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query mode
- queryParams.put(PortletRequestDecoder.MODE_PARAMETER,
asStringArray(Mode.VIEW.toString()));
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.NAV_TYPE, o.getType());
- assertEquals(Mode.VIEW, o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query mode two values
- queryParams.put(PortletRequestDecoder.MODE_PARAMETER, new
String[]{Mode.VIEW.toString(), Mode.EDIT.toString()});
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.NAV_TYPE, o.getType());
- assertEquals(Mode.VIEW, o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Body mode
- bodyParams.put(PortletRequestDecoder.MODE_PARAMETER,
asStringArray(Mode.VIEW.toString()));
- o.decode(queryParams, bodyParams);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.NAV_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- bodyParams.clear();
-
- // Query mode + Body mode
- queryParams.put(PortletRequestDecoder.MODE_PARAMETER, new
String[]{Mode.VIEW.toString()});
- bodyParams.put(PortletRequestDecoder.MODE_PARAMETER, new
String[]{Mode.EDIT.toString()});
- o.decode(queryParams, bodyParams);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.NAV_TYPE, o.getType());
- assertEquals(Mode.VIEW, o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
- bodyParams.clear();
-
- // Query window state
- queryParams.put(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
asStringArray(WindowState.NORMAL.toString()));
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.NAV_TYPE, o.getType());
- assertNull(o.getMode());
- assertEquals(WindowState.NORMAL, o.getWindowState());
- queryParams.clear();
-
- // Body window state
- bodyParams.put(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
asStringArray(WindowState.NORMAL.toString()));
- o.decode(queryParams, bodyParams);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.NAV_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- bodyParams.clear();
- }
-
- @Test
- public void testRender()
- {
- Map queryParams = new HashMap();
- PortletRequestDecoder o = new PortletRequestDecoder();
-
- // Empty
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK)));
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertEquals(ParametersStateString.create(), o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query mode
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.MODE_MASK)));
- queryParams.put(PortletRequestDecoder.MODE_PARAMETER,
asStringArray(Mode.VIEW.toString()));
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertEquals(ParametersStateString.create(), o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertEquals(Mode.VIEW, o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query window state
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.WINDOW_STATE_MASK)));
- queryParams.put(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
asStringArray(WindowState.NORMAL.toString()));
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertEquals(ParametersStateString.create(), o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertEquals(WindowState.NORMAL, o.getWindowState());
- queryParams.clear();
- }
-
- @Test
- public void testRenderNonOpaque()
- {
- Map queryParams = new HashMap();
- Map bodyParams = new HashMap();
- PortletRequestDecoder o = new PortletRequestDecoder();
- ParametersStateString navState = ParametersStateString.create();
-
- // Query parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK)));
- queryParams.put("foo", asStringArray("bar"));
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- navState.setValue("foo", "bar");
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- navState.clear();
- queryParams.clear();
-
- // Query meta parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER, new
String[]{Integer.toHexString(PortletRequestDecoder.RENDER_MASK), "bar"});
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- navState.setValue(PortletRequestDecoder.META_PARAMETER, "bar");
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- navState.clear();
- queryParams.clear();
-
- // Query window state parameter + window state meta parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER, new
String[]{Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.WINDOW_STATE_MASK)});
- queryParams.put(PortletRequestDecoder.WINDOW_STATE_PARAMETER, new
String[]{WindowState.NORMAL.toString(), "bar"});
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- navState.setValue(PortletRequestDecoder.WINDOW_STATE_PARAMETER, "bar");
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertEquals(WindowState.NORMAL, o.getWindowState());
- navState.clear();
- queryParams.clear();
-
- // Query window state parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER, new
String[]{Integer.toHexString(PortletRequestDecoder.RENDER_MASK)});
- queryParams.put(PortletRequestDecoder.WINDOW_STATE_PARAMETER, new
String[]{"bar"});
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- navState.setValue(PortletRequestDecoder.WINDOW_STATE_PARAMETER, "bar");
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- navState.clear();
- queryParams.clear();
-
- // Query mode parameter + mode meta parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER, new
String[]{Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.MODE_MASK)});
- queryParams.put(PortletRequestDecoder.MODE_PARAMETER, new
String[]{Mode.VIEW.toString(), "bar"});
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- navState.setValue(PortletRequestDecoder.MODE_PARAMETER, "bar");
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertEquals(Mode.VIEW, o.getMode());
- assertNull(o.getWindowState());
- navState.clear();
- queryParams.clear();
-
- // Query mode parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER, new
String[]{Integer.toHexString(PortletRequestDecoder.RENDER_MASK)});
- queryParams.put(PortletRequestDecoder.MODE_PARAMETER, new
String[]{"bar"});
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- navState.setValue(PortletRequestDecoder.MODE_PARAMETER, "bar");
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- navState.clear();
- queryParams.clear();
-
- // Body parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK)));
- bodyParams.put("foo", asStringArray("bar2"));
- o.decode(queryParams, bodyParams);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- navState.clear();
- queryParams.clear();
- bodyParams.clear();
-
- // Query multivalued parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK)));
- queryParams.put("foo", new String[]{"bar1",
"bar2"});
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- navState.setValues("foo", new String[]{"bar1",
"bar2"});
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- navState.clear();
- queryParams.clear();
-
- // Query + Body parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK)));
- queryParams.put("foo", new String[]{"bar1"});
- bodyParams.put("foo", new String[]{"bar2"});
- o.decode(queryParams, bodyParams);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- navState.setValue("foo", "bar1");
- assertEquals(navState, o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- navState.clear();
- queryParams.clear();
- bodyParams.clear();
- }
-
- @Test
- public void testRenderOpaque()
- {
- Map queryParams = new HashMap();
- Map bodyParams = new HashMap();
- PortletRequestDecoder o = new PortletRequestDecoder();
-
- // Empty
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query nav state
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- queryParams.put(PortletRequestDecoder.NAVIGATIONAL_STATE_PARAMETER,
asStringArray("navstatevalue"));
- o.decode(queryParams, bodyParams);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertEquals(new OpaqueStateString("navstatevalue"),
o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Body nav state
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- bodyParams.put(PortletRequestDecoder.NAVIGATIONAL_STATE_PARAMETER,
asStringArray("navstatevalue"));
- o.decode(queryParams, bodyParams);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
- bodyParams.clear();
-
- // Query int state is ignored
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- queryParams.put(PortletRequestDecoder.INTERACTION_STATE_PARAMETER,
asStringArray("intstatevalue"));
- o.decode(queryParams, null);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Body int state is ignored
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.RENDER_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- bodyParams.put(PortletRequestDecoder.INTERACTION_STATE_PARAMETER,
asStringArray("intstatevalue"));
- o.decode(queryParams, bodyParams);
- assertNull(o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.RENDER_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
- bodyParams.clear();
- }
-
- @Test
- public void testAction()
- {
- Map queryParams = new HashMap();
- PortletRequestDecoder o = new PortletRequestDecoder();
-
- // Empty
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK)));
- o.decode(queryParams, null);
- assertEquals(new ParameterMap(), o.getForm());
- assertEquals(ParametersStateString.create(), o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query mode
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK |
PortletRequestDecoder.MODE_MASK)));
- queryParams.put(PortletRequestDecoder.MODE_PARAMETER,
asStringArray(Mode.VIEW.toString()));
- o.decode(queryParams, null);
- assertEquals(new ParameterMap(), o.getForm());
- assertEquals(ParametersStateString.create(), o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertEquals(Mode.VIEW, o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query window state
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK |
PortletRequestDecoder.WINDOW_STATE_MASK)));
- queryParams.put(PortletRequestDecoder.WINDOW_STATE_PARAMETER,
asStringArray(WindowState.NORMAL.toString()));
- o.decode(queryParams, null);
- assertEquals(new ParameterMap(), o.getForm());
- assertEquals(ParametersStateString.create(), o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertEquals(WindowState.NORMAL, o.getWindowState());
- queryParams.clear();
- }
-
- @Test
- public void testActionNonOpaque()
- {
- Map queryParams = new HashMap();
- Map bodyParams = new HashMap();
- PortletRequestDecoder o = new PortletRequestDecoder();
- ParametersStateString intState = ParametersStateString.create();
- ParameterMap form = new ParameterMap();
-
- // Query parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK)));
- queryParams.put("foo", asStringArray("bar"));
- o.decode(queryParams, null);
- assertEquals(form, o.getForm());
- intState.setValue("foo", "bar");
- assertEquals(intState, o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- intState.clear();
- queryParams.clear();
- form.clear();
-
- // Query multivalued parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK)));
- queryParams.put("foo", new String[]{"bar1",
"bar2"});
- o.decode(queryParams, null);
- assertEquals(form, o.getForm());
- intState.setValues("foo", new String[]{"bar1",
"bar2"});
- assertEquals(intState, o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- intState.clear();
- queryParams.clear();
- form.clear();
-
- // Body parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK)));
- bodyParams.put("foo", asStringArray("bar"));
- o.decode(queryParams, bodyParams);
- form.setValue("foo", "bar");
- assertEquals(form, o.getForm());
- assertEquals(intState, o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- form.clear();
- queryParams.clear();
- bodyParams.clear();
- form.clear();
-
- // Body multivalued parameter
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK)));
- bodyParams.put("foo", new String[]{"bar1", "bar2"});
- o.decode(queryParams, bodyParams);
- form.setValues("foo", new String[]{"bar1", "bar2"});
- assertEquals(form, o.getForm());
- assertEquals(intState, o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- form.clear();
- queryParams.clear();
- bodyParams.clear();
- form.clear();
- }
-
- @Test
- public void testActionOpaque()
- {
- Map queryParams = new HashMap();
- Map bodyParams = new HashMap();
- PortletRequestDecoder o = new PortletRequestDecoder();
-
- // Empty
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- o.decode(queryParams, null);
- assertEquals(new ParameterMap(), o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query nav state
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- queryParams.put(PortletRequestDecoder.NAVIGATIONAL_STATE_PARAMETER,
asStringArray("navstatevalue"));
- o.decode(queryParams, null);
- assertEquals(new ParameterMap(), o.getForm());
- assertNull(o.getInteractionState());
- assertEquals(new OpaqueStateString("navstatevalue"),
o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Query int state
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- queryParams.put(PortletRequestDecoder.INTERACTION_STATE_PARAMETER,
asStringArray("intstatevalue"));
- o.decode(queryParams, null);
- assertEquals(new ParameterMap(), o.getForm());
- assertEquals(new OpaqueStateString("intstatevalue"),
o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
-
- // Body parameters
- queryParams.put(PortletRequestDecoder.META_PARAMETER,
asStringArray(Integer.toHexString(PortletRequestDecoder.ACTION_MASK |
PortletRequestDecoder.OPAQUE_MASK)));
- bodyParams.put("foo1", asStringArray("bar1"));
- bodyParams.put("foo2", new String[]{"bar2",
"bar3"});
- queryParams.put("foo3", new String[]{"bar4"});
- bodyParams.put("foo3", new String[]{"bar5"});
- o.decode(queryParams, bodyParams);
- ParameterMap form = new ParameterMap();
- form.setValue("foo1", "bar1");
- form.setValues("foo2", new String[]{"bar2",
"bar3"});
- form.setValues("foo3", new String[]{"bar5"});
- assertEquals(form, o.getForm());
- assertNull(o.getInteractionState());
- assertNull(o.getNavigationalState());
- assertEquals(PortletRequestDecoder.ACTION_TYPE, o.getType());
- assertNull(o.getMode());
- assertNull(o.getWindowState());
- queryParams.clear();
- bodyParams.clear();
- }
-}
Deleted:
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/PortletRequestEncoderTestCase.java
===================================================================
---
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/PortletRequestEncoderTestCase.java 2008-04-14
13:48:45 UTC (rev 10581)
+++
modules/portlet/trunk/portlet/src/test/java/org/jboss/portal/test/portlet/PortletRequestEncoderTestCase.java 2008-04-14
16:33:27 UTC (rev 10582)
@@ -1,224 +0,0 @@
-/******************************************************************************
- * 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;
-
-import org.jboss.portal.portlet.impl.PortletRequestEncoder;
-import org.jboss.portal.portlet.impl.PortletRequestDecoder;
-import org.jboss.portal.portlet.ParametersStateString;
-import org.jboss.portal.common.util.ParameterMap;
-import org.jboss.portal.Mode;
-import org.jboss.portal.WindowState;
-
-import static org.jboss.unit.api.Assert.*;
-import org.jboss.unit.api.pojo.annotations.Create;
-import org.jboss.unit.api.pojo.annotations.Destroy;
-import org.jboss.unit.api.pojo.annotations.Test;
-
-/**
- * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
- * @version $Revision: 1.1 $
- */
-public class PortletRequestEncoderTestCase
-{
-
- /** . */
- public static final int RENDER = 0;
-
- /** . */
- public static final int ACTION = 1;
-
- /** . */
- private ParameterMap params;
-
- /** . */
- private PortletRequestEncoder encoder;
-
- @Create
- public void setUp() throws Exception
- {
- params = new ParameterMap();
- encoder = new PortletRequestEncoder(params);
- }
-
- @Destroy
- public void tearDown() throws Exception
- {
- params = null;
- encoder = null;
- }
-
- @Test
- public void testEncodeRender()
- {
- _testEncodeRender(RENDER, PortletRequestDecoder.RENDER_MASK);
- }
-
- @Test
- public void testEncodeAction()
- {
- _testEncodeRender(ACTION, PortletRequestDecoder.ACTION_MASK);
- }
-
- public void _testEncodeRender(int lifecycle, int lifecycleMask)
- {
- ParametersStateString pp = ParametersStateString.create();
- encode(pp, null, null, lifecycle);
- assertEquals(1, params.size());
- _assertEquals(lifecycleMask,
params.getValues(PortletRequestDecoder.META_PARAMETER));
-
- //
- pp = ParametersStateString.create();
- pp.setValue(PortletRequestDecoder.META_PARAMETER, "foo");
- encode(pp, null, null, lifecycle);
- assertEquals(1, params.size());
- _assertEquals(new String[]{Integer.toHexString(lifecycleMask),"foo"},
params.getValues(PortletRequestDecoder.META_PARAMETER));
-
- //
- pp = ParametersStateString.create();
- pp.setValue("foo", "bar");
- encode(pp, null, null, lifecycle);
- assertEquals(2, params.size());
- _assertEquals(lifecycleMask,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals("bar", params.getValues("foo"));
-
- //
- pp = ParametersStateString.create();
- encode(pp, Mode.VIEW, null, lifecycle);
- assertEquals(2, params.size());
- _assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
-
- //
- pp = ParametersStateString.create();
- pp.setValue(PortletRequestDecoder.MODE_PARAMETER, "foo");
- encode(pp, Mode.VIEW, null, lifecycle);
- assertEquals(2, params.size());
- _assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals(new String[]{Mode.VIEW.toString(),"foo"},
params.getValues(PortletRequestDecoder.MODE_PARAMETER));
-
- //
- pp = ParametersStateString.create();
- pp.setValue("foo", "bar");
- encode(pp, Mode.VIEW, null, lifecycle);
- assertEquals(3, params.size());
- _assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
- _assertEquals("bar", params.getValues("foo"));
-
- //
- pp = ParametersStateString.create();
- encode(pp, null, WindowState.NORMAL, lifecycle);
- assertEquals(2, params.size());
- _assertEquals(lifecycleMask | PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
-
- //
- pp = ParametersStateString.create();
- pp.setValue(PortletRequestDecoder.WINDOW_STATE_PARAMETER, "foo");
- encode(pp, null, WindowState.NORMAL, lifecycle);
- assertEquals(2, params.size());
- _assertEquals(lifecycleMask | PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals(new String[]{WindowState.NORMAL.toString(),"foo"},
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
-
- //
- pp = ParametersStateString.create();
- pp.setValue("foo", "bar");
- encode(pp, null, WindowState.NORMAL, lifecycle);
- assertEquals(3, params.size());
- _assertEquals(lifecycleMask | PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
- _assertEquals("bar", params.getValues("foo"));
-
- //
- pp = ParametersStateString.create();
- encode(pp, Mode.VIEW, WindowState.NORMAL, lifecycle);
- assertEquals(3, params.size());
- _assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK |
PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
- _assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
-
- //
- pp = ParametersStateString.create();
- pp.setValue("foo", "bar");
- encode(pp, Mode.VIEW, WindowState.NORMAL, lifecycle);
- assertEquals(4, params.size());
- _assertEquals(lifecycleMask | PortletRequestDecoder.MODE_MASK |
PortletRequestDecoder.WINDOW_STATE_MASK,
params.getValues(PortletRequestDecoder.META_PARAMETER));
- _assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
- _assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
- _assertEquals("bar", params.getValues("foo"));
- }
-
- @Test
- public void testEncodeNav()
- {
- encode(null, null, null, RENDER);
- assertEquals(0, params.size());
-
- //
- encode(null, Mode.VIEW, null, RENDER);
- assertEquals(1, params.size());
- _assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
-
- //
- encode(null, null, WindowState.NORMAL, RENDER);
- assertEquals(1, params.size());
- _assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
-
- //
- encode(null, Mode.VIEW, WindowState.NORMAL, RENDER);
- assertEquals(2, params.size());
- _assertEquals(Mode.VIEW, params.getValues(PortletRequestDecoder.MODE_PARAMETER));
- _assertEquals(WindowState.NORMAL,
params.getValues(PortletRequestDecoder.WINDOW_STATE_PARAMETER));
- }
-
- private void encode(ParametersStateString params, Mode view, WindowState normal, int
lifecycle)
- {
- if (lifecycle == RENDER)
- {
- encoder.encodeRender(params, view, normal);
- }
- else if (lifecycle == ACTION)
- {
- encoder.encodeAction(null, params, view, normal);
- }
- else
- {
- fail();
- }
- }
-
- void _assertEquals(int expected, String[] actual)
- {
- _assertEquals(new String[]{Integer.toHexString(expected)}, actual);
- }
-
- void _assertEquals(Object expected, String[] actual)
- {
- _assertEquals(new String[]{"" + expected}, actual);
- }
-
- void _assertEquals(String[] expected, String[] actual)
- {
- assertEquals(expected, actual);
- }
-}
Modified: modules/portlet/trunk/portlet/src/test/resources/local-jboss-unit.xml
===================================================================
--- modules/portlet/trunk/portlet/src/test/resources/local-jboss-unit.xml 2008-04-14
13:48:45 UTC (rev 10581)
+++ modules/portlet/trunk/portlet/src/test/resources/local-jboss-unit.xml 2008-04-14
16:33:27 UTC (rev 10582)
@@ -20,12 +20,6 @@
<class
name="org.jboss.portal.test.portlet.state.StateConverterV0TestCase"/>
</test>
<test>
- <class
name="org.jboss.portal.test.portlet.PortletRequestDecoderTestCase"/>
- </test>
- <test>
- <class
name="org.jboss.portal.test.portlet.PortletRequestEncoderTestCase"/>
- </test>
- <test>
<class
name="org.jboss.portal.test.portlet.ParametersTestCase"/>
</test>
<test>