You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@any23.apache.org by mo...@apache.org on 2012/02/05 14:01:04 UTC

svn commit: r1240713 - in /incubator/any23/trunk/core/src/test: java/org/apache/any23/extractor/html/ java/org/apache/any23/extractor/rdfa/ resources/html/rdfa/

Author: mostarda
Date: Sun Feb  5 13:01:03 2012
New Revision: 1240713

URL: http://svn.apache.org/viewvc?rev=1240713&view=rev
Log:
Changed behavior of assertExtracts to verify also issues by default.
Added flag to disable verification. Removed custom verification logic
from RDFa11ExtractorTest. Refactored tests to be compliant with issue
verification.

Modified:
    incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/AbstractExtractorTestCase.java
    incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/LicenseExtractorTest.java
    incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/RDFMergerTest.java
    incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java
    incubator/any23/trunk/core/src/test/resources/html/rdfa/basic.html
    incubator/any23/trunk/core/src/test/resources/html/rdfa/incomplete-triples.html
    incubator/any23/trunk/core/src/test/resources/html/rdfa/rdfa-11-curies.html

Modified: incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/AbstractExtractorTestCase.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/AbstractExtractorTestCase.java?rev=1240713&r1=1240712&r2=1240713&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/AbstractExtractorTestCase.java (original)
+++ incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/AbstractExtractorTestCase.java Sun Feb  5 13:01:03 2012
@@ -144,6 +144,15 @@ public abstract class AbstractExtractorT
     }
 
     /**
+     * Returns the list of errors raised by the extractor under testing.
+     *
+     * @return collection of errors.
+     */
+    protected Collection<ErrorReporter.Error> getErrors() {
+        return getErrors( getExtractorFactory().getExtractorName() );
+    }
+
+    /**
      * Applies the extractor provided by the {@link #getExtractorFactory()} to the specified resource.
      *
      * @param resource resource name.
@@ -163,13 +172,15 @@ public abstract class AbstractExtractorT
 
     /**
      * Performs data extraction over the content of a resource
-     * and assert that the extraction was correct.
+     * and assert that the extraction was fine.
      *
      * @param resource resource name.
+     * @param assertNoIssues if <code>true</code>invokes {@link #assertNoIssues()}  after the extraction.
      */
