Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/javax/xml/bind/xsom/8159240/WhitespacesTest.java
38862 views
/*1* Copyright (c) 2017, 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 815924026* @summary Check if types and names with whitespaces are collapsed by27* XSOM schema parser28* @compile -XDignore.symbol.file WhitespacesTest.java29* @run testng WhitespacesTest30*31*/3233import com.sun.xml.internal.xsom.parser.XSOMParser;34import java.io.File;35import java.nio.file.Paths;36import javax.xml.parsers.SAXParserFactory;37import org.testng.annotations.DataProvider;38import org.testng.annotations.Test;39import org.xml.sax.ErrorHandler;40import org.xml.sax.SAXException;41import org.xml.sax.SAXParseException;4243public class WhitespacesTest {4445@Test(dataProvider = "TestSchemaFiles")46public void testWhitespacesCollapse(String schemaFile) throws Exception {47XSOMParser parser = new XSOMParser(SAXParserFactory.newInstance());48XsomErrorHandler eh = new XsomErrorHandler();4950parser.setErrorHandler(eh);51parser.parse(getSchemaFile(schemaFile));5253if (eh.gotError) {54throw new RuntimeException("XSOM parser encountered error", eh.e);55}56}5758// Get location of schema file located in test source directory59private static File getSchemaFile(String filename) {60String testSrc = System.getProperty("test.src", ".");61return Paths.get(testSrc).resolve(filename).toFile();62}6364@DataProvider(name = "TestSchemaFiles")65private Object[][] dataTestSchemaFiles() {66return new Object[][] {67{"complexType.xsd"},68{"complexTypeExtension.xsd"},69{"complexTypeRestriction.xsd"},70{"identityConstraint.xsd"},71{"particlesAndAttributes.xsd"},72{"simpleType.xsd"}73};7475}7677// Test XSOM error handler78private static class XsomErrorHandler implements ErrorHandler {7980public boolean gotError = false;81public Exception e = null;8283@Override84public void warning(SAXParseException ex) throws SAXException {85System.err.println("XSOM warning:" + ex);86}8788@Override89public void error(SAXParseException ex) throws SAXException {90System.err.println("XSOM error:" + ex);91e = ex;92gotError = true;93}9495@Override96public void fatalError(SAXParseException ex) throws SAXException {97System.err.println("XSOM fatal error:" + ex);98e = ex;99gotError = true;100}101}102}103104105