< prev index next >
test/javax/xml/jaxp/functional/org/xml/sax/ptests/ParserAdapterTest.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2014, 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.
--- 1,7 ----
/*
! * Copyright (c) 2003, 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.
*** 21,43 ****
* questions.
*/
package org.xml.sax.ptests;
import java.io.FileInputStream;
- import java.io.IOException;
- import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
! import static jaxp.library.JAXPTestUtilities.failUnexpected;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
- import org.xml.sax.SAXNotSupportedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.ParserAdapter;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.helpers.XMLReaderAdapter;
import static org.xml.sax.ptests.SAXTestConst.XML_DIR;
--- 21,40 ----
* questions.
*/
package org.xml.sax.ptests;
import java.io.FileInputStream;
import javax.xml.parsers.SAXParserFactory;
! import jaxp.library.JAXPFileReadOnlyBaseTest;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.testng.annotations.Test;
import org.xml.sax.ContentHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.ParserAdapter;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.helpers.XMLReaderAdapter;
import static org.xml.sax.ptests.SAXTestConst.XML_DIR;
*** 45,55 ****
/**
* Unit test cases for ParserAdapter API. By default the only features recognized
* are namespaces and namespace-prefixes.
*/
! public class ParserAdapterTest {
/**
* namespaces feature name.
*/
private static final String NAMESPACES =
"http://xml.org/sax/features/namespaces";
--- 42,52 ----
/**
* Unit test cases for ParserAdapter API. By default the only features recognized
* are namespaces and namespace-prefixes.
*/
! public class ParserAdapterTest extends JAXPFileReadOnlyBaseTest {
/**
* namespaces feature name.
*/
private static final String NAMESPACES =
"http://xml.org/sax/features/namespaces";
*** 65,78 ****
*/
private final ParserAdapter parserAdapter;
/**
* Initiate ParserAdapter.
! * @throws ParserConfigurationException
! * @throws SAXException
*/
! ParserAdapterTest() throws ParserConfigurationException, SAXException {
SAXParserFactory spf = SAXParserFactory.newInstance();
XMLReader xmlReader = spf.newSAXParser().getXMLReader();
XMLReaderAdapter xmlReaderAdapter = new XMLReaderAdapter(xmlReader);
parserAdapter = new ParserAdapter(xmlReaderAdapter);
}
--- 62,74 ----
*/
private final ParserAdapter parserAdapter;
/**
* Initiate ParserAdapter.
! * @throws Exception If any errors occur.
*/
! ParserAdapterTest() throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
XMLReader xmlReader = spf.newSAXParser().getXMLReader();
XMLReaderAdapter xmlReaderAdapter = new XMLReaderAdapter(xmlReader);
parserAdapter = new ParserAdapter(xmlReaderAdapter);
}
*** 149,279 ****
parserAdapter.setErrorHandler(null);
}
/**
* parserAdapter.getFeature(NAMESPACES) returns true be default.
*/
@Test
! public void getFeature01() {
! try {
assertTrue(parserAdapter.getFeature(NAMESPACES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* parserAdapter.getFeature(NAMESPACE_PREFIXES) returns true be default.
*/
@Test
! public void getFeature02() {
! try {
assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* SAXNotRecognizedException thrown when feature name is not known one.
! * @throws org.xml.sax.SAXNotRecognizedException expected Exception
*/
@Test(expectedExceptions = SAXNotRecognizedException.class)
! public void getFeature03() throws SAXNotRecognizedException {
! try {
parserAdapter.getFeature("no-meaning-feature");
- } catch (SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* Obtain getFeature after it's set returns set value.
*/
@Test
! public void setFeature01() {
! try {
parserAdapter.setFeature(NAMESPACES, false);
assertFalse(parserAdapter.getFeature(NAMESPACES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* Obtain getFeature after it's set returns set value.
*/
@Test
! public void setFeature02() {
! try {
parserAdapter.setFeature(NAMESPACE_PREFIXES, false);
assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* Obtain getFeature after it's set returns set value.
*/
@Test
! public void setFeature03() {
! try {
parserAdapter.setFeature(NAMESPACES, true);
assertTrue(parserAdapter.getFeature(NAMESPACES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* Obtain getFeature after it's set returns set value.
*/
@Test
! public void setFeature04() {
! try {
parserAdapter.setFeature(NAMESPACE_PREFIXES, true);
assertTrue(parserAdapter.getFeature(NAMESPACE_PREFIXES));
- } catch (SAXNotRecognizedException | SAXNotSupportedException ex) {
- failUnexpected(ex);
- }
}
/**
* NPE expected when parsing a null object by ParserAdapter.
*/
@Test(expectedExceptions = NullPointerException.class)
! public void parse01() {
! try {
parserAdapter.parse((InputSource)null);
- } catch (IOException | SAXException ex) {
- failUnexpected(ex);
- }
}
/**
* SAXException expected when parsing a wrong-formatter XML with ParserAdapter.
! * @throws org.xml.sax.SAXException
*/
! @Test(expectedExceptions = SAXException.class)
! public void parse02() throws SAXException {
try(FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")) {
InputSource is = new InputSource(fis);
parserAdapter.parse(is);
- } catch (IOException ex) {
- failUnexpected(ex);
}
}
/**
* Parse a well-formatter XML with ParserAdapter.
*/
! @Test
! public void parse03() {
try(FileInputStream fis = new FileInputStream(XML_DIR + "correct.xml")) {
InputSource is = new InputSource(fis);
parserAdapter.parse(is);
- } catch (IOException | SAXException ex) {
- failUnexpected(ex);
}
}
}
--- 145,257 ----
parserAdapter.setErrorHandler(null);
}
/**
* parserAdapter.getFeature(NAMESPACES) returns true be default.
+ *
+ * @exception Exception If any errors occur.
*/
@Test
! public void getFeature01() throws Exception {
assertTrue(parserAdapter.getFeature(NAMESPACES));
}
/**
* parserAdapter.getFeature(NAMESPACE_PREFIXES) returns true be default.
+ *
+ * @exception Exception If any errors occur.
*/
@Test
! public void getFeature02() throws Exception {
assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES));
}
/**
* SAXNotRecognizedException thrown when feature name is not known one.
! *
! * @exception Exception If any errors occur.
*/
@Test(expectedExceptions = SAXNotRecognizedException.class)
! public void getFeature03() throws Exception {
parserAdapter.getFeature("no-meaning-feature");
}
/**
* Obtain getFeature after it's set returns set value.
+ *
+ * @exception Exception If any errors occur.
*/
@Test
! public void setFeature01() throws Exception {
parserAdapter.setFeature(NAMESPACES, false);
assertFalse(parserAdapter.getFeature(NAMESPACES));
}
/**
* Obtain getFeature after it's set returns set value.
+ *
+ * @exception Exception If any errors occur.
*/
@Test
! public void setFeature02() throws Exception {
parserAdapter.setFeature(NAMESPACE_PREFIXES, false);
assertFalse(parserAdapter.getFeature(NAMESPACE_PREFIXES));
}
/**
* Obtain getFeature after it's set returns set value.
+ *
+ * @exception Exception If any errors occur.
*/
@Test
! public void setFeature03() throws Exception {
parserAdapter.setFeature(NAMESPACES, true);
assertTrue(parserAdapter.getFeature(NAMESPACES));
}
/**
* Obtain getFeature after it's set returns set value.
+ *
+ * @exception Exception If any errors occur.
*/
@Test
! public void setFeature04() throws Exception {
parserAdapter.setFeature(NAMESPACE_PREFIXES, true);
assertTrue(parserAdapter.getFeature(NAMESPACE_PREFIXES));
}
/**
* NPE expected when parsing a null object by ParserAdapter.
+ *
+ * @throws Exception If any errors occur.
*/
@Test(expectedExceptions = NullPointerException.class)
! public void parse01() throws Exception {
parserAdapter.parse((InputSource)null);
}
/**
* SAXException expected when parsing a wrong-formatter XML with ParserAdapter.
! *
! * @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"}, expectedExceptions = SAXException.class)
! public void parse02() throws Exception {
try(FileInputStream fis = new FileInputStream(XML_DIR + "invalid.xml")) {
InputSource is = new InputSource(fis);
parserAdapter.parse(is);
}
}
/**
* Parse a well-formatter XML with ParserAdapter.
+ *
+ * @throws Exception If any errors occur.
*/
! @Test(groups = {"readLocalFiles"})
! public void parse03() throws Exception {
try(FileInputStream fis = new FileInputStream(XML_DIR + "correct.xml")) {
InputSource is = new InputSource(fis);
parserAdapter.parse(is);
}
}
}
< prev index next >