222d9d5285e562d735ae99a9806b0cf848ce0d86
1 package be
.nikiroo
.fanfix
.test
;
4 import java
.util
.ArrayList
;
7 import be
.nikiroo
.fanfix
.Library
;
8 import be
.nikiroo
.fanfix
.data
.Chapter
;
9 import be
.nikiroo
.fanfix
.data
.MetaData
;
10 import be
.nikiroo
.fanfix
.data
.Paragraph
;
11 import be
.nikiroo
.fanfix
.data
.Story
;
12 import be
.nikiroo
.fanfix
.output
.BasicOutput
.OutputType
;
13 import be
.nikiroo
.utils
.IOUtils
;
14 import be
.nikiroo
.utils
.test
.TestCase
;
15 import be
.nikiroo
.utils
.test
.TestLauncher
;
17 public class LibraryTest
extends TestLauncher
{
21 public LibraryTest(String
[] args
) {
22 super("Library", args
);
24 final String luid1
= "001"; // A
25 final String luid2
= "002"; // B
26 final String luid3
= "003"; // B then A, then B
27 final String source1
= "Source A";
28 final String source2
= "Source B";
29 final String author1
= "Unknown author";
30 final String author2
= "Another other otter author";
32 addSeries(new TestLauncher("Local", args
) {
34 addTest(new TestCase("getList") {
36 public void test() throws Exception
{
38 List
<MetaData
> metas
= lib
.getListBySource(null);
39 assertEquals(0, metas
.size());
43 addTest(new TestCase("save") {
45 public void test() throws Exception
{
46 lib
.save(story(luid1
, "My story 1", source1
, author1
),
50 List
<MetaData
> metas
= lib
.getListBySource(null);
51 assertEquals(1, metas
.size());
55 addTest(new TestCase("save more") {
57 public void test() throws Exception
{
58 List
<MetaData
> metas
= null;
60 lib
.save(story(luid2
, "My story 2", source2
, author1
),
64 metas
= lib
.getListBySource(null);
65 assertEquals(2, metas
.size());
67 lib
.save(story(luid3
, "My story 3", source2
, author1
),
71 metas
= lib
.getListBySource(null);
72 assertEquals(3, metas
.size());
76 addTest(new TestCase("save override luid (change author)") {
78 public void test() throws Exception
{
79 // same luid as a previous one
80 lib
.save(story(luid3
, "My story 3", source2
, author2
),
84 List
<MetaData
> metas
= lib
.getListBySource(null);
85 assertEquals(3, metas
.size());
89 addTest(new TestCase("getList with results") {
91 public void test() throws Exception
{
93 List
<MetaData
> metas
= lib
.getListBySource(null);
94 assertEquals(3, metas
.size());
98 addTest(new TestCase("getList by source") {
100 public void test() throws Exception
{
101 List
<MetaData
> metas
= null;
103 metas
= lib
.getListBySource(source1
);
104 assertEquals(1, metas
.size());
106 metas
= lib
.getListBySource(source2
);
107 assertEquals(2, metas
.size());
109 metas
= lib
.getListBySource(null);
110 assertEquals(3, metas
.size());
114 addTest(new TestCase("getList by author") {
116 public void test() throws Exception
{
117 List
<MetaData
> metas
= null;
119 metas
= lib
.getListByAuthor(author1
);
120 assertEquals(2, metas
.size());
122 metas
= lib
.getListByAuthor(author2
);
123 assertEquals(1, metas
.size());
125 metas
= lib
.getListByAuthor(null);
126 assertEquals(3, metas
.size());
130 addTest(new TestCase("changeType") {
132 public void test() throws Exception
{
133 List
<MetaData
> metas
= null;
135 lib
.changeType(luid3
, source1
);
137 metas
= lib
.getListBySource(source1
);
138 assertEquals(2, metas
.size());
140 metas
= lib
.getListBySource(source2
);
141 assertEquals(1, metas
.size());
143 metas
= lib
.getListBySource(null);
144 assertEquals(3, metas
.size());
148 addTest(new TestCase("save override luid (change source)") {
150 public void test() throws Exception
{
151 List
<MetaData
> metas
= null;
153 // same luid as a previous one
154 lib
.save(story(luid3
, "My story 3", source2
, author2
),
157 metas
= lib
.getListBySource(source1
);
158 assertEquals(1, metas
.size());
160 metas
= lib
.getListBySource(source2
);
161 assertEquals(2, metas
.size());
163 metas
= lib
.getListBySource(null);
164 assertEquals(3, metas
.size());
172 protected void start() throws Exception
{
173 tmp
= File
.createTempFile(".test-fanfix", ".library");
177 lib
= new Library(tmp
, OutputType
.INFO_TEXT
, OutputType
.CBZ
);
181 protected void stop() throws Exception
{
182 IOUtils
.deltree(tmp
);
185 private Story
story(String luid
, String title
, String source
, String author
) {
186 Story story
= new Story();
188 MetaData meta
= new MetaData();
190 meta
.setTitle(title
);
191 meta
.setSource(source
);
192 meta
.setAuthor(author
);
195 Chapter resume
= chapter(0, "Resume");
196 meta
.setResume(resume
);
198 List
<Chapter
> chapters
= new ArrayList
<Chapter
>();
199 chapters
.add(chapter(1, "Chap 1"));
200 chapters
.add(chapter(2, "Chap 2"));
201 story
.setChapters(chapters
);
204 for (Chapter chap
: story
.getChapters()) {
205 words
+= chap
.getWords();
207 meta
.setWords(words
);
212 private Chapter
chapter(int number
, String name
) {
213 Chapter chapter
= new Chapter(number
, name
);
215 List
<Paragraph
> paragraphs
= new ArrayList
<Paragraph
>();
216 paragraphs
.add(new Paragraph(Paragraph
.ParagraphType
.NORMAL
,
217 "some words in this paragraph please thank you", 8));
219 chapter
.setParagraphs(paragraphs
);
222 for (Paragraph para
: chapter
.getParagraphs()) {
223 words
+= para
.getWords();
225 chapter
.setWords(words
);