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.filter;
1920import org.apache.any23.extractor.ExtractionContext;
21import org.apache.any23.extractor.MockTripleHandler;
22import org.apache.any23.rdf.RDFUtils;
23import org.apache.any23.writer.TripleHandlerException;
24import org.junit.Before;
25import org.junit.Test;
26import org.eclipse.rdf4j.model.IRI;
2728/**29 * Test case for {@link ExtractionContextBlocker}.30 */31publicclassExtractionContextBlockerTest {
3233privatefinalstatic IRI docIRI = RDFUtils.iri("http://example.com/doc");
34privatefinalstatic IRI s = (IRI) RDFUtils.toValue("ex:s");
35privatefinalstatic IRI p = (IRI) RDFUtils.toValue("ex:p");
36privatefinalstatic IRI o = (IRI) RDFUtils.toValue("ex:o");
37private ExtractionContextBlocker blocker;
38privateMockTripleHandler handler;
3940 @Before
41publicvoid setUp() throws Exception {
42 handler = newMockTripleHandler();
43 blocker = new ExtractionContextBlocker(handler);
44 }
4546 @Test
47publicvoid 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);
5354 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 }
6465 }