xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From curc...@apache.org
Subject cvs commit: xml-xalan/test/tests/bugzilla BugzillaNodeInfo.java BugzillaNodeInfo.xml BugzillaNodeInfo.xsl
Date Tue, 12 Feb 2002 18:38:16 GMT
curcuru     02/02/12 10:38:16

  Added:       test/tests/bugzilla BugzillaNodeInfo.java
                        BugzillaNodeInfo.xml BugzillaNodeInfo.xsl
  Log:
  Simple test of NodeInfo extension test; not really a bugzilla
  test but this is the easiest place to automate it
  
  Revision  Changes    Path
  1.1                  xml-xalan/test/tests/bugzilla/BugzillaNodeInfo.java
  
  Index: BugzillaNodeInfo.java
  ===================================================================
  /*
   * Covered by The Apache Software License, Version 1.1
   * See xml-xalan/License
   */
  // Common Qetest / Xalan testing imports
  import org.apache.qetest.Datalet;
  import org.apache.qetest.Logger;
  import org.apache.qetest.TestletImpl;
  import org.apache.qetest.CheckService;
  import org.apache.qetest.xsl.XHTFileCheckService;
  
  import org.apache.xalan.processor.TransformerFactoryImpl;
  import org.apache.xalan.transformer.TransformerImpl;
  import org.apache.xalan.transformer.XalanProperties;
  import javax.xml.transform.*;
  import javax.xml.transform.stream.*;
  
  import java.io.File;
  import java.io.FileReader;
  import java.io.BufferedReader;
  import java.io.IOException;
  
  /**
   * Custom Testlet for testing NodeInfo extension.
   *
   * @author shane_curcuru@us.ibm.com
   */
  public class BugzillaNodeInfo extends TestletImpl
  {
      // Initialize our classname for TestletImpl's main() method - must be updated!
      static { thisClassName = "BugzillaNodeInfo"; }
  
      /**
       * Write Minimal code to reproduce your Bugzilla bug report.
       * Many Bugzilla tests won't bother with a datalet; they'll 
       * just have the data to reproduce the bug encoded by default.
       * @param d (optional) Datalet to use as data point for the test.
       */
      public void execute(Datalet d)
  	{
          // Use logger.logMsg(...) instead of System.out.println(...)
          logger.logMsg(Logger.STATUSMSG, getDescription());
  
          String xslName = "BugzillaNodeInfo.xsl";
          String xmlName = "BugzillaNodeInfo.xml";
          String outputName = "BugzillaNodeInfo.output";
          String goldName = "BugzillaNodeInfo.gold";
          try
          {
              TransformerFactory factory = TransformerFactory.newInstance();
              // Must set on both the factory impl..
              TransformerFactoryImpl factoryImpl = (TransformerFactoryImpl)factory;
              factoryImpl.setAttribute(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
              
              Transformer transformer = factory.newTransformer(new StreamSource(xslName));
              // ..and the transformer impl
              TransformerImpl impl = ((TransformerImpl) transformer);
              impl.setProperty(XalanProperties.SOURCE_LOCATION, Boolean.TRUE);
              transformer.transform(new StreamSource(xmlName), 
                                    new StreamResult(outputName));
          } 
          catch (Throwable t)
          {
              logger.logThrowable(logger.ERRORMSG, t, "Unexpectedly threw");
              logger.checkErr("Unexpectedly threw: " + t.toString());
              return;
          }    
      
          // CheckService fileChecker = new XHTFileCheckService();
          // fileChecker.check(logger,
          //                   new File(outputName), 
          //                   new File(goldName), 
          //                  getDescription());
          // Since the gold data isn't nailed down yet, do a simple validation
          // Just ensure the systemId of the xml file was included somewhere in the file
          checkFileContains(outputName, xmlName, "NodeInfo got partial systemID correct");
  	}
  
  
      /**
       * Checks and reports if a file contains a certain string 
       * (all within one line).
       *
       * @param fName local path/name of file to check
       * @param checkStr String to look for in the file
       * @param comment to log with the check() call
       * @return true if pass, false otherwise
       */
      protected boolean checkFileContains(String fName, String checkStr,
                                          String comment)
      {
          boolean passFail = false;
          File f = new File(fName);
  
          if (!f.exists())
          {
              logger.checkFail("checkFileContains(" + fName
                                 + ") does not exist: " + comment);
              return false;
          }
  
          try
          {
              FileReader fr = new FileReader(f);
              BufferedReader br = new BufferedReader(fr);
  
              for (;;)
              {
                  String inbuf = br.readLine();
                  if (inbuf == null)
                      break;
  
                  if (inbuf.indexOf(checkStr) >= 0)
                  {
                      passFail = true;
                      logger.logMsg(logger.TRACEMSG, 
                          "checkFileContains passes with line: " + inbuf);
                      break;
                  }
              }
          }
          catch (IOException ioe)
          {
              logger.checkFail("checkFileContains(" + fName + ") threw: "
                                 + ioe.toString() + " for: " + comment);
  
              return false;
          }
  
          if (passFail)
          {
              logger.checkPass(comment);
          }
          else
          {
              logger.logMsg(logger.ERRORMSG, "checkFileContains failed to find: " + checkStr);
              logger.checkFail(comment);
          }
          return passFail;
      }
  
  
      /**
       * @return Xalan custom extension NodeInfo.
       */
      public String getDescription()
      {
          return "Xalan custom extension NodeInfo";
      }
  
  }  // end of class BugzillaNodeInfo
  
  
  
  
  1.1                  xml-xalan/test/tests/bugzilla/BugzillaNodeInfo.xml
  
  Index: BugzillaNodeInfo.xml
  ===================================================================
  <?xml version="1.0" encoding="UTF-8"?>
  <doc>
    <!-- NOTE: when editing this file, you may need to update gold line/col values below!
-->
    <elem line="4" col="29" />
    <elem line="5" col="41" multi="true" >
      <subelem line="6" col="34" />
    </elem>
  </doc>
  
  
  1.1                  xml-xalan/test/tests/bugzilla/BugzillaNodeInfo.xsl
  
  Index: BugzillaNodeInfo.xsl
  ===================================================================
  <?xml version="1.0"?>
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
                  xmlns:java="http://xml.apache.org/xslt/java"
                  xmlns:xalan="http://xml.apache.org/xalan"
                  exclude-result-prefixes="java">
  
    <!-- FileName: javaNodeInfo01 -->
    <!-- Document: http://www.w3.org/TR/xslt -->
    <!-- DocVersion: 19991116 -->
    <!-- Section: 14 Extensions -->
    <!-- Purpose: Testing Xalan custom extension "NodeInfo", implemented in lib/NodeInfo.java.
-->
   
    <xsl:strip-space elements="*"/>
    <xsl:output indent="yes"/>
               
  <xsl:template match="/">
    <out>
      <xsl:variable name="rtf">
        <docelem>
          <elem1/>
          <elem2>
            <elem3>content</elem3>
          </elem2>
        </docelem>
      </xsl:variable>
      <global>
        <xsl:element name="lineNumber">
          <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.lineNumber()"/>
        </xsl:element>
        <xsl:element name="columnNumber">
          <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.columnNumber()"/>
        </xsl:element>
        <xsl:element name="systemId">
          <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.systemId()"/>
        </xsl:element>
        <xsl:element name="publicId">
          <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.publicId()"/>
        </xsl:element>
      </global>
      <rtf>
        <xsl:element name="lineNumber">
          <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.lineNumber((xalan:nodeset($rtf)))"/>
        </xsl:element>
        <xsl:element name="columnNumber">
          <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.columnNumber((xalan:nodeset($rtf)))"/>
        </xsl:element>
        <xsl:element name="systemId">
          <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.systemId((xalan:nodeset($rtf)))"/>
        </xsl:element>
        <xsl:element name="publicId">
          <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.publicId((xalan:nodeset($rtf)))"/>
        </xsl:element>
      </rtf>
      <elems>
        <xsl:apply-templates />
      </elems>
    </out>
  </xsl:template>
  <xsl:template match="elem | subelem">
    <elem>
      <xsl:element name="lineNumber">
        <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.lineNumber(.)"/>
      </xsl:element>
      <xsl:element name="columnNumber">
        <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.columnNumber(.)"/>
      </xsl:element>
      <xsl:element name="systemId">
        <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.systemId(.)"/>
      </xsl:element>
      <xsl:element name="publicId">
        <xsl:value-of select="java:org.apache.xalan.lib.NodeInfo.publicId(.)"/>
      </xsl:element>
    </elem>
    <xsl:apply-templates />
  </xsl:template>
    
  </xsl:stylesheet>
  
  
  

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


Mime
View raw message