FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Basic bread

/* * File: TestJSONML.java Author: JSON.org */ package org.json.tests; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONML; import org.json.JSONObject; import org.json.XML; import junit.framework.TestCase; /** * The Class TestJSONML. */ public class TestJSONML extends TestCase { /** The jsonobject. */ private JSONObject jsonobject; /** The jsonarray. */ private JSONArray jsonarray; /** The string. */ private String string; /** * Tests the toJsonArray method using open xml tag. */ public void testToJsonArray_OpenXmlTag() { try { string = "'.", e.getMessage()); } } /** * Tests the toJSONArray method using closing tag with question. */ public void testToJSONArray_ClosingTagWithQuestion() { try { jsonarray = JSONML.toJSONArray(""); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Misshaped close tag at 11 [character 12 line 1]", e.getMessage()); } } /** * Tests the toJSONArray method using meta tag with two dashes. */ public void testToJSONArray_MetaTagWithTwoDashes() { try { jsonarray = JSONML.toJSONArray(""); assertEquals( "[\"abc\",\">\"]", jsonarray.toString()); assertEquals( ">", JSONML.toString(jsonarray)); } catch (JSONException e) { fail(e.getMessage()); } } /** * Tests the toJSONArray method using meta tag with one dash. */ public void testToJSONArray_MetaTagWithOneDash() { try { jsonarray = JSONML.toJSONArray(""); assertEquals( "[\"abc\",\"abc-->\"]", jsonarray.toString()); assertEquals( "abc-->", JSONML.toString(jsonarray)); } catch (JSONException e) { fail(e.getMessage()); } } /** * Tests the toJSONArray method using meta tag with cdata. */ public void testToJSONArray_MetaTagWithCdata() { try { jsonarray = JSONML.toJSONArray("]]>"); assertEquals( "[\"abc\",\"\"]", jsonarray.toString()); assertEquals( "<abc></abc>", JSONML.toString(jsonarray)); } catch (JSONException e) { fail(e.getMessage()); } } /** * Tests the toJSONArray method using meta tag with bad cdata. */ public void testToJSONArray_MetaTagWithBadCdata() { try { jsonarray = JSONML.toJSONArray("?]>"); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Unclosed CDATA at 35 [character 36 line 1]", e.getMessage()); } try { jsonarray = JSONML.toJSONArray("]?>"); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Unclosed CDATA at 35 [character 36 line 1]", e.getMessage()); } try { jsonarray = JSONML.toJSONArray("]]>"); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Expected 'CDATA[' at 12 [character 13 line 1]", e.getMessage()); } } /** * Tests the toJSONArray method using meta tag with cdata only. */ public void testToJSONArray_MetaTagWithCdataOnly() { try { jsonarray = JSONML.toJSONArray("]]>"); assertEquals( "[\"abc\"]", jsonarray.toString()); assertEquals( "", JSONML.toString(jsonarray)); } catch (JSONException e) { fail(e.getMessage()); } } /** * Tests the toJSONArray method using meta tag with broken cdata. */ public void testToJSONArray_MetaTagWithBrokenCdata() { try { jsonarray = JSONML.toJSONArray("]]>"); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Bad XML at 23 [character 24 line 1]", e.getMessage()); } try { jsonarray = JSONML.toJSONArray(""); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Expected 'CDATA[' at 9 [character 10 line 1]", e.getMessage()); } } /** * Tests the toJSONArray method using php tag. */ public void testToJSONArray_PhpTag() { try { jsonarray = JSONML.toJSONArray(""); assertEquals( "[\"abc\"]", jsonarray.toString()); assertEquals( "", JSONML.toString(jsonarray)); } catch (JSONException e) { fail(e.getMessage()); } } /** * Tests the toJSONArray method using misshaped tag. */ public void testToJSONArray_MisshapedTag() { try { jsonarray = JSONML.toJSONArray(""); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Misshaped tag at 7 [character 8 line 1]", e.getMessage()); } } /** * Tests the toJSONObject method using reserved attribute tag name. */ public void testToJSONObject_ReservedAttributeTagName() { try { jsonobject = JSONML.toJSONObject("def"); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Reserved attribute. at 12 [character 13 line 1]", e.getMessage()); } } /** * Tests the toJSONObject method using reserved attribute child node. */ public void testToJSONObject_ReservedAttributeChildNode() { try { jsonobject = JSONML.toJSONObject("def"); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Reserved attribute. at 14 [character 15 line 1]", e.getMessage()); } } /** * Tests the toJSONObject method using no value attribute. */ public void testToJSONObject_NoValueAttribute() { try { jsonobject = JSONML.toJSONObject("def"); assertEquals( "{\"novalue\":\"\",\"tagName\":\"abc\",\"childNodes\":[\"def\"]}", jsonobject.toString()); assertEquals( "def", JSONML.toString(jsonobject)); } catch (JSONException e) { fail(e.getMessage()); } } /** * Tests the toJSONObject method using no value attribute with equals. */ public void testToJSONObject_NoValueAttributeWithEquals() { try { jsonobject = JSONML.toJSONObject("def"); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Missing value at 14 [character 15 line 1]", e.getMessage()); } } /** * Tests the toJSONObject method using empty tag. */ public void testToJSONObject_EmptyTag() { try { jsonobject = JSONML.toJSONObject(""); assertEquals( "{\"tagName\":\"abc\"}", jsonobject.toString()); assertEquals( "", JSONML.toString(jsonobject)); } catch (JSONException e) { fail(e.getMessage()); } } /** * Tests the toJSONArray method using empty tag. */ public void testToJSONArray_EmptyTag() { try { jsonarray = JSONML.toJSONArray(""); assertEquals( "[\"abc\"]", jsonarray.toString()); assertEquals( "", JSONML.toString(jsonarray)); } catch (JSONException e) { fail(e.getMessage()); } } /** * Tests the toJSONObject method using broken empty tag. */ public void testToJSONObject_BrokenEmptyTag() { try { jsonobject = JSONML.toJSONObject(""); fail("Should have thrown exception."); } catch (JSONException e) { assertEquals("Misshaped tag at 11 [character 12 line 1]", e.getMessage()); } } /** * Tests the toJSONObject method using misshaped tag. */ public void testToJSONObject_MisshapedTag() { try { jsonobject = JSONML.toJSONObject("

Back | FazBrowse Home | New Git URL