diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/SearchType.java b/src/main/java/com/omertron/themoviedbapi/enumeration/SearchType.java
new file mode 100644
index 000000000..c367bed08
--- /dev/null
+++ b/src/main/java/com/omertron/themoviedbapi/enumeration/SearchType.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2004-2015 Stuart Boston
+ *
+ * This file is part of TheMovieDB API.
+ *
+ * TheMovieDB API is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * TheMovieDB API is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with TheMovieDB API. If not, see .
+ *
+ */
+package com.omertron.themoviedbapi.enumeration;
+
+/**
+ *
+ * @author Stuart
+ */
+public enum SearchType {
+
+ PHRASE,
+ NGRAM;
+
+ public String getPropertyString() {
+ return this.name().toLowerCase();
+ }
+
+}
diff --git a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java
index 78e62a63d..b80de72d9 100644
--- a/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java
+++ b/src/main/java/com/omertron/themoviedbapi/enumeration/SortBy.java
@@ -1,3 +1,22 @@
+/*
+ * Copyright (c) 2004-2015 Stuart Boston
+ *
+ * This file is part of TheMovieDB API.
+ *
+ * TheMovieDB API is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * any later version.
+ *
+ * TheMovieDB API is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with TheMovieDB API. If not, see .
+ *
+ */
package com.omertron.themoviedbapi.enumeration;
public enum SortBy {
diff --git a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java
index 11dc8fd5d..f94fe5c83 100644
--- a/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java
+++ b/src/main/java/com/omertron/themoviedbapi/methods/AbstractMethod.java
@@ -49,12 +49,14 @@ public class AbstractMethod {
protected static final ObjectMapper MAPPER = new ObjectMapper();
// Logger
protected static final Logger LOG = LoggerFactory.getLogger(TmdbAccount.class);
- protected static final TypeReference> TR_MOVIE_BASIC = new TypeReference>() {
- };
- protected static final TypeReference> TR_TV_BASIC = new TypeReference>() {
- };
- protected static final TypeReference> TR_USER_LIST = new TypeReference>() {
- };
+ protected static final TypeReference> TR_MOVIE_BASIC = getTypeReference(MovieBasic.class);
+ protected static final TypeReference> TR_TV_BASIC = getTypeReference(TVBasic.class);
+ protected static final TypeReference> TR_USER_LIST = getTypeReference(UserList.class);
+
+ protected static TypeReference getTypeReference(T Class) {
+ return new TypeReference>() {
+ };
+ }
/**
* Default constructor for the methods
@@ -78,16 +80,28 @@ public class AbstractMethod {
* @throws MovieDbException
*/
public List processWrapperList(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException {
+ WrapperGenericList val = processWrapper(typeRef, url, errorMessageSuffix);
+ return val.getResults();
+ }
+
+ /**
+ * Process the wrapper list and return the whole wrapper
+ *
+ * @param Type of list to process
+ * @param typeRef
+ * @param url URL of the page (Error output only)
+ * @param errorMessageSuffix Error message to output (Error output only)
+ * @return
+ * @throws MovieDbException
+ */
+ public WrapperGenericList processWrapper(TypeReference typeRef, URL url, String errorMessageSuffix) throws MovieDbException {
String webpage = httpTools.getRequest(url);
try {
// Due to type erasure, this doesn't work
// TypeReference> typeRef = new TypeReference>() {};
- WrapperGenericList results = MAPPER.readValue(webpage, typeRef);
- return results.getResults();
+ return MAPPER.readValue(webpage, typeRef);
} catch (IOException ex) {
throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get " + errorMessageSuffix, url, ex);
}
-
}
-
}
diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java
index 7d68eef35..169744e80 100644
--- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java
+++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java
@@ -20,12 +20,14 @@
package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.MovieDbException;
+import com.omertron.themoviedbapi.enumeration.SearchType;
import com.omertron.themoviedbapi.model2.collection.Collection;
import com.omertron.themoviedbapi.model2.company.Company;
import com.omertron.themoviedbapi.model.keyword.Keyword;
import com.omertron.themoviedbapi.model.MovieDb;
-import com.omertron.themoviedbapi.model.MovieList;
import com.omertron.themoviedbapi.model.person.Person;
+import com.omertron.themoviedbapi.model2.list.UserList;
+import com.omertron.themoviedbapi.model2.tv.TVBasic;
import com.omertron.themoviedbapi.results.TmdbResultsList;
import com.omertron.themoviedbapi.tools.ApiUrl;
import com.omertron.themoviedbapi.tools.HttpTools;
@@ -33,13 +35,7 @@ import com.omertron.themoviedbapi.tools.MethodBase;
import com.omertron.themoviedbapi.tools.MethodSub;
import com.omertron.themoviedbapi.tools.Param;
import com.omertron.themoviedbapi.tools.TmdbParameters;
-import com.omertron.themoviedbapi.wrapper.WrapperCollection;
-import com.omertron.themoviedbapi.wrapper.WrapperCompany;
-import com.omertron.themoviedbapi.wrapper.WrapperKeywords;
-import com.omertron.themoviedbapi.wrapper.WrapperMovie;
-import com.omertron.themoviedbapi.wrapper.WrapperMovieList;
-import com.omertron.themoviedbapi.wrapper.WrapperPerson;
-import java.io.IOException;
+import com.omertron.themoviedbapi.wrapper.WrapperGenericList;
import java.net.URL;
import org.yamj.api.common.exception.ApiExceptionType;
@@ -61,36 +57,28 @@ public class TmdbSearch extends AbstractMethod {
}
/**
- * Search Movies This is a good starting point to start finding movies on TMDb.
+ * Search Companies.
*
- * @param movieName
- * @param searchYear Limit the search to the provided year. Zero (0) will get all years
- * @param language The language to include. Can be blank/null.
- * @param includeAdult true or false to include adult titles in the search
- * @param page The page of results to return. 0 to get the default (first page)
+ * You can use this method to search for production companies that are part of TMDb. The company IDs will map to those returned
+ * on movie calls.
+ *
+ * http://help.themoviedb.org/kb/api/search-companies
+ *
+ * @param query
+ * @param page
* @return
* @throws MovieDbException
*/
- public TmdbResultsList searchMovie(String movieName, int searchYear, String language, boolean includeAdult, int page) throws MovieDbException {
+ public TmdbResultsList searchCompanies(String query, Integer page) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
- parameters.add(Param.QUERY, movieName);
- parameters.add(Param.YEAR, searchYear);
- parameters.add(Param.LANGUAGE, language);
- parameters.add(Param.ADULT, includeAdult);
+ parameters.add(Param.QUERY, query);
parameters.add(Param.PAGE, page);
- URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters);
- String webpage = httpTools.getRequest(url);
-
- try {
- WrapperMovie wrapper = MAPPER.readValue(webpage, WrapperMovie.class);
- TmdbResultsList results = new TmdbResultsList(wrapper.getMovies());
- results.copyWrapper(wrapper);
- return results;
- } catch (IOException ex) {
- throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find movie", url, ex);
- }
-
+ URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters);
+ WrapperGenericList wrapper = processWrapper(getTypeReference(Company.class), url, "company");
+ TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
+ results.copyWrapper(wrapper);
+ return results;
}
/**
@@ -102,112 +90,17 @@ public class TmdbSearch extends AbstractMethod {
* @return
* @throws MovieDbException
*/
- public TmdbResultsList searchCollection(String query, String language, int page) throws MovieDbException {
+ public TmdbResultsList searchCollection(String query, Integer page, String language) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.QUERY, query);
- parameters.add(Param.LANGUAGE, language);
parameters.add(Param.PAGE, page);
+ parameters.add(Param.LANGUAGE, language);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COLLECTION).buildUrl(parameters);
- String webpage = httpTools.getRequest(url);
-
- try {
- WrapperCollection wrapper = MAPPER.readValue(webpage, WrapperCollection.class);
- TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
- results.copyWrapper(wrapper);
- return results;
- } catch (IOException ex) {
- throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find collection", url, ex);
- }
- }
-
- /**
- * This is a good starting point to start finding people on TMDb.
- *
- * The idea is to be a quick and light method so you can iterate through people quickly.
- *
- * @param personName
- * @param includeAdult
- * @param page
- * @return
- * @throws MovieDbException
- */
- public TmdbResultsList searchPeople(String personName, boolean includeAdult, int page) throws MovieDbException {
- TmdbParameters parameters = new TmdbParameters();
- parameters.add(Param.QUERY, personName);
- parameters.add(Param.ADULT, includeAdult);
- parameters.add(Param.PAGE, page);
-
- URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters);
- String webpage = httpTools.getRequest(url);
-
- try {
- WrapperPerson wrapper = MAPPER.readValue(webpage, WrapperPerson.class);
- TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
- results.copyWrapper(wrapper);
- return results;
- } catch (IOException ex) {
- throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find person", url, ex);
- }
- }
-
- /**
- * Search for lists by name and description.
- *
- * @param query
- * @param language
- * @param page
- * @return
- * @throws MovieDbException
- */
- public TmdbResultsList searchList(String query, String language, int page) throws MovieDbException {
- TmdbParameters parameters = new TmdbParameters();
- parameters.add(Param.QUERY, query);
- parameters.add(Param.LANGUAGE, language);
- parameters.add(Param.PAGE, page);
-
- URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters);
- String webpage = httpTools.getRequest(url);
-
- try {
- WrapperMovieList wrapper = MAPPER.readValue(webpage, WrapperMovieList.class);
- TmdbResultsList results = new TmdbResultsList(wrapper.getMovieList());
- results.copyWrapper(wrapper);
- return results;
- } catch (IOException ex) {
- throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find list", url, ex);
- }
- }
-
- /**
- * Search Companies.
- *
- * You can use this method to search for production companies that are part of TMDb. The company IDs will map to those returned
- * on movie calls.
- *
- * http://help.themoviedb.org/kb/api/search-companies
- *
- * @param companyName
- * @param page
- * @return
- * @throws MovieDbException
- */
- public TmdbResultsList searchCompanies(String companyName, int page) throws MovieDbException {
- TmdbParameters parameters = new TmdbParameters();
- parameters.add(Param.QUERY, companyName);
- parameters.add(Param.PAGE, page);
-
- URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.COMPANY).buildUrl(parameters);
- String webpage = httpTools.getRequest(url);
-
- try {
- WrapperCompany wrapper = MAPPER.readValue(webpage, WrapperCompany.class);
- TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
- results.copyWrapper(wrapper);
- return results;
- } catch (IOException ex) {
- throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find company", url, ex);
- }
+ WrapperGenericList wrapper = processWrapper(getTypeReference(Collection.class), url, "collection");
+ TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
+ results.copyWrapper(wrapper);
+ return results;
}
/**
@@ -218,22 +111,158 @@ public class TmdbSearch extends AbstractMethod {
* @return
* @throws MovieDbException
*/
- public TmdbResultsList searchKeyword(String query, int page) throws MovieDbException {
+ public TmdbResultsList searchKeyword(String query, Integer page) throws MovieDbException {
TmdbParameters parameters = new TmdbParameters();
parameters.add(Param.QUERY, query);
parameters.add(Param.PAGE, page);
URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.KEYWORD).buildUrl(parameters);
- String webpage = httpTools.getRequest(url);
+ WrapperGenericList wrapper = processWrapper(getTypeReference(Keyword.class), url, "keyword");
+ TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
+ results.copyWrapper(wrapper);
+ return results;
+ }
- try {
- WrapperKeywords wrapper = MAPPER.readValue(webpage, WrapperKeywords.class);
- TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
- results.copyWrapper(wrapper);
- return results;
- } catch (IOException ex) {
- throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to find keyword", url, ex);
+ /**
+ * Search for lists by name and description.
+ *
+ * @param query
+ * @param language
+ * @param includeAdult
+ * @param page
+ * @return
+ * @throws MovieDbException
+ */
+ public TmdbResultsList searchList(String query, Integer page, Boolean includeAdult) throws MovieDbException {
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.QUERY, query);
+ parameters.add(Param.PAGE, page);
+ parameters.add(Param.INCLUDE_ADULT, includeAdult);
+
+ URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.LIST).buildUrl(parameters);
+ WrapperGenericList wrapper = processWrapper(getTypeReference(UserList.class), url, "list");
+ TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
+ results.copyWrapper(wrapper);
+ return results;
+ }
+
+ /**
+ * Search Movies This is a good starting point to start finding movies on TMDb.
+ *
+ * @param query
+ * @param searchYear Limit the search to the provided year. Zero (0) will get all years
+ * @param language The language to include. Can be blank/null.
+ * @param includeAdult true or false to include adult titles in the search
+ * @param page The page of results to return. 0 to get the default (first page)
+ * @param primaryReleaseYear
+ * @param searchType
+ * @return
+ * @throws MovieDbException
+ */
+ public TmdbResultsList searchMovie(String query,
+ Integer page,
+ String language,
+ Boolean includeAdult,
+ Integer searchYear,
+ Integer primaryReleaseYear,
+ SearchType searchType) throws MovieDbException {
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.QUERY, query);
+ parameters.add(Param.PAGE, page);
+ parameters.add(Param.LANGUAGE, language);
+ parameters.add(Param.ADULT, includeAdult);
+ parameters.add(Param.YEAR, searchYear);
+ parameters.add(Param.PRIMARY_RELEASE_YEAR, primaryReleaseYear);
+ if (searchType != null) {
+ parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
}
+ URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters);
+
+ WrapperGenericList wrapper = processWrapper(getTypeReference(MovieDb.class), url, "movie");
+ TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
+ results.copyWrapper(wrapper);
+ return results;
+ }
+
+ /**
+ * Search the movie, tv show and person collections with a single query.
+ *
+ * Each item returned in the result array has a media_type field that maps to either movie, tv or person.
+ *
+ * Each mapped result is the same response you would get from each independent search
+ *
+ * @param query
+ * @param page
+ * @param language
+ * @param includeAdult
+ * @return
+ * @throws MovieDbException
+ */
+ public String searchMulti(String query, Integer page, String language, Boolean includeAdult) throws MovieDbException {
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.QUERY, query);
+ parameters.add(Param.PAGE, page);
+ parameters.add(Param.LANGUAGE, language);
+ parameters.add(Param.ADULT, includeAdult);
+
+ URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MULTI).buildUrl(parameters);
+ throw new MovieDbException(ApiExceptionType.UNKNOWN_CAUSE, "Not implemented yet");
+ }
+
+ /**
+ * This is a good starting point to start finding people on TMDb.
+ *
+ * The idea is to be a quick and light method so you can iterate through people quickly.
+ *
+ * @param query
+ * @param includeAdult
+ * @param page
+ * @param searchType
+ * @return
+ * @throws MovieDbException
+ */
+ public TmdbResultsList searchPeople(String query, Integer page, Boolean includeAdult, SearchType searchType) throws MovieDbException {
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.QUERY, query);
+ parameters.add(Param.ADULT, includeAdult);
+ parameters.add(Param.PAGE, page);
+ if (searchType != null) {
+ parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
+ }
+ URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.PERSON).buildUrl(parameters);
+
+ WrapperGenericList wrapper = processWrapper(getTypeReference(Person.class), url, "person");
+ TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
+ results.copyWrapper(wrapper);
+ return results;
+ }
+
+ /**
+ * Search for TV shows by title.
+ *
+ * @param query
+ * @param page
+ * @param language
+ * @param firstAirDateYear
+ * @param searchType
+ * @return
+ * @throws com.omertron.themoviedbapi.MovieDbException
+ */
+ public TmdbResultsList searchTV(String query, Integer page, String language, Integer firstAirDateYear, SearchType searchType) throws MovieDbException {
+ TmdbParameters parameters = new TmdbParameters();
+ parameters.add(Param.QUERY, query);
+ parameters.add(Param.PAGE, page);
+ parameters.add(Param.LANGUAGE, language);
+ parameters.add(Param.FIRST_AIR_DATE_YEAR, firstAirDateYear);
+ if (searchType != null) {
+ parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString());
+ }
+ URL url = new ApiUrl(apiKey, MethodBase.SEARCH).setSubMethod(MethodSub.MOVIE).buildUrl(parameters);
+
+ WrapperGenericList wrapper = processWrapper(getTypeReference(TVBasic.class), url, "TV Show");
+ TmdbResultsList results = new TmdbResultsList(wrapper.getResults());
+ results.copyWrapper(wrapper);
+ return results;
}
}
diff --git a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt
index 35502c4e1..0e2023986 100644
--- a/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt
+++ b/src/main/java/com/omertron/themoviedbapi/methods/_Method_List.txt
@@ -105,13 +105,13 @@ People
Reviews (Done)
/review/{id} Get the full details of a review by ID.
-Search
+Search (Partial - multi search to do)
/search/company Search for companies by name.
/search/collection Search for collections by name.
/search/keyword Search for keywords by name.
/search/list Search for lists by name and description.
/search/movie Search for movies by title.
-/search/multi Search the movie, tv show and person collections with a single query.
+*** /search/multi Search the movie, tv show and person collections with a single query.
/search/person Search for people by name.
/search/tv Search for TV shows by title.
diff --git a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java
index b911025e9..d8b73dfda 100644
--- a/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java
+++ b/src/main/java/com/omertron/themoviedbapi/tools/MethodSub.java
@@ -46,6 +46,7 @@ public enum MethodSub {
MOVIE("movie"),
MOVIES("movies"),
MOVIE_LIST("movie/list"),
+ MULTI("multi"),
NOW_PLAYING("now-playing"),
PERSON("person"),
POPULAR("popular"),
diff --git a/src/main/java/com/omertron/themoviedbapi/tools/Param.java b/src/main/java/com/omertron/themoviedbapi/tools/Param.java
index a1b1e08be..b52efc98c 100644
--- a/src/main/java/com/omertron/themoviedbapi/tools/Param.java
+++ b/src/main/java/com/omertron/themoviedbapi/tools/Param.java
@@ -46,6 +46,7 @@ public enum Param {
PAGE("page="),
PASSWORD("password="),
QUERY("query="),
+ SEARCH_TYPE("search_type="),
SESSION("session_id="),
START_DATE("start_date="),
TOKEN("request_token="),
diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java
index 30a46b995..193513409 100644
--- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java
+++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java
@@ -21,16 +21,23 @@ package com.omertron.themoviedbapi.methods;
import com.omertron.themoviedbapi.AbstractTests;
import com.omertron.themoviedbapi.MovieDbException;
+import com.omertron.themoviedbapi.enumeration.SearchType;
import com.omertron.themoviedbapi.model2.collection.Collection;
import com.omertron.themoviedbapi.model2.company.Company;
import com.omertron.themoviedbapi.model.keyword.Keyword;
import com.omertron.themoviedbapi.model.MovieDb;
-import com.omertron.themoviedbapi.model.MovieList;
import com.omertron.themoviedbapi.model.person.Person;
+import com.omertron.themoviedbapi.model2.list.UserList;
+import com.omertron.themoviedbapi.model2.tv.TVBasic;
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 static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
@@ -57,27 +64,26 @@ public class TmdbSearchTest extends AbstractTests {
public static void tearDownClass() {
}
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
/**
- * Test of searchMovie method, of class TheMovieDbApi.
+ * Test of searchCompanies method, of class TheMovieDbApi.
*
* @throws MovieDbException
*/
@Test
- public void testSearchMovie() throws MovieDbException {
- LOG.info("searchMovie");
-
- // Try a movie with less than 1 page of results
- TmdbResultsList movieList = instance.searchMovie("Blade Runner", 0, "", true, 0);
-// List movieList = tmdb.searchMovie("Blade Runner", "", true);
- assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0);
-
- // Try a russian langugage movie
- movieList = 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);
+ public void testSearchCompanies() throws MovieDbException {
+ LOG.info("searchCompanies");
+ TmdbResultsList result = instance.searchCompanies(COMPANY_NAME, 0);
+ assertNotNull("Null results", result);
+ assertNotNull("Null company", result.getResults());
+ assertFalse("Empty company", result.isEmpty());
}
/**
@@ -90,50 +96,10 @@ public class TmdbSearchTest extends AbstractTests {
LOG.info("searchCollection");
String query = "batman";
int page = 0;
- TmdbResultsList 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 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 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 result = instance.searchCompanies(COMPANY_NAME, 0);
- assertTrue("No company information found", !result.getResults().isEmpty());
+ TmdbResultsList result = instance.searchCollection(query, page, LANGUAGE_DEFAULT);
+ assertNotNull("Null results", result);
+ assertNotNull("Null collection", result.getResults());
+ assertFalse("Empty collection", result.isEmpty());
}
/**
@@ -147,8 +113,100 @@ public class TmdbSearchTest extends AbstractTests {
String query = "action";
int page = 0;
TmdbResultsList result = instance.searchKeyword(query, page);
- assertFalse("No keywords found", result.getResults() == null);
- assertTrue("No keywords found", result.getResults().size() > 0);
+ assertNotNull("Null results", result);
+ assertNotNull("Null keyword", result.getResults());
+ assertFalse("Empty keyword", result.isEmpty());
+ }
+
+ /**
+ * 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 result = instance.searchList(query, page, null);
+ assertNotNull("Null results", result);
+ assertNotNull("Null list", result.getResults());
+ assertFalse("Empty list", result.isEmpty());
+ }
+
+ /**
+ * Test of searchMovie method, of class TheMovieDbApi.
+ *
+ * @throws MovieDbException
+ */
+ @Test
+ public void testSearchMovie() throws MovieDbException {
+ LOG.info("searchMovie");
+
+ // Try a movie with less than 1 page of results
+ TmdbResultsList movieList = instance.searchMovie("Blade Runner", 0, "", null, 0, 0, SearchType.PHRASE);
+ assertTrue("No movies found, should be at least 1", movieList.getResults().size() > 0);
+
+ // Try a russian langugage movie
+ movieList = instance.searchMovie("О чём говорят мужчины", 0, LANGUAGE_RUSSIAN, null, 0, 0, SearchType.PHRASE);
+ 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, null, 0, 0, SearchType.PHRASE);
+ assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15);
+ }
+
+ /**
+ * Test of searchMulti method, of class TmdbSearch.
+ *
+ * @throws com.omertron.themoviedbapi.MovieDbException
+ */
+ @Test
+ public void testSearchMulti() throws MovieDbException {
+ System.out.println("searchMulti");
+ String query = "j";
+ Integer page = null;
+ String language = "";
+ Boolean includeAdult = null;
+ String expResult = "";
+ String result = instance.searchMulti(query, page, language, includeAdult);
+ 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 searchPeople method, of class TheMovieDbApi.
+ *
+ * @throws MovieDbException
+ */
+ @Test
+ public void testSearchPeople() throws MovieDbException {
+ LOG.info("searchPeople");
+ String personName = "Bruce Willis";
+ TmdbResultsList result = instance.searchPeople(personName, null, null, SearchType.PHRASE);
+ assertNotNull("Null results", result);
+ assertNotNull("Null people", result.getResults());
+ assertFalse("Empty people", result.isEmpty());
+ }
+
+ /**
+ * Test of searchTV method, of class TmdbSearch.
+ *
+ * @throws com.omertron.themoviedbapi.MovieDbException
+ */
+ @Test
+ public void testSearchTV() throws MovieDbException {
+ System.out.println("searchTV");
+ String query = "The Walking Dead";
+ Integer page = null;
+ String language = LANGUAGE_ENGLISH;
+ Integer firstAirDateYear = null;
+ SearchType searchType = SearchType.PHRASE;
+ TmdbResultsList result = instance.searchTV(query, page, language, firstAirDateYear, searchType);
+ assertNotNull("Null results", result);
+ assertNotNull("Null TV", result.getResults());
+ assertFalse("Empty TV", result.isEmpty());
}
}