WW-3620: Bring Portlet 2.0 (JSR286) plugin from sandbox to trunk

Remove unnecessary Tests

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1139078 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Johannes Geppert
2011-06-23 21:19:00 +00:00
parent a534481cf7
commit 1e1705bb41
3 changed files with 0 additions and 391 deletions
@@ -1,237 +0,0 @@
/*
* $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.components;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.HashMap;
import java.util.Map;
import javax.portlet.PortletMode;
import javax.portlet.PortletURL;
import org.apache.struts2.StrutsStatics;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.apache.struts2.portlet.servlet.PortletServletRequest;
import org.apache.struts2.portlet.servlet.PortletServletResponse;
import org.easymock.EasyMock;
import org.springframework.mock.web.portlet.MockPortalContext;
import org.springframework.mock.web.portlet.MockPortletContext;
import org.springframework.mock.web.portlet.MockPortletURL;
import org.springframework.mock.web.portlet.MockRenderRequest;
import org.springframework.mock.web.portlet.MockRenderResponse;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.mock.MockActionInvocation;
import com.opensymphony.xwork2.mock.MockActionProxy;
import com.opensymphony.xwork2.util.ValueStack;
public class PortletUrlRendererTest extends StrutsTestCase {
PortletUrlRenderer renderer;
MockPortletURL renderUrl;
MockPortletURL actionUrl;
MockRenderRequest request;
MockRenderResponse response;
MockPortletContext context;
ActionContext ctx;
ValueStack stack;
public void setUp() throws Exception {
super.setUp();
renderer = new PortletUrlRenderer();
context = new MockPortletContext();
renderUrl = new MockPortletURL(
new MockPortalContext(), "render");
actionUrl = new MockPortletURL(
new MockPortalContext(), "action");
request = new MockRenderRequest();
response = new MockRenderResponse() {
@Override
public PortletURL createActionURL() {
return actionUrl;
}
@Override
public PortletURL createRenderURL() {
return renderUrl;
}
};
ctx = ActionContext.getContext();
ctx.put(PortletActionConstants.PHASE,
PortletActionConstants.RENDER_PHASE);
ctx.put(PortletActionConstants.REQUEST, request);
ctx.put(PortletActionConstants.RESPONSE, response);
ctx.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, context);
Map<PortletMode, String> modeMap = new HashMap<PortletMode, String>();
modeMap.put(PortletMode.VIEW, "/view");
ctx.put(PortletActionConstants.MODE_NAMESPACE_MAP, modeMap);
stack = ctx.getValueStack();
}
/**
* Ensure that the namespace of the current executing action is used when no
* namespace is specified. (WW-1875)
*/
public void testShouldIncludeCurrentNamespaceIfNoNamespaceSpecifiedForRenderUrl()
throws Exception {
URL url = new URL(stack, new PortletServletRequest(request, null),
new PortletServletResponse(response));
MockActionInvocation ai = new MockActionInvocation();
MockActionProxy ap = new MockActionProxy();
ap.setActionName("testAction");
ap.setNamespace("/current_namespace");
ai.setProxy(ap);
ai.setStack(stack);
ai.setAction(new Object());
ctx.setActionInvocation(ai);
StringWriter renderOutput = new StringWriter();
renderer.renderUrl(renderOutput, url.getUrlProvider());
String action = renderUrl
.getParameter(PortletActionConstants.ACTION_PARAM);
assertEquals("/view/current_namespace/testAction", action);
}
/**
* Ensure that the namespace of the current executing action is used when no
* namespace is specified. (WW-1875)
*/
public void testShouldIncludeCurrentNamespaceIfNoNamespaceSpecifiedForRenderFormUrl()
throws Exception {
Form form = new Form(stack, new PortletServletRequest(request, null),
new PortletServletResponse(response));
MockActionInvocation ai = new MockActionInvocation();
MockActionProxy ap = new MockActionProxy();
ap.setActionName("testAction");
ap.setNamespace("/current_namespace");
ai.setProxy(ap);
ai.setStack(stack);
ai.setAction(new Object());
ctx.setActionInvocation(ai);
renderer.renderFormUrl(form);
String action = actionUrl
.getParameter(PortletActionConstants.ACTION_PARAM);
assertEquals("/view/current_namespace/testAction", action);
}
public void testShouldEvaluateActionAsOGNLExpression() throws Exception {
TestObject obj = new TestObject();
obj.someProperty = "EvaluatedProperty";
stack.push(obj);
MockActionInvocation ai = new MockActionInvocation();
MockActionProxy ap = new MockActionProxy();
ap.setActionName("testAction");
ap.setNamespace("");
ai.setProxy(ap);
ai.setStack(stack);
ctx.setActionInvocation(ai);
URL url = new URL(stack, new PortletServletRequest(request, null),
new PortletServletResponse(response));
url.setAction("%{someProperty}");
StringWriter renderOutput = new StringWriter();
renderer.renderUrl(renderOutput, url.getUrlProvider());
String action = renderUrl
.getParameter(PortletActionConstants.ACTION_PARAM);
assertEquals("/view/EvaluatedProperty", action);
}
public void testShouldEvaluateAnchorAsOGNLExpression() throws Exception {
TestObject obj = new TestObject();
obj.someProperty = "EvaluatedProperty";
stack.push(obj);
MockActionInvocation ai = new MockActionInvocation();
MockActionProxy ap = new MockActionProxy();
ap.setActionName("testAction");
ap.setNamespace("");
ai.setProxy(ap);
ai.setStack(stack);
ctx.setActionInvocation(ai);
URL url = new URL(stack, new PortletServletRequest(request, null),
new PortletServletResponse(response));
url.setAnchor("%{someProperty}");
StringWriter renderOutput = new StringWriter();
renderer.renderUrl(renderOutput, url.getUrlProvider());
assertTrue(renderOutput.toString().indexOf("#EvaluatedProperty") != -1);
}
public void testShouldPassThroughRenderUrlToServletUrlRendererIfNotPortletRequest() throws Exception {
UrlRenderer mockRenderer = EasyMock.createMock(UrlRenderer.class);
ActionContext.getContext().put(StrutsStatics.STRUTS_PORTLET_CONTEXT, null);
renderer.setServletRenderer(mockRenderer);
URL url = new URL(stack, new PortletServletRequest(request, null), new PortletServletResponse(response));
StringWriter renderOutput = new StringWriter();
mockRenderer.renderUrl(renderOutput, url.getUrlProvider());
EasyMock.replay(mockRenderer);
renderer.renderUrl(renderOutput, url.getUrlProvider());
EasyMock.verify(mockRenderer);
}
public void testShouldPassThroughRenderFormUrlToServletUrlRendererIfNotPortletRequest() throws Exception {
UrlRenderer mockRenderer = EasyMock.createMock(UrlRenderer.class);
ActionContext.getContext().put(StrutsStatics.STRUTS_PORTLET_CONTEXT, null);
renderer.setServletRenderer(mockRenderer);
Form form = new Form(stack, new PortletServletRequest(request, null), new PortletServletResponse(response));
mockRenderer.renderFormUrl(form);
EasyMock.replay(mockRenderer);
renderer.renderFormUrl(form);
EasyMock.verify(mockRenderer);
}
public void testShouldPassThroughRenderUrlToServletUrlRendererWhenPortletUrlTypeIsNone() throws Exception {
UrlRenderer mockRenderer = EasyMock.createMock(UrlRenderer.class);
renderer.setServletRenderer(mockRenderer);
URL url = new URL(stack, new PortletServletRequest(request, null), new PortletServletResponse(response));
url.setPortletUrlType("none");
StringWriter renderOutput = new StringWriter();
mockRenderer.renderUrl(renderOutput, url.getUrlProvider());
EasyMock.replay(mockRenderer);
renderer.renderUrl(renderOutput, url.getUrlProvider());
EasyMock.verify(mockRenderer);
}
private final static class TestObject {
public String someProperty;
}
}
@@ -1,49 +0,0 @@
package org.apache.struts2.portlet.servlet;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.StrutsTestCase;
import org.apache.struts2.dispatcher.mapper.ActionMapping;
import org.apache.struts2.portlet.PortletActionConstants;
import org.apache.struts2.portlet.context.PortletActionContext;
import org.springframework.mock.web.portlet.MockPortletContext;
import org.springframework.mock.web.portlet.MockPortletRequest;
import com.opensymphony.xwork2.ActionContext;
public class PortletServletRequestTest extends StrutsTestCase {
private MockPortletRequest portletRequest;
private MockPortletContext portletContext;
private PortletServletRequest request;
protected void setUp() throws Exception {
super.setUp();
portletRequest = new MockPortletRequest();
portletContext = new MockPortletContext();
request = new PortletServletRequest(portletRequest, portletContext);
}
public void testGetServletPathShouldHandleDefaultActionExtension() throws Exception {
portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
request.setExtension("action");
assertEquals("actionName.action", request.getServletPath());
}
public void testGetServletPathShouldHandleCustomActionExtension() throws Exception {
portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
request.setExtension("custom");
assertEquals("actionName.custom", request.getServletPath());
}
public void testGetServletPathShouldHandleNoExtension() throws Exception {
portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
request.setExtension("");
assertEquals("actionName", request.getServletPath());
}
public void testGetServletPathShouldHandleMultipleExtensionsByUsingTheFirst() throws Exception {
portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
request.setExtension("action,,");
assertEquals("actionName.action", request.getServletPath());
}
}
@@ -1,105 +0,0 @@
/*
* $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.views.freemarker;
import java.util.HashMap;
import java.util.Map;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletContext;
import javax.portlet.PortletMode;
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;
public class PortletFreemarkerResultTest extends MockObjectTestCase implements PortletActionConstants {
Mock mockInvocation = null;
Mock mockConfig = null;
Mock mockCtx = null;
public void setUp() throws Exception {
super.setUp();
mockInvocation = mock(ActionInvocation.class);
mockCtx = mock(PortletContext.class);
Map paramMap = new HashMap();
Map sessionMap = new HashMap();
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));
mockInvocation.stubs().method("getInvocationContext").will(returnValue(ActionContext.getContext()));
}
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(PortletActionConstants.ACTION_PARAM), eq("freemarkerDirect")};
mockResponse.expects(once()).method("setRenderParameter").with(params);
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));
mockProxy.stubs().method("getNamespace").will(returnValue(""));
mockInvocation.stubs().method("getProxy").will(returnValue(mockProxy.proxy()));
ActionContext ctx = ActionContext.getContext();
Map session = new HashMap();
ctx.put(PortletActionConstants.REQUEST, mockRequest.proxy());
ctx.put(PortletActionConstants.RESPONSE, mockResponse.proxy());
ctx.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
ctx.put(ActionContext.SESSION, session);
PortletFreemarkerResult result = new PortletFreemarkerResult();
try {
result.doExecute("/WEB-INF/pages/testJsp.ftl", (ActionInvocation)mockInvocation.proxy());
}
catch(Exception e) {
e.printStackTrace();
fail("Error occured!");
}
assertEquals("/WEB-INF/pages/testJsp.ftl", session.get(RENDER_DIRECT_LOCATION));
}
public void tearDown() throws Exception {
super.tearDown();
ActionContext.setContext(null);
}
}