Repository: struts Updated Branches: refs/heads/master 8de090fda -> 6bc99ab93
http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java b/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java new file mode 100644 index 0000000..d9d878d --- /dev/null +++ b/core/src/test/java/org/apache/struts2/result/ServletDispatcherResultTest.java @@ -0,0 +1,110 @@ +/* + * $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.result; + +import javax.servlet.RequestDispatcher; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import ognl.Ognl; + +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.StrutsInternalTestCase; +import org.apache.struts2.StrutsStatics; + +import com.mockobjects.dynamic.C; +import com.mockobjects.dynamic.Mock; +import com.opensymphony.xwork2.ActionContext; +import org.apache.struts2.result.ServletDispatcherResult; + + +/** + * + */ +public class ServletDispatcherResultTest extends StrutsInternalTestCase implements StrutsStatics { + + public void testInclude() { + ServletDispatcherResult view = new ServletDispatcherResult(); + view.setLocation("foo.jsp"); + + Mock dispatcherMock = new Mock(RequestDispatcher.class); + dispatcherMock.expect("include", C.ANY_ARGS); + + Mock requestMock = new Mock(HttpServletRequest.class); + requestMock.expectAndReturn("getAttribute", "struts.actiontag.invocation", null); + requestMock.expectAndReturn("getRequestDispatcher", C.args(C.eq("foo.jsp")), dispatcherMock.proxy()); + + Mock responseMock = new Mock(HttpServletResponse.class); + responseMock.expectAndReturn("isCommitted", Boolean.TRUE); + + ActionContext ac = new ActionContext(Ognl.createDefaultContext(null)); + ActionContext.setContext(ac); + ServletActionContext.setRequest((HttpServletRequest) requestMock.proxy()); + ServletActionContext.setResponse((HttpServletResponse) responseMock.proxy()); + + try { + view.execute(null); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + dispatcherMock.verify(); + requestMock.verify(); + dispatcherMock.verify(); + } + + public void testSimple() { + ServletDispatcherResult view = new ServletDispatcherResult(); + view.setLocation("foo.jsp"); + + Mock dispatcherMock = new Mock(RequestDispatcher.class); + dispatcherMock.expect("forward", C.ANY_ARGS); + + Mock requestMock = new Mock(HttpServletRequest.class); + requestMock.expectAndReturn("getAttribute", "struts.actiontag.invocation", null); + requestMock.expectAndReturn("getAttribute", "javax.servlet.include.servlet_path", null); + requestMock.expectAndReturn("getRequestDispatcher", C.args(C.eq("foo.jsp")), dispatcherMock.proxy()); + requestMock.expect("setAttribute", C.ANY_ARGS); // this is a bad mock, but it works + requestMock.expect("setAttribute", C.ANY_ARGS); // this is a bad mock, but it works + requestMock.matchAndReturn("getRequestURI", "foo.jsp"); + + Mock responseMock = new Mock(HttpServletResponse.class); + responseMock.expectAndReturn("isCommitted", Boolean.FALSE); + + ActionContext ac = new ActionContext(Ognl.createDefaultContext(null)); + ActionContext.setContext(ac); + ServletActionContext.setRequest((HttpServletRequest) requestMock.proxy()); + ServletActionContext.setResponse((HttpServletResponse) responseMock.proxy()); + + try { + view.execute(null); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + + dispatcherMock.verify(); + requestMock.verify(); + dispatcherMock.verify(); + } +} http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/core/src/test/java/org/apache/struts2/result/ServletRedirectResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/result/ServletRedirectResultTest.java b/core/src/test/java/org/apache/struts2/result/ServletRedirectResultTest.java new file mode 100644 index 0000000..cdf4104 --- /dev/null +++ b/core/src/test/java/org/apache/struts2/result/ServletRedirectResultTest.java @@ -0,0 +1,361 @@ +/* + * $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.result; + +import static javax.servlet.http.HttpServletResponse.SC_SEE_OTHER; +import static org.easymock.EasyMock.createControl; +import static org.easymock.EasyMock.createNiceMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; + +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import ognl.Ognl; + +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.StrutsInternalTestCase; +import org.apache.struts2.StrutsStatics; +import org.apache.struts2.dispatcher.mapper.ActionMapper; +import org.apache.struts2.result.ServletRedirectResult; +import org.apache.struts2.views.util.DefaultUrlHelper; +import org.easymock.IMocksControl; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpServletResponse; + +import com.mockobjects.dynamic.C; +import com.mockobjects.dynamic.Mock; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ActionProxy; +import com.opensymphony.xwork2.config.entities.ActionConfig; +import com.opensymphony.xwork2.config.entities.PackageConfig; +import com.opensymphony.xwork2.config.entities.ResultConfig; +import com.opensymphony.xwork2.mock.MockActionInvocation; +import com.opensymphony.xwork2.util.ValueStack; + + +/** + */ +public class ServletRedirectResultTest extends StrutsInternalTestCase implements StrutsStatics { + + protected ServletRedirectResult view; + private Mock requestMock; + private Mock responseMock; + protected ActionInvocation ai; + + + public void testAbsoluteRedirect() { + view.setLocation("/bar/foo.jsp"); + responseMock.expectAndReturn("encodeRedirectURL", "/context/bar/foo.jsp", "/context/bar/foo.jsp"); + responseMock.expect("sendRedirect", C.args(C.eq("/context/bar/foo.jsp"))); + + try { + view.execute(ai); + requestMock.verify(); + responseMock.verify(); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + public void testFullUrlRedirect() { + view.setLocation("http://localhost/bar/foo.jsp"); + responseMock.expectAndReturn("encodeRedirectURL", C.args(C.eq("http://localhost/bar/foo.jsp")), "http://localhost/bar/foo.jsp"); + responseMock.expect("sendRedirect", C.args(C.eq("http://localhost/bar/foo.jsp"))); + + try { + view.execute(ai); + requestMock.verify(); + responseMock.verify(); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + public void testFullUrlRedirectWithSpaces() { + view.setLocation("http://localhost/bar/foo some.pdf"); + responseMock.expectAndReturn("encodeRedirectURL", C.args(C.eq("http://localhost/bar/foo some.pdf")), "http://localhost/bar/foo some.pdf"); + responseMock.expect("sendRedirect", C.args(C.eq("http://localhost/bar/foo some.pdf"))); + + try { + view.execute(ai); + requestMock.verify(); + responseMock.verify(); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + public void testFullUrlRedirectWithParams() { + view.setLocation("http://localhost/bar/foo.action?param=1¶m 2=3"); + responseMock.expectAndReturn("encodeRedirectURL", C.args(C.eq("http://localhost/bar/foo.action?param=1¶m 2=3")), "http://localhost/bar/foo.action?param=1¶m 2=3"); + responseMock.expect("sendRedirect", C.args(C.eq("http://localhost/bar/foo.action?param=1¶m 2=3"))); + + try { + view.execute(ai); + requestMock.verify(); + responseMock.verify(); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + public void testAbsoluteRedirect303() { + view.setLocation("/bar/foo.jsp"); + view.setStatusCode(303); + responseMock.expectAndReturn("encodeRedirectURL", "/context/bar/foo.jsp", "/context/bar/foo.jsp"); + responseMock.expect("setStatus", C.args(C.eq(SC_SEE_OTHER))); + responseMock.expect("setHeader", C.args(C.eq("Location"), C.eq("/context/bar/foo.jsp"))); + StringWriter writer = new StringWriter(); + responseMock.matchAndReturn("getWriter", new PrintWriter(writer)); + + try { + view.execute(ai); + requestMock.verify(); + responseMock.verify(); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + assertEquals("/context/bar/foo.jsp", writer.toString()); + } + + public void testAbsoluteRedirectAnchor() { + view.setLocation("/bar/foo.jsp"); + view.setAnchor("fragment"); + responseMock.expectAndReturn("encodeRedirectURL", "/context/bar/foo.jsp#fragment", "/context/bar/foo.jsp#fragment"); + responseMock.expect("sendRedirect", C.args(C.eq("/context/bar/foo.jsp#fragment"))); + + try { + view.execute(ai); + requestMock.verify(); + responseMock.verify(); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + public void testPrependServletContextFalse() { + view.setLocation("/bar/foo.jsp"); + view.setPrependServletContext(false); + responseMock.expectAndReturn("encodeRedirectURL", "/bar/foo.jsp", "/bar/foo.jsp"); + responseMock.expect("sendRedirect", C.args(C.eq("/bar/foo.jsp"))); + + try { + view.execute(ai); + requestMock.verify(); + responseMock.verify(); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + public void testRelativeRedirect() throws Exception { + view.setLocation("foo.jsp"); + requestMock.expectAndReturn("getParameterMap", new HashMap()); + requestMock.expectAndReturn("getServletPath", "/namespace/some.action"); + requestMock.expectAndReturn("getRequestURI", "/namespace/some.action"); + requestMock.expectAndReturn("getAttribute", C.ANY_ARGS, null); + responseMock.expectAndReturn("encodeRedirectURL", "/context/namespace/foo.jsp", "/context/namespace/foo.jsp"); + responseMock.expect("sendRedirect", C.args(C.eq("/context/namespace/foo.jsp"))); + + view.execute(ai); + + requestMock.verify(); + responseMock.verify(); + } + + public void testMultipleParametersRedirect() throws Exception { + view.setLocation("foo.jsp?foo=bar&baz=jim"); + requestMock.expectAndReturn("getParameterMap", new HashMap()); + requestMock.expectAndReturn("getServletPath", "/namespace/some.action"); + requestMock.expectAndReturn("getRequestURI", "/namespace/some.action"); + requestMock.expectAndReturn("getAttribute", C.ANY_ARGS, null); + responseMock.expectAndReturn("encodeRedirectURL", "/context/namespace/foo.jsp?foo=bar&baz=jim", "/context/namespace/foo.jsp?foo=bar&baz=jim"); + responseMock.expect("sendRedirect", C.args(C.eq("/context/namespace/foo.jsp?foo=bar&baz=jim"))); + + view.execute(ai); + + requestMock.verify(); + responseMock.verify(); + } + + public void testIncludeParameterInResult() throws Exception { + + ResultConfig resultConfig = new ResultConfig.Builder("", "") + .addParam("namespace", "someNamespace") + .addParam("encode", "true") + .addParam("parse", "true") + .addParam("location", "someLocation") + .addParam("prependServletContext", "true") + .addParam("method", "someMethod") + .addParam("statusCode", "333") + .addParam("param1", "value 1") + .addParam("param2", "value 2") + .addParam("param3", "value 3") + .build(); + + ActionContext context = ActionContext.getContext(); + MockHttpServletRequest req = new MockHttpServletRequest(); + MockHttpServletResponse res = new MockHttpServletResponse(); + context.put(ServletActionContext.HTTP_REQUEST, req); + context.put(ServletActionContext.HTTP_RESPONSE, res); + + + Map<String, ResultConfig> results= new HashMap<String, ResultConfig>(); + results.put("myResult", resultConfig); + + ActionConfig actionConfig = new ActionConfig.Builder("", "", "") + .addResultConfigs(results).build(); + + ServletRedirectResult result = new ServletRedirectResult(); + result.setLocation("/myNamespace/myAction.action"); + result.setParse(false); + result.setEncode(false); + result.setPrependServletContext(false); + result.setAnchor("fragment"); + result.setUrlHelper(new DefaultUrlHelper()); + + IMocksControl control = createControl(); + ActionProxy mockActionProxy = control.createMock(ActionProxy.class); + ActionInvocation mockInvocation = control.createMock(ActionInvocation.class); + expect(mockInvocation.getProxy()).andReturn(mockActionProxy); + expect(mockInvocation.getResultCode()).andReturn("myResult"); + expect(mockActionProxy.getConfig()).andReturn(actionConfig); + expect(mockInvocation.getInvocationContext()).andReturn(context); + + control.replay(); + result.setActionMapper(container.getInstance(ActionMapper.class)); + result.execute(mockInvocation); + assertEquals("/myNamespace/myAction.action?param1=value+1¶m2=value+2¶m3=value+3#fragment", res.getRedirectedUrl()); + control.verify(); + } + + public void testIncludeCollectionParameterInResult() throws Exception { + List<String> paramValues = new ArrayList<String>(); + paramValues.add("value 1"); + paramValues.add(""); + paramValues.add("value 2"); + paramValues.add(null); + + ResultConfig resultConfig = new ResultConfig.Builder("", "") + .addParam("namespace", "someNamespace") + .addParam("param", "${list}") + .build(); + + ActionContext context = ActionContext.getContext(); + MockHttpServletRequest req = new MockHttpServletRequest(); + MockHttpServletResponse res = new MockHttpServletResponse(); + context.put(ServletActionContext.HTTP_REQUEST, req); + context.put(ServletActionContext.HTTP_RESPONSE, res); + + Map<String, ResultConfig> results= new HashMap<String, ResultConfig>(); + results.put("myResult", resultConfig); + + ActionConfig actionConfig = new ActionConfig.Builder("", "", "") + .addResultConfigs(results).build(); + + ServletRedirectResult result = new ServletRedirectResult(); + result.setLocation("/myNamespace/myAction.action"); + result.setParse(true); + result.setEncode(false); + result.setPrependServletContext(false); + result.setUrlHelper(new DefaultUrlHelper()); + result.setSuppressEmptyParameters(true); + + IMocksControl control = createControl(); + ActionProxy mockActionProxy = control.createMock(ActionProxy.class); + ActionInvocation mockInvocation = control.createMock(ActionInvocation.class); + + ValueStack mockValueStack = control.createMock(ValueStack.class); + Map<String, Object> mockContext = new HashMap<String, Object>(); + mockContext.put(ActionContext.CONTAINER, container); + + expect(mockInvocation.getStack()).andReturn(mockValueStack); + expect(mockValueStack.getContext()).andReturn(mockContext); + + expect(mockInvocation.getStack()).andReturn(mockValueStack); + + expect(mockValueStack.findValue("list")).andReturn(paramValues); // no asType !!! + + expect(mockInvocation.getProxy()).andReturn(mockActionProxy); + expect(mockInvocation.getResultCode()).andReturn("myResult"); + expect(mockActionProxy.getConfig()).andReturn(actionConfig); + expect(mockInvocation.getInvocationContext()).andReturn(context); + + expect(mockValueStack.getContext()).andReturn(mockContext); + + control.replay(); + result.setActionMapper(container.getInstance(ActionMapper.class)); + result.execute(mockInvocation); + assertEquals("/myNamespace/myAction.action?param=value+1¶m=value+2", res.getRedirectedUrl()); + control.verify(); + } + + protected void setUp() throws Exception { + super.setUp(); + configurationManager.getConfiguration(). + addPackageConfig("foo", new PackageConfig.Builder("foo").namespace("/namespace").build()); + + view = new ServletRedirectResult(); + container.inject(view); + + responseMock = new Mock(HttpServletResponse.class); + + requestMock = new Mock(HttpServletRequest.class); + requestMock.matchAndReturn("getContextPath", "/context"); + + ResultConfig resultConfig = new ResultConfig.Builder("", "").build(); + + Map<String, ResultConfig> results= new HashMap<String, ResultConfig>(); + results.put("myResult", resultConfig); + + ActionConfig actionConfig = new ActionConfig.Builder("", "", "") + .addResultConfigs(results).build(); + + ActionContext ac = new ActionContext(Ognl.createDefaultContext(null)); + ac.put(ServletActionContext.HTTP_REQUEST, requestMock.proxy()); + ac.put(ServletActionContext.HTTP_RESPONSE, responseMock.proxy()); + MockActionInvocation ai = new MockActionInvocation(); + ai.setInvocationContext(ac); + ai.setResultCode("myResult"); + ActionProxy mockActionProxy = createNiceMock(ActionProxy.class); + ai.setProxy(mockActionProxy); + expect(mockActionProxy.getConfig()).andReturn(actionConfig).anyTimes(); + replay(mockActionProxy); + this.ai = ai; + ai.setStack(ActionContext.getContext().getValueStack()); + } +} http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/core/src/test/java/org/apache/struts2/result/StreamResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/result/StreamResultTest.java b/core/src/test/java/org/apache/struts2/result/StreamResultTest.java new file mode 100644 index 0000000..fbb2525 --- /dev/null +++ b/core/src/test/java/org/apache/struts2/result/StreamResultTest.java @@ -0,0 +1,277 @@ +/* + * $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.result; + +import com.opensymphony.xwork2.Action; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.mock.MockActionInvocation; +import com.opensymphony.xwork2.util.ClassLoaderUtil; +import com.opensymphony.xwork2.util.ValueStack; +import org.apache.struts2.ServletActionContext; +import org.apache.struts2.StrutsInternalTestCase; +import org.springframework.mock.web.MockHttpServletResponse; + +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStream; +import java.net.URI; +import java.net.URL; + +/** + * Unit test for {@link StreamResult}. + * + */ +public class StreamResultTest extends StrutsInternalTestCase { + + private StreamResult result; + private MockHttpServletResponse response; + + private MockActionInvocation mai; + private ValueStack stack; + private int contentLength = 0; + + public void testStreamResultNoInputName() throws Exception { + result.setParse(false); + result.setInputName(null); + + try { + result.doExecute("helloworld", mai); + fail("Should have thrown an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } + + public void testStreamResultParseNoInputName() throws Exception { + result.setParse(true); + result.setInputName("${top}"); + + try { + result.doExecute("helloworld", mai); + fail("Should have thrown an IllegalArgumentException"); + } catch (IllegalArgumentException e) { + // success + } + } + + public void testStreamResultDefault() throws Exception { + result.setInputName("streamForImage"); + + result.doExecute("helloworld", mai); + + assertEquals(String.valueOf(contentLength), result.getContentLength()); + assertEquals("text/plain", result.getContentType()); + assertEquals("streamForImage", result.getInputName()); + assertEquals(1024, result.getBufferSize()); // 1024 is default + assertEquals("inline", result.getContentDisposition()); + + assertEquals("text/plain", response.getContentType()); + assertEquals(contentLength, response.getContentLength()); + assertEquals("inline", response.getHeader("Content-disposition")); + } + + public void testStreamResultWithCharSet() throws Exception { + result.setInputName("streamForImage"); + result.setContentCharSet("ISO-8859-1"); + result.doExecute("helloworld", mai); + + assertEquals(String.valueOf(contentLength), result.getContentLength()); + assertEquals("text/plain", result.getContentType()); + assertEquals("streamForImage", result.getInputName()); + assertEquals(1024, result.getBufferSize()); // 1024 is default + assertEquals("inline", result.getContentDisposition()); + assertEquals("text/plain;charset=ISO-8859-1", response.getContentType()); + assertEquals(contentLength, response.getContentLength()); + assertEquals("inline", response.getHeader("Content-disposition")); + } + + public void testStreamResultWithCharSet2() throws Exception { + result.setParse(true); + result.setInputName("streamForImage"); + result.setContentCharSet("${contentCharSetMethod}"); + + result.doExecute("helloworld", mai); + + assertEquals(String.valueOf(contentLength), result.getContentLength()); + assertEquals("text/plain", result.getContentType()); + assertEquals("streamForImage", result.getInputName()); + assertEquals(1024, result.getBufferSize()); // 1024 is default + assertEquals("inline", result.getContentDisposition()); + assertEquals("text/plain;charset=UTF-8", response.getContentType()); + assertEquals(contentLength, response.getContentLength()); + assertEquals("inline", response.getHeader("Content-disposition")); + } + + public void testAllowCacheDefault() throws Exception { + result.setInputName("streamForImage"); + + result.doExecute("helloworld", mai); + + //check that that headers are not set by default + assertNull(response.getHeader("Pragma")); + assertNull(response.getHeader("Cache-Control")); + } + + public void testAllowCacheFalse() throws Exception { + result.setInputName("streamForImage"); + result.setAllowCaching(false); + result.doExecute("helloworld", mai); + + //check that that headers are not set by default + assertEquals("no-cache", response.getHeader("Pragma")); + assertEquals("no-cache", response.getHeader("Cache-Control")); + } + + public void testStreamResultNoDefault() throws Exception { + // it's not easy to test using easymock as we use getOutputStream on HttpServletResponse. + result.setParse(false); + result.setInputName("streamForImage"); + result.setBufferSize(128); + result.setContentLength(String.valueOf(contentLength)); + result.setContentDisposition("filename=\"logo.png\""); + result.setContentType("image/jpeg"); + + result.doExecute("helloworld", mai); + + assertEquals(String.valueOf(contentLength), result.getContentLength()); + assertEquals("image/jpeg", result.getContentType()); + assertEquals("streamForImage", result.getInputName()); + assertEquals(128, result.getBufferSize()); + assertEquals("filename=\"logo.png\"", result.getContentDisposition()); + + assertEquals("image/jpeg", response.getContentType()); + assertEquals(contentLength, response.getContentLength()); + assertEquals("filename=\"logo.png\"", response.getHeader("Content-disposition")); + } + + public void testStreamResultParse1() throws Exception { + /////////////////// + result.setParse(true); + // ${...} conditionalParse of Result, returns String, + // which gets evaluated to the stack, that's how it works. + // We use ${streamForImageAsString} that returns "streamForImage" + // which is a property that returns an InputStream object. + result.setInputName("${streamForImageAsString}"); + result.setBufferSize(128); + result.setContentLength(String.valueOf(contentLength)); + result.setContentDisposition("filename=\"logo.png\""); + result.setContentType("image/jpeg"); + + result.doExecute("helloworld", mai); + + assertEquals(String.valueOf(contentLength), result.getContentLength()); + assertEquals("image/jpeg", result.getContentType()); + assertEquals("${streamForImageAsString}", result.getInputName()); + assertEquals(128, result.getBufferSize()); + assertEquals("filename=\"logo.png\"", result.getContentDisposition()); + + assertEquals("image/jpeg", response.getContentType()); + assertEquals(contentLength, response.getContentLength()); + assertEquals("filename=\"logo.png\"", response.getHeader("Content-disposition")); + } + + public void testStreamResultParse2() throws Exception { + /////////////////// + result.setParse(true); + // This time we dun use ${...}, so streamForImage will + // be evaluated to the stack, which should reaturn an + // InputStream object, cause there's such a property in + // the action object itself. + result.setInputName("streamForImage"); + result.setBufferSize(128); + result.setContentLength(String.valueOf(contentLength)); + result.setContentDisposition("filename=\"logo.png\""); + result.setContentType("image/jpeg"); + + result.doExecute("helloworld", mai); + + assertEquals(String.valueOf(contentLength), result.getContentLength()); + assertEquals("image/jpeg", result.getContentType()); + assertEquals("streamForImage", result.getInputName()); + assertEquals(128, result.getBufferSize()); + assertEquals("filename=\"logo.png\"", result.getContentDisposition()); + + assertEquals("image/jpeg", response.getContentType()); + assertEquals(contentLength, response.getContentLength()); + assertEquals("filename=\"logo.png\"", response.getHeader("Content-disposition")); + } + + protected void setUp() throws Exception { + super.setUp(); + response = new MockHttpServletResponse(); + + result = new StreamResult(); + stack = ActionContext.getContext().getValueStack(); + + MyImageAction action = new MyImageAction(); + contentLength = (int) action.getContentLength(); + + mai = new com.opensymphony.xwork2.mock.MockActionInvocation(); + mai.setAction(action); + mai.setStack(stack); + mai.setInvocationContext(ActionContext.getContext()); + stack.push(action); + + ActionContext.getContext().put(ServletActionContext.HTTP_RESPONSE, response); + } + + + + protected void tearDown() throws Exception { + super.tearDown(); + response = null; + result = null; + stack = null; + contentLength = 0; + mai = null; + } + + public class MyImageAction implements Action { + + public InputStream getStreamForImage() throws Exception { + // just use src/test/log4j2.xml as test file + URL url = ClassLoaderUtil.getResource("log4j2.xml", StreamResultTest.class); + File file = new File(new URI(url.toString())); + FileInputStream fis = new FileInputStream(file); + return fis; + } + + public String execute() throws Exception { + return SUCCESS; + } + + public long getContentLength() throws Exception { + URL url = ClassLoaderUtil.getResource("log4j2.xml", StreamResultTest.class); + File file = new File(new URI(url.toString())); + return file.length(); + } + + public String getStreamForImageAsString() { + return "streamForImage"; + } + + public String getContentCharSetMethod() { + return "UTF-8"; + } + } + +} http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/core/src/test/java/org/apache/struts2/result/StrutsResultSupportTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/result/StrutsResultSupportTest.java b/core/src/test/java/org/apache/struts2/result/StrutsResultSupportTest.java new file mode 100644 index 0000000..6a8f90a --- /dev/null +++ b/core/src/test/java/org/apache/struts2/result/StrutsResultSupportTest.java @@ -0,0 +1,156 @@ +/* + * $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.result; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import org.apache.struts2.StrutsInternalTestCase; +import org.apache.struts2.result.StrutsResultSupport; +import org.easymock.EasyMock; + +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ActionSupport; +import com.opensymphony.xwork2.util.ValueStack; + +/** + * Test case for StrutsResultSupport. + */ +public class StrutsResultSupportTest extends StrutsInternalTestCase { + + + public void testParse() throws Exception { + ValueStack stack = ActionContext.getContext().getValueStack(); + stack.push(new ActionSupport() { + public String getMyLocation() { + return "ThisIsMyLocation"; + } + }); + + ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class); + mockActionInvocation.getStack(); + EasyMock.expectLastCall().andReturn(stack); + EasyMock.replay(mockActionInvocation); + + InternalStrutsResultSupport result = new InternalStrutsResultSupport(); + result.setParse(true); + result.setEncode(false); + result.setLocation("/pages/myJsp.jsp?location=${myLocation}"); + + result.execute(mockActionInvocation); + + assertNotNull(result.getInternalLocation()); + assertEquals("/pages/myJsp.jsp?location=ThisIsMyLocation", result.getInternalLocation()); + EasyMock.verify(mockActionInvocation); + } + + public void testParseAndEncode() throws Exception { + ValueStack stack = ActionContext.getContext().getValueStack(); + stack.push(new ActionSupport() { + public String getMyLocation() { + return "/myPage?param=value¶m1=value1"; + } + }); + + ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class); + mockActionInvocation.getStack(); + EasyMock.expectLastCall().andReturn(stack); + EasyMock.replay(mockActionInvocation); + + InternalStrutsResultSupport result = new InternalStrutsResultSupport(); + result.setParse(true); + result.setEncode(true); + result.setLocation("/pages/myJsp.jsp?location=${myLocation}"); + + result.execute(mockActionInvocation); + + assertNotNull(result.getInternalLocation()); + assertEquals("/pages/myJsp.jsp?location=%2FmyPage%3Fparam%3Dvalue%26param1%3Dvalue1", result.getInternalLocation()); + EasyMock.verify(mockActionInvocation); + } + + + public void testNoParseAndEncode() throws Exception { + ValueStack stack = ActionContext.getContext().getValueStack(); + stack.push(new ActionSupport() { + public String getMyLocation() { + return "myLocation.jsp"; + } + }); + + ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class); + EasyMock.replay(mockActionInvocation); + + InternalStrutsResultSupport result = new InternalStrutsResultSupport(); + result.setParse(false); + result.setEncode(false); // don't really need this, as encode is only valid when parse is true. + result.setLocation("/pages/myJsp.jsp?location=${myLocation}"); + + result.execute(mockActionInvocation); + + assertNotNull(result.getInternalLocation()); + assertEquals("/pages/myJsp.jsp?location=${myLocation}", result.getInternalLocation()); + EasyMock.verify(mockActionInvocation); + } + + public void testConditionalParseCollection() throws Exception { + ValueStack stack = ActionContext.getContext().getValueStack(); + stack.push(new ActionSupport() { + public List<String> getList() { + return new ArrayList<String>(){{ + add("val 1"); + add("val 2"); + }}; + } + }); + + ActionInvocation mockActionInvocation = EasyMock.createNiceMock(ActionInvocation.class); + mockActionInvocation.getStack(); + EasyMock.expectLastCall().andReturn(stack); + EasyMock.replay(mockActionInvocation); + + InternalStrutsResultSupport result = new InternalStrutsResultSupport(); + result.setParse(true); + result.setEncode(true); + + Collection<String> collection = result.conditionalParseCollection("${list}", mockActionInvocation, true); + + assertNotNull(collection); + assertEquals(2, collection.size()); + assertTrue(collection.contains("val+1")); + assertTrue(collection.contains("val+2")); + EasyMock.verify(mockActionInvocation); + } + + public static class InternalStrutsResultSupport extends StrutsResultSupport { + private String _internalLocation = null; + + protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { + _internalLocation = finalLocation; + } + + public String getInternalLocation() { + return _internalLocation; + } + } +} http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/core/src/test/java/org/apache/struts2/result/VelocityResultTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/struts2/result/VelocityResultTest.java b/core/src/test/java/org/apache/struts2/result/VelocityResultTest.java new file mode 100644 index 0000000..0a945ec --- /dev/null +++ b/core/src/test/java/org/apache/struts2/result/VelocityResultTest.java @@ -0,0 +1,149 @@ +/* + * $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.result; + +import org.apache.struts2.StrutsInternalTestCase; +import org.apache.struts2.result.StrutsResultSupport; +import org.apache.struts2.result.VelocityResult; +import org.apache.velocity.Template; +import org.apache.velocity.app.VelocityEngine; +import org.apache.velocity.exception.ParseErrorException; +import org.apache.velocity.exception.ResourceNotFoundException; + +import com.mockobjects.dynamic.Mock; +import com.opensymphony.xwork2.ActionContext; +import com.opensymphony.xwork2.ActionInvocation; +import com.opensymphony.xwork2.ActionProxy; +import com.opensymphony.xwork2.util.ValueStack; + + +/** + * + */ +public class VelocityResultTest extends StrutsInternalTestCase { + + ActionInvocation actionInvocation; + Mock mockActionProxy; + ValueStack stack; + String namespace; + TestVelocityEngine velocity; + VelocityResult result; + + + public void testCanResolveLocationUsingOgnl() throws Exception { + TestResult result = new TestResult(); + + String location = "/myaction.action"; + Bean bean = new Bean(); + bean.setLocation(location); + + ValueStack stack = ActionContext.getContext().getValueStack(); + stack.push(bean); + + assertEquals(location, stack.findValue("location")); + + result.setLocation("${location}"); + result.execute(actionInvocation); + assertEquals(location, result.finalLocation); + } + + public void testCanResolveLocationUsingStaticExpression() throws Exception { + TestResult result = new TestResult(); + String location = "/any.action"; + result.setLocation("${'" + location + "'}"); + result.execute(actionInvocation); + assertEquals(location, result.finalLocation); + } + + public void testResourcesFoundUsingAbsolutePath() throws Exception { + String location = "/WEB-INF/views/registration.vm"; + + Template template = result.getTemplate(stack, velocity, actionInvocation, location, "UTF-8"); + assertNotNull(template); + assertEquals("expect absolute locations to be handled as is", location, velocity.templateName); + } + + public void testResourcesFoundUsingNames() throws Exception { + String location = "Registration.vm"; + String expectedTemplateName = namespace + "/" + location; + + Template template = result.getTemplate(stack, velocity, actionInvocation, location, "UTF-8"); + assertNotNull(template); + assertEquals("expect the prefix to be appended to the path when the location is not absolute", expectedTemplateName, velocity.templateName); + } + + protected void setUp() throws Exception { + super.setUp(); + namespace = "/html"; + result = new VelocityResult(); + stack = ActionContext.getContext().getValueStack(); + ActionContext.getContext().setValueStack(stack); + velocity = new TestVelocityEngine(); + mockActionProxy = new Mock(ActionProxy.class); + mockActionProxy.expectAndReturn("getNamespace", "/html"); + + Mock mockActionInvocation = new Mock(ActionInvocation.class); + mockActionInvocation.expectAndReturn("getProxy", mockActionProxy.proxy()); + mockActionInvocation.expectAndReturn("getStack", stack); + actionInvocation = (ActionInvocation) mockActionInvocation.proxy(); + } + + + class Bean { + private String location; + + public void setLocation(String location) { + this.location = location; + } + + public String getLocation() { + return location; + } + } + + class TestResult extends StrutsResultSupport { + + private static final long serialVersionUID = -1512206785088317315L; + + public String finalLocation; + + protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { + this.finalLocation = finalLocation; + } + } + + class TestVelocityEngine extends VelocityEngine { + public String templateName; + + public Template getTemplate(String templateName) throws ResourceNotFoundException, ParseErrorException, Exception { + this.templateName = templateName; + + return new Template(); + } + + public Template getTemplate(String templateName, String charSet) throws ResourceNotFoundException, ParseErrorException, Exception { + this.templateName = templateName; + + return new Template(); + } + } +} http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/convention/src/test/java/org/apache/struts2/convention/ConventionUnknownHandlerTest.java ---------------------------------------------------------------------- diff --git a/plugins/convention/src/test/java/org/apache/struts2/convention/ConventionUnknownHandlerTest.java b/plugins/convention/src/test/java/org/apache/struts2/convention/ConventionUnknownHandlerTest.java index 10733af..ad40e59 100644 --- a/plugins/convention/src/test/java/org/apache/struts2/convention/ConventionUnknownHandlerTest.java +++ b/plugins/convention/src/test/java/org/apache/struts2/convention/ConventionUnknownHandlerTest.java @@ -27,7 +27,7 @@ import com.opensymphony.xwork2.config.entities.PackageConfig; import com.opensymphony.xwork2.config.entities.ResultTypeConfig; import com.opensymphony.xwork2.inject.Container; import junit.framework.TestCase; -import org.apache.struts2.dispatcher.ServletDispatcherResult; +import org.apache.struts2.result.ServletDispatcherResult; import org.easymock.EasyMock; import javax.servlet.ServletContext; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java ---------------------------------------------------------------------- diff --git a/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java b/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java index 502b202..abda7b3 100644 --- a/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java +++ b/plugins/convention/src/test/java/org/apache/struts2/convention/DefaultResultMapBuilderTest.java @@ -29,7 +29,7 @@ import org.apache.struts2.convention.actions.NoAnnotationAction; import org.apache.struts2.convention.actions.result.*; import org.apache.struts2.convention.actions.resultpath.ClassLevelResultPathAction; import org.apache.struts2.convention.annotation.Action; -import org.apache.struts2.dispatcher.ServletDispatcherResult; +import org.apache.struts2.result.ServletDispatcherResult; import org.easymock.EasyMock; import org.easymock.IAnswer; @@ -205,7 +205,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals(4, results.size()); assertEquals("success", results.get("success").getName()); assertEquals(3, results.get("success").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); assertEquals("/WEB-INF/location/namespace/no-annotation-success.jsp", results.get("success").getParams().get("location")); assertEquals(1, results.get("input").getParams().size()); assertEquals("org.apache.struts2.views.freemarker.FreemarkerResult", results.get("input").getClassName()); @@ -214,7 +214,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals("org.apache.struts2.views.freemarker.FreemarkerResult", results.get("error").getClassName()); assertEquals("/WEB-INF/location/namespace/no-annotation.ftl", results.get("error").getParams().get("location")); assertEquals(3, results.get("failure").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); assertEquals("/WEB-INF/location/namespace/no-annotation-failure.jsp", results.get("failure").getParams().get("location")); EasyMock.verify(context); @@ -243,7 +243,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals("success", results.get("success").getName()); assertEquals(3, results.get("success").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); assertEquals("/WEB-INF/location/namespace/no-annotation/success.jsp", results.get("success").getParams().get("location")); assertEquals(1, results.get("index").getParams().size()); @@ -251,7 +251,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals("/WEB-INF/location/namespace/no-annotation/index.ftl", results.get("index").getParams().get("location")); assertEquals(3, results.get("failure").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); assertEquals("/WEB-INF/location/namespace/no-annotation/failure.jsp", results.get("failure").getParams().get("location")); EasyMock.verify(context); } @@ -274,7 +274,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals(1, results.size()); assertEquals("success", results.get("success").getName()); assertEquals(3, results.get("success").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); assertEquals("/WEB-INF/location/namespace/no-annotation-success.jsp", results.get("success").getParams().get("location")); EasyMock.verify(context); @@ -296,7 +296,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals(1, results.size()); assertEquals("error", results.get("error").getName()); assertEquals(3, results.get("error").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("error").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName()); assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location")); assertEquals("value", results.get("error").getParams().get("key")); assertEquals("value1", results.get("error").getParams().get("key1")); @@ -319,7 +319,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals(1, results.size()); assertEquals("error", results.get("error").getName()); assertEquals(3, results.get("error").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("error").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName()); assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location")); assertEquals("value", results.get("error").getParams().get("key")); assertEquals("value1", results.get("error").getParams().get("key1")); @@ -342,7 +342,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals(1, results.size()); assertEquals("error", results.get("error").getName()); assertEquals(5, results.get("error").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("error").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName()); assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location")); assertEquals("value", results.get("error").getParams().get("key")); assertEquals("value1", results.get("error").getParams().get("key1")); @@ -370,21 +370,21 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals("success", results.get("success").getName()); assertEquals("failure", results.get("failure").getName()); assertEquals(3, results.get("error").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("error").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName()); assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location")); assertEquals("ann-value", results.get("error").getParams().get("key")); assertEquals("ann-value1", results.get("error").getParams().get("key1")); assertEquals(1, results.get("input").getParams().size()); assertEquals("foo.action", results.get("input").getParams().get("actionName")); - assertEquals("org.apache.struts2.dispatcher.ServletActionRedirectResult", results.get("input").getClassName()); + assertEquals("org.apache.struts2.result.ServletActionRedirectResult", results.get("input").getClassName()); assertEquals(3, results.get("failure").getParams().size()); assertEquals("/WEB-INF/location/namespace/action-failure.jsp", results.get("failure").getParams().get("location")); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("failure").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("failure").getClassName()); assertEquals("value", results.get("failure").getParams().get("key")); assertEquals("value1", results.get("failure").getParams().get("key1")); assertEquals(3, results.get("success").getParams().size()); assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location")); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); assertEquals("value", results.get("success").getParams().get("key")); assertEquals("value1", results.get("success").getParams().get("key1")); EasyMock.verify(context); @@ -409,21 +409,21 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals("success", results.get("success").getName()); assertEquals("failure", results.get("failure").getName()); assertEquals(3, results.get("error").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("error").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName()); assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location")); assertEquals("ann-value", results.get("error").getParams().get("key")); assertEquals("ann-value1", results.get("error").getParams().get("key1")); assertEquals(1, results.get("input").getParams().size()); assertEquals("foo.action", results.get("input").getParams().get("actionName")); - assertEquals("org.apache.struts2.dispatcher.ServletActionRedirectResult", results.get("input").getClassName()); + assertEquals("org.apache.struts2.result.ServletActionRedirectResult", results.get("input").getClassName()); assertEquals(3, results.get("failure").getParams().size()); assertEquals("/WEB-INF/location/namespace/action-failure.jsp", results.get("failure").getParams().get("location")); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("failure").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("failure").getClassName()); assertEquals("value", results.get("failure").getParams().get("key")); assertEquals("value1", results.get("failure").getParams().get("key1")); assertEquals(3, results.get("success").getParams().size()); assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location")); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); assertEquals("value", results.get("success").getParams().get("key")); assertEquals("value1", results.get("success").getParams().get("key1")); EasyMock.verify(context); @@ -445,7 +445,7 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals(1, results.size()); assertEquals("success", results.get("success").getName()); assertEquals(3, results.get("success").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location")); assertEquals("value", results.get("success").getParams().get("key")); assertEquals("value1", results.get("success").getParams().get("key1")); @@ -471,26 +471,26 @@ public class DefaultResultMapBuilderTest extends TestCase { assertEquals("success", results.get("success").getName()); assertEquals("failure", results.get("failure").getName()); assertEquals(3, results.get("error").getParams().size()); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("error").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("error").getClassName()); assertEquals("/WEB-INF/location/namespace/error.jsp", results.get("error").getParams().get("location")); assertEquals("value", results.get("success").getParams().get("key")); assertEquals("value1", results.get("success").getParams().get("key1")); assertEquals(1, results.get("input").getParams().size()); assertEquals("foo.action", results.get("input").getParams().get("actionName")); - assertEquals("org.apache.struts2.dispatcher.ServletActionRedirectResult", results.get("input").getClassName()); + assertEquals("org.apache.struts2.result.ServletActionRedirectResult", results.get("input").getClassName()); assertEquals(3, results.get("failure").getParams().size()); assertEquals("/WEB-INF/location/namespace/action-failure.jsp", results.get("failure").getParams().get("location")); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("failure").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("failure").getClassName()); assertEquals(3, results.get("success").getParams().size()); assertEquals("/WEB-INF/location/namespace/action-success.jsp", results.get("success").getParams().get("location")); - assertEquals("org.apache.struts2.dispatcher.ServletDispatcherResult", results.get("success").getClassName()); + assertEquals("org.apache.struts2.result.ServletDispatcherResult", results.get("success").getClassName()); EasyMock.verify(context); } public void testClassPath() throws Exception { ServletContext context = EasyMock.createNiceMock(ServletContext.class); - ResultTypeConfig resultType = new ResultTypeConfig.Builder("freemarker", "org.apache.struts2.dispatcher.ServletDispatcherResult"). + ResultTypeConfig resultType = new ResultTypeConfig.Builder("freemarker", "org.apache.struts2.result.ServletDispatcherResult"). defaultResultParam("location").build(); PackageConfig packageConfig = new PackageConfig.Builder("package"). defaultResultType("dispatcher").addResultTypeConfig(resultType).build(); @@ -514,11 +514,11 @@ public class DefaultResultMapBuilderTest extends TestCase { } private PackageConfig createPackageConfigBuilder(String namespace) { - ResultTypeConfig resultType = new ResultTypeConfig.Builder("dispatcher", "org.apache.struts2.dispatcher.ServletDispatcherResult"). + ResultTypeConfig resultType = new ResultTypeConfig.Builder("dispatcher", "org.apache.struts2.result.ServletDispatcherResult"). addParam("key", "value").addParam("key1", "value1").defaultResultParam("location").build(); ResultTypeConfig redirect = new ResultTypeConfig.Builder("redirectAction", - "org.apache.struts2.dispatcher.ServletActionRedirectResult").defaultResultParam("actionName").build(); + "org.apache.struts2.result.ServletActionRedirectResult").defaultResultParam("actionName").build(); ResultTypeConfig ftlResultType = new ResultTypeConfig.Builder("freemarker", "org.apache.struts2.views.freemarker.FreemarkerResult").defaultResultParam("location").build(); http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java ---------------------------------------------------------------------- diff --git a/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java b/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java index 7fbd420..38403a0 100644 --- a/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java +++ b/plugins/convention/src/test/java/org/apache/struts2/convention/PackageBasedActionConfigBuilderTest.java @@ -65,7 +65,7 @@ import org.apache.struts2.convention.actions.transactions.TransNameAction; import org.apache.struts2.convention.annotation.Action; import org.apache.struts2.convention.annotation.Actions; import org.apache.struts2.convention.dontfind.DontFindMeAction; -import org.apache.struts2.dispatcher.ServletDispatcherResult; +import org.apache.struts2.result.ServletDispatcherResult; import org.easymock.EasyMock; import javax.servlet.ServletContext; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/embeddedjsp/src/main/java/org/apache/struts2/EmbeddedJSPResult.java ---------------------------------------------------------------------- diff --git a/plugins/embeddedjsp/src/main/java/org/apache/struts2/EmbeddedJSPResult.java b/plugins/embeddedjsp/src/main/java/org/apache/struts2/EmbeddedJSPResult.java index c402cb5..7be0910 100644 --- a/plugins/embeddedjsp/src/main/java/org/apache/struts2/EmbeddedJSPResult.java +++ b/plugins/embeddedjsp/src/main/java/org/apache/struts2/EmbeddedJSPResult.java @@ -22,7 +22,7 @@ package org.apache.struts2; import com.opensymphony.xwork2.ActionInvocation; import org.apache.commons.lang3.StringUtils; -import org.apache.struts2.dispatcher.StrutsResultSupport; +import org.apache.struts2.result.StrutsResultSupport; /** * Can render jsps from the classpath. "includes" in the jsps must not use relative paths http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java ---------------------------------------------------------------------- diff --git a/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java b/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java index 56cd4b0..a8492af 100644 --- a/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java +++ b/plugins/jasperreports/src/main/java/org/apache/struts2/views/jasperreports/JasperReportsResult.java @@ -32,11 +32,10 @@ import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.StrutsResultSupport; +import org.apache.struts2.result.StrutsResultSupport; import javax.servlet.ServletContext; import javax.servlet.ServletException; -import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java ---------------------------------------------------------------------- diff --git a/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java b/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java index 76c2936..4a1886e 100644 --- a/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java +++ b/plugins/jfreechart/src/main/java/org/apache/struts2/dispatcher/ChartResult.java @@ -25,6 +25,7 @@ import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionInvocation; import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; +import org.apache.struts2.result.StrutsResultSupport; import org.jfree.chart.ChartUtilities; import org.jfree.chart.JFreeChart; @@ -247,4 +248,4 @@ public class ChartResult extends StrutsResultSupport { } } -} \ No newline at end of file +} http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java ---------------------------------------------------------------------- diff --git a/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java b/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java index c08a99b..d10693c 100644 --- a/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java +++ b/plugins/portlet-tiles/src/main/java/org/apache/struts2/views/tiles/PortletTilesResult.java @@ -3,7 +3,7 @@ package org.apache.struts2.views.tiles; import com.opensymphony.xwork2.ActionInvocation; import freemarker.template.TemplateException; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.ServletDispatcherResult; +import org.apache.struts2.result.ServletDispatcherResult; import org.apache.struts2.portlet.PortletConstants; import org.apache.struts2.portlet.context.PortletActionContext; import org.apache.tiles.TilesContainer; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java ---------------------------------------------------------------------- diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java index 04729c1..5ef5a1a 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletActionRedirectResult.java @@ -23,7 +23,7 @@ package org.apache.struts2.portlet.result; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.config.entities.ResultConfig; import com.opensymphony.xwork2.inject.Inject; -import org.apache.struts2.dispatcher.ServletActionRedirectResult; +import org.apache.struts2.result.ServletActionRedirectResult; import org.apache.struts2.dispatcher.mapper.ActionMapper; import org.apache.struts2.dispatcher.mapper.ActionMapping; import org.apache.struts2.portlet.PortletConstants; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java ---------------------------------------------------------------------- diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java index 7fa2336..50fa223 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletResult.java @@ -26,7 +26,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.apache.commons.lang3.StringUtils; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.StrutsResultSupport; +import org.apache.struts2.result.StrutsResultSupport; import org.apache.struts2.portlet.PortletConstants; import org.apache.struts2.portlet.PortletPhase; import org.apache.struts2.portlet.context.PortletActionContext; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java ---------------------------------------------------------------------- diff --git a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java index 2d43c27..ccfec82 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/portlet/result/PortletVelocityResult.java @@ -28,7 +28,7 @@ import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.LogManager; import org.apache.struts2.ServletActionContext; import org.apache.struts2.StrutsConstants; -import org.apache.struts2.dispatcher.StrutsResultSupport; +import org.apache.struts2.result.StrutsResultSupport; import org.apache.struts2.portlet.PortletConstants; import org.apache.struts2.portlet.PortletPhase; import org.apache.struts2.portlet.context.PortletActionContext; @@ -115,7 +115,7 @@ public class PortletVelocityResult extends StrutsResultSupport { } /* (non-Javadoc) - * @see org.apache.struts2.dispatcher.StrutsResultSupport#doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation) + * @see org.apache.struts2.result.StrutsResultSupport#doExecute(java.lang.String, com.opensymphony.xwork2.ActionInvocation) */ public void doExecute(String location, ActionInvocation invocation) throws Exception { PortletPhase phase = PortletActionContext.getPhase(); http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java ---------------------------------------------------------------------- diff --git a/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java b/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java index 71d0cee..036bd14 100644 --- a/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java +++ b/plugins/portlet/src/main/java/org/apache/struts2/views/freemarker/PortletFreemarkerResult.java @@ -30,7 +30,7 @@ import freemarker.template.TemplateException; import freemarker.template.TemplateModel; import freemarker.template.TemplateModelException; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.StrutsResultSupport; +import org.apache.struts2.result.StrutsResultSupport; import org.apache.struts2.portlet.PortletConstants; import org.apache.struts2.portlet.PortletPhase; import org.apache.struts2.portlet.context.PortletActionContext; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java ---------------------------------------------------------------------- diff --git a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java index 65e6084..c5a687f 100644 --- a/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java +++ b/plugins/rest/src/main/java/org/apache/struts2/rest/RestActionInvocation.java @@ -32,7 +32,7 @@ import org.apache.commons.lang3.BooleanUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.HttpHeaderResult; +import org.apache.struts2.result.HttpHeaderResult; import org.apache.struts2.rest.handler.ContentTypeHandler; import org.apache.struts2.rest.handler.HtmlHandler; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/rest/src/main/resources/struts-plugin.xml ---------------------------------------------------------------------- diff --git a/plugins/rest/src/main/resources/struts-plugin.xml b/plugins/rest/src/main/resources/struts-plugin.xml index 1e95d4eaf..0f0937e 100644 --- a/plugins/rest/src/main/resources/struts-plugin.xml +++ b/plugins/rest/src/main/resources/struts-plugin.xml @@ -48,10 +48,10 @@ <package name="rest-default" extends="struts-default"> <result-types> - <result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"> + <result-type name="redirect" class="org.apache.struts2.result.ServletRedirectResult"> <param name="statusCode">303</param> </result-type> - <result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"> + <result-type name="redirectAction" class="org.apache.struts2.result.ServletActionRedirectResult"> <param name="statusCode">303</param> </result-type> </result-types> http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java ---------------------------------------------------------------------- diff --git a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java index 6db05f1..1ebdc94 100644 --- a/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java +++ b/plugins/rest/src/test/java/org/apache/struts2/rest/RestActionInvocationTest.java @@ -14,7 +14,7 @@ import com.opensymphony.xwork2.ognl.OgnlUtil; import com.opensymphony.xwork2.util.XWorkTestCaseHelper; import junit.framework.TestCase; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.HttpHeaderResult; +import org.apache.struts2.result.HttpHeaderResult; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; @@ -174,7 +174,7 @@ public class RestActionInvocationTest extends TestCase { restActionInvocation.setDefaultErrorResultName("default-error"); ResultConfig resultConfig = new ResultConfig.Builder("default-error", - "org.apache.struts2.dispatcher.HttpHeaderResult") + "org.apache.struts2.result.HttpHeaderResult") .addParam("status", "123").build(); ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction") @@ -219,7 +219,7 @@ public class RestActionInvocationTest extends TestCase { // Define result 'success' ResultConfig resultConfig = new ResultConfig.Builder("success", - "org.apache.struts2.dispatcher.HttpHeaderResult") + "org.apache.struts2.result.HttpHeaderResult") .addParam("status", "123").build(); ActionConfig actionConfig = new ActionConfig.Builder("org.apache.rest", "RestAction", "org.apache.rest.RestAction") http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java ---------------------------------------------------------------------- diff --git a/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java b/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java index 6135302..490de79 100644 --- a/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java +++ b/plugins/tiles/src/main/java/org/apache/struts2/views/tiles/TilesResult.java @@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.ServletDispatcherResult; +import org.apache.struts2.result.ServletDispatcherResult; import org.apache.tiles.TilesContainer; import org.apache.tiles.access.TilesAccess; http://git-wip-us.apache.org/repos/asf/struts/blob/6bc99ab9/plugins/tiles3/src/main/java/org/apache/struts2/views/tiles/TilesResult.java ---------------------------------------------------------------------- diff --git a/plugins/tiles3/src/main/java/org/apache/struts2/views/tiles/TilesResult.java b/plugins/tiles3/src/main/java/org/apache/struts2/views/tiles/TilesResult.java index a774edb..6bc15bb 100644 --- a/plugins/tiles3/src/main/java/org/apache/struts2/views/tiles/TilesResult.java +++ b/plugins/tiles3/src/main/java/org/apache/struts2/views/tiles/TilesResult.java @@ -23,7 +23,7 @@ package org.apache.struts2.views.tiles; import com.opensymphony.xwork2.ActionInvocation; import org.apache.struts2.ServletActionContext; -import org.apache.struts2.dispatcher.ServletDispatcherResult; +import org.apache.struts2.result.ServletDispatcherResult; import org.apache.tiles.TilesContainer; import org.apache.tiles.access.TilesAccess; import org.apache.tiles.request.ApplicationContext;
