mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
coverage XMLTest 81.2% / XMLTokener 82.2%
This commit is contained in:
parent
a18e9f7a25
commit
89f359e4f8
2 changed files with 225 additions and 59 deletions
74
Util.java
74
Util.java
|
@ -9,12 +9,11 @@ import org.json.*;
|
||||||
public class Util {
|
public class Util {
|
||||||
|
|
||||||
|
|
||||||
/////////////////////////// UTILITY METHODS /////////////////////////
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compares two json arrays for equality
|
* Compares two json arrays for equality
|
||||||
* @param jsonArray created by the code to be tested
|
* @param jsonArray created by the code to be tested
|
||||||
* @param expectedJsonArray created specifically for compar
|
* @param expectedJsonArray created specifically for comparing
|
||||||
*/
|
*/
|
||||||
public static void compareActualVsExpectedJsonArrays(JSONArray jsonArray,
|
public static void compareActualVsExpectedJsonArrays(JSONArray jsonArray,
|
||||||
JSONArray expectedJsonArray) {
|
JSONArray expectedJsonArray) {
|
||||||
|
@ -27,19 +26,17 @@ public class Util {
|
||||||
jsonObject.length() == expectedJsonObject.length());
|
jsonObject.length() == expectedJsonObject.length());
|
||||||
Iterator<String> keys = jsonObject.keys();
|
Iterator<String> keys = jsonObject.keys();
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
// TODO: check for nonstring types
|
|
||||||
String key = keys.next();
|
String key = keys.next();
|
||||||
Object value = jsonObject.get(key);
|
compareJsonObjectEntries(jsonObject, expectedJsonObject, key);
|
||||||
String testStr = "row: "+i+" key: "+key+" val: "+value.toString();
|
|
||||||
String actualStr = expectedJsonObject .get(key).toString();
|
|
||||||
assertTrue("values should be equal for actual: "+testStr+
|
|
||||||
" expected: "+actualStr,
|
|
||||||
value.equals(expectedJsonArray.getJSONObject(i).
|
|
||||||
get(key).toString()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two json objects for equality
|
||||||
|
* @param jsonObject created by the code to be tested
|
||||||
|
* @param expectedJsonObject created specifically for comparing
|
||||||
|
*/
|
||||||
public static void compareActualVsExpectedJsonObjects(
|
public static void compareActualVsExpectedJsonObjects(
|
||||||
JSONObject jsonObject, JSONObject expectedJsonObject) {
|
JSONObject jsonObject, JSONObject expectedJsonObject) {
|
||||||
assertTrue("jsonObjects should have the same length",
|
assertTrue("jsonObjects should have the same length",
|
||||||
|
@ -47,27 +44,42 @@ public class Util {
|
||||||
Iterator<String> keys = jsonObject.keys();
|
Iterator<String> keys = jsonObject.keys();
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
String key = keys.next();
|
String key = keys.next();
|
||||||
Object value = jsonObject.get(key);
|
compareJsonObjectEntries(jsonObject, expectedJsonObject, key);
|
||||||
Object expectedValue = expectedJsonObject.get(key);
|
}
|
||||||
if (value instanceof JSONObject) {
|
}
|
||||||
JSONObject childJsonObject = jsonObject.getJSONObject(key);
|
|
||||||
JSONObject expectedChildJsonObject =
|
/**
|
||||||
expectedJsonObject.getJSONObject(key);
|
* Compare two jsonObject entries
|
||||||
compareActualVsExpectedJsonObjects(
|
* @param jsonObject created by the code to be tested
|
||||||
childJsonObject, expectedChildJsonObject);
|
* @param expectedJsonObject created specifically for comparing
|
||||||
} else if (value instanceof JSONArray) {
|
* @param key key to the jsonObject entry to be compared
|
||||||
JSONArray childJsonArray = jsonObject.getJSONArray(key);
|
*/
|
||||||
JSONArray expectedChildJsonArray =
|
private static void compareJsonObjectEntries(JSONObject jsonObject,
|
||||||
expectedJsonObject.getJSONArray(key);
|
JSONObject expectedJsonObject, String key) {
|
||||||
compareActualVsExpectedJsonArrays(
|
Object value = jsonObject.get(key);
|
||||||
childJsonArray, expectedChildJsonArray);
|
Object expectedValue = expectedJsonObject.get(key);
|
||||||
} else {
|
if (value instanceof JSONObject) {
|
||||||
String testStr = "key: "+key+" val: "+value.toString();
|
JSONObject childJsonObject = jsonObject.getJSONObject(key);
|
||||||
String actualStr = expectedValue.toString();
|
JSONObject expectedChildJsonObject =
|
||||||
assertTrue("string values should be equal for actual: "+
|
expectedJsonObject.getJSONObject(key);
|
||||||
testStr+" expected: "+actualStr,
|
compareActualVsExpectedJsonObjects(
|
||||||
value.equals(expectedValue.toString()));
|
childJsonObject, expectedChildJsonObject);
|
||||||
}
|
} else if (value instanceof JSONArray) {
|
||||||
|
JSONArray childJsonArray = jsonObject.getJSONArray(key);
|
||||||
|
JSONArray expectedChildJsonArray =
|
||||||
|
expectedJsonObject.getJSONArray(key);
|
||||||
|
compareActualVsExpectedJsonArrays(
|
||||||
|
childJsonArray, expectedChildJsonArray);
|
||||||
|
} else if (!(value instanceof String) && !(expectedValue instanceof String)) {
|
||||||
|
assertTrue("string values should be equal for actual: "+
|
||||||
|
value.toString()+" expected: "+expectedValue.toString(),
|
||||||
|
value.toString().equals(expectedValue.toString()));
|
||||||
|
} else {
|
||||||
|
String testStr = "key: "+key+" val: "+value.toString();
|
||||||
|
String actualStr = expectedValue.toString();
|
||||||
|
assertTrue("string values should be equal for actual: "+
|
||||||
|
testStr+" expected: "+actualStr,
|
||||||
|
value.equals(expectedValue.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
210
XMLTest.java
210
XMLTest.java
|
@ -1,7 +1,5 @@
|
||||||
package org.json.junit;
|
package org.json.junit;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.json.*;
|
import org.json.*;
|
||||||
|
@ -22,25 +20,19 @@ public class XMLTest {
|
||||||
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
|
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test
|
||||||
public void shouldHandleNullJSONXML() {
|
public void shouldHandleEmptyXML() {
|
||||||
JSONObject jsonObject= null;
|
|
||||||
String xmlStr = XML.toString(jsonObject);
|
String xmlStr = "";
|
||||||
|
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
||||||
|
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test
|
||||||
public void shouldHandleInvalidBangInTag() {
|
public void shouldHandleNonXML() {
|
||||||
String xmlStr =
|
String xmlStr = "{ \"this is\": \"not xml\"}";
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
|
||||||
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
|
||||||
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
|
||||||
" <address>\n"+
|
|
||||||
" <name>Joe Tester</name>\n"+
|
|
||||||
" <!street>abc street</street>\n"+
|
|
||||||
" </address>\n"+
|
|
||||||
"</addresses>";
|
|
||||||
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
||||||
assertTrue(jsonObject == null);
|
assertTrue("xml string should be empty", jsonObject.length() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
|
@ -54,22 +46,96 @@ public class XMLTest {
|
||||||
" <street>abc street</street>\n"+
|
" <street>abc street</street>\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
XML.toJSONObject(xmlStr);
|
||||||
assertTrue(jsonObject == null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test(expected=JSONException.class)
|
||||||
public void shouldHandleEmptyXML() {
|
public void shouldHandleInvalidBangInTag() {
|
||||||
|
String xmlStr =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
|
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
||||||
|
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
||||||
|
" <address>\n"+
|
||||||
|
" <name/>\n"+
|
||||||
|
" <!>\n"+
|
||||||
|
" </address>\n"+
|
||||||
|
"</addresses>";
|
||||||
|
XML.toJSONObject(xmlStr);
|
||||||
|
}
|
||||||
|
|
||||||
String xmlStr = "";
|
@Test(expected=JSONException.class)
|
||||||
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
public void shouldHandleInvalidBangNoCloseInTag() {
|
||||||
assertTrue("jsonObject should be empty", jsonObject.length() == 0);
|
String xmlStr =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
|
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
||||||
|
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
||||||
|
" <address>\n"+
|
||||||
|
" <name/>\n"+
|
||||||
|
" <!\n"+
|
||||||
|
" </address>\n"+
|
||||||
|
"</addresses>";
|
||||||
|
XML.toJSONObject(xmlStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=JSONException.class)
|
||||||
|
public void shouldHandleNoCloseStartTag() {
|
||||||
|
String xmlStr =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
|
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
||||||
|
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
||||||
|
" <address>\n"+
|
||||||
|
" <name/>\n"+
|
||||||
|
" <abc\n"+
|
||||||
|
" </address>\n"+
|
||||||
|
"</addresses>";
|
||||||
|
XML.toJSONObject(xmlStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=JSONException.class)
|
||||||
|
public void shouldHandleInvalidCDATABangInTag() {
|
||||||
|
String xmlStr =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
|
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
||||||
|
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
||||||
|
" <address>\n"+
|
||||||
|
" <name>Joe Tester</name>\n"+
|
||||||
|
" <![[]>\n"+
|
||||||
|
" </address>\n"+
|
||||||
|
"</addresses>";
|
||||||
|
XML.toJSONObject(xmlStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected=NullPointerException.class)
|
||||||
|
public void shouldHandleNullJSONXML() {
|
||||||
|
JSONObject jsonObject= null;
|
||||||
|
XML.toString(jsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHandleEmptyJSONXML() {
|
public void shouldHandleEmptyJSONXML() {
|
||||||
JSONObject jsonObject= new JSONObject();
|
JSONObject jsonObject= new JSONObject();
|
||||||
String xmlStr = XML.toString(jsonObject);
|
String xmlStr = XML.toString(jsonObject);
|
||||||
|
assertTrue("xml string should be empty", xmlStr.length() == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHandleNoStartTag() {
|
||||||
|
String xmlStr =
|
||||||
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
|
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
||||||
|
" xsi:noNamespaceSchemaLocation='test.xsd'>\n"+
|
||||||
|
" <address>\n"+
|
||||||
|
" <name/>\n"+
|
||||||
|
" <nocontent/>>\n"+
|
||||||
|
" </address>\n"+
|
||||||
|
"</addresses>";
|
||||||
|
String expectedStr =
|
||||||
|
"{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\",\""+
|
||||||
|
"content\":\">\"},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+
|
||||||
|
"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}";
|
||||||
|
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
||||||
|
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
||||||
|
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -82,17 +148,28 @@ public class XMLTest {
|
||||||
" <name>Joe Tester</name>\n"+
|
" <name>Joe Tester</name>\n"+
|
||||||
" <street>[CDATA[Baker street 5]</street>\n"+
|
" <street>[CDATA[Baker street 5]</street>\n"+
|
||||||
" <NothingHere/>\n"+
|
" <NothingHere/>\n"+
|
||||||
|
" <TrueValue>true</TrueValue>\n"+
|
||||||
|
" <FalseValue>false</FalseValue>\n"+
|
||||||
|
" <NullValue>null</NullValue>\n"+
|
||||||
|
" <PositiveValue>42</PositiveValue>\n"+
|
||||||
|
" <NegativeValue>-23</NegativeValue>\n"+
|
||||||
|
" <DoubleValue>-23.45</DoubleValue>\n"+
|
||||||
|
" <Nan>-23x.45</Nan>\n"+
|
||||||
|
" <ArrayOfNum>1, 2, 3, 4.1, 5.2</ArrayOfNum>\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
|
|
||||||
String expectedStr =
|
String expectedStr =
|
||||||
"{\"addresses\":{\"address\":{\"street\":\"[CDATA[Baker street 5]\","+
|
"{\"addresses\":{\"address\":{\"street\":\"[CDATA[Baker street 5]\","+
|
||||||
"\"name\":\"Joe Tester\",\"NothingHere\":\"\"},\"xsi:noNamespaceSchemaLocation\":"+
|
"\"name\":\"Joe Tester\",\"NothingHere\":\"\",TrueValue:true,\n"+
|
||||||
|
"\"FalseValue\":false,\"NullValue\":null,\"PositiveValue\":42,\n"+
|
||||||
|
"\"NegativeValue\":-23,\"DoubleValue\":-23.45,\"Nan\":-23x.45,\n"+
|
||||||
|
"\"ArrayOfNum\":\"1, 2, 3, 4.1, 5.2\"\n"+
|
||||||
|
"},\"xsi:noNamespaceSchemaLocation\":"+
|
||||||
"\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+
|
"\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+
|
||||||
"XMLSchema-instance\"}}";
|
"XMLSchema-instance\"}}";
|
||||||
|
|
||||||
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
||||||
|
|
||||||
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
||||||
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
||||||
}
|
}
|
||||||
|
@ -113,6 +190,11 @@ public class XMLTest {
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
JSONObject jsonObject = XML.toJSONObject(xmlStr);
|
||||||
|
String expectedStr = "{\"addresses\":{\"address\":{\"street\":\"Baker "+
|
||||||
|
"street 5\",\"name\":\"Joe Tester\",\"content\":\" this is -- "+
|
||||||
|
"<another> comment \"}}}";
|
||||||
|
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
||||||
|
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -124,12 +206,15 @@ public class XMLTest {
|
||||||
" <address>\n"+
|
" <address>\n"+
|
||||||
" <name>[CDATA[Joe & T > e < s " t ' er]]</name>\n"+
|
" <name>[CDATA[Joe & T > e < s " t ' er]]</name>\n"+
|
||||||
" <street>Baker street 5</street>\n"+
|
" <street>Baker street 5</street>\n"+
|
||||||
|
" <ArrayOfNum>1, 2, 3, 4.1, 5.2</ArrayOfNum>\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
|
|
||||||
String expectedStr =
|
String expectedStr =
|
||||||
"{\"addresses\":{\"address\":{\"street\":\"Baker street 5\","+
|
"{\"addresses\":{\"address\":{\"street\":\"Baker street 5\","+
|
||||||
"\"name\":\"[CDATA[Joe & T > e < s \\\" t \\\' er]]\"},\"xsi:noNamespaceSchemaLocation\":"+
|
"\"name\":\"[CDATA[Joe & T > e < s \\\" t \\\' er]]\","+
|
||||||
|
"\"ArrayOfNum\":\"1, 2, 3, 4.1, 5.2\"\n"+
|
||||||
|
"},\"xsi:noNamespaceSchemaLocation\":"+
|
||||||
"\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+
|
"\"test.xsd\",\"xmlns:xsi\":\"http://www.w3.org/2001/"+
|
||||||
"XMLSchema-instance\"}}";
|
"XMLSchema-instance\"}}";
|
||||||
|
|
||||||
|
@ -140,4 +225,73 @@ public class XMLTest {
|
||||||
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
||||||
Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject);
|
Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHandleContentNoArraytoString() {
|
||||||
|
String expectedStr =
|
||||||
|
"{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\",\""+
|
||||||
|
"content\":\">\"},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+
|
||||||
|
"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}";
|
||||||
|
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
||||||
|
String finalStr = XML.toString(expectedJsonObject);
|
||||||
|
String expectedFinalStr = "<addresses><address><name/><nocontent/>>"+
|
||||||
|
"</address><xsi:noNamespaceSchemaLocation>test.xsd</xsi:noName"+
|
||||||
|
"spaceSchemaLocation><xmlns:xsi>http://www.w3.org/2001/XMLSche"+
|
||||||
|
"ma-instance</xmlns:xsi></addresses>";
|
||||||
|
assertTrue("Should handle expectedFinal: ["+expectedStr+"] final: ["+
|
||||||
|
finalStr+"]", expectedFinalStr.equals(finalStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHandleContentArraytoString() {
|
||||||
|
String expectedStr =
|
||||||
|
"{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\",\""+
|
||||||
|
"content\":[1, 2, 3]},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+
|
||||||
|
"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}";
|
||||||
|
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
||||||
|
String finalStr = XML.toString(expectedJsonObject);
|
||||||
|
String expectedFinalStr = "<addresses><address><name/><nocontent/>"+
|
||||||
|
"1\n2\n3"+
|
||||||
|
"</address><xsi:noNamespaceSchemaLocation>test.xsd</xsi:noName"+
|
||||||
|
"spaceSchemaLocation><xmlns:xsi>http://www.w3.org/2001/XMLSche"+
|
||||||
|
"ma-instance</xmlns:xsi></addresses>";
|
||||||
|
assertTrue("Should handle expectedFinal: ["+expectedStr+"] final: ["+
|
||||||
|
finalStr+"]", expectedFinalStr.equals(finalStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHandleArraytoString() {
|
||||||
|
String expectedStr =
|
||||||
|
"{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\","+
|
||||||
|
"\"something\":[1, 2, 3]},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+
|
||||||
|
"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}";
|
||||||
|
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
||||||
|
String finalStr = XML.toString(expectedJsonObject);
|
||||||
|
String expectedFinalStr = "<addresses><address><name/><nocontent/>"+
|
||||||
|
"<something>1</something><something>2</something><something>3</something>"+
|
||||||
|
"</address><xsi:noNamespaceSchemaLocation>test.xsd</xsi:noName"+
|
||||||
|
"spaceSchemaLocation><xmlns:xsi>http://www.w3.org/2001/XMLSche"+
|
||||||
|
"ma-instance</xmlns:xsi></addresses>";
|
||||||
|
assertTrue("Should handle expectedFinal: ["+expectedStr+"] final: ["+
|
||||||
|
finalStr+"]", expectedFinalStr.equals(finalStr));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldHandleNestedArraytoString() {
|
||||||
|
String xmlStr =
|
||||||
|
"{\"addresses\":{\"address\":{\"name\":\"\",\"nocontent\":\"\","+
|
||||||
|
"\"outer\":[[1], [2], [3]]},\"xsi:noNamespaceSchemaLocation\":\"test.xsd\",\""+
|
||||||
|
"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"}}";
|
||||||
|
JSONObject jsonObject = new JSONObject(xmlStr);
|
||||||
|
String finalStr = XML.toString(jsonObject);
|
||||||
|
JSONObject finalJsonObject = XML.toJSONObject(finalStr);
|
||||||
|
String expectedStr = "<addresses><address><name/><nocontent/>"+
|
||||||
|
"<outer><array>1</array></outer><outer><array>2</array>"+
|
||||||
|
"</outer><outer><array>3</array></outer>"+
|
||||||
|
"</address><xsi:noNamespaceSchemaLocation>test.xsd</xsi:noName"+
|
||||||
|
"spaceSchemaLocation><xmlns:xsi>http://www.w3.org/2001/XMLSche"+
|
||||||
|
"ma-instance</xmlns:xsi></addresses>";
|
||||||
|
JSONObject expectedJsonObject = XML.toJSONObject(expectedStr);
|
||||||
|
Util.compareActualVsExpectedJsonObjects(finalJsonObject,expectedJsonObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue