Repository: any23 Updated Branches: refs/heads/master f9f316435 -> cb9209aa2
ANY23-360 Resolved Xerces deprecation warnings Project: http://git-wip-us.apache.org/repos/asf/any23/repo Commit: http://git-wip-us.apache.org/repos/asf/any23/commit/cb9209aa Tree: http://git-wip-us.apache.org/repos/asf/any23/tree/cb9209aa Diff: http://git-wip-us.apache.org/repos/asf/any23/diff/cb9209aa Branch: refs/heads/master Commit: cb9209aa2c1ce51a8d3d06f2c7a6d787d8e552d2 Parents: f9f3164 Author: Hans <[email protected]> Authored: Mon Jul 9 20:02:15 2018 -0500 Committer: Hans <[email protected]> Committed: Mon Jul 9 20:02:15 2018 -0500 ---------------------------------------------------------------------- .../any23/validator/DefaultValidatorTest.java | 80 ++++++++------------ 1 file changed, 32 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/any23/blob/cb9209aa/core/src/test/java/org/apache/any23/validator/DefaultValidatorTest.java ---------------------------------------------------------------------- diff --git a/core/src/test/java/org/apache/any23/validator/DefaultValidatorTest.java b/core/src/test/java/org/apache/any23/validator/DefaultValidatorTest.java index 13f393b..7ebafb6 100644 --- a/core/src/test/java/org/apache/any23/validator/DefaultValidatorTest.java +++ b/core/src/test/java/org/apache/any23/validator/DefaultValidatorTest.java @@ -17,9 +17,8 @@ package org.apache.any23.validator; +import org.apache.any23.extractor.html.DomUtils; import org.apache.any23.extractor.html.TagSoupParser; -import org.apache.xml.serialize.OutputFormat; -import org.apache.xml.serialize.XMLSerializer; import org.junit.After; import org.junit.Assert; import org.junit.Before; @@ -28,7 +27,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Node; -import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.URI; @@ -69,48 +67,48 @@ public class DefaultValidatorTest { @Test public void testMissingOGNamespace() throws IOException, ValidatorException, URISyntaxException { DOMDocument document = loadDocument("missing-og-namespace.html"); - Assert.assertNull( document.getNode("/HTML").getAttributes().getNamedItem("xmlns:og") ); + Assert.assertNull(document.getNode("/HTML").getAttributes().getNamedItem("xmlns:og")); ValidationReport validationReport = validator.validate(document, true); - Assert.assertNotNull( document.getNode("/HTML").getAttributes().getNamedItem("xmlns:og") ); - if(logger.isDebugEnabled()) { - logger.debug( validationReport.toString() ); + Assert.assertNotNull(document.getNode("/HTML").getAttributes().getNamedItem("xmlns:og")); + if (logger.isDebugEnabled()) { + logger.debug(validationReport.toString()); } } @Test public void testMissingItemscopeAttributeValue() throws IOException, URISyntaxException, ValidatorException { - DOMDocument document = loadDocument("microdata-basic.html"); - List<Node> nullItemScopeNodes = document.getNodesWithAttribute("itemscope"); - for (Node node : nullItemScopeNodes) { + DOMDocument document = loadDocument("microdata-basic.html"); + List<Node> nullItemScopeNodes = document.getNodesWithAttribute("itemscope"); + for (Node node : nullItemScopeNodes) { // all nodes with itemscope have an empty string value - Assert.assertEquals("", node.getAttributes().getNamedItem("itemscope").getNodeValue() ); - } - ValidationReport validationReport = validator.validate(document, true); - List<Node> fixedItemScopeNodes = document.getNodesWithAttribute("itemscope"); - for (Node node : fixedItemScopeNodes) { - // all nodes with itemscope now have a default value of "itemscope" - Assert.assertNotNull(node.getAttributes().getNamedItem("itemscope").getNodeValue() ); - Assert.assertEquals("itemscope", node.getAttributes().getNamedItem("itemscope").getNodeValue() ); - } - if(logger.isDebugEnabled()) { - logger.debug( validationReport.toString() ); - } - } + Assert.assertEquals("", node.getAttributes().getNamedItem("itemscope").getNodeValue()); + } + ValidationReport validationReport = validator.validate(document, true); + List<Node> fixedItemScopeNodes = document.getNodesWithAttribute("itemscope"); + for (Node node : fixedItemScopeNodes) { + // all nodes with itemscope now have a default value of "itemscope" + Assert.assertNotNull(node.getAttributes().getNamedItem("itemscope").getNodeValue()); + Assert.assertEquals("itemscope", node.getAttributes().getNamedItem("itemscope").getNodeValue()); + } + if (logger.isDebugEnabled()) { + logger.debug(validationReport.toString()); + } + } @Test public void testMetaNameMisuse() throws Exception { DOMDocument document = loadDocument("meta-name-misuse.html"); ValidationReport validationReport = validator.validate(document, true); - logger.debug( validationReport.toString() ); - if(logger.isDebugEnabled()) { - logger.debug( serialize(document) ); + if (logger.isDebugEnabled()) { + logger.debug(validationReport.toString()); + logger.debug(DomUtils.serializeToXML(document.getOriginalDocument(), true)); } List<Node> metas = document.getNodes("/HTML/HEAD/META"); - for(Node meta : metas) { + for (Node meta : metas) { Node name = meta.getAttributes().getNamedItem("name"); - if(name != null) { - Assert.assertFalse( name.getTextContent().contains(":") ); + if (name != null) { + Assert.assertFalse(name.getTextContent().contains(":")); } } } @@ -119,31 +117,17 @@ public class DefaultValidatorTest { public void testAboutNotIRIRule() throws Exception { DOMDocument document = loadDocument("invalid-rdfa-about.html"); ValidationReport validationReport = validator.validate(document, true); - logger.debug(validationReport.toString()); - Assert.assertEquals( "Unexpected number of issues.", 1, validationReport.getIssues().size() ); + if (logger.isDebugEnabled()) { + logger.debug(validationReport.toString()); + } + Assert.assertEquals("Unexpected number of issues.", 1, validationReport.getIssues().size()); } public static DOMDocument loadDocument(String document) throws IOException, URISyntaxException { InputStream is = DefaultValidatorTest.class.getResourceAsStream(document); final String documentIRI = "http://test.com"; TagSoupParser tsp = new TagSoupParser(is, documentIRI); - return new DefaultDOMDocument( new URI(documentIRI), tsp.getDOM() ); - } - - private String serialize(DOMDocument document) throws Exception { - OutputFormat format = new OutputFormat(document.getOriginalDocument()); - format.setLineSeparator("\n"); - format.setIndenting(true); - format.setLineWidth(0); - format.setPreserveSpace(true); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - XMLSerializer serializer = new XMLSerializer( - baos, - format - ); - serializer.asDOMSerializer(); - serializer.serialize( document.getOriginalDocument() ); - return baos.toString(); + return new DefaultDOMDocument(new URI(documentIRI), tsp.getDOM()); } class FakeRule implements Rule {
