You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by jo...@apache.org on 2011/06/26 10:30:02 UTC
svn commit: r1139729 [2/3] - in /struts/struts2/trunk: ./ apps/portlet/
apps/portlet/src/main/webapp/WEB-INF/
archetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/
archetypes/struts2-archetype-dbportlet/src/main/resources/arche...
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequest.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet.servlet;
import java.io.BufferedReader;
@@ -25,7 +26,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.security.Principal;
-import java.util.Collections;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;
@@ -42,7 +42,12 @@ import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
-import static org.apache.struts2.portlet.PortletConstants.*;
+import org.apache.struts2.StrutsConstants;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.apache.struts2.portlet.context.PortletActionContext;
+
+import com.opensymphony.xwork2.inject.Inject;
/**
* Wrapper object exposing a {@link PortletRequest} as a
@@ -50,24 +55,17 @@ import static org.apache.struts2.portlet
* will in fact operate on the {@link PortletRequest} object wrapped by this
* request object.
*/
-public class PortletServletRequest implements HttpServletRequest {
+public class PortletServletRequest implements HttpServletRequest, PortletActionConstants {
private PortletRequest portletRequest;
private PortletContext portletContext;
- private Map<String, String[]> extraParams;
-
- public PortletServletRequest(PortletRequest portletRequest,
- PortletContext portletContext) {
- this(portletRequest, portletContext, Collections.EMPTY_MAP);
- }
+ private String extension;
- public PortletServletRequest(PortletRequest portletRequest,
- PortletContext portletContext, Map<String, String[]> extraParams) {
- this.portletContext = portletContext;
+ public PortletServletRequest(PortletRequest portletRequest, PortletContext portletContext) {
this.portletRequest = portletRequest;
- this.extraParams = extraParams;
+ this.portletContext = portletContext;
}
/*
@@ -238,12 +236,17 @@ public class PortletServletRequest imple
*/
public String getServletPath() {
String actionPath = getParameter(ACTION_PARAM);
- if (actionPath != null && !actionPath.endsWith(".action")) {
- actionPath += ".action";
+ if (!hasExtension(actionPath)) {
+ actionPath += "." + extension;
}
return actionPath;
}
+ private boolean hasExtension(String actionPath) {
+ return extension == null || "".equals(extension)
+ || (actionPath != null && actionPath.endsWith("." + extension));
+ }
+
/**
* Get the {@link PortletSession} as a {@link PortletHttpSession} instance.
*
@@ -399,8 +402,7 @@ public class PortletServletRequest imple
*/
public ServletInputStream getInputStream() throws IOException {
if (portletRequest instanceof ActionRequest) {
- return new PortletServletInputStream(
- ((ActionRequest) portletRequest).getPortletInputStream());
+ return new PortletServletInputStream(((ActionRequest) portletRequest).getPortletInputStream());
} else {
throw new IllegalStateException("Not allowed in render phase");
}
@@ -469,13 +471,6 @@ public class PortletServletRequest imple
* @see javax.servlet.ServletRequest#getParameter(java.lang.String)
*/
public String getParameter(String name) {
- // Check if the parameter is overriden in the extra params
- if (extraParams.containsKey(name)) {
- String[] values = extraParams.get(name);
- if (values != null && values.length > 0) {
- return values[0];
- }
- }
return portletRequest.getParameter(name);
}
@@ -589,8 +584,7 @@ public class PortletServletRequest imple
* @see javax.servlet.ServletRequest#getRequestDispatcher(java.lang.String)
*/
public RequestDispatcher getRequestDispatcher(String path) {
- return new PortletServletRequestDispatcher(portletContext
- .getRequestDispatcher(path));
+ return new PortletServletRequestDispatcher(portletContext.getRequestDispatcher(path));
}
/*
@@ -659,8 +653,7 @@ public class PortletServletRequest imple
* @throws IllegalStateException
* If the portlet is not in the event phase.
*/
- public void setCharacterEncoding(String env)
- throws UnsupportedEncodingException {
+ public void setCharacterEncoding(String env) throws UnsupportedEncodingException {
if (portletRequest instanceof ActionRequest) {
((ActionRequest) portletRequest).setCharacterEncoding(env);
} else {
@@ -676,4 +669,11 @@ public class PortletServletRequest imple
public PortletRequest getPortletRequest() {
return portletRequest;
}
+
+ @Inject(StrutsConstants.STRUTS_ACTION_EXTENSION)
+ public void setExtension(String extension) {
+ if (extension != null) {
+ this.extension = extension.split(",")[0];
+ }
+ }
}
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequestDispatcher.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequestDispatcher.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequestDispatcher.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletRequestDispatcher.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet.servlet;
import java.io.IOException;
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletResponse.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletResponse.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletResponse.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/servlet/PortletServletResponse.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet.servlet;
import java.io.IOException;
@@ -32,7 +33,7 @@ import javax.servlet.http.HttpServletRes
public class PortletServletResponse implements HttpServletResponse {
- protected PortletResponse portletResponse;
+ private PortletResponse portletResponse;
public PortletServletResponse(PortletResponse portletResponse) {
this.portletResponse = portletResponse;
@@ -47,7 +48,7 @@ public class PortletServletResponse impl
}
public void addHeader(String name, String value) {
- portletResponse.addProperty(name, value);
+ throw new IllegalStateException("Not allowed in a portlet");
}
public void addIntHeader(String name, int value) {
@@ -106,125 +107,125 @@ public class PortletServletResponse impl
throw new IllegalStateException("Not allowed in a portlet");
}
- public void flushBuffer() throws IOException {
- if(portletResponse instanceof RenderResponse) {
- ((RenderResponse)portletResponse).flushBuffer();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public int getBufferSize() {
- if(portletResponse instanceof RenderResponse) {
- return ((RenderResponse)portletResponse).getBufferSize();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public String getCharacterEncoding() {
- if(portletResponse instanceof RenderResponse) {
- return ((RenderResponse)portletResponse).getCharacterEncoding();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public String getContentType() {
- if(portletResponse instanceof RenderResponse) {
- return ((RenderResponse)portletResponse).getContentType();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public Locale getLocale() {
- if(portletResponse instanceof RenderResponse) {
- return ((RenderResponse)portletResponse).getLocale();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public ServletOutputStream getOutputStream() throws IOException {
- if(portletResponse instanceof RenderResponse) {
- return new PortletServletOutputStream(((RenderResponse)portletResponse).getPortletOutputStream());
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public PrintWriter getWriter() throws IOException {
- if(portletResponse instanceof RenderResponse) {
- return ((RenderResponse)portletResponse).getWriter();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public boolean isCommitted() {
- if(portletResponse instanceof RenderResponse) {
- return ((RenderResponse)portletResponse).isCommitted();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public void reset() {
- if(portletResponse instanceof RenderResponse) {
- ((RenderResponse)portletResponse).reset();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public void resetBuffer() {
- if(portletResponse instanceof RenderResponse) {
- ((RenderResponse)portletResponse).resetBuffer();
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public void setBufferSize(int size) {
- if(portletResponse instanceof RenderResponse) {
- ((RenderResponse)portletResponse).setBufferSize(size);
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public void setCharacterEncoding(String charset) {
- throw new IllegalStateException("Not allowed in a portlet");
- }
-
- public void setContentLength(int len) {
- throw new IllegalStateException("Not allowed in a portlet");
- }
-
- public void setContentType(String type) {
- if(portletResponse instanceof RenderResponse) {
- ((RenderResponse)portletResponse).setContentType(type);
- }
- else {
- throw new IllegalStateException("Not allowed in event phase");
- }
- }
-
- public void setLocale(Locale loc) {
- throw new IllegalStateException("Not allowed in a portlet");
- }
+ public void flushBuffer() throws IOException {
+ if(portletResponse instanceof RenderResponse) {
+ ((RenderResponse)portletResponse).flushBuffer();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public int getBufferSize() {
+ if(portletResponse instanceof RenderResponse) {
+ return ((RenderResponse)portletResponse).getBufferSize();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public String getCharacterEncoding() {
+ if(portletResponse instanceof RenderResponse) {
+ return ((RenderResponse)portletResponse).getCharacterEncoding();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public String getContentType() {
+ if(portletResponse instanceof RenderResponse) {
+ return ((RenderResponse)portletResponse).getContentType();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public Locale getLocale() {
+ if(portletResponse instanceof RenderResponse) {
+ return ((RenderResponse)portletResponse).getLocale();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public ServletOutputStream getOutputStream() throws IOException {
+ if(portletResponse instanceof RenderResponse) {
+ return new PortletServletOutputStream(((RenderResponse)portletResponse).getPortletOutputStream());
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public PrintWriter getWriter() throws IOException {
+ if(portletResponse instanceof RenderResponse) {
+ return ((RenderResponse)portletResponse).getWriter();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public boolean isCommitted() {
+ if(portletResponse instanceof RenderResponse) {
+ return ((RenderResponse)portletResponse).isCommitted();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public void reset() {
+ if(portletResponse instanceof RenderResponse) {
+ ((RenderResponse)portletResponse).reset();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public void resetBuffer() {
+ if(portletResponse instanceof RenderResponse) {
+ ((RenderResponse)portletResponse).resetBuffer();
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public void setBufferSize(int size) {
+ if(portletResponse instanceof RenderResponse) {
+ ((RenderResponse)portletResponse).setBufferSize(size);
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public void setCharacterEncoding(String charset) {
+ throw new IllegalStateException("Not allowed in a portlet");
+ }
+
+ public void setContentLength(int len) {
+ throw new IllegalStateException("Not allowed in a portlet");
+ }
+
+ public void setContentType(String type) {
+ if(portletResponse instanceof RenderResponse) {
+ ((RenderResponse)portletResponse).setContentType(type);
+ }
+ else {
+ throw new IllegalStateException("Not allowed in event phase");
+ }
+ }
+
+ public void setLocale(Locale loc) {
+ throw new IllegalStateException("Not allowed in a portlet");
+ }
public PortletResponse getPortletResponse() {
return portletResponse;
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/portlet/util/PortletUrlHelper.java Sun Jun 26 08:30:00 2011
@@ -18,11 +18,17 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet.util;
-import static org.apache.struts2.portlet.PortletConstants.ACTION_PARAM;
-import static org.apache.struts2.portlet.PortletConstants.MODE_PARAM;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import org.apache.commons.lang.StringUtils;
+import org.apache.struts2.StrutsException;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.apache.struts2.portlet.context.PortletActionContext;
+import javax.portlet.*;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;
@@ -30,26 +36,12 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.StringTokenizer;
-import javax.portlet.PortletMode;
-import javax.portlet.PortletRequest;
-import javax.portlet.PortletSecurityException;
-import javax.portlet.PortletURL;
-import javax.portlet.RenderResponse;
-import javax.portlet.WindowState;
-
-import org.apache.commons.lang.StringUtils;
-import org.apache.struts2.StrutsException;
-import org.apache.struts2.portlet.context.PortletActionContext;
-
-import com.opensymphony.xwork2.util.logging.Logger;
-import com.opensymphony.xwork2.util.logging.LoggerFactory;
-
/**
* Helper class for creating Portlet URLs. Portlet URLs are fundamentally different from regular
* servlet URLs since they never target the application itself; all requests go through the portlet
* container and must therefore be programatically constructed using the
- * {@link javax.portlet.MimeResponse#createActionURL()} and
- * {@link javax.portlet.MimeResponse#createRenderURL()} APIs.
+ * {@link javax.portlet.RenderResponse#createActionURL()} and
+ * {@link javax.portlet.RenderResponse#createRenderURL()} APIs.
*
*/
public class PortletUrlHelper {
@@ -57,13 +49,6 @@ public class PortletUrlHelper {
private static final Logger LOG = LoggerFactory.getLogger(PortletUrlHelper.class);
- protected static final String PORTLETMODE_NAME_EDIT = "edit";
- protected static final String PORTLETMODE_NAME_VIEW = "view";
- protected static final String PORTLETMODE_NAME_HELP = "help";
-
- protected static final String URLTYPE_NAME_ACTION = "action";
- protected static final String URLTYPE_NAME_RESOURCE = "resource";
-
/**
* Create a portlet URL with for the specified action and namespace.
*
@@ -76,7 +61,7 @@ public class PortletUrlHelper {
* @param state The WindowState of the URL.
* @return The URL String.
*/
- public String buildUrl(String action, String namespace, String method, Map<String, Object> params,
+ public static String buildUrl(String action, String namespace, String method, Map params,
String type, String mode, String state) {
return buildUrl(action, namespace, method, params, null, type, mode, state,
true, true);
@@ -85,19 +70,23 @@ public class PortletUrlHelper {
/**
* Create a portlet URL with for the specified action and namespace.
*
- * @see #buildUrl(String, String, String, java.util.Map, String, String, String)
+ * @see #buildUrl(String, String, Map, String, String, String)
*/
- public String buildUrl(String action, String namespace, String method, Map<String, Object> params,
+ public static String buildUrl(String action, String namespace, String method, Map params,
String scheme, String type, String portletMode, String windowState,
boolean includeContext, boolean encodeResult) {
StringBuffer resultingAction = new StringBuffer();
- PortletRequest request = PortletActionContext.getRequest();
- LOG.debug("Creating url. Action = " + action + ", Namespace = "
+ RenderRequest request = PortletActionContext.getRenderRequest();
+ RenderResponse response = PortletActionContext.getRenderResponse();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Creating url. Action = " + action + ", Namespace = "
+ namespace + ", Type = " + type);
- namespace = prependNamespace(namespace, portletMode, !URLTYPE_NAME_RESOURCE.equalsIgnoreCase(type));
+ }
+ namespace = prependNamespace(namespace, portletMode);
if (StringUtils.isEmpty(portletMode)) {
- portletMode = PortletActionContext.getRequest().getPortletMode().toString();
+ portletMode = PortletActionContext.getRenderRequest().getPortletMode().toString();
}
+ String result = null;
int paramStartIndex = action.indexOf('?');
if (paramStartIndex > 0) {
String value = action;
@@ -122,81 +111,60 @@ public class PortletUrlHelper {
resultingAction.append("!").append(method);
}
if (LOG.isDebugEnabled()) LOG.debug("Resulting actionPath: " + resultingAction);
- params.put(ACTION_PARAM, new String[] { resultingAction.toString() });
- params.put(MODE_PARAM, new String[]{portletMode});
- final Map<String, String[]> portletParams = ensureParamsAreStringArrays(params);
-
- Object url = createUrl(scheme, type, portletParams);
- if(url instanceof PortletURL) {
- try {
- final PortletURL portletUrl = (PortletURL) url;
- portletUrl.setPortletMode(getPortletMode(request, portletMode));
- portletUrl.setWindowState(getWindowState(request, windowState));
- } catch (Exception e) {
- LOG.error("Unable to set mode or state:" + e.getMessage(), e);
- }
- }
-
- String result = url.toString();
- // TEMP BUG-WORKAROUND FOR DOUBLE ESCAPING OF AMPERSAND
- if(result.indexOf("&") >= 0) {
- result = result.replace("&", "&");
- }
- return result;
+ params.put(PortletActionConstants.ACTION_PARAM, new String[] { resultingAction.toString() });
- }
-
- protected Object createUrl( String scheme, String type, Map<String, String[]> portletParams ) {
- RenderResponse response = PortletActionContext.getRenderResponse();
- PortletURL url;
- if (URLTYPE_NAME_ACTION.equalsIgnoreCase(type)) {
+ PortletURL url = null;
+ if ("action".equalsIgnoreCase(type)) {
if (LOG.isDebugEnabled()) LOG.debug("Creating action url");
url = response.createActionURL();
- }
- else {
+ } else {
if (LOG.isDebugEnabled()) LOG.debug("Creating render url");
url = response.createRenderURL();
}
- url.setParameters(portletParams);
+ params.put(PortletActionConstants.MODE_PARAM, portletMode);
+ url.setParameters(ensureParamsAreStringArrays(params));
if ("HTTPS".equalsIgnoreCase(scheme)) {
try {
url.setSecure(true);
- } catch ( PortletSecurityException e) {
+ } catch (PortletSecurityException e) {
LOG.error("Cannot set scheme to https", e);
}
}
- return url;
+ try {
+ url.setPortletMode(getPortletMode(request, portletMode));
+ url.setWindowState(getWindowState(request, windowState));
+ } catch (Exception e) {
+ LOG.error("Unable to set mode or state:" + e.getMessage(), e);
+ }
+ result = url.toString();
+ // TEMP BUG-WORKAROUND FOR DOUBLE ESCAPING OF AMPERSAND
+ if(result.indexOf("&") >= 0) {
+ result = result.replace("&", "&");
+ }
+ return result;
+
}
/**
+ *
* Prepend the namespace configuration for the specified namespace and PortletMode.
*
- * @param namespace The base namespace.
- * @param portletMode The PortletMode.
- * @param prependModeNamespace In JSR286, the new URL type resource was added, which does not operate in the context
- * of a portlet mode. If the URL to create is of type resource, this parameter should be
- * set to false. Set it to true in any other case.
+ * @param namespace The base namespace.
+ * @param portletMode The PortletMode.
+ *
* @return prepended namespace.
*/
- private String prependNamespace(String namespace, String portletMode, boolean prependModeNamespace) {
+ private static String prependNamespace(String namespace, String portletMode) {
StringBuffer sb = new StringBuffer();
- String modeNamespace;
- if (prependModeNamespace) {
- PortletMode mode = PortletActionContext.getRequest().getPortletMode();
- if(StringUtils.isNotEmpty(portletMode)) {
- mode = new PortletMode(portletMode);
- }
- modeNamespace = (String)PortletActionContext.getModeNamespaceMap().get(mode);
- } else {
- modeNamespace = null;
+ PortletMode mode = PortletActionContext.getRenderRequest().getPortletMode();
+ if(StringUtils.isNotEmpty(portletMode)) {
+ mode = new PortletMode(portletMode);
}
String portletNamespace = PortletActionContext.getPortletNamespace();
- if (LOG.isDebugEnabled()) {
- LOG.debug("PortletNamespace: " + portletNamespace + ", modeNamespace: "
- + (modeNamespace!=null ? modeNamespace : "IGNORED"));
- }
+ String modeNamespace = (String)PortletActionContext.getModeNamespaceMap().get(mode);
+ if (LOG.isDebugEnabled()) LOG.debug("PortletNamespace: " + portletNamespace + ", modeNamespace: " + modeNamespace);
if(StringUtils.isNotEmpty(portletNamespace)) {
sb.append(portletNamespace);
}
@@ -223,7 +191,7 @@ public class PortletUrlHelper {
* @param value
* @return encoded url to non Struts action resources.
*/
- public String buildResourceUrl(String value, Map params) {
+ public static String buildResourceUrl(String value, Map<String, Object> params) {
StringBuffer sb = new StringBuffer();
// Relative URLs are not allowed in a portlet
if (!value.startsWith("/")) {
@@ -232,14 +200,13 @@ public class PortletUrlHelper {
sb.append(value);
if(params != null && params.size() > 0) {
sb.append("?");
- Iterator it = params.keySet().iterator();
+ Iterator<Map.Entry<String, Object>> it = params.entrySet().iterator();
try {
while(it.hasNext()) {
- String key = (String)it.next();
- String val = (String)params.get(key);
+ Map.Entry<String, Object> entry = it.next();
- sb.append(URLEncoder.encode(key, ENCODING)).append("=");
- sb.append(URLEncoder.encode(val, ENCODING));
+ sb.append(URLEncoder.encode(entry.getKey(), ENCODING)).append("=");
+ sb.append(URLEncoder.encode(entry.getValue().toString(), ENCODING));
if(it.hasNext()) {
sb.append("&");
}
@@ -248,12 +215,8 @@ public class PortletUrlHelper {
throw new StrutsException("Encoding "+ENCODING+" not found");
}
}
- PortletRequest req = PortletActionContext.getRequest();
- return encodeUrl(sb, req);
- }
-
- protected String encodeUrl( StringBuffer sb, PortletRequest req ) {
RenderResponse resp = PortletActionContext.getRenderResponse();
+ RenderRequest req = PortletActionContext.getRenderRequest();
return resp.encodeURL(req.getContextPath() + sb.toString());
}
@@ -264,16 +227,18 @@ public class PortletUrlHelper {
* @param params The parameters to the URL.
* @return A Map with all parameters as String arrays.
*/
- public static Map<String, String[]> ensureParamsAreStringArrays(Map<String, Object> params) {
+ public static Map ensureParamsAreStringArrays(Map<String, Object> params) {
Map<String, String[]> result = null;
if (params != null) {
result = new LinkedHashMap<String, String[]>(params.size());
- for ( String key : params.keySet() ) {
- Object val = params.get(key);
+ Iterator<Map.Entry<String, Object>> it = params.entrySet().iterator();
+ while (it.hasNext()) {
+ Map.Entry<String, Object> entry = it.next();
+ Object val = entry.getValue();
if (val instanceof String[]) {
- result.put(key, (String[]) val);
+ result.put(entry.getKey(), (String[])val);
} else {
- result.put(key, new String[]{val.toString()});
+ result.put(entry.getKey(), new String[] { val.toString() });
}
}
}
@@ -283,12 +248,12 @@ public class PortletUrlHelper {
/**
* Convert the given String to a WindowState object.
*
- * @param portletReq The PortletRequest.
+ * @param portletReq The RenderRequest.
* @param windowState The WindowState as a String.
* @return The WindowState that mathces the <tt>windowState</tt> String, or if
* the String is blank, the current WindowState.
*/
- private WindowState getWindowState(PortletRequest portletReq,
+ private static WindowState getWindowState(RenderRequest portletReq,
String windowState) {
WindowState state = portletReq.getWindowState();
if (StringUtils.isNotEmpty(windowState)) {
@@ -309,21 +274,21 @@ public class PortletUrlHelper {
/**
* Convert the given String to a PortletMode object.
*
- * @param portletReq The PortletRequest.
+ * @param portletReq The RenderRequest.
* @param portletMode The PortletMode as a String.
* @return The PortletMode that mathces the <tt>portletMode</tt> String, or if
* the String is blank, the current PortletMode.
*/
- private PortletMode getPortletMode(PortletRequest portletReq,
+ private static PortletMode getPortletMode(RenderRequest portletReq,
String portletMode) {
PortletMode mode = portletReq.getPortletMode();
if (StringUtils.isNotEmpty(portletMode)) {
- if (PORTLETMODE_NAME_EDIT.equalsIgnoreCase(portletMode)) {
+ if ("edit".equalsIgnoreCase(portletMode)) {
mode = PortletMode.EDIT;
- } else if (PORTLETMODE_NAME_VIEW.equalsIgnoreCase(portletMode)) {
+ } else if ("view".equalsIgnoreCase(portletMode)) {
mode = PortletMode.VIEW;
- } else if (PORTLETMODE_NAME_HELP.equalsIgnoreCase(portletMode)) {
+ } else if ("help".equalsIgnoreCase(portletMode)) {
mode = PortletMode.HELP;
}
}
Modified: struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.views.freemarker;
import java.io.IOException;
@@ -50,7 +51,7 @@ import freemarker.template.TemplateModel
/**
*/
-public class PortletFreemarkerResult extends StrutsResultSupport implements PortletActionConstants {
+public class PortletFreemarkerResult extends StrutsResultSupport implements PortletActionConstants{
private static final long serialVersionUID = -5570612389289887543L;
@@ -104,7 +105,7 @@ public class PortletFreemarkerResult ext
*/
public void doExecute(String location, ActionInvocation invocation)
throws IOException, TemplateException, PortletException {
- if (PortletActionContext.isAction()) {
+ if (PortletActionContext.isEvent()) {
executeActionResult(location, invocation);
} else if (PortletActionContext.isRender()) {
executeRenderResult(location, invocation);
@@ -119,9 +120,8 @@ public class PortletFreemarkerResult ext
ActionInvocation invocation) {
ActionResponse res = PortletActionContext.getActionResponse();
// View is rendered outside an action...uh oh...
- invocation.getInvocationContext().getSession().put(RENDER_DIRECT_LOCATION, location);
+ invocation.getInvocationContext().getSession().put(RENDER_DIRECT_LOCATION, location);
res.setRenderParameter(PortletActionConstants.ACTION_PARAM, "freemarkerDirect");
- res.setRenderParameter("location", location);
res.setRenderParameter(PortletActionConstants.MODE_PARAM, PortletActionContext
.getRequest().getPortletMode().toString());
Modified: struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml (original)
+++ struts/struts2/trunk/plugins/portlet/src/main/resources/struts-plugin.xml Sun Jun 26 08:30:00 2011
@@ -21,10 +21,9 @@
* under the License.
*/
-->
-
<!DOCTYPE struts PUBLIC
- "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
- "http://struts.apache.org/dtds/struts-2.1.7.dtd">
+ "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+ "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
@@ -33,7 +32,8 @@
<constant name="struts.urlRenderer" value="portlet" />
<constant name="struts.portlet.useDispatcherServlet" value="false" />
<constant name="struts.portlet.dispatcherServletName" value="Struts2PortletDispatcherServlet" />
-
+ <constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="false" />
+
<package name="struts-portlet-default" extends="struts-default">
<result-types>
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet;
import java.util.ArrayList;
@@ -94,7 +95,7 @@ public class PortletApplicationMapTest e
Enumeration names = new Enumeration() {
- List keys = Arrays.asList("key1", "key2");
+ List keys = Arrays.asList(new Object[] { "key1", "key2" });
Iterator it = keys.iterator();
@@ -109,7 +110,7 @@ public class PortletApplicationMapTest e
};
Enumeration initParamNames = new Enumeration() {
- List keys = Arrays.asList("key3");
+ List keys = Arrays.asList(new Object[] { "key3" });
Iterator it = keys.iterator();
@@ -156,7 +157,7 @@ public class PortletApplicationMapTest e
mockPortletContext.expects(once()).method("removeAttribute").with(eq("key1"));
mockPortletContext.expects(once()).method("removeAttribute").with(eq("key2"));
- ArrayList<String> dummy = new ArrayList<String>();
+ ArrayList dummy = new ArrayList();
dummy.add("key1");
dummy.add("key2");
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet;
import java.util.Iterator;
@@ -83,27 +84,25 @@ public class PortletRequestMapTest exten
PortletRequestMap map = new PortletRequestMap(request);
Set entries = map.entrySet();
- assertEquals(3, entries.size());
+ assertEquals(2, entries.size());
Iterator it = entries.iterator();
- for (Iterator iterator = entries.iterator(); iterator.hasNext();) {
- Map.Entry entry = (Map.Entry) iterator.next();
- checkEntry(entry);
- }
+ Map.Entry entry = (Map.Entry)it.next();
+ checkEntry(entry);
+ entry = (Map.Entry)it.next();
+ checkEntry(entry);
+
}
- private void checkEntry(Map.Entry entry) {
- if(entry.getKey().equals("testAttribute1")) {
+ private void checkEntry(Map.Entry entry) {
+ if(entry.getKey().equals("testAttribute1")) {
assertEquals("testValue1", entry.getValue());
}
else if(entry.getKey().equals("testAttribute2")) {
assertEquals("testValue2", entry.getValue());
}
- else if(entry.getKey().equals("javax.portlet.lifecycle_phase")) {
- assertNull(entry.getValue());
- }
else {
- fail("Unexpected entry in entry set: " + entry);
+ fail("Unexpected entry in etry set: " + entry);
}
- }
+ }
}
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet;
import java.util.Iterator;
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java Sun Jun 26 08:30:00 2011
@@ -18,10 +18,8 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts2.portlet.context;
-import static org.apache.struts2.portlet.PortletConstants.*;
-import static org.apache.struts2.portlet.context.PortletActionContext.*;
+package org.apache.struts2.portlet.context;
import java.util.HashMap;
import java.util.Map;
@@ -32,7 +30,10 @@ import javax.portlet.PortletConfig;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
+import junit.textui.TestRunner;
+
import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.portlet.PortletActionConstants;
import org.jmock.Mock;
import org.jmock.MockObjectTestCase;
@@ -56,7 +57,7 @@ public class PortletActionContextTest ex
PortletConfig portletConfig;
- Map<String, Object> context = new HashMap<String, Object>();
+ Map context = new HashMap();
public void setUp() throws Exception {
super.setUp();
@@ -77,63 +78,53 @@ public class PortletActionContextTest ex
}
public void testGetPhase() {
- context.put(PHASE, RENDER_PHASE);
+ context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
- assertEquals(RENDER_PHASE, getPhase());
+ assertEquals(PortletActionConstants.RENDER_PHASE, PortletActionContext.getPhase());
}
public void testIsRender() {
- context.put(PHASE, RENDER_PHASE);
+ context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
- assertTrue(isRender());
- assertFalse(isAction());
- assertFalse(isEvent());
+ assertTrue(PortletActionContext.isRender());
+ assertFalse(PortletActionContext.isEvent());
}
- public void testIsAction() {
- context.put(PHASE, ACTION_PHASE);
-
- assertTrue(isAction());
- assertFalse(isRender());
- assertFalse(isEvent());
- }
-
public void testIsEvent() {
- context.put(PHASE, EVENT_PHASE);
-
- assertTrue(isEvent());
- assertFalse(isAction());
- assertFalse(isRender());
+ context.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
+
+ assertTrue(PortletActionContext.isEvent());
+ assertFalse(PortletActionContext.isRender());
}
public void testGetPortletConfig() {
- context.put(PORTLET_CONFIG, portletConfig);
- assertSame(portletConfig, getPortletConfig());
+ context.put(PortletActionConstants.PORTLET_CONFIG, portletConfig);
+ assertSame(portletConfig, PortletActionContext.getPortletConfig());
}
public void testGetRenderRequestAndResponse() {
- context.put(REQUEST, renderRequest);
- context.put(RESPONSE, renderResponse);
- context.put(PHASE, RENDER_PHASE);
- assertSame(renderRequest, getRenderRequest());
- assertSame(renderResponse, getRenderResponse());
- assertSame(renderRequest, getRequest());
- assertSame(renderResponse, getResponse());
+ context.put(PortletActionConstants.REQUEST, renderRequest);
+ context.put(PortletActionConstants.RESPONSE, renderResponse);
+ context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
+ assertSame(renderRequest, PortletActionContext.getRenderRequest());
+ assertSame(renderResponse, PortletActionContext.getRenderResponse());
+ assertSame(renderRequest, PortletActionContext.getRequest());
+ assertSame(renderResponse, PortletActionContext.getResponse());
}
public void testGetRenderRequestAndResponseInEventPhase() {
- context.put(REQUEST, renderRequest);
- context.put(RESPONSE, renderResponse);
- context.put(PHASE, ACTION_PHASE);
+ context.put(PortletActionConstants.REQUEST, renderRequest);
+ context.put(PortletActionConstants.RESPONSE, renderResponse);
+ context.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
try {
- getRenderRequest();
+ PortletActionContext.getRenderRequest();
fail("Should throw IllegalStateException!");
}
catch(IllegalStateException e) {
assertTrue(true);
}
try {
- getRenderResponse();
+ PortletActionContext.getRenderResponse();
fail("Should throw IllegalStateException!");
}
catch(IllegalStateException e) {
@@ -142,28 +133,28 @@ public class PortletActionContextTest ex
}
public void testGetActionRequestAndResponse() {
- context.put(REQUEST, actionRequest);
- context.put(RESPONSE, actionResponse);
- context.put(PHASE, ACTION_PHASE);
- assertSame(actionRequest, getActionRequest());
- assertSame(actionResponse, getActionResponse());
- assertSame(actionRequest, getRequest());
- assertSame(actionResponse, getResponse());
+ context.put(PortletActionConstants.REQUEST, actionRequest);
+ context.put(PortletActionConstants.RESPONSE, actionResponse);
+ context.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
+ assertSame(actionRequest, PortletActionContext.getActionRequest());
+ assertSame(actionResponse, PortletActionContext.getActionResponse());
+ assertSame(actionRequest, PortletActionContext.getRequest());
+ assertSame(actionResponse, PortletActionContext.getResponse());
}
public void testGetActionRequestAndResponseInRenderPhase() {
- context.put(REQUEST, actionRequest);
- context.put(RESPONSE, actionResponse);
- context.put(PHASE, RENDER_PHASE);
+ context.put(PortletActionConstants.REQUEST, actionRequest);
+ context.put(PortletActionConstants.RESPONSE, actionResponse);
+ context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
try {
- getActionRequest();
+ PortletActionContext.getActionRequest();
fail("Should throw IllegalStateException!");
}
catch(IllegalStateException e) {
assertTrue(true);
}
try {
- getActionResponse();
+ PortletActionContext.getActionResponse();
fail("Should throw IllegalStateException!");
}
catch(IllegalStateException e) {
@@ -172,14 +163,14 @@ public class PortletActionContextTest ex
}
public void testGetNamespace() {
- context.put(PORTLET_NAMESPACE, "testNamespace");
- assertEquals("testNamespace", getPortletNamespace());
+ context.put(PortletActionConstants.PORTLET_NAMESPACE, "testNamespace");
+ assertEquals("testNamespace", PortletActionContext.getPortletNamespace());
}
public void testGetDefaultActionForMode() {
ActionMapping mapping = new ActionMapping();
- context.put(DEFAULT_ACTION_FOR_MODE, mapping);
- assertEquals(mapping, getDefaultActionForMode());
+ context.put(PortletActionConstants.DEFAULT_ACTION_FOR_MODE, mapping);
+ assertEquals(mapping, PortletActionContext.getDefaultActionForMode());
}
public void tearDown() throws Exception {
@@ -187,4 +178,7 @@ public class PortletActionContextTest ex
super.tearDown();
}
+ public static void main(String[] args) {
+ TestRunner.run(PortletActionContextTest.class);
+ }
}
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet.dispatcher;
import com.opensymphony.xwork2.Action;
@@ -27,7 +28,7 @@ import com.opensymphony.xwork2.ActionPro
import com.opensymphony.xwork2.util.ValueStack;
import org.apache.struts2.StrutsConstants;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
-import static org.apache.struts2.portlet.PortletConstants.*;
+import org.apache.struts2.portlet.PortletActionConstants;
import org.easymock.EasyMock;
import org.jmock.Mock;
import org.jmock.cglib.MockObjectTestCase;
@@ -40,248 +41,259 @@ import java.util.*;
/**
* Jsr168DispatcherTest. Insert description.
- *
+ *
*/
-public class Jsr168DispatcherTest extends MockObjectTestCase {
-
- private final String MULTIPART_REQUEST = "-----------------------------4827543632391\r\n"
- + "Content-Disposition: form-data; name=\"upload\"; filename=\"test.txt\"\r\n"
- + "Content-Type: text/plain\r\n"
- + "\r\n"
- + "This is a test file\r\n"
- + "-----------------------------4827543632391\r\n"
- + "Content-Disposition: form-data; name=\"caption\"\r\n"
- + "\r\n"
- + "TestCaption\r\n"
- + "-----------------------------4827543632391--";
-
- Jsr168Dispatcher dispatcher = null;
- Mock mockConfig = null;
- Mock mockCtx = null;
- Mock mockRequest = null;
- Mock mockSession = null;
- Mock mockActionFactory = null;
- Mock mockActionProxy = null;
- Mock mockAction = null;
- Mock mockInvocation = null;
-
- public void setUp() {
- dispatcher = new Jsr168Dispatcher();
- }
-
- private void initPortletConfig(final Map<String, String> initParams, final Map<String, Object> attributes) {
- mockConfig = mock(PortletConfig.class);
- mockCtx = mock(PortletContext.class);
- mockConfig.stubs().method(ANYTHING);
- mockCtx.stubs().method(ANYTHING);
- setupStub(initParams, mockConfig, "getInitParameter");
- mockCtx.stubs().method("getAttributeNames").will(returnValue(Collections.enumeration(attributes.keySet())));
- setupStub(attributes, mockCtx, "getAttribute");
- mockConfig.stubs().method("getPortletContext").will(returnValue(mockCtx.proxy()));
- mockCtx.stubs().method("getInitParameterNames").will(returnValue(Collections.enumeration(initParams.keySet())));
- setupStub(initParams, mockCtx, "getInitParameter");
- mockConfig.stubs().method("getInitParameterNames").will(returnValue(Collections.enumeration(initParams.keySet())));
- setupStub(initParams, mockConfig, "getInitParameter");
- mockConfig.stubs().method("getResourceBundle").will(returnValue(new ListResourceBundle() {
- protected Object[][] getContents() {
- return new String[][]{{"javax.portlet.title", "MyTitle"}};
- }
- }));
- }
-
- private void setupActionFactory(String namespace, String actionName, String result, ValueStack stack) {
- if(mockActionFactory == null) {
- mockActionFactory = mock(ActionProxyFactory.class);
- }
- mockAction = mock(Action.class);
- mockActionProxy = mock(ActionProxy.class);
- mockInvocation = mock(ActionInvocation.class);
-
- mockActionFactory.expects(once()).method("createActionProxy").with(new Constraint[]{eq(namespace), eq(actionName), NULL, isA(Map.class)}).will(returnValue(mockActionProxy.proxy()));
- mockActionProxy.stubs().method("getAction").will(returnValue(mockAction.proxy()));
- mockActionProxy.expects(once()).method("execute").will(returnValue(result));
- mockActionProxy.expects(once()).method("getInvocation").will(returnValue(mockInvocation.proxy()));
- mockInvocation.stubs().method("getStack").will(returnValue(stack));
-
- }
-
- public void testParseConfigWithBang() {
- MockPortletContext portletContext = new MockPortletContext();
- MockPortletConfig portletConfig = new MockPortletConfig(portletContext);
-
- portletConfig.addInitParameter("viewNamespace", "/view");
- portletConfig.addInitParameter("defaultViewAction", "index!input");
-
- Map<PortletMode, ActionMapping> actionMap = new HashMap<PortletMode, ActionMapping>();
-
- dispatcher.parseModeConfig(actionMap, portletConfig, PortletMode.VIEW, "viewNamespace", "defaultViewAction");
-
- ActionMapping mapping = actionMap.get(PortletMode.VIEW);
- assertEquals("index", mapping.getName());
- assertEquals("/view", mapping.getNamespace());
- assertEquals("input", mapping.getMethod());
- }
-
- public void testRender_ok() {
- final Mock mockResponse = mock(RenderResponse.class);
- mockResponse.stubs().method(ANYTHING);
-
- PortletMode mode = PortletMode.VIEW;
-
- Map<String, String[]> requestParams = new HashMap<String, String[]>();
- requestParams.put(ACTION_PARAM, new String[]{"/view/testAction"});
- requestParams.put(EVENT_ACTION, new String[]{"true"});
- requestParams.put(MODE_PARAM, new String[]{mode.toString()});
-
- Map<String, Object> sessionMap = new HashMap<String, Object>();
-
-
-
- Map<String, String> initParams = new HashMap<String, String>();
- initParams.put("viewNamespace", "/view");
- initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE, "true");
-
- initPortletConfig(initParams, new HashMap<String, Object>());
- initRequest(requestParams, new HashMap<String, Object>(), sessionMap, PortletMode.VIEW, WindowState.NORMAL, false, null);
- setupActionFactory("/view", "testAction", "success", EasyMock.createNiceMock(ValueStack.class));
-
- mockInvocation.expects(once()).method("getStack").will(
- returnValue(null));
- //mockSession.expects(once()).method("setAttribute").with(new Constraint[]{eq(PortletActionConstants.LAST_MODE), eq(PortletMode.VIEW)});
- try {
- dispatcher
- .setActionProxyFactory((ActionProxyFactory) mockActionFactory
- .proxy());
- dispatcher.init((PortletConfig) mockConfig.proxy());
- dispatcher.render((RenderRequest) mockRequest.proxy(),
- (RenderResponse) mockResponse.proxy());
- } catch (Exception e) {
- e.printStackTrace();
- fail("Error occured");
- }
- }
-
- public void testProcessAction_ok() {
- final Mock mockResponse = mock(ActionResponse.class);
+public class Jsr168DispatcherTest extends MockObjectTestCase implements PortletActionConstants {
- PortletMode mode = PortletMode.VIEW;
- Map<String, String> initParams = new HashMap<String, String>();
- initParams.put("viewNamespace", "/view");
-
- Map<String, String[]> requestParams = new HashMap<String, String[]>();
- requestParams.put(ACTION_PARAM, new String[]{"/view/testAction"});
- requestParams.put(MODE_PARAM, new String[]{mode.toString()});
-
- initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE, "true");
- initPortletConfig(initParams, new HashMap<String, Object>());
- initRequest(requestParams, new HashMap<String, Object>(), new HashMap<String, Object>(), PortletMode.VIEW, WindowState.NORMAL, true, null);
- setupActionFactory("/view", "testAction", "success", EasyMock.createNiceMock(ValueStack.class));
- //mockSession.expects(once()).method("setAttribute").with(new Constraint[]{eq(PortletActionConstants.LAST_MODE), eq(PortletMode.VIEW)});
- try {
- dispatcher
- .setActionProxyFactory((ActionProxyFactory) mockActionFactory
- .proxy());
- dispatcher.init((PortletConfig) mockConfig.proxy());
- dispatcher.processAction((ActionRequest) mockRequest.proxy(),
- (ActionResponse) mockResponse.proxy());
- } catch (Exception e) {
- e.printStackTrace();
- fail("Error occured");
- }
- }
+ private final String MULTIPART_REQUEST = "-----------------------------4827543632391\r\n"
+ + "Content-Disposition: form-data; name=\"upload\"; filename=\"test.txt\"\r\n"
+ + "Content-Type: text/plain\r\n"
+ + "\r\n"
+ + "This is a test file\r\n"
+ + "-----------------------------4827543632391\r\n"
+ + "Content-Disposition: form-data; name=\"caption\"\r\n"
+ + "\r\n"
+ + "TestCaption\r\n" + "-----------------------------4827543632391--";
+
+ Jsr168Dispatcher dispatcher = null;
+
+ Mock mockConfig = null;
+
+ Mock mockCtx = null;
+
+ Mock mockRequest = null;
+
+ Mock mockSession = null;
+
+ Mock mockActionFactory = null;
+
+ Mock mockActionProxy = null;
+
+ Mock mockAction = null;
+
+ Mock mockInvocation = null;
+
+ public void setUp() throws Exception {
+ super.setUp();
+ dispatcher = new Jsr168Dispatcher();
+ }
+
+ private void initPortletConfig(final Map<String, String> initParams, final Map<String, Object> attributes) {
+ mockConfig = mock(PortletConfig.class);
+ mockCtx = mock(PortletContext.class);
+ mockConfig.stubs().method(ANYTHING);
+ mockCtx.stubs().method(ANYTHING);
+ setupStub(initParams, mockConfig, "getInitParameter");
+ mockCtx.stubs().method("getAttributeNames").will(returnValue(Collections.enumeration(attributes.keySet())));
+ setupStub(attributes, mockCtx, "getAttribute");
+ mockConfig.stubs().method("getPortletContext").will(returnValue(mockCtx.proxy()));
+ mockCtx.stubs().method("getInitParameterNames").will(returnValue(Collections.enumeration(initParams.keySet())));
+ setupStub(initParams, mockCtx, "getInitParameter");
+ mockConfig.stubs().method("getInitParameterNames").will(
+ returnValue(Collections.enumeration(initParams.keySet())));
+ setupStub(initParams, mockConfig, "getInitParameter");
+ mockConfig.stubs().method("getResourceBundle").will(returnValue(new ListResourceBundle() {
+ protected Object[][] getContents() {
+ return new String[][] { { "javax.portlet.title", "MyTitle" } };
+ }
+ }));
+ }
+
+ private void setupActionFactory(String namespace, String actionName, String result, ValueStack stack) {
+ if (mockActionFactory == null) {
+ mockActionFactory = mock(ActionProxyFactory.class);
+ }
+ mockAction = mock(Action.class);
+ mockActionProxy = mock(ActionProxy.class);
+ mockInvocation = mock(ActionInvocation.class);
+
+ mockActionFactory.expects(once()).method("createActionProxy").with(
+ new Constraint[] { eq(namespace), eq(actionName), NULL, isA(Map.class) }).will(
+ returnValue(mockActionProxy.proxy()));
+ mockActionProxy.stubs().method("getAction").will(returnValue(mockAction.proxy()));
+ mockActionProxy.expects(once()).method("execute").will(returnValue(result));
+ mockActionProxy.expects(once()).method("getInvocation").will(returnValue(mockInvocation.proxy()));
+ mockInvocation.stubs().method("getStack").will(returnValue(stack));
+
+ }
+
+ public void testParseConfigWithBang() {
+ MockPortletContext portletContext = new MockPortletContext();
+ MockPortletConfig portletConfig = new MockPortletConfig(portletContext);
+
+ portletConfig.addInitParameter("viewNamespace", "/view");
+ portletConfig.addInitParameter("defaultViewAction", "index!input");
+
+ Map<PortletMode, ActionMapping> actionMap = new HashMap<PortletMode, ActionMapping>();
+
+ dispatcher.parseModeConfig(actionMap, portletConfig, PortletMode.VIEW, "viewNamespace", "defaultViewAction");
+
+ ActionMapping mapping = actionMap.get(PortletMode.VIEW);
+ assertEquals("index", mapping.getName());
+ assertEquals("/view", mapping.getNamespace());
+ assertEquals("input", mapping.getMethod());
+ }
+
+ public void testRender_ok() throws Exception {
+ final Mock mockResponse = mock(RenderResponse.class);
+ mockResponse.stubs().method(ANYTHING);
+
+ PortletMode mode = PortletMode.VIEW;
+
+ Map<String, String[]> requestParams = new HashMap<String, String[]>();
+ requestParams.put(PortletActionConstants.ACTION_PARAM, new String[] { "/view/testAction" });
+ requestParams.put(EVENT_ACTION, new String[] { "true" });
+ requestParams.put(PortletActionConstants.MODE_PARAM, new String[] { mode.toString() });
+
+ Map<String, Object> sessionMap = new HashMap<String, Object>();
+
+ Map<String, String> initParams = new HashMap<String, String>();
+ initParams.put("viewNamespace", "/view");
+ initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE, "true");
+
+ initPortletConfig(initParams, new HashMap<String, Object>());
+ initRequest(requestParams, new HashMap<String, Object>(), sessionMap, new HashMap<String, String[]>(), PortletMode.VIEW, WindowState.NORMAL,
+ false, null);
+ setupActionFactory("/view", "testAction", "success", EasyMock.createNiceMock(ValueStack.class));
+
+ mockInvocation.expects(once()).method("getStack").will(returnValue(null));
+ // mockSession.expects(once()).method("setAttribute").with(new
+ // Constraint[]{eq(PortletActionConstants.LAST_MODE),
+ // eq(PortletMode.VIEW)});
+ dispatcher.setActionProxyFactory((ActionProxyFactory) mockActionFactory.proxy());
+ dispatcher.init((PortletConfig) mockConfig.proxy());
+ dispatcher.render((RenderRequest) mockRequest.proxy(), (RenderResponse) mockResponse.proxy());
+ }
+
+ public void testProcessAction_ok() throws Exception {
+ final Mock mockResponse = mock(ActionResponse.class);
+
+ PortletMode mode = PortletMode.VIEW;
+ Map<String, String> initParams = new HashMap<String, String>();
+ initParams.put("viewNamespace", "/view");
+
+ Map<String, String[]> requestParams = new HashMap<String, String[]>();
+ requestParams.put(PortletActionConstants.ACTION_PARAM, new String[] { "/view/testAction" });
+ requestParams.put(PortletActionConstants.MODE_PARAM, new String[] { mode.toString() });
+
+ initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE, "true");
+ initPortletConfig(initParams, new HashMap<String, Object>());
+ initRequest(requestParams, new HashMap<String, Object>(), new HashMap<String, Object>(), new HashMap<String, String[]>(), PortletMode.VIEW, WindowState.NORMAL,
+ true, null);
+ setupActionFactory("/view", "testAction", "success", EasyMock.createNiceMock(ValueStack.class));
+ // mockSession.expects(once()).method("setAttribute").with(new
+ // Constraint[]{eq(PortletActionConstants.LAST_MODE),
+ // eq(PortletMode.VIEW)});
+ dispatcher.setActionProxyFactory((ActionProxyFactory) mockActionFactory.proxy());
+ dispatcher.init((PortletConfig) mockConfig.proxy());
+ dispatcher.processAction((ActionRequest) mockRequest.proxy(), (ActionResponse) mockResponse.proxy());
+ }
+
+ /**
+ * Initialize the mock request (and as a result, the mock session)
+ *
+ * @param requestParams
+ * The request parameters
+ * @param requestAttributes
+ * The request attributes
+ * @param sessionParams
+ * The session attributes
+ * @param renderParams
+ * The render parameters. Will only be set if
+ * <code>isEvent</code> is <code>true</code>
+ * @param mode
+ * The portlet mode
+ * @param state
+ * The portlet window state
+ * @param isEvent
+ * <code>true</code> when the request is an ActionRequest.
+ * @param locale
+ * The locale. If <code>null</code>, the request will return
+ * <code>Locale.getDefault()</code>
+ */
+ private void initRequest(Map<String, String[]> requestParams, Map<String, Object> requestAttributes, Map<String, Object> sessionParams, Map<String, String[]> renderParams,
+ PortletMode mode, WindowState state, boolean isEvent, Locale locale) {
+ mockRequest = isEvent ? mock(ActionRequest.class) : mock(RenderRequest.class);
+ mockSession = mock(PortletSession.class);
+ mockSession.stubs().method(ANYTHING);
+ mockRequest.stubs().method(ANYTHING);
+ setupStub(sessionParams, mockSession, "getAttribute");
+ mockSession.stubs().method("getAttributeNames").will(
+ returnValue(Collections.enumeration(sessionParams.keySet())));
+ setupParamStub(requestParams, mockRequest, "getParameter");
+ setupStub(requestAttributes, mockRequest, "getAttribute");
+ mockRequest.stubs().method("getAttributeNames").will(
+ returnValue(Collections.enumeration(requestAttributes.keySet())));
+ mockRequest.stubs().method("getParameterMap").will(returnValue(requestParams));
+ mockRequest.stubs().method("getParameterNames").will(
+ returnValue(Collections.enumeration(requestParams.keySet())));
+ mockRequest.stubs().method("getPortletSession").will(returnValue(mockSession.proxy()));
+ if (locale != null) {
+ mockRequest.stubs().method("getLocale").will(returnValue(locale));
+ } else {
+ mockRequest.stubs().method("getLocale").will(returnValue(Locale.getDefault()));
+ }
+ mockRequest.stubs().method("getPortletMode").will(returnValue(mode));
+ mockRequest.stubs().method("getWindowState").will(returnValue(state));
+ }
- /**
- * Initialize the mock request (and as a result, the mock session)
- * @param requestParams The request parameters
- * @param requestAttributes The request attributes
- * @param sessionParams The session attributes
- * @param mode The portlet mode
- * @param state The portlet window state
- * @param isEvent <code>true</code> when the request is an ActionRequest.
- * @param locale The locale. If <code>null</code>, the request will return <code>Locale.getDefault()</code>
- */
- private void initRequest(Map<String, String[]> requestParams, Map<String, Object> requestAttributes, Map<String, Object> sessionParams, PortletMode mode, WindowState state, boolean isEvent, Locale locale) {
- mockRequest = isEvent ? mock(ActionRequest.class) : mock(RenderRequest.class);
- mockSession = mock(PortletSession.class);
- mockSession.stubs().method(ANYTHING);
- mockRequest.stubs().method(ANYTHING);
- setupStub(sessionParams, mockSession, "getAttribute");
- mockSession.stubs().method("getAttributeNames").will(returnValue(Collections.enumeration(sessionParams.keySet())));
- setupParamStub(requestParams, mockRequest, "getParameter");
- setupStub(requestAttributes, mockRequest, "getAttribute");
- mockRequest.stubs().method("getAttributeNames").will(returnValue(Collections.enumeration(requestAttributes.keySet())));
- mockRequest.stubs().method("getParameterMap").will(returnValue(requestParams));
- mockRequest.stubs().method("getParameterNames").will(returnValue(Collections.enumeration(requestParams.keySet())));
- mockRequest.stubs().method("getPortletSession").will(returnValue(mockSession.proxy()));
- if(locale != null) {
- mockRequest.stubs().method("getLocale").will(returnValue(locale));
- }
- else {
- mockRequest.stubs().method("getLocale").will(returnValue(Locale.getDefault()));
- }
- mockRequest.stubs().method("getPortletMode").will(returnValue(mode));
- mockRequest.stubs().method("getWindowState").will(returnValue(state));
- }
-
- private void setupParamStub(Map<String, String[]> requestParams, Mock mockRequest, String method) {
- Map<String, String> newMap = new HashMap<String, String>();
+ private void setupParamStub(Map<String, String[]> requestParams, Mock mockRequest, String method) {
+ Map<String, String> newMap = new HashMap<String, String>();
for ( String key : requestParams.keySet() ) {
String[] val = requestParams.get(key);
newMap.put(key, val[0]);
}
- setupStub(newMap, mockRequest, method);
+ setupStub(newMap, mockRequest, method);
- }
+ }
- /**
- * Set up stubs for the mock.
- * @param map The map containing the <code>key</code> and <code>values</code>. The key is the
- * expected parameter to <code>method</code>, and value is the value that should be returned from
- * the stub.
- * @param mock The mock to initialize.
- * @param method The name of the method to stub.
- */
- private void setupStub(Map map, Mock mock, String method) {
+ /**
+ * Set up stubs for the mock.
+ *
+ * @param map
+ * The map containing the <code>key</code> and
+ * <code>values</code>. The key is the expected parameter to
+ * <code>method</code>, and value is the value that should be
+ * returned from the stub.
+ * @param mock
+ * The mock to initialize.
+ * @param method
+ * The name of the method to stub.
+ */
+ private void setupStub(Map map, Mock mock, String method) {
for ( Object key : map.keySet() ) {
Object val = map.get(key);
mock.stubs().method(method).with(eq(key)).will(returnValue(val));
}
- }
+ }
+
+ public void testModeChangeUsingPortletWidgets() throws Exception {
+ final Mock mockResponse = mock(RenderResponse.class);
+ mockResponse.stubs().method(ANYTHING);
+ PortletMode mode = PortletMode.EDIT;
+
+ Map<String, String[]> requestParams = new HashMap<String, String[]>();
+ requestParams.put(PortletActionConstants.ACTION_PARAM, new String[] { "/view/testAction" });
+ requestParams.put(EVENT_ACTION, new String[] { "false" });
+ requestParams.put(PortletActionConstants.MODE_PARAM, new String[] { PortletMode.VIEW.toString() });
+
+ Map<String, Object> sessionMap = new HashMap<String, Object>();
+
+ Map<String, String> initParams = new HashMap<String, String>();
+ initParams.put("viewNamespace", "/view");
+ initParams.put("editNamespace", "/edit");
+
+ initPortletConfig(initParams, new HashMap<String, Object>());
+ initRequest(requestParams, new HashMap<String, Object>(), sessionMap, new HashMap<String, String[]>(), mode, WindowState.NORMAL, false, null);
+ setupActionFactory("/edit", "default", "success", EasyMock.createNiceMock(ValueStack.class));
+
+ mockInvocation.expects(once()).method("getStack").will(returnValue(null));
+ // mockSession.expects(once()).method("setAttribute").with(new
+ // Constraint[]{eq(PortletActionConstants.LAST_MODE),
+ // eq(PortletMode.VIEW)});
+ dispatcher.setActionProxyFactory((ActionProxyFactory) mockActionFactory.proxy());
+ dispatcher.init((PortletConfig) mockConfig.proxy());
+ dispatcher.render((RenderRequest) mockRequest.proxy(), (RenderResponse) mockResponse.proxy());
+ }
- public void testModeChangeUsingPortletWidgets() {
- final Mock mockResponse = mock(RenderResponse.class);
- mockResponse.stubs().method(ANYTHING);
- PortletMode mode = PortletMode.EDIT;
-
- Map<String, String[]> requestParams = new HashMap<String, String[]>();
- requestParams.put(ACTION_PARAM, new String[]{"/view/testAction"});
- requestParams.put(EVENT_ACTION, new String[]{"false"});
- requestParams.put(MODE_PARAM, new String[]{PortletMode.VIEW.toString()});
-
- Map<String, Object> sessionMap = new HashMap<String, Object>();
-
- Map<String, String> initParams = new HashMap<String, String>();
- initParams.put("viewNamespace", "/view");
- initParams.put("editNamespace", "/edit");
-
- initPortletConfig(initParams, new HashMap<String, Object>());
- initRequest(requestParams, new HashMap<String, Object>(), sessionMap, mode, WindowState.NORMAL, false, null);
- setupActionFactory("/edit", "default", "success", EasyMock.createNiceMock(ValueStack.class));
-
- mockInvocation.expects(once()).method("getStack").will(
- returnValue(null));
- //mockSession.expects(once()).method("setAttribute").with(new Constraint[]{eq(PortletActionConstants.LAST_MODE), eq(PortletMode.VIEW)});
- try {
- dispatcher
- .setActionProxyFactory((ActionProxyFactory) mockActionFactory
- .proxy());
- dispatcher.init((PortletConfig) mockConfig.proxy());
- dispatcher.render((RenderRequest) mockRequest.proxy(),
- (RenderResponse) mockResponse.proxy());
- } catch (Exception e) {
- e.printStackTrace();
- fail("Error occured");
- }
- }
-
}
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java Sun Jun 26 08:30:00 2011
@@ -18,11 +18,13 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet.interceptor;
import java.util.HashMap;
import java.util.Map;
+import javax.portlet.PortletConfig;
import javax.portlet.PortletRequest;
import junit.framework.TestCase;
@@ -36,10 +38,22 @@ import com.opensymphony.xwork2.ActionInv
public class PortletAwareInterceptorTest extends TestCase implements PortletActionConstants {
private PortletAwareInterceptor interceptor;
+ private TestAction action;
+ private PortletRequest portletRequest;
+ private PortletConfig portletConfig;
+ private Map<String, Object> contextMap;
+ private ActionInvocation invocation;
protected void setUp() throws Exception {
super.setUp();
interceptor = new PortletAwareInterceptor();
+ action = new TestAction();
+ portletRequest = EasyMock.createNiceMock(PortletRequest.class);
+ portletConfig = EasyMock.createNiceMock(PortletConfig.class);
+ contextMap = new HashMap<String, Object>();
+ invocation = EasyMock.createNiceMock(ActionInvocation.class);
+ EasyMock.expect(invocation.getAction()).andReturn(action);
+ EasyMock.expect(invocation.getInvocationContext()).andReturn(new ActionContext(contextMap));
}
protected void tearDown() throws Exception {
@@ -47,21 +61,39 @@ public class PortletAwareInterceptorTest
}
public void testPortletRequestIsSet() throws Exception {
- PortletRequest request = EasyMock.createMock(PortletRequest.class);
- Map<String, Object> ctx = new HashMap<String, Object>();
- ctx.put(REQUEST, request);
- PortletRequestAware action = EasyMock.createMock(PortletRequestAware.class);
- action.setPortletRequest(request);
-
- ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
- EasyMock.expect(invocation.getInvocationContext()).andReturn(new ActionContext(ctx));
- EasyMock.expect(invocation.getAction()).andReturn(action);
-
- EasyMock.replay(action);
+ contextMap.put(REQUEST, portletRequest);
+ EasyMock.replay(invocation);
+ interceptor.intercept(invocation);
+ assertEquals(portletRequest, action.getPortletRequest());
+ }
+
+ public void testPortletConfigIsSet() throws Exception {
+ contextMap.put(PORTLET_CONFIG, portletConfig);
EasyMock.replay(invocation);
-
interceptor.intercept(invocation);
+ assertEquals(portletConfig, action.getPortletConfig());
+ }
+
+ public static class TestAction implements PortletRequestAware, PortletConfigAware {
+
+ private PortletRequest request;
+ private PortletConfig config;
+
+ public void setPortletRequest(PortletRequest request) {
+ this.request = request;
+ }
+
+ public void setPortletConfig(PortletConfig portletConfig) {
+ this.config = portletConfig;
+ }
+
+ public PortletConfig getPortletConfig() {
+ return config;
+ }
+
+ public PortletRequest getPortletRequest() {
+ return request;
+ }
- EasyMock.verify(action);
}
}
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java Sun Jun 26 08:30:00 2011
@@ -18,6 +18,7 @@
* specific language governing permissions and limitations
* under the License.
*/
+
package org.apache.struts2.portlet.interceptor;
import java.util.HashMap;
@@ -26,8 +27,11 @@ import java.util.Map;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
+import junit.framework.TestCase;
+
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.dispatcher.DefaultActionSupport;
+import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction;
import org.easymock.EasyMock;
@@ -36,9 +40,7 @@ import com.opensymphony.xwork2.ActionInv
import com.opensymphony.xwork2.util.ValueStack;
import com.opensymphony.xwork2.util.ValueStackFactory;
-import static org.apache.struts2.portlet.PortletConstants.*;
-
-public class PortletStateInterceptorTest extends StrutsTestCase {
+public class PortletStateInterceptorTest extends StrutsTestCase implements PortletActionConstants {
private PortletStateInterceptor interceptor;
@@ -52,7 +54,7 @@ public class PortletStateInterceptorTest
ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
Map<String, Object> ctxMap = new HashMap<String, Object>();
- ctxMap.put(PHASE, ACTION_PHASE);
+ ctxMap.put(PHASE, EVENT_PHASE);
ctxMap.put(RESPONSE, actionResponse);
Map<String, Object> session = new HashMap<String, Object>();
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java (original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java Sun Jun 26 08:30:00 2011
@@ -18,16 +18,15 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.struts2.portlet.result;
-import static org.apache.struts2.portlet.PortletConstants.*;
-import static com.opensymphony.xwork2.ActionContext.*;
+package org.apache.struts2.portlet.result;
import java.util.HashMap;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
import javax.portlet.PortletContext;
import javax.portlet.PortletMode;
import javax.portlet.PortletRequestDispatcher;
@@ -36,19 +35,24 @@ import javax.portlet.RenderResponse;
import junit.textui.TestRunner;
+import org.apache.struts2.StrutsConstants;
import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.portlet.PortletActionConstants;
import org.jmock.Mock;
import org.jmock.cglib.MockObjectTestCase;
import org.jmock.core.Constraint;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.mock.MockActionProxy;
+import com.opensymphony.xwork2.mock.MockActionInvocation;
/**
* PortletResultTest. Insert description.
*
*/
-public class PortletResultTest extends MockObjectTestCase implements StrutsStatics {
+public class PortletResultTest extends MockObjectTestCase implements PortletActionConstants {
Mock mockInvocation = null;
Mock mockConfig = null;
@@ -59,13 +63,13 @@ public class PortletResultTest extends M
mockInvocation = mock(ActionInvocation.class);
mockCtx = mock(PortletContext.class);
- Map<String, String[]> paramMap = new HashMap<String, String[]>();
- Map<String, Object> sessionMap = new HashMap<String, Object>();
+ Map paramMap = new HashMap();
+ Map sessionMap = new HashMap();
- Map<String, Object> context = new HashMap<String, Object>();
- context.put(SESSION, sessionMap);
- context.put(PARAMETERS, paramMap);
- context.put(STRUTS_PORTLET_CONTEXT, mockCtx.proxy());
+ Map context = new HashMap();
+ context.put(ActionContext.SESSION, sessionMap);
+ context.put(ActionContext.PARAMETERS, paramMap);
+ context.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, mockCtx.proxy());
ActionContext.setContext(new ActionContext(context));
@@ -87,16 +91,15 @@ public class PortletResultTest extends M
Constraint[] params = new Constraint[]{same(req), same(res)};
mockRd.expects(once()).method("include").with(params);
mockCtx.expects(once()).method("getRequestDispatcher").with(eq("/WEB-INF/pages/testPage.jsp")).will(returnValue(rd));
- mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
mockResponse.expects(once()).method("setContentType").with(eq("text/html"));
mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
ActionContext ctxMap = ActionContext.getContext();
- ctxMap.put(RESPONSE, res);
- ctxMap.put(REQUEST, req);
- ctxMap.put(SERVLET_CONTEXT, ctx);
- ctxMap.put(PHASE, RENDER_PHASE);
+ ctxMap.put(PortletActionConstants.RESPONSE, res);
+ ctxMap.put(PortletActionConstants.REQUEST, req);
+ ctxMap.put(StrutsStatics.SERVLET_CONTEXT, ctx);
+ ctxMap.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
PortletResult result = new PortletResult();
try {
@@ -114,17 +117,16 @@ public class PortletResultTest extends M
Mock mockRequest = mock(ActionRequest.class);
Mock mockResponse = mock(ActionResponse.class);
- Constraint[] params = new Constraint[]{eq(ACTION_PARAM), eq("testView")};
+ Constraint[] params = new Constraint[]{eq(PortletActionConstants.ACTION_PARAM), eq("testView")};
mockResponse.expects(once()).method("setRenderParameter").with(params);
- params = new Constraint[]{eq(MODE_PARAM), eq(PortletMode.VIEW.toString())};
+ params = new Constraint[]{eq(PortletActionConstants.MODE_PARAM), eq(PortletMode.VIEW.toString())};
mockResponse.expects(once()).method("setRenderParameter").with(params);
mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
- mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
ActionContext ctx = ActionContext.getContext();
- ctx.put(REQUEST, mockRequest.proxy());
- ctx.put(RESPONSE, mockResponse.proxy());
- ctx.put(PHASE, ACTION_PHASE);
+ ctx.put(PortletActionConstants.REQUEST, mockRequest.proxy());
+ ctx.put(PortletActionConstants.RESPONSE, mockResponse.proxy());
+ ctx.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
PortletResult result = new PortletResult();
try {
@@ -140,21 +142,24 @@ public class PortletResultTest extends M
public void testDoExecute_event_locationIsJsp() {
Mock mockRequest = mock(ActionRequest.class);
Mock mockResponse = mock(ActionResponse.class);
+ Mock mockProxy = mock(ActionProxy.class);
- Constraint[] params = new Constraint[]{eq(ACTION_PARAM), eq("renderDirect")};
+ Constraint[] params = new Constraint[]{eq(PortletActionConstants.ACTION_PARAM), eq("renderDirect")};
mockResponse.expects(once()).method("setRenderParameter").with(params);
- params = new Constraint[]{eq(MODE_PARAM), eq(PortletMode.VIEW.toString())};
+ params = new Constraint[]{eq(PortletActionConstants.MODE_PARAM), eq(PortletMode.VIEW.toString())};
mockResponse.expects(once()).method("setRenderParameter").with(params);
mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
- mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-
+ mockProxy.stubs().method("getNamespace").will(returnValue(""));
+
+ mockInvocation.stubs().method("getProxy").will(returnValue(mockProxy.proxy()));
+
ActionContext ctx = ActionContext.getContext();
Map session = new HashMap();
- ctx.put(REQUEST, mockRequest.proxy());
- ctx.put(RESPONSE, mockResponse.proxy());
- ctx.put(PHASE, ACTION_PHASE);
+ ctx.put(PortletActionConstants.REQUEST, mockRequest.proxy());
+ ctx.put(PortletActionConstants.RESPONSE, mockResponse.proxy());
+ ctx.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
ctx.put(ActionContext.SESSION, session);
PortletResult result = new PortletResult();
@@ -172,22 +177,21 @@ public class PortletResultTest extends M
Mock mockRequest = mock(ActionRequest.class);
Mock mockResponse = mock(ActionResponse.class);
- Constraint[] params = new Constraint[]{eq(ACTION_PARAM), eq("testView")};
+ Constraint[] params = new Constraint[]{eq(PortletActionConstants.ACTION_PARAM), eq("testView")};
mockResponse.expects(once()).method("setRenderParameter").with(params);
params = new Constraint[]{eq("testParam1"), eq("testValue1")};
mockResponse.expects(once()).method("setRenderParameter").with(params);
params = new Constraint[]{eq("testParam2"), eq("testValue2")};
mockResponse.expects(once()).method("setRenderParameter").with(params);
- params = new Constraint[]{eq(MODE_PARAM), eq(PortletMode.VIEW.toString())};
+ params = new Constraint[]{eq(PortletActionConstants.MODE_PARAM), eq(PortletMode.VIEW.toString())};
mockResponse.expects(once()).method("setRenderParameter").with(params);
mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
- mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
ActionContext ctx = ActionContext.getContext();
- ctx.put(REQUEST, mockRequest.proxy());
- ctx.put(RESPONSE, mockResponse.proxy());
- ctx.put(PHASE, ACTION_PHASE);
+ ctx.put(PortletActionConstants.REQUEST, mockRequest.proxy());
+ ctx.put(PortletActionConstants.RESPONSE, mockResponse.proxy());
+ ctx.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
PortletResult result = new PortletResult();
try {
@@ -212,15 +216,14 @@ public class PortletResultTest extends M
Constraint[] params = new Constraint[]{same(req), same(res)};
mockRd.expects(once()).method("include").with(params);
mockCtx.expects(once()).method("getRequestDispatcher").with(eq("/WEB-INF/pages/testPage.jsp")).will(returnValue(rd));
- mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
ActionContext ctxMap = ActionContext.getContext();
- ctxMap.put(RESPONSE, res);
- ctxMap.put(REQUEST, req);
- ctxMap.put(SERVLET_CONTEXT, ctx);
- ctxMap.put(PHASE, RENDER_PHASE);
+ ctxMap.put(PortletActionConstants.RESPONSE, res);
+ ctxMap.put(PortletActionConstants.REQUEST, req);
+ ctxMap.put(StrutsStatics.SERVLET_CONTEXT, ctx);
+ ctxMap.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
mockResponse.expects(atLeastOnce()).method("setTitle").with(eq("testTitle"));
mockResponse.expects(atLeastOnce()).method("setContentType").with(eq("testContentType"));