8166398: CatalogSupport tests need to be fixed
authorjoehw
Thu, 22 Sep 2016 10:17:19 -0700
changeset 41148 16dbd72eac41
parent 41035 9cb87c88ed85
child 41149 7223a315fd01
8166398: CatalogSupport tests need to be fixed Reviewed-by: dfuchs
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java
jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java
jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.java
jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.xml
jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java
jaxp/test/javax/xml/jaxp/unittest/catalog/XI_simple4Catalog.xml
jaxp/test/javax/xml/jaxp/unittest/catalog/XI_test2Catalog.xml
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java	Wed Jul 05 22:14:30 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/impl/XMLEntityManager.java	Thu Sep 22 10:17:19 2016 -0700
@@ -1033,12 +1033,12 @@
             staxInputSource = new StaxXMLInputSource(xmlInputSource, fISCreatedByResolver);
         }
 
-        if (staxInputSource == null) {
+        if (staxInputSource == null && fUseCatalog) {
             if (fCatalogFeatures == null) {
                 fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
             }
             fCatalogFile = fCatalogFeatures.get(Feature.FILES);
-            if (fUseCatalog && fCatalogFile != null) {
+            if (fCatalogFile != null) {
                 try {
                     if (fCatalogResolver == null) {
                         fCatalogResolver = CatalogManager.catalogResolver(fCatalogFeatures);
@@ -1133,12 +1133,12 @@
             xmlInputSource = fEntityResolver.resolveEntity(resourceIdentifier);
         }
 
-        if (xmlInputSource == null) {
+        if (xmlInputSource == null && fUseCatalog) {
             if (fCatalogFeatures == null) {
                 fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
             }
             fCatalogFile = fCatalogFeatures.get(Feature.FILES);
-            if (fUseCatalog && fCatalogFile != null) {
+            if (fCatalogFile != null) {
                 /*
                  since the method can be called from various processors, both
                  EntityResolver and URIResolver are used to attempt to find
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java	Wed Jul 05 22:14:30 2017 +0200
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/xerces/internal/xinclude/XIncludeHandler.java	Thu Sep 22 10:17:19 2016 -0700
@@ -34,6 +34,8 @@
 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter;
 import com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException;
 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter;
+import com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration;
+import com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration;
 import com.sun.org.apache.xerces.internal.util.AugmentationsImpl;
 import com.sun.org.apache.xerces.internal.util.HTTPInputSource;
 import com.sun.org.apache.xerces.internal.util.IntStack;
@@ -129,8 +131,6 @@
 public class XIncludeHandler
     implements XMLComponent, XMLDocumentFilter, XMLDTDFilter {
 
-    public final static String XINCLUDE_DEFAULT_CONFIGURATION =
-        "com.sun.org.apache.xerces.internal.parsers.XIncludeParserConfiguration";
     public final static String HTTP_ACCEPT = "Accept";
     public final static String HTTP_ACCEPT_LANGUAGE = "Accept-Language";
     public final static String XPOINTER = "xpointer";
@@ -1624,12 +1624,12 @@
                 includedSource =
                     fEntityResolver.resolveEntity(resourceIdentifier);
 
-                if (includedSource == null) {
+                if (includedSource == null && fUseCatalog) {
                     if (fCatalogFeatures == null) {
                         fCatalogFeatures = JdkXmlUtils.getCatalogFeatures(fDefer, fCatalogFile, fPrefer, fResolve);
                     }
                     fCatalogFile = fCatalogFeatures.get(CatalogFeatures.Feature.FILES);
-                    if (fUseCatalog && fCatalogFile != null) {
+                    if (fCatalogFile != null) {
                         /*
                            Although URI entry is preferred for resolving XInclude, system entry
                            is allowed as well.
@@ -1690,14 +1690,11 @@
             if ((xpointer != null && fXPointerChildConfig == null)
                         || (xpointer == null && fXIncludeChildConfig == null) ) {
 
-                String parserName = XINCLUDE_DEFAULT_CONFIGURATION;
-                if (xpointer != null)
-                        parserName = "com.sun.org.apache.xerces.internal.parsers.XPointerParserConfiguration";
-
-                fChildConfig =
-                    (XMLParserConfiguration)ObjectFactory.newInstance(
-                        parserName,
-                        true);
+                if (xpointer == null) {
+                    fChildConfig = new XIncludeParserConfiguration();
+                } else {
+                    fChildConfig = new XPointerParserConfiguration();
+                }
 
                 // use the same symbol table, error reporter, entity resolver, security manager and buffer size.
                 if (fSymbolTable != null) fChildConfig.setProperty(SYMBOL_TABLE, fSymbolTable);
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.java	Wed Jul 05 22:14:30 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.java	Thu Sep 22 10:17:19 2016 -0700
@@ -32,7 +32,6 @@
 import javax.xml.transform.sax.SAXSource;
 import javax.xml.transform.stax.StAXSource;
 import javax.xml.transform.stream.StreamSource;
-
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Listeners;
@@ -42,7 +41,7 @@
 
 /**
  * @test
- * @bug 8158084 8162438 8162442 8166220
+ * @bug 8158084 8162438 8162442 8166220 8166398
  * @library /javax/xml/jaxp/libs /javax/xml/jaxp/unittest
  * @run testng/othervm -DrunSecMngr=true catalog.CatalogSupport
  * @run testng/othervm catalog.CatalogSupport
@@ -51,7 +50,7 @@
  * A custom resolver is used whether or not there's a Catalog;
  * A Catalog is used when there's no custom resolver, and the USE_CATALOG
  * is true (which is the case by default).
- */
+*/
 
 /**
  * Support Catalog:
@@ -177,13 +176,13 @@
      */
     @DataProvider(name = "data_SAXA")
     public Object[][] getDataSAX() {
-        String[] systemIds = {"system.xsd"};
-        InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))};
-        MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem);
+        String[] systemIds = {"system.dtd"};
         return new Object[][]{
             {false, true, xml_catalog, xml_system, new MyHandler(elementInSystem), expectedWCatalog},
-            {false, true, xml_catalog, xml_system, entityHandler, expectedWResolver},
-            {true, true, xml_catalog, xml_system, entityHandler, expectedWResolver}
+            {false, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds,
+                    new InputSource(new StringReader(dtd_systemResolved))), expectedWResolver},
+            {true, true, xml_catalog, xml_system, getMyEntityHandler(elementInSystem, systemIds,
+                    new InputSource(new StringReader(dtd_systemResolved))), expectedWResolver}
         };
     }
 
@@ -209,7 +208,7 @@
      */
     @DataProvider(name = "data_DOMA")
     public Object[][] getDataDOM() {
-        String[] systemIds = {"system.xsd"};
+        String[] systemIds = {"system.dtd"};
         InputSource[] returnValues = {new InputSource(new StringReader(dtd_systemResolved))};
         MyEntityHandler entityHandler = new MyEntityHandler(systemIds, returnValues, elementInSystem);
         return new Object[][]{
@@ -230,8 +229,8 @@
 
         return new Object[][]{
             {false, true, xml_catalog, xml_system, null, expectedWCatalog},
-            {false, true, xml_catalog, xml_system, null, expectedWResolver},
-            {true, true, xml_catalog, xml_system, null, expectedWResolver}
+            {false, true, xml_catalog, xml_system, new MyStaxEntityResolver(), expectedWResolver},
+            {true, true, xml_catalog, xml_system, new MyStaxEntityResolver(), expectedWResolver}
         };
     }
 
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.xml	Wed Jul 05 22:14:30 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupport.xml	Thu Sep 22 10:17:19 2016 -0700
@@ -15,6 +15,7 @@
     <system systemId="XI_utf8.xml" uri="XI_utf8.xml"/>
     <system systemId="XI_utf8Catalog.xml" uri="XI_utf8Catalog.xml"/>
     <system systemId="XI_test2.xml" uri="XI_test2.xml"/>
+    <system systemId="XI_test2Catalog.xml" uri="XI_test2Catalog.xml"/>
     <system systemId="XI_red.dtd" uri="XI_red.dtd"/>
 
     <!-- xsd import can be mapped using the namespace or systemId -->
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java	Wed Jul 05 22:14:30 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/CatalogSupportBase.java	Thu Sep 22 10:17:19 2016 -0700
@@ -276,7 +276,7 @@
         SAXParser parser = getSAXParser(setUseCatalog, useCatalog, catalog);
 
         parser.parse(xml, handler);
-        assertEquals(expected, handler.getResult().trim(), "");
+        Assert.assertEquals(handler.getResult().trim(), expected);
     }
 
     /*
@@ -287,8 +287,9 @@
         XMLReader reader = getXMLReader(setUseCatalog, useCatalog, catalog);
 
         reader.setContentHandler(handler);
+        reader.setEntityResolver(handler);
         reader.parse(xml);
-        assertEquals(expected, handler.getResult().trim(), "");
+        Assert.assertEquals(handler.getResult().trim(), expected);
     }
 
     /*
@@ -300,7 +301,7 @@
 
         parser.parse(new InputSource(new StringReader(xml)), handler);
         debugPrint("handler.result:" + handler.getResult());
-        assertEquals(expected, handler.getResult(), "Catalog support for XInclude");
+        Assert.assertEquals(handler.getResult().trim(), expected);
     }
 
     /*
@@ -314,8 +315,7 @@
 
         Node node = doc.getElementsByTagName(elementInSystem).item(0);
         String result = node.getFirstChild().getTextContent();
-
-        assertEquals(expected, result.trim(), "Catalog support for DOM");
+        Assert.assertEquals(result.trim(), expected);
     }
 
     /*
@@ -327,7 +327,7 @@
             XMLStreamReader streamReader = getStreamReader(
                     setUseCatalog, useCatalog, catalog, xml, resolver);
             String text = getText(streamReader, XMLStreamConstants.CHARACTERS);
-            assertEquals(expected, text.trim(), "Catalog support for StAX");
+            Assert.assertEquals(text.trim(), expected);
     }
 
     /*
@@ -340,7 +340,7 @@
             XMLStreamReader streamReader = getStreamReader(
                     setUseCatalog, useCatalog, catalog, xml, resolver);
             String text = getText(streamReader, XMLStreamConstants.ENTITY_REFERENCE);
-            assertEquals(expected, text.trim(), "Catalog support for StAX");
+            Assert.assertEquals(text.trim(), expected);
     }
 
     /*
@@ -601,9 +601,11 @@
     }
 
     /**
-     * Returns the text of the first element found by the reader.
+     * Returns the accumulated text of an event type.
+     *
      * @param streamReader the XMLStreamReader
-     * @return the text of the first element
+     * @param type the type of event requested
+     * @return the text of the accumulated text for the request type
      * @throws XMLStreamException
      */
     String getText(XMLStreamReader streamReader, int type) throws XMLStreamException {
@@ -662,24 +664,6 @@
         return factory;
     }
 
-    void assertNotNull(Object obj, String msg) {
-        if (obj == null) {
-            debugPrint("Test failed: " + msg);
-        } else {
-            debugPrint("Test passed: " + obj + " is not null");
-        }
-    }
-
-    void assertEquals(String expected, String actual, String msg) {
-        if (!expected.equals(actual)) {
-            debugPrint("Test failed: " + msg);
-        } else {
-            debugPrint("Test passed: ");
-        }
-        debugPrint("Expected: " + expected);
-        debugPrint("Actual: " + actual);
-    }
-
     void fail(String msg) {
         System.out.println("Test failed:");
         System.out.println(msg);
--- a/jaxp/test/javax/xml/jaxp/unittest/catalog/XI_simple4Catalog.xml	Wed Jul 05 22:14:30 2017 +0200
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/XI_simple4Catalog.xml	Thu Sep 22 10:17:19 2016 -0700
@@ -9,7 +9,7 @@
     </another>
   </latin1>
   <test2>
-    <xinclude:include href="XI_test2.xml"/>
+    <xinclude:include href="XI_test2Catalog.xml"/>
   </test2>
   <test3>
    <!-- <xinclude:include href="XI_roottest.xml"/> -->
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jaxp/test/javax/xml/jaxp/unittest/catalog/XI_test2Catalog.xml	Thu Sep 22 10:17:19 2016 -0700
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<!-- comment before root -->
+<!DOCTYPE red SYSTEM "XI_red.dtd">
+<red xmlns:xinclude="http://www.w3.org/2001/XInclude">
+  <blue>
+    <xinclude:include href="XI_utf8Catalog.xml" parse="text"/>
+  </blue>
+</red>
+<!-- comment after root -->
+