You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xalan.apache.org by cu...@apache.org on 2001/11/27 16:57:13 UTC

cvs commit: xml-xalan/test/java/src/org/apache/qetest/xalanj2 SmoketestOuttakes.java ProgrammaticDOMTest.java

curcuru     01/11/27 07:57:13

  Modified:    test/java/src/org/apache/qetest/xalanj2
                        SmoketestOuttakes.java ProgrammaticDOMTest.java
  Log:
  Move parts of ProgrammaticDOMTest.testCase2 to SmoketestOuttakes.testCase6
  due to Bugzilla#5133
  
  Revision  Changes    Path
  1.5       +184 -2    xml-xalan/test/java/src/org/apache/qetest/xalanj2/SmoketestOuttakes.java
  
  Index: SmoketestOuttakes.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xalanj2/SmoketestOuttakes.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SmoketestOuttakes.java	2001/11/03 00:35:48	1.4
  +++ SmoketestOuttakes.java	2001/11/27 15:57:13	1.5
  @@ -91,6 +91,9 @@
   import org.xml.sax.ext.DeclHandler;
   
   // Needed DOM classes
  +import org.w3c.dom.Document;
  +import org.w3c.dom.DocumentFragment;
  +import org.w3c.dom.Element;
   import org.w3c.dom.Node;
   
   // java classes
  @@ -118,7 +121,7 @@
    * due to recent changes you have made).
    *
    * @author shane_curcuru@lotus.com
  - * @version $Id: SmoketestOuttakes.java,v 1.4 2001/11/03 00:35:48 curcuru Exp $
  + * @version $Id: SmoketestOuttakes.java,v 1.5 2001/11/27 15:57:13 curcuru Exp $
    */
   public class SmoketestOuttakes extends XSLProcessorTestBase
   {
  @@ -130,7 +133,7 @@
       /** Just initialize test name, comment, numTestCases. */
       public SmoketestOuttakes()
       {
  -        numTestCases = 5;  // REPLACE_num
  +        numTestCases = 6;  // REPLACE_num
           testName = "SmoketestOuttakes";
           testComment = "Individual test points taken out of other automation files";
       }
  @@ -665,6 +668,185 @@
           return true;
       }
   
  +
  +       public static final String xslNamespace = "http://www.w3.org/1999/XSL/Transform";
  +      public static final String nsNamespace = "http://www.w3.org/XML/1998/namespace";
  +    /**
  +     * From ProgrammaticDOMTest.java testCase2 Bugzilla#5133
  +     * Build a stylesheet DOM programmatically and use it.
  +     * 
  +     * @return false if we should abort the test; true otherwise
  +     */
  +    public boolean testCase6()
  +    {
  +        reporter.testCaseInit("Build a stylesheet DOM programmatically and use it");
  +
  +        XSLTestfileInfo testFileInfo = new XSLTestfileInfo();
  +        testFileInfo.inputName = inputDir + File.separator + "trax" + File.separator + "identity.xsl";
  +        testFileInfo.xmlName = inputDir + File.separator + "trax" + File.separator + "identity.xml";
  +        testFileInfo.goldName = goldDir + File.separator + "trax" + File.separator + "identity.out";
  +        try
  +        {
  +            // Startup a factory and docbuilder, create some nodes/DOMs
  +            DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
  +            dfactory.setNamespaceAware(true);
  +            DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
  +
  +            reporter.logTraceMsg("parsing xml file");
  +            Document xmlDoc = docBuilder.parse(new InputSource(testFileInfo.xmlName));
  +            TransformerFactory factory = TransformerFactory.newInstance();
  +            Transformer transformer = null;
  + 
  +            // Programmatically build the XSL file into a Document and transform
  +            Document xslBuiltDoc = docBuilder.newDocument();
  +            appendIdentityDOMXSL(xslBuiltDoc, xslBuiltDoc, true);
  +            // For debugging, write the generated stylesheet out
  +            //  Note this will not textually exactly match the identity.xsl file
  +            reporter.logInfoMsg("Writing out xslBuiltDoc to "+ outNames.nextName());
  +            transformer = factory.newTransformer();
  +            transformer.transform(new DOMSource(xslBuiltDoc), new StreamResult(outNames.currentName()));
  +
  +            reporter.logInfoMsg("About to newTransformer(xslBuiltDoc)");
  +            transformer = factory.newTransformer(new DOMSource(xslBuiltDoc));
  +            reporter.logInfoMsg("About to transform(xmlDoc, StreamResult(" + outNames.nextName() + "))");
  +            transformer.transform(new DOMSource(xmlDoc), new StreamResult(outNames.currentName()));
  +            fileChecker.check(reporter, 
  +                              new File(outNames.currentName()), 
  +                              new File(testFileInfo.goldName), 
  +                              "transform(xslBuiltDoc,...) into " + outNames.currentName());
  +
  +
  +            // Programmatically build the XSL file into a DocFrag and transform
  +            xslBuiltDoc = docBuilder.newDocument();
  +            DocumentFragment xslBuiltDocFrag = xslBuiltDoc.createDocumentFragment();
  +            appendIdentityDOMXSL(xslBuiltDocFrag, xslBuiltDoc, true);
  +            // For debugging, write the generated stylesheet out
  +            reporter.logInfoMsg("Writing out xslBuiltDocFrag to "+ outNames.nextName());
  +            transformer = factory.newTransformer();
  +            transformer.transform(new DOMSource(xslBuiltDocFrag), new StreamResult(outNames.currentName()));
  +
  +            reporter.logCriticalMsg("//@todo Verify that this is even a valid operation!");
  +            reporter.logInfoMsg("About to newTransformer(xslBuiltDocFrag)");
  +            reporter.logCriticalMsg("Bugzilla#5133: will throw NPE");
  +            transformer = factory.newTransformer(new DOMSource(xslBuiltDocFrag));
  +            reporter.logInfoMsg("About to transform(xmlDoc, StreamResult(" + outNames.nextName() + "))");
  +            transformer.transform(new DOMSource(xmlDoc), new StreamResult(outNames.currentName()));
  +            fileChecker.check(reporter, 
  +                              new File(outNames.currentName()), 
  +                              new File(testFileInfo.goldName), 
  +                              "transform(xslBuiltDocFrag,...) into " + outNames.currentName());
  +        }
  +        catch (Throwable t)
  +        {
  +            reporter.checkFail("Problem with various XSL1 elems/documents");
  +            reporter.logThrowable(reporter.ERRORMSG, t, "Problem with various XSL1 elems/documents");
  +        }
  +        try
  +        {
  +            // Startup a factory and docbuilder, create some nodes/DOMs
  +            DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
  +            dfactory.setNamespaceAware(true);
  +            DocumentBuilder docBuilder = dfactory.newDocumentBuilder();
  +
  +            reporter.logTraceMsg("parsing xml file");
  +            Document xmlDoc = docBuilder.parse(new InputSource(testFileInfo.xmlName));
  +            TransformerFactory factory = TransformerFactory.newInstance();
  +            Transformer transformer = null;
  +
  +            // Programmatically build the XSL file into an Element and transform
  +            Document xslBuiltDoc = docBuilder.newDocument();
  +            // Note: Here, we implicitly already have the outer list 
  +            //  element, so ensure the worker method doesn't add again
  +            reporter.logCriticalMsg("Bugzilla#5133: will throw DOM003 exception");
  +            Element xslBuiltElem = xslBuiltDoc.createElementNS(xslNamespace, "xsl:stylesheet");
  +            xslBuiltElem.setAttributeNS(null, "version", "1.0");
  +            xslBuiltElem.setAttributeNS(nsNamespace, "xmlns:xsl", xslNamespace);
  +            appendIdentityDOMXSL(xslBuiltElem, xslBuiltDoc, false);
  +            // For debugging, write the generated stylesheet out
  +            reporter.logInfoMsg("Writing out xslBuiltElem to "+ outNames.nextName());
  +            transformer = factory.newTransformer();
  +            transformer.transform(new DOMSource(xslBuiltElem), new StreamResult(outNames.currentName()));
  +
  +            reporter.logCriticalMsg("//@todo Verify that this is even a valid operation!");
  +            reporter.logInfoMsg("About to newTransformer(xslBuiltElem)");
  +            transformer = factory.newTransformer(new DOMSource(xslBuiltElem));
  +            reporter.logInfoMsg("About to transform(xmlDoc, StreamResult(" + outNames.nextName() + "))");
  +            transformer.transform(new DOMSource(xmlDoc), new StreamResult(outNames.currentName()));
  +            fileChecker.check(reporter, 
  +                              new File(outNames.currentName()), 
  +                              new File(testFileInfo.goldName), 
  +                              "transform(xslBuiltElem,...) into " + outNames.currentName());
  +        }
  +        catch (Throwable t)
  +        {
  +            reporter.checkFail("Problem with various XSL2 elems/documents");
  +            reporter.logThrowable(reporter.ERRORMSG, t, "Problem with various XSL2 elems/documents");
  +        }
  +
  +        reporter.testCaseClose();
  +        return true;
  +    }
  +
  +    /**
  +     * Adds identity.xsl elems to Node passed in.  
  +     * Subject to change; hackish for now
  +     * @author curcuru
  +     * @param n Node to append DOM elems to
  +     * @param factory Document providing createElement, etc. services
  +     * @param useOuterElem if we should append the top-level <stylesheet> elem
  +     */
  +    public void appendIdentityDOMXSL(Node n, Document factory, boolean useOuterElem)
  +    {
  +        try
  +        {
  +            /// <xsl:template match="@*|node()">
  +            Element template = factory.createElementNS(xslNamespace, "xsl:template");
  +            template.setAttributeNS(null, "match", "@*|node()");
  +
  +            /// <xsl:copy>
  +            Element copyElem = factory.createElementNS(xslNamespace, "xsl:copy");
  +
  +            /// <xsl:apply-templates select="@*|node()"/>
  +            Element applyTemplatesElem = factory.createElementNS(xslNamespace, "xsl:apply-templates");
  +            applyTemplatesElem.setAttributeNS(null, "select", "@*|node()");
  +
  +            // Stick it all together with faked-up newlines for readability
  +            copyElem.appendChild(factory.createTextNode("\n    "));
  +            copyElem.appendChild(applyTemplatesElem);
  +            copyElem.appendChild(factory.createTextNode("\n  "));
  +
  +            template.appendChild(factory.createTextNode("\n  "));
  +            template.appendChild(copyElem);
  +            template.appendChild(factory.createTextNode("\n"));
  +
  +
  +            if (useOuterElem)
  +            {
  +                // If asked to, create and append top-level <stylesheet> elem
  +                /// <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  +                Element stylesheetElem = factory.createElementNS(xslNamespace, "xsl:stylesheet");
  +                stylesheetElem.setAttributeNS(null, "version", "1.0");
  +
  +                // Following is not officially needed by the DOM,  but may help 
  +                // less-sophisticated DOM readers downstream
  +                // Removed due to DOM003 Namespace error
  +                // stylesheetElem.setAttributeNS(nsNamespace, "xmlns:xsl", xslNamespace);
  +                stylesheetElem.appendChild(template);
  +                n.appendChild(stylesheetElem);
  +            }
  +            else
  +            {
  +                // Otherwise, just use their Node
  +                n.appendChild(template);
  +            }
  +
  +        }
  +        catch (Exception e)
  +        {
  +            reporter.logErrorMsg("appendIdentityDOMXSL threw: " + e.toString());
  +            reporter.logThrowable(Logger.ERRORMSG, e, "appendIdentityDOMXSL threw");
  +        }
  +    }    
   
       /**
        * Worker method to get an XMLReader.
  
  
  
  1.2       +18 -4     xml-xalan/test/java/src/org/apache/qetest/xalanj2/ProgrammaticDOMTest.java
  
  Index: ProgrammaticDOMTest.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/test/java/src/org/apache/qetest/xalanj2/ProgrammaticDOMTest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ProgrammaticDOMTest.java	2001/06/14 19:43:14	1.1
  +++ ProgrammaticDOMTest.java	2001/11/27 15:57:13	1.2
  @@ -91,7 +91,7 @@
    * Functionality/system/integration tests for DOMSource.
    * Various kinds of DOM elements, documents used.
    * @author shane_curcuru@lotus.com
  - * @version $Id: ProgrammaticDOMTest.java,v 1.1 2001/06/14 19:43:14 curcuru Exp $
  + * @version $Id: ProgrammaticDOMTest.java,v 1.2 2001/11/27 15:57:13 curcuru Exp $
    */
   public class ProgrammaticDOMTest extends XSLProcessorTestBase
   {
  @@ -320,6 +320,13 @@
               transformer.transform(new DOMSource(xslBuiltDocFrag), new StreamResult(outNames.currentName()));
   
               reporter.logCriticalMsg("//@todo Verify that this is even a valid operation!");
  +            reporter.logCriticalMsg("Bugzilla#5133 NPE below MOVED to SmoketestOuttakes.java 27-Nov-01 -sc");
  +/* @todo Bugzilla#5133 NPE below MOVED to SmoketestOuttakes.java 27-Nov-01 -sc
  +// Check that the DOM is actually correct, esp namespace nodes on top level
  +// java.lang.NullPointerException
  +//	at org.apache.xalan.transformer.TransformerImpl.createResultContentHandler(TransformerImpl.java, Compiled Code)
  +
  +
               reporter.logInfoMsg("About to newTransformer(xslBuiltDocFrag)");
               transformer = factory.newTransformer(new DOMSource(xslBuiltDocFrag));
               reporter.logInfoMsg("About to transform(xmlDoc, StreamResult(" + outNames.nextName() + "))");
  @@ -328,12 +335,21 @@
                                 new File(outNames.currentName()), 
                                 new File(testFileInfo.goldName), 
                                 "transform(xslBuiltDocFrag,...) into " + outNames.currentName());
  +** @todo Bugzilla#5133 NPE above MOVED to SmoketestOuttakes.java 27-Nov-01 -sc */
           }
           catch (Throwable t)
           {
               reporter.checkFail("Problem with various XSL1 elems/documents");
               reporter.logThrowable(reporter.ERRORMSG, t, "Problem with various XSL1 elems/documents");
           }
  +
  +/* @todo Bugzilla#5133 DOM003 Namespace error below MOVED to SmoketestOuttakes.java 27-Nov-01 -sc
  +//org.w3c.dom.DOMException: DOM003 Namespace error
  +//	at org.apache.xerces.dom.AttrNSImpl.&lt;init&gt;(AttrNSImpl.java:134)
  +//	at org.apache.xerces.dom.CoreDocumentImpl.createAttributeNS(CoreDocumentImpl.java:1363)
  +//	at org.apache.xerces.dom.ElementImpl.setAttributeNS(ElementImpl.java:596)
  +//	at org.apache.qetest.xalanj2.ProgrammaticDOMTest.testCase2(ProgrammaticDOMTest.java:355)
  +
           try
           {
               // Startup a factory and docbuilder, create some nodes/DOMs
  @@ -374,6 +390,7 @@
               reporter.checkFail("Problem with various XSL2 elems/documents");
               reporter.logThrowable(reporter.ERRORMSG, t, "Problem with various XSL2 elems/documents");
           }
  +** @todo Bugzilla#5133 DOM003 Namespace error above MOVED to SmoketestOuttakes.java 27-Nov-01 -sc */
   
           reporter.testCaseClose();
           return true;
  @@ -507,7 +524,6 @@
       }    
   
   
  -
       /**
        * Convenience method to print out usage information - update if needed.  
        * @return String denoting usage of this test class
  @@ -527,9 +543,7 @@
        */
       public static void main(String[] args)
       {
  -
           ProgrammaticDOMTest app = new ProgrammaticDOMTest();
  -
           app.doMain(args);
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org