-    protected void assertExtracts(String resource) {
+    protected void assertExtracts(String resource, boolean assertNoIssues) {
         try {
             extract(resource);
+            if(assertNoIssues) assertNoIssues();
         } catch (ExtractionException ex) {
             throw new RuntimeException(ex);
         } catch (IOException ex) {
@@ -178,6 +189,16 @@ public abstract class AbstractExtractorT
     }
 
     /**
+     * Performs data extraction over the content of a resource
+     *  and assert that the extraction was fine and raised no issues.
+     *
+     * @param resource
+     */
+    protected void assertExtracts(String resource) {
+        assertExtracts(resource, true);
+    }
+
+    /**
      * Asserts that the extracted triples contain the pattern <code>(_ p o)</code>.
      *
      * @param p predicate

Modified: incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/LicenseExtractorTest.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/LicenseExtractorTest.java?rev=1240713&r1=1240712&r2=1240713&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/LicenseExtractorTest.java (original)
+++ incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/LicenseExtractorTest.java Sun Feb  5 13:01:03 2012
@@ -17,14 +17,18 @@
 
 package org.apache.any23.extractor.html;
 
+import org.apache.any23.extractor.ErrorReporter;
 import org.apache.any23.extractor.ExtractorFactory;
 import org.apache.any23.rdf.RDFUtils;
 import org.apache.any23.vocab.SINDICE;
 import org.apache.any23.vocab.XHTML;
+import org.junit.Assert;
 import org.junit.Test;
 import org.openrdf.model.URI;
 import org.openrdf.repository.RepositoryException;
 
+import java.util.Collection;
+
 /**
  *
  * Reference Test class for the {@link LicenseExtractor} extractor.
@@ -66,9 +70,15 @@ public class LicenseExtractorTest extend
 
     @Test
     public void testMultipleEmptyHref() throws RepositoryException {
-        assertExtracts("microformats/license/multiple-empty-href.html");
+        assertExtracts("microformats/license/multiple-empty-href.html", false);
         assertNotContains(baseURI, vXHTML.license, "");
         assertContains(baseURI, vXHTML.license, apache);
+        
+        final Collection<ErrorReporter.Error> errors = getErrors();
+        Assert.assertEquals(1, errors.size());
+        ErrorReporter.Error error = errors.iterator().next();
+        Assert.assertTrue(error.getMessage().contains("Invalid license link detected"));
+        Assert.assertEquals(ErrorReporter.ErrorLevel.WARN, error.getLevel());
     }
 
     @Test

Modified: incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/RDFMergerTest.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/RDFMergerTest.java?rev=1240713&r1=1240712&r2=1240713&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/RDFMergerTest.java (original)
+++ incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/html/RDFMergerTest.java Sun Feb  5 13:01:03 2012
@@ -74,7 +74,7 @@ public class RDFMergerTest extends Abstr
 
     @Test
     public void test01XFNFoaf() throws RepositoryException {
-        assertExtracts("mixed/01-xfn-foaf.html");
+        assertExtracts("mixed/01-xfn-foaf.html", false);
         assertModelNotEmpty();
         assertStatementsSize(RDF.TYPE, vVCARD.VCard, 1);
         Resource vcard = findExactlyOneBlankSubject(RDF.TYPE, vVCARD.VCard);

Modified: incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java?rev=1240713&r1=1240712&r2=1240713&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java (original)
+++ incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java Sun Feb  5 13:01:03 2012
@@ -48,7 +48,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testObjectResourceConversion() throws RepositoryException {
-        extractsAndCheckNoIssues("html/rdfa/object-resource-test.html");
+        assertExtracts("html/rdfa/object-resource-test.html");
         logger.debug(dumpModelToTurtle());
          assertContains(
                 null,
@@ -67,7 +67,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testExplicitDatatypeDeclaration() throws RepositoryException {
-        extractsAndCheckNoIssues("html/rdfa/xmlliteral-datatype-test.html");
+        assertExtracts("html/rdfa/xmlliteral-datatype-test.html");
         logger.debug(dumpModelToTurtle());
 
         Literal literal = RDFUtils.literal(
@@ -88,7 +88,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testRelWithHref() throws RepositoryException {
-        extractsAndCheckNoIssues("html/rdfa/rel-href.html");
+        assertExtracts("html/rdfa/rel-href.html");
         logger.debug(dumpModelToTurtle());
 
         assertContains(
@@ -110,7 +110,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testRelRevSupport() throws RepositoryException {
-        extractsAndCheckNoIssues("html/rdfa/rel-rev.html");
+        assertExtracts("html/rdfa/rel-rev.html");
         logger.debug(dumpModelToTurtle());
 
         assertContains(
@@ -132,7 +132,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testVocabSupport() throws RepositoryException {
-        extractsAndCheckNoIssues("html/rdfa/vocab.html");
+        assertExtracts("html/rdfa/vocab.html");
         logger.debug(dumpModelToTurtle());
 
         assertContains(
@@ -152,7 +152,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testTolerantParsing() {
-        assertExtracts("html/rdfa/oreilly-invalid-datatype.html");
+        assertExtracts("html/rdfa/oreilly-invalid-datatype.html", false);
         assertError(ErrorReporter.ErrorLevel.WARN, ".*Cannot map prefix \'mailto\'.*");
     }
 
@@ -170,7 +170,7 @@ public class RDFa11ExtractorTest extends
     throws RepositoryException, RDFHandlerException, IOException, RDFParseException {
         final int EXPECTED_STATEMENTS = 33;
 
-        extractsAndCheckNoIssues("html/rdfa/goodrelations-rdfa10.html");
+        assertExtracts("html/rdfa/goodrelations-rdfa10.html");
         logger.debug(dumpModelToNQuads());
 
         Assert.assertEquals(EXPECTED_STATEMENTS, dumpAsListOfStatements().size());
@@ -191,7 +191,7 @@ public class RDFa11ExtractorTest extends
     throws RepositoryException, RDFHandlerException, IOException, RDFParseException {
         final int EXPECTED_STATEMENTS = 33;
 
-        extractsAndCheckNoIssues("html/rdfa/goodrelations-rdfa11.html");
+        assertExtracts("html/rdfa/goodrelations-rdfa11.html");
         logger.debug(dumpHumanReadableTriples());
 
         Assert.assertEquals(EXPECTED_STATEMENTS, dumpAsListOfStatements().size());
@@ -208,7 +208,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testOpenGraphStructuredProperties() throws IOException, ExtractionException, RepositoryException {
-        extractsAndCheckNoIssues("html/rdfa/opengraph-structured-properties.html");
+        assertExtracts("html/rdfa/opengraph-structured-properties.html");
         logger.info( dumpHumanReadableTriples() );
 
         Assert.assertEquals(8, getStatementsSize(null, null, null) );
@@ -233,10 +233,5 @@ public class RDFa11ExtractorTest extends
     protected ExtractorFactory<?> getExtractorFactory() {
         return RDFa11Extractor.factory;
     }
-    
-    private void extractsAndCheckNoIssues(String resource) {
-        assertExtracts(resource);
-        assertNoIssues();
-    }
 
 }

Modified: incubator/any23/trunk/core/src/test/resources/html/rdfa/basic.html
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/resources/html/rdfa/basic.html?rev=1240713&r1=1240712&r2=1240713&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/resources/html/rdfa/basic.html (original)
+++ incubator/any23/trunk/core/src/test/resources/html/rdfa/basic.html Sun Feb  5 13:01:03 2012
@@ -1,4 +1,4 @@
-<html xml:lang="en">
+<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
 <head></head>
 <body>
 <div xmlns:dc="http://purl.org/dc/terms/" xmlns:fake="http://fake.org/">

Modified: incubator/any23/trunk/core/src/test/resources/html/rdfa/incomplete-triples.html
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/resources/html/rdfa/incomplete-triples.html?rev=1240713&r1=1240712&r2=1240713&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/resources/html/rdfa/incomplete-triples.html (original)
+++ incubator/any23/trunk/core/src/test/resources/html/rdfa/incomplete-triples.html Sun Feb  5 13:01:03 2012
@@ -1,4 +1,4 @@
-<html>
+<html xmlns="http://www.w3.org/1999/xhtml">
 <head></head>
 <body xmlns:dbp="http://dbpedia.org/property/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:xsd="ttp://www.w3.org/2001/XMLSchema#">
 <div about="http://dbpedia.org/resource/Albert_Einstein">

Modified: incubator/any23/trunk/core/src/test/resources/html/rdfa/rdfa-11-curies.html
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/resources/html/rdfa/rdfa-11-curies.html?rev=1240713&r1=1240712&r2=1240713&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/resources/html/rdfa/rdfa-11-curies.html (original)
+++ incubator/any23/trunk/core/src/test/resources/html/rdfa/rdfa-11-curies.html Sun Feb  5 13:01:03 2012
@@ -1,4 +1,4 @@
-<html>
+<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 </head>
 <body>