Skip to content

Commit 3f9b53f

Browse files
author
Zach
committed
longer forcelist tests
1 parent a0f90b7 commit 3f9b53f

1 file changed

Lines changed: 43 additions & 2 deletions

File tree

src/test/java/org/json/junit/XMLConfigurationTest.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -907,11 +907,10 @@ public void testConfig() {
907907
}
908908

909909
/**
910-
* Confirm XMLParserConfiguration functionality
910+
* Test forceList parameter
911911
*/
912912
@Test
913913
public void testSimpleForceList() {
914-
915914
String xmlStr =
916915
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
917916
"<addresses>\n"+
@@ -933,6 +932,48 @@ public void testSimpleForceList() {
933932

934933
Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject);
935934
}
935+
@Test
936+
public void testLongForceList() {
937+
String xmlStr =
938+
"<servers>"+
939+
"<server>"+
940+
"<name>host1</name>"+
941+
"<os>Linux</os>"+
942+
"<interfaces>"+
943+
"<interface>"+
944+
"<name>em0</name>"+
945+
"<ip_address>10.0.0.1</ip_address>"+
946+
"</interface>"+
947+
"</interfaces>"+
948+
"</server>"+
949+
"</servers>";
950+
951+
String expectedStr =
952+
"{"+
953+
"\"servers\": ["+
954+
"{"+
955+
"\"server\": {"+
956+
"\"name\": \"host1\","+
957+
"\"os\": \"Linux\","+
958+
"\"interfaces\": ["+
959+
"{"+
960+
"\"interface\": {"+
961+
"\"name\": \"em0\","+
962+
"\"ip_address\": \"10.0.0.1\""+
963+
"}}]}}]}";
964+
965+
Set<String> forceList = new HashSet<String>();
966+
forceList.add("servers");
967+
forceList.add("interfaces");
968+
969+
XMLParserConfiguration config =
970+
new XMLParserConfiguration()
971+
.withForceList(forceList);
972+
JSONObject jsonObject = XML.toJSONObject(xmlStr, config);
973+
JSONObject expetedJsonObject = new JSONObject(expectedStr);
974+
975+
Util.compareActualVsExpectedJsonObjects(jsonObject, expetedJsonObject);
976+
}
936977

937978

938979
/**

0 commit comments

Comments
 (0)