• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the  "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 /*
19  * $Id$
20  */
21 
22 /*
23  *
24  * TransformerFactoryAPITest.java
25  *
26  */
27 package org.apache.qetest.trax;
28 
29 import java.io.File;
30 import java.io.FileInputStream;
31 import java.io.FileOutputStream;
32 import java.util.Properties;
33 
34 import javax.xml.XMLConstants;
35 import javax.xml.parsers.DocumentBuilder;
36 import javax.xml.parsers.DocumentBuilderFactory;
37 import javax.xml.transform.ErrorListener;
38 import javax.xml.transform.Source;
39 import javax.xml.transform.Templates;
40 import javax.xml.transform.Transformer;
41 import javax.xml.transform.TransformerConfigurationException;
42 import javax.xml.transform.TransformerFactory;
43 import javax.xml.transform.URIResolver;
44 import javax.xml.transform.dom.DOMSource;
45 import javax.xml.transform.stream.StreamResult;
46 import javax.xml.transform.stream.StreamSource;
47 
48 import org.apache.qetest.FileBasedTest;
49 import org.apache.qetest.Logger;
50 import org.apache.qetest.OutputNameManager;
51 import org.apache.qetest.QetestUtils;
52 import org.apache.qetest.xsl.XSLTestfileInfo;
53 import org.apache.xml.utils.DefaultErrorHandler;
54 
55 import org.w3c.dom.Document;
56 
57 //-------------------------------------------------------------------------
58 
59 /**
60  * API Coverage test for TransformerFactory class of TRAX.
61  * @author shane_curcuru@lotus.com
62  * @version $Id$
63  */
64 public class TransformerFactoryAPITest extends FileBasedTest
65 {
66 
67     /**
68      * Provides nextName(), currentName() functionality for tests
69      * that may produce any number of output files.
70      */
71     protected OutputNameManager outNames;
72 
73     /** Basic identity test file for newTransformer, newTemplates.  */
74     protected XSLTestfileInfo testFileInfo = new XSLTestfileInfo();
75 
76     /** Embedded identity test file for getEmbedded....  */
77     protected XSLTestfileInfo embeddedFileInfo = new XSLTestfileInfo();
78 
79     /** Modern test for testCase6.  */
80     protected XSLTestfileInfo embeddedCSSFileInfo = new XSLTestfileInfo();
81 
82     /** Subdirectory under test\tests\api for our xsl/xml files.  */
83     public static final String TRAX_SUBDIR = "trax";
84 
85     /** Cached system property.  */
86     protected String cachedSysProp = null;
87 
88     /** System property name, from TransformerFactory (why is it private there?).  */
89     public static final String defaultPropName = "javax.xml.transform.TransformerFactory";
90 
91     /** System property name for Xalan-J 2.x impl.  */
92     public static final String XALAN_CLASSNAME = "org.apache.xalan.processor.TransformerFactoryImpl";
93 
94     /** Just initialize test name, comment, numTestCases. */
TransformerFactoryAPITest()95     public TransformerFactoryAPITest()
96     {
97         numTestCases = 7;  // REPLACE_num
98         testName = "TransformerFactoryAPITest";
99         testComment = "API Coverage test for TransformerFactory class of TRAX";
100     }
101 
102 
103     /**
104      * Initialize this test - Set names of xml/xsl test files,
105      * cache system property javax.xml.transform.TransformerFactory.
106      *
107      * @param p Properties to initialize from (if needed)
108      * @return false if we should abort the test; true otherwise
109      */
doTestFileInit(Properties p)110     public boolean doTestFileInit(Properties p)
111     {
112         // NOTE: 'reporter' variable is already initialized at this point
113 
114         // Used for all tests; just dump files in trax subdir
115         File outSubDir = new File(outputDir + File.separator + TRAX_SUBDIR);
116         if (!outSubDir.mkdirs())
117             reporter.logWarningMsg("Could not create output dir: " + outSubDir);
118         // Initialize an output name manager to that dir with .out extension
119         outNames = new OutputNameManager(outputDir + File.separator + TRAX_SUBDIR
120                                          + File.separator + testName, ".out");
121 
122         String testBasePath = inputDir
123                               + File.separator
124                               + TRAX_SUBDIR
125                               + File.separator;
126         String goldBasePath = goldDir
127                               + File.separator
128                               + TRAX_SUBDIR
129                               + File.separator;
130 
131         testFileInfo.inputName = QetestUtils.filenameToURL(testBasePath + "identity.xsl");
132         testFileInfo.xmlName = QetestUtils.filenameToURL(testBasePath + "identity.xml");
133         testFileInfo.goldName = goldBasePath + "identity.out";
134 
135         embeddedFileInfo.xmlName = QetestUtils.filenameToURL(testBasePath + "embeddedIdentity.xml");
136         embeddedFileInfo.goldName = goldBasePath + "embeddedIdentity.out";
137 
138         embeddedCSSFileInfo.xmlName = testBasePath + "TransformerFactoryAPIModern.xml"; // just the local path\filename
139         // embeddedCSSFileInfo.optionalName = testBasePath + "TransformerFactoryAPIModern.css"; // other file required by XML file
140 
141         // Cache the system property; is reset in testFileClose
142         cachedSysProp = System.getProperty(defaultPropName);
143         return true;
144     }
145 
146 
147     /**
148      * Cleanup this test - reset cached system property.
149      *
150      * @param p Properties to initialize from (if needed)
151      * @return false if we should abort the test; true otherwise
152      */
doTestFileClose(Properties p)153     public boolean doTestFileClose(Properties p)
154     {
155         if (cachedSysProp == null)
156             System.getProperties().remove(defaultPropName);
157         else
158             System.getProperties().put(defaultPropName, cachedSysProp);
159         return true;
160     }
161 
162 
163     /**
164      * Coverage tests for factory pattern API's.
165      *
166      * @return false if we should abort the test; true otherwise
167      */
testCase1()168     public boolean testCase1()
169     {
170         reporter.testCaseInit("Coverage tests for factory pattern API's");
171 
172         // protected TransformerFactory(){} not normally accessible - not tested
173         // public static TransformerFactory newInstance()
174         TransformerFactory factory = null;
175         // test when system property is user-set (i.e. whatever we started with)
176         try
177         {
178             reporter.logStatusMsg("System property " + defaultPropName
179                                   + " is: " + System.getProperty(defaultPropName));
180             factory = TransformerFactory.newInstance();
181             // No verification: just log what happened for user to see
182             reporter.logStatusMsg("factory.newInstance() is: " + factory.toString());
183         }
184         catch (Throwable t)
185         {
186             reporter.logStatusMsg("factory.newInstance() threw: " + t.toString());
187         }
188 
189         // test when system property is null
190         try
191         {
192             System.getProperties().remove(defaultPropName);
193             reporter.logStatusMsg("System property " + defaultPropName
194                                   + " is: " + System.getProperty(defaultPropName));
195             factory = TransformerFactory.newInstance();
196             reporter.logStatusMsg("factory.newInstance() is: " + factory.toString());
197         }
198         catch (Throwable t)
199         {
200             reporter.logStatusMsg("factory.newInstance() threw: " + t.toString());
201         }
202 
203         // test when system property is a bogus name
204         try
205         {
206             System.getProperties().put(defaultPropName, "this.class.does.not.exist");
207             reporter.logStatusMsg("System property " + defaultPropName
208                                   + " is: " + System.getProperty(defaultPropName));
209             factory = TransformerFactory.newInstance();
210             reporter.checkFail("factory.newInstance() with bogus name got: " + factory.toString());
211         }
212         catch (Throwable t)
213         {
214             reporter.checkPass("factory.newInstance() with bogus name properly threw: " + t.toString());
215             // Could also verify specific type of exception
216         }
217 
218         // test when system property is another kind of classname
219         try
220         {
221             System.getProperties().put(defaultPropName, "java.lang.String");
222             reporter.logStatusMsg("System property " + defaultPropName
223                                   + " is: " + System.getProperty(defaultPropName));
224             factory = TransformerFactory.newInstance();
225             reporter.checkFail("factory.newInstance() with bogus class got: " + factory.toString());
226         }
227         catch (Throwable t)
228         {
229             reporter.checkPass("factory.newInstance() with bogus class properly threw: " + t.toString());
230             // Could also verify specific type of exception
231         }
232 
233         // Reset the system property to what was cached previously
234         try
235         {
236             // This should come last so it will stay set for the rest of the test
237             // Note: this needs review, since in the future we may
238             //  not guaruntee order of testCase execution!
239             if (cachedSysProp == null)
240                 System.getProperties().remove(defaultPropName);
241             else
242                 System.getProperties().put(defaultPropName, cachedSysProp);
243 
244             reporter.logStatusMsg("System property (default) " + defaultPropName
245                                   + " is: " + System.getProperty(defaultPropName));
246             factory = TransformerFactory.newInstance();
247             reporter.checkPass("factory.newInstance() of default impl is: " + factory.toString());
248         }
249         catch (Throwable t)
250         {
251             reporter.checkFail("factory.newInstance() of default impl threw: " + t.toString());
252             reporter.logThrowable(reporter.ERRORMSG, t, "factory.newInstance() of default impl threw:");
253         }
254 
255         reporter.logStatusMsg("@todo code coverage for findFactory() method");
256 
257         reporter.testCaseClose();
258         return true;
259     }
260 
261 
262     /**
263      * Coverage tests for newTransformer() API's.
264      *
265      * @return false if we should abort the test; true otherwise
266      */
testCase2()267     public boolean testCase2()
268     {
269         reporter.testCaseInit("Coverage tests for newTransformer() API's");
270         TransformerFactory factory = null;
271 
272         try
273         {
274             reporter.logStatusMsg("System property " + defaultPropName
275                                   + " is: " + System.getProperty(defaultPropName));
276             factory = TransformerFactory.newInstance();
277             factory.setErrorListener(new DefaultErrorHandler());
278             Transformer identityTransformer = factory.newTransformer();
279             reporter.check((identityTransformer != null), true, "newTransformer() APICoverage");
280 
281             if (factory.getFeature(StreamSource.FEATURE))
282             {
283                 Transformer transformer = factory.newTransformer(new StreamSource(testFileInfo.inputName));
284                 reporter.check((transformer != null), true, "newTransformer(Source) APICoverage");
285             }
286             else
287                 reporter.logErrorMsg("NOTE: getFeature(StreamSource.FEATURE) false, can't test newTransformer(Source)");
288         }
289         catch (Throwable t)
290         {
291             reporter.checkFail("newTransformer() tests threw: " + t.toString());
292             reporter.logThrowable(reporter.ERRORMSG, t, "newTransformer() tests threw");
293         }
294 
295         reporter.testCaseClose();
296         return true;
297     }
298 
299 
300     /**
301      * Coverage tests for newTemplates() API's.
302      *
303      * @return false if we should abort the test; true otherwise
304      */
testCase3()305     public boolean testCase3()
306     {
307         reporter.testCaseInit("Coverage tests for newTemplates() API's");
308         TransformerFactory factory = null;
309 
310         try
311         {
312             reporter.logStatusMsg("System property " + defaultPropName
313                                   + " is: " + System.getProperty(defaultPropName));
314             factory = TransformerFactory.newInstance();
315             factory.setErrorListener(new DefaultErrorHandler());
316             if (factory.getFeature(StreamSource.FEATURE))
317             {
318                 Templates templates = factory.newTemplates(new StreamSource(testFileInfo.inputName));
319                 reporter.check((templates != null), true, "newTemplates(Source) APICoverage");
320             }
321             else
322                 reporter.logErrorMsg("NOTE: getFeature(StreamSource.FEATURE) false, can't test newTemplates(Source)");
323         }
324         catch (Throwable t)
325         {
326             reporter.checkFail("newTemplates() tests threw: " + t.toString());
327             reporter.logThrowable(reporter.ERRORMSG, t, "newTemplates() tests threw");
328         }
329 
330         reporter.testCaseClose();
331         return true;
332     }
333 
334 
335     /**
336      * Coverage tests for getAssociatedStylesheet() API's.
337      *
338      * @return false if we should abort the test; true otherwise
339      */
testCase4()340     public boolean testCase4()
341     {
342         reporter.testCaseInit("Coverage tests for getAssociatedStylesheet() API's");
343         TransformerFactory factory = null;
344 
345         try
346         {
347             reporter.logStatusMsg("System property " + defaultPropName
348                                   + " is: " + System.getProperty(defaultPropName));
349             factory = TransformerFactory.newInstance();
350             factory.setErrorListener(new DefaultErrorHandler());
351             String media= null;     // currently untested
352             String title = null;    // currently untested
353             String charset = null;  // currently untested
354 
355             // May throw IOException
356             FileOutputStream resultStream = new FileOutputStream(outNames.nextName());
357 
358             // Get the xml-stylesheet and process it
359             Source stylesheet = factory.getAssociatedStylesheet(new StreamSource(embeddedFileInfo.xmlName),
360                                                                 media, title, charset);
361             reporter.check((stylesheet instanceof Source), true, "getAssociatedStylesheet returns instanceof Source");
362             reporter.check((null != stylesheet), true, "getAssociatedStylesheet returns a non-null Source");
363 
364             Transformer transformer = factory.newTransformer(stylesheet);
365             transformer.setErrorListener(new DefaultErrorHandler());
366             reporter.logCriticalMsg("SPR SCUU4RXTSQ occours in below line, even though check reports pass (missing linefeed)");
367             transformer.transform(new StreamSource(embeddedFileInfo.xmlName), new StreamResult(resultStream));
368             resultStream.close();   // just in case
369             int result = fileChecker.check(reporter,
370                                            new File(outNames.currentName()),
371                                            new File(embeddedFileInfo.goldName),
372                                           "transform of getAssociatedStylesheet into " + outNames.currentName());
373             if (result == Logger.FAIL_RESULT)
374                 reporter.logInfoMsg("transform of getAssociatedStylesheet... failure reason:" + fileChecker.getExtendedInfo());
375         }
376         catch (Throwable t)
377         {
378             reporter.logThrowable(reporter.ERRORMSG, t, "getAssociatedStylesheet() tests threw:");
379         }
380 
381         reporter.testCaseClose();
382         return true;
383     }
384 
385 
386     /**
387      * Coverage tests for get/setURIResolver(), get/setErrorListener() API's.
388      *
389      * @return false if we should abort the test; true otherwise
390      */
testCase5()391     public boolean testCase5()
392     {
393         reporter.testCaseInit("Coverage tests for get/setURIResolver(), get/setErrorListener() API's");
394         TransformerFactory factory = null;
395         reporter.logStatusMsg("System property " + defaultPropName
396                               + " is: " + System.getProperty(defaultPropName));
397         try
398         {
399             factory = TransformerFactory.newInstance();
400             factory.setErrorListener(new DefaultErrorHandler());
401             URIResolver URIRes = factory.getURIResolver();
402             reporter.logInfoMsg("factory.getURIResolver() default is: " + URIRes);
403 
404             LoggingURIResolver loggingURIRes = new LoggingURIResolver(reporter);
405             factory.setURIResolver(loggingURIRes);
406             reporter.checkObject(factory.getURIResolver(), loggingURIRes, "set/getURIResolver API coverage");
407             factory.setURIResolver(null);
408             if (factory.getURIResolver() == null)
409             {
410                 reporter.checkPass("setURIResolver(null) is OK");
411             }
412             else
413             {
414                 reporter.checkFail("setURIResolver(null) not OK, is: " + factory.getURIResolver());
415             }
416         }
417         catch (Throwable t)
418         {
419             reporter.checkErr("Coverage of get/setURIResolver threw: " + t.toString());
420             reporter.logThrowable(reporter.STATUSMSG, t, "Coverage of get/setURIResolver threw:");
421         }
422         reporter.logStatusMsg("//@todo feature testing for URIResolver: see URIResolverTest.java");
423 
424         try
425         {
426             factory = TransformerFactory.newInstance();
427             ErrorListener errListener = factory.getErrorListener();
428             if (errListener == null)
429             {
430                 reporter.checkFail("getErrorListener() non-null by default");
431             }
432             else
433             {
434                 reporter.checkPass("getErrorListener() non-null by default, is: " + errListener);
435             }
436 
437             LoggingErrorListener loggingErrListener = new LoggingErrorListener(reporter);
438             factory.setErrorListener(loggingErrListener);
439             reporter.checkObject(factory.getErrorListener(), loggingErrListener, "set/getErrorListener API coverage(1)");
440             try
441             {
442                 factory.setErrorListener(null);
443                 reporter.checkFail("setErrorListener(null) worked, should have thrown exception");
444             }
445             catch (IllegalArgumentException iae)
446             {
447                 reporter.checkPass("setErrorListener(null) properly threw: " + iae.toString());
448             }
449             // Verify the previous ErrorListener is still set
450             reporter.checkObject(factory.getErrorListener(), loggingErrListener, "set/getErrorListener API coverage(2)");
451         }
452         catch (Throwable t)
453         {
454             reporter.checkErr("Coverage of get/setErrorListener threw: " + t.toString());
455             reporter.logThrowable(reporter.STATUSMSG, t, "Coverage of get/setErrorListener threw:");
456         }
457         reporter.logStatusMsg("//@todo feature testing for ErrorListener: see ErrorListenerAPITest.java, ErrorListenerTest.java");
458 
459         reporter.testCaseClose();
460         return true;
461     }
462 
463 
464     /**
465      * Miscellaneous tests.
466      * Bug/tests submitted by Bhakti.Mehta@eng.sun.com
467      *
468      * @return false if we should abort the test; true otherwise
469      */
testCase6()470     public boolean testCase6()
471     {
472         reporter.testCaseInit("Miscellaneous getAssociatedStylesheets tests");
473         TransformerFactory factory = null;
474         try
475         {
476             factory = TransformerFactory.newInstance();
477             factory.setErrorListener(new DefaultErrorHandler());
478 
479             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
480             DocumentBuilder db = dbf.newDocumentBuilder();
481 
482             // Note that embeddedCSSFileInfo has the following PI:
483             //  <?xml-stylesheet href="TransformerFactoryAPIModern.css" title="Modern" media="screen" type="text/css"?>
484             // Which we should return null from, since we only support
485             //  types that are properly mapped to xslt:
486             //  text/xsl, text/xml, and application/xml+xslt
487             //  see also EmbeddedStylesheetTest
488             Document doc = db.parse(new File(embeddedCSSFileInfo.xmlName));
489             DOMSource domSource = new DOMSource(doc);
490 
491             // TransformerFactory01.check01()
492             try
493             {
494                 reporter.logInfoMsg("About to getAssociatedStylesheet(domsource-w/outsystemid, screen,Modern,null)");
495                 Source s = factory.getAssociatedStylesheet(domSource,"screen","Modern",null);
496                 reporter.check((null == s), true, "getAssociatedStylesheet returns null Source for text/css");
497             }
498             catch (Throwable t)
499             {
500                 reporter.checkFail("TransformerFactory01.check01a threw: " + t.toString());
501                 reporter.logThrowable(reporter.STATUSMSG, t, "TransformerFactory01.check01a threw");
502             }
503             try
504             {
505                 domSource.setSystemId(QetestUtils.filenameToURL(embeddedCSSFileInfo.xmlName));
506                 reporter.logInfoMsg("About to getAssociatedStylesheet(domsource-w/systemid, screen,Modern,null)");
507                 Source s = factory.getAssociatedStylesheet(domSource,"screen","Modern",null);
508                 reporter.check((null == s), true, "getAssociatedStylesheet returns null Source for text/css");
509             }
510             catch (Throwable t)
511             {
512                 reporter.checkFail("TransformerFactory01.check01b threw: " + t.toString());
513                 reporter.logThrowable(reporter.STATUSMSG, t, "TransformerFactory01.check01b threw");
514             }
515 
516             // public void TransformerFactory02.check01(){
517             try
518             {
519                 StreamSource ss = new StreamSource(new FileInputStream(embeddedCSSFileInfo.xmlName));
520                 reporter.logInfoMsg("About to getAssociatedStylesheet(streamsource-w/outsystemid, screen,Modern,null)");
521                 Source s = factory.getAssociatedStylesheet(ss,"screen","Modern",null);
522                 reporter.check((null == s), true, "getAssociatedStylesheet returns null Source for text/css");
523             }
524             catch (Throwable t)
525             {
526                 reporter.checkFail("TransformerFactory02.check01a threw: " + t.toString());
527                 reporter.logThrowable(reporter.STATUSMSG, t, "TransformerFactory02.check01a threw");
528             }
529             try
530             {
531                 StreamSource ss = new StreamSource(new FileInputStream(embeddedCSSFileInfo.xmlName));
532                 ss.setSystemId(QetestUtils.filenameToURL(embeddedCSSFileInfo.xmlName));
533                 reporter.logInfoMsg("About to getAssociatedStylesheet(streamsource-w/systemid, screen,Modern,null)");
534                 Source s = factory.getAssociatedStylesheet(ss,"screen","Modern",null);
535                 reporter.check((null == s), true, "getAssociatedStylesheet returns null Source for text/css");
536             }
537             catch (Throwable t)
538             {
539                 reporter.checkFail("TransformerFactory02.check01b threw: " + t.toString());
540                 reporter.logThrowable(reporter.STATUSMSG, t, "TransformerFactory02.check01b threw");
541             }
542         }
543         catch (Throwable t)
544         {
545             reporter.checkErr("Miscellaneous getAssociatedStylesheets tests threw: " + t.toString());
546             reporter.logThrowable(reporter.STATUSMSG, t, "Miscellaneous getAssociatedStylesheets tests threw");
547         }
548 
549         reporter.testCaseClose();
550         return true;
551     }
552 
553 
554     /**
555      * Coverage tests for set/getFeature, set/getAttribute API's.
556      *
557      * @return false if we should abort the test; true otherwise
558      */
testCase7()559     public boolean testCase7()
560     {
561         reporter.testCaseInit("Coverage tests for set/getFeature, set/getAttribute API's");
562         // This test case should be JAXP-generic, and must not rely on Xalan-J 2.x functionality
563         reporter.logInfoMsg("Note: only simple validation: most are negative tests");
564         TransformerFactory factory = null;
565         final String BOGUS_NAME = "fnord:this/feature/does/not/exist";
566 
567         try
568         {
569             factory = TransformerFactory.newInstance();
570             try
571             {
572                 reporter.logStatusMsg("Calling: factory.getFeature(BOGUS_NAME)");
573                 boolean b = factory.getFeature(BOGUS_NAME);
574                 reporter.checkPass("factory.getFeature(BOGUS_NAME) did not throw exception");
575                 reporter.logStatusMsg("factory.getFeature(BOGUS_NAME) = " + b);
576             }
577             catch (IllegalArgumentException iae1)
578             {
579                 // This isn't documented, but is what I might expect
580                 reporter.checkPass("factory.getFeature(BOGUS_NAME) threw expected IllegalArgumentException");
581             }
582 
583             try
584             {
585                 reporter.logStatusMsg("Calling: factory.setAttribute(BOGUS_NAME,...)");
586                 factory.setAttribute(BOGUS_NAME, "on");
587                 reporter.checkFail("factory.setAttribute(BOGUS_NAME,...) did not throw expected exception");
588             }
589             catch (IllegalArgumentException iae2)
590             {
591                 reporter.checkPass("factory.setAttribute(BOGUS_NAME,...) threw expected IllegalArgumentException");
592             }
593 
594             try
595             {
596                 reporter.logStatusMsg("Calling: factory.getAttribute(BOGUS_NAME)");
597                 Object o = factory.getAttribute(BOGUS_NAME);
598                 reporter.checkFail("factory.getAttribute(BOGUS_NAME) did not throw expected exception");
599                 reporter.logStatusMsg("factory.getAttribute(BOGUS_NAME) = " + o);
600             }
601             catch (IllegalArgumentException iae3)
602             {
603                 reporter.checkPass("factory.getAttribute(BOGUS_NAME) threw expected IllegalArgumentException");
604             }
605         }
606         catch (Throwable t)
607         {
608             reporter.checkFail("getFeature/Attribute() tests threw: " + t.toString());
609             reporter.logThrowable(reporter.ERRORMSG, t, "getFeature/Attribute() tests threw");
610         }
611 
612         try
613         {
614             reporter.logWarningMsg("Note testing assumption: all factories must support Streams");
615             factory = TransformerFactory.newInstance();
616             reporter.logStatusMsg("Calling: factory.getFeature(StreamSource.FEATURE)");
617             boolean b = factory.getFeature(StreamSource.FEATURE);
618             reporter.check(b, true, "factory.getFeature(StreamSource.FEATURE)");
619 
620             reporter.logStatusMsg("Calling: factory.getFeature(StreamResult.FEATURE)");
621             b = factory.getFeature(StreamResult.FEATURE);
622             reporter.check(b, true, "factory.getFeature(StreamResult.FEATURE)");
623         }
624         catch (Throwable t)
625         {
626             reporter.checkFail("getFeature/Attribute()2 tests threw: " + t.toString());
627             reporter.logThrowable(reporter.ERRORMSG, t, "getFeature/Attribute()2 tests threw");
628         }
629 
630         try
631         {
632             reporter.logStatusMsg("Calling: factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
633             factory = TransformerFactory.newInstance();
634             try
635             {
636                 // All implementations are required to support the XMLConstants.FEATURE_SECURE_PROCESSING feature
637                 factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
638                 boolean b = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
639                 reporter.check(b, true, "factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
640                 factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, false);
641                 b = factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING);
642                 reporter.check(b, false, "factory.getFeature(XMLConstants.FEATURE_SECURE_PROCESSING)");
643 
644             }
645             catch (TransformerConfigurationException tce)
646             {
647                 reporter.checkFail("set/getFeature(XMLConstants.FEATURE_SECURE_PROCESSING) tests threw: " + tce.toString());
648                 reporter.logThrowable(reporter.ERRORMSG, tce, "set/getFeature(XMLConstants.FEATURE_SECURE_PROCESSING) tests threw");
649             }
650 
651             try
652             {
653                 factory.setFeature(BOGUS_NAME, true);
654                 reporter.checkFail("factory.setFeature(BOGUS_NAME) did not throw expected exception");
655 
656             }
657             catch (TransformerConfigurationException tce)
658             {
659                 reporter.checkPass("factory.setFeature(BOGUS_NAME) threw expected TransformerConfigurationException");
660             }
661 
662             try
663             {
664                 factory.setFeature(null, true);
665                 reporter.checkFail("factory.setFeature(null, true) did not throw expected exception");
666             }
667             catch (NullPointerException npe)
668 	    {
669 	        reporter.checkPass("factory.setFeature(null, true) threw expected NullPointerException");
670             }
671 
672         }
673         catch (Throwable t)
674         {
675             reporter.checkFail("set/getFeature() tests threw: " + t.toString());
676             reporter.logThrowable(reporter.ERRORMSG, t, "set/getFeature() tests threw");
677         }
678 
679         reporter.testCaseClose();
680         return true;
681     }
682 
683 
684     /**
685      * Convenience method to print out usage information - update if needed.
686      * @return String denoting usage of this test class
687      */
usage()688     public String usage()
689     {
690         return ("Common [optional] options supported by TransformerFactoryAPITest:\n"
691                 + "-transformerFactory <FQCN of TransformerFactoryImpl; default Xalan 2.x>\n"
692                 + "(Note: assumes inputDir=.\\tests\\api)\n"
693                 + super.usage());   // Grab our parent classes usage as well
694     }
695 
696 
697     /**
698      * Main method to run test from the command line - can be left alone.
699      * @param args command line argument array
700      */
main(String[] args)701     public static void main(String[] args)
702     {
703         TransformerFactoryAPITest app = new TransformerFactoryAPITest();
704         app.doMain(args);
705     }
706 }
707