/*
* Copyright (c) 2004-2015 Stuart Boston
*
* This file is part of TheMovieDB API.
*
* TheMovieDB API is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* TheMovieDB API is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with TheMovieDB API. If not, see .
*
*/
package com.omertron.themoviedbapi;
import com.omertron.themoviedbapi.model.AlternativeTitle;
import com.omertron.themoviedbapi.model.Artwork;
import com.omertron.themoviedbapi.model.ChangedMedia;
import com.omertron.themoviedbapi.model.Collection;
import com.omertron.themoviedbapi.model.CollectionInfo;
import com.omertron.themoviedbapi.model.Company;
import com.omertron.themoviedbapi.model.Discover;
import com.omertron.themoviedbapi.model.Genre;
import com.omertron.themoviedbapi.model.JobDepartment;
import com.omertron.themoviedbapi.model.Keyword;
import com.omertron.themoviedbapi.model.KeywordMovie;
import com.omertron.themoviedbapi.model.MovieDb;
import com.omertron.themoviedbapi.model.MovieDbList;
import com.omertron.themoviedbapi.model.MovieList;
import com.omertron.themoviedbapi.model.Person;
import com.omertron.themoviedbapi.model.PersonCredit;
import com.omertron.themoviedbapi.model.ReleaseInfo;
import com.omertron.themoviedbapi.model.Reviews;
import com.omertron.themoviedbapi.model.Configuration;
import com.omertron.themoviedbapi.model.TokenAuthorisation;
import com.omertron.themoviedbapi.model.TokenSession;
import com.omertron.themoviedbapi.model.Translation;
import com.omertron.themoviedbapi.model.Video;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.apache.commons.lang3.StringUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
* Test cases for TheMovieDbApi API
*
* @author stuart.boston
*/
public class TheMovieDbApiTest extends AbstractTests{
private static TheMovieDbApi tmdb;
// Test data
private static final int ID_MOVIE_BLADE_RUNNER = 78;
private static final int ID_MOVIE_THE_AVENGERS = 24428;
private static final int ID_COLLECTION_STAR_WARS = 10;
private static final int ID_PERSON_BRUCE_WILLIS = 62;
private static final int ID_COMPANY = 2;
private static final String COMPANY_NAME = "Marvel Studios";
private static final int ID_GENRE_ACTION = 28;
private static final String ID_KEYWORD = "1721";
// Languages
private static final String LANGUAGE_DEFAULT = "";
private static final String LANGUAGE_ENGLISH = "en";
private static final String LANGUAGE_RUSSIAN = "ru";
// session and account id of test users named 'apitests'
public TheMovieDbApiTest() throws MovieDbException {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
tmdb = new TheMovieDbApi(getApiKey());
}
/**
* Test of getConfiguration method, of class TheMovieDbApi.
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testConfiguration() throws MovieDbException {
LOG.info("Test Configuration");
Configuration tmdbConfig = tmdb.getConfiguration();
assertNotNull("Configuration failed", tmdbConfig);
assertTrue("No base URL", StringUtils.isNotBlank(tmdbConfig.getBaseUrl()));
assertTrue("No backdrop sizes", tmdbConfig.getBackdropSizes().size() > 0);
assertTrue("No poster sizes", tmdbConfig.getPosterSizes().size() > 0);
assertTrue("No profile sizes", tmdbConfig.getProfileSizes().size() > 0);
LOG.info(tmdbConfig.toString());
}
/**
* Test of searchMovie method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testSearchMovie() throws MovieDbException {
LOG.info("searchMovie");
// Try a movie with less than 1 page of results
TmdbResultsList movieList = tmdb.searchMovie("Blade Runner", 0, "", true, 0);
// List movieList = tmdb.searchMovie("Blade Runner", "", true);
assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0);
// Try a russian langugage movie
movieList = tmdb.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, true, 0);
assertTrue("No 'RU' movies found, should be at least 1", movieList.getResults().size() > 0);
// Try a movie with more than 20 results
movieList = tmdb.searchMovie("Star Wars", 0, LANGUAGE_ENGLISH, false, 0);
assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15);
}
/**
* Test of getMovieInfo method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieInfo() throws MovieDbException {
LOG.info("getMovieInfo");
MovieDb result = tmdb.getMovieInfo(ID_MOVIE_BLADE_RUNNER, LANGUAGE_ENGLISH, "alternative_titles,casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists");
assertEquals("Incorrect movie information", "Blade Runner", result.getOriginalTitle());
}
/**
* Test of getMovieAlternativeTitles method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieAlternativeTitles() throws MovieDbException {
LOG.info("getMovieAlternativeTitles");
String country = "";
TmdbResultsList result = tmdb.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country, "casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists");
assertTrue("No alternative titles found", result.getResults().size() > 0);
country = "US";
result = tmdb.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country);
assertTrue("No alternative titles found", result.getResults().size() > 0);
}
/**
* Test of getMovieCasts method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieCasts() throws MovieDbException {
LOG.info("getMovieCasts");
TmdbResultsList people = tmdb.getMovieCasts(ID_MOVIE_BLADE_RUNNER, "alternative_titles,casts,images,keywords,releases,trailers,translations,similar_movies,reviews,lists");
assertTrue("No cast information", people.getResults().size() > 0);
String name1 = "Harrison Ford";
String name2 = "Charles Knode";
boolean foundName1 = Boolean.FALSE;
boolean foundName2 = Boolean.FALSE;
for (Person person : people.getResults()) {
if (!foundName1 && person.getName().equalsIgnoreCase(name1)) {
foundName1 = Boolean.TRUE;
}
if (!foundName2 && person.getName().equalsIgnoreCase(name2)) {
foundName2 = Boolean.TRUE;
}
}
assertTrue("Couldn't find " + name1, foundName1);
assertTrue("Couldn't find " + name2, foundName2);
}
/**
* Test of getMovieImages method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieImages() throws MovieDbException {
LOG.info("getMovieImages");
String language = "";
TmdbResultsList result = tmdb.getMovieImages(ID_MOVIE_BLADE_RUNNER, language);
assertFalse("No artwork found", result.getResults().isEmpty());
}
/**
* Test of getMovieKeywords method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieKeywords() throws MovieDbException {
LOG.info("getMovieKeywords");
TmdbResultsList result = tmdb.getMovieKeywords(ID_MOVIE_BLADE_RUNNER);
assertFalse("No keywords found", result.getResults().isEmpty());
}
/**
* Test of getMovieReleaseInfo method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieReleaseInfo() throws MovieDbException {
LOG.info("getMovieReleaseInfo");
TmdbResultsList result = tmdb.getMovieReleaseInfo(ID_MOVIE_BLADE_RUNNER, "");
assertFalse("Release information missing", result.getResults().isEmpty());
}
/**
* Test of getMovieTrailers method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieTrailers() throws MovieDbException {
LOG.info("getMovieTrailers");
TmdbResultsList