Updated methods

master
Stuart Boston 11 years ago
parent debfb1209e
commit ba64e339b1

@ -0,0 +1,106 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi;
import com.omertron.themoviedbapi.tools.HttpTools;
import java.io.File;
import java.util.Properties;
import org.apache.http.impl.client.HttpClient;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.BeforeClass;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.SimpleHttpClientBuilder;
public class AbstractTests {
protected static final Logger LOG = LoggerFactory.getLogger(AbstractTests.class);
private static final String PROP_FIlENAME = "testing.properties";
private static final Properties props = new Properties();
private static HttpClient httpClient;
private static HttpTools httpTools;
// Constants
protected static final String LANGUAGE_DEFAULT = "";
protected static final String LANGUAGE_ENGLISH = "en";
protected static final String LANGUAGE_RUSSIAN = "ru";
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
httpClient = new SimpleHttpClientBuilder().build();
httpTools = new HttpTools(httpClient);
if (props.isEmpty()) {
File f = new File(PROP_FIlENAME);
if (f.exists()) {
LOG.info("Loading properties from '{}'", PROP_FIlENAME);
TestLogger.loadProperties(props, f);
} else {
LOG.info("Property file '{}' not found, creating dummy file.", PROP_FIlENAME);
props.setProperty("API_Key", "INSERT_YOUR_KEY_HERE");
props.setProperty("Username", "INSERT_YOUR_USERNAME_HERE");
props.setProperty("Password", "INSERT_YOUR_PASSWORD_HERE");
TestLogger.saveProperties(props, f, "Properties file for tests");
fail("Failed to get key information from properties file '" + PROP_FIlENAME + "'");
}
}
}
@AfterClass
public static void tearDownClass() throws MovieDbException {
}
@Before
public void setUp() throws MovieDbException {
}
@After
public void tearDown() throws MovieDbException {
}
public static HttpClient getHttpClient() {
return httpClient;
}
public static HttpTools getHttpTools() {
return httpTools;
}
public static String getApiKey() {
return props.getProperty("API_Key");
}
public static String getUsername() {
return props.getProperty("Username");
}
public static String getPassword() {
return props.getProperty("Password");
}
public static String getProperty(String property) {
return props.getProperty(property);
}
}

@ -0,0 +1,185 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import com.omertron.themoviedbapi.model.Account;
import com.omertron.themoviedbapi.model.MovieDb;
import com.omertron.themoviedbapi.model.MovieDbList;
import com.omertron.themoviedbapi.model.StatusCode;
import java.util.List;
import org.junit.AfterClass;
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 org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
*
* @author stuart.boston
*/
public class TmdbAccountTest extends AbstractTests {
// API
private static TmdbAccount instance;
// Constants
private static final int ID_MOVIE_FIGHT_CLUB = 550;
public TmdbAccountTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbAccount(getApiKey(), getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* Test of getAccount method, of class TmdbAccount.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetAccount() throws MovieDbException {
LOG.info("getAccount");
Account result = instance.getAccount(SESSION_ID_APITESTS);
assertEquals("Wrong account returned", ACCOUNT_ID_APITESTS, result.getId());
}
/**
* Test of getUserLists method, of class TmdbAccount.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetUserLists() throws MovieDbException {
LOG.info("getUserLists");
List<MovieDbList> result = instance.getUserLists(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertNotNull("Null list returned", result);
}
/**
* Test of getFavoriteMovies method, of class TmdbAccount.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetFavoriteMovies() throws MovieDbException {
LOG.info("getFavoriteMovies");
LOG.info("Check favorite list is empty");
// make sure it's empty (because it's just a test account
List<MovieDb> favList = instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertTrue("Favorite list was not empty!", favList.isEmpty());
LOG.info("Add movie to list");
// add a movie
StatusCode status = instance.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, ID_MOVIE_FIGHT_CLUB, true);
LOG.info("Add Status: {}", status);
LOG.info("Get favorite list");
favList = instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertNotNull("Empty favorite list returned", favList);
assertFalse("Favorite list empty", favList.isEmpty());
// clean up again
LOG.info("Remove movie(s) from list");
for (MovieDb movie : favList) {
LOG.info("Removing movie {}-'{}'", movie.getId(), movie.getTitle());
status = instance.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, movie.getId(), false);
LOG.info("Remove status: {}", status);
}
assertTrue("Favorite list was not empty", instance.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty());
}
/**
* Test of changeFavoriteStatus method, of class TmdbAccount.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Tested as part of getFavoriteMovies")
public void testChangeFavoriteStatus() throws MovieDbException {
}
/**
* Test of getRatedMovies method, of class TmdbAccount.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetRatedMovies() throws MovieDbException {
LOG.info("getRatedMovies");
List<MovieDb> result = instance.getRatedMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertFalse("No rated movies", result.isEmpty());
}
/**
* Test of getWatchList method, of class TmdbAccount.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetWatchList() throws MovieDbException {
LOG.info("getWatchList");
LOG.info("Check list is empty");
// make sure it's empty (because it's just a test account
List<MovieDb> watchList = instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertTrue("Watch list was not empty!", watchList.isEmpty());
LOG.info("Add movie to list");
// add a movie
StatusCode status = instance.modifyWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, ID_MOVIE_FIGHT_CLUB, true);
LOG.info("Add Status: {}", status);
LOG.info("Get watch list");
watchList = instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertNotNull("Empty watch list returned", watchList);
assertFalse("Watchlist list empty", watchList.isEmpty());
LOG.info("Removing movie(s) from list");
// clean up again
for (MovieDb movie : watchList) {
LOG.info("Removing movie {}-'{}'", movie.getId(), movie.getTitle());
status = instance.modifyWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, movie.getId(), false);
LOG.info("Remove status: {}", status);
}
assertTrue(instance.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty());
}
/**
* Test of modifyWatchList method, of class TmdbAccount.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Tested as part of testGetWatchList")
public void testModifyWatchList() throws MovieDbException {
}
}

@ -0,0 +1,99 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import com.omertron.themoviedbapi.model.TokenAuthorisation;
import com.omertron.themoviedbapi.model.TokenSession;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
*
* @author stuart.boston
*/
public class TmdbAuthenticationTest extends AbstractTests{
// API
private static TmdbAuthentication instance;
public TmdbAuthenticationTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbAuthentication(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* Test of getAuthorisationToken method, of class TmdbAuthentication.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetAuthorisationToken() throws MovieDbException {
LOG.info("getAuthorisationToken");
TokenAuthorisation token = instance.getAuthorisationToken();
assertFalse("Token is null", token == null);
assertTrue("Token is not valid", token.getSuccess());
}
/**
* Test of getSessionToken method, of class TmdbAuthentication.
*
* TODO: Cannot be tested without a HTTP authorisation: <br/>
* http://help.themoviedb.org/kb/api/user-authentication
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Session needs to be authorised")
public void testGetSessionToken() throws MovieDbException {
LOG.info("getSessionToken");
TokenAuthorisation token = instance.getAuthorisationToken();
// Need to authorise the token here.
TokenSession result = instance.getSessionToken(token);
assertFalse("Session token is null", result == null);
assertTrue("Session token is not valid", result.getSuccess());
}
/**
* Test of getGuestSessionToken method, of class TmdbAuthentication.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetGuestSessionToken() throws MovieDbException {
LOG.info("getGuestSessionToken");
TokenSession result = instance.getGuestSessionToken();
assertTrue("Failed to get guest session", result.getSuccess());
}
}

@ -0,0 +1,79 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import com.omertron.themoviedbapi.model.Certification;
import com.omertron.themoviedbapi.results.TmdbResultsMap;
import java.util.List;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import org.junit.BeforeClass;
import org.junit.Test;
/**
*
* @author stuart.boston
* @author Luca Tagliani
*/
public class TmdbCertificationsTest extends AbstractTests {
// API
private static TmdbCertifications instance;
public TmdbCertificationsTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbCertifications(getApiKey(), getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* Test of getMoviesCertification method, of class TmdbCertifications.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieCertifications() throws MovieDbException {
LOG.info("getMovieCertifications");
TmdbResultsMap<String, List<Certification>> result = instance.getMoviesCertification();
assertFalse("No movie certifications.", result.getResults().isEmpty());
}
/**
* Test of getTvCertification method, of class TmdbCertifications.
*
* @throws MovieDbException
*/
@Test
public void testGetTvCertifications() throws MovieDbException {
LOG.info("getTvCertifications");
TmdbResultsMap<String, List<Certification>> result = instance.getTvCertification();
assertFalse("No tv certifications.", result.getResults().isEmpty());
}
}

@ -0,0 +1,86 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import com.omertron.themoviedbapi.model.ChangedMovie;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
*
* @author stuart.boston
*/
public class TmdbChangesTest extends AbstractTests {
// API
private static TmdbChanges instance;
public TmdbChangesTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbChanges(getApiKey(), getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* Test of getMovieChangesList method, of class TmdbChanges.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieChangesList() throws MovieDbException {
LOG.info("getMovieChangesList");
int page = 0;
String startDate = "";
String endDate = "";
TmdbResultsList<ChangedMovie> result = instance.getMovieChangesList(page, startDate, endDate);
assertFalse("No movie changes.", result.getResults().isEmpty());
}
/**
* Test of getPersonMovieOldChangesList method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Ignore("Not ready yet")
public void testGetPersonChangesList() throws MovieDbException {
LOG.info("getPersonChangesList");
int page = 0;
String startDate = "";
String endDate = "";
instance.getPersonChangesList(page, startDate, endDate);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
}

@ -0,0 +1,81 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import com.omertron.themoviedbapi.model.Artwork;
import com.omertron.themoviedbapi.model.CollectionInfo;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import org.junit.BeforeClass;
import org.junit.Test;
/**
*
* @author stuart.boston
*/
public class TmdbCollectionsTest extends AbstractTests {
// API
private static TmdbCollections instance;
private static final int ID_COLLECTION_STAR_WARS = 10;
public TmdbCollectionsTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbCollections(getApiKey(), getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* Test of getCollectionInfo method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetCollectionInfo() throws MovieDbException {
LOG.info("getCollectionInfo");
String language = "";
CollectionInfo result = instance.getCollectionInfo(ID_COLLECTION_STAR_WARS, language);
assertFalse("No collection information", result.getParts().isEmpty());
}
/**
* Test of getCollectionImages method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetCollectionImages() throws MovieDbException {
LOG.info("getCollectionImages");
TmdbResultsList<Artwork> result = instance.getCollectionImages(ID_COLLECTION_STAR_WARS, LANGUAGE_DEFAULT);
assertFalse("No artwork found", result.getResults().isEmpty());
}
}

@ -0,0 +1,98 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT;
import com.omertron.themoviedbapi.model.Company;
import com.omertron.themoviedbapi.model.movie.MovieDb;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbCompaniesTest extends AbstractTests{
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbCompaniesTest.class);
// API
private static TmdbCompanies instance;
private static final int ID_COMPANY = 2;
public TmdbCompaniesTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbCompanies(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getCompanyInfo method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetCompanyInfo() throws MovieDbException {
LOG.info("getCompanyInfo");
Company company = instance.getCompanyInfo(ID_COMPANY);
assertTrue("No company information found", company.getCompanyId() > 0);
assertNotNull("No parent company found", company.getParentCompany());
}
/**
* Test of getCompanyMovies method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetCompanyMovies() throws MovieDbException {
LOG.info("getCompanyMovies");
TmdbResultsList<MovieDb> result = instance.getCompanyMovies(ID_COMPANY, LANGUAGE_DEFAULT, 0);
assertTrue("No company movies found", !result.getResults().isEmpty());
}
}

@ -0,0 +1,105 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import com.omertron.themoviedbapi.model.Configuration;
import com.omertron.themoviedbapi.model.type.ArtworkType;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbConfigurationTest extends AbstractTests {
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbConfigurationTest.class);
// API
private static TmdbConfiguration instance;
public TmdbConfigurationTest() {
}
@BeforeClass
public static void setUpClass() {
TestLogger.Configure();
instance = new TmdbConfiguration(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getConfig method, of class TmdbConfiguration.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetConfig() throws MovieDbException {
LOG.info("getConfig");
Configuration result = instance.getConfig();
LOG.info(result.toString());
assertFalse("No backdrop sizes", result.getBackdropSizes().isEmpty());
assertFalse("No logo sizes", result.getLogoSizes().isEmpty());
assertFalse("No poster sizes", result.getPosterSizes().isEmpty());
assertFalse("No profile sizes", result.getProfileSizes().isEmpty());
assertTrue("No base url", StringUtils.isNotBlank(result.getBaseUrl()));
assertTrue("No secure base url", StringUtils.isNotBlank(result.getSecureBaseUrl()));
}
/**
* Test of createImageUrl method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testCreateImageUrl() throws MovieDbException {
LOG.info("createImageUrl");
Configuration config = instance.getConfig();
String result = config.createImageUrl("http://mediaplayersite.com/image.jpg", ArtworkType.POSTER, "original").toString();
assertTrue("Error compiling image URL", !result.isEmpty());
}
}

@ -0,0 +1,86 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import com.omertron.themoviedbapi.model.person.PersonCredits;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbCreditsTest extends AbstractTests{
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbCreditsTest.class);
// API
private static TmdbCredits instance;
public TmdbCreditsTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbCredits(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getCreditInfo method, of class TmdbCredits.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetCreditInfo() throws MovieDbException {
LOG.info("getCreditInfo");
String creditId = "525346f619c29579400d4145";
String language = "";
PersonCredits result = instance.getCreditInfo(creditId, language);
assertEquals("Wrong name", "Sean Bean", result.getPerson().getName());
assertEquals("Wrong job", "Actor", result.getJob());
assertFalse("No seasons", result.getMedia().getSeasons().isEmpty());
}
}

@ -0,0 +1,102 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_ENGLISH;
import com.omertron.themoviedbapi.model.discover.Discover;
import com.omertron.themoviedbapi.model.movie.MovieDb;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbDiscoverTest extends AbstractTests {
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbDiscoverTest.class);
// API
private static TmdbDiscover instance;
public TmdbDiscoverTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbDiscover(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getDiscoverMovie method, of class TmdbDiscover.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetDiscoverMovie() throws MovieDbException {
LOG.info("getDiscoverMovie");
Discover discover = new Discover();
discover.year(2013).language(LANGUAGE_ENGLISH);
TmdbResultsList<MovieDb> result = instance.getDiscoverMovie(discover);
assertFalse("No movies discovered", result.getResults().isEmpty());
}
/**
* Test of getDiscoverTv method, of class TmdbDiscover.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetDiscoverTv() throws MovieDbException {
LOG.info("getDiscoverTv");
Discover discover = new Discover();
discover.year(2013).language(LANGUAGE_ENGLISH);
TmdbResultsList<MovieDb> result = instance.getDiscoverMovie(discover);
assertFalse("No TV shows discovered", result.getResults().isEmpty());
}
}

@ -0,0 +1,97 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import com.omertron.themoviedbapi.model.FindResults;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
* @author Luca Tagliani
*/
public class TmdbFindTest extends AbstractTests {
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbFindTest.class);
// API
private static TmdbFind instance;
public TmdbFindTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbFind(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getMovieChangesList method, of class TmdbFindTest.
*
* @throws MovieDbException
*/
@Test
public void testFindMoviesImdbID() throws MovieDbException {
LOG.info("findMoviesImdbID");
FindResults result = instance.find("tt0196229", TmdbFind.ExternalSource.imdb_id, "it");
assertFalse("No movie for id.", result.getMovieResults().isEmpty());
}
@Test
public void testFindTvSeriesImdbID() throws MovieDbException {
LOG.info("findTvSeriesImdbID");
FindResults result = instance.find("tt1219024", TmdbFind.ExternalSource.imdb_id, "it");
assertFalse("No tv for id.", result.getTvResults().isEmpty());
}
@Test
public void testFindPersonImdbID() throws MovieDbException {
LOG.info("findPersonImdbID");
FindResults result = instance.find("nm0001774", TmdbFind.ExternalSource.imdb_id, "it");
assertFalse("No person for id.", result.getPersonResults().isEmpty());
}
}

@ -0,0 +1,97 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT;
import com.omertron.themoviedbapi.model.Genre;
import com.omertron.themoviedbapi.model.movie.MovieDb;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbGenresTest extends AbstractTests {
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class);
// API
private static TmdbGenres instance;
private static final int ID_GENRE_ACTION = 28;
public TmdbGenresTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbGenres(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getGenreList method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetGenreList() throws MovieDbException {
LOG.info("getGenreList");
TmdbResultsList<Genre> result = instance.getGenreList(LANGUAGE_DEFAULT);
assertTrue("No genres found", !result.getResults().isEmpty());
}
/**
* Test of getGenreMovies method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetGenreMovies() throws MovieDbException {
LOG.info("getGenreMovies");
TmdbResultsList<MovieDb> result = instance.getGenreMovies(ID_GENRE_ACTION, LANGUAGE_DEFAULT, 0, Boolean.TRUE);
assertTrue("No genre movies found", !result.getResults().isEmpty());
}
}

@ -0,0 +1,82 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import com.omertron.themoviedbapi.model.JobDepartment;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbJobsTest extends AbstractTests {
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class);
// API
private static TmdbJobs tmdb;
public TmdbJobsTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
tmdb = new TmdbJobs(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getJobs method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetJobs() throws MovieDbException {
LOG.info("getJobs");
TmdbResultsList<JobDepartment> result = tmdb.getJobs();
assertFalse("No jobs found", result.getResults().isEmpty());
}
}

@ -0,0 +1,99 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT;
import com.omertron.themoviedbapi.model.Keyword;
import com.omertron.themoviedbapi.model.movie.MovieDbBasic;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbKeywordsTest extends AbstractTests{
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class);
// API
private static TmdbKeywords tmdb;
private static final String ID_KEYWORD = "1721";
public TmdbKeywordsTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
tmdb = new TmdbKeywords(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getKeyword method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetKeyword() throws MovieDbException {
LOG.info("getKeyword");
Keyword result = tmdb.getKeyword(ID_KEYWORD);
assertEquals("fight", result.getName());
}
/**
* Test of getMovieDbBasics method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetKeywordMovies() throws MovieDbException {
LOG.info("getKeywordMovies");
int page = 0;
TmdbResultsList<MovieDbBasic> result = tmdb.getKeywordMovies(ID_KEYWORD, LANGUAGE_DEFAULT, page);
assertFalse("No keyword movies found", result.getResults().isEmpty());
}
}

@ -0,0 +1,170 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import static com.omertron.themoviedbapi.TheMovieDbApiTest.SESSION_ID_APITESTS;
import com.omertron.themoviedbapi.model.StatusCode;
import com.omertron.themoviedbapi.model.StatusCodeList;
import com.omertron.themoviedbapi.model.movie.MovieDbList;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.fail;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TmdbListsTest extends AbstractTests{
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class);
// API
private static TmdbLists instance;
public TmdbListsTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbLists(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of createList method, of class TmdbList.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Not working")
public void test1CreateList() throws MovieDbException {
LOG.info("createList");
String name = "My Totally Awesome List";
String description = "This list was created to share all of the totally awesome movies I've seen.";
StatusCodeList result = instance.createList(SESSION_ID_APITESTS, name, description);
LOG.info(result.toString());
// TODO review the generated test code and remove the default call to fail.
// fail("The test case is a prototype.");
}
/**
* Test of getList method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void test2GetList() throws MovieDbException {
LOG.info("getList");
String listId = "509ec17b19c2950a0600050d";
MovieDbList result = instance.getList(listId);
assertFalse("List not found", result.getItems().isEmpty());
}
/**
* Test of addMovieToList method, of class TmdbList.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Not working")
public void test3AddMovieToList() throws MovieDbException {
LOG.info("addMovieToList");
String listId = "";
Integer movieId = null;
StatusCode expResult = null;
StatusCode result = instance.addMovieToList(SESSION_ID_APITESTS, listId, movieId);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of isMovieOnList method, of class TmdbList.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Not working")
public void test4IsMovieOnList() throws MovieDbException {
LOG.info("isMovieOnList");
String listId = "";
Integer movieId = null;
boolean expResult = false;
boolean result = instance.isMovieOnList(listId, movieId);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of removeMovieFromList method, of class TmdbList.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Not working")
public void test5RemoveMovieFromList() throws MovieDbException {
LOG.info("removeMovieFromList");
String listId = "";
Integer movieId = null;
StatusCode expResult = null;
StatusCode result = instance.removeMovieFromList(SESSION_ID_APITESTS, listId, movieId);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
/**
* Test of deleteMovieList method, of class TmdbList.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Not working")
public void test6DeleteMovieList() throws MovieDbException {
LOG.info("deleteMovieList");
String listId = "";
StatusCode expResult = null;
StatusCode result = instance.deleteMovieList(SESSION_ID_APITESTS, listId);
assertEquals(expResult, result);
// TODO review the generated test code and remove the default call to fail.
fail("The test case is a prototype.");
}
}

@ -0,0 +1,420 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.ACCOUNT_ID_APITESTS;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_ENGLISH;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.SESSION_ID_APITESTS;
import com.omertron.themoviedbapi.model.AlternativeTitle;
import com.omertron.themoviedbapi.model.Artwork;
import com.omertron.themoviedbapi.model.ChangedItem;
import com.omertron.themoviedbapi.model.Keyword;
import com.omertron.themoviedbapi.model.ReleaseInfo;
import com.omertron.themoviedbapi.model.Review;
import com.omertron.themoviedbapi.model.Trailer;
import com.omertron.themoviedbapi.model.Translation;
import com.omertron.themoviedbapi.model.movie.MovieDb;
import com.omertron.themoviedbapi.model.movie.MovieList;
import com.omertron.themoviedbapi.model.movie.MovieState;
import com.omertron.themoviedbapi.model.person.PersonMovieOld;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.results.TmdbResultsMap;
import java.util.List;
import java.util.Random;
import org.junit.AfterClass;
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 org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
/**
*
* @author stuart.boston
*/
public class TmdbMoviesTest extends AbstractTests{
// API
private static TmdbMovies instance;
private static final int ID_MOVIE_BLADE_RUNNER = 78;
private static final int ID_MOVIE_THE_AVENGERS = 24428;
public TmdbMoviesTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbMovies(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* Test of getMovieInfo method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieInfo() throws MovieDbException {
LOG.info("getMovieInfo");
MovieDb result = instance.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 getMovieInfoImdb method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieInfoImdb() throws MovieDbException {
LOG.info("getMovieInfoImdb");
MovieDb result = instance.getMovieInfoImdb("tt0076759", "en-US");
assertTrue("Error getting the movie from IMDB ID", result.getId() == 11);
}
/**
* Test of getMovieAlternativeTitles method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieAlternativeTitles() throws MovieDbException {
LOG.info("getMovieAlternativeTitles");
String country = "";
TmdbResultsList<AlternativeTitle> result = instance.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 = instance.getMovieAlternativeTitles(ID_MOVIE_BLADE_RUNNER, country);
assertTrue("No alternative titles found", result.getResults().size() > 0);
}
/**
* Test of getMovieCredits method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieCasts() throws MovieDbException {
LOG.info("getMovieCasts");
TmdbResultsList<PersonMovieOld> people = instance.getMovieCredits(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 (PersonMovieOld 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<Artwork> result = instance.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<Keyword> result = instance.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<ReleaseInfo> result = instance.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<Trailer> result = instance.getMovieTrailers(ID_MOVIE_BLADE_RUNNER, "");
assertFalse("Movie trailers missing", result.getResults().isEmpty());
}
/**
* Test of getMovieTranslations method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieTranslations() throws MovieDbException {
LOG.info("getMovieTranslations");
TmdbResultsList<Translation> result = instance.getMovieTranslations(ID_MOVIE_BLADE_RUNNER);
assertFalse("No translations found", result.getResults().isEmpty());
}
/**
* Test of getSimilarMovies method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetSimilarMovies() throws MovieDbException {
LOG.info("getSimilarMovies");
TmdbResultsList<MovieDb> result = instance.getSimilarMovies(ID_MOVIE_BLADE_RUNNER, LANGUAGE_DEFAULT, 0);
assertTrue("No similar movies found", !result.getResults().isEmpty());
}
/**
* Test of getReview method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetReviews() throws MovieDbException {
LOG.info("getReviews");
int page = 0;
TmdbResultsList<Review> result = instance.getReviews(ID_MOVIE_THE_AVENGERS, LANGUAGE_DEFAULT, page);
assertFalse("No reviews found", result.getResults().isEmpty());
}
/**
* Test of getMovieLists method, of class TmdbMovie.
*
* @throws MovieDbException
*/
@Test
public void testGetMovieLists() throws MovieDbException {
LOG.info("getMovieLists");
TmdbResultsList<MovieList> result = instance.getMovieLists(ID_MOVIE_BLADE_RUNNER, LANGUAGE_ENGLISH, 0);
assertNotNull("No results found", result);
assertTrue("No results found", result.getResults().size() > 0);
}
/**
* Test of getMovieChanges method,of class TheMovieDbApi
*
* @throws MovieDbException
*/
@Ignore("Do not test this until it is fixed")
public void testGetMovieChanges() throws MovieDbException {
LOG.info("getMovieChanges");
String startDate = "";
String endDate = null;
// Get some popular movies
TmdbResultsList<MovieDb> movieList = instance.getPopularMovieList(LANGUAGE_DEFAULT, 0);
for (MovieDb movie : movieList.getResults()) {
TmdbResultsMap<String, List<ChangedItem>> result = instance.getMovieChanges(movie.getId(), startDate, endDate);
LOG.info("{} has {} changes.", movie.getTitle(), result.getResults().size());
assertTrue("No changes found", result.getResults().size() > 0);
break;
}
}
/**
* Test of getLatestMovie method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetLatestMovie() throws MovieDbException {
LOG.info("getLatestMovie");
MovieDb result = instance.getLatestMovie();
assertTrue("No latest movie found", result != null);
assertTrue("No latest movie found", result.getId() > 0);
}
/**
* Test of getUpcoming method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetUpcoming() throws MovieDbException {
LOG.info("getUpcoming");
TmdbResultsList<MovieDb> result = instance.getUpcoming(LANGUAGE_DEFAULT, 0);
assertTrue("No upcoming movies found", !result.getResults().isEmpty());
}
/**
* Test of getNowPlayingMovies method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetNowPlayingMovies() throws MovieDbException {
LOG.info("getNowPlayingMovies");
TmdbResultsList<MovieDb> result = instance.getNowPlayingMovies(LANGUAGE_DEFAULT, 0);
assertTrue("No now playing movies found", !result.getResults().isEmpty());
}
/**
* Test of getPopularMovieList method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetPopularMovieList() throws MovieDbException {
LOG.info("getPopularMovieList");
TmdbResultsList<MovieDb> result = instance.getPopularMovieList(LANGUAGE_DEFAULT, 0);
assertTrue("No popular movies found", !result.getResults().isEmpty());
}
/**
* Test of getTopRatedMovies method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetTopRatedMovies() throws MovieDbException {
LOG.info("getTopRatedMovies");
TmdbResultsList<MovieDb> result = instance.getTopRatedMovies(LANGUAGE_DEFAULT, 0);
assertTrue("No top rated movies found", !result.getResults().isEmpty());
}
/**
* Test of postMovieRating method, of class TheMovieDbApi.
*
* TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication /**
*
* @throws MovieDbException
*/
@Test
public void testMovieRating() throws MovieDbException {
LOG.info("postMovieRating");
Integer movieID = 68724;
Integer rating = new Random().nextInt(10) + 1;
boolean wasPosted = instance.postMovieRating(SESSION_ID_APITESTS, movieID, rating);
assertTrue("Failed to post rating", wasPosted);
try {
// Make sure that we pause long enough for the record to by updated
Thread.sleep(5000);
} catch (InterruptedException ex) {
// Ignore the exception and move on
}
// get all rated movies
TmdbAccount account = new TmdbAccount(getApiKey(),getHttpTools());
List<MovieDb> ratedMovies = account.getRatedMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertTrue(ratedMovies.size() > 0);
// make sure that we find the movie and it is rated correctly
boolean foundMovie = false;
for (MovieDb movie : ratedMovies) {
if (movie.getId() == movieID) {
assertEquals("Incorrect rating", movie.getUserRating(), (float) rating, 0);
foundMovie = true;
break;
}
}
assertTrue("Movie not found!", foundMovie);
}
/**
* Test of getMovieCredits method, of class TmdbMovies.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetMovieCredits() throws MovieDbException {
LOG.info("getMovieCredits");
TmdbResultsList<PersonMovieOld> result = instance.getMovieCredits(ID_MOVIE_BLADE_RUNNER, "");
assertFalse("No credits returned", result.getResults().isEmpty());
}
/**
* Test of getMovieStatus method, of class TmdbMovies.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetMovieStatus() throws MovieDbException {
LOG.info("getMovieStatus");
// This movie should be rated
MovieState result = instance.getMovieStatus(SESSION_ID_APITESTS, ID_MOVIE_BLADE_RUNNER);
assertNotNull("No state returned", result);
assertFalse("Movie is favourited", result.isFavorite());
assertFalse("Movie is not rated", result.getRating() < 0);
assertFalse("Movie is watch listed", result.isWatchlist());
// This movie should not be rated
result = instance.getMovieStatus(SESSION_ID_APITESTS, ID_MOVIE_THE_AVENGERS);
assertNotNull("No state returned", result);
assertFalse("Movie is favourited", result.isFavorite());
assertFalse("Movie is rated", result.getRating() > -1);
assertFalse("Movie is watch listed", result.isWatchlist());
}
/**
* Test of postMovieRating method, of class TmdbMovies.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testPostMovieRating() throws MovieDbException {
LOG.info("postMovieRating");
Integer rating = 10;
boolean result = instance.postMovieRating(SESSION_ID_APITESTS, ID_MOVIE_BLADE_RUNNER, rating);
assertEquals("Failed to set rating", true, result);
}
}

@ -0,0 +1,65 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import com.omertron.themoviedbapi.model.tv.Network;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import org.junit.BeforeClass;
import org.junit.Test;
/**
*
* @author stuart.boston
*/
public class TmdbNetworksTest extends AbstractTests {
// API
private static TmdbNetworks instance;
public TmdbNetworksTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbNetworks(getApiKey(), getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* Test of getNetworkInfo method, of class TmdbNetworks.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetNetworkInfo() throws MovieDbException {
LOG.info("getNetworkInfo");
Network result = instance.getNetworkInfo(1);
assertEquals("Wrong network returned", "Fuji Television", result.getName());
}
}

@ -0,0 +1,215 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import static com.omertron.themoviedbapi.TheMovieDbApiTest.LANGUAGE_DEFAULT;
import com.omertron.themoviedbapi.model.Artwork;
import com.omertron.themoviedbapi.model.person.NewCast;
import com.omertron.themoviedbapi.model.person.NewPersonCredits;
import com.omertron.themoviedbapi.model.person.Person;
import com.omertron.themoviedbapi.model.person.PersonBasic;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
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 org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbPeopleTest extends AbstractTests{
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbGenresTest.class);
// API
private static TmdbPeople instance;
private static final int ID_BRUCE_WILLIS = 62;
private static final int ID_SEAN_BEAN = 48;
private static final int ID_DICK_WOLF = 117443;
public TmdbPeopleTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbPeople(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getPersonMovieOldInfo method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
// @Test
public void testGetPersonInfo() throws MovieDbException {
LOG.info("getPersonInfo");
Person result = instance.getPersonInfo(ID_BRUCE_WILLIS);
assertTrue("Wrong actor returned", result.getId() == ID_BRUCE_WILLIS);
assertTrue("Missing bio", StringUtils.isNotBlank(result.getBiography()));
assertTrue("Missing birthday", StringUtils.isNotBlank(result.getBirthday()));
assertTrue("Missing homepage", StringUtils.isNotBlank(result.getHomepage()));
assertTrue("Missing IMDB", StringUtils.isNotBlank(result.getImdbId()));
assertTrue("Missing name", StringUtils.isNotBlank(result.getName()));
assertTrue("Missing birth place", StringUtils.isNotBlank(result.getBirthplace()));
assertTrue("Missing artwork", StringUtils.isNotBlank(result.getProfilePath()));
assertTrue("Missing bio", result.getPopularity() > 0F);
}
/**
* Test of getPersonMovieOldImages method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
// @Test
public void testGetPersonImages() throws MovieDbException {
LOG.info("getPersonImages");
TmdbResultsList<Artwork> result = instance.getPersonImages(ID_BRUCE_WILLIS);
assertTrue("No cast information", result.getResults().size() > 0);
for (Artwork artwork : result.getResults()) {
assertTrue("Artwork is blank", StringUtils.isNotBlank(artwork.getFilePath()));
}
}
/**
* Test of getPersonChanges method, of class TmdbPeople.
*
* @throws MovieDbException
*/
@Ignore("Not ready yet")
public void testGetPersonChanges() throws MovieDbException {
LOG.info("getPersonChanges");
String startDate = "";
String endDate = "";
instance.getPersonChanges(ID_BRUCE_WILLIS, startDate, endDate);
}
/**
* Test of getPersonPopular method, of class TmdbPeople.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
public void testGetPersonPopular() throws MovieDbException {
LOG.info("getPersonPopular");
int page = 0;
TmdbResultsList<PersonBasic> result = instance.getPersonPopular(page);
assertFalse("No popular people", result.getResults().isEmpty());
for (PersonBasic person : result.getResults()) {
assertTrue("Missing name", StringUtils.isNotBlank(person.getName()));
}
}
/**
* Test of getPersonLatest method, of class TmdbPeople.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
public void testGetPersonLatest() throws MovieDbException {
LOG.info("getPersonLatest");
Person result = instance.getPersonLatest();
assertNotNull("No results found", result);
assertTrue("No results found", StringUtils.isNotBlank(result.getName()));
}
/**
* Test of getPersonMovieOldCredits method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testGetPersonMovieCredits() throws MovieDbException {
LOG.info("getPersonMovieCredits");
NewPersonCredits result = instance.getPersonMovieCredits(ID_BRUCE_WILLIS, LANGUAGE_DEFAULT);
assertEquals("Invalid ID", ID_BRUCE_WILLIS, result.getId());
assertFalse("No cast information returned", result.getCast().isEmpty());
for(NewCast person:result.getCast()) {
LOG.info(person.toString());
}
assertFalse("No crew information returned", result.getCrew().isEmpty());
}
/**
* Test of getPersonTvCredits method, of class TmdbPeople.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
public void testGetPersonTvCredits() throws MovieDbException {
LOG.info("getPersonTvCredits");
NewPersonCredits result = instance.getPersonTvCredits(ID_DICK_WOLF, LANGUAGE_DEFAULT);
assertEquals("Invalid ID", ID_DICK_WOLF, result.getId());
assertFalse("No cast information returned", result.getCast().isEmpty());
assertFalse("No crew information returned", result.getCrew().isEmpty());
}
/**
* Test of getPersonCombinedCredits method, of class TmdbPeople.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
// @Test
public void testGetPersonCombinedCredits() throws MovieDbException {
LOG.info("getPersonCombinedCredits");
NewPersonCredits result = instance.getPersonCombinedCredits(ID_SEAN_BEAN, LANGUAGE_DEFAULT);
assertEquals("Invalid ID", ID_SEAN_BEAN, result.getId());
assertFalse("No cast information returned", result.getCast().isEmpty());
assertFalse("No crew information returned", result.getCrew().isEmpty());
LOG.info("{}", result.toString());
}
}

@ -0,0 +1,85 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import static com.omertron.themoviedbapi.TheMovieDbApiTest.getApiKey();
import com.omertron.themoviedbapi.model.Review;
import org.apache.commons.lang3.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yamj.api.common.http.DefaultPoolingHttpClient;
/**
*
* @author stuart.boston
*/
public class TmdbReviewsTest extends AbstractTests{
// Logger
private static final Logger LOG = LoggerFactory.getLogger(TmdbAuthenticationTest.class);
// API
private static TmdbReviews instance;
public TmdbReviewsTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbReviews(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
/**
* Test of getReview method, of class TmdbReviews.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetReview() throws MovieDbException {
LOG.info("getReview");
String reviewId = "5013bc76760ee372cb00253e";
Review result = instance.getReview(reviewId);
LOG.info(result.toString());
assertTrue("No Author", StringUtils.isNotBlank(result.getAuthor()));
assertTrue("No Content", StringUtils.isNotBlank(result.getContent()));
}
}

@ -0,0 +1,168 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import com.omertron.themoviedbapi.model.Collection;
import com.omertron.themoviedbapi.model.Company;
import com.omertron.themoviedbapi.model.Keyword;
import com.omertron.themoviedbapi.model.MovieDb;
import com.omertron.themoviedbapi.model.MovieList;
import com.omertron.themoviedbapi.model.person.PersonMovieOld;
import com.omertron.themoviedbapi.model.tv.TVSeriesBasic;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.junit.AfterClass;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.BeforeClass;
import org.junit.Test;
/**
*
* @author stuart.boston
*/
public class TmdbSearchTest extends AbstractTests {
// API
private static TmdbSearch instance;
private static final String COMPANY_NAME = "Marvel Studios";
public TmdbSearchTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbSearch(getApiKey(), getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* 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<MovieDb> movieList = instance.searchMovie("Blade Runner", 0, "", true, 0);
// List<MovieDb> 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 = instance.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 = instance.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 searchTv method, of class TmdbSearch.
*
* @throws MovieDbException
*/
@Test
public void testSearchTv() throws MovieDbException {
LOG.info("searchTv");
TmdbResultsList<TVSeriesBasic> results = instance.searchTv("Big Bang Theory", 0, LANGUAGE_DEFAULT, null, 0);
assertFalse("No shows found, should be at least 1", results.getResults().isEmpty());
}
/**
* Test of searchCollection method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testSearchCollection() throws MovieDbException {
LOG.info("searchCollection");
String query = "batman";
int page = 0;
TmdbResultsList<Collection> result = instance.searchCollection(query, LANGUAGE_DEFAULT, page);
assertFalse("No collections found", result == null);
assertTrue("No collections found", result.getResults().size() > 0);
}
/**
* Test of searchPeople method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testSearchPeople() throws MovieDbException {
LOG.info("searchPeople");
String personName = "Bruce Willis";
boolean includeAdult = false;
TmdbResultsList<PersonMovieOld> result = instance.searchPeople(personName, includeAdult, 0);
assertTrue("Couldn't find the person", result.getResults().size() > 0);
}
/**
* Test of searchList method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testSearchList() throws MovieDbException {
LOG.info("searchList");
String query = "watch";
int page = 0;
TmdbResultsList<MovieList> result = instance.searchList(query, LANGUAGE_DEFAULT, page);
assertFalse("No lists found", result.getResults() == null);
assertTrue("No lists found", result.getResults().size() > 0);
}
/**
* Test of searchCompanies method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testSearchCompanies() throws MovieDbException {
LOG.info("searchCompanies");
TmdbResultsList<Company> result = instance.searchCompanies(COMPANY_NAME, 0);
assertTrue("No company information found", !result.getResults().isEmpty());
}
/**
* Test of searchKeyword method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
public void testSearchKeyword() throws MovieDbException {
LOG.info("searchKeyword");
String query = "action";
int page = 0;
TmdbResultsList<Keyword> result = instance.searchKeyword(query, page);
assertFalse("No keywords found", result.getResults() == null);
assertTrue("No keywords found", result.getResults().size() > 0);
}
}

@ -0,0 +1,225 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*
*/
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestLogger;
import com.omertron.themoviedbapi.model.Artwork;
import com.omertron.themoviedbapi.model.ExternalIds;
import com.omertron.themoviedbapi.model.tv.TVCredits;
import com.omertron.themoviedbapi.model.tv.TVEpisode;
import com.omertron.themoviedbapi.model.tv.TVSeason;
import com.omertron.themoviedbapi.model.tv.TVSeries;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import org.apache.commons.lang3.StringUtils;
import org.junit.AfterClass;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
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 for the TV Method
*
* @author stuart.boston
*/
public class TmdbTVTest extends AbstractTests {
// API
private static TmdbTV instance;
// IDs
private static final int ID_BIG_BANG_THEORY = 1418;
public TmdbTVTest() {
}
@BeforeClass
public static void setUpClass() throws MovieDbException {
TestLogger.Configure();
instance = new TmdbTV(getApiKey(),getHttpTools());
}
@AfterClass
public static void tearDownClass() {
}
/**
* Test of getTv method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
public void testGetTv() throws MovieDbException {
LOG.info("getTv");
TVSeries result = instance.getTv(ID_BIG_BANG_THEORY, LANGUAGE_DEFAULT, null);
assertEquals("Wrong title returned", "The Big Bang Theory", result.getName());
assertTrue("No seasons returned", result.getNumberSeasons() >= 5);
assertTrue("No episodes returned", result.getNumberEpisodes() > 100);
assertFalse("No genres returned", result.getGenres().isEmpty());
assertFalse("No created by", result.getCreatedBy().isEmpty());
}
/**
* Test of getTvCredits method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetTvCredits() throws MovieDbException {
LOG.info("getTvCredits");
TVCredits result = instance.getTvCredits(ID_BIG_BANG_THEORY, LANGUAGE_DEFAULT, null);
assertFalse("No cast", result.getCast().isEmpty());
assertFalse("No crew", result.getCrew().isEmpty());
assertTrue("Guest stars returned", result.getGuestStar().isEmpty());
}
/**
* Test of getTvExternalIds method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
public void testGetTvExternalIds() throws MovieDbException {
LOG.info("getTvExternalIds");
ExternalIds result = instance.getTvExternalIds(ID_BIG_BANG_THEORY, LANGUAGE_DEFAULT);
assertFalse("No ids found", result.getIds().isEmpty());
assertTrue("TMDB Id not found", result.hasId("id"));
assertEquals("Wrong id returned", Integer.toString(ID_BIG_BANG_THEORY), result.getId("id"));
assertEquals("Wrong TVDB Id returned", "80379", result.getId("tvdb_id"));
}
/**
* Test of getTvImages method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
public void testGetTvImages() throws MovieDbException {
LOG.info("getTvImages");
TmdbResultsList<Artwork> result = instance.getTvImages(ID_BIG_BANG_THEORY, LANGUAGE_DEFAULT);
assertFalse("No results found", result.getResults().isEmpty());
}
/**
* Test of getTvSeason method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
public void testGetTvSeason() throws MovieDbException {
LOG.info("getTvSeason");
TVSeason result = instance.getTvSeason(ID_BIG_BANG_THEORY, 1, LANGUAGE_DEFAULT, null);
assertFalse("No episodes found for season", result.getEpisodes().isEmpty());
assertEquals("Wrong air date", "2007-09-24", result.getAirDate());
assertEquals("Wrong season name", "Season 1", result.getName());
}
/**
* Test of getTvSeasonExternalIds method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
public void testGetTvSeasonExternalIds() throws MovieDbException {
LOG.info("getTvSeasonExternalIds");
ExternalIds result = instance.getTvSeasonExternalIds(ID_BIG_BANG_THEORY, 1, LANGUAGE_DEFAULT);
assertFalse("No ids found", result.getIds().isEmpty());
assertTrue("TMDB Id not found", result.hasId("id"));
assertEquals("Wrong season id returned", "3738", result.getId("id"));
assertEquals("Wrong TVDB Id returned", "28047", result.getId("tvdb_id"));
}
/**
* Test of getTvSeasonImages method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
public void testGetTvSeasonImages() throws MovieDbException {
LOG.info("getTvSeasonImages");
TmdbResultsList<Artwork> result = instance.getTvSeasonImages(ID_BIG_BANG_THEORY, 1, LANGUAGE_DEFAULT);
assertFalse("No results found", result.getResults().isEmpty());
}
/**
* Test of getTvEpisode method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
public void testGetTvEpisode() throws MovieDbException {
LOG.info("getTvEpisode");
TVEpisode result = instance.getTvEpisode(ID_BIG_BANG_THEORY, 1, 1, LANGUAGE_DEFAULT, null);
assertEquals("Wrong ID", 64766, result.getId());
assertEquals("Wrong date", "2007-09-24", result.getAirDate());
assertTrue("No overview", StringUtils.isNotBlank(result.getOverview()));
}
/**
* Test of getTvEpisodeCredits method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Test
public void testGetTvEpisodeCredits() throws MovieDbException {
LOG.info("getTvEpisodeCredits");
TVCredits result = instance.getTvEpisodeCredits(ID_BIG_BANG_THEORY, 1, 1, LANGUAGE_DEFAULT);
assertFalse("No cast", result.getCast().isEmpty());
assertFalse("No crew", result.getCrew().isEmpty());
assertFalse("No Guest stars returned", result.getGuestStar().isEmpty());
}
/**
* Test of getTvEpisodeExternalIds method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
@Ignore("Find an episode with ids to test this on")
public void testGetTvEpisodeExternalIds() throws MovieDbException {
LOG.info("getTvEpisodeExternalIds");
ExternalIds result = instance.getTvEpisodeExternalIds(ID_BIG_BANG_THEORY, 1, 1, LANGUAGE_DEFAULT);
LOG.info("{}", result);
assertFalse("No ids found", result.getIds().isEmpty());
assertTrue("TMDB Id not found", result.hasId("id"));
assertEquals("Wrong season id returned", "3738", result.getId("id"));
assertEquals("Wrong TVDB Id returned", "28047", result.getId("tvdb_id"));
}
/**
* Test of getTvEpisodeImages method, of class TV.
*
* @throws com.omertron.themoviedbapi.MovieDbException
*/
//@Test
public void testGetTvEpisodeImages() throws MovieDbException {
LOG.info("getTvEpisodeImages");
String result = instance.getTvEpisodeImages(ID_BIG_BANG_THEORY, 1, 1, LANGUAGE_DEFAULT);
LOG.info("{}", result);
fail("Unfinished");
}
}
Loading…
Cancel
Save