< prev index next >

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

Print this page

        

*** 24,43 **** import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; - import java.nio.file.Files; - import java.nio.file.Path; - import java.nio.file.Paths; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; import static jaxp.library.JAXPTestUtilities.compareWithGold; - import static jaxp.library.JAXPTestUtilities.failCleanup; - import static jaxp.library.JAXPTestUtilities.failUnexpected; import static org.testng.Assert.assertTrue; import org.testng.annotations.Test; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; --- 24,40 ---- import java.io.BufferedWriter; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; + import jaxp.library.JAXPFileBaseTest; import static jaxp.library.JAXPTestUtilities.compareWithGold; import static org.testng.Assert.assertTrue; + import static org.testng.Assert.fail; import org.testng.annotations.Test; import org.xml.sax.InputSource; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader;
*** 48,64 **** /** * ErrorHandler unit test. Set a ErrorHandle to XMLReader. Capture fatal error * events in ErrorHandler. */ ! public class EHFatalTest { /** * Error Handler to capture all error events to output file. Verifies the * output file is same as golden file. */ @Test ! public void testEHFatal() { String outputFile = CLASS_DIR + "EHFatal.out"; String goldFile = GOLDEN_DIR + "EHFatalGF.out"; String xmlFile = XML_DIR + "invalid.xml"; try(MyErrorHandler eHandler = new MyErrorHandler(outputFile); --- 45,67 ---- /** * ErrorHandler unit test. Set a ErrorHandle to XMLReader. Capture fatal error * events in ErrorHandler. */ ! public class EHFatalTest extends JAXPFileBaseTest { /** * Error Handler to capture all error events to output file. Verifies the * output file is same as golden file. + * + * @throws IOException if the file exists but is a directory rather than + * a regular file, does not exist but cannot be created, or cannot + * be opened for any other reason. + * @throws ParserConfigurationException if a DocumentBuilder cannot be + * created which satisfies the configuration requested. */ @Test ! public void testEHFatal() throws ParserConfigurationException, IOException { String outputFile = CLASS_DIR + "EHFatal.out"; String goldFile = GOLDEN_DIR + "EHFatalGF.out"; String xmlFile = XML_DIR + "invalid.xml"; try(MyErrorHandler eHandler = new MyErrorHandler(outputFile);
*** 66,94 **** SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setErrorHandler(eHandler); InputSource is = new InputSource(instream); xmlReader.parse(is); ! } catch (IOException | ParserConfigurationException ex) { ! failUnexpected(ex); ! } catch (SAXException ex) { ! System.out.println("This is expected:" + ex); } // Need close the output file before we compare it with golden file. - try { assertTrue(compareWithGold(goldFile, outputFile)); - } catch (IOException ex) { - failUnexpected(ex); - } finally { - try { - Path outputPath = Paths.get(outputFile); - if(Files.exists(outputPath)) - Files.delete(outputPath); - } catch (IOException ex) { - failCleanup(ex, outputFile); - } - } } } /** * A fatal error event handler only capture fatal error event and write event to --- 69,84 ---- SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser(); XMLReader xmlReader = saxParser.getXMLReader(); xmlReader.setErrorHandler(eHandler); InputSource is = new InputSource(instream); xmlReader.parse(is); ! fail("Parse should throw SAXException"); ! } catch (SAXException expected) { ! // This is expected. } // Need close the output file before we compare it with golden file. assertTrue(compareWithGold(goldFile, outputFile)); } } /** * A fatal error event handler only capture fatal error event and write event to
< prev index next >