mirror of
https://github.com/kiwix/java-libkiwix.git
synced 2025-09-09 07:08:49 -04:00
Introduce TestBook, TestLibrary, TestManager and TestServer.
This commit is contained in:
parent
f84d951e97
commit
83a6429565
40
lib/src/test/org/kiwix/test/libkiwix/TestBook.java
Normal file
40
lib/src/test/org/kiwix/test/libkiwix/TestBook.java
Normal file
@ -0,0 +1,40 @@
|
||||
|
||||
package org.kiwix.test.libkiwix;
|
||||
|
||||
import org.kiwix.libkiwix.Book;
|
||||
import org.kiwix.libkiwix.Illustration;
|
||||
import org.kiwix.test.libzim.TestArchive;
|
||||
|
||||
public class TestBook
|
||||
{
|
||||
private Book inner;
|
||||
public TestBook() { inner = new Book(); }
|
||||
public TestBook(Book _inner) { inner = _inner; }
|
||||
public Book inner() { return inner; }
|
||||
|
||||
public void update(TestBook book) { inner.update(book.inner()); }
|
||||
public void update(TestArchive archive) { inner.update(archive.inner()); }
|
||||
|
||||
public String getId() { return inner.getId(); }
|
||||
public String getPath() { return inner.getPath(); }
|
||||
public String getHumanReadableIdFromPath() { return inner.getHumanReadableIdFromPath(); }
|
||||
public boolean isPathValid() { return inner.isPathValid(); }
|
||||
public String getTitle() { return inner.getTitle(); }
|
||||
public String getDescription() { return inner.getDescription(); }
|
||||
public String getLanguage() { return inner.getLanguage(); }
|
||||
public String getCreator() { return inner.getCreator(); }
|
||||
public String getPublisher() { return inner.getPublisher(); }
|
||||
public String getDate() { return inner.getDate(); }
|
||||
public String getUrl() { return inner.getUrl(); }
|
||||
public String getName() { return inner.getName(); }
|
||||
public String getFlavour() { return inner.getFlavour(); }
|
||||
public String getCategory() { return inner.getCategory(); }
|
||||
public String getTags() { return inner.getTags(); }
|
||||
public String getTagStr(String tagName) { return inner.getTagStr(tagName); }
|
||||
public long getArticleCount() { return inner.getArticleCount(); }
|
||||
public long getMediaCount() { return inner.getMediaCount(); }
|
||||
public long getSize() { return inner.getSize(); }
|
||||
|
||||
public Illustration[] getIllustrations() { return inner.getIllustrations(); }
|
||||
public Illustration getIllustration(int size) { return inner.getIllustration(size); }
|
||||
}
|
62
lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java
Normal file
62
lib/src/test/org/kiwix/test/libkiwix/TestLibrary.java
Normal file
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (C) 2019-2020 Matthieu Gautier <mgautier@kymeria.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.kiwix.test.libkiwix;
|
||||
|
||||
import org.kiwix.libkiwix.Library;
|
||||
import org.kiwix.test.libzim.TestArchive;
|
||||
import org.kiwix.libzim.Searcher;
|
||||
import org.kiwix.libkiwix.Filter;
|
||||
import org.kiwix.libkiwix.Book;
|
||||
import org.kiwix.libkiwix.JNIKiwixException;
|
||||
import org.kiwix.libkiwix.Bookmark;
|
||||
|
||||
public class TestLibrary
|
||||
{
|
||||
private Library inner;
|
||||
public Library inner() { return inner; }
|
||||
public TestLibrary() { inner = new Library(); }
|
||||
public TestLibrary(Library _inner) { inner = _inner; }
|
||||
public boolean addBook(TestBook book) throws JNIKiwixException { return inner.addBook(book.inner()); }
|
||||
|
||||
public TestBook getBookById(String id) { return new TestBook(inner.getBookById(id)); }
|
||||
|
||||
public TestArchive getArchiveById(String id) { return new TestArchive(inner.getArchiveById(id)); }
|
||||
//public native Searcher getSearcherById(String id);
|
||||
//public native Searcher getSearcherByIds(String ids[]);
|
||||
|
||||
public boolean removeBookById(String id) { return inner.removeBookById(id); }
|
||||
|
||||
public boolean writeToFile(String path) { return inner.writeToFile(path); }
|
||||
public boolean writeBookmarksToFile(String path) { return inner.writeBookmarksToFile(path); }
|
||||
|
||||
public int getBookCount(boolean localBooks, boolean remoteBooks) { return inner.getBookCount(localBooks, remoteBooks); }
|
||||
|
||||
public String[] getBooksIds() { return inner.getBooksIds(); }
|
||||
public String[] filter(Filter filter) { return inner.filter(filter); }
|
||||
|
||||
public String[] getBooksLanguages() { return inner.getBooksLanguages(); }
|
||||
public String[] getBooksCategories() { return inner.getBooksCategories(); }
|
||||
public String[] getBooksCreators() { return inner.getBooksCreators(); }
|
||||
public String[] getBooksPublishers() { return inner.getBooksPublishers(); }
|
||||
|
||||
public void addBookmark(Bookmark bookmark) { inner.addBookmark(bookmark); }
|
||||
public boolean removeBookmark(String zimId, String url) { return inner.removeBookmark(zimId, url); }
|
||||
public Bookmark[] getBookmarks(boolean onlyValidBookmarks) { return inner.getBookmarks(onlyValidBookmarks); }
|
||||
}
|
43
lib/src/test/org/kiwix/test/libkiwix/TestManager.java
Normal file
43
lib/src/test/org/kiwix/test/libkiwix/TestManager.java
Normal file
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright (C) 2020 Matthieu Gautier <mgautier@kymeria.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.kiwix.test.libkiwix;
|
||||
|
||||
import org.kiwix.libkiwix.Manager;
|
||||
|
||||
public class TestManager
|
||||
{
|
||||
private Manager inner;
|
||||
|
||||
public TestManager(Manager _inner) { inner = _inner; }
|
||||
|
||||
public boolean readFile(String path) { return inner.readFile(path); }
|
||||
public boolean readXml(String content, String libraryPath) { return inner.readXml(content, libraryPath); }
|
||||
public boolean readOpds(String content, String urlHost) { return inner.readOpds(content, urlHost); }
|
||||
public boolean readBookmarkFile(String path) { return inner.readBookmarkFile(path); }
|
||||
public String addBookFromPath(String pathToOpen,
|
||||
String pathToSave,
|
||||
String url,
|
||||
boolean checkMetaData)
|
||||
{ return inner.addBookFromPath(pathToOpen, pathToSave, url, checkMetaData); }
|
||||
|
||||
public TestManager(TestLibrary library) {
|
||||
inner = new Manager(library.inner());
|
||||
}
|
||||
}
|
41
lib/src/test/org/kiwix/test/libkiwix/TestServer.java
Normal file
41
lib/src/test/org/kiwix/test/libkiwix/TestServer.java
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Matthieu Gautier <mgautier@kymeria.fr>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
package org.kiwix.test.libkiwix;
|
||||
|
||||
import org.kiwix.libkiwix.Library;
|
||||
import org.kiwix.libkiwix.Server;
|
||||
|
||||
public class TestServer
|
||||
{
|
||||
private Server inner;
|
||||
|
||||
public void setRoot(String root) { inner.setRoot(root); }
|
||||
public void setAddress(String address) { inner.setAddress(address); }
|
||||
public void setPort(int port) { inner.setPort(port); }
|
||||
public void setNbThreads(int nbTreads) { inner.setNbThreads(nbTreads); }
|
||||
public void setTaskbar(boolean withTaskBar, boolean witLibraryButton) { inner.setTaskbar(withTaskBar, witLibraryButton); }
|
||||
public void setBlockExternalLinks(boolean blockExternalLinks) { inner.setBlockExternalLinks(blockExternalLinks); }
|
||||
public boolean start() { return inner.start(); }
|
||||
public void stop() { inner.stop(); }
|
||||
public TestServer(TestLibrary library)
|
||||
{
|
||||
inner = new Server(library.inner());
|
||||
}
|
||||
}
|
@ -28,7 +28,9 @@ import org.kiwix.libzim.*;
|
||||
public class TestArchive
|
||||
{
|
||||
private Archive inner;
|
||||
public Archive inner() { return inner; }
|
||||
|
||||
public TestArchive(Archive _inner) { inner = _inner; }
|
||||
public TestArchive(String filename) throws ZimFileFormatException
|
||||
{
|
||||
inner = new Archive(filename);
|
||||
|
@ -8,6 +8,7 @@ import static org.junit.Assert.*;
|
||||
import org.kiwix.libkiwix.*;
|
||||
import org.kiwix.libzim.*;
|
||||
import org.kiwix.test.libzim.*;
|
||||
import org.kiwix.test.libkiwix.*;
|
||||
|
||||
public class test {
|
||||
static {
|
||||
@ -111,8 +112,8 @@ public class test {
|
||||
@Test
|
||||
public void testLibrary()
|
||||
throws IOException {
|
||||
Library lib = new Library();
|
||||
Manager manager = new Manager(lib);
|
||||
TestLibrary lib = new TestLibrary();
|
||||
TestManager manager = new TestManager(lib);
|
||||
String content = getTextFileContent("catalog.xml");
|
||||
manager.readOpds(content, "http://localhost");
|
||||
assertEquals(lib.getBookCount(true, true), 1);
|
||||
@ -120,7 +121,7 @@ public class test {
|
||||
assertEquals(bookIds.length, 1);
|
||||
lib.filter(new Filter().local(true));
|
||||
|
||||
Book book = lib.getBookById(bookIds[0]);
|
||||
TestBook book = lib.getBookById(bookIds[0]);
|
||||
assertEquals(book.getTitle(), "Test ZIM file");
|
||||
assertEquals(book.getTags(), "unit;test");
|
||||
assertEquals(book.getIllustration(48).width(), 48);
|
||||
@ -135,22 +136,22 @@ public class test {
|
||||
|
||||
@Test
|
||||
public void testServer() throws ZimFileFormatException, JNIKiwixException {
|
||||
Archive archive = new Archive("small.zim");
|
||||
Library lib = new Library();
|
||||
Book book = new Book();
|
||||
TestArchive archive = new TestArchive("small.zim");
|
||||
TestLibrary lib = new TestLibrary();
|
||||
TestBook book = new TestBook();
|
||||
book.update(archive);
|
||||
lib.addBook(book);
|
||||
assertEquals(1, lib.getBookCount(true, true));
|
||||
Server server = new Server(lib);
|
||||
TestServer server = new TestServer(lib);
|
||||
server.setPort(8080);
|
||||
assertEquals(true, server.start());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBookMark() throws ZimFileFormatException, JNIKiwixException {
|
||||
Archive archive = new Archive("small.zim");
|
||||
Library lib = new Library();
|
||||
Book book = new Book();
|
||||
TestArchive archive = new TestArchive("small.zim");
|
||||
TestLibrary lib = new TestLibrary();
|
||||
TestBook book = new TestBook();
|
||||
book.update(archive);
|
||||
lib.addBook(book);
|
||||
Bookmark bookmark = new Bookmark();
|
||||
|
Loading…
x
Reference in New Issue
Block a user