mirror of
https://github.com/apache/struts.git
synced 2026-08-06 07:06:58 +00:00
WW-5220 Moves JUnit related test into the JUnit plugin
Also moves all the plugin classes under junit package
This commit is contained in:
@@ -18,10 +18,10 @@
|
||||
*/
|
||||
package org.apache.struts2.json;
|
||||
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.json.annotations.JSONFieldBridge;
|
||||
import org.apache.struts2.json.bridge.StringBridge;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
import org.apache.struts2.junit.StrutsTestCase;
|
||||
import org.apache.struts2.junit.util.TestUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.net.URL;
|
||||
@@ -32,10 +32,10 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class DefaultJSONWriterTest extends StrutsTestCase{
|
||||
public class DefaultJSONWriterTest extends StrutsTestCase {
|
||||
@Test
|
||||
public void testWrite() throws Exception {
|
||||
Bean bean1=new Bean();
|
||||
Bean bean1 = new Bean();
|
||||
bean1.setStringField("str");
|
||||
bean1.setBooleanField(true);
|
||||
bean1.setCharField('s');
|
||||
@@ -54,7 +54,7 @@ public class DefaultJSONWriterTest extends StrutsTestCase{
|
||||
|
||||
@Test
|
||||
public void testWriteExcludeNull() throws Exception {
|
||||
BeanWithMap bean1=new BeanWithMap();
|
||||
BeanWithMap bean1 = new BeanWithMap();
|
||||
bean1.setStringField("str");
|
||||
bean1.setBooleanField(true);
|
||||
bean1.setCharField('s');
|
||||
@@ -78,7 +78,7 @@ public class DefaultJSONWriterTest extends StrutsTestCase{
|
||||
TestUtils.assertEquals(DefaultJSONWriter.class.getResource("jsonwriter-write-bean-03.txt"), json);
|
||||
}
|
||||
|
||||
private class BeanWithMap extends Bean{
|
||||
private class BeanWithMap extends Bean {
|
||||
private Map map;
|
||||
|
||||
public Map getMap() {
|
||||
@@ -92,7 +92,7 @@ public class DefaultJSONWriterTest extends StrutsTestCase{
|
||||
|
||||
@Test
|
||||
public void testWriteAnnotatedBean() throws Exception {
|
||||
AnnotatedBean bean1=new AnnotatedBean();
|
||||
AnnotatedBean bean1 = new AnnotatedBean();
|
||||
bean1.setStringField("str");
|
||||
bean1.setBooleanField(true);
|
||||
bean1.setCharField('s');
|
||||
@@ -146,7 +146,7 @@ public class DefaultJSONWriterTest extends StrutsTestCase{
|
||||
}
|
||||
}
|
||||
|
||||
private class AnnotatedBean extends Bean{
|
||||
private class AnnotatedBean extends Bean {
|
||||
private URL url;
|
||||
|
||||
@JSONFieldBridge(impl = StringBridge.class)
|
||||
|
||||
+7
-8
@@ -18,19 +18,18 @@
|
||||
*/
|
||||
package org.apache.struts2.json;
|
||||
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;
|
||||
import org.apache.struts2.views.util.DefaultUrlHelper;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.config.entities.ActionConfig;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.mock.MockActionProxy;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.dispatcher.mapper.DefaultActionMapper;
|
||||
import org.apache.struts2.junit.StrutsTestCase;
|
||||
import org.apache.struts2.views.util.DefaultUrlHelper;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
public class JSONActionRedirectResultTest extends StrutsTestCase {
|
||||
|
||||
|
||||
@@ -18,19 +18,18 @@
|
||||
*/
|
||||
package org.apache.struts2.json;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.junit.StrutsTestCase;
|
||||
import org.apache.struts2.junit.util.TestUtils;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class JSONInterceptorTest extends StrutsTestCase {
|
||||
private MockActionInvocationEx invocation;
|
||||
@@ -294,7 +293,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
|
||||
assertEquals("application/json;charset=UTF-8", response.getContentType());
|
||||
}
|
||||
|
||||
@SuppressWarnings( { "unchecked", "unchecked" })
|
||||
@SuppressWarnings({"unchecked", "unchecked"})
|
||||
public void testReadEmpty() throws Exception {
|
||||
// request
|
||||
setRequestContent("json-6.txt");
|
||||
@@ -309,7 +308,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
|
||||
interceptor.intercept(this.invocation);
|
||||
}
|
||||
|
||||
@SuppressWarnings( { "unchecked", "unchecked" })
|
||||
@SuppressWarnings({"unchecked", "unchecked"})
|
||||
public void test() throws Exception {
|
||||
// request
|
||||
setRequestContent("json-1.txt");
|
||||
@@ -457,7 +456,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
|
||||
assertEquals(bean2.getDoubleField(), 10.1);
|
||||
assertEquals(bean2.getByteField(), 3);
|
||||
}
|
||||
|
||||
|
||||
public void testJSONArray() throws Exception {
|
||||
setRequestContent("json-12.txt");
|
||||
this.request.addHeader("Content-Type", "application/json");
|
||||
@@ -509,7 +508,7 @@ public class JSONInterceptorTest extends StrutsTestCase {
|
||||
assertEquals(beans.get(0).getDoubleField(), 10.1);
|
||||
assertEquals(beans.get(0).getByteField(), 3);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
@@ -27,7 +27,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
import org.apache.struts2.junit.util.TestUtils;
|
||||
|
||||
public class JSONPopulatorTest extends TestCase {
|
||||
|
||||
|
||||
@@ -18,6 +18,19 @@
|
||||
*/
|
||||
package org.apache.struts2.json;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.Result;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.junit.StrutsTestCase;
|
||||
import org.apache.struts2.junit.util.TestUtils;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -33,21 +46,6 @@ import java.util.Map;
|
||||
import java.util.Set;
|
||||
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;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.mock.web.MockHttpServletResponse;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
|
||||
import com.opensymphony.xwork2.ActionContext;
|
||||
import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.util.ValueStack;
|
||||
|
||||
/**
|
||||
* JSONResultTest
|
||||
*/
|
||||
@@ -298,13 +296,13 @@ public class JSONResultTest extends StrutsTestCase {
|
||||
stack.push(action);
|
||||
|
||||
// test scape characters
|
||||
action.setArray(new String[] { "a", "a", "\"", "\\", "/", "\b", "\f", "\n", "\r", "\t" });
|
||||
action.setArray(new String[]{"a", "a", "\"", "\\", "/", "\b", "\f", "\n", "\r", "\t"});
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
list.add("b");
|
||||
list.add(1);
|
||||
list.add(new int[] { 10, 12 });
|
||||
list.add(new int[]{10, 12});
|
||||
action.setCollection(list);
|
||||
|
||||
// beans
|
||||
@@ -343,7 +341,7 @@ public class JSONResultTest extends StrutsTestCase {
|
||||
Map map = new LinkedHashMap();
|
||||
|
||||
map.put("a", 1);
|
||||
map.put("c", new float[] { 1.0f, 2.0f });
|
||||
map.put("c", new float[]{1.0f, 2.0f});
|
||||
action.setMap(map);
|
||||
|
||||
action.setFoo("foo");
|
||||
@@ -403,13 +401,13 @@ public class JSONResultTest extends StrutsTestCase {
|
||||
stack.push(action);
|
||||
|
||||
// test scape characters
|
||||
action.setArray(new String[] { "a", "a", "\"", "\\", "/", "\b", "\f", "\n", "\r", "\t" });
|
||||
action.setArray(new String[]{"a", "a", "\"", "\\", "/", "\b", "\f", "\n", "\r", "\t"});
|
||||
|
||||
List list = new ArrayList();
|
||||
|
||||
list.add("b");
|
||||
list.add(1);
|
||||
list.add(new int[] { 10, 12 });
|
||||
list.add(new int[]{10, 12});
|
||||
action.setCollection(list);
|
||||
|
||||
// beans
|
||||
@@ -446,7 +444,7 @@ public class JSONResultTest extends StrutsTestCase {
|
||||
Map map = new LinkedHashMap();
|
||||
|
||||
map.put("a", 1);
|
||||
map.put("c", new float[] { 1.0f, 2.0f });
|
||||
map.put("c", new float[]{1.0f, 2.0f});
|
||||
action.setMap(map);
|
||||
|
||||
action.setFoo("foo");
|
||||
@@ -714,7 +712,7 @@ public class JSONResultTest extends StrutsTestCase {
|
||||
assertEquals("UTF-8", encoding);
|
||||
}
|
||||
|
||||
public void testPassingNullInvocation() throws Exception{
|
||||
public void testPassingNullInvocation() throws Exception {
|
||||
Result result = new JSONResult();
|
||||
try {
|
||||
result.execute(null);
|
||||
|
||||
+14
-14
@@ -26,13 +26,13 @@ import com.opensymphony.xwork2.mock.MockActionInvocation;
|
||||
import com.opensymphony.xwork2.mock.MockActionProxy;
|
||||
import com.opensymphony.xwork2.validator.annotations.EmailValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.IntRangeFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.RequiredStringValidator;
|
||||
import com.opensymphony.xwork2.validator.annotations.StringLengthFieldValidator;
|
||||
import org.apache.struts2.StrutsStatics;
|
||||
import org.apache.struts2.StrutsTestCase;
|
||||
import org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor;
|
||||
import org.apache.struts2.interceptor.validation.SkipValidation;
|
||||
import org.apache.struts2.util.TestUtils;
|
||||
import org.apache.struts2.junit.StrutsTestCase;
|
||||
import org.apache.struts2.junit.util.TestUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.PrintWriter;
|
||||
@@ -53,13 +53,13 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
private AnnotationValidationInterceptor validationInterceptor;
|
||||
|
||||
public void testValidationFails() throws Exception {
|
||||
|
||||
|
||||
action.addActionError("General error");
|
||||
|
||||
|
||||
Map parameters = new HashMap();
|
||||
parameters.put("struts.enableJSONValidation", "true");
|
||||
request.setParameterMap(parameters);
|
||||
|
||||
|
||||
validationInterceptor.intercept(invocation);
|
||||
interceptor.intercept(invocation);
|
||||
|
||||
@@ -69,11 +69,11 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
|
||||
//json
|
||||
assertThat(normalizedActual)
|
||||
.contains("\"errors\":[\"Generalerror\"]")
|
||||
.contains("\"fieldErrors\":{")
|
||||
.contains("\"value\":[\"Minvalueis-1\"]")
|
||||
.contains("\"text\":[\"Tooshort\",\"Thisisnoemail\"]")
|
||||
.contains("\"password\":[\"Passwordisn'tcorrect\"]");
|
||||
.contains("\"errors\":[\"Generalerror\"]")
|
||||
.contains("\"fieldErrors\":{")
|
||||
.contains("\"value\":[\"Minvalueis-1\"]")
|
||||
.contains("\"text\":[\"Tooshort\",\"Thisisnoemail\"]")
|
||||
.contains("\"password\":[\"Passwordisn'tcorrect\"]");
|
||||
|
||||
//execution
|
||||
assertFalse(action.isExecuted());
|
||||
@@ -89,7 +89,7 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
action.setText("abcd@ggg.com");
|
||||
action.setPassword("apassword");
|
||||
action.setValue(10);
|
||||
|
||||
|
||||
Map parameters = new HashMap();
|
||||
parameters.put("struts.enableJSONValidation", "true");
|
||||
request.setParameterMap(parameters);
|
||||
@@ -102,7 +102,7 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
String normalizedActual = TestUtils.normalize(json, true);
|
||||
assertEquals("", normalizedActual);
|
||||
}
|
||||
|
||||
|
||||
public void testValidationSucceedsValidateOnly() throws Exception {
|
||||
JSONValidationInterceptor interceptor = new JSONValidationInterceptor();
|
||||
|
||||
@@ -115,7 +115,7 @@ public class JSONValidationInterceptorTest extends StrutsTestCase {
|
||||
parameters.put("struts.validateOnly", "true");
|
||||
parameters.put("struts.enableJSONValidation", "true");
|
||||
request.setParameterMap(parameters);
|
||||
|
||||
|
||||
validationInterceptor.intercept(invocation);
|
||||
interceptor.intercept(invocation);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user