2009-01-04 13:28:28 -05:00
|
|
|
|
|
|
|
package net.sourceforge.filebot.web;
|
|
|
|
|
|
|
|
|
2009-05-17 13:22:44 -04:00
|
|
|
import static org.junit.Assert.*;
|
2009-01-04 13:28:28 -05:00
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
import org.junit.AfterClass;
|
|
|
|
import org.junit.BeforeClass;
|
2009-07-03 09:07:43 -04:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
import net.sf.ehcache.CacheManager;
|
2011-12-20 08:00:38 -05:00
|
|
|
import net.sourceforge.filebot.web.TheTVDBClient.BannerDescriptor;
|
2009-01-04 13:28:28 -05:00
|
|
|
import net.sourceforge.filebot.web.TheTVDBClient.MirrorType;
|
2011-12-21 00:54:30 -05:00
|
|
|
import net.sourceforge.filebot.web.TheTVDBClient.SeriesInfo;
|
2009-01-04 13:28:28 -05:00
|
|
|
import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult;
|
|
|
|
|
|
|
|
|
|
|
|
public class TheTVDBClientTest {
|
|
|
|
|
|
|
|
private TheTVDBClient thetvdb = new TheTVDBClient("BA864DEE427E384A");
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Test
|
|
|
|
public void search() throws Exception {
|
|
|
|
// test default language and query escaping (blanks)
|
|
|
|
List<SearchResult> results = thetvdb.search("babylon 5");
|
|
|
|
|
2009-08-27 19:30:21 -04:00
|
|
|
assertEquals(1, results.size());
|
2009-01-04 13:28:28 -05:00
|
|
|
|
|
|
|
TheTVDBSearchResult first = (TheTVDBSearchResult) results.get(0);
|
|
|
|
|
|
|
|
assertEquals("Babylon 5", first.getName());
|
|
|
|
assertEquals(70726, first.getSeriesId());
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Test
|
|
|
|
public void searchGerman() throws Exception {
|
2011-10-01 00:08:46 -04:00
|
|
|
List<SearchResult> results = thetvdb.search("Buffy the Vampire Slayer", Locale.GERMAN);
|
2009-01-04 13:28:28 -05:00
|
|
|
|
2011-10-01 00:08:46 -04:00
|
|
|
assertEquals(2, results.size());
|
2009-01-04 13:28:28 -05:00
|
|
|
|
|
|
|
TheTVDBSearchResult first = (TheTVDBSearchResult) results.get(0);
|
|
|
|
|
2011-10-01 00:08:46 -04:00
|
|
|
assertEquals("Buffy the Vampire Slayer", first.getName());
|
2009-01-04 13:28:28 -05:00
|
|
|
assertEquals(70327, first.getSeriesId());
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListAll() throws Exception {
|
|
|
|
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Buffy the Vampire Slayer", 70327));
|
|
|
|
|
2009-04-25 03:57:14 -04:00
|
|
|
assertTrue(list.size() >= 144);
|
2009-01-04 13:28:28 -05:00
|
|
|
|
2010-02-04 09:30:39 -05:00
|
|
|
// check ordinary episode
|
2009-01-04 13:28:28 -05:00
|
|
|
Episode first = list.get(0);
|
2009-01-24 19:08:57 -05:00
|
|
|
assertEquals("Buffy the Vampire Slayer", first.getSeriesName());
|
2011-10-01 00:08:46 -04:00
|
|
|
assertEquals("1997-03-10", first.getSeriesStartDate().toString());
|
2010-02-04 09:30:39 -05:00
|
|
|
assertEquals("Welcome to the Hellmouth (1)", first.getTitle());
|
2010-10-24 08:10:30 -04:00
|
|
|
assertEquals("1", first.getEpisode().toString());
|
|
|
|
assertEquals("1", first.getSeason().toString());
|
2010-11-09 03:04:12 -05:00
|
|
|
assertEquals("1", first.getAbsolute().toString());
|
2010-10-23 08:47:43 -04:00
|
|
|
assertEquals("1997-03-10", first.airdate().toString());
|
2010-02-04 09:30:39 -05:00
|
|
|
|
|
|
|
// check special episode
|
|
|
|
Episode last = list.get(list.size() - 1);
|
|
|
|
assertEquals("Buffy the Vampire Slayer", last.getSeriesName());
|
2010-10-21 10:47:47 -04:00
|
|
|
assertEquals("Unaired Pilot", last.getTitle());
|
2010-10-24 09:26:30 -04:00
|
|
|
assertEquals("1", last.getSeason().toString());
|
|
|
|
assertEquals(null, last.getEpisode());
|
2011-08-08 13:37:45 -04:00
|
|
|
assertEquals(null, last.getAbsolute());
|
2010-10-24 09:26:30 -04:00
|
|
|
assertEquals("1", last.getSpecial().toString());
|
2010-10-23 08:47:43 -04:00
|
|
|
assertEquals(null, last.airdate());
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListSingleSeason() throws Exception {
|
2009-07-03 09:07:43 -04:00
|
|
|
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Wonderfalls", 78845), 1);
|
2009-01-04 13:28:28 -05:00
|
|
|
|
2011-08-08 13:37:45 -04:00
|
|
|
assertEquals(14, list.size());
|
2009-01-04 13:28:28 -05:00
|
|
|
|
2010-10-23 08:47:43 -04:00
|
|
|
Episode first = list.get(0);
|
2009-01-04 13:28:28 -05:00
|
|
|
|
2010-10-23 08:47:43 -04:00
|
|
|
assertEquals("Wonderfalls", first.getSeriesName());
|
2011-10-01 00:08:46 -04:00
|
|
|
assertEquals("2004-03-12", first.getSeriesStartDate().toString());
|
2010-10-23 08:47:43 -04:00
|
|
|
assertEquals("Wax Lion", first.getTitle());
|
2010-10-24 08:10:30 -04:00
|
|
|
assertEquals("1", first.getEpisode().toString());
|
|
|
|
assertEquals("1", first.getSeason().toString());
|
2010-11-09 03:04:12 -05:00
|
|
|
assertEquals(null, first.getAbsolute()); // should be "1" but data has not yet been entered
|
2010-10-23 08:47:43 -04:00
|
|
|
assertEquals("2004-03-12", first.airdate().toString());
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2010-11-15 05:06:24 -05:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListNumbering() throws Exception {
|
|
|
|
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Firefly", 78874), 1);
|
|
|
|
|
|
|
|
assertEquals(14, list.size());
|
|
|
|
|
|
|
|
Episode first = list.get(0);
|
|
|
|
assertEquals("Firefly", first.getSeriesName());
|
2011-10-01 00:08:46 -04:00
|
|
|
assertEquals("2002-09-20", first.getSeriesStartDate().toString());
|
2010-11-15 05:06:24 -05:00
|
|
|
assertEquals("Serenity", first.getTitle());
|
|
|
|
assertEquals("1", first.getEpisode().toString());
|
|
|
|
assertEquals("1", first.getSeason().toString());
|
|
|
|
assertEquals("1", first.getAbsolute().toString());
|
|
|
|
assertEquals("2002-12-20", first.airdate().toString());
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListLink() {
|
|
|
|
assertEquals("http://www.thetvdb.com/?tab=seasonall&id=78874", thetvdb.getEpisodeListLink(new TheTVDBSearchResult("Firefly", 78874)).toString());
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Test
|
|
|
|
public void getEpisodeListLinkSingleSeason() {
|
|
|
|
assertEquals("http://www.thetvdb.com/?tab=season&seriesid=73965&seasonid=6749", thetvdb.getEpisodeListLink(new TheTVDBSearchResult("Roswell", 73965), 3).toString());
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Test
|
|
|
|
public void getMirror() throws Exception {
|
|
|
|
assertNotNull(thetvdb.getMirror(MirrorType.XML));
|
|
|
|
assertNotNull(thetvdb.getMirror(MirrorType.BANNER));
|
|
|
|
assertNotNull(thetvdb.getMirror(MirrorType.ZIP));
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
@Test
|
|
|
|
public void resolveTypeMask() {
|
|
|
|
// no flags set
|
|
|
|
assertEquals(EnumSet.noneOf(MirrorType.class), MirrorType.fromTypeMask(0));
|
|
|
|
|
|
|
|
// xml and zip flags set
|
|
|
|
assertEquals(EnumSet.of(MirrorType.ZIP, MirrorType.XML), MirrorType.fromTypeMask(5));
|
|
|
|
|
|
|
|
// all flags set
|
|
|
|
assertEquals(EnumSet.allOf(MirrorType.class), MirrorType.fromTypeMask(7));
|
|
|
|
}
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2011-12-21 00:54:30 -05:00
|
|
|
@Test
|
|
|
|
public void getSeriesInfo() throws Exception {
|
2011-12-21 03:31:57 -05:00
|
|
|
SeriesInfo it = thetvdb.getSeriesInfo(new TheTVDBSearchResult(null, 80348), Locale.ENGLISH);
|
2011-12-21 00:54:30 -05:00
|
|
|
|
|
|
|
assertEquals(80348, it.getId(), 0);
|
|
|
|
assertEquals("Adam Baldwin", it.getActors().get(2));
|
|
|
|
assertEquals("TV-PG", it.getContentRating());
|
|
|
|
assertEquals("2007-09-24", it.getFirstAired().toString());
|
|
|
|
assertEquals("Action and Adventure", it.getGenre().get(0));
|
|
|
|
assertEquals(934814, it.getImdbId(), 0);
|
|
|
|
assertEquals("English", it.getLanguage().getDisplayLanguage(Locale.ENGLISH));
|
|
|
|
assertEquals(310, it.getOverview().length());
|
|
|
|
assertEquals("60", it.getRuntime());
|
2011-12-21 03:46:19 -05:00
|
|
|
assertEquals("Chuck", it.getName());
|
2011-12-21 00:54:30 -05:00
|
|
|
assertEquals("http://thetvdb.com/banners/graphical/80348-g23.jpg", it.getBannerUrl().toString());
|
|
|
|
assertEquals("http://thetvdb.com/banners/fanart/original/80348-51.jpg", it.getFanartUrl().toString());
|
|
|
|
assertEquals("http://thetvdb.com/banners/posters/80348-16.jpg", it.getPosterUrl().toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-19 21:37:36 -05:00
|
|
|
@Test
|
|
|
|
public void getBanner() throws Exception {
|
2011-12-21 00:54:30 -05:00
|
|
|
BannerDescriptor banner = thetvdb.getBanner(new TheTVDBSearchResult("Buffy the Vampire Slayer", 70327), "season", "seasonwide", 7, Locale.ENGLISH, 0);
|
2011-12-19 21:37:36 -05:00
|
|
|
|
2011-12-20 08:00:38 -05:00
|
|
|
assertEquals(857660, banner.getId(), 0);
|
|
|
|
assertEquals("season", banner.getBannerType());
|
|
|
|
assertEquals("seasonwide", banner.getBannerType2());
|
|
|
|
assertEquals("http://thetvdb.com/banners/seasonswide/70327-7.jpg", banner.getUrl().toString());
|
|
|
|
assertEquals(99712, WebRequest.fetch(banner.getUrl()).remaining(), 0);
|
2011-12-19 21:37:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
2011-12-20 08:00:38 -05:00
|
|
|
public void getBannerList() throws Exception {
|
|
|
|
List<BannerDescriptor> banners = thetvdb.getBannerList(70327);
|
2011-12-19 21:37:36 -05:00
|
|
|
|
|
|
|
assertEquals(106, banners.size());
|
2011-12-20 08:00:38 -05:00
|
|
|
assertEquals("fanart", banners.get(0).getBannerType());
|
|
|
|
assertEquals("1280x720", banners.get(0).getBannerType2());
|
|
|
|
assertEquals(486993, WebRequest.fetch(banners.get(0).getUrl()).remaining(), 0);
|
2011-12-19 21:37:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
@BeforeClass
|
|
|
|
@AfterClass
|
|
|
|
public static void clearCache() {
|
|
|
|
CacheManager.getInstance().clearAll();
|
|
|
|
}
|
|
|
|
|
2009-01-04 13:28:28 -05:00
|
|
|
}
|