< prev index next >

test/javax/xml/jaxp/functional/org/xml/sax/ptests/DefaultHandlerTest.java

Print this page


   1 /*
   2  * Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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 package org.xml.sax.ptests;
  24 






  25 import java.io.BufferedWriter;
  26 import java.io.File;
  27 import java.io.FileWriter;
  28 import java.io.IOException;

  29 import javax.xml.parsers.SAXParser;
  30 import javax.xml.parsers.SAXParserFactory;
  31 import jaxp.library.JAXPFileBaseTest;
  32 import static jaxp.library.JAXPTestUtilities.USER_DIR;
  33 import static jaxp.library.JAXPTestUtilities.compareWithGold;
  34 import static org.testng.Assert.assertTrue;
  35 import org.testng.annotations.Test;
  36 import org.xml.sax.Attributes;
  37 import org.xml.sax.Locator;
  38 import org.xml.sax.SAXException;
  39 import org.xml.sax.SAXParseException;
  40 import org.xml.sax.helpers.DefaultHandler;
  41 import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR;
  42 import static org.xml.sax.ptests.SAXTestConst.XML_DIR;
  43 
  44 /**
  45  * XMLReader parse XML with default handler that transverses XML and
  46  * print all visited node. Test verifies output is same as the golden file.
  47  */
  48 public class DefaultHandlerTest extends JAXPFileBaseTest {

  49     /**
  50      * Test default handler that transverses XML and  print all visited node.
  51      *
  52      * @throws Exception If any errors occur.
  53      */
  54     @Test
  55     public void testDefaultHandler() throws Exception {
  56         String outputFile = USER_DIR + "DefaultHandler.out";
  57         String goldFile = GOLDEN_DIR + "DefaultHandlerGF.out";
  58         String xmlFile = XML_DIR + "namespace1.xml";
  59 
  60         SAXParserFactory spf = SAXParserFactory.newInstance();
  61         spf.setNamespaceAware(true);
  62         SAXParser saxparser = spf.newSAXParser();
  63 
  64         MyDefaultHandler handler = new MyDefaultHandler(outputFile);
  65         File file = new File(xmlFile);
  66         String Absolutepath = file.getAbsolutePath();
  67         String newAbsolutePath = Absolutepath;
  68         if (File.separatorChar == '\\')


   1 /*
   2  * Copyright (c) 2003, 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  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 package org.xml.sax.ptests;
  24 
  25 import static jaxp.library.JAXPTestUtilities.USER_DIR;
  26 import static jaxp.library.JAXPTestUtilities.compareWithGold;
  27 import static org.testng.Assert.assertTrue;
  28 import static org.xml.sax.ptests.SAXTestConst.GOLDEN_DIR;
  29 import static org.xml.sax.ptests.SAXTestConst.XML_DIR;
  30 
  31 import java.io.BufferedWriter;
  32 import java.io.File;
  33 import java.io.FileWriter;
  34 import java.io.IOException;
  35 
  36 import javax.xml.parsers.SAXParser;
  37 import javax.xml.parsers.SAXParserFactory;
  38 
  39 import org.testng.annotations.Listeners;


  40 import org.testng.annotations.Test;
  41 import org.xml.sax.Attributes;
  42 import org.xml.sax.Locator;
  43 import org.xml.sax.SAXException;
  44 import org.xml.sax.SAXParseException;
  45 import org.xml.sax.helpers.DefaultHandler;


  46 
  47 /**
  48  * XMLReader parse XML with default handler that transverses XML and
  49  * print all visited node. Test verifies output is same as the golden file.
  50  */
  51 @Listeners({jaxp.library.FilePolicy.class})
  52 public class DefaultHandlerTest {
  53     /**
  54      * Test default handler that transverses XML and  print all visited node.
  55      *
  56      * @throws Exception If any errors occur.
  57      */
  58     @Test
  59     public void testDefaultHandler() throws Exception {
  60         String outputFile = USER_DIR + "DefaultHandler.out";
  61         String goldFile = GOLDEN_DIR + "DefaultHandlerGF.out";
  62         String xmlFile = XML_DIR + "namespace1.xml";
  63 
  64         SAXParserFactory spf = SAXParserFactory.newInstance();
  65         spf.setNamespaceAware(true);
  66         SAXParser saxparser = spf.newSAXParser();
  67 
  68         MyDefaultHandler handler = new MyDefaultHandler(outputFile);
  69         File file = new File(xmlFile);
  70         String Absolutepath = file.getAbsolutePath();
  71         String newAbsolutePath = Absolutepath;
  72         if (File.separatorChar == '\\')


< prev index next >