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

209 lines
6.7 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;
2011-12-30 14:31:33 -05:00
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
2011-12-30 14:31:33 -05:00
import java.util.Map;
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;
2012-10-25 14:06:12 -04:00
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
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 {
2012-02-13 04:54:57 -05:00
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Wonderfalls", 78845));
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 {
2012-02-13 04:54:57 -05:00
List<Episode> list = thetvdb.getEpisodeList(new TheTVDBSearchResult("Firefly", 78874), SortOrder.DVD, Locale.ENGLISH);
2010-11-15 05:06:24 -05:00
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 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
2013-03-18 01:23:41 -04:00
assertEquals(EnumSet.of(MirrorType.ZIP, MirrorType.XML, MirrorType.SEARCH), 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 lookupByID() throws Exception {
TheTVDBSearchResult series = thetvdb.lookupByID(78874, Locale.ENGLISH);
assertEquals("Firefly", series.getName());
2012-02-13 04:54:57 -05:00
assertEquals(78874, series.getSeriesId());
}
@Test
public void lookupByIMDbID() throws Exception {
2012-02-13 04:54:57 -05:00
TheTVDBSearchResult series = thetvdb.lookupByIMDbID(303461, Locale.ENGLISH);
assertEquals("Firefly", series.getName());
2012-02-13 04:54:57 -05:00
assertEquals(78874, series.getSeriesId());
}
@Test
public void getSeriesInfo() throws Exception {
SeriesInfo it = thetvdb.getSeriesInfo(new TheTVDBSearchResult(null, 80348), Locale.ENGLISH);
assertEquals(80348, it.getId(), 0);
assertEquals("TV-PG", it.getContentRating());
assertEquals("2007-09-24", it.getFirstAired().toString());
2013-03-18 01:23:41 -04:00
assertEquals("Action", it.getGenres().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-19 21:37:36 -05:00
@Test
public void getBanner() throws Exception {
2011-12-30 14:31:33 -05:00
Map<String, String> filter = new HashMap<String, String>();
filter.put("BannerType", "season");
filter.put("BannerType2", "seasonwide");
filter.put("Season", "7");
filter.put("Language", "en");
BannerDescriptor banner = thetvdb.getBanner(new TheTVDBSearchResult("Buffy the Vampire Slayer", 70327), filter);
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 {
2011-12-28 23:05:10 -05:00
List<BannerDescriptor> banners = thetvdb.getBannerList(new TheTVDBSearchResult("Buffy the Vampire Slayer", 70327));
2011-12-19 21:37:36 -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
}
@BeforeClass
@AfterClass
public static void clearCache() {
CacheManager.getInstance().clearAll();
}
}