filebot/test/net/sourceforge/filebot/web/TheTVDBClientTest.java

200 lines
6.6 KiB
Java
Raw Normal View History

package net.sourceforge.filebot.web;
2009-05-17 13:22:44 -04:00
import static org.junit.Assert.*;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import org.junit.AfterClass;
import org.junit.BeforeClass;
2009-07-03 09:07:43 -04:00
import org.junit.Test;
import net.sf.ehcache.CacheManager;
import net.sourceforge.filebot.web.TheTVDBClient.BannerDescriptor;
import net.sourceforge.filebot.web.TheTVDBClient.MirrorType;
import net.sourceforge.filebot.web.TheTVDBClient.SeriesInfo;
import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult;
public class TheTVDBClientTest {
private TheTVDBClient thetvdb = new TheTVDBClient("BA864DEE427E384A");
2011-12-19 21:37:36 -05:00
@Test
public void search() throws Exception {
// test default language and query escaping (blanks)
List<SearchResult> results = thetvdb.search("babylon 5");
assertEquals(1, results.size());
TheTVDBSearchResult first = (TheTVDBSearchResult) results.get(0);
assertEquals("Babylon 5", first.getName());
assertEquals(70726, first.getSeriesId());
}
2011-12-19 21:37:36 -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);
2011-10-01 00:08:46 -04:00
assertEquals(2, results.size());
TheTVDBSearchResult first = (TheTVDBSearchResult) results.get(0);
2011-10-01 00:08:46 -04:00
assertEquals("Buffy the Vampire Slayer", first.getName());
assertEquals(70327, first.getSeriesId());
}
2011-12-19 21:37:36 -05:00
@Test
public void getEpisodeListAll() throws Exception {
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Buffy the Vampire Slayer", 70327));
assertTrue(list.size() >= 144);
2010-02-04 09:30:39 -05:00
// check ordinary episode
Episode first = list.get(0);
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());
assertEquals("1", first.getEpisode().toString());
assertEquals("1", first.getSeason().toString());
assertEquals("1", first.getAbsolute().toString());
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());
assertEquals("Unaired Pilot", last.getTitle());
2010-10-24 09:26:30 -04:00
assertEquals("1", last.getSeason().toString());
assertEquals(null, last.getEpisode());
assertEquals(null, last.getAbsolute());
2010-10-24 09:26:30 -04:00
assertEquals("1", last.getSpecial().toString());
assertEquals(null, last.airdate());
}
2011-12-19 21:37:36 -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);
assertEquals(14, list.size());
Episode first = list.get(0);
assertEquals("Wonderfalls", first.getSeriesName());
2011-10-01 00:08:46 -04:00
assertEquals("2004-03-12", first.getSeriesStartDate().toString());
assertEquals("Wax Lion", first.getTitle());
assertEquals("1", first.getEpisode().toString());
assertEquals("1", first.getSeason().toString());
assertEquals(null, first.getAbsolute()); // should be "1" but data has not yet been entered
assertEquals("2004-03-12", first.airdate().toString());
}
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
@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
@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
@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
@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
@Test
public void getSeriesInfo() throws Exception {
SeriesInfo it = thetvdb.getSeriesInfo(new TheTVDBSearchResult(null, 80348), Locale.ENGLISH);
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());
assertEquals("Chuck", it.getSeriesName());
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 {
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
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
public void getBannerList() throws Exception {
List<BannerDescriptor> banners = thetvdb.getBannerList(70327);
2011-12-19 21:37:36 -05:00
assertEquals(106, banners.size());
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
}
@BeforeClass
@AfterClass
public static void clearCache() {
CacheManager.getInstance().clearAll();
}
}