This project has retired. For details please refer to its
Attic page.
MockTripleHandler xref
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.any23.extractor;
19
20 import org.apache.any23.rdf.RDFUtils;
21 import org.apache.any23.writer.TripleHandler;
22 import org.junit.Assert;
23 import org.eclipse.rdf4j.model.Resource;
24 import org.eclipse.rdf4j.model.IRI;
25 import org.eclipse.rdf4j.model.Value;
26
27 import java.util.LinkedList;
28 import java.util.List;
29
30
31
32
33
34
35
36 public class MockTripleHandler implements TripleHandler {
37
38 private final List<String> expectations = new LinkedList<String>();
39
40 public void expectStartDocument(IRI documentIRI) {
41 expectations.add("startDocument(" + documentIRI + ")");
42 }
43
44 public void expectEndDocument(IRI documentIRI) {
45 expectations.add("endDocument(" + documentIRI + ")");
46 }
47
48 public void expectSetContentLength(long contentLength) {
49 expectations.add("setContentLength(" + contentLength + ")");
50 }
51
52 public void expectClose() {
53 expectations.add("close()");
54 }
55
56 public void expectOpenContext(String extractorName, IRI documentIRI, String localID) {
57 expectations.add("openContext(" + new ExtractionContext(extractorName, documentIRI, localID) + ")");
58 }
59
60 public void expectCloseContext(String extractorName, IRI documentIRI, String localID) {
61 expectations.add("closeContext(" + new ExtractionContext(extractorName, documentIRI, localID) + ")");
62 }
63
64 public void expectTriple(Resource s, IRI p, Value o, IRI g, String extractorName, IRI documentIRI, String localID) {
65 expectations.add("triple(" + RDFUtils.quad(s, p, o, g) + ", "
66 + new ExtractionContext(extractorName, documentIRI, localID) + ")");
67 }
68
69 public void expectNamespace(String prefix, String uri, String extractorName, IRI documentIRI, String localID) {
70 expectations.add("namespace(" + prefix + ", " + uri + ", "
71 + new ExtractionContext(extractorName, documentIRI, localID) + ")");
72 }
73
74 public void verify() {
75 if (!expectations.isEmpty()) {
76 Assert.fail("Expected " + expectations.size() + " more invocation(s), first: " + expectations.get(0));
77 }
78 }
79
80 public void startDocument(IRI documentIRI) {
81 assertNextExpectation("startDocument(" + documentIRI + ")");
82 }
83
84 public void endDocument(IRI documentIRI) {
85 assertNextExpectation("endDocument(" + documentIRI + ")");
86 }
87
88 public void openContext(ExtractionContext context) {
89 assertNextExpectation("openContext(" + context + ")");
90 }
91
92 public void closeContext(ExtractionContext context) {
93 assertNextExpectation("closeContext(" + context + ")");
94 }
95
96 public void receiveTriple(Resource s, IRI p, Value o, IRI g, ExtractionContext context) {
97 assertNextExpectation("triple(" + RDFUtils.quad(s, p, o, g) + ", " + context + ")");
98 }
99
100 public void receiveNamespace(String prefix, String uri, ExtractionContext context) {
101 assertNextExpectation("namespace(" + prefix + ", " + uri + ", " + context + ")");
102 }
103
104 public void close() {
105 assertNextExpectation("close()");
106 }
107
108 public void setContentLength(long contentLength) {
109 assertNextExpectation("setContentLength(" + contentLength + ")");
110 }
111
112 private void assertNextExpectation(String invocation) {
113 if (expectations.isEmpty()) {
114 Assert.fail("Next expectation was <null>, invocation was " + invocation);
115 }
116 String expectation = expectations.remove(0);
117 Assert.assertEquals("Invocation doesn't match expectation", expectation, invocation);
118 }
119
120 }