/
EpubReaderTest.java
78 lines (64 loc) · 2.66 KB
/
EpubReaderTest.java
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
package nl.siegmann.epublib.epub;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import nl.siegmann.epublib.domain.Book;
import nl.siegmann.epublib.domain.Resource;
import nl.siegmann.epublib.service.MediatypeService;
import org.junit.Assert;
import org.junit.Test;
public class EpubReaderTest {
@Test
public void testCover_only_cover() throws IOException {
Book book = new Book();
book.setCoverImage(new Resource(this.getClass().getResourceAsStream(
"/book1/cover.png"), "cover.png"));
ByteArrayOutputStream out = new ByteArrayOutputStream();
(new EpubWriter()).write(book, out);
byte[] epubData = out.toByteArray();
Book readBook = new EpubReader().readEpub(new ByteArrayInputStream(
epubData));
Assert.assertNotNull(readBook.getCoverImage());
}
@Test
public void testCover_cover_one_section() throws IOException {
Book book = new Book();
book.setCoverImage(new Resource(this.getClass().getResourceAsStream(
"/book1/cover.png"), "cover.png"));
book.addSection("Introduction", new Resource(this.getClass()
.getResourceAsStream("/book1/chapter1.html"), "chapter1.html"));
book.generateSpineFromTableOfContents();
ByteArrayOutputStream out = new ByteArrayOutputStream();
(new EpubWriter()).write(book, out);
byte[] epubData = out.toByteArray();
Book readBook = new EpubReader().readEpub(new ByteArrayInputStream(
epubData));
Assert.assertNotNull(readBook.getCoverPage());
Assert.assertEquals(1, readBook.getSpine().size());
Assert.assertEquals(1, readBook.getTableOfContents().size());
}
@Test
public void testReadEpub_opf_ncx_docs() throws IOException {
Book book = new Book();
book.setCoverImage(new Resource(this.getClass().getResourceAsStream(
"/book1/cover.png"), "cover.png"));
book.addSection("Introduction", new Resource(this.getClass()
.getResourceAsStream("/book1/chapter1.html"), "chapter1.html"));
book.generateSpineFromTableOfContents();
ByteArrayOutputStream out = new ByteArrayOutputStream();
(new EpubWriter()).write(book, out);
byte[] epubData = out.toByteArray();
Book readBook = new EpubReader().readEpub(new ByteArrayInputStream(
epubData));
Assert.assertNotNull(readBook.getCoverPage());
Assert.assertEquals(1, readBook.getSpine().size());
Assert.assertEquals(1, readBook.getTableOfContents().size());
Assert.assertNotNull(readBook.getOpfResource());
Assert.assertNotNull(readBook.getNcxResource());
Assert.assertEquals(MediatypeService.NCX, readBook.getNcxResource()
.getMediaType());
}
}