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.filter;
    19
    20  import org.apache.any23.extractor.ExtractionContext;
    21  import org.apache.any23.extractor.MockTripleHandler;
    22  import org.apache.any23.rdf.RDFUtils;
    23  import org.apache.any23.writer.TripleHandlerException;
    24  import org.junit.Before;
    25  import org.junit.Test;
    26  import org.eclipse.rdf4j.model.IRI;
    27
    28  /**
    29   * Test case for {@link ExtractionContextBlocker}.
    30   */
    31  public class ExtractionContextBlockerTest {
    32
    33      private final static IRI docIRI = RDFUtils.iri("http://example.com/doc");
    34      private final static IRI s = (IRI) RDFUtils.toValue("ex:s");
    35      private final static IRI p = (IRI) RDFUtils.toValue("ex:p");
    36      private final static IRI o = (IRI) RDFUtils.toValue("ex:o");
    37      private ExtractionContextBlocker blocker;
    38      private MockTripleHandler handler;
    39
    40      @Before
    41      public void setUp() throws Exception {
    42          handler = new MockTripleHandler();
    43          blocker = new ExtractionContextBlocker(handler);
    44      }
    45
    46      @Test
    47      public void testSendsNamespaceAfterUnblock() throws TripleHandlerException {
    48          handler.expectOpenContext("test", docIRI, null);
    49          handler.expectNamespace("ex", "http://example.com/", "test", docIRI, null);
    50          handler.expectTriple(s, p, o, null, "test", docIRI, null);
    51          handler.expectCloseContext("test", docIRI, null);
    52          handler.expectEndDocument(docIRI);
    53
    54          ExtractionContext context = new ExtractionContext("test", docIRI);
    55          blocker.openContext(context);
    56          blocker.blockContext(context);
    57          blocker.receiveNamespace("ex", "http://example.com/", context);
    58          blocker.receiveTriple(s, p, o, null, context);
    59          blocker.closeContext(context);
    60          blocker.unblockContext(context);
    61          blocker.endDocument(docIRI);
    62          handler.verify();
    63      }
    64
    65  }