/* * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ /* * @test * @bug 8159240 * @summary Check that whitespaces within schema types and names are * collapsed by XSOM parser * @modules jdk.xml.bind * jdk.xml.bind/com.sun.xml.internal.xsom * jdk.xml.bind/com.sun.xml.internal.xsom.parser * @run testng TestXSOM * */ import com.sun.xml.internal.xsom.XSSchemaSet; import com.sun.xml.internal.xsom.parser.XSOMParser; import java.io.File; import java.nio.file.Paths; import javax.xml.parsers.SAXParserFactory; import org.testng.Assert; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import org.xml.sax.ErrorHandler; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; public class TestXSOM { @Test(dataProvider = "WhitespacedTypes") public void testWhitespacesCollapse(String schemaFile) throws Exception { XSOMParser parser = new XSOMParser(SAXParserFactory.newInstance()); XsomErrorHandler eh = new XsomErrorHandler(); parser.setErrorHandler(eh); parser.parse(getSchemaFile(schemaFile)); XSSchemaSet sset = parser.getResult(); Assert.assertFalse(eh.gotError); Assert.assertNotNull(sset); } // Get location of schema file located in test source directory private static File getSchemaFile(String filename) { String testSrc = System.getProperty("test.src"); if (testSrc == null) { testSrc = "."; } return Paths.get(testSrc).resolve(filename).toFile(); } @DataProvider(name = "WhitespacedTypes") private Object[][] dataWhitespacedTypes() { return new Object[][]{ {"SimpleType.xsd"}, {"ComplexType.xsd"}, {"ComplexTypeExtension.xsd"}, {"ComplexTypeRestriction.xsd"}, {"IdentityConstraint.xsd"}, {"ParticlesAndAttributes.xsd"} }; } // Test XSOM error handler private static class XsomErrorHandler implements ErrorHandler { public boolean gotError = false; @Override public void warning(SAXParseException ex) throws SAXException { System.out.println("XSOM warning:" + ex); } @Override public void error(SAXParseException ex) throws SAXException { System.out.println("XSOM error:" + ex); gotError = true; } @Override public void fatalError(SAXParseException ex) throws SAXException { System.out.println("XSOM fatal error:" + ex); gotError = true; } } }