|
| 1 | +/* |
| 2 | + * Copyright (C) 2014 Evolved Binary Ltd |
| 3 | + * |
| 4 | + * Changes made by Evolved Binary are proprietary and are not Open Source. |
| 5 | + */ |
| 6 | +package org.exist.util.serializer; |
| 7 | + |
| 8 | +import org.apache.commons.io.output.StringBuilderWriter; |
| 9 | +import org.junit.Test; |
| 10 | + |
| 11 | +import javax.xml.transform.OutputKeys; |
| 12 | +import javax.xml.transform.TransformerException; |
| 13 | +import java.io.IOException; |
| 14 | +import java.util.Properties; |
| 15 | + |
| 16 | +import static org.junit.Assert.assertEquals; |
| 17 | + |
| 18 | +public class XMLWriterTest { |
| 19 | + |
| 20 | + @Test |
| 21 | + public void characters() throws IOException, TransformerException { |
| 22 | + final String inputText = "Enter Priest, &c. in procession; the Corpse of OPHELIA, LAERTES and Mourners following; KING CLAUDIUS, QUEEN GERTRUDE, their trains, &c"; |
| 23 | + final String expectedText = inputText.replace("&", "&"); |
| 24 | + |
| 25 | + final Properties outputProperties = new Properties(); |
| 26 | + outputProperties.getProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); |
| 27 | + |
| 28 | + try (final StringBuilderWriter writer = new StringBuilderWriter()) { |
| 29 | + final XMLWriter xmlWriter = new XMLWriter(writer); |
| 30 | + xmlWriter.setOutputProperties(outputProperties); |
| 31 | + |
| 32 | + xmlWriter.characters(inputText); |
| 33 | + |
| 34 | + final String actualText = writer.toString(); |
| 35 | + assertEquals(expectedText, actualText); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void writeChars() throws IOException { |
| 41 | + final String inputText = "Enter Priest, &c. in procession; the Corpse of OPHELIA, LAERTES and Mourners following; KING CLAUDIUS, QUEEN GERTRUDE, their trains, &c"; |
| 42 | + final String expectedText = inputText.replace("&", "&"); |
| 43 | + |
| 44 | + try (final StringBuilderWriter writer = new StringBuilderWriter()) { |
| 45 | + final XMLWriter xmlWriter = new XMLWriter(writer); |
| 46 | + |
| 47 | + xmlWriter.writeChars(inputText, false); |
| 48 | + |
| 49 | + final String actualText = writer.toString(); |
| 50 | + assertEquals(expectedText, actualText); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
0 commit comments