WW-3638 additional unit test for multi-level array in includeProperties

git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1129864 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Lindal
2011-05-31 19:24:27 +00:00
parent b40ef08d31
commit 0f2a57f94b
5 changed files with 70 additions and 9 deletions
@@ -28,8 +28,10 @@ import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletResponse;
@@ -530,6 +532,47 @@ public class JSONResultTest extends StrutsTestCase {
assertEquals("application/json;charset=ISO-8859-1", response.getContentType());
}
public void testIncludePropertiesWithSetList() throws Exception {
JSONResult result = new JSONResult();
result.setIncludeProperties("^set\\[\\d+\\]\\.list\\[\\d+\\]\\.booleanField");
TestAction action = new TestAction();
stack.push(action);
Set set = new LinkedHashSet();
TestAction a1 = new TestAction();
List list = new ArrayList();
list.add(new Bean());
list.add(new Bean());
list.add(new Bean());
a1.setList(list);
set.add(a1);
TestAction a2 = new TestAction();
list = new ArrayList();
list.add(new Bean());
list.add(new Bean());
a2.setList(list);
set.add(a2);
action.setSet(set);
this.invocation.setAction(action);
result.execute(this.invocation);
String json = response.getContentAsString();
String normalizedActual = TestUtils.normalize(json, true);
String normalizedExpected = TestUtils.normalize(JSONResultTest.class.getResource("json-11.txt"));
assertEquals(normalizedExpected, normalizedActual);
assertEquals("application/json;charset=ISO-8859-1", response.getContentType());
}
@Override
protected void setUp() throws Exception {
super.setUp();
@@ -23,6 +23,7 @@ package org.apache.struts2.json;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.struts2.json.annotations.JSON;
@@ -37,6 +38,7 @@ public class TestAction extends ActionSupport {
private List collection;
private List collection2;
private Map map;
private Set set;
private String foo;
private String result;
private String[] array;
@@ -82,6 +84,14 @@ public class TestAction extends ActionSupport {
this.map = map;
}
public Set getSet() {
return this.set;
}
public void setSet(Set set) {
this.set = set;
}
public String getFoo() {
return this.foo;
}
@@ -0,0 +1,6 @@
{
"set":[
{"list":[{"booleanField":false},{"booleanField":false},{"booleanField":false}]},
{"list":[{"booleanField":false},{"booleanField":false}]}
]
}
@@ -39,5 +39,6 @@
"a": 1,
"c": [1.0, 2.0]
},
"result":null
"result":null,
"set":null
} */
@@ -3,20 +3,20 @@
"bean": null,
"collection": ["b", 1, [10, 12]],
"collection2": [{
"bigDecimal": 111111.111111,
"bigInteger": 111111111111,
"bigDecimal": 111111.111111,
"bigInteger": 111111111111,
"booleanField": true,
"byteField": 0,
"charField": "s",
"doubleField": 10.1,
"enumBean": "One",
"enumField": "ValueA",
"floatField": 1.5,
"floatField": 1.5,
"intField": 10,
"longField": 100,
"objectField": {
"bigDecimal": null,
"bigInteger": null,
"bigDecimal": null,
"bigInteger": null,
"booleanField": false,
"byteField": 0,
"charField": "\u0000",
@@ -28,8 +28,8 @@
"longField":0,
"objectField":null,
"stringField":" "
},
"stringField": "str"
},
"stringField": "str"
}],
"date": "1999-12-31T11:59:59",
"date2": "31\/12\/99",
@@ -39,5 +39,6 @@
"a": 1,
"c": [1.0, 2.0]
},
"result":null
"result":null,
"set":null
}