forked from tabulapdf/tabula-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestObjectExtractor.java
More file actions
127 lines (103 loc) · 4.42 KB
/
TestObjectExtractor.java
File metadata and controls
127 lines (103 loc) · 4.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package technology.tabula;
import static org.junit.Assert.*;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.junit.Test;
public class TestObjectExtractor {
@Test(expected=IOException.class)
public void testWrongPasswordRaisesException() throws IOException {
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/encrypted.pdf");
ObjectExtractor oe = new ObjectExtractor(pdf_document, "wrongpass");
oe.extract().next();
}
@Test(expected=IOException.class)
public void testEmptyOnEncryptedFileRaisesException() throws IOException {
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/encrypted.pdf");
ObjectExtractor oe = new ObjectExtractor(pdf_document);
oe.extract().next();
}
@Test
public void testCanReadPDFWithOwnerEncryption() throws IOException {
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/S2MNCEbirdisland.pdf");
ObjectExtractor oe = new ObjectExtractor(pdf_document);
PageIterator pi = oe.extract();
int i = 0;
while (pi.hasNext()) {
i++;
pi.next();
}
assertEquals(2, i);
}
@Test
public void testGoodPassword() throws IOException {
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/encrypted.pdf");
ObjectExtractor oe = new ObjectExtractor(pdf_document, "userpassword");
List<Page> pages = new ArrayList<Page>();
PageIterator pi = oe.extract();
while (pi.hasNext()) {
pages.add(pi.next());
}
assertEquals(1, pages.size());
}
@Test
public void testTextExtractionDoesNotRaise() throws IOException {
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/rotated_page.pdf");
ObjectExtractor oe = new ObjectExtractor(pdf_document);
PageIterator pi = oe.extract();
assertTrue(pi.hasNext());
assertNotNull(pi.next());
assertFalse(pi.hasNext());
}
@Test
public void testShouldDetectRulings() throws IOException {
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/should_detect_rulings.pdf");
ObjectExtractor oe = new ObjectExtractor(pdf_document);
PageIterator pi = oe.extract();
while (pi.hasNext()) {
assertNotEquals(0, pi.next().getRulings().size());
}
}
@Test
public void testDontThrowNPEInShfill() throws IOException {
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/labor.pdf");
ObjectExtractor oe = new ObjectExtractor(pdf_document);
PageIterator pi = oe.extract();
assertTrue(pi.hasNext());
try {
Page p = pi.next();
assertNotNull(p);
}
catch (NullPointerException e) {
fail("NPE in ObjectExtractor " + e.toString());
}
}
@Test
public void testExtractOnePage() throws IOException{
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/S2MNCEbirdisland.pdf");
assertEquals(2, pdf_document.getNumberOfPages());
ObjectExtractor oe = new ObjectExtractor(pdf_document);
Page page = oe.extract(2);
assertNotNull(page);
}
@Test(expected = IndexOutOfBoundsException.class)
public void testExtractWrongPageNumber() throws IOException{
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/S2MNCEbirdisland.pdf");
assertEquals(2, pdf_document.getNumberOfPages());
ObjectExtractor oe = new ObjectExtractor(pdf_document);
oe.extract(3);
}
@Test
public void testExtractWithoutExtractingRulings() throws IOException {
PDDocument pdf_document = PDDocument.load("src/test/resources/technology/tabula/should_detect_rulings.pdf");
ObjectExtractor oe = new ObjectExtractor(pdf_document, null, false, false);
PageIterator pi = oe.extract();
assertTrue(pi.hasNext());
Page page = pi.next();
assertNotNull(page);
assertEquals(0, page.getRulings().size());
assertFalse(pi.hasNext());
}
}