< prev index next >

test/javax/xml/jaxp/unittest/stream/XMLOutputFactoryTest/StreamResultTest.java

Print this page




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package stream.XMLOutputFactoryTest;
  25 
  26 import java.io.ByteArrayOutputStream;
  27 
  28 import javax.xml.stream.XMLEventFactory;
  29 import javax.xml.stream.XMLEventWriter;
  30 import javax.xml.stream.XMLOutputFactory;
  31 import javax.xml.stream.XMLStreamWriter;
  32 import javax.xml.transform.stax.StAXResult;
  33 import javax.xml.transform.stream.StreamResult;
  34 


  35 import org.testng.Assert;

  36 import org.testng.annotations.Test;
  37 
  38 /*
  39  * @summary Test create XMLWriter with variant Result.
  40  */

  41 public class StreamResultTest {
  42 
  43     @Test
  44     public void testStreamResult() {
  45         final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";
  46         try {
  47             XMLOutputFactory ofac = XMLOutputFactory.newInstance();
  48             ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  49             StreamResult sr = new StreamResult(buffer);
  50             XMLStreamWriter writer = ofac.createXMLStreamWriter(sr);
  51             writer.writeStartDocument("1.0");
  52             writer.writeStartElement("root");
  53             writer.writeEndElement();
  54             writer.writeEndDocument();
  55             writer.close();
  56             Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
  57         } catch (Exception e) {
  58             e.printStackTrace();
  59             Assert.fail(e.toString());
  60         }




  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 package stream.XMLOutputFactoryTest;
  25 
  26 import java.io.ByteArrayOutputStream;
  27 
  28 import javax.xml.stream.XMLEventFactory;
  29 import javax.xml.stream.XMLEventWriter;
  30 import javax.xml.stream.XMLOutputFactory;
  31 import javax.xml.stream.XMLStreamWriter;
  32 import javax.xml.transform.stax.StAXResult;
  33 import javax.xml.transform.stream.StreamResult;
  34 
  35 import jaxp.library.JAXPTestUtilities;
  36 
  37 import org.testng.Assert;
  38 import org.testng.annotations.Listeners;
  39 import org.testng.annotations.Test;
  40 
  41 /*
  42  * @summary Test create XMLWriter with variant Result.
  43  */
  44 @Listeners({jaxp.library.BasePolicy.class})
  45 public class StreamResultTest {
  46 
  47     @Test
  48     public void testStreamResult() {
  49         final String EXPECTED_OUTPUT = "<?xml version=\"1.0\"?><root></root>";
  50         try {
  51             XMLOutputFactory ofac = XMLOutputFactory.newInstance();
  52             ByteArrayOutputStream buffer = new ByteArrayOutputStream();
  53             StreamResult sr = new StreamResult(buffer);
  54             XMLStreamWriter writer = ofac.createXMLStreamWriter(sr);
  55             writer.writeStartDocument("1.0");
  56             writer.writeStartElement("root");
  57             writer.writeEndElement();
  58             writer.writeEndDocument();
  59             writer.close();
  60             Assert.assertEquals(buffer.toString(), EXPECTED_OUTPUT);
  61         } catch (Exception e) {
  62             e.printStackTrace();
  63             Assert.fail(e.toString());
  64         }


< prev index next >