Java Code Examples for com.helger.xml.microdom.IMicroDocument#isEqualContent()

The following examples show how to use com.helger.xml.microdom.IMicroDocument#isEqualContent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MicroWriterTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore ("Takes too long and was already tested with JDK 1.8 runtime parser")
public void testSpecialCharactersXML10CDATA ()
{
  final EXMLSerializeVersion eXMLSerializeVersion = EXMLSerializeVersion.XML_10;

  final XMLWriterSettings aSettings = new XMLWriterSettings ().setSerializeVersion (eXMLSerializeVersion);
  for (int i = Character.MIN_VALUE; i <= Character.MAX_VALUE; ++i)
    if (!XMLCharHelper.isInvalidXMLCDATAChar (eXMLSerializeVersion, (char) i))
    {
      final String sText = "abc" + (char) i + "def";
      assertEquals (7, sText.length ());
      final IMicroDocument aDoc = new MicroDocument ();
      aDoc.appendElement ("root").appendCDATA (sText);
      final String sXML = MicroWriter.getNodeAsString (aDoc, aSettings);
      final IMicroDocument aDoc2 = MicroReader.readMicroXML (sXML);
      assertNotNull ("Failed to read with byte " + i + "\n" + sXML, aDoc2);
      assertEquals ("Length for byte " + i, i == 0 ? 6 : 7, aDoc2.getDocumentElement ().getTextContent ().length ());

      // Difference between created "\r" and read "\n"
      if (i != '\r')
        if (!aDoc.isEqualContent (aDoc2))
        {
          final String sXML2 = MicroWriter.getNodeAsString (aDoc2, aSettings);
          fail ("0x" + Integer.toHexString (i) + "\n" + sXML + "\n" + sXML2);
        }
    }
}
 
Example 2
Source File: MicroWriterTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore ("Takes too long and was already tested with JDK 1.8 runtime parser")
public void testSpecialCharactersXML11Text ()
{
  final EXMLSerializeVersion eXMLSerializeVersion = EXMLSerializeVersion.XML_11;

  final XMLWriterSettings aSettings = new XMLWriterSettings ().setSerializeVersion (eXMLSerializeVersion);
  for (int i = Character.MIN_VALUE; i <= Character.MAX_VALUE; ++i)
    if (!XMLCharHelper.isInvalidXMLTextChar (eXMLSerializeVersion, (char) i))
    {
      final String sText = "abc" + (char) i + "def";
      assertEquals (7, sText.length ());
      final IMicroDocument aDoc = new MicroDocument ();
      aDoc.appendElement ("root").appendText (sText);
      final String sXML = MicroWriter.getNodeAsString (aDoc, aSettings);
      final IMicroDocument aDoc2 = MicroReader.readMicroXML (sXML);
      assertNotNull ("Failed to read with byte " + i + "\n" + sXML, aDoc2);
      assertEquals ("Length for byte " + i, i == 0 ? 6 : 7, aDoc2.getDocumentElement ().getTextContent ().length ());

      // Difference between created "0x2028" and read "\n"
      if (i != 0x2028)
        if (!aDoc.isEqualContent (aDoc2))
        {
          final String sXML2 = MicroWriter.getNodeAsString (aDoc2, aSettings);
          fail ("0x" + Integer.toHexString (i) + "\n" + sXML + "\n" + sXML2);
        }
    }
}
 
Example 3
Source File: MicroWriterTest.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore ("Takes too long and was already tested with JDK 1.8 runtime parser")
public void testSpecialCharactersXML11CDATA ()
{
  final EXMLSerializeVersion eXMLSerializeVersion = EXMLSerializeVersion.XML_11;

  final XMLWriterSettings aSettings = new XMLWriterSettings ().setSerializeVersion (eXMLSerializeVersion);
  for (int i = Character.MIN_VALUE; i <= Character.MAX_VALUE; ++i)
    if (!XMLCharHelper.isInvalidXMLCDATAChar (eXMLSerializeVersion, (char) i))
    {
      final String sText = "abc" + (char) i + "def";
      assertEquals (7, sText.length ());
      final IMicroDocument aDoc = new MicroDocument ();
      aDoc.appendElement ("root").appendCDATA (sText);
      final String sXML = MicroWriter.getNodeAsString (aDoc, aSettings);
      final IMicroDocument aDoc2 = MicroReader.readMicroXML (sXML);
      assertNotNull ("Failed to read with byte " + i + "\n" + sXML, aDoc2);
      assertEquals ("Length for byte " + i, i == 0 ? 6 : 7, aDoc2.getDocumentElement ().getTextContent ().length ());

      // Difference between created "\r" and read "\n"
      // Difference between created "0x2028" and read "\n"
      if (i != '\r' && i != 0x2028)
        if (!aDoc.isEqualContent (aDoc2))
        {
          final String sXML2 = MicroWriter.getNodeAsString (aDoc2, aSettings);
          fail ("0x" + Integer.toHexString (i) + "\n" + sXML + "\n" + sXML2);
        }
    }
}