curcuru     00/11/09 14:17:09

  Modified:    test/java/src/org/apache/qetest/trax TransformerAPITest.java
  Log:
  Update to new javax.xml.transform APIs
  Not fully complete, see @todo 's
  
  Revision  Changes    Path
  1.2       +409 -188  
xml-xalan/test/java/src/org/apache/qetest/trax/TransformerAPITest.java
  
  Index: TransformerAPITest.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/test/java/src/org/apache/qetest/trax/TransformerAPITest.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TransformerAPITest.java   2000/11/01 23:26:54     1.1
  +++ TransformerAPITest.java   2000/11/09 22:17:09     1.2
  @@ -65,18 +65,14 @@
   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;
  -
  -// java classes
  -import java.io.File;
  -import java.io.FileOutputStream;
  -
  -import java.util.Properties;
  +// javax JAXP classes for parser pluggability
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.ParserConfigurationException;
   
   // Needed SAX classes
   import org.xml.sax.InputSource;
  @@ -90,107 +86,119 @@
   import org.w3c.dom.Node;
   import org.w3c.dom.Document;
   
  -// javax JAXP classes for parser pluggability
  -import javax.xml.parsers.DocumentBuilder;
  -import javax.xml.parsers.DocumentBuilderFactory;
  -import javax.xml.parsers.ParserConfigurationException;
  +// java classes
  +import java.io.File;
  +import java.io.FileOutputStream;
  +import java.util.Properties;
   
   //-------------------------------------------------------------------------
   
   /**
    * Basic API coverage test for the Transformer class of TRAX.
  + * This test focuses on coverage testing for the API's, and 
  + * very brief functional testing.  Also see tests in the 
  + * trax\sax, trax\dom, and trax\stream directories for specific 
  + * coverage of Transformer API's in those usage cases.
    * @author [EMAIL PROTECTED]
    */
   public class TransformerAPITest extends XSLProcessorTestBase
   {
   
  -    /**
  -     * Cheap-o filename for various output files.
  -     *
  -     */
  +    /** Cheap-o filename for various output files.  */
       protected OutputNameManager outNames;
   
  -    /** Cheap-o filename set for both API tests and exampleSimple. */
  +    /** Cheap-o filename set for general API tests. */
       protected XSLTestfileInfo simpleTest = new XSLTestfileInfo();
   
  -    /** NEEDSDOC Field paramTest          */
  +    /** TransformerAPIParam.xsl used for set/getParameter related tests  */
       protected XSLTestfileInfo paramTest = new XSLTestfileInfo();
   
  +    /** Parameter names from TransformerAPIParam.xsl  */
  +    public static final String PARAM1S = "param1s";
  +    public static final String PARAM2S = "param2s";
  +    public static final String PARAM3S = "param3s";
  +    public static final String PARAM1N = "param1n";
  +    public static final String PARAM2N = "param2n";
  +    public static final String PARAM3N = "param3n";
  +
  +    /** TransformerAPIOutputFormat.xsl used for set/getOutputFormat related 
tests  */
  +    protected XSLTestfileInfo outputFormatTest = new XSLTestfileInfo();
  +
  +    /** Known outputFormat property name from outputFormatTest  */
  +    public static final String OUTPUT_FORMAT_NAME = "cdata-section-elements";
  +
  +    /** Known outputFormat property value from outputFormatTest  */
  +    public static final String OUTPUT_FORMAT_VALUE = "cdataHere";
  +
       /** 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          */
  +    /** 
  +     * Commandline/properties string to initialize a different 
  +     * TransformerFactory implementation - otherwise we default to 
  +     * Xalan 2.x org.apache.xalan.processor.TransformerFactoryImpl
  +     */
       protected String PROCESSOR_CLASSNAME = "processorClassname";
   
       /** NEEDSDOC Field processorClassname          */
       protected String processorClassname = XALAN_CLASSNAME;
   
       /** NEEDSDOC Field TRAX_PROCESSOR_XSLT          */
  -    public static final String TRAX_PROCESSOR_XSLT = "trax.processor.xslt";
  -
  -    /** NEEDSDOC Field XSLT          */
  -    public static final String XSLT = "xslt";
  -
  -    /** 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";;
  +    public static final String TRAX_PROCESSOR_XSLT = 
"javax.xml.transform.TransformerFactory";
   
  -    /** NEEDSDOC Field FEATURE_SAX_INPUT          */
  -    public static final String FEATURE_SAX_INPUT =
  -        "http://xml.org/trax/features/sax/input";;
  +    /** Subdir name under test\tests\api for files.  */
  +    public static final String TRAX_SUBDIR = "trax";
   
  -    /** NEEDSDOC Field XAPI          */
  -    public static final String XAPI = "trax";
  -
       /** Default ctor initializes test name, comment, numTestCases. */
       public TransformerAPITest()
       {
   
  -        numTestCases = 2;  // REPLACE_num
  +        numTestCases = 3;  // REPLACE_num
           testName = "TransformerAPITest";
  -        testComment = "Basic API coverage test for the class of TRAX";
  +        testComment = "Basic API coverage test for the Transformer class";
       }
   
       /**
        * Initialize this test - Set names of xml/xsl test files, cache system 
property.  
  -     *
  -     * NEEDSDOC @param p
        *
  -     * NEEDSDOC ($objectName$) @return
  +     * @param p Properties to initialize with (may be unused)
  +     * @return false if test should be aborted, true otherwise
        */
       public boolean doTestFileInit(Properties p)
       {
   
  -        // Used for all tests; just dump files in xapi subdir
  -        File outSubDir = new File(outputDir + File.separator + XAPI);
  +        // Used for all tests; just dump files in trax subdir
  +        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
  +        // We assume inputDir=...tests\api, and use the trax subdir
  +        //  also assume inputDir, etc. exist already
  +        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";
  -        paramTest.xmlName = testBasePath + "TraxMinitestParam.xml";
  -        paramTest.inputName = testBasePath + "TraxMinitestParam.xsl";
  -        paramTest.goldName = goldBasePath + "TraxMinitestParam.out";
  +        simpleTest.xmlName = testBasePath + "TransformerAPIParam.xml";
  +        simpleTest.inputName = testBasePath + "TransformerAPIParam.xsl";
  +        simpleTest.goldName = goldBasePath + "TransformerAPIParam.out";
  +
  +        paramTest.xmlName = testBasePath + "TransformerAPIParam.xml";
  +        paramTest.inputName = testBasePath + "TransformerAPIParam.xsl";
  +        paramTest.goldName = goldBasePath + "TransformerAPIParam.out";
  +        
  +        outputFormatTest.xmlName = testBasePath + 
"TransformerAPIOutputFormat.xml";
  +        outputFormatTest.inputName = testBasePath + 
"TransformerAPIOutputFormat.xsl";
  +        outputFormatTest.goldName = goldBasePath + 
"TransformerAPIOutputFormat.out";
   
           // Cache trax system property
           saveXSLTProp = System.getProperty(TRAX_PROCESSOR_XSLT);
  @@ -201,27 +209,39 @@
           // Check if user wants to use a processor other than Xalan 2.x
           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)");
  +        try
  +        {
  +            TransformerFactory tf = TransformerFactory.newInstance();
  +            if (!tf.getFeature(Features.STREAM))
  +            {   // The rest of this test relies on Streams only
  +                reporter.logWarningMsg("Features.STREAM not supported! Some 
tests may be invalid!");
  +            }
  +        }
  +        catch (Exception e)
  +        {
  +            reporter.checkFail(
  +                "Problem creating Templates; cannot continue testcase");
  +            reporter.logThrowable(reporter.ERRORMSG, e,
  +                                  "Problem creating Templates");
  +            return true;
  +        }
   
           return true;
       }
   
       /**
        * Cleanup this test - reset the cached system property 
trax.processor.xslt.  
  -     *
  -     * NEEDSDOC @param p
        *
  -     * NEEDSDOC ($objectName$) @return
  +     * @param p Properties to initialize with (may be unused)
  +     * @return false if test should be aborted, true otherwise
        */
       public boolean doTestFileClose(Properties p)
       {
  @@ -239,207 +259,410 @@
       }
   
       /**
  -     * TRAX Transformer: cover other APIs and functionality.
  -     *
  +     * TRAX Transformer: cover basic get/setParameter(s) APIs.
  +     * See [EMAIL PROTECTED] ParamTest ParamTest to be written} for more 
  +     * functional test coverage on setting different kinds 
  +     * and types of parameters, etc.
  +     * 
        * NEEDSDOC ($objectName$) @return
        */
       public boolean testCase1()
       {
   
           reporter.testCaseInit(
  -            "TRAX Transformer: cover other APIs and functionality");
  +            "TRAX Transformer: cover basic get/setParameter(s) APIs");
   
  -        Processor p = null;
  +        TransformerFactory factory = null;
           Templates templates = null;
  -
  +        Transformer transformer = null;
  +        Transformer identityTransformer = null;
           try
           {
  -            p = Processor.newInstance(XSLT);
  -
  -            // Use paramTest for later testing of 
setParameter()/resetParameters()
  -            templates = p.process(new InputSource(paramTest.inputName));
  +            factory = TransformerFactory.newInstance();
  +            identityTransformer = factory.newTransformer();
  +            templates = factory.newTemplates(new 
StreamSource(paramTest.inputName));
           }
           catch (Exception e)
           {
  -            reporter.checkFail(
  -                "Problem creating Processor; cannot continue testcase");
  -            reporter.logThrowable(reporter.ERRORMSG, e,
  -                                  "Problem creating Processor");
  -
  +            reporter.checkFail("Problem creating Templates; cannot continue 
testcase");
  +            reporter.logThrowable(reporter.ERRORMSG, e, 
  +                                  "Problem creating Templates; cannot 
continue testcase");
               return true;
           }
  -
  -        Transformer transformer = templates.newTransformer();
  -
  +        // Note: large number of try...catch blocks so that early 
  +        // exceptions won't blow out the whole testCase
           try
           {
  -
  -            // Cover APIs get*Handler()
  -            if (p.getFeature(FEATURE_SAX_INPUT))
  +            // See what the default 'identity' transform has by default
  +            Object tmp = 
identityTransformer.getParameter("This-param-does-not-exist");
  +            reporter.checkObject(tmp, null, "This-param-does-not-exist is 
null by default identityTransformer");
  +            // Can you set properties on this transformer?
  +            identityTransformer.setParameter("foo", "bar");
  +            tmp = identityTransformer.getParameter("foo");
  +            if (tmp == null)
               {
  +                reporter.checkAmbiguous("@todo set/getParameter on identity 
transform returns null, what should it do?");
  +            }
  +            else
  +            {
  +                reporter.checkString((String)tmp, "bar", 
"identityTransformer set/getParameter");
  +            }
  +        } 
  +        catch (Exception e)
  +        {
  +            reporter.checkFail("Problem with identity parameters");
  +            reporter.logThrowable(reporter.ERRORMSG, e, "Problem with 
identity parameters");
  +        }
   
  -                // Validate simply by checking for null
  -                reporter.check((transformer.getInputContentHandler() != 
null),
  -                               true, "getInputContentHandler() is non-null");
  -                reporter.check((transformer.getInputDeclHandler() != null),
  -                               true, "getInputDeclHandler() is non-null");
  -                reporter.check((transformer.getInputLexicalHandler() != 
null),
  -                               true, "getInputLexicalHandler() is non-null");
  +        try
  +        {
  +            transformer = templates.newTransformer(); // may throw 
TransformerConfigurationException
  +            // Default Transformer should not have any parameters..
  +            Object tmp = 
transformer.getParameter("This-param-does-not-exist");
  +            reporter.checkObject(tmp, null, "This-param-does-not-exist is 
null by default");
  +            //  .. including params in the stylesheet
  +            tmp = transformer.getParameter(PARAM1S);
  +            if (tmp == null)
  +            {   // @todo should use checkObject instead of this if... 
construct
  +                reporter.checkPass(PARAM1S + " is null by default");
               }
               else
               {
  +                reporter.checkFail(PARAM1S + " is " + tmp + " by default");
  +            }
   
  -                // Can't validate, just print out values
  -                reporter.logWarningMsg(
  -                    "getInputContentHandler is: "
  -                    + transformer.getInputContentHandler());
  -                reporter.logWarningMsg("getInputDeclHandler is: "
  -                                       + transformer.getInputDeclHandler());
  -                reporter.logWarningMsg(
  -                    "getInputLexicalHandler is: "
  -                    + transformer.getInputLexicalHandler());
  +            // Verify simple set/get of a single parameter
  +            transformer.setParameter(PARAM1S, "new value1s");
  +            reporter.logTraceMsg("Just reset " + PARAM1S + " to new 
value1s");
  +            tmp = transformer.getParameter(PARAM1S);    // SPR SCUU4QWTVZ - 
returns an XString
  +            if (tmp == null)
  +            {
  +                reporter.checkFail(PARAM1S + " is still set to null!");
  +            }
  +            else
  +            {
  +                reporter.logTraceMsg(PARAM1S + " is now ?" + tmp + "?, isa " 
+ tmp.getClass().getName());
  +                reporter.checkString((String)tmp, "new value1s", PARAM1S + " 
is now set to ?" + tmp + "?");
               }
  +        } 
  +        catch (Exception e)
  +        {
  +            reporter.checkFail("Problem set/getParameter testing");
  +            reporter.logThrowable(reporter.ERRORMSG, e, "Problem 
set/getParameter testing");
           }
  +
  +        try
  +        {
  +            transformer = templates.newTransformer();
  +            // Verify simple set/get of a single parameter
  +            transformer.setParameter(PARAM1S, new Integer(1234));
  +            reporter.logTraceMsg("Just set " + PARAM1S + " to 
Integer(1234)");
  +            Object tmp = transformer.getParameter(PARAM1S);    // SPR 
SCUU4QWTVZ - returns an XObject
  +            // @todo need to type-check maybe?
  +            reporter.logTraceMsg(PARAM1S + " is now ?" + tmp + "?, isa " + 
tmp.getClass().getName());
  +            reporter.checkObject(tmp, new Integer(1234), PARAM1S + " is now 
set to ?" + tmp + "?");
  +
  +            transformer.setParameter(PARAM3S, "new value3s");
  +            reporter.logTraceMsg("Just reset " + PARAM3S + " to new 
value3s");
  +            tmp = transformer.getParameter(PARAM3S);
  +            reporter.checkString((String)tmp, "new value3s", PARAM3S + " is 
now set to ?" + tmp + "?");
  +
  +            Properties setParams = new Properties();
  +            setParams.put(PARAM1S, "another value1s");
  +            setParams.put(PARAM2S, "yet another value2s");
  +
  +            // Verify setting Properties full of params works
  +            transformer.setParameters(setParams);
  +            tmp = transformer.getParameter(PARAM2S);
  +            reporter.checkString((String)tmp, "yet another value2s", PARAM2S 
+ " is now set to ?" + tmp + "?");
  +
  +            // Verify we overwrite earlier setting of individual param
  +            tmp = transformer.getParameter(PARAM1S);
  +            reporter.checkString((String)tmp, "another value1s", PARAM1S + " 
is now set to ?" + tmp + "?");
  +
  +            // Verify we cleared earlier set params 
  +            tmp = transformer.getParameter(PARAM3S);
  +            if (tmp == null)
  +            {   // @todo should use checkObject instead of this if... 
construct
  +                reporter.checkPass(PARAM3S + " is null after setting 
params");
  +            }
  +            else
  +            {
  +                reporter.checkFail(PARAM3S + " is ?" + tmp + "? after 
setting params");
  +            }
  +        } 
           catch (Exception e)
           {
  -            reporter.checkErr("get*Handler() test threw: " + e.toString());
  -            reporter.logThrowable(reporter.ERRORMSG, e,
  -                                  "get*Handler() test threw:");
  +            reporter.checkFail("Problem set/getParameters testing");
  +            reporter.logThrowable(reporter.ERRORMSG, e, "Problem 
set/getParameters testing");
           }
   
           try
           {
               transformer = templates.newTransformer();
  +            transformer.setParameter(PARAM1S, "test-param-1s");
  +            transformer.setParameter(PARAM1N, "test-param-1n");
  +            // Verify basic params actually affect transformation
  +            if (doTransform(templates.newTransformer(), 
  +                            new StreamSource(paramTest.xmlName), 
  +                            new StreamResult(new 
FileOutputStream(outNames.nextName()))))
  +            {
  +                // @todo should update goldFile!
  +                fileChecker.check(reporter, 
  +                                  new File(outNames.currentName()), 
  +                                  new File(paramTest.goldName), 
  +                                  "transform with param1s,param1n into: " + 
outNames.currentName());
  +            }
  +            reporter.checkAmbiguous("@todo verify if params are still set 
after transform");
  +        } 
  +        catch (Exception e)
  +        {
  +            reporter.checkFail("Problem with parameter transform");
  +            reporter.logThrowable(reporter.ERRORMSG, e, "Problem with 
parameter transform");
  +        }
   
  -            // Basic setOutputFormat() test
  -            String fName1 = outNames.nextName();
  +        reporter.testCaseClose();
   
  -            transformer.transform(new InputSource(paramTest.xmlName),
  -                                  new Result(new FileOutputStream(fName1)));
  -            reporter.logStatusMsg("Created default output: " + fName1);
  +        return true;
  +    }
  +
   
  -            // Force output type to be different
  -            OutputFormat outputFormat = templates.getOutputFormat();
  +    /**
  +     * TRAX Transformer: cover basic get/setOutputFormat APIs.
  +     * See [EMAIL PROTECTED] OutputFormatTest} for more coverage on setting 
  +     * different kinds of outputs, etc.
  +     * 
  +     * NEEDSDOC ($objectName$) @return
  +     */
  +    public boolean testCase2()
  +    {
  +
  +        reporter.testCaseInit(
  +            "TRAX Transformer: cover basic get/setOutputFormat APIs");
   
  -            outputFormat.setMethod(Method.Text);  // TODO better switch
  -            transformer.setOutputFormat(outputFormat);
  -            transformer.transform(
  -                new InputSource(paramTest.xmlName),
  -                new Result(new FileOutputStream(outNames.nextName())));
  -            reporter.checkAmbiguous("// TODO validate: Created TEXT output: "
  -                                    + outNames.currentName());
  +        TransformerFactory factory = null;
  +        Templates templates = null;
  +        Transformer transformer = null;
  +        Transformer identityTransformer = null;
  +        try
  +        {
  +            factory = TransformerFactory.newInstance();
  +            identityTransformer = factory.newTransformer();
  +            templates = factory.newTemplates(new 
StreamSource(outputFormatTest.inputName));
           }
           catch (Exception e)
           {
  -            reporter.checkErr("setOutputFormat() test threw: "
  -                              + e.toString());
  -            reporter.logThrowable(reporter.ERRORMSG, e,
  -                                  "setOutputFormat() test threw:");
  +            reporter.checkFail("Problem creating Templates; cannot continue 
testcase");
  +            reporter.logThrowable(reporter.ERRORMSG, e, 
  +                                  "Problem creating Templates; cannot 
continue testcase");
  +            return true;
           }
   
           try
           {
  -            transformer = templates.newTransformer();
  +            // See what the default 'identity' transform has by default
  +            Properties identityProps = 
identityTransformer.getOutputProperties();
  +            reporter.logHashtable(reporter.STATUSMSG, identityProps, 
  +                                  "default 
identityTransformer.getOutputProperties()");
  +
  +            // Can you set properties on this transformer?
  +            
identityTransformer.setOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS, 
"cdata-sections");
  +            String tmp = 
identityTransformer.getOutputProperty(OutputKeys.CDATA_SECTION_ELEMENTS);
  +            reporter.check(tmp, "cdata-sections", "identityTransformer 
set/getOutputProperty");
  +        } 
  +        catch (Exception e)
  +        {
  +            reporter.checkFail("Problem with identity output properties");
  +            reporter.logThrowable(reporter.ERRORMSG, e,
  +                                  "Problem with identity output properties");
  +        }
   
  -            // Basic setParameter()/resetParameters() test
  -            String noParams = outNames.nextName();
  -            String withParams = outNames.nextName();
  -            String resetParams = outNames.nextName();
  -            String neverParams = outNames.nextName();
  -
  -            transformer.transform(new InputSource(paramTest.xmlName),
  -                                  new Result(new 
FileOutputStream(noParams)));
  -            reporter.logStatusMsg("Created noParams output: " + noParams);
  -
  -            String paramName = "paramName";
  -            String paramNamespace = null;  // TODO write stylesheet that 
uses the namespaces
  -            String paramValue = "paramValue";
  -
  -            transformer.setParameter(paramName, paramNamespace, paramValue);
  -            transformer.transform(
  -                new InputSource(paramTest.xmlName),
  -                new Result(new FileOutputStream(withParams)));
  -            reporter.logStatusMsg("Created withParams output: " + 
withParams);
  -            transformer.resetParameters();
  -            transformer.transform(
  -                new InputSource(paramTest.xmlName),
  -                new Result(new FileOutputStream(resetParams)));
  -            reporter.checkAmbiguous(
  -                "// TODO validate Created resetParams output: "
  -                + resetParams);
  +        try
  +        {
  +            // See what our templates parent has
  +            Properties tmpltProps = templates.getOutputProperties();
  +            reporter.logHashtable(reporter.STATUSMSG, tmpltProps, 
  +                                  "default templates.getOutputProperties()");
   
  -            // Also check what happens when you use a new transformer
  +            // See what we have by default, from our testfile
               transformer = templates.newTransformer();
  +            Properties outProps = transformer.getOutputProperties();
  +            reporter.logHashtable(reporter.STATUSMSG, outProps, 
  +                                  "default 
transformer.getOutputProperties()");
  +            
  +            reporter.checkAmbiguous("@todo validate transformer, templates 
have same default output formats");
  +
  +            // @todo validate some known output property from our testfile
  +            String tmp = transformer.getOutputProperty(OUTPUT_FORMAT_NAME);
  +            reporter.check(tmp, OUTPUT_FORMAT_VALUE, "transformer get known 
OutputProperty value ?" + tmp + "?");
  +
  +            // Simple set/getOutputProperty
  +            tmp = 
transformer.getOutputProperty(OutputKeys.OMIT_XML_DECLARATION);
  +            reporter.logTraceMsg(OutputKeys.OMIT_XML_DECLARATION + " is 
currently: " + tmp);
  +            transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, 
"yes");
  +            tmp = 
transformer.getOutputProperty(OutputKeys.OMIT_XML_DECLARATION);
  +            reporter.check(tmp, "yes", "transformer set/getOutputProperty 
value to ?" + tmp + "?");
  +
  +            // setOutputProperties(Properties oformat)
  +            // Properties getOutputProperties()
  +            // setOutputProperty(String name, String value) throws 
TransformerException
  +            // String getOutputProperty(String name) throws 
TransformerException;
  +            // Only with StreamResult, obviously
  +            // OutputKeys.METHOD = xml|html|text|qname-but-not-ncname
  +            // OutputKeys.VERSION = number
  +            // OutputKeys.ENCODING = string
  +            // OutputKeys.OMIT_XML_DECLARATION = yes|no
  +            // OutputKeys.STANDALONE = yes|no
  +            // OutputKeys.DOCTYPE_PUBLIC = string
  +            // OutputKeys.DOCTYPE_SYSTEM = string
  +            // OutputKeys.CDATA_SECTION_ELEMENTS = qnames
  +            // OutputKeys.INDENT = qnames
  +            // OutputKeys.MEDIA_TYPE = qnames
  +            // OutputKeys.CDATA_SECTION_ELEMENTS = qnames
   
  -            transformer.transform(
  -                new InputSource(paramTest.xmlName),
  -                new Result(new FileOutputStream(neverParams)));
  -            reporter.checkAmbiguous(
  -                "// TODO validate Created neverParams output: "
  -                + neverParams);
  -        }
  +            reporter.checkAmbiguous("@todo Cover 
set/getOutputProperty/ies()");
  +        } 
           catch (Exception e)
           {
  -            reporter.checkErr("setParameter()/resetParameters() test threw: "
  -                              + e.toString());
  -            reporter.logThrowable(
  -                reporter.ERRORMSG, e,
  -                "setParameter()/resetParameters() test threw:");
  +            reporter.checkFail("Problem with set/get output properties");
  +            reporter.logThrowable(reporter.ERRORMSG, e,
  +                                  "Problem with set/get output properties");
           }
   
  -        reporter.checkAmbiguous(
  -            "// TODO Cover setURIResolver() API and functionality");
           reporter.testCaseClose();
   
           return true;
       }
   
       /**
  -     * TRAX Transformer: cover transform*() APIs and functionality.
  +     * TRAX Transformer: cover transform() API and basic 
  +     * functionality; plus set/getURIResolver() API.
        *
  +     * Note: These are simply coverage tests for the 
  +     * transform() API - for more general testing, 
  +     * see TraxWrapper.java and use ConformanceTest or 
  +     * another suitable test driver.
  +     * 
  +     * @todo should the Features.SAX and Features.DOM tests be in 
  +     * this file, or should they be in sax/dom subdirectory tests?
        * NEEDSDOC ($objectName$) @return
        */
  -    public boolean testCase2()
  +    public boolean testCase3()
       {
  -
           reporter.testCaseInit(
  -            "TRAX Transformer: cover transform*() APIs and functionality");
  -
  +            "TRAX Transformer: cover transform() and set/getURIResolver API 
and functionality");
  +        TransformerFactory factory = null;
           try
           {
  -            Processor p = Processor.newInstance(XSLT);
  +            // Grab a stylesheet to use 
  +            factory = TransformerFactory.newInstance();
  +            Templates templates = factory.newTemplates(new 
StreamSource(simpleTest.inputName));
  +
  +            Transformer transformer = templates.newTransformer();
  +            // URIResolver should be null by default; try to set/get one
  +            reporter.checkObject(transformer.getURIResolver(), null, 
"getURIResolver is null by default");
  +            LoggingURIResolver myURIResolver = new 
LoggingURIResolver(reporter);
  +            transformer.setURIResolver(myURIResolver);
  +            reporter.checkObject(transformer.getURIResolver(), 
myURIResolver, "set/getURIResolver test");
  +            reporter.logTraceMsg("myURIres.getCounterString = " + 
myURIResolver.getCounterString());
  +
  +            // Assumes we support Streams
  +            if (doTransform(transformer, 
  +                            new StreamSource(simpleTest.xmlName), 
  +                            new StreamResult(new 
FileOutputStream(outNames.nextName()))))
  +            {
  +                fileChecker.check(reporter, 
  +                                  new File(outNames.currentName()), 
  +                                  new File(simpleTest.goldName), 
  +                                  "transform(Stream, Stream) into: " + 
outNames.currentName());
  +            }
  +            reporter.logTraceMsg("myURIres.getCounterString = " + 
myURIResolver.getCounterString());
   
  -            // These tests are already covered in TraxWrapper.java
  -            reporter.checkAmbiguous("// TODO transform(InputSource) -> SAX");
  -            reporter.checkAmbiguous("// TODO transform(InputSource, 
Result)");
  +            reporter.checkAmbiguous("@todo basic URIResolver functionality 
test (i.e. does it get used in a transform)");
  +        }
  +        catch (Exception e)
  +        {
  +            reporter.checkFail("TestCase threw: " + e.toString());
  +            reporter.logThrowable(reporter.ERRORMSG, e, "TestCase threw:");
  +        }
   
  -            if (p.getFeature(FEATURE_DOM_INPUT))
  +        try
  +        {
  +            if (factory.getFeature(Features.DOM))
               {
  -                reporter.checkAmbiguous(
  -                    "// TODO transformNode(Node, Result)  if dom/input");
  -                reporter.checkAmbiguous(
  -                    "// TODO transformNode(Node) -> SAX  if dom/input");
  +                // @todo should they be in sax/dom subdirectory tests?
  +                reporter.checkAmbiguous("@todo transform(DOM, DOM)");
  +                reporter.checkAmbiguous("@todo transform(DOM, Stream)");
  +                reporter.checkAmbiguous("@todo transform(Stream, DOM)");
               }
               else
               {
  -                reporter.logWarningMsg("Skipping transformNode(*) tests, "
  -                                       + FEATURE_DOM_INPUT
  +                reporter.logWarningMsg("Skipping transform(DOM*) tests, "
  +                                       + Features.DOM
                                          + " not supported");
               }
  +
  +            if (factory.getFeature(Features.SAX))
  +            {
  +                // @todo should they be in sax/dom subdirectory tests?
  +                reporter.checkAmbiguous("@todo transform(SAX, SAX)");
  +                reporter.checkAmbiguous("@todo transform(SAX, Stream)");
  +                reporter.checkAmbiguous("@todo transform(Stream, SAX)");
  +            }
  +            else
  +            {
  +                reporter.logWarningMsg("Skipping transform(SAX*) tests, "
  +                                       + Features.SAX
  +                                       + " not supported");
  +            }
  +            if (factory.getFeature(Features.SAX) && 
factory.getFeature(Features.DOM))
  +            {
  +                // @todo should they be in sax/dom subdirectory tests?
  +                reporter.checkAmbiguous("@todo transform(SAX, DOM)");
  +                reporter.checkAmbiguous("@todo transform(DOM, SAX)");
  +            }
  +            else
  +            {
  +                reporter.logWarningMsg("Skipping transform(SAX/DOM) tests, 
one of them not supported.");
  +            }
           }
           catch (Exception e)
           {
               reporter.checkFail("TestCase threw: " + e.toString());
               reporter.logThrowable(reporter.ERRORMSG, e, "TestCase threw:");
  -
  -            return true;
           }
  -
           reporter.testCaseClose();
   
           return true;
       }
   
  +
  +    /**
  +     * Worker method performs transforms (and catches exceptions, etc.)
  +     * Side effect: checkFail() if exception thrown
  +     *
  +     * @param Transformer to use
  +     * @param Source to pull in XML from
  +     * @param Result to put output in; may be modified
  +     * @return false if exception thrown, true otherwise
  +     */
  +    public boolean doTransform(Transformer t, Source s, Result r)
  +    {
  +        try
  +        {
  +            t.transform(s, r);
  +            return true;
  +            
  +        } 
  +        catch (TransformerException e)
  +        {
  +            reporter.checkFail("doTransform threw: " + e.toString());
  +            reporter.logThrowable(reporter.ERRORMSG, e, "doTransform 
threw:");
  +            return false;
  +        }
  +    }
  +
  +
       /**
        * Convenience method to print out usage information - update if needed. 
 
        *
  @@ -447,17 +670,15 @@
        */
       public String usage()
       {
  -
           return ("Common [optional] options supported by 
TransformerAPITest:\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