curcuru     00/11/09 17:57:32

  Modified:    test/java/src/org/apache/qetest/trax TemplatesAPITest.java
  Log:
  Update to new javax.xml.transform API
  
  Revision  Changes    Path
  1.2       +58 -137   
xml-xalan/test/java/src/org/apache/qetest/trax/TemplatesAPITest.java
  
  Index: TemplatesAPITest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/trax/TemplatesAPITest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TemplatesAPITest.java     2000/11/01 23:26:54     1.1
  +++ TemplatesAPITest.java     2000/11/10 01:57:32     1.2
  @@ -65,15 +65,10 @@
   import org.apache.qetest.*;
   import org.apache.qetest.xsl.*;
   
  -// Just import the whole trax package; note the packaging is likely to change
  -import org.apache.trax.*;
  +// Import all relevant TRAX packages
  +import javax.xml.transform.*;
  +import javax.xml.transform.stream.*;    // We assume Features.STREAM for 
some tests
   
  -// Use Serializer classes from Xalan distro
  -import org.apache.serialize.Method;
  -import org.apache.serialize.OutputFormat;
  -import org.apache.serialize.Serializer;
  -import org.apache.serialize.SerializerFactory;
  -
   // Needed SAX classes
   import org.xml.sax.InputSource;
   import org.xml.sax.SAXException;
  @@ -99,13 +94,12 @@
   import java.io.FileWriter;
   import java.io.IOException;
   import java.io.StringWriter;
  -
   import java.util.Properties;
   
   //-------------------------------------------------------------------------
   
   /**
  - * Basic API coverage test for the Templates and TemplatesBuilder classes of 
TRAX.
  + * Basic API coverage test for the Templates class of TRAX.
    * @author [EMAIL PROTECTED]
    */
   public class TemplatesAPITest extends XSLProcessorTestBase
  @@ -121,14 +115,14 @@
       protected XSLTestfileInfo simpleTest = new XSLTestfileInfo();
   
       /** Name of a stylesheet with xsl:output HTML. */
  -    protected String htmlStylesheet = null;
  +    protected String outputFormatXSL = null;
   
       /** Cache the relevant system property. */
       protected String saveXSLTProp = null;
   
       /** Allow user to override our default of Xalan 2.x processor classname. 
*/
       public static final String XALAN_CLASSNAME =
  -        "org.apache.xalan.processor.StylesheetProcessor";
  +        "org.apache.xalan.processor.TransformerFactoryImpl";
   
       /** NEEDSDOC Field PROCESSOR_CLASSNAME          */
       protected String PROCESSOR_CLASSNAME = "processorClassname";
  @@ -137,40 +131,24 @@
       protected String processorClassname = XALAN_CLASSNAME;
   
       /** NEEDSDOC Field TRAX_PROCESSOR_XSLT          */
  -    public static final String TRAX_PROCESSOR_XSLT = "trax.processor.xslt";
  +    public static final String TRAX_PROCESSOR_XSLT = 
