Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/jaxp/transform/8079323/TemplatesTest.java
38860 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 807932326* @summary This file contains tests for Templates.27* @run testng/othervm TemplatesTest28*/2930import java.io.ByteArrayOutputStream;31import java.io.NotSerializableException;32import java.io.ObjectOutputStream;33import java.io.StringReader;34import javax.xml.transform.Templates;35import javax.xml.transform.Transformer;36import javax.xml.transform.TransformerFactory;37import javax.xml.transform.stream.StreamSource;38import org.testng.annotations.DataProvider;39import org.testng.annotations.Test;4041public class TemplatesTest {4243/**44* bug 8079323 Test Templates serialization45* <p>46* Serialization compatibility test: verify that serializing the Templates47* that contain auxiliary classes will result in a NotSerializableException48* due to the use of Xalan's non-serializable Hashtable.49*50* @param templates an instance of Templates51* @throws Exception as expected.52*/53@Test(dataProvider = "templates", expectedExceptions = NotSerializableException.class)54public void testSerialization(Templates templates) throws Exception {55Transformer xformer = templates.newTransformer();56try (ByteArrayOutputStream byteOut = new ByteArrayOutputStream();57ObjectOutputStream out = new ObjectOutputStream(byteOut);) {58out.writeObject(templates);59out.flush();60}61}6263/*64* DataProvider: Templates65*/66@DataProvider(name = "templates")67Object[][] getTemplates() throws Exception {68return new Object[][]{{TransformerFactory.newInstance().69newTemplates(new StreamSource(new StringReader(XSL)))}};70}7172static final String XSL = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"73+ "<xsl:stylesheet version=\"1.0\""74+ " xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">"75+ "<xsl:variable name=\"validAffectsRelClasses\">"76+ "</xsl:variable>"77+ "<xsl:key name=\"UniqueAffectsRelObjects\""78+ " match=\"/ObjectSetRoot/Object["79+ " contains($validAffectsRelClasses, @Class)]\""80+ " use=\"not(@OBID=preceding-sibling::Object["81+ " contains($validAffectsRelClasses, @Class)]/@OBID)\"/>"82+ "</xsl:stylesheet>";83}848586