summaryrefslogtreecommitdiff
path: root/test/java/src/org/apache/qetest/trax/TransformerFactoryAPITest.java
blob: 6d1694721e2d6ea9c51179ec8947560a7ab1f8fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the  "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/*
 * $Id$
 */

/*
 *
 * TransformerFactoryAPITest.java
 *
 */
package org.apache.qetest.trax;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
import javax.xml.transform.Templates;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.URIResolver;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.apache.qetest.FileBasedTest;
import org.apache.qetest.Logger;
import org.apache.qetest.OutputNameManager;
import org.apache.qetest.QetestUtils;
import org.apache.qetest.xsl.XSLTestfileInfo;
import org.apache.xml.utils.DefaultErrorHandler;

import org.w3c.dom.Document;

//-------------------------------------------------------------------------

/**
 * API Coverage test for TransformerFactory class of TRAX.
 * @author shane_curcuru@lotus.com
 * @version $Id$
 */
public class TransformerFactoryAPITest extends FileBasedTest
{

    /**
     * Provides nextName(), currentName() functionality for tests 
     * that may produce any number of output files.
     */
    protected OutputNameManager outNames;

    /** Basic identity test file for newTransformer, newTemplates.  */
    protected XSLTestfileInfo testFileInfo = new XSLTestfileInfo();

    /** Embedded identity test file for getEmbedded....  */
    protected XSLTestfileInfo embeddedFileInfo = new XSLTestfileInfo();

    /** Modern test for testCase6.  */
    protected XSLTestfileInfo embeddedCSSFileInfo = new XSLTestfileInfo();

    /** Subdirectory under test\tests\api for our xsl/xml files.  */
    public static final String TRAX_SUBDIR = "trax";

    /** Cached system property.  */
    protected String cachedSysProp = null;

    /** System property name, from TransformerFactory (why is it private there?).  */
    public static final String defaultPropName = "javax.xml.transform.TransformerFactory";

    /** System property name for Xalan-J 2.x impl.  */
    public static final String XALAN_CLASSNAME = "org.apache.xalan.processor.TransformerFactoryImpl";

    /** Just initialize test name, comment, numTestCases. */
    public TransformerFactoryAPITest()
    {
        numTestCases = 7;  // REPLACE_num
        testName = "TransformerFactoryAPITest";
        testComment = "API Coverage test for TransformerFactory class of TRAX";
    }


    /**
     * Initialize this test - Set names of xml/xsl test files,
     * cache system property javax.xml.transform.TransformerFactory.  
     *
     * @param p Properties to initialize from (if needed)
     * @return false if we should abort the test; true otherwise
     */
    public boolean doTestFileInit(Properties p)
    {
        // NOTE: 'reporter' variable is already initialized at this point

        // 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);
        // Initialize an output name manager to that dir with .out extension
        outNames = new OutputNameManager(outputDir + File.separator + TRAX_SUBDIR
                                         + File.separator + testName, ".out");

        String testBasePath = inputDir 
                              + File.separator 
                              + TRAX_SUBDIR
                              + File.separator;
        String goldBasePath = goldDir 
                              + File.separator 
                              + TRAX_SUBDIR
                              + File.separator;

        testFileInfo.inputName = QetestUtils.filenameToURL(testBasePath + "identity.xsl");
        testFileInfo.xmlName = QetestUtils.filenameToURL(testBasePath + "identity.xml");
        testFileInfo.goldName = goldBasePath + "identity.out";

        embeddedFileInfo.xmlName = QetestUtils.filenameToURL(testBasePath + "embeddedIdentity.xml");
        embeddedFileInfo.goldName = goldBasePath + "embeddedIdentity.out";

        embeddedCSSFileInfo.xmlName = testBasePath + "TransformerFactoryAPIModern.xml"; // just the local path\filename
        // embeddedCSSFileInfo.optionalName = testBasePath + "TransformerFactoryAPIModern.css"; // other file required by XML file

        // Cache the system property; is reset in testFileClose
        cachedSysProp = System.getProperty(defaultPropName);
        return true;
    }


    /**
     * Cleanup this test - reset cached system property.  
     *
     * @param p Properties to initialize from (if needed)
     * @return false if we should abort the test; true otherwise
     */
    public boolean doTestFileClose(Properties p)
    {
        if (cachedSysProp == null)
            System.getProperties().remove(defaultPropName);
        else
            System.getProperties().put(defaultPropName, cachedSysProp);
        return true;
    }


    /**
     * Coverage tests for factory pattern API's.
     *
     * @return false if we should abort the test; true otherwise
     */
    public boolean testCase1()
    {
        reporter.testCaseInit("Coverage tests for factory pattern API's");

        // protected TransformerFactory(){} not normally accessible - not tested
        // public static TransformerFactory newInstance()
        TransformerFactory factory = null;
        // test when system property is user-set (i.e. whatever we started with)
        try
        {
            reporter.logStatusMsg("System property " + defaultPropName 
                                  + " is: " + System.getProperty(defaultPropName));
            factory = TransformerFactory.newInstance();
            // No verification: just log what happened for user to see
            reporter.logStatusMsg("factory.newInstance() is: " + factory.toString());
        }
        catch (Throwable t)
        {
            reporter.logStatusMsg("factory.newInstance() threw: " + t.toString());
        }

        // test when system property is null
        try
        {
            System.getProperties().remove(defaultPropName);
            reporter.logStatusMsg("System property " + defaultPropName 
                                  + " is: " + System.getProperty(defaultPropName));
            factory = TransformerFactory.newInstance();
            reporter.logStatusMsg("factory.newInstance() is: " + factory.toString());
        }
        catch (Throwable t)
        {
            reporter.logStatusMsg("factory.newInstance() threw: " + t.toString());
        }

        // test when system property is a bogus name
        try
        {
            System.getProperties().put(defaultPropName, "this.class.does.not.exist");
            reporter.logStatusMsg("System property " + defaultPropName 
                                  + " is: " + System.getProperty(defaultPropName));
            factory = TransformerFactory.newInstance();
            reporter.checkFail("factory.newInstance() with bogus name got: " + factory.toString());
        }
        catch (Throwable t)
        {
            reporter.checkPass("factory.newInstance() with bogus name properly threw: " + t.toString());
            // Could also verify specific type of exception
        }

        // test when system property is another kind of classname
        try
        {
            System.getProperties().put(defaultPropName, "java.lang.String");
            reporter.logStatusMsg("System property " + defaultPropName 
                                  + " is: " + System.getProperty(defaultPropName));
            factory = TransformerFactory.newInstance();
            reporter.checkFail("factory.newInstance() with bogus class got: " + factory.toString());
        }
        catch (Throwable t)
        {
            reporter.checkPass("factory.newInstance() with bogus class properly threw: " + t.toString());
            // Could also verify specific type of exception
        }

        // Reset the system property to what was cached previously
        try
        {
            // This should come last so it will stay set for the rest of the test
            // Note: this needs review, since in the future we may 
            //  not guaruntee order of testCase execution!
            if (cachedSysProp == null)
                System.getProperties().remove(defaultPropName);
            else
                System.getProperties().put(defaultPropName, cachedSysProp);

            reporter.logStatusMsg("System property (default) " + defaultPropName 
                                  + " is: " + System.getProperty(defaultPropName));
            factory = TransformerFactory.newInstance();
            reporter.checkPass("factory.newInstance() of default impl is: " + factory.toString());
        }
        catch (Throwable t)
        {
            reporter.checkFail("factory.newInstance() of default impl threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "factory.newInstance() of default impl threw:");
        }

        reporter.logStatusMsg("@todo code coverage for findFactory() method");

        reporter.testCaseClose();
        return true;
    }


    /**
     * Coverage tests for newTransformer() API's.
     *
     * @return false if we should abort the test; true otherwise
     */
    public boolean testCase2()
    {
        reporter.testCaseInit("Coverage tests for newTransformer() API's");
        TransformerFactory factory = null;

        try
        {
            reporter.logStatusMsg("System property " + defaultPropName 
                                  + " is: " + System.getProperty(defaultPropName));
            factory = TransformerFactory.newInstance();
            factory.setErrorListener(new DefaultErrorHandler());
            Transformer identityTransformer = factory.newTransformer();
            reporter.check((identityTransformer != null), true, "newTransformer() APICoverage");

            if (factory.getFeature(StreamSource.FEATURE))
            {
                Transformer transformer = factory.newTransformer(new StreamSource(testFileInfo.inputName));
                reporter.check((transformer != null), true, "newTransformer(Source) APICoverage");
            }
            else
                reporter.logErrorMsg("NOTE: getFeature(StreamSource.FEATURE) false, can't test newTransformer(Source)");
        }
        catch (Throwable t)
        {
            reporter.checkFail("newTransformer() tests threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "newTransformer() tests threw");
        }

        reporter.testCaseClose();
        return true;
    }


    /**
     * Coverage tests for newTemplates() API's.
     *
     * @return false if we should abort the test; true otherwise
     */
    public boolean testCase3()
    {
        reporter.testCaseInit("Coverage tests for newTemplates() API's");
        TransformerFactory factory = null;

        try
        {
            reporter.logStatusMsg("System property " + defaultPropName 
                                  + " is: " + System.getProperty(defaultPropName));
            factory = TransformerFactory.newInstance();
            factory.setErrorListener(new DefaultErrorHandler());
            if (factory.getFeature(StreamSource.FEATURE))
            {
                Templates templates = factory.newTemplates(new StreamSource(testFileInfo.inputName));
                reporter.check((templates != null), true, "newTemplates(Source) APICoverage");
            }
            else
                reporter.logErrorMsg("NOTE: getFeature(StreamSource.FEATURE) false, can't test newTemplates(Source)");
        }
        catch (Throwable t)
        {
            reporter.checkFail("newTemplates() tests threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "newTemplates() tests threw");
        }

        reporter.testCaseClose();
        return true;
    }


    /**
     * Coverage tests for getAssociatedStylesheet() API's.
     *
     * @return false if we should abort the test; true otherwise
     */
    public boolean testCase4()
    {
        reporter.testCaseInit("Coverage tests for getAssociatedStylesheet() API's");
        TransformerFactory factory = null;

        try
        {
            reporter.logStatusMsg("System property " + defaultPropName 
                                  + " is: " + System.getProperty(defaultPropName));
            factory = TransformerFactory.newInstance();
            factory.setErrorListener(new DefaultErrorHandler());
            String media= null;     // currently untested
            String title = null;    // currently untested
            String charset = null;  // currently untested

            // May throw IOException
            FileOutputStream resultStream = new FileOutputStream(outNames.nextName());

            // Get the xml-stylesheet and process it
            Source stylesheet = factory.getAssociatedStylesheet(new StreamSource(embeddedFileInfo.xmlName), 
                                                                media, title, charset);
            reporter.check((stylesheet instanceof Source), true, "getAssociatedStylesheet returns instanceof Source");
            reporter.check((null != stylesheet), true, "getAssociatedStylesheet returns a non-null Source");

            Transformer transformer = factory.newTransformer(stylesheet);
            transformer.setErrorListener(new DefaultErrorHandler());
            reporter.logCriticalMsg("SPR SCUU4RXTSQ occours in below line, even though check reports pass (missing linefeed)");
            transformer.transform(new StreamSource(embeddedFileInfo.xmlName), new StreamResult(resultStream));
            resultStream.close();   // just in case
            int result = fileChecker.check(reporter, 
                                           new File(outNames.currentName()), 
                                           new File(embeddedFileInfo.goldName), 
                                          "transform of getAssociatedStylesheet into " + outNames.currentName());
            if (result == Logger.FAIL_RESULT)
                reporter.logInfoMsg("transform of getAssociatedStylesheet... failure reason:" + fileChecker.getExtendedInfo());
        }
        catch (Throwable t)
        {
            reporter.logThrowable(reporter.ERRORMSG, t, "getAssociatedStylesheet() tests threw:");
        }

        reporter.testCaseClose();
        return true;
    }


    /**
     * Coverage tests for get/setURIResolver(), get/setErrorListener() API's.
     *
     * @return false if we should abort the test; true otherwise
     */
    public boolean testCase5()
    {
        reporter.testCaseInit("Coverage tests for get/setURIResolver(), get/setErrorListener() API's");
        TransformerFactory factory = null;
        reporter.logStatusMsg("System property " + defaultPropName 
                              + " is: " + System.getProperty(defaultPropName));
        try
        {
            factory = TransformerFactory.newInstance();
            factory.setErrorListener(new DefaultErrorHandler());
            URIResolver URIRes = factory.getURIResolver();
            reporter.logInfoMsg("factory.getURIResolver() default is: " + URIRes);
            
            LoggingURIResolver loggingURIRes = new LoggingURIResolver(reporter);
            factory.setURIResolver(loggingURIRes);
            reporter.checkObject(factory.getURIResolver(), loggingURIRes, "set/getURIResolver API coverage");
            factory.setURIResolver(null);
            if (factory.getURIResolver() == null)
            {
                reporter.checkPass("setURIResolver(null) is OK");
            }
            else
            {
                reporter.checkFail("setURIResolver(null) not OK, is: " + factory.getURIResolver());
            }
        }
        catch (Throwable t)
        {
            reporter.checkErr("Coverage of get/setURIResolver threw: " + t.toString());
            reporter.logThrowable(reporter.STATUSMSG, t, "Coverage of get/setURIResolver threw:");
        }
        reporter.logStatusMsg("//@todo feature testing for URIResolver: see URIResolverTest.java");

        try
        {
            factory = TransformerFactory.newInstance();
            ErrorListener errListener = factory.getErrorListener();
            if (errListener == null)
            {
                reporter.checkFail("getErrorListener() non-null by default");
            }
            else
            {
                reporter.checkPass("getErrorListener() non-null by default, is: " + errListener);
            }
            
            LoggingErrorListener loggingErrListener = new LoggingErrorListener(reporter);
            factory.setErrorListener(loggingErrListener);
            reporter.checkObject(factory.getErrorListener(), loggingErrListener, "set/getErrorListener API coverage(1)");
            try
            {
                factory.setErrorListener(null);                
                reporter.checkFail("setErrorListener(null) worked, should have thrown exception");
            }
            catch (IllegalArgumentException iae)
            {
                reporter.checkPass("setErrorListener(null) properly threw: " + iae.toString());
            }
            // Verify the previous ErrorListener is still set
            reporter.checkObject(factory.getErrorListener(), loggingErrListener, "set/getErrorListener API coverage(2)");
        }
        catch (Throwable t)
        {
            reporter.checkErr("Coverage of get/setErrorListener threw: " + t.toString());
            reporter.logThrowable(reporter.STATUSMSG, t, "Coverage of get/setErrorListener threw:");
        }
        reporter.logStatusMsg("//@todo feature testing for ErrorListener: see ErrorListenerAPITest.java, ErrorListenerTest.java");

        reporter.testCaseClose();
        return true;
    }


    /**
     * Miscellaneous tests.
     * Bug/tests submitted by Bhakti.Mehta@eng.sun.com
     *
     * @return false if we should abort the test; true otherwise
     */
    public boolean testCase6()
    {
        reporter.testCaseInit("Miscellaneous getAssociatedStylesheets tests");
        TransformerFactory factory = null;
        try
        {
            factory = TransformerFactory.newInstance();
            factory.setErrorListener(new DefaultErrorHandler());

            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            DocumentBuilder db = dbf.newDocumentBuilder();

            // Note that embeddedCSSFileInfo has the following PI:
            //  <?xml-stylesheet href="TransformerFactoryAPIModern.css" title="Modern" media="screen" type="text/css"?>
            // Which we should return null from, since we only support 
            //  types that are properly mapped to xslt:
            //  text/xsl, text/xml, and application/xml+xslt
            //  see also EmbeddedStylesheetTest
            Document doc = db.parse(new File(embeddedCSSFileInfo.xmlName));
            DOMSource domSource = new DOMSource(doc);

            // TransformerFactory01.check01()
            try 
            {
                reporter.logInfoMsg("About to getAssociatedStylesheet(domsource-w/outsystemid, screen,Modern,null)");
                Source s = factory.getAssociatedStylesheet(domSource,"screen","Modern",null);
                reporter.check((null == s), true, "getAssociatedStylesheet returns null Source for text/css");
            }
            catch (Throwable t)
            {
                reporter.checkFail("TransformerFactory01.check01a threw: " + t.toString());
                reporter.logThrowable(reporter.STATUSMSG, t, "TransformerFactory01.check01a threw");
            }
            try 
            {
                domSource.setSystemId(QetestUtils.filenameToURL(embeddedCSSFileInfo.xmlName));
                reporter.logInfoMsg("About to getAssociatedStylesheet(domsource-w/systemid, screen,Modern,null)");
                Source s = factory.getAssociatedStylesheet(domSource,"screen","Modern",null);
                reporter.check((null == s), true, "getAssociatedStylesheet returns null Source for text/css");
            }
            catch (Throwable t)
            {
                reporter.checkFail("TransformerFactory01.check01b threw: " + t.toString());
                reporter.logThrowable(reporter.STATUSMSG, t, "TransformerFactory01.check01b threw");
            }

            // public void TransformerFactory02.check01(){
            try 
            {
                StreamSource ss = new StreamSource(new FileInputStream(embeddedCSSFileInfo.xmlName));
                reporter.logInfoMsg("About to getAssociatedStylesheet(streamsource-w/outsystemid, screen,Modern,null)");
                Source s = factory.getAssociatedStylesheet(ss,"screen","Modern",null);
                reporter.check((null == s), true, "getAssociatedStylesheet returns null Source for text/css");
            }
            catch (Throwable t)
            {
                reporter.checkFail("TransformerFactory02.check01a threw: " + t.toString());
                reporter.logThrowable(reporter.STATUSMSG, t, "TransformerFactory02.check01a threw");
            }
            try 
            {
                StreamSource ss = new StreamSource(new FileInputStream(embeddedCSSFileInfo.xmlName));
                ss.setSystemId(QetestUtils.filenameToURL(embeddedCSSFileInfo.xmlName));
                reporter.logInfoMsg("About to getAssociatedStylesheet(streamsource-w/systemid, screen,Modern,null)");
                Source s = factory.getAssociatedStylesheet(ss,"screen","Modern",null);
                reporter.check((null == s), true, "getAssociatedStylesheet returns null Source for text/css");
            }
            catch (Throwable t)
            {
                reporter.checkFail("TransformerFactory02.check01b threw: " + t.toString());
                reporter.logThrowable(reporter.STATUSMSG, t, "TransformerFactory02.check01b threw");
            }
        }
        catch (Throwable t)
        {
            reporter.checkErr("Miscellaneous getAssociatedStylesheets tests threw: " + t.toString());
            reporter.logThrowable(reporter.STATUSMSG, t, "Miscellaneous getAssociatedStylesheets tests threw");
        }

        reporter.testCaseClose();
        return true;
    }


    /**
     * Coverage tests for set/getFeature, set/getAttribute API's.
     *
     * @return false if we should abort the test; true otherwise
     */
    public boolean testCase7()
    {
        reporter.testCaseInit("Coverage tests for set/getFeature, set/getAttribute API's");
        // This test case should be JAXP-generic, and must not rely on Xalan-J 2.x functionality
        reporter.logInfoMsg("Note: only simple validation: most are negative tests");
        TransformerFactory factory = null;
        final String BOGUS_NAME = "fnord:this/feature/does/not/exist";

        try
        {
            factory = TransformerFactory.newInstance();
            try
            {
                reporter.logStatusMsg("Calling: factory.getFeature(BOGUS_NAME)");
                boolean b = factory.getFeature(BOGUS_NAME);
                reporter.checkPass("factory.getFeature(BOGUS_NAME) did not throw exception");
                reporter.logStatusMsg("factory.getFeature(BOGUS_NAME) = " + b);
            }
            catch (IllegalArgumentException iae1)
            {
                // This isn't documented, but is what I might expect
                reporter.checkPass("factory.getFeature(BOGUS_NAME) threw expected IllegalArgumentException");
            }

            try
            {
                reporter.logStatusMsg("Calling: factory.setAttribute(BOGUS_NAME,...)");
                factory.setAttribute(BOGUS_NAME, "on");
                reporter.checkFail("factory.setAttribute(BOGUS_NAME,...) did not throw expected exception");
            }
            catch (IllegalArgumentException iae2)
            {
                reporter.checkPass("factory.setAttribute(BOGUS_NAME,...) threw expected IllegalArgumentException");
            }

            try
            {
                reporter.logStatusMsg("Calling: factory.getAttribute(BOGUS_NAME)");
                Object o = factory.getAttribute(BOGUS_NAME);
                reporter.checkFail("factory.getAttribute(BOGUS_NAME) did not throw expected exception");
                reporter.logStatusMsg("factory.getAttribute(BOGUS_NAME) = " + o);
            }
            catch (IllegalArgumentException iae3)
            {
                reporter.checkPass("factory.getAttribute(BOGUS_NAME) threw expected IllegalArgumentException");
            }
        }
        catch (Throwable t)
        {
            reporter.checkFail("getFeature/Attribute() tests threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "getFeature/Attribute() tests threw");
        }

        try
        {
            reporter.logWarningMsg("Note testing assumption: all factories must support Streams");
            factory = TransformerFactory.newInstance();
            reporter.logStatusMsg("Calling: factory.getFeature(StreamSource.FEATURE)");
            boolean b = factory.getFeature(StreamSource.FEATURE);
            reporter.check(b, true, "factory.getFeature(StreamSource.FEATURE)");

            reporter.logStatusMsg("Calling: factory.getFeature(StreamResult.FEATURE)");
            b = factory.getFeature(StreamResult.FEATURE);
            reporter.check(b, true, "factory.getFeature(StreamResult.FEATURE)");
        }
        catch (Throwable t)
        {
            reporter.checkFail("getFeature/Attribute()2 tests threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "getFeature/Attribute()2 tests threw");
        }

        try
        {
            reporter.logStatusMsg("Calling: factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
            factory = TransformerFactory.newInstance();
            try
            {
                // All implementations are required to support the XMLConstants.FEATURE_SECURE_PROCESSING feature
                factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
                boolean b = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
                reporter.check(b, true, "factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
                factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
                b = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
                reporter.check(b, false, "factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
                
            }
            catch (TransformerConfigurationException tce)
            {
                reporter.checkFail("set/getFeature(XMLConstants.FEATURE_SECURE_PROCESSING) tests threw: " + tce.toString());
                reporter.logThrowable(reporter.ERRORMSG, tce, "set/getFeature(XMLConstants.FEATURE_SECURE_PROCESSING) tests threw");
            }
            
            try
            {
                factory.setFeature(BOGUS_NAME, true);
                reporter.checkFail("factory.setFeature(BOGUS_NAME) did not throw expected exception");
                
            }
            catch (TransformerConfigurationException tce)
            {
                reporter.checkPass("factory.setFeature(BOGUS_NAME) threw expected TransformerConfigurationException");
            }
            
            try
            {
                factory.setFeature(null, true);
                reporter.checkFail("factory.setFeature(null, true) did not throw expected exception");
            }
            catch (NullPointerException npe)
	    {
	        reporter.checkPass("factory.setFeature(null, true) threw expected NullPointerException");
            }
                
        }
        catch (Throwable t)
        {
            reporter.checkFail("set/getFeature() tests threw: " + t.toString());
            reporter.logThrowable(reporter.ERRORMSG, t, "set/getFeature() tests threw");
        }

        reporter.testCaseClose();
        return true;
    }


    /**
     * Convenience method to print out usage information - update if needed.  
     * @return String denoting usage of this test class
     */
    public String usage()
    {
        return ("Common [optional] options supported by TransformerFactoryAPITest:\n"
                + "-transformerFactory <FQCN of TransformerFactoryImpl; default Xalan 2.x>\n"
                + "(Note: assumes inputDir=.\\tests\\api)\n"
                + super.usage());   // Grab our parent classes usage as well
    }


    /**
     * Main method to run test from the command line - can be left alone.  
     * @param args command line argument array
     */
    public static void main(String[] args)
    {
        TransformerFactoryAPITest app = new TransformerFactoryAPITest();
        app.doMain(args);
    }
}