"javax.xml.transform.TransformerFactory";
   
  -    /** NEEDSDOC Field XSLT          */
  -    public static final String XSLT = "xslt";
  +    /** Known outputFormat property name from outputFormatTest  */
  +    public static final String OUTPUT_FORMAT_NAME = "cdata-section-elements";
   
  -    // http://xml.org/sax/features/namespace-prefixes feature
  -    // http://xml.org/sax/features/namespaces feature
  -    // http://xml.org/sax/features/external-general-entities property
  -    // http://xml.org/sax/features/external-parameter-entities property
  -    // http://xml.apache.org/xslt/sourcebase property in TransformerImpl
  -
  -    /** NEEDSDOC Field PROPERTY_LEXICAL_HANDLER          */
  -    public static final String PROPERTY_LEXICAL_HANDLER =
  -        "http://xml.org/sax/properties/lexical-handler";;
  -
  -    /** NEEDSDOC Field FEATURE_DOM_INPUT          */
  -    public static final String FEATURE_DOM_INPUT =
  -        "http://xml.org/trax/features/dom/input";;
  -
  -    /** NEEDSDOC Field FEATURE_SAX_INPUT          */
  -    public static final String FEATURE_SAX_INPUT =
  -        "http://xml.org/trax/features/sax/input";;
  +    /** Known outputFormat property value from outputFormatTest  */
  +    public static final String OUTPUT_FORMAT_VALUE = "cdataHere";
   
  -    /** NEEDSDOC Field XAPI          */
  -    public static final String XAPI = "trax";
  +    /** NEEDSDOC Field TRAX_SUBDIR          */
  +    public static final String TRAX_SUBDIR = "trax";
   
       /** Default ctor initializes test name, comment, numTestCases. */
       public TemplatesAPITest()
       {
   
  -        numTestCases = 2;  // REPLACE_num
  +        numTestCases = 1;  // REPLACE_num
           testName = "TemplatesAPITest";
  -        testComment =
  -            "Basic API coverage test for the Templates and TemplatesBuilder 
classes of TRAX";
  +        testComment = "Basic API coverage test for the Templates class of 
TRAX";
       }
   
       /**
  @@ -184,26 +162,25 @@
       {
   
           // Used for all tests; just dump files in xapi subdir
  -        File outSubDir = new File(outputDir + File.separator + XAPI);
  +        File outSubDir = new File(outputDir + File.separator + TRAX_SUBDIR);
   
           if (!outSubDir.mkdirs())
               reporter.logWarningMsg("Could not create output dir: "
                                      + outSubDir);
   
  -        outNames = new OutputNameManager(outputDir + File.separator + XAPI
  +        outNames = new OutputNameManager(outputDir + File.separator + 
TRAX_SUBDIR
                                            + File.separator + testName, 
".out");
   
           // Used for API coverage and exampleSimple
  -        String testBasePath = inputDir + File.separator + XAPI
  +        String testBasePath = inputDir + File.separator + TRAX_SUBDIR
                                 + File.separator;
  -        String goldBasePath = goldDir + File.separator + XAPI
  +        String goldBasePath = goldDir + File.separator + TRAX_SUBDIR
                                 + File.separator;
   
  -        simpleTest.xmlName = testBasePath + "APIMinitest.xml";
  -        simpleTest.inputName = testBasePath + "APIMinitest.xsl";
  -        simpleTest.goldName = goldBasePath + "APIMinitest.out";
  -        htmlStylesheet = inputDir + File.separator + XAPI + File.separator
  -                         + "TemplatesAPIHTML.xsl";
  +        simpleTest.xmlName = testBasePath + "TransformerAPIParam.xml";
  +        simpleTest.inputName = testBasePath + "TransformerAPIParam.xsl";
  +        simpleTest.goldName = goldBasePath + "TransformerAPIParam.out";
  +        outputFormatXSL = testBasePath + "TransformerAPIOutputFormat.xsl";
   
           // Cache trax system property
           saveXSLTProp = System.getProperty(TRAX_PROCESSOR_XSLT);
  @@ -215,17 +192,14 @@
           processorClassname = testProps.getProperty(PROCESSOR_CLASSNAME,
                                                      XALAN_CLASSNAME);
   
  +        // @todo fix: user should be able to specify -processorClassname 
  +        //  on the command line to override the system properties
  +
           reporter.logInfoMsg(PROCESSOR_CLASSNAME + " property is: "
                               + processorClassname);
           reporter.logInfoMsg(TRAX_PROCESSOR_XSLT + " property is: "
                               + System.getProperty(TRAX_PROCESSOR_XSLT));
   
  -        // Just call this static method once for the whole test
  -        // TODO will this ever affect other tests run through a harness?
  -        Processor.setPlatformDefaultProcessor(processorClassname);
  -        reporter.logTraceMsg(
  -            "Processor.setPlatformDefaultProcessor(processorClassname)");
  -
           return true;
       }
   
  @@ -252,20 +226,19 @@
       }
   
       /**
  -     * TRAX Templates: cover APIs and functionality.
  +     * TRAX Templates: cover newTransformer(), 
  +     * getOutputProperties() APIs and basic functionality.
        *
        * NEEDSDOC ($objectName$) @return
        */
       public boolean testCase1()
       {
  -
  -        reporter.testCaseInit("TRAX Templates: cover APIs and 
functionality");
  -
  -        Processor p = null;
  +        reporter.testCaseInit("TRAX Templates: cover APIs and basic 
functionality");
   
  +        TransformerFactory factory = null;
           try
           {
  -            p = Processor.newInstance(XSLT);
  +            factory = TransformerFactory.newInstance();
           }
           catch (Exception e)
           {
  @@ -273,47 +246,53 @@
                   "Problem creating Processor; cannot continue testcase");
               reporter.logThrowable(reporter.ERRORMSG, e,
                                     "Problem creating Processor");
  -
               return true;
           }
   
           try
           {
  -
  -            // Cover APIs newTransformer(), getOutputFormat()
  +            // Cover APIs newTransformer(), getOutputProperties()
               Templates templates =
  -                p.process(new InputSource(simpleTest.inputName));
  +                factory.newTemplates(new StreamSource(simpleTest.inputName));
               Transformer transformer = templates.newTransformer();
   
               reporter.check((transformer != null), true,
                              "newTransformer() is non-null for "
                              + simpleTest.inputName);
   
  -            OutputFormat outputFormat = templates.getOutputFormat();
  +            Properties outputFormat = templates.getOutputProperties();
   
               reporter.check((outputFormat != null), true,
  -                           "getOutputFormat() is non-null for "
  -                           + simpleTest.inputName);
  -            reporter.check(outputFormat.getMethod(), Method.XML,
  -                           "outputFormat.getMethod() is xml for "
  +                           "getOutputProperties() is non-null for "
                              + simpleTest.inputName);
  +            reporter.logHashtable(reporter.STATUSMSG, outputFormat,
  +                                  "getOutputProperties for " + 
simpleTest.inputName);
           }
           catch (Exception e)
           {
  -            reporter.checkErr("newTransformer/getOutputFormat threw: "
  +            reporter.checkErr("newTransformer/getOutputProperties threw: "
                                 + e.toString());
               reporter.logThrowable(reporter.STATUSMSG, e,
  -                                  "newTransformer/getOutputFormat threw:");
  +                                  "newTransformer/getOutputProperties 
threw:");
           }
   
           try
           {
  -            Templates templatesHTML =
  -                p.process(new InputSource(htmlStylesheet));
  -            OutputFormat outputFormatHTML = templatesHTML.getOutputFormat();
  -
  -            reporter.check(outputFormatHTML.getMethod(), Method.HTML,
  -                           "outputFormat() is html for " + htmlStylesheet);
  +            Templates templates2 =
  +                factory.newTemplates(new StreamSource(outputFormatXSL));
  +            Properties outputFormat2 = templates2.getOutputProperties();
  +
  +            reporter.check((outputFormat2 != null), true,
  +                           "getOutputProperties() is non-null for "
  +                           + outputFormatXSL);
  +            reporter.logHashtable(reporter.STATUSMSG, outputFormat2,
  +                                  "getOutputProperties for " + 
outputFormatXSL);
  +
  +            String tmp = outputFormat2.getProperty(OUTPUT_FORMAT_NAME);
  +            reporter.check(tmp, OUTPUT_FORMAT_VALUE, "outputProperty " + 
OUTPUT_FORMAT_NAME + " has known value ?" + tmp + "?");
  +            // HACK: check for another value instead; should 
cdata-section-elements come back?
  +            tmp = outputFormat2.getProperty("omit-xml-declaration");
  +            reporter.check(tmp, "yes", "outputProperty omit-xml-declaration 
has known value ?" + tmp + "?");
           }
           catch (Exception e)
           {
  @@ -322,71 +301,13 @@
               reporter.logThrowable(reporter.STATUSMSG, e,
                                     "outputFormat() is html... threw:");
           }
  -
  +        reporter.logTraceMsg("Functionality of Transformers covered in 
TransformerAPITest, elsewhere");
           reporter.testCaseClose();
   
           return true;
       }
   
  -    /**
  -     * TRAX TemplatesBuilder: cover APIs and functionality.
  -     *
  -     * NEEDSDOC ($objectName$) @return
  -     */
  -    public boolean testCase2()
  -    {
  -
  -        reporter.testCaseInit(
  -            "TRAX TemplatesBuilder: cover APIs and functionality");
  -
  -        try
  -        {
  -            Processor p = Processor.newInstance(XSLT);
  -            TemplatesBuilder templatesBuilder = p.getTemplatesBuilder();
  -
  -            reporter.check((templatesBuilder != null), true,
  -                           "getTemplatesBuilder() is non-null");
   
  -            XMLReader reader = XMLReaderFactory.createXMLReader();
  -
  -            reader.setContentHandler(templatesBuilder);
  -
  -            if (templatesBuilder instanceof org.xml.sax.ext.LexicalHandler)
  -            {
  -                reader.setProperty(PROPERTY_LEXICAL_HANDLER,
  -                                   templatesBuilder);
  -            }
  -
  -            reader.parse(new InputSource(htmlStylesheet));
  -
  -            Templates templates = templatesBuilder.getTemplates();
  -
  -            reporter.check((templates != null), true,
  -                           "templates from SAX build is non-null");
  -
  -            // Cheap-o verification it's the right stylesheet
  -            OutputFormat outputFormatHTML = templates.getOutputFormat();
  -
  -            reporter.check(outputFormatHTML.getMethod(), Method.HTML,
  -                           "outputFormat() is html for " + htmlStylesheet);
  -            reporter.checkAmbiguous(
  -                "//TODO create stylesheet both ways (t=process() and via SAX 
build) and compare outputs");
  -            reporter.checkAmbiguous(
  -                "//TODO setBaseID() and then create different stylesheet");
  -        }
  -        catch (Exception e)
  -        {
  -            reporter.checkFail("TestCase threw: " + e.toString());
  -            reporter.logThrowable(reporter.ERRORMSG, e, "TestCase threw:");
  -
  -            return true;
  -        }
  -
  -        reporter.testCaseClose();
  -
  -        return true;
  -    }
  -
       /**
        * Convenience method to print out usage information - update if needed. 
 
        *
  @@ -396,15 +317,15 @@
       {
   
           return ("Common [optional] options supported by TemplatesAPITest:\n"
  -                + "(Note: assumes inputDir=.\\prod)\n"
  +                + "(Note: assumes inputDir=.\\tests\\api)\n"
                   + "-processorClassname classname.of.processor  (to override 
setPlatformDefaultProcessor to Xalan 2.x)\n"
                   + super.usage());
       }
   
  +
       /**
        * Main method to run test from the command line - can be left alone.  
  -     *
  -     * NEEDSDOC @param args
  +     * @param args command line argument array
        */
       public static void main(String[] args)
       {
  
  
  

Reply via email to