Add TestSuite

Update AccountTests
master
Stuart Boston 11 years ago
parent 1b1e2d8f67
commit a21e09a7ae

@ -27,6 +27,7 @@ import com.omertron.themoviedbapi.model.account.Account;
import com.omertron.themoviedbapi.model.list.UserList;
import com.omertron.themoviedbapi.model.movie.MovieBasic;
import com.omertron.themoviedbapi.model.tv.TVBasic;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.tools.ApiUrl;
import com.omertron.themoviedbapi.tools.HttpTools;
import com.omertron.themoviedbapi.tools.MethodBase;
@ -35,6 +36,7 @@ import com.omertron.themoviedbapi.tools.Param;
import com.omertron.themoviedbapi.tools.PostBody;
import com.omertron.themoviedbapi.tools.PostTools;
import com.omertron.themoviedbapi.tools.TmdbParameters;
import com.omertron.themoviedbapi.wrapper.WrapperGenericList;
import java.io.IOException;
import java.net.URL;
import java.util.List;
@ -58,8 +60,7 @@ public class TmdbAccount extends AbstractMethod {
}
/**
* Get the basic information for an account. You will need to have a valid
* session id.
* Get the basic information for an account. You will need to have a valid session id.
*
* @param sessionId
* @return
@ -104,13 +105,14 @@ public class TmdbAccount extends AbstractMethod {
* @return
* @throws MovieDbException
*/
public List<MovieBasic> getFavoriteMovies(String sessionId, int accountId) throws MovieDbException {
public TmdbResultsList<MovieBasic> getFavoriteMovies(String sessionId, int accountId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.SESSION_ID, sessionId);
parameters.add(Param.ID, accountId);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.FAVORITE_MOVIES).buildUrl(parameters);
return processWrapperList(getTypeReference(MovieBasic.class), url, "favorite movies");
WrapperGenericList<MovieBasic> wrapper = processWrapper(getTypeReference(MovieBasic.class), url, "favorite movies");
return wrapper.getTmdbResultsList();
}
/**
@ -121,13 +123,14 @@ public class TmdbAccount extends AbstractMethod {
* @return
* @throws MovieDbException
*/
public List<TVBasic> getFavoriteTv(String sessionId, int accountId) throws MovieDbException {
public TmdbResultsList<TVBasic> getFavoriteTv(String sessionId, int accountId) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.SESSION_ID, sessionId);
parameters.add(Param.ID, accountId);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.FAVORITE_TV).buildUrl(parameters);
return processWrapperList(getTypeReference(TVBasic.class), url, "favorite TV shows");
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "favorite TV shows");
return wrapper.getTmdbResultsList();
}
/**
@ -173,7 +176,7 @@ public class TmdbAccount extends AbstractMethod {
* @return
* @throws MovieDbException
*/
public List<MovieBasic> getRatedMovies(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
public TmdbResultsList<MovieBasic> getRatedMovies(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.SESSION_ID, sessionId);
parameters.add(Param.ID, accountId);
@ -182,7 +185,8 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.RATED_MOVIES).buildUrl(parameters);
return processWrapperList(getTypeReference(MovieBasic.class), url, "rated movies");
WrapperGenericList<MovieBasic> wrapper = processWrapper(getTypeReference(MovieBasic.class), url, "rated movies");
return wrapper.getTmdbResultsList();
}
/**
@ -196,7 +200,7 @@ public class TmdbAccount extends AbstractMethod {
* @return
* @throws MovieDbException
*/
public List<TVBasic> getRatedTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
public TmdbResultsList<TVBasic> getRatedTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.SESSION_ID, sessionId);
parameters.add(Param.ID, accountId);
@ -205,7 +209,8 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.RATED_TV).buildUrl(parameters);
return processWrapperList(getTypeReference(TVBasic.class), url, "rated TV shows");
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "rated TV shows");
return wrapper.getTmdbResultsList();
}
/**
@ -219,7 +224,7 @@ public class TmdbAccount extends AbstractMethod {
* @return The watch list of the user
* @throws MovieDbException
*/
public List<MovieBasic> getWatchListMovie(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
public TmdbResultsList<MovieBasic> getWatchListMovie(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.SESSION_ID, sessionId);
parameters.add(Param.ID, accountId);
@ -228,7 +233,8 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.WATCHLIST_MOVIES).buildUrl(parameters);
return processWrapperList(getTypeReference(MovieBasic.class), url, "movie watch list");
WrapperGenericList<MovieBasic> wrapper = processWrapper(getTypeReference(MovieBasic.class), url, "movie watch list");
return wrapper.getTmdbResultsList();
}
/**
@ -242,7 +248,7 @@ public class TmdbAccount extends AbstractMethod {
* @return The watch list of the user
* @throws MovieDbException
*/
public List<TVBasic> getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
public TmdbResultsList<TVBasic> getWatchListTV(String sessionId, int accountId, Integer page, String sortBy, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.SESSION_ID, sessionId);
parameters.add(Param.ID, accountId);
@ -251,7 +257,8 @@ public class TmdbAccount extends AbstractMethod {
parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.ACCOUNT).subMethod(MethodSub.WATCHLIST_TV).buildUrl(parameters);
return processWrapperList(getTypeReference(TVBasic.class), url, "TV watch list");
WrapperGenericList<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "TV watch list");
return wrapper.getTmdbResultsList();
}
/**
@ -296,7 +303,7 @@ public class TmdbAccount extends AbstractMethod {
* @return
* @throws MovieDbException
*/
public List<MovieBasic> getGuestRatedMovies(String guestSessionId, String language, Integer page, SortBy sortBy) throws MovieDbException {
public TmdbResultsList<MovieBasic> getGuestRatedMovies(String guestSessionId, String language, Integer page, SortBy sortBy) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.ID, guestSessionId);
parameters.add(Param.LANGUAGE, language);
@ -313,6 +320,7 @@ public class TmdbAccount extends AbstractMethod {
}
URL url = new ApiUrl(apiKey, MethodBase.GUEST_SESSION).subMethod(MethodSub.RATED_MOVIES_GUEST).buildUrl(parameters);
return processWrapperList(getTypeReference(MovieBasic.class), url, "Guest Session Movies");
WrapperGenericList<MovieBasic> wrapper = processWrapper(getTypeReference(MovieBasic.class), url, "Guest Session Movies");
return wrapper.getTmdbResultsList();
}
}

