mirror of
https://github.com/apache/struts.git
synced 2026-08-11 09:36:57 +00:00
WW-3769 adds missing line of code to generate namespace without explicit specifying it
git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1297994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -75,6 +75,7 @@ public class PortletUrlRenderer implements UrlRenderer {
|
||||
}
|
||||
|
||||
String result;
|
||||
urlComponent.setNamespace(urlComponent.determineNamespace(urlComponent.getNamespace(), urlComponent.getStack(), urlComponent.getHttpServletRequest()));
|
||||
if (onlyActionSpecified(urlComponent)) {
|
||||
result = portletUrlHelper.buildUrl(urlComponent.getAction(), urlComponent.getNamespace(), urlComponent.getMethod(),
|
||||
urlComponent.getParameters(), urlComponent.getPortletUrlType(), urlComponent.getPortletMode(), urlComponent.getWindowState());
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.apache.struts2.components;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
|
||||
public class PortletAction {
|
||||
|
||||
public String execute() {
|
||||
return Action.SUCCESS;
|
||||
}
|
||||
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
package org.apache.struts2.components;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.portlet.PortletConstants;
|
||||
import org.springframework.mock.web.portlet.MockMimeResponse;
|
||||
import org.springframework.mock.web.portlet.MockPortletContext;
|
||||
import org.springframework.mock.web.portlet.MockPortletRequest;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import java.io.StringWriter;
|
||||
import java.io.Writer;
|
||||
import java.util.Collections;
|
||||
|
||||
public class PortletUrlRendererTest extends StrutsTestCase {
|
||||
|
||||
private ValueStack stack;
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ActionProxy actionProxy = getActionProxy("/portlettest/test"); // creates new empty ActionContext
|
||||
ActionContext.getContext().put(ActionContext.ACTION_INVOCATION, actionProxy.getInvocation());
|
||||
|
||||
PortletContext portletCtx = new MockPortletContext();
|
||||
ActionContext.getContext().put(StrutsStatics.STRUTS_PORTLET_CONTEXT, portletCtx);
|
||||
ActionContext.getContext().put(PortletConstants.REQUEST, new MockPortletRequest(portletCtx));
|
||||
ActionContext.getContext().put(PortletConstants.RESPONSE, new MockMimeResponse());
|
||||
ActionContext.getContext().put(PortletConstants.MODE_NAMESPACE_MAP, Collections.emptyMap());
|
||||
|
||||
stack = actionProxy.getInvocation().getStack();
|
||||
}
|
||||
|
||||
public void testRenderUrlWithNamespace() throws Exception {
|
||||
// given
|
||||
PortletUrlRenderer renderer = new PortletUrlRenderer();
|
||||
UrlProvider component = new URL(stack, request, response).getUrlProvider();
|
||||
Writer writer = new StringWriter();
|
||||
|
||||
// when
|
||||
renderer.renderUrl(writer, component);
|
||||
|
||||
// then
|
||||
assertTrue("/portlettest".equals(component.getNamespace()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,35 +20,38 @@
|
||||
*/
|
||||
package org.apache.struts2.views.jsp;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.portlet.*;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
import org.apache.struts2.portlet.PortletActionConstants;
|
||||
import org.apache.struts2.portlet.util.PortletUrlHelper;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import static org.apache.struts2.StrutsStatics.*;
|
||||
import org.jmock.Mock;
|
||||
import org.jmock.cglib.MockObjectTestCase;
|
||||
import org.jmock.core.Constraint;
|
||||
|
||||
import com.mockobjects.servlet.MockJspWriter;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import static com.opensymphony.xwork2.ActionContext.SESSION;
|
||||
import static com.opensymphony.xwork2.ActionContext.PARAMETERS;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import com.opensymphony.xwork2.util.ValueStackFactory;
|
||||
import junit.textui.TestRunner;
|
||||
import org.apache.struts2.dispatcher.Dispatcher;
|
||||
import org.apache.struts2.portlet.PortletActionConstants;
|
||||
import org.apache.struts2.portlet.util.PortletUrlHelper;
|
||||
import org.jmock.Mock;
|
||||
import org.jmock.cglib.MockObjectTestCase;
|
||||
import org.jmock.core.Constraint;
|
||||
|
||||
import javax.portlet.PortletContext;
|
||||
import javax.portlet.PortletMode;
|
||||
import javax.portlet.PortletRequest;
|
||||
import javax.portlet.PortletResponse;
|
||||
import javax.portlet.PortletURL;
|
||||
import javax.portlet.RenderRequest;
|
||||
import javax.portlet.RenderResponse;
|
||||
import javax.portlet.WindowState;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.servlet.jsp.PageContext;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.apache.struts2.StrutsStatics.STRUTS_PORTLET_CONTEXT;
|
||||
|
||||
/**
|
||||
*/
|
||||
@@ -117,6 +120,11 @@ public class PortletUrlTagTest extends MockObjectTestCase {
|
||||
mockHttpReq.stubs().method("getAttribute").with(
|
||||
eq("javax.portlet.request")).will(
|
||||
returnValue((PortletRequest) mockPortletReq.proxy()));
|
||||
mockHttpReq.stubs().method("getAttribute").with(
|
||||
eq("javax.servlet.include.servlet_path")).will(
|
||||
returnValue("/servletPath"));
|
||||
mockHttpReq.stubs().method("getParameterMap").will(
|
||||
returnValue(Collections.emptyMap()));
|
||||
|
||||
mockPortletReq.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
|
||||
mockPortletReq.stubs().method("getWindowState").will(returnValue(WindowState.NORMAL));
|
||||
@@ -332,6 +340,7 @@ public class PortletUrlTagTest extends MockObjectTestCase {
|
||||
|
||||
Mock mockActionProxy = mock(ActionProxy.class);
|
||||
mockActionProxy.stubs().method("getActionName").will(returnValue("currentExecutingAction"));
|
||||
mockActionProxy.stubs().method("getNamespace").will(returnValue(""));
|
||||
final ActionProxy proxy = (ActionProxy)mockActionProxy.proxy();
|
||||
|
||||
Mock mockActionInvocation = mock(ActionInvocation.class);
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE struts PUBLIC
|
||||
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
|
||||
"http://struts.apache.org/dtds/struts-2.3.dtd">
|
||||
|
||||
<struts>
|
||||
|
||||
<package name="test-portlet-default" namespace="/portlettest" extends="struts-portlet-default">
|
||||
|
||||
<action name="test" class="org.apache.struts2.components.PortletAction">
|
||||
<result type="redirectAction">redirectAction</result>
|
||||
</action>
|
||||
|
||||
</package>
|
||||
|
||||
</struts>
|
||||
Reference in New Issue
Block a user