diff --git a/JSONMLTest.java b/JSONMLTest.java index 3271584..3629fd4 100644 --- a/JSONMLTest.java +++ b/JSONMLTest.java @@ -15,20 +15,20 @@ public class JSONMLTest { public void nullXMLException() { String xmlStr = null; - JSONML.toJSONObject(xmlStr); + JSONML.toJSONArray(xmlStr); } @Test(expected=JSONException.class) public void emptyXMLException() { String xmlStr = ""; - JSONML.toJSONObject(xmlStr); + JSONML.toJSONArray(xmlStr); } @Test(expected=JSONException.class) public void nonXMLException() { String xmlStr = "{ \"this is\": \"not xml\"}"; - JSONML.toJSONObject(xmlStr); + JSONML.toJSONArray(xmlStr); } @Test(expected=JSONException.class) @@ -42,7 +42,7 @@ public class JSONMLTest { " abc street\n"+ " \n"+ ""; - JSONML.toJSONObject(xmlStr); + JSONML.toJSONArray(xmlStr); } @Test(expected=JSONException.class) @@ -56,7 +56,7 @@ public class JSONMLTest { " \n"+ " \n"+ ""; - JSONML.toJSONObject(xmlStr); + JSONML.toJSONArray(xmlStr); } @Test(expected=JSONException.class) @@ -70,7 +70,7 @@ public class JSONMLTest { " \n"+ ""; - JSONML.toJSONObject(xmlStr); + JSONML.toJSONArray(xmlStr); } @Test(expected=JSONException.class) @@ -84,7 +84,7 @@ public class JSONMLTest { " \n"+ ""; - JSONML.toJSONObject(xmlStr); + JSONML.toJSONArray(xmlStr); } @Test(expected=JSONException.class) @@ -98,23 +98,23 @@ public class JSONMLTest { " \n"+ " \n"+ ""; - JSONML.toJSONObject(xmlStr); + JSONML.toJSONArray(xmlStr); } @Test(expected=NullPointerException.class) public void nullJSONXMLException() { - JSONObject jsonObject= null; - JSONML.toString(jsonObject); + JSONArray jsonArray= null; + JSONML.toString(jsonArray); } @Test(expected=JSONException.class) public void emptyJSONXMLException() { - JSONObject jsonObject= new JSONObject(); - JSONML.toString(jsonObject); + JSONArray jsonArray = new JSONArray(); + JSONML.toString(jsonArray); } @Test - public void noStartTag() { + public void complexTypeXML() { String xmlStr = "\n"+ "\n"+ ""; String expectedStr = - "{\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+ - "\"childNodes\":[{"+ - "\"childNodes\":"+ - "[{\"tagName\":\"name\"},"+ - "{\"tagName\":\"nocontent\"},"+ - "\">\"],"+ - "\"tagName\":\"address\"}],"+ - "\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\","+ - "\"tagName\":\"addresses\"}"; - JSONObject jsonObject = JSONML.toJSONObject(xmlStr); - JSONObject expectedJsonObject = new JSONObject(expectedStr); - Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); + "[\"addresses\","+ + "{\"xsi:noNamespaceSchemaLocation\":\"test.xsd\","+ + "\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\"},"+ + "[\"address\","+ + "[\"name\"],"+ + "[\"nocontent\"],"+ + "\">\""+ + "]"+ + "]"; + JSONArray jsonArray = JSONML.toJSONArray(xmlStr); + JSONArray expectedJsonArray = new JSONArray(expectedStr); + Util.compareActualVsExpectedJsonArrays(jsonArray,expectedJsonArray); } @Test - public void simpleXML() { + public void basicXMLAsObject() { String xmlStr = "\n"+ "-23\n"+ "-23.45\n"+ "-23x.45\n"+ - "1, 2, 3, 4.1, 5.2\n"+ + "\n"+ + "1\n"+ + "2\n"+ + "3\n"+ + "4.1\n"+ + "5.2\n"+ + "\n"+ "\n"+ ""; @@ -183,8 +189,19 @@ public class JSONMLTest { "\"tagName\":\"DoubleValue\"},"+ "{\"childNodes\":[\"-23x.45\"],"+ "\"tagName\":\"Nan\"},"+ - "{\"childNodes\":[\"1, 2, 3, 4.1, 5.2\"],"+ - "\"tagName\":\"ArrayOfNum\"}],"+ + "{\"childNodes\":["+ + "{\"childNodes\":[1],"+ + "\"tagName\":\"value\"},"+ + "{\"childNodes\":[1],"+ + "\"tagName\":\"value\"},"+ + "{\"childNodes\":[1],"+ + "\"tagName\":\"value\"},"+ + "{\"childNodes\":[1],"+ + "\"tagName\":\"value\"},"+ + "{\"childNodes\":[1],"+ + "\"tagName\":\"value\"},"+ + "]," + "\"tagName\":\"address\"}],"+ "\"xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\","+ "\"tagName\":\"addresses\"}"; @@ -193,6 +210,53 @@ public class JSONMLTest { Util.compareActualVsExpectedJsonObjects(jsonObject,expectedJsonObject); } + public void basicXMLAsArray() { + String xmlStr = + "\n"+ + "\n"+ + "
\n"+ + "Joe Tester\n"+ + "[CDATA[Baker street 5]\n"+ + "\n"+ + "true\n"+ + "false\n"+ + "null\n"+ + "42\n"+ + "-23\n"+ + "-23.45\n"+ + "-23x.45\n"+ + "\n"+ + "1\n"+ + "2\n"+ + "3\n"+ + "4.1\n"+ + "5.2\n"+ + "\n"+ + "
\n"+ + "
"; + + 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 public void commentsInXML() {