You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2017/09/13 16:48:09 UTC
svn commit: r1808256 - in /commons/proper/vfs/trunk/commons-vfs2/src/test:
java/org/apache/commons/vfs2/provider/zip/test/ resources/test-data/
resources/test-data/read-xml-tests/
Author: ggregory
Date: Wed Sep 13 16:48:08 2017
New Revision: 1808256
URL: http://svn.apache.org/viewvc?rev=1808256&view=rev
Log:
Add tests to parse XML files while validating with XSD files within the same zip file. I am seeing a closed input stream bug in an application that I am trying to reproduce.
Modified:
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ParseXmlInZipTestCase.java
commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/TestEntityResolver.java
commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests.zip
commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-invalid.xml
commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-not-well-formed.xml
commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-with-xsd-ref.xml
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ParseXmlInZipTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ParseXmlInZipTestCase.java?rev=1808256&r1=1808255&r2=1808256&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ParseXmlInZipTestCase.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/ParseXmlInZipTestCase.java Wed Sep 13 16:48:08 2017
@@ -49,8 +49,8 @@ public class ParseXmlInZipTestCase {
return newZipFile;
}
- private DocumentBuilder newDocumentBuilder(final FileObject sourceFile, final String pathToXsdInZip)
- throws IOException {
+ private DocumentBuilder newDocumentBuilder(final FileObject containerFile, final FileObject sourceFile,
+ final String pathToXsdInZip) throws IOException {
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
final boolean validate = pathToXsdInZip != null;
documentBuilderFactory.setValidating(validate);
@@ -59,7 +59,7 @@ public class ParseXmlInZipTestCase {
documentBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
@SuppressWarnings("resource")
- final FileObject schema = sourceFile.resolveFile(pathToXsdInZip);
+ final FileObject schema = containerFile.resolveFile(pathToXsdInZip);
if (schema.exists()) {
documentBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",
schema.getContent().getInputStream());
@@ -71,11 +71,11 @@ public class ParseXmlInZipTestCase {
DocumentBuilder documentBuilder = null;
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
- documentBuilder.setEntityResolver(new TestEntityResolver(sourceFile));
+ documentBuilder.setEntityResolver(new TestEntityResolver(containerFile, sourceFile));
} catch (final ParserConfigurationException e) {
throw new IOException("Cannot read Java Connector configuration: " + e, e);
}
- documentBuilder.setErrorHandler(new TestErrorHandler(sourceFile.toString()));
+ documentBuilder.setErrorHandler(new TestErrorHandler(containerFile + " - " + sourceFile));
return documentBuilder;
}
@@ -86,7 +86,7 @@ public class ParseXmlInZipTestCase {
final FileSystemManager manager = VFS.getManager();
try (final FileObject zipFileObject = manager.resolveFile(xmlFilePath)) {
try (final InputStream inputStream = zipFileObject.getContent().getInputStream()) {
- final Document document = newDocumentBuilder(zipFileObject, null).parse(inputStream);
+ final Document document = newDocumentBuilder(zipFileObject, zipFileObject, null).parse(inputStream);
Assert.assertNotNull(document);
}
}
@@ -135,7 +135,8 @@ public class ParseXmlInZipTestCase {
try (final FileObject zipFileObject = manager.resolveFile(zipFilePath)) {
try (final FileObject xmlFileObject = zipFileObject.resolveFile(path)) {
try (final InputStream inputStream = xmlFileObject.getContent().getInputStream()) {
- final Document document = newDocumentBuilder(zipFileObject, xsdPathInZip).parse(inputStream);
+ final Document document = newDocumentBuilder(zipFileObject, xmlFileObject, xsdPathInZip)
+ .parse(inputStream);
Assert.assertNotNull(document);
}
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/TestEntityResolver.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/TestEntityResolver.java?rev=1808256&r1=1808255&r2=1808256&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/TestEntityResolver.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/zip/test/TestEntityResolver.java Wed Sep 13 16:48:08 2017
@@ -14,21 +14,24 @@ import org.xml.sax.SAXException;
*/
public class TestEntityResolver implements EntityResolver {
+ private final FileObject containerFile;
private final FileObject sourceFile;
- public TestEntityResolver(final FileObject sourceFile) {
+ public TestEntityResolver(final FileObject containerFile, FileObject sourceFile) {
+ this.containerFile = containerFile;
this.sourceFile = sourceFile;
}
@Override
public InputSource resolveEntity(final String publicId, final String systemId) throws SAXException, IOException {
- System.out.println("resolving publicId=" + publicId + ", systemId=" + systemId);
+ // System.out.println("resolving publicId=" + publicId + ", systemId=" + systemId);
final String fileName = new File(URI.create(systemId).getPath()).getName();
- if (/*fileName.equals("person.xsd") || */fileName.equals("name.xsd") || fileName.equals("address.xsd")) {
+ if (/* fileName.equals("person.xsd") || */fileName.equals("name.xsd") || fileName.equals("address.xsd")) {
final String path = "/read-xml-tests/" + fileName;
final FileObject xsdFileObject = sourceFile.resolveFile(path);
if (!xsdFileObject.exists()) {
- throw new IllegalStateException("Schema " + path + " not found in file " + sourceFile);
+ throw new IllegalStateException(
+ "Schema " + path + " not found in file " + containerFile + " parsing " + sourceFile);
}
return new InputSource(xsdFileObject.getContent().getInputStream());
}
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests.zip
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests.zip?rev=1808256&r1=1808255&r2=1808256&view=diff
==============================================================================
Binary files - no diff available.
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-invalid.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-invalid.xml?rev=1808256&r1=1808255&r2=1808256&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-invalid.xml (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-invalid.xml Wed Sep 13 16:48:08 2017
@@ -2,7 +2,7 @@
<name
xmlns="https://www.apache.org/vfs/example/name"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="https://www.apache.org/xml/name.xsd">
+ xsi:schemaLocation="https://www.apache.org/xml/name.xsd name.xsd">
<FOO>John</FOO>
<middle>Q.</middle>
<last>Public</last>
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-not-well-formed.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-not-well-formed.xml?rev=1808256&r1=1808255&r2=1808256&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-not-well-formed.xml (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-not-well-formed.xml Wed Sep 13 16:48:08 2017
@@ -2,7 +2,7 @@
<name
xmlns="https://www.apache.org/vfs/example/name"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="https://www.apache.org/xml/name.xsd">
+ xsi:schemaLocation="https://www.apache.org/xml/name.xsd name.xsd">
<first>John</first>
<middle>Q.</middle>
<last>Public</last>
Modified: commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-with-xsd-ref.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-with-xsd-ref.xml?rev=1808256&r1=1808255&r2=1808256&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-with-xsd-ref.xml (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/test/resources/test-data/read-xml-tests/name-with-xsd-ref.xml Wed Sep 13 16:48:08 2017
@@ -2,7 +2,7 @@
<name
xmlns="https://www.apache.org/vfs/example/name"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="https://www.apache.org/xml/name.xsd">
+ xsi:schemaLocation="https://www.apache.org/xml/name.xsd name.xsd">
<first>John</first>
<middle>Q.</middle>
<last>Public</last>