2008-07-07 19:38:17 -04:00
|
|
|
|
|
|
|
package net.sourceforge.filebot.web;
|
|
|
|
|
|
|
|
|
2009-05-17 13:22:44 -04:00
|
|
|
import static org.junit.Assert.*;
|
2008-07-07 19:38:17 -04:00
|
|
|
|
|
|
|
import java.util.List;
|
2010-11-11 09:23:59 -05:00
|
|
|
import java.util.Locale;
|
2008-07-07 19:38:17 -04:00
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
import org.junit.AfterClass;
|
2008-07-07 19:38:17 -04:00
|
|
|
import org.junit.BeforeClass;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
import net.sf.ehcache.CacheManager;
|
2009-10-28 11:09:47 -04:00
|
|
|
import net.sourceforge.filebot.web.AnidbClient.AnidbSearchResult;
|
|
|
|
|
2008-07-07 19:38:17 -04:00
|
|
|
|
|
|
|
public class AnidbClientTest {
|
|
|
|
|
2008-07-08 14:26:18 -04:00
|
|
|
/**
|
|
|
|
* 74 episodes
|
|
|
|
*/
|
2009-10-28 11:09:47 -04:00
|
|
|
private static AnidbSearchResult monsterSearchResult;
|
2008-07-07 19:38:17 -04:00
|
|
|
|
2008-07-08 14:26:18 -04:00
|
|
|
/**
|
2009-10-28 11:09:47 -04:00
|
|
|
* 45 episodes
|
2008-07-08 14:26:18 -04:00
|
|
|
*/
|
2009-10-28 11:09:47 -04:00
|
|
|
private static AnidbSearchResult twelvekingdomsSearchResult;
|
2008-07-07 19:38:17 -04:00
|
|
|
|
2009-09-22 16:56:43 -04:00
|
|
|
/**
|
|
|
|
* 38 episodes, lots of special characters
|
|
|
|
*/
|
2009-10-28 11:09:47 -04:00
|
|
|
private static AnidbSearchResult princessTutuSearchResult;
|
2009-09-22 16:56:43 -04:00
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2008-07-07 19:38:17 -04:00
|
|
|
@BeforeClass
|
|
|
|
public static void setUpBeforeClass() throws Exception {
|
2009-10-28 11:09:47 -04:00
|
|
|
monsterSearchResult = new AnidbSearchResult(1539, "Monster", null);
|
2011-11-04 01:23:23 -04:00
|
|
|
twelvekingdomsSearchResult = new AnidbSearchResult(26, "Juuni Kokuki", null);
|
2009-10-28 11:09:47 -04:00
|
|
|
princessTutuSearchResult = new AnidbSearchResult(516, "Princess Tutu", null);
|
2008-07-07 19:38:17 -04:00
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2011-10-01 00:08:46 -04:00
|
|
|
private AnidbClient anidb = new AnidbClient("filebot", 2);
|
2008-07-08 14:26:18 -04:00
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2008-07-07 19:38:17 -04:00
|
|
|
@Test
|
|
|
|
public void search() throws Exception {
|
|
|
|
List<SearchResult> results = anidb.search("one piece");
|
|
|
|
|
2009-10-28 11:09:47 -04:00
|
|
|
AnidbSearchResult result = (AnidbSearchResult) results.get(0);
|
2011-11-04 01:23:23 -04:00
|
|
|
assertEquals("One Piece", result.getName());
|
|
|
|
assertEquals(69, result.getAnimeId());
|
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2011-11-04 01:23:23 -04:00
|
|
|
@Test
|
|
|
|
public void searchJapanese() throws Exception {
|
|
|
|
List<SearchResult> results = anidb.search("ワンピース", Locale.JAPANESE);
|
2008-07-07 19:38:17 -04:00
|
|
|
|
2011-11-04 01:23:23 -04:00
|
|
|
AnidbSearchResult result = (AnidbSearchResult) results.get(0);
|
2008-07-07 19:38:17 -04:00
|
|
|
assertEquals("One Piece", result.getName());
|
2009-10-28 11:09:47 -04:00
|
|
|
assertEquals(69, result.getAnimeId());
|
2008-07-07 19:38:17 -04:00
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2009-07-18 18:06:32 -04:00
|
|
|
@Test
|
|
|
|
public void searchNoMatch() throws Exception {
|
|
|
|
List<SearchResult> results = anidb.search("i will not find anything for this query string");
|
|
|
|
|
|
|
|
assertTrue(results.isEmpty());
|
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2008-07-07 19:38:17 -04:00
|
|
|
@Test
|
2009-08-17 10:19:07 -04:00
|
|
|
public void searchTitleAlias() throws Exception {
|
|
|
|
// Seikai no Senki (main title), Banner of the Stars (official English title)
|
|
|
|
assertEquals("Seikai no Senki", anidb.search("banner of the stars").get(0).getName());
|
2009-05-25 16:13:30 -04:00
|
|
|
assertEquals("Seikai no Senki", anidb.search("seikai no senki").get(0).getName());
|
|
|
|
|
|
|
|
// no matching title
|
|
|
|
assertEquals("Naruto", anidb.search("naruto").get(0).getName());
|
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2008-07-07 19:38:17 -04:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListAll() throws Exception {
|
2008-07-08 14:26:18 -04:00
|
|
|
List<Episode> list = anidb.getEpisodeList(monsterSearchResult);
|
2008-07-07 19:38:17 -04:00
|
|
|
|
|
|
|
assertEquals(74, list.size());
|
|
|
|
|
|
|
|
Episode first = list.get(0);
|
|
|
|
|
2009-01-24 19:08:57 -05:00
|
|
|
assertEquals("Monster", first.getSeriesName());
|
2011-10-01 00:08:46 -04:00
|
|
|
assertEquals("2004-04-07", first.getSeriesStartDate().toString());
|
2008-07-07 19:38:17 -04:00
|
|
|
assertEquals("Herr Dr. Tenma", first.getTitle());
|
2010-10-24 08:10:30 -04:00
|
|
|
assertEquals("1", first.getEpisode().toString());
|
2010-11-09 03:04:12 -05:00
|
|
|
assertEquals("1", first.getAbsolute().toString());
|
2009-05-03 11:21:04 -04:00
|
|
|
assertEquals(null, first.getSeason());
|
2010-10-23 08:47:43 -04:00
|
|
|
assertEquals("2004-04-07", first.airdate().toString());
|
2008-07-07 19:38:17 -04:00
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2008-07-07 19:38:17 -04:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListAllShortLink() throws Exception {
|
2008-07-08 14:26:18 -04:00
|
|
|
List<Episode> list = anidb.getEpisodeList(twelvekingdomsSearchResult);
|
2008-07-07 19:38:17 -04:00
|
|
|
|
|
|
|
assertEquals(45, list.size());
|
|
|
|
|
|
|
|
Episode first = list.get(0);
|
|
|
|
|
2011-08-08 13:37:45 -04:00
|
|
|
assertEquals("The Twelve Kingdoms", first.getSeriesName());
|
2011-10-01 00:08:46 -04:00
|
|
|
assertEquals("2002-04-09", first.getSeriesStartDate().toString());
|
2008-07-07 19:38:17 -04:00
|
|
|
assertEquals("Shadow of the Moon, The Sea of Shadow - Chapter 1", first.getTitle());
|
2010-10-24 08:10:30 -04:00
|
|
|
assertEquals("1", first.getEpisode().toString());
|
2010-11-09 03:04:12 -05:00
|
|
|
assertEquals("1", first.getAbsolute().toString());
|
2009-05-03 11:21:04 -04:00
|
|
|
assertEquals(null, first.getSeason());
|
2010-10-23 08:47:43 -04:00
|
|
|
assertEquals("2002-04-09", first.airdate().toString());
|
2008-07-07 19:38:17 -04:00
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2009-09-22 16:56:43 -04:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListEncoding() throws Exception {
|
|
|
|
assertEquals("Raven Princess - An der schönen blauen Donau", anidb.getEpisodeList(princessTutuSearchResult).get(6).getTitle());
|
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2010-11-11 09:23:59 -05:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListI18N() throws Exception {
|
2012-02-13 04:54:57 -05:00
|
|
|
List<Episode> list = anidb.getEpisodeList(monsterSearchResult, SortOrder.Airdate, Locale.JAPANESE);
|
2010-11-11 09:23:59 -05:00
|
|
|
|
|
|
|
Episode last = list.get(73);
|
2011-08-08 13:37:45 -04:00
|
|
|
assertEquals("モンスター", last.getSeriesName());
|
2011-10-01 00:08:46 -04:00
|
|
|
assertEquals("2004-04-07", last.getSeriesStartDate().toString());
|
2010-11-11 09:23:59 -05:00
|
|
|
assertEquals("本当の怪物", last.getTitle());
|
|
|
|
assertEquals("74", last.getEpisode().toString());
|
|
|
|
assertEquals("74", last.getAbsolute().toString());
|
|
|
|
assertEquals(null, last.getSeason());
|
|
|
|
assertEquals("2005-09-28", last.airdate().toString());
|
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2009-05-25 16:30:32 -04:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListTrimRecap() throws Exception {
|
|
|
|
assertEquals("Sea God of the East, Azure Sea of the West - Transition Chapter", anidb.getEpisodeList(twelvekingdomsSearchResult).get(44).getTitle());
|
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2008-07-07 19:38:17 -04:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListLink() throws Exception {
|
2009-10-28 11:09:47 -04:00
|
|
|
assertEquals("http://anidb.net/a1539", anidb.getEpisodeListLink(monsterSearchResult).toURL().toString());
|
2008-07-07 19:38:17 -04:00
|
|
|
}
|
|
|
|
|
2012-02-13 04:54:57 -05:00
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
@BeforeClass
|
|
|
|
@AfterClass
|
|
|
|
public static void clearCache() {
|
|
|
|
CacheManager.getInstance().clearAll();
|
|
|
|
}
|
|
|
|
|
2008-07-07 19:38:17 -04:00
|
|
|
}
|