This project has retired. For details please refer to its Attic page.
LicenseExtractorTest xref
View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *  http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.any23.extractor.html;
19  
20  import org.apache.any23.extractor.IssueReport;
21  import org.apache.any23.extractor.ExtractorFactory;
22  import org.apache.any23.rdf.RDFUtils;
23  import org.apache.any23.vocab.SINDICE;
24  import org.apache.any23.vocab.XHTML;
25  import org.junit.Assert;
26  import org.junit.Test;
27  import org.eclipse.rdf4j.model.IRI;
28  import org.eclipse.rdf4j.repository.RepositoryException;
29  
30  import java.util.Collection;
31  
32  /**
33   *
34   * Reference Test class for the {@link LicenseExtractor} extractor.
35   *
36   */
37  public class LicenseExtractorTest extends AbstractExtractorTestCase {
38  
39      private static final SINDICE vSINDICE = SINDICE.getInstance();
40      private static final XHTML vXHTML = XHTML.getInstance();
41  
42      private IRI ccBy = RDFUtils.iri("http://creativecommons.org/licenses/by/2.0/");
43  
44      private IRI apache = RDFUtils.iri("http://www.apache.org/licenses/LICENSE-2.0");
45  
46      public ExtractorFactory<?> getExtractorFactory() {
47          return new LicenseExtractorFactory();
48      }
49  
50      @Test
51      public void testOnlyCc() throws RepositoryException {
52          assertExtract("/microformats/license/ccBy.html");
53          assertContains(baseIRI, vXHTML.license, ccBy);
54          assertNotContains(baseIRI, vXHTML.license, apache);
55      }
56  
57      @Test
58      public void testOnlyApache() throws RepositoryException {
59          assertExtract("/microformats/license/apache.html");
60          assertNotContains(baseIRI, vXHTML.license, ccBy);
61          assertContains(baseIRI, vXHTML.license, apache);
62      }
63  
64      @Test
65      public void testMultipleLicenses() throws RepositoryException {
66          assertExtract("/microformats/license/multiple.html");
67          assertContains(baseIRI, vXHTML.license, ccBy);
68          assertContains(baseIRI, vXHTML.license, apache);
69      }
70  
71      @Test
72      public void testMultipleEmptyHref() throws RepositoryException {
73          assertExtract("/microformats/license/multiple-empty-href.html", false);
74          assertNotContains(baseIRI, vXHTML.license, "");
75          assertContains(baseIRI, vXHTML.license, apache);
76  
77          final Collection<IssueReport.Issue> errors = getIssues();
78          Assert.assertEquals(1, errors.size());
79          IssueReport.Issue error = errors.iterator().next();
80          Assert.assertTrue(error.getMessage().contains("Invalid license link detected"));
81          Assert.assertEquals(IssueReport.IssueLevel.WARNING, error.getLevel());
82      }
83  
84      @Test
85      public void testEmpty() throws RepositoryException {
86          assertExtract("/microformats/license/empty.html");
87          assertModelEmpty();
88      }
89  
90      @Test
91      public void testMixedCaseTitleTag() throws RepositoryException {
92          assertExtract("/microformats/license/multiple-mixed-case.html");
93          assertContains(baseIRI, vXHTML.license, ccBy);
94          assertContains(baseIRI, vXHTML.license, apache);
95      }
96  
97  }