Return-Path: Delivered-To: apmail-struts-commits-archive@locus.apache.org Received: (qmail 61488 invoked from network); 23 Aug 2007 08:54:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 23 Aug 2007 08:54:35 -0000 Received: (qmail 49534 invoked by uid 500); 23 Aug 2007 08:54:29 -0000 Delivered-To: apmail-struts-commits-archive@struts.apache.org Received: (qmail 49500 invoked by uid 500); 23 Aug 2007 08:54:29 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 49491 invoked by uid 99); 23 Aug 2007 08:54:29 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Aug 2007 01:54:29 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Aug 2007 08:54:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 0C4A91A981A; Thu, 23 Aug 2007 01:54:12 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r568894 - in /struts/struts2/branches/STRUTS_2_0_X/core/src: main/java/org/apache/struts2/portlet/interceptor/ main/java/org/apache/struts2/portlet/result/ test/java/org/apache/struts2/portlet/interceptor/ Date: Thu, 23 Aug 2007 08:54:11 -0000 To: commits@struts.apache.org From: rgielen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070823085412.0C4A91A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rgielen Date: Thu Aug 23 01:54:10 2007 New Revision: 568894 URL: http://svn.apache.org/viewvc?rev=568894&view=rev Log: WW-1989, WW-2052, WW-2053, WW-2101, WW-2105: Backporting portlet servlet wrapping, portlet redirect/redirectAction result and related issues to 2.0.x Added: struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptor.java struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/portlet/interceptor/ struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java Added: struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptor.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptor.java?rev=568894&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptor.java (added) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptor.java Thu Aug 23 01:54:10 2007 @@ -0,0 +1,84 @@ +/* + * $Id: $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import javax.portlet.PortletContext; +import javax.portlet.PortletRequest; +import javax.portlet.PortletResponse; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.StrutsStatics; +import org.apache.struts2.interceptor.PrincipalAware; +import org.apache.struts2.portlet.PortletActionConstants; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.interceptor.AbstractInterceptor; + +public class PortletAwareInterceptor extends AbstractInterceptor implements PortletActionConstants, StrutsStatics { + + private static final long serialVersionUID = 2476509721059587700L; + + private static final Log LOG = LogFactory.getLog(PortletAwareInterceptor.class); + + /** + * Sets action properties based on the interfaces an action implements. Things like application properties, + * parameters, session attributes, etc are set based on the implementing interface. + * + * @param invocation an encapsulation of the action execution state. + * @throws Exception if an error occurs when setting action properties. + */ + public String intercept(ActionInvocation invocation) throws Exception { + final Object action = invocation.getAction(); + final ActionContext context = invocation.getInvocationContext(); + + if (action instanceof PortletRequestAware) { + PortletRequest request = (PortletRequest) context.get(REQUEST); + ((PortletRequestAware) action).setPortletRequest(request); + } + + if (action instanceof PortletResponseAware) { + PortletResponse response = (PortletResponse) context.get(RESPONSE); + ((PortletResponseAware) action).setPortletResponse(response); + } + if (action instanceof PrincipalAware) { + PortletRequest request = (PortletRequest) context.get(REQUEST); + ((PrincipalAware) action).setPrincipalProxy(new PortletPrincipalProxy(request)); + } + if (action instanceof PortletContextAware) { + PortletContext portletContext = (PortletContext) context.get(STRUTS_PORTLET_CONTEXT); + ((PortletContextAware) action).setPortletContext(portletContext); + } + if (action instanceof PortletPreferencesAware) { + PortletRequest request = (PortletRequest) context.get(REQUEST); + + // Check if running in a servlet environment + if (request == null) { + LOG.warn("This portlet preferences implementation should only be used during development"); + ((PortletPreferencesAware)action).setPortletPreferences(new ServletPortletPreferences(ActionContext.getContext().getSession())); + } else { + ((PortletPreferencesAware)action).setPortletPreferences(request.getPreferences()); + } + } + return invocation.invoke(); + } +} Added: struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java?rev=568894&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java (added) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletContextAware.java Thu Aug 23 01:54:10 2007 @@ -0,0 +1,29 @@ +/* + * $Id: $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import javax.portlet.PortletContext; + +public interface PortletContextAware { + + void setPortletContext(PortletContext portletContext); + +} Added: struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java?rev=568894&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java (added) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletRequestAware.java Thu Aug 23 01:54:10 2007 @@ -0,0 +1,29 @@ +/* + * $Id: $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import javax.portlet.PortletRequest; + +public interface PortletRequestAware { + + void setPortletRequest(PortletRequest request); + +} Added: struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java?rev=568894&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java (added) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletResponseAware.java Thu Aug 23 01:54:10 2007 @@ -0,0 +1,29 @@ +/* + * $Id: $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import javax.portlet.PortletResponse; + +public interface PortletResponseAware { + + void setPortletResponse(PortletResponse response); + +} Added: struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java?rev=568894&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java (added) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptor.java Thu Aug 23 01:54:10 2007 @@ -0,0 +1,95 @@ +/* + * $Id: $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.interceptor; + +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.interceptor.AbstractInterceptor; +import com.opensymphony.xwork2.util.CompoundRoot; +import com.opensymphony.xwork2.util.TextUtils; +import com.opensymphony.xwork2.util.ValueStack; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.struts2.portlet.PortletActionConstants; +import org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction; + +import javax.portlet.ActionResponse; +import javax.portlet.RenderRequest; +import java.util.Map; + +public class PortletStateInterceptor extends AbstractInterceptor implements PortletActionConstants { + + private final static Log LOG = LogFactory.getLog(PortletStateInterceptor.class); + + private static final long serialVersionUID = 6138452063353911784L; + + @Override + public String intercept(ActionInvocation invocation) throws Exception { + Integer phase = (Integer) invocation.getInvocationContext().get(PHASE); + if (RENDER_PHASE.equals(phase)) { + restoreStack(invocation); + return invocation.invoke(); + } else if (EVENT_PHASE.equals(phase)) { + try { + return invocation.invoke(); + } finally { + saveStack(invocation); + } + } else { + return invocation.invoke(); + } + } + + @SuppressWarnings("unchecked") + private void saveStack(ActionInvocation invocation) { + Map session = invocation.getInvocationContext().getSession(); + session.put(STACK_FROM_EVENT_PHASE, invocation.getStack()); + ActionResponse actionResponse = (ActionResponse) invocation.getInvocationContext().get(RESPONSE); + actionResponse.setRenderParameter(EVENT_ACTION, "true"); + } + + @SuppressWarnings("unchecked") + private void restoreStack(ActionInvocation invocation) { + RenderRequest request = (RenderRequest) invocation.getInvocationContext().get(REQUEST); + if (TextUtils.stringSet(request.getParameter(EVENT_ACTION))) { + Map session = invocation.getInvocationContext().getSession(); + if(!isProperPrg(invocation)) { + LOG.debug("Restoring value stack from event phase"); + ValueStack oldStack = (ValueStack) invocation.getInvocationContext().getSession().get( + STACK_FROM_EVENT_PHASE); + if (oldStack != null) { + CompoundRoot oldRoot = oldStack.getRoot(); + ValueStack currentStack = invocation.getStack(); + CompoundRoot root = currentStack.getRoot(); + root.addAll(oldRoot); + LOG.debug("Restored stack"); + } + } + else { + LOG.debug("Won't restore stack from event phase since it's a proper PRG request"); + } + } + } + + private boolean isProperPrg(ActionInvocation invocation) { + return !(invocation.getAction() instanceof DirectRenderFromEventAction); + } + +} Added: struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java?rev=568894&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java (added) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java Thu Aug 23 01:54:10 2007 @@ -0,0 +1,238 @@ +/* + * $Id: $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.struts2.portlet.result; + +import java.util.Arrays; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +import org.apache.struts2.dispatcher.ServletActionRedirectResult; +import org.apache.struts2.dispatcher.mapper.ActionMapper; +import org.apache.struts2.dispatcher.mapper.ActionMapping; +import org.apache.struts2.views.util.UrlHelper; + +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.config.entities.ResultConfig; +import com.opensymphony.xwork2.inject.Inject; + +/** + * + * Portlet modification of the {@link ServletActionRedirectResult}. + * + * + + * This result uses the {@link ActionMapper} provided by the {@link ActionMapperFactory} to instruct the render phase to + * invoke the specified action and (optional) namespace. This is better than the {@link PortletResult} + * because it does not require you to encode the URL patterns processed by the {@link ActionMapper} in to your struts.xml + * configuration files. This means you can change your URL patterns at any point and your application will still work. + * It is strongly recommended that if you are redirecting to another action, you use this result rather than the + * standard redirect result. + * + * See examples below for an example of how request parameters could be passed in. + * + * + * + * This result type takes the following parameters: + * + * + * + *
    + * + *
  • actionName (default) - the name of the action that will be redirect to
  • + * + *
  • namespace - used to determine which namespace the action is in that we're redirecting to . If namespace is + * null, this defaults to the current namespace
  • + * + *
+ * + * + * + * Example: + * + *

+ * <package name="public" extends="struts-default">
+ *     <action name="login" class="...">
+ *         <!-- Redirect to another namespace -->
+ *         <result type="redirect-action">
+ *             <param name="actionName">dashboard</param>
+ *             <param name="namespace">/secure</param>
+ *         </result>
+ *     </action>
+ * </package>
+ *
+ * <package name="secure" extends="struts-default" namespace="/secure">
+ *     <-- Redirect to an action in the same namespace -->
+ *     <action name="dashboard" class="...">
+ *         <result>dashboard.jsp</result>
+ *         <result name="error" type="redirect-action">error</result>
+ *     </action>
+ *
+ *     <action name="error" class="...">
+ *         <result>error.jsp</result>
+ *     </action>
+ * </package>
+ *
+ * <package name="passingRequestParameters" extends="struts-default" namespace="/passingRequestParameters">
+ *    <-- Pass parameters (reportType, width and height) -->
+ *    <!--
+ *    The redirect-action url generated will be :
+ *    /genReport/generateReport.action?reportType=pie&width=100&height=100
+ *    -->
+ *    <action name="gatherReportInfo" class="...">
+ *       <result name="showReportResult" type="redirect-action">
+ *          <param name="actionName">generateReport</param>
+ *          <param name="namespace">/genReport</param>
+ *          <param name="reportType">pie</param>
+ *          <param name="width">100</param>
+ *          <param name="height">100</param>
+ *       </result>
+ *    </action>
+ * </package>
+ *
+ *
+ * 
+ * + * @see ActionMapper + */ +public class PortletActionRedirectResult extends PortletResult { + + private static final long serialVersionUID = -7627388936683562557L; + + /** The default parameter */ + public static final String DEFAULT_PARAM = "actionName"; + + protected String actionName; + protected String namespace; + protected String method; + + private Map requestParameters = new LinkedHashMap(); + + private ActionMapper actionMapper; + + public PortletActionRedirectResult() { + super(); + } + + public PortletActionRedirectResult(String actionName) { + this(null, actionName, null); + } + + public PortletActionRedirectResult(String actionName, String method) { + this(null, actionName, method); + } + + public PortletActionRedirectResult(String namespace, String actionName, String method) { + super(null); + this.namespace = namespace; + this.actionName = actionName; + this.method = method; + } + + protected List prohibitedResultParam = Arrays.asList(new String[] { + DEFAULT_PARAM, "namespace", "method", "encode", "parse", "location", + "prependServletContext" }); + + @Inject + public void setActionMapper(ActionMapper actionMapper) { + this.actionMapper = actionMapper; + } + + /** + * @see com.opensymphony.xwork2.Result#execute(com.opensymphony.xwork2.ActionInvocation) + */ + public void execute(ActionInvocation invocation) throws Exception { + actionName = conditionalParse(actionName, invocation); + if (namespace == null) { + namespace = invocation.getProxy().getNamespace(); + } else { + namespace = conditionalParse(namespace, invocation); + } + if (method == null) { + method = ""; + } + else { + method = conditionalParse(method, invocation); + } + + String resultCode = invocation.getResultCode(); + if (resultCode != null) { + ResultConfig resultConfig = invocation.getProxy().getConfig().getResults().get( + resultCode); + Map resultConfigParams = resultConfig.getParams(); + for (Iterator i = resultConfigParams.entrySet().iterator(); i.hasNext(); ) { + Map.Entry e = (Map.Entry) i.next(); + if (! prohibitedResultParam.contains(e.getKey())) { + requestParameters.put(e.getKey().toString(), + e.getValue() == null ? "": + conditionalParse(e.getValue().toString(), invocation)); + } + } + } + + StringBuffer tmpLocation = new StringBuffer(actionMapper.getUriFromActionMapping(new ActionMapping(actionName, namespace, method, null))); + UrlHelper.buildParametersString(requestParameters, tmpLocation, "&"); + + setLocation(tmpLocation.toString()); + + super.execute(invocation); + } + + /** + * Sets the action name + * + * @param actionName The name + */ + public void setActionName(String actionName) { + this.actionName = actionName; + } + + /** + * Sets the namespace + * + * @param namespace The namespace + */ + public void setNamespace(String namespace) { + this.namespace = namespace; + } + + /** + * Sets the method + * + * @param method The method + */ + public void setMethod(String method) { + this.method = method; + } + + /** + * Adds a request parameter to be added to the redirect url + * + * @param key The parameter name + * @param value The parameter value + */ + public PortletActionRedirectResult addParameter(String key, Object value) { + requestParameters.put(key, String.valueOf(value)); + return this; + } + +} Added: struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java URL: http://svn.apache.org/viewvc/struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java?rev=568894&view=auto ============================================================================== --- struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java (added) +++ struts/struts2/branches/STRUTS_2_0_X/core/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java Thu Aug 23 01:54:10 2007 @@ -0,0 +1,67 @@ +/* + * $Id: $ + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * 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.PortletRequest; + +import junit.framework.TestCase; + +import org.apache.struts2.portlet.PortletActionConstants; +import org.easymock.EasyMock; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; + +public class PortletAwareInterceptorTest extends TestCase implements PortletActionConstants { + + private PortletAwareInterceptor interceptor; + + protected void setUp() throws Exception { + super.setUp(); + interceptor = new PortletAwareInterceptor(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testPortletRequestIsSet() throws Exception { + PortletRequest request = EasyMock.createMock(PortletRequest.class); + Map ctx = new HashMap(); + 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); + EasyMock.replay(invocation); + + interceptor.intercept(invocation); + + EasyMock.verify(action); + } +}