8051710: Convert JAXP function tests: javax.xml.jaxp14.* to jtreg (testng) tests

Reviewed-by: lancea, joehw
This commit is contained in:
Frank Yuan 2015-01-30 19:10:29 -08:00 committed by Joe Wang
parent ffe5a2e589
commit 1b0daecb26
13 changed files with 1062 additions and 3 deletions

View File

@ -0,0 +1,74 @@
/*
* Copyright (c) 1999, 2015, 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.
*/
package javax.xml.datatype.ptests;
import static org.testng.Assert.assertNotNull;
import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.Duration;
import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPBaseTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
* @summary Tests for DatatypeFactory.newInstance(factoryClassName , classLoader)
*/
public class FactoryNewInstanceTest extends JAXPBaseTest {
private static final String DATATYPE_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl";
@DataProvider(name = "parameters")
public Object[][] getValidateParameters() {
return new Object[][] { { DATATYPE_FACTORY_CLASSNAME, null }, { DATATYPE_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
}
/*
* test for DatatypeFactory.newInstance(java.lang.String factoryClassName,
* java.lang.ClassLoader classLoader) factoryClassName points to correct
* implementation of javax.xml.datatype.DatatypeFactory , should return
* newInstance of DatatypeFactory
*/
@Test(dataProvider = "parameters")
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
DatatypeFactory dtf = DatatypeFactory.newInstance(DATATYPE_FACTORY_CLASSNAME, null);
Duration duration = dtf.newDuration(true, 1, 1, 1, 1, 1, 1);
assertNotNull(duration);
}
/*
* test for DatatypeFactory.newInstance(java.lang.String factoryClassName,
* java.lang.ClassLoader classLoader) factoryClassName is null , should
* throw DatatypeConfigurationException
*/
@Test(expectedExceptions = DatatypeConfigurationException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) throws DatatypeConfigurationException {
DatatypeFactory.newInstance(factoryClassName, classLoader);
}
}

View File

@ -26,27 +26,38 @@ package javax.xml.parsers.ptests;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilePermission;
import java.io.FileReader;
import static javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import static javax.xml.parsers.ptests.ParserTestConst.GOLDEN_DIR;
import static javax.xml.parsers.ptests.ParserTestConst.XML_DIR;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPFileBaseTest;
import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.compareWithGold;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -59,6 +70,52 @@ import org.xml.sax.helpers.DefaultHandler;
* This checks the methods of DocumentBuilderFactoryImpl.
*/
public class DocumentBuilderFactoryTest extends JAXPFileBaseTest {
/**
* DocumentBuilderFactory implementation class name.
*/
private static final String DOCUMENT_BUILDER_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl";
/**
* Provide valid DocumentBuilderFactory instantiation parameters.
*
* @return a data provider contains DocumentBuilderFactory instantiation parameters.
*/
@DataProvider(name = "parameters")
public Object[][] getValidateParameters() {
return new Object[][] { { DOCUMENT_BUILDER_FACTORY_CLASSNAME, null }, { DOCUMENT_BUILDER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
}
/**
* Test for DocumentBuilderFactory.newInstance(java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
* points to correct implementation of
* javax.xml.parsers.DocumentBuilderFactory , should return newInstance of
* DocumentBuilderFactory
*
* @param factoryClassName
* @param classLoader
* @throws ParserConfigurationException
*/
@Test(dataProvider = "parameters")
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(factoryClassName, classLoader);
DocumentBuilder builder = dbf.newDocumentBuilder();
assertNotNull(builder);
}
/**
* test for DocumentBuilderFactory.newInstance(java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is
* null , should throw FactoryConfigurationError
*
* @param factoryClassName
* @param classLoader
*/
@Test(expectedExceptions = FactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
DocumentBuilderFactory.newInstance(factoryClassName, classLoader);
}
/**
* Test the default functionality of schema support method.
* @throws Exception If any errors occur.

View File

@ -0,0 +1,75 @@
/*
* Copyright (c) 1999, 2015, 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.
*/
package javax.xml.parsers.ptests;
import static org.testng.Assert.assertNotNull;
import javax.xml.parsers.FactoryConfigurationError;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPBaseTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;
/*
* @summary Tests for SAXParserFactory.newInstance(factoryClassName , classLoader)
*/
public class SAXFactoryNewInstanceTest extends JAXPBaseTest {
private static final String SAXPARSER_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl";
@DataProvider(name = "parameters")
public Object[][] getValidateParameters() {
return new Object[][] { { SAXPARSER_FACTORY_CLASSNAME, null }, { SAXPARSER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
}
/*
* test for SAXParserFactory.newInstance(java.lang.String factoryClassName,
* java.lang.ClassLoader classLoader) factoryClassName points to correct
* implementation of javax.xml.parsers.SAXParserFactory , should return
* newInstance of SAXParserFactory
*/
@Test(dataProvider = "parameters")
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws ParserConfigurationException, SAXException {
SAXParserFactory spf = SAXParserFactory.newInstance(factoryClassName, classLoader);
SAXParser sp = spf.newSAXParser();
assertNotNull(sp);
}
/*
* test for SAXParserFactory.newInstance(java.lang.String factoryClassName,
* java.lang.ClassLoader classLoader) factoryClassName is null , should
* throw FactoryConfigurationError
*/
@Test(expectedExceptions = FactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
SAXParserFactory.newInstance(factoryClassName, classLoader);
}
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 1999, 2015, 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.
*/
package javax.xml.stream.ptests;
import static org.testng.Assert.assertNotNull;
import javax.xml.stream.XMLEventFactory;
import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPBaseTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
* @summary Tests for XMLEventFactory.newFactory(factoryId , classLoader)
*/
public class XMLEventFactoryNewInstanceTest extends JAXPBaseTest {
private static final String XMLEVENT_FACTORY_CLASSNAME = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
private static final String XMLEVENT_FACRORY_ID = "javax.xml.stream.XMLEventFactory";
@DataProvider(name = "parameters")
public Object[][] getValidateParameters() {
return new Object[][] { { XMLEVENT_FACRORY_ID, null }, { XMLEVENT_FACRORY_ID, this.getClass().getClassLoader() } };
}
/*
* test for XMLEventFactory.newFactory(java.lang.String factoryClassName,
* java.lang.ClassLoader classLoader) factoryClassName points to correct
* implementation of javax.xml.stream.XMLEventFactory , should return
* newInstance of XMLEventFactory
*/
@Test(dataProvider = "parameters")
public void testNewFactory(String factoryId, ClassLoader classLoader) {
setSystemProperty(XMLEVENT_FACRORY_ID, XMLEVENT_FACTORY_CLASSNAME);
try {
XMLEventFactory xef = XMLEventFactory.newFactory(factoryId, classLoader);
assertNotNull(xef);
} finally {
setSystemProperty(XMLEVENT_FACRORY_ID, null);
}
}
/*
* test for XMLEventFactory.newFactory(java.lang.String factoryClassName,
* java.lang.ClassLoader classLoader) factoryClassName is null , should
* throw NullPointerException
*/
@Test(expectedExceptions = NullPointerException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewFactoryNeg(String factoryId, ClassLoader classLoader) {
XMLEventFactory.newFactory(null, null);
}
}

View File

@ -0,0 +1,76 @@
/*
* Copyright (c) 1999, 2015, 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.
*/
package javax.xml.stream.ptests;
import static org.testng.Assert.assertNotNull;
import javax.xml.stream.XMLInputFactory;
import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPBaseTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/*
* @summary Tests for XMLInputFactory.newFactory(factoryId , classLoader)
*/
public class XMLInputFactoryNewInstanceTest extends JAXPBaseTest {
private static final String XMLINPUT_FACTORY_CLASSNAME = "com.sun.xml.internal.stream.XMLInputFactoryImpl";
private static final String XMLINPUT_FACRORY_ID = "javax.xml.stream.XMLInputFactory";
@DataProvider(name = "parameters")
public Object[][] getValidateParameters() {
return new Object[][] { { XMLINPUT_FACRORY_ID, null }, { XMLINPUT_FACRORY_ID, this.getClass().getClassLoader() } };
}
/*
* test for XMLInputFactory.newFactory(java.lang.String factoryId,
* java.lang.ClassLoader classLoader) factoryClassName points to correct
* implementation of javax.xml.stream.XMLInputFactory , should return
* newInstance of XMLInputFactory
*/
@Test(dataProvider = "parameters")
public void testNewFactory(String factoryId, ClassLoader classLoader) {
setSystemProperty(XMLINPUT_FACRORY_ID, XMLINPUT_FACTORY_CLASSNAME);
try {
XMLInputFactory xif = XMLInputFactory.newFactory(factoryId, classLoader);
assertNotNull(xif);
} finally {
setSystemProperty(XMLINPUT_FACRORY_ID, null);
}
}
/*
* test for XMLInputFactory.newFactory(java.lang.String factoryClassName,
* java.lang.ClassLoader classLoader) factoryClassName is null , should
* throw NullPointerException
*/
@Test(expectedExceptions = NullPointerException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewFactoryNeg(String factoryId, ClassLoader classLoader) {
XMLInputFactory.newFactory(factoryId, classLoader);
}
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 1999, 2015, 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.
*/
package javax.xml.transform.ptests;
import java.io.ByteArrayOutputStream;
import java.io.File;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import jaxp.library.JAXPFileBaseTest;
import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
/*
* @bug 6384418
* @summary verify the transforming won't throw any exception
*/
public class Bug6384418Test extends JAXPFileBaseTest {
@Test
public void test() throws Exception {
TransformerFactory tfactory = TransformerFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(new File(XML_DIR + "dataentry.xsl"));
DOMSource domSource = new DOMSource(document);
Transformer transformer = tfactory.newTransformer(domSource);
StreamSource streamSource = new StreamSource(new File(XML_DIR + "test.xml"));
StreamResult streamResult = new StreamResult(new ByteArrayOutputStream());
transformer.transform(streamSource, streamResult);
}
}

View File

@ -0,0 +1,383 @@
/*
* Copyright (c) 1999, 2015, 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.
*/
package javax.xml.transform.ptests;
import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.function.Supplier;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.stream.XMLEventWriter;
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.XMLStreamWriter;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.sax.SAXSource;
import javax.xml.transform.stax.StAXResult;
import javax.xml.transform.stax.StAXSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import jaxp.library.JAXPFileBaseTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
/*
* @summary Tests for variable combination of Transformer.transform(Source, Result)
*/
@Test(singleThreaded = true)
public class TransformTest extends JAXPFileBaseTest {
/*
* Initialize the share objects.
*/
@BeforeClass
public void setup() throws Exception {
ifac = XMLInputFactory.newInstance();
ofac = XMLOutputFactory.newInstance();
tfac = TransformerFactory.newInstance();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
db = dbf.newDocumentBuilder();
xml = Files.readAllBytes(Paths.get(XML_DIR + "cities.xml"));
template = Files.readAllBytes(Paths.get(XML_DIR + "cities.xsl"));
xmlDoc = db.parse(xmlInputStream());
}
@DataProvider(name = "input-provider")
public Object[][] prepareTestCombination() throws Exception {
Supplier<Source> staxStreamSource = () -> new StAXSource(getXMLStreamReader());
Supplier<Source> staxEventSource = this::getStAXEventSource;
Supplier<Source> domSource = () -> new DOMSource(xmlDoc);
Supplier<Source> saxSource = () -> new SAXSource(new InputSource(xmlInputStream()));
Supplier<Source> streamSource = () -> new StreamSource(xmlInputStream());
Supplier<Result> staxStreamResult = () -> new StAXResult(getXMLStreamWriter());
Supplier<Result> staxEventResult = () -> new StAXResult(getXMLEventWriter());
Supplier<Result> saxResult = this::getHandlerSAXResult;
Supplier<Result> streamResult = () -> new StreamResult(transOutputStream());
Transformer domTemplateTransformer = createTransformer(getDomTemplate());
Transformer saxTemplateTransformer = createTransformer(getSAXTemplate());
Transformer streamTemplateTransformer = createTransformer(getStreamTemplate());
Transformer noTemplateTransformer = createTransformer(null);
Transformer staxStreamTemplateTransformer = createTransformer(getStAXStreamTemplate());
Transformer staxEventTemplateTransformer = createTransformer(getStAXEventTemplate());
return new Object[][] {
// StAX Stream
{ staxStreamSource, staxStreamResult, domTemplateTransformer },
{ staxStreamSource, staxStreamResult, saxTemplateTransformer },
{ staxStreamSource, staxStreamResult, streamTemplateTransformer },
{ staxStreamSource, staxStreamResult, noTemplateTransformer },
{ staxStreamSource, staxStreamResult, staxStreamTemplateTransformer },
{ staxStreamSource, saxResult, domTemplateTransformer },
{ staxStreamSource, streamResult, domTemplateTransformer },
{ domSource, staxStreamResult, domTemplateTransformer },
{ saxSource, staxStreamResult, domTemplateTransformer },
{ streamSource, staxStreamResult, domTemplateTransformer },
{ staxStreamSource, streamResult, saxTemplateTransformer },
{ domSource, staxStreamResult, saxTemplateTransformer },
{ saxSource, staxStreamResult, saxTemplateTransformer },
{ streamSource, staxStreamResult, saxTemplateTransformer },
{ staxStreamSource, streamResult, streamTemplateTransformer },
{ domSource, staxStreamResult, streamTemplateTransformer },
{ saxSource, staxStreamResult, streamTemplateTransformer },
{ streamSource, staxStreamResult, streamTemplateTransformer },
// StAX Event
{ staxEventSource, staxEventResult, domTemplateTransformer },
{ staxEventSource, staxEventResult, saxTemplateTransformer },
{ staxEventSource, staxEventResult, streamTemplateTransformer },
{ staxEventSource, staxEventResult, noTemplateTransformer },
{ staxEventSource, staxEventResult, staxEventTemplateTransformer },
{ staxEventSource, saxResult, domTemplateTransformer },
{ staxEventSource, streamResult, domTemplateTransformer },
{ domSource, staxEventResult, domTemplateTransformer },
{ saxSource, staxEventResult, domTemplateTransformer },
{ streamSource, staxEventResult, domTemplateTransformer },
{ staxEventSource, streamResult, saxTemplateTransformer },
{ domSource, staxEventResult, saxTemplateTransformer },
{ saxSource, staxEventResult, saxTemplateTransformer },
{ streamSource, staxEventResult, saxTemplateTransformer },
{ staxEventSource, streamResult, streamTemplateTransformer },
{ domSource, staxEventResult, streamTemplateTransformer },
{ saxSource, staxEventResult, streamTemplateTransformer },
{ streamSource, staxEventResult, streamTemplateTransformer } };
}
/*
* run Transformer.transform(Source, Result)
*/
@Test(dataProvider = "input-provider")
public void testTransform(Supplier<Source> src, Supplier<Result> res, Transformer transformer) throws Throwable {
try {
transformer.transform(src.get(), res.get());
} catch (WrapperException e) {
throw e.getCause();
}
}
private InputStream xmlInputStream() {
return new ByteArrayInputStream(xml);
}
private InputStream templateInputStream() {
return new ByteArrayInputStream(template);
}
private OutputStream transOutputStream() {
return new ByteArrayOutputStream(xml.length);
}
private XMLStreamReader getXMLStreamReader() {
try {
return ifac.createXMLStreamReader(xmlInputStream());
} catch (XMLStreamException e) {
throw new WrapperException(e);
}
}
private XMLStreamWriter getXMLStreamWriter() {
try {
return ofac.createXMLStreamWriter(transOutputStream());
} catch (XMLStreamException e) {
throw new WrapperException(e);
}
}
private StAXSource getStAXEventSource() {
try {
return new StAXSource(ifac.createXMLEventReader(xmlInputStream()));
} catch (XMLStreamException e) {
throw new WrapperException(e);
}
}
private XMLEventWriter getXMLEventWriter() {
try {
return ofac.createXMLEventWriter(transOutputStream());
} catch (XMLStreamException e) {
throw new WrapperException(e);
}
}
private SAXResult getHandlerSAXResult() {
SAXResult res = new SAXResult();
MyContentHandler myContentHandler = new MyContentHandler(transOutputStream());
res.setHandler(myContentHandler);
return res;
}
private Source getDomTemplate() throws SAXException, IOException {
return new DOMSource(db.parse(templateInputStream()));
}
private Source getSAXTemplate() {
return new SAXSource(new InputSource(templateInputStream()));
}
private Source getStreamTemplate() {
return new StreamSource(templateInputStream());
}
private Source getStAXStreamTemplate() throws XMLStreamException {
return new StAXSource(ifac.createXMLStreamReader(templateInputStream()));
}
private Source getStAXEventTemplate() throws XMLStreamException {
return new StAXSource(ifac.createXMLEventReader(templateInputStream()));
}
private Transformer createTransformer(Source templateSource) throws TransformerConfigurationException {
Transformer transformer = (templateSource == null) ? tfac.newTransformer() : tfac.newTransformer(templateSource);
transformer.setOutputProperty("indent", "yes");
return transformer;
}
private static class MyContentHandler implements ContentHandler {
private BufferedWriter bWriter;
public MyContentHandler(OutputStream os) {
bWriter = new BufferedWriter(new OutputStreamWriter(os));
}
public void setDocumentLocator(Locator locator) {
}
public void startDocument() throws SAXException {
String str = "startDocument";
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void endDocument() throws SAXException {
String str = "endDocument";
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
bWriter.flush();
bWriter.close();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
String str = "startPrefixMapping: " + prefix + ", " + uri;
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void endPrefixMapping(String prefix) throws SAXException {
String str = "endPrefixMapping: " + prefix;
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
StringBuilder str = new StringBuilder("startElement: ").append(namespaceURI).append(", ").append(namespaceURI).append(", ").append(qName).append(" : ");
int n = atts.getLength();
for (int i = 0; i < n; i++) {
str.append(", ").append(atts.getQName(i)).append(" : ").append(atts.getValue(i));
}
try {
bWriter.write(str.toString(), 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
String str = "endElement: " + namespaceURI + ", " + namespaceURI + ", " + qName;
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void characters(char ch[], int start, int length) throws SAXException {
String str = new String(ch, start, length);
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void ignorableWhitespace(char ch[], int start, int length) throws SAXException {
String str = "ignorableWhitespace";
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void processingInstruction(String target, String data) throws SAXException {
String str = "processingInstruction: " + target + ", " + target;
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
public void skippedEntity(String name) throws SAXException {
String str = "skippedEntity: " + name;
try {
bWriter.write(str, 0, str.length());
bWriter.newLine();
} catch (IOException e) {
System.out.println("bWriter error");
}
}
}
private static class WrapperException extends RuntimeException {
public WrapperException(Throwable cause) {
super(cause);
}
}
private XMLInputFactory ifac;
private XMLOutputFactory ofac;
private TransformerFactory tfac;
private DocumentBuilder db;
private byte[] xml;
private byte[] template;
private Document xmlDoc;
}

View File

@ -23,25 +23,78 @@
package javax.xml.transform.ptests;
import java.io.*;
import java.io.FileOutputStream;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import static javax.xml.transform.ptests.TransformerTestConst.GOLDEN_DIR;
import static javax.xml.transform.ptests.TransformerTestConst.XML_DIR;
import javax.xml.transform.stream.*;
import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPFileBaseTest;
import static jaxp.library.JAXPTestUtilities.USER_DIR;
import static jaxp.library.JAXPTestUtilities.compareWithGold;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.w3c.dom.*;
/**
* Class containing the test cases for TransformerFactory API's
* getAssociatedStyleSheet method.
* getAssociatedStyleSheet method and TransformerFactory.newInstance(factoryClassName , classLoader).
*/
public class TransformerFactoryTest extends JAXPFileBaseTest {
/**
* TransformerFactory implementation class name.
*/
private static final String TRANSFORMER_FACTORY_CLASSNAME = "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl";
/**
* Provide valid TransformerFactory instantiation parameters.
*
* @return a data provider contains TransformerFactory instantiation parameters.
*/
@DataProvider(name = "parameters")
public Object[][] getValidateParameters() {
return new Object[][] { { TRANSFORMER_FACTORY_CLASSNAME, null }, { TRANSFORMER_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
}
/**
* Test for TransformerFactory.newInstance(java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
* points to correct implementation of
* javax.xml.transform.TransformerFactory , should return newInstance of
* TransformerFactory
*
* @param factoryClassName
* @param classLoader
* @throws TransformerConfigurationException
*/
@Test(dataProvider = "parameters")
public void testNewInstance(String factoryClassName, ClassLoader classLoader) throws TransformerConfigurationException {
TransformerFactory tf = TransformerFactory.newInstance(factoryClassName, classLoader);
Transformer transformer = tf.newTransformer();
assertNotNull(transformer);
}
/**
* Test for TransformerFactory.newInstance(java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName is
* null , should throw TransformerFactoryConfigurationError
*
* @param factoryClassName
* @param classLoader
*/
@Test(expectedExceptions = TransformerFactoryConfigurationError.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewInstanceNeg(String factoryClassName, ClassLoader classLoader) {
TransformerFactory.newInstance(factoryClassName, classLoader);
}
/**
* This test case checks for the getAssociatedStylesheet method
* of TransformerFactory.

View File

@ -0,0 +1,20 @@
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="dataentry">
<table cellspacing="0" cellpadding="0" width="85%" align="center"
class="color1" border="0">
<xsl:apply-templates/>
</table>
</xsl:template>
<xsl:template match="list">
<xsl:value-of select="self::node()[@multi='false']"/>
<!--
<xsl:if test="self::node()[@multi='false']">
<xsl:if test="self::node()">
FALSE<br/>
</xsl:if>
-->
</xsl:template>
</xsl:stylesheet>

View File

@ -0,0 +1,8 @@
<appcapp>
<dataentry>
<list multi="false">
<name>TypeOfLifeApp</name>
</list>
</dataentry>
</appcapp>

View File

@ -46,6 +46,8 @@ import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import jaxp.library.JAXPDataProvider;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
@ -81,6 +83,59 @@ public class SchemaFactoryTest {
xml = Files.readAllBytes(Paths.get(XML_DIR + "test.xml"));
}
@DataProvider(name = "parameters")
public Object[][] getValidateParameters() {
return new Object[][] { { W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, null },
{ W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
}
/*
* test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
* java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
* factoryClassName points to correct implementation of
* javax.xml.validation.SchemaFactory , should return newInstance of
* SchemaFactory
*/
@Test(dataProvider = "parameters")
public void testNewInstance(String schemaLanguage, String factoryClassName, ClassLoader classLoader) throws SAXException {
SchemaFactory sf = SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI, SCHEMA_FACTORY_CLASSNAME, null);
Schema schema = sf.newSchema();
assertNotNull(schema);
}
/*
* test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
* java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
* factoryClassName is null , should throw IllegalArgumentException
*/
@Test(expectedExceptions = IllegalArgumentException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewInstanceWithNullFactoryClassName(String factoryClassName, ClassLoader classLoader) {
SchemaFactory.newInstance(W3C_XML_SCHEMA_NS_URI, factoryClassName, classLoader);
}
/*
* test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
* java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
* schemaLanguage is null , should throw NPE
*/
@Test(expectedExceptions = NullPointerException.class)
public void testNewInstanceWithNullSchemaLanguage() {
SchemaFactory.newInstance(null, SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader());
}
/*
* test for SchemaFactory.newInstance(java.lang.String schemaLanguage,
* java.lang.String factoryClassName, java.lang.ClassLoader classLoader)
* schemaLanguage is empty , should throw IllegalArgumentException
*/
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNewInstanceWithEmptySchemaLanguage() {
SchemaFactory.newInstance("", SCHEMA_FACTORY_CLASSNAME, this.getClass().getClassLoader());
}
@Test(expectedExceptions = SAXParseException.class)
public void testNewSchemaDefault() throws SAXException, IOException {
validate(sf.newSchema());
@ -288,6 +343,8 @@ public class SchemaFactoryTest {
private static final String UNRECOGNIZED_NAME = "http://xml.org/sax/features/namespace-prefixes";
private static final String SCHEMA_FACTORY_CLASSNAME = "com.sun.org.apache.xerces.internal.jaxp.validation.XMLSchemaFactory";
private SchemaFactory sf;
private byte[] xsd1;
private byte[] xsd2;

View File

@ -24,10 +24,16 @@
package javax.xml.xpath.ptests;
import static javax.xml.xpath.XPathConstants.DOM_OBJECT_MODEL;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import javax.xml.xpath.XPathFactoryConfigurationException;
import jaxp.library.JAXPDataProvider;
import jaxp.library.JAXPBaseTest;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.Assert.assertNotNull;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
/**
@ -44,6 +50,78 @@ public class XPathFactoryTest extends JAXPBaseTest {
*/
private static final String INVALID_URL = "http://java.sun.com/jaxp/xpath/dom1";
/**
* XPathFactory implementation class name.
*/
private static final String XPATH_FACTORY_CLASSNAME = "com.sun.org.apache.xpath.internal.jaxp.XPathFactoryImpl";
/**
* Provide valid XPathFactory instantiation parameters.
*
* @return a data provider contains XPathFactory instantiation parameters.
*/
@DataProvider(name = "parameters")
public Object[][] getValidateParameters() {
return new Object[][] { { VALID_URL, XPATH_FACTORY_CLASSNAME, null }, { VALID_URL, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader() } };
}
/**
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader) factoryClassName
* points to correct implementation of javax.xml.xpath.XPathFactory , should
* return newInstance of XPathFactory
*
* @param uri
* @param factoryClassName
* @param classLoader
* @throws XPathFactoryConfigurationException
*/
@Test(dataProvider = "parameters")
public void testNewInstance(String uri, String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
XPathFactory xpf = XPathFactory.newInstance(uri, factoryClassName, classLoader);
XPath xpath = xpf.newXPath();
assertNotNull(xpath);
}
/**
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader)
*
* @param factoryClassName
* @param classLoader
* @throws XPathFactoryConfigurationException
* is expected when factoryClassName is null
*/
@Test(expectedExceptions = XPathFactoryConfigurationException.class, dataProvider = "new-instance-neg", dataProviderClass = JAXPDataProvider.class)
public void testNewInstanceWithNullFactoryClassName(String factoryClassName, ClassLoader classLoader) throws XPathFactoryConfigurationException {
XPathFactory.newInstance(VALID_URL, factoryClassName, classLoader);
}
/**
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader) uri is null , should
* throw NPE
*
* @throws XPathFactoryConfigurationException
*/
@Test(expectedExceptions = NullPointerException.class)
public void testNewInstanceWithNullUri() throws XPathFactoryConfigurationException {
XPathFactory.newInstance(null, XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader());
}
/**
* Test for XPathFactory.newInstance(java.lang.String uri, java.lang.String
* factoryClassName, java.lang.ClassLoader classLoader)
*
* @throws IllegalArgumentException
* is expected when uri is empty
*/
@Test(expectedExceptions = IllegalArgumentException.class)
public void testNewInstanceWithEmptyUri() throws XPathFactoryConfigurationException {
XPathFactory.newInstance("", XPATH_FACTORY_CLASSNAME, this.getClass().getClassLoader());
}
/**
* Test for constructor - XPathFactory.newInstance().
*/

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2015, 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.
*/
package jaxp.library;
import org.testng.annotations.DataProvider;
/**
* Provide invalid parameters for negative testing Factory.newInstance.
*/
public class JAXPDataProvider {
@DataProvider(name = "new-instance-neg")
public static Object[][] getNewInstanceNeg() {
return new Object[][] { { null, null }, { null, JAXPDataProvider.class.getClassLoader() } };
}
}