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

157 lines
4.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.MirrorType;
import net.sourceforge.filebot.web.TheTVDBClient.TheTVDBSearchResult;
public class TheTVDBClientTest {
private TheTVDBClient thetvdb = new TheTVDBClient("BA864DEE427E384A");
2009-07-03 09:07:43 -04: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());
}
@Test
public void searchGerman() throws Exception {
List<SearchResult> results = thetvdb.search("buffy", Locale.GERMAN);
assertEquals(4, results.size());
TheTVDBSearchResult first = (TheTVDBSearchResult) results.get(0);
assertEquals("Buffy", first.getName());
assertEquals(70327, first.getSeriesId());
TheTVDBSearchResult second = (TheTVDBSearchResult) results.get(1);
assertEquals("Buffy the Vampire Slayer", second.getName());
assertEquals(70327, second.getSeriesId());
}
@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());
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());
2011-08-05 00:32:28 -04:00
assertEquals("1", last.getAbsolute().toString());
2010-10-24 09:26:30 -04:00
assertEquals("1", last.getSpecial().toString());
assertEquals(null, last.airdate());
}
@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-07-03 09:07:43 -04:00
assertEquals(13, list.size());
Episode first = list.get(0);
assertEquals("Wonderfalls", first.getSeriesName());
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());
}
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());
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());
}
@Test
public void getEpisodeListLink() {
assertEquals("http://www.thetvdb.com/?tab=seasonall&id=78874", thetvdb.getEpisodeListLink(new TheTVDBSearchResult("Firefly", 78874)).toString());
}
@Test
public void getEpisodeListLinkSingleSeason() {
assertEquals("http://www.thetvdb.com/?tab=season&seriesid=73965&seasonid=6749", thetvdb.getEpisodeListLink(new TheTVDBSearchResult("Roswell", 73965), 3).toString());
}
@Test
public void getMirror() throws Exception {
assertNotNull(thetvdb.getMirror(MirrorType.XML));
assertNotNull(thetvdb.getMirror(MirrorType.BANNER));
assertNotNull(thetvdb.getMirror(MirrorType.ZIP));
}
@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));
}
@BeforeClass
@AfterClass
public static void clearCache() {
CacheManager.getInstance().clearAll();
}
}