@@ -60,7 +60,7 @@ private void testArchive(TestArchive archive)
6060 assertEquals ("main.html" , mainPage .getItem (true ).getPath ());
6161
6262 // test zim file size
63- assertEquals (66910 , archive .getFilesize ()); // The file size is in KiB
63+ assertEquals (66937 , archive .getFilesize ()); // The file size is in KiB
6464 // test zim file content
6565 byte [] mainData = getFileContent ("small_zimfile_data/main.html" );
6666 byte [] inZimMainData = archive .getEntryByPath ("main.html" ).getItem (true ).getData ().getData ();
@@ -86,7 +86,7 @@ private void testArchive(TestArchive archive)
8686 assertFalse (archive .isMultiPart ());
8787 assertTrue (archive .hasNewNamespaceScheme ());
8888 assertTrue (archive .hasChecksum ());
89- assertEquals ("f4373bda1fdce141ba8e5c80baaf905d " , archive .getChecksum ());
89+ assertEquals ("4a2709fddbee8c27db708c20b4952a06 " , archive .getChecksum ());
9090 assertTrue (archive .hasTitleIndex ());
9191 assertTrue (archive .hasFulltextIndex ());
9292 assertTrue (archive .hasMainEntry ());
@@ -97,7 +97,7 @@ private void testArchive(TestArchive archive)
9797 metaKeys ,
9898 archive .getMetadataKeys ()
9999 ));
100- assertEquals ("c23a31c1-c357-9e82-3b43-f87aaf706d04 " , archive .getUuid ());
100+ assertEquals ("e34f5109-ed0d-b93e-943d-06f7717c7340 " , archive .getUuid ());
101101 assertEquals (1 , archive .getMediaCount ());
102102 assertEquals (1 , archive .getArticleCount ());
103103 assertEquals (2 , archive .getEntryCount ());
@@ -205,49 +205,95 @@ private void testLibrary(TestLibrary lib)
205205 assertEquals (bookIds .length , 1 );
206206 lib .filter (new Filter ().local (true ));
207207 assertTrue (Arrays .equals (lib .getBooksPublishers (), new String []{"Publisher" }));
208- assertTrue (Arrays .equals (lib .getBooksCreators (), new String []{"Kiwix" }));
209- assertTrue (Arrays .equals (lib .getBooksCategories (), new String []{"Super category" }));
210- assertTrue (Arrays .equals (lib .getBooksLanguages (), new String []{"en" }));
208+ assertTrue (Arrays .equals (lib .getBooksCreators (), new String []{"Creator" }));
209+ System .out .println (Arrays .toString (lib .getBooksCategories ()));
210+ assertTrue (Arrays .equals (lib .getBooksCategories (), new String []{"Category" }));
211+ assertTrue (Arrays .equals (lib .getBooksLanguages (), new String []{"eng" }));
211212
212213
213214 // getArchiveById needs books with valid path. Which is not possible by definition if library is initialized by opds stream.
214215 //assertEquals("86c91e51-55bf-8882-464e-072aca37a3e8", lib.getArchiveById("86c91e51-55bf-8882-464e-072aca37a3e8").getUuid());
215216
216217 TestBook book = lib .getBookById (bookIds [0 ]);
217218 assertEquals (book .getTitle (), "Test ZIM file" );
218- assertEquals (book .getTags (), "unit;test " );
219+ assertEquals (book .getTags (), "_category:Category;_ftindex:yes;_ftindex:yes;_pictures:yes;_videos:yes;_details:yes " );
219220 assertEquals (book .getIllustration (48 ).width (), 48 );
220- assertEquals (book .getIllustration (48 ).url (), "http://localhost/meta?name=favicon&content=small" );
221221 assertEquals (book .getUrl (), "http://localhost/small.zim" );
222- assertEquals (book .getPath (), "" );
223- assertEquals (book .getHumanReadableIdFromPath (), "" );
224- assertFalse (book .isPathValid ());
225- assertEquals (book .getDescription (), "This is a ZIM file used in libzim unit-tests" );
226- assertEquals (book .getCreator (), "Kiwix" );
222+ assertEquals (book .getDescription (), "Description" );
223+ assertEquals (book .getCreator (), "Creator" );
227224 assertEquals (book .getPublisher (), "Publisher" );
228225 assertEquals (book .getFlavour (), "" );
229- assertEquals (book .getCategory (), "Super category " );
230- assertEquals (book .getArticleCount (), 0 );
231- assertEquals (book .getMediaCount (), 0 );
232- assertEquals (book .getSize (), 78982 );
226+ assertEquals (book .getCategory (), "Category " );
227+ assertEquals (book .getArticleCount (), 1 );
228+ assertEquals (book .getMediaCount (), 1 );
229+ assertEquals (book .getSize (), 66560 );
233230 Illustration [] illustrations = book .getIllustrations ();
234231 assertEquals (1 , illustrations .length );
235232
236233 assertEquals (book .getTagStr ("video" ), "" );
234+ }
235+
236+ @ Test
237+ public void testLibrarySimple () throws IOException {
238+ TestLibrary lib = new TestLibrary ();
239+ TestManager manager = new TestManager (lib );
240+ manager .addBookFromPath ("small.zim" , "small.zim" , "http://localhost/small.zim" , true );
241+ testLibrary (lib );
242+ String [] bookIds = lib .getBooksIds ();
243+ TestBook book = lib .getBookById (bookIds [0 ]);
244+ assertEquals (book .getIllustration (48 ).url (), "" );
245+ assertEquals (book .getPath (), new File ("small.zim" ).getAbsolutePath ());
246+ assertEquals (book .getHumanReadableIdFromPath (), "small" );
247+ assertTrue (book .isPathValid ());
237248
238249 // remove book from library by id
239250 lib .removeBookById (bookIds [0 ]);
240251 bookIds = lib .getBooksIds ();
241252 assertEquals (bookIds .length , 0 );
242253 }
243254
255+ @ Test
256+ public void testLibraryXml () throws IOException {
257+ TestLibrary lib = new TestLibrary ();
258+ TestManager manager = new TestManager (lib );
259+ manager .readFile ("library.xml" );
260+ testLibrary (lib );
261+ String [] bookIds = lib .getBooksIds ();
262+ TestBook book = lib .getBookById (bookIds [0 ]);
263+ assertEquals (book .getIllustration (48 ).url (), "" );
264+ assertEquals (book .getPath (), new File ("small.zim" ).getAbsolutePath ());
265+ assertEquals (book .getHumanReadableIdFromPath (), "small" );
266+ assertTrue (book .isPathValid ());
267+ }
268+
269+ @ Test
270+ public void testLibraryXmlContent () throws IOException {
271+ TestLibrary lib = new TestLibrary ();
272+ TestManager manager = new TestManager (lib );
273+ String content = getTextFileContent ("library.xml" );
274+ manager .readXml (content , "library.xml" );
275+ testLibrary (lib );
276+ String [] bookIds = lib .getBooksIds ();
277+ TestBook book = lib .getBookById (bookIds [0 ]);
278+ assertEquals (book .getIllustration (48 ).url (), "" );
279+ assertEquals (book .getPath (), new File ("small.zim" ).getAbsolutePath ());
280+ assertEquals (book .getHumanReadableIdFromPath (), "small" );
281+ assertTrue (book .isPathValid ());
282+ }
283+
244284 @ Test
245285 public void testLibraryOPDS () throws IOException {
246286 TestLibrary lib = new TestLibrary ();
247287 TestManager manager = new TestManager (lib );
248288 String content = getTextFileContent ("catalog.xml" );
249289 manager .readOpds (content , "http://localhost" );
250290 testLibrary (lib );
291+ String [] bookIds = lib .getBooksIds ();
292+ TestBook book = lib .getBookById (bookIds [0 ]);
293+ assertEquals (book .getIllustration (48 ).url (), "http://localhost/meta?name=favicon&content=small" );
294+ assertEquals (book .getPath (), "" );
295+ assertEquals (book .getHumanReadableIdFromPath (), "" );
296+ assertFalse (book .isPathValid ());
251297 }
252298
253299 @ Test
@@ -322,7 +368,7 @@ public void testSearcher() throws Exception, ZimFileFormatException, JNIKiwixExc
322368 assertEquals (3 , iterator .getWordCount ());
323369 assertEquals (0 , iterator .getFileIndex ());
324370 assertEquals (-1 , iterator .getSize ());
325- assertEquals ("c23a31c1-c357-9e82-3b43-f87aaf706d04 " , iterator .getZimId ());
371+ assertEquals ("e34f5109-ed0d-b93e-943d-06f7717c7340 " , iterator .getZimId ());
326372 TestEntry entry = iterator .next ();
327373 assertEquals ("main.html" , entry .getPath ());
328374
0 commit comments