1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
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 }