mirror of
https://github.com/apache/struts.git
synced 2026-08-06 07:06:58 +00:00
WW-5063 Adds tests to cover new functionality
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* 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 com.opensymphony.xwork2;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class ActionChainResultTest {
|
||||
|
||||
@Test
|
||||
public void testPassingNullInvocation() throws Exception{
|
||||
Result result = new ActionChainResult();
|
||||
try {
|
||||
result.execute(null);
|
||||
fail("Exception should be thrown!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Invocation cannot be null!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,7 +25,6 @@ import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.util.reflection.ReflectionProvider;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
import org.apache.struts2.result.HttpHeaderResult;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
@@ -36,18 +35,19 @@ import java.util.Map;
|
||||
*/
|
||||
public class HttpHeaderResultTest extends StrutsInternalTestCase {
|
||||
|
||||
ActionInvocation invocation;
|
||||
HttpHeaderResult result;
|
||||
HttpServletResponse response;
|
||||
Mock responseMock;
|
||||
ReflectionProvider reflectionProvider;
|
||||
private Mock invocationMock;
|
||||
private ActionInvocation invocation;
|
||||
private HttpHeaderResult result;
|
||||
private HttpServletResponse response;
|
||||
private Mock responseMock;
|
||||
private ReflectionProvider reflectionProvider;
|
||||
|
||||
public void testHeaderValuesAreNotParsedWhenParseIsFalse() throws Exception {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("headers.foo", "${bar}");
|
||||
params.put("headers.baz", "baz");
|
||||
|
||||
Map<String, String> values = new HashMap<String, String>();
|
||||
Map<String, String> values = new HashMap<>();
|
||||
values.put("bar", "abc");
|
||||
ActionContext.getContext().getValueStack().push(values);
|
||||
|
||||
@@ -61,11 +61,11 @@ public class HttpHeaderResultTest extends StrutsInternalTestCase {
|
||||
}
|
||||
|
||||
public void testHeaderValuesAreParsedAndSet() throws Exception {
|
||||
Map<String, String> params = new HashMap<String, String>();
|
||||
Map<String, String> params = new HashMap<>();
|
||||
params.put("headers.foo", "${bar}");
|
||||
params.put("headers.baz", "baz");
|
||||
|
||||
Map<String, String> values = new HashMap<String, String>();
|
||||
Map<String, String> values = new HashMap<>();
|
||||
values.put("bar", "abc");
|
||||
ActionContext.getContext().getValueStack().push(values);
|
||||
|
||||
@@ -113,12 +113,21 @@ public class HttpHeaderResultTest extends StrutsInternalTestCase {
|
||||
responseMock.verify();
|
||||
}
|
||||
|
||||
public void testPassingNullInvocation() throws Exception {
|
||||
try {
|
||||
result.execute(null);
|
||||
fail("Exception should be thrown!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Invocation cannot be null!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
result = new HttpHeaderResult();
|
||||
responseMock = new Mock(HttpServletResponse.class);
|
||||
response = (HttpServletResponse) responseMock.proxy();
|
||||
Mock invocationMock = new Mock(ActionInvocation.class);
|
||||
invocationMock = new Mock(ActionInvocation.class);
|
||||
invocationMock.expectAndReturn("getInvocationContext", ActionContext.getContext());
|
||||
invocationMock.expectAndReturn("getStack", ActionContext.getContext().getValueStack());
|
||||
invocation = (ActionInvocation) invocationMock.proxy();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package org.apache.struts2.result;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import org.apache.struts2.StrutsException;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
@@ -127,6 +128,16 @@ public class PlainResultTest extends StrutsInternalTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testPassingNullInvocation() throws Exception{
|
||||
Result result = (PlainResult) response -> response.write("ignore");
|
||||
try {
|
||||
result.execute(null);
|
||||
fail("Exception should be thrown!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Invocation cannot be null!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
invocation = new MockActionInvocation();
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.apache.struts2.result;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.ServletActionContext;
|
||||
import org.apache.struts2.StrutsInternalTestCase;
|
||||
@@ -32,7 +33,6 @@ import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import static org.easymock.EasyMock.createControl;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
|
||||
|
||||
public class PostbackResultTest extends StrutsInternalTestCase {
|
||||
|
||||
public void testWithNoNamespace() throws Exception {
|
||||
@@ -93,4 +93,15 @@ public class PostbackResultTest extends StrutsInternalTestCase {
|
||||
control.verify();
|
||||
}
|
||||
|
||||
public void testPassingNullInvocation() throws Exception{
|
||||
Result result = new PostbackResult();
|
||||
try {
|
||||
result.execute(null);
|
||||
fail("Exception should be thrown!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Invocation cannot be null!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.mockobjects.dynamic.Mock;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.ActionInvocation;
|
||||
import com.opensymphony.xwork2.ActionProxy;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.config.entities.PackageConfig;
|
||||
import com.opensymphony.xwork2.config.entities.ResultConfig;
|
||||
@@ -376,7 +377,7 @@ public class ServletRedirectResultTest extends StrutsInternalTestCase implements
|
||||
* the desired log warning when an IllegalStateException is thrown for statusCode SC_FOUND.
|
||||
*/
|
||||
public void testSendRedirectSCFoundIllegalStateException() {
|
||||
HttpServletResponse httpServletResponseMock = (HttpServletResponse) createMock(HttpServletResponse.class);
|
||||
HttpServletResponse httpServletResponseMock = createMock(HttpServletResponse.class);
|
||||
boolean iseCaught = false;
|
||||
view.setLocation("/bar/foo.jsp");
|
||||
view.setStatusCode(HttpServletResponse.SC_FOUND);
|
||||
@@ -432,6 +433,16 @@ public class ServletRedirectResultTest extends StrutsInternalTestCase implements
|
||||
}
|
||||
}
|
||||
|
||||
public void testPassingNullInvocation() throws Exception{
|
||||
Result result = new ServletRedirectResult();
|
||||
try {
|
||||
result.execute(null);
|
||||
fail("Exception should be thrown!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Invocation cannot be null!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
configurationManager.getConfiguration().
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
package org.apache.struts2.views.xslt;
|
||||
|
||||
import com.opensymphony.xwork2.Action;
|
||||
import com.opensymphony.xwork2.ActionChainResult;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ClassLoaderUtil;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
@@ -241,6 +243,16 @@ public class XSLTResultTest extends StrutsInternalTestCase {
|
||||
assertEquals(actual, "ISO-8859-1");
|
||||
}
|
||||
|
||||
public void testPassingNullInvocation() throws Exception{
|
||||
Result result = new XSLTResult();
|
||||
try {
|
||||
result.execute(null);
|
||||
fail("Exception should be thrown!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Invocation cannot be null!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
request = new MockHttpServletRequest();
|
||||
|
||||
@@ -35,6 +35,7 @@ import java.util.regex.Pattern;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
@@ -713,6 +714,16 @@ public class JSONResultTest extends StrutsTestCase {
|
||||
assertEquals("UTF-8", encoding);
|
||||
}
|
||||
|
||||
public void testPassingNullInvocation() throws Exception{
|
||||
Result result = new JSONResult();
|
||||
try {
|
||||
result.execute(null);
|
||||
fail("Exception should be thrown!");
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertEquals("Invocation cannot be null!", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
Reference in New Issue
Block a user