From f27e78608b0a1fbd4bacf767bd80e6d0911461fc Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Sat, 8 Sep 2018 22:28:02 +0000 Subject: [PATCH] handle test issues when running with old xerces git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1840386 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ooxml/util/TestDocumentHelper.java | 10 ++++++--- .../apache/poi/ooxml/util/TestSAXHelper.java | 21 ++++++++++++------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java b/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java index c8147c2800..febec72b5f 100644 --- a/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java +++ b/src/ooxml/testcases/org/apache/poi/ooxml/util/TestDocumentHelper.java @@ -37,8 +37,12 @@ public class TestDocumentHelper { @Test public void testDocumentBuilderFactory() throws Exception { - assertTrue(DocumentHelper.documentBuilderFactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)); - assertFalse(DocumentHelper.documentBuilderFactory.getFeature(POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR)); - assertFalse(DocumentHelper.documentBuilderFactory.getFeature(POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD)); + try { + assertTrue(DocumentHelper.documentBuilderFactory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)); + assertFalse(DocumentHelper.documentBuilderFactory.getFeature(POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR)); + assertFalse(DocumentHelper.documentBuilderFactory.getFeature(POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD)); + } catch(AbstractMethodError e) { + // ignore exceptions from old parsers that don't support this API (https://bz.apache.org/bugzilla/show_bug.cgi?id=62692) + } } } diff --git a/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java b/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java index 1190c47612..1036a68f01 100644 --- a/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java +++ b/src/ooxml/testcases/org/apache/poi/ooxml/util/TestSAXHelper.java @@ -24,6 +24,7 @@ import javax.xml.XMLConstants; import org.junit.Test; import org.xml.sax.InputSource; +import org.xml.sax.SAXNotRecognizedException; import org.xml.sax.XMLReader; public class TestSAXHelper { @@ -31,14 +32,18 @@ public class TestSAXHelper { public void testXMLReader() throws Exception { XMLReader reader = SAXHelper.newXMLReader(); assertNotSame(reader, SAXHelper.newXMLReader()); - assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)); - assertFalse(reader.getFeature(POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR)); - assertFalse(reader.getFeature(POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD)); - assertEquals(SAXHelper.IGNORING_ENTITY_RESOLVER, reader.getEntityResolver()); - assertNotNull(reader.getProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT)); - assertEquals("1", reader.getProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT)); - assertNotNull(reader.getProperty(POIXMLConstants.PROPERTY_SECURITY_MANAGER)); - + try { + assertTrue(reader.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)); + assertFalse(reader.getFeature(POIXMLConstants.FEATURE_LOAD_DTD_GRAMMAR)); + assertFalse(reader.getFeature(POIXMLConstants.FEATURE_LOAD_EXTERNAL_DTD)); + assertEquals(SAXHelper.IGNORING_ENTITY_RESOLVER, reader.getEntityResolver()); + assertNotNull(reader.getProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT)); + assertEquals("1", reader.getProperty(POIXMLConstants.PROPERTY_ENTITY_EXPANSION_LIMIT)); + assertNotNull(reader.getProperty(POIXMLConstants.PROPERTY_SECURITY_MANAGER)); + } catch(SAXNotRecognizedException e) { + // ignore exceptions from old parsers that don't support these features + // (https://bz.apache.org/bugzilla/show_bug.cgi?id=62692) + } reader.parse(new InputSource(new ByteArrayInputStream("".getBytes("UTF-8")))); } }