mirror of
https://github.com/ethauvin/JSON-java.git
synced 2025-06-17 07:50:52 -07:00
in progress
This commit is contained in:
parent
ef7e0c7d08
commit
9a6215c3be
1 changed files with 93 additions and 29 deletions
122
JSONMLTest.java
122
JSONMLTest.java
|
@ -15,20 +15,20 @@ public class JSONMLTest {
|
||||||
public void nullXMLException() {
|
public void nullXMLException() {
|
||||||
|
|
||||||
String xmlStr = null;
|
String xmlStr = null;
|
||||||
JSONML.toJSONObject(xmlStr);
|
JSONML.toJSONArray(xmlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
public void emptyXMLException() {
|
public void emptyXMLException() {
|
||||||
|
|
||||||
String xmlStr = "";
|
String xmlStr = "";
|
||||||
JSONML.toJSONObject(xmlStr);
|
JSONML.toJSONArray(xmlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
public void nonXMLException() {
|
public void nonXMLException() {
|
||||||
String xmlStr = "{ \"this is\": \"not xml\"}";
|
String xmlStr = "{ \"this is\": \"not xml\"}";
|
||||||
JSONML.toJSONObject(xmlStr);
|
JSONML.toJSONArray(xmlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
|
@ -42,7 +42,7 @@ public class JSONMLTest {
|
||||||
" <street>abc street</street>\n"+
|
" <street>abc street</street>\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
JSONML.toJSONObject(xmlStr);
|
JSONML.toJSONArray(xmlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
|
@ -56,7 +56,7 @@ public class JSONMLTest {
|
||||||
" <!>\n"+
|
" <!>\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
JSONML.toJSONObject(xmlStr);
|
JSONML.toJSONArray(xmlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
|
@ -70,7 +70,7 @@ public class JSONMLTest {
|
||||||
" <!\n"+
|
" <!\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
JSONML.toJSONObject(xmlStr);
|
JSONML.toJSONArray(xmlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
|
@ -84,7 +84,7 @@ public class JSONMLTest {
|
||||||
" <abc\n"+
|
" <abc\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
JSONML.toJSONObject(xmlStr);
|
JSONML.toJSONArray(xmlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
|
@ -98,23 +98,23 @@ public class JSONMLTest {
|
||||||
" <![[]>\n"+
|
" <![[]>\n"+
|
||||||
" </address>\n"+
|
" </address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
JSONML.toJSONObject(xmlStr);
|
JSONML.toJSONArray(xmlStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=NullPointerException.class)
|
@Test(expected=NullPointerException.class)
|
||||||
public void nullJSONXMLException() {
|
public void nullJSONXMLException() {
|
||||||
JSONObject jsonObject= null;
|
JSONArray jsonArray= null;
|
||||||
JSONML.toString(jsonObject);
|
JSONML.toString(jsonArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected=JSONException.class)
|
@Test(expected=JSONException.class)
|
||||||
public void emptyJSONXMLException() {
|
public void emptyJSONXMLException() {
|
||||||
JSONObject jsonObject= new JSONObject();
|
JSONArray jsonArray = new JSONArray();
|
||||||
JSONML.toString(jsonObject);
|
JSONML.toString(jsonArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noStartTag() {
|
public void complexTypeXML() {
|
||||||
String xmlStr =
|
String xmlStr =
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
||||||
|
@ -125,22 +125,22 @@ public class JSONMLTest {
|
||||||
"</address>\n"+
|
"</address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
String expectedStr =
|
String expectedStr =
|
||||||
"{\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+
|
"[\"addresses\","+
|
||||||
"\"childNodes\":[{"+
|
"{\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+
|
||||||
"\"childNodes\":"+
|
"\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"},"+
|
||||||
"[{\"tagName\":\"name\"},"+
|
"[\"address\","+
|
||||||
"{\"tagName\":\"nocontent\"},"+
|
"[\"name\"],"+
|
||||||
"\">\"],"+
|
"[\"nocontent\"],"+
|
||||||
"\"tagName\":\"address\"}],"+
|
"\">\""+
|
||||||
"\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\","+
|
"]"+
|
||||||
"\"tagName\":\"addresses\"}";
|
"]";
|
||||||
JSONObject jsonObject = JSONML.toJSONObject(xmlStr);
|
JSONArray jsonArray = JSONML.toJSONArray(xmlStr);
|
||||||
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
JSONArray expectedJsonArray = new JSONArray(expectedStr);
|
||||||
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
Util.compareActualVsExpectedJsonArrays(jsonArray,expectedJsonArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleXML() {
|
public void basicXMLAsObject() {
|
||||||
String xmlStr =
|
String xmlStr =
|
||||||
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"+
|
||||||
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
"<addresses xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\""+
|
||||||
|
@ -156,7 +156,13 @@ public class JSONMLTest {
|
||||||
"<NegativeValue>-23</NegativeValue>\n"+
|
"<NegativeValue>-23</NegativeValue>\n"+
|
||||||
"<DoubleValue>-23.45</DoubleValue>\n"+
|
"<DoubleValue>-23.45</DoubleValue>\n"+
|
||||||
"<Nan>-23x.45</Nan>\n"+
|
"<Nan>-23x.45</Nan>\n"+
|
||||||
"<ArrayOfNum>1, 2, 3, 4.1, 5.2</ArrayOfNum>\n"+
|
"<ArrayOfNum>\n"+
|
||||||
|
"<value>1</value>\n"+
|
||||||
|
"<value>2</value>\n"+
|
||||||
|
"<value>3</value>\n"+
|
||||||
|
"<value>4.1</value>\n"+
|
||||||
|
"<value>5.2</value>\n"+
|
||||||
|
"</ArrayOfNum>\n"+
|
||||||
"</address>\n"+
|
"</address>\n"+
|
||||||
"</addresses>";
|
"</addresses>";
|
||||||
|
|
||||||
|
@ -183,8 +189,19 @@ public class JSONMLTest {
|
||||||
"\"tagName\":\"DoubleValue\"},"+
|
"\"tagName\":\"DoubleValue\"},"+
|
||||||
"{\"childNodes\":[\"-23x.45\"],"+
|
"{\"childNodes\":[\"-23x.45\"],"+
|
||||||
"\"tagName\":\"Nan\"},"+
|
"\"tagName\":\"Nan\"},"+
|
||||||
"{\"childNodes\":[\"1, 2, 3, 4.1, 5.2\"],"+
|
"{\"childNodes\":["+
|
||||||
"\"tagName\":\"ArrayOfNum\"}],"+
|
"{\"childNodes\":[1],"+
|
||||||
|
"\"tagName\":\"value\"},"+
|
||||||
|
"{\"childNodes\":[1],"+
|
||||||
|
"\"tagName\":\"value\"},"+
|
||||||
|
"{\"childNodes\":[1],"+
|
||||||
|
"\"tagName\":\"value\"},"+
|
||||||
|
"{\"childNodes\":[1],"+
|
||||||
|
"\"tagName\":\"value\"},"+
|
||||||
|
"{\"childNodes\":[1],"+
|
||||||
|
"\"tagName\":\"value\"},"+
|
||||||
|
"],"
|
||||||
|
|
||||||
"\"tagName\":\"address\"}],"+
|
"\"tagName\":\"address\"}],"+
|
||||||
"\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\","+
|
"\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\","+
|
||||||
"\"tagName\":\"addresses\"}";
|
"\"tagName\":\"addresses\"}";
|
||||||
|
@ -193,6 +210,53 @@ public class JSONMLTest {
|
||||||
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void basicXMLAsArray() {
|
||||||
|
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"+
|
||||||
|
"<street>[CDATA[Baker street 5]</street>\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>\n"+
|
||||||
|
"<value>1</value>\n"+
|
||||||
|
"<value>2</value>\n"+
|
||||||
|
"<value>3</value>\n"+
|
||||||
|
"<value>4.1</value>\n"+
|
||||||
|
"<value>5.2</value>\n"+
|
||||||
|
"</ArrayOfNum>\n"+
|
||||||
|
"</address>\n"+
|
||||||
|
"</addresses>";
|
||||||
|
|
||||||
|
String expectedStr =
|
||||||
|
"[\"addresses\","+
|
||||||
|
"{\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+
|
||||||
|
"\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"},"+
|
||||||
|
"[\"address\","+
|
||||||
|
"[\"name\", \"Joe Tester\"]"+
|
||||||
|
"[\"street\", \"[CDATA[Baker street 5]\"]"+
|
||||||
|
"[\"NothingHere\"]"+
|
||||||
|
"[\"TrueValue\", true]"+
|
||||||
|
"[\"FalseValue\", false]"+
|
||||||
|
"[\"NullValue\", null]"+
|
||||||
|
"[\"PositiveValue\", 42]"+
|
||||||
|
"[\"NegativeValue\", -23]"+
|
||||||
|
"[\"DoubleValue\", -23.45]"+
|
||||||
|
"[\"Nan\", \"-23x.45\"]"+
|
||||||
|
"[\"ArrayOfNum\", ]"+
|
||||||
|
JSONObject jsonObject = JSONML.toJSONObject(xmlStr);
|
||||||
|
JSONObject expectedJsonObject = new JSONObject(expectedStr);
|
||||||
|
Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void commentsInXML() {
|
public void commentsInXML() {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue