1 /*
2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23 package transform;
24
25 import java.util.Properties;
26 import javax.xml.transform.Templates;
27 import javax.xml.transform.Transformer;
28 import javax.xml.transform.TransformerConfigurationException;
29 import javax.xml.transform.TransformerException;
30 import javax.xml.transform.TransformerFactory;
31 import javax.xml.transform.sax.SAXTransformerFactory;
32 import org.testng.Assert;
33 import org.testng.annotations.Test;
34 import org.xml.sax.XMLFilter;
35
36 /*
37 * @test
38 * @bug 8206164
39 * @modules java.xml
40 * @run testng transform.SAXTFactoryTest
41 * @summary Tests SAXTransformerFactory.
42 */
43 public class SAXTFactoryTest {
44
45 /*
46 * Verifies that the default ErrorListener throws a TransformerException
47 * when a fatal error is encountered. It is then wrapped and thrown again in
48 * a TransformerConfigurationException.
49 */
50 @Test
51 public void testErrorListener() throws Exception {
52 try {
53 SAXTransformerFactory saxTFactory =
54 (SAXTransformerFactory)TransformerFactory.newInstance();
55 XMLFilter filter = saxTFactory.newXMLFilter(new ATemplatesImpl());
56 } catch (TransformerConfigurationException tce) {
57 Throwable cause = tce.getCause();
58 Assert.assertTrue((cause != null && cause instanceof TransformerException),
59 "The TransformerFactoryImpl terminates upon a fatal error "
60 + "by throwing a TransformerException.");
61 }
62
63 }
64
65 class ATemplatesImpl implements Templates {
66
67 @Override
test()68 public Transformer newTransformer() throws TransformerConfigurationException {
69 throw new TransformerConfigurationException("TCE from ATemplatesImpl");
70 }
71
72 @Override
73 public Properties getOutputProperties() {
74 throw new UnsupportedOperationException("Not supported yet.");
75 }
76
77 }
getParser()78 }
79