@ -4,16 +4,16 @@
* 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
* it under the terms of the GNU General protected 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.
* GNU General protected License for more details.
*
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General protected License
* along with TheMovieDB API. If not, see <http://www.gnu.org/licenses/>.
*
*/
@ -60,7 +60,7 @@ public class AbstractTests {
*
* @throws MovieDbException
*/
public static final void doConfiguration() throws MovieDbException {
protected static final void doConfiguration() throws MovieDbException {
TestLogger.Configure();
httpClient = new SimpleHttpClientBuilder().build();
httpTools = new HttpTools(httpClient);
@ -149,7 +149,7 @@ public class AbstractTests {
* @return
* @throws MovieDbException
*/
public static final String getSessionId() throws MovieDbException {
protected static final String getSessionId() throws MovieDbException {
if (tokenSession == null) {
LOG.info("Create a session token for the rest of the tests");
String filename = TokenSession.class.getSimpleName();
@ -180,7 +180,7 @@ public class AbstractTests {
* @return
* @throws MovieDbException
*/
public static final int getAccountId() throws MovieDbException {
protected static final int getAccountId() throws MovieDbException {
if (account == null) {
LOG.info("Getting account information");
String filename = Account.class.getSimpleName();
@ -204,7 +204,7 @@ public class AbstractTests {
*
* @return
*/
public static HttpClient getHttpClient() {
protected static HttpClient getHttpClient() {
return httpClient;
}
@ -213,7 +213,7 @@ public class AbstractTests {
*
* @return
*/
public static HttpTools getHttpTools() {
protected static HttpTools getHttpTools() {
return httpTools;
}
@ -222,7 +222,7 @@ public class AbstractTests {
*
* @return
*/
public static String getApiKey() {
protected static String getApiKey() {
return props.getProperty("API_Key");
}
@ -231,7 +231,7 @@ public class AbstractTests {
*
* @return
*/
public static String getUsername() {
protected static String getUsername() {
return props.getProperty("Username");
}
@ -240,7 +240,7 @@ public class AbstractTests {
*
* @return
*/
public static String getPassword() {
protected static String getPassword() {
return props.getProperty("Password");
}
@ -249,7 +249,7 @@ public class AbstractTests {
*
* @return
*/
public static String getGuestSession() {
protected static String getGuestSession() {
return props.getProperty("GuestSession");
}
@ -259,7 +259,7 @@ public class AbstractTests {
* @param property
* @return
*/
public static String getProperty(String property) {
protected static String getProperty(String property) {
return props.getProperty(property);
}
}

@ -0,0 +1,59 @@
/*
* 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.model.list.UserList;
import com.omertron.themoviedbapi.model.movie.MovieBasic;
import com.omertron.themoviedbapi.model.tv.TVBasic;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import static org.junit.Assert.assertTrue;
public class TestSuite {
private TestSuite() {
throw new UnsupportedOperationException("Utility class");
}
public static void test(MovieBasic test) {
assertTrue("No title", isNotBlank(test.getTitle()));
assertTrue("No poster", isNotBlank(test.getPosterPath()));
assertTrue("No release date", isNotBlank(test.getReleaseDate()));
}
public static void test(UserList test) {
assertTrue("No ID", isNotBlank(test.getId()));
assertTrue("No Description", isNotBlank(test.getDescription()));
}
public static void test(TVBasic test) {
assertTrue("No name", isNotBlank(test.getName()));
assertTrue("No poster", isNotBlank(test.getPosterPath()));
assertTrue("No first air date", isNotBlank(test.getFirstAirDate()));
}
public static void test(int test) {
}
public static void test(float test) {
}
public static void test(boolean test) {
}
}

@ -21,6 +21,7 @@ package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestSuite;
import com.omertron.themoviedbapi.enumeration.MediaType;
import com.omertron.themoviedbapi.enumeration.SortBy;
import com.omertron.themoviedbapi.model.StatusCode;
@ -28,6 +29,7 @@ import com.omertron.themoviedbapi.model.account.Account;
import com.omertron.themoviedbapi.model.list.UserList;
import com.omertron.themoviedbapi.model.movie.MovieBasic;
import com.omertron.themoviedbapi.model.tv.TVBasic;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;
@ -98,8 +100,8 @@ public class TmdbAccountTest extends AbstractTests {
List<UserList> results = instance.getUserLists(getSessionId(), getAccountId());
assertNotNull("No list found", results);
assertFalse("No entries found", results.isEmpty());
for (UserList r : results) {
LOG.info(" {}", r.toString());
for (UserList result : results) {
TestSuite.test(result);
}
}
@ -111,11 +113,10 @@ public class TmdbAccountTest extends AbstractTests {
@Test
public void testGetFavoriteMovies() throws MovieDbException {
LOG.info("getFavoriteMovies");
List<MovieBasic> results = instance.getFavoriteMovies(getSessionId(), getAccountId());
assertNotNull("No list found", results);
TmdbResultsList<MovieBasic> results = instance.getFavoriteMovies(getSessionId(), getAccountId());
assertFalse("No entries found", results.isEmpty());
for (MovieBasic r : results) {
LOG.info(" {}", r.toString());
for (MovieBasic result : results.getResults()) {
TestSuite.test(result);
}
}
@ -127,11 +128,10 @@ public class TmdbAccountTest extends AbstractTests {
@Test
public void testGetFavoriteTv() throws MovieDbException {
LOG.info("getFavoriteTv");
List<TVBasic> results = instance.getFavoriteTv(getSessionId(), getAccountId());
assertNotNull("No list found", results);
TmdbResultsList<TVBasic> results = instance.getFavoriteTv(getSessionId(), getAccountId());
assertFalse("No entries found", results.isEmpty());
for (TVBasic r : results) {
LOG.info(" {}", r.toString());
for (TVBasic result : results.getResults()) {
TestSuite.test(result);
}
}
@ -173,8 +173,7 @@ public class TmdbAccountTest extends AbstractTests {
@Test
public void testGetRatedMovies() throws MovieDbException {
LOG.info("getRatedMovies");
List<MovieBasic> results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null);
assertNotNull("No rated list found", results);
TmdbResultsList<MovieBasic> results = instance.getRatedMovies(getSessionId(), getAccountId(), null, null, null);
assertFalse("No entries found", results.isEmpty());
}
@ -186,11 +185,10 @@ public class TmdbAccountTest extends AbstractTests {
@Test
public void testGetRatedTV() throws MovieDbException {
LOG.info("getRatedTV");
List<TVBasic> results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null);
assertNotNull("No rated list found", results);
TmdbResultsList<TVBasic> results = instance.getRatedTV(getSessionId(), getAccountId(), null, null, null);
assertFalse("No entries found", results.isEmpty());
for (TVBasic r : results) {
LOG.info(" {}", r.toString());
for (TVBasic result : results.getResults()) {
TestSuite.test(result);
}
}
@ -202,11 +200,11 @@ public class TmdbAccountTest extends AbstractTests {
@Test
public void testGetWatchListMovie() throws MovieDbException {
LOG.info("getWatchListMovie");
List<MovieBasic> results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null);
TmdbResultsList<MovieBasic> results = instance.getWatchListMovie(getSessionId(), getAccountId(), null, null, null);
assertNotNull("No rated list found", results);
assertFalse("No entries found", results.isEmpty());
for (MovieBasic r : results) {
LOG.info(" {}", r.toString());
for (MovieBasic result : results.getResults()) {
TestSuite.test(result);
}
}
@ -218,11 +216,11 @@ public class TmdbAccountTest extends AbstractTests {
@Test
public void testGetWatchListTV() throws MovieDbException {
LOG.info("getWatchListTV");
List<TVBasic> results = instance.getWatchListTV(getSessionId(), getAccountId(), null, null, null);
TmdbResultsList<TVBasic> results = instance.getWatchListTV(getSessionId(), getAccountId(), null, null, null);
assertNotNull("No rated list found", results);
assertFalse("No entries found", results.isEmpty());
for (TVBasic r : results) {
LOG.info(" {}", r.toString());
for (TVBasic result : results.getResults()) {
TestSuite.test(result);
}
}
@ -271,7 +269,7 @@ public class TmdbAccountTest extends AbstractTests {
String language = LANGUAGE_DEFAULT;
Integer page = null;
SortBy sortBy = SortBy.CREATED_AT_ASC;
List<MovieBasic> result = instance.getGuestRatedMovies(guestSession, language, page, sortBy);
TmdbResultsList<MovieBasic> result = instance.getGuestRatedMovies(guestSession, language, page, sortBy);
// Check and post some ratings if required
if (result.isEmpty()) {
@ -289,10 +287,6 @@ public class TmdbAccountTest extends AbstractTests {
result = instance.getGuestRatedMovies(guestSession, language, page, sortBy);
}
for (MovieBasic mb : result) {
LOG.info("{}", mb);
}
assertFalse("No movies found!", result.isEmpty());
}

@ -20,7 +20,6 @@
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import static com.omertron.themoviedbapi.AbstractTests.doConfiguration;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.model.Certification;
import com.omertron.themoviedbapi.results.TmdbResultsMap;

@ -20,8 +20,6 @@
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
import com.omertron.themoviedbapi.ArtworkResults;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestID;

@ -20,8 +20,6 @@
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
import com.omertron.themoviedbapi.ArtworkResults;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestID;

@ -20,9 +20,6 @@
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import static com.omertron.themoviedbapi.AbstractTests.doConfiguration;
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
import com.omertron.themoviedbapi.ArtworkResults;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestID;

@ -20,8 +20,6 @@
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import static com.omertron.themoviedbapi.AbstractTests.getApiKey;
import static com.omertron.themoviedbapi.AbstractTests.getHttpTools;
import com.omertron.themoviedbapi.ArtworkResults;
import com.omertron.themoviedbapi.MovieDbException;
import com.omertron.themoviedbapi.TestID;

Loading…
Cancel
Save