1/*2 * Licensed to the Apache Software Foundation (ASF) under one or more3 * contributor license agreements. See the NOTICE file distributed with4 * this work for additional information regarding copyright ownership.5 * The ASF licenses this file to You under the Apache License, Version 2.06 * (the "License"); you may not use this file except in compliance with7 * the License. You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * 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 and15 * limitations under the License.16 */1718package org.apache.any23.plugin.htmlscraper;
1920import org.apache.any23.extractor.ExtractionContext;
21import org.apache.any23.extractor.ExtractionException;
22import org.apache.any23.extractor.ExtractionParameters;
23import org.apache.any23.extractor.ExtractionResult;
24import org.junit.After;
25import org.junit.Assert;
26import org.junit.Before;
27import org.junit.Test;
28import org.eclipse.rdf4j.model.IRI;
29import org.eclipse.rdf4j.model.impl.SimpleValueFactory;
3031import java.io.IOException;
32import java.io.InputStream;
33import java.util.Arrays;
34import java.util.HashSet;
3536importstatic org.mockito.Mockito.any;
37importstatic org.mockito.Mockito.eq;
38importstatic org.mockito.Mockito.mock;
39importstatic org.mockito.Mockito.verify;
4041/**42 * Test case for {@link HTMLScraperExtractor}.43 *44 * @author Michele Mostarda (mostarda@fbk.eu)45 */46publicclassHTMLScraperExtractorTest {
4748private HTMLScraperExtractor extractor;
4950 @Before
51publicvoid setUp() {
52 extractor = new HTMLScraperExtractorFactory().createExtractor();
53 }
5455 @After
56publicvoid tearDown() {
57 extractor = null;
58 }
5960 @Test
61publicvoid testGetExtractors() {
62final String[] extractors = extractor.getTextExtractors();
63 Assert.assertEquals( new HashSet<>(Arrays.asList(extractors)).size(), 4 );
64 }
6566 @Test
67publicvoid testRun() throws IOException, ExtractionException {
68final InputStream is = this.getClass().getResourceAsStream("html-scraper-extractor-test.html");
69final ExtractionResult extractionResult = mock(ExtractionResult.class);
70final IRI pageIRI = SimpleValueFactory.getInstance().createIRI("http://fake/test/page/testrun");
71final ExtractionContext extractionContext = new ExtractionContext(
72 extractor.getDescription().getExtractorName(),
73 pageIRI
74 );
75 extractor.run(ExtractionParameters.newDefault(), extractionContext, is, extractionResult);
7677 verify(extractionResult).writeTriple(
78 eq(pageIRI), eq(HTMLScraperExtractor.PAGE_CONTENT_DE_PROPERTY), any());
79 verify(extractionResult).writeTriple(
80 eq(pageIRI), eq(HTMLScraperExtractor.PAGE_CONTENT_AE_PROPERTY), any());
81 verify(extractionResult).writeTriple(
82 eq(pageIRI), eq(HTMLScraperExtractor.PAGE_CONTENT_LCE_PROPERTY), any());
83 verify(extractionResult).writeTriple(
84 eq(pageIRI), eq(HTMLScraperExtractor.PAGE_CONTENT_CE_PROPERTY), any());
85 }
8687 }