filebot/test/net/filebot/web/TMDbClientTest.java

163 lines
5.1 KiB
Java
Raw Normal View History

2014-04-19 02:30:29 -04:00
package net.filebot.web;
import static net.filebot.CachedResource.*;
import static org.junit.Assert.*;
import java.net.URL;
import java.time.Duration;
2016-07-18 15:29:31 -04:00
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import org.junit.Ignore;
import org.junit.Test;
import net.filebot.Cache;
import net.filebot.CacheType;
import net.filebot.CachedResource;
public class TMDbClientTest {
static TMDbClient db = new TMDbClient("66308fb6e3fd850dde4c7d21df2e8306", false);
@Test
public void searchByName() throws Exception {
2016-05-09 10:59:21 -04:00
List<Movie> result = db.searchMovie("Serenity", Locale.CHINESE);
2011-09-22 08:55:04 -04:00
Movie movie = result.get(0);
assertEquals("冲出宁静号", movie.getName());
2011-01-07 06:02:11 -05:00
assertEquals(2005, movie.getYear());
assertEquals(-1, movie.getImdbId());
assertEquals(16320, movie.getTmdbId());
}
@Test
public void searchByNameWithYearShortName() throws Exception {
2016-05-09 10:59:21 -04:00
List<Movie> result = db.searchMovie("Up 2009", Locale.ENGLISH);
Movie movie = result.get(0);
assertEquals("Up", movie.getName());
assertEquals(2009, movie.getYear());
assertEquals(-1, movie.getImdbId());
assertEquals(14160, movie.getTmdbId());
}
@Test
public void searchByNameWithYearNumberName() throws Exception {
2016-05-09 10:59:21 -04:00
List<Movie> result = db.searchMovie("9 (2009)", Locale.ENGLISH);
Movie movie = result.get(0);
assertEquals("9", movie.getName());
assertEquals(2009, movie.getYear());
assertEquals(-1, movie.getImdbId());
assertEquals(12244, movie.getTmdbId());
}
@Test
public void searchByNameGerman() throws Exception {
2016-05-09 10:59:21 -04:00
List<Movie> result = db.searchMovie("East of Eden", Locale.GERMAN);
Movie movie = result.get(0);
assertEquals("Jenseits von Eden", movie.getName());
assertEquals(1955, movie.getYear());
assertEquals(Arrays.asList("Jenseits von Eden (1955)", "East of Eden (1955)"), movie.getEffectiveNames());
}
@Test
public void searchByNameMexican() throws Exception {
List<Movie> result = db.searchMovie("Suicide Squad", new Locale("es", "MX"));
Movie movie = result.get(0);
assertEquals("Escuadrón suicida", movie.getName());
assertEquals(2016, movie.getYear());
assertEquals(-1, movie.getImdbId());
assertEquals(297761, movie.getTmdbId());
}
@Test
public void searchByIMDB() throws Exception {
2016-05-09 10:59:21 -04:00
Movie movie = db.getMovieDescriptor(new Movie(418279), Locale.ENGLISH);
assertEquals("Transformers", movie.getName());
assertEquals(2007, movie.getYear(), 0);
assertEquals(418279, movie.getImdbId(), 0);
assertEquals(1858, movie.getTmdbId(), 0);
}
@Test
public void getMovieInfo() throws Exception {
2016-05-09 10:59:21 -04:00
MovieInfo movie = db.getMovieInfo(new Movie(418279), Locale.ENGLISH, true);
assertEquals("Transformers", movie.getName());
assertEquals("2007-06-27", movie.getReleased().toString());
assertEquals("PG-13", movie.getCertification());
assertEquals("[es, en]", movie.getSpokenLanguages().toString());
assertEquals("Shia LaBeouf", movie.getActors().get(0));
assertEquals("Michael Bay", movie.getDirector());
}
@Test
public void getAlternativeTitles() throws Exception {
Map<String, List<String>> titles = db.getAlternativeTitles(16320); // Serenity
assertEquals("[宁静号]", titles.get("HK").toString());
}
@Test
public void getArtwork() throws Exception {
2016-05-09 10:59:21 -04:00
Artwork a = db.getArtwork(16320, "backdrops", Locale.ROOT).get(0);
assertEquals("[backdrops, 1920x1080]", a.getTags().toString());
assertEquals("http://image.tmdb.org/t/p/original/mQPg3iZyztfzFNwrW40nCUtXy2l.jpg", a.getUrl().toString());
2016-03-26 13:40:59 -04:00
}
2016-05-09 10:59:21 -04:00
@Test
public void getPeople() throws Exception {
Person p = db.getMovieInfo("16320", Locale.ENGLISH, true).getCrew().get(0);
2016-05-09 10:59:21 -04:00
assertEquals("Nathan Fillion", p.getName());
assertEquals("Mal", p.getCharacter());
assertEquals(null, p.getJob());
assertEquals(null, p.getDepartment());
assertEquals("0", p.getOrder().toString());
assertEquals("http://image.tmdb.org/t/p/original/B7VTVtnKyFk0AtYjEbqzBQlPec.jpg", p.getImage().toString());
}
2016-07-18 15:29:31 -04:00
@Test
public void discoverPeriod() throws Exception {
Movie m = db.discover(LocalDate.parse("2014-09-15"), LocalDate.parse("2014-10-22"), Locale.ENGLISH).get(0);
2016-10-20 15:48:33 -04:00
assertEquals("John Wick", m.getName());
2016-07-18 15:29:31 -04:00
assertEquals(2014, m.getYear());
2016-10-20 15:48:33 -04:00
assertEquals(245891, m.getTmdbId());
2016-07-18 15:29:31 -04:00
}
2016-07-20 03:30:26 -04:00
@Test
public void discoverBestOfYear() throws Exception {
Movie m = db.discover(2015, Locale.ENGLISH).get(0);
assertEquals("Mad Max: Fury Road", m.getName());
assertEquals(2015, m.getYear());
assertEquals(76341, m.getTmdbId());
}
@Ignore
2012-04-08 04:41:48 -04:00
@Test
public void floodLimit() throws Exception {
for (Locale it : Locale.getAvailableLocales()) {
2016-05-09 10:59:21 -04:00
List<Movie> results = db.searchMovie("Serenity", it);
assertEquals(16320, results.get(0).getTmdbId());
2012-04-08 04:41:48 -04:00
}
}
@Ignore
@Test
public void etag() throws Exception {
Cache cache = Cache.getCache("test", CacheType.Persistent);
Cache etagStorage = Cache.getCache("etag", CacheType.Persistent);
CachedResource<String, byte[]> resource = cache.bytes("http://devel.squid-cache.org/old_projects.html#etag", URL::new).fetch(fetchIfNoneMatch(etagStorage::get, etagStorage::put)).expire(Duration.ZERO);
assertArrayEquals(resource.get(), resource.get());
}
}