From 90e6891088db5e92107acaa13a095723c359d3f6 Mon Sep 17 00:00:00 2001 From: Stuart Boston Date: Fri, 6 Mar 2015 17:53:28 +0000 Subject: [PATCH] Updated Models & Test cases --- .../themoviedbapi/methods/TmdbSearch.java | 2 +- .../themoviedbapi/model/AbstractIdName.java | 4 +- .../themoviedbapi/model/company/Company.java | 15 ++-- .../themoviedbapi/model/media/MediaBasic.java | 15 +++- .../themoviedbapi/model/movie/MovieBasic.java | 5 ++ .../model/person/PersonFind.java | 7 +- .../themoviedbapi/model/tv/TVBasic.java | 5 ++ .../model/tv/TVEpisodeBasic.java | 5 ++ .../results/AbstractResults.java | 4 +- .../wrapper/WrapperMultiSearch.java | 4 +- .../com/omertron/themoviedbapi/TestSuite.java | 27 ++++-- .../methods/TmdbCompaniesTest.java | 2 +- .../themoviedbapi/methods/TmdbSearchTest.java | 87 ++++++++++--------- 13 files changed, 115 insertions(+), 67 deletions(-) diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java index 570de8be6..718bdcdc2 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbSearch.java @@ -256,7 +256,7 @@ public class TmdbSearch extends AbstractMethod { if (searchType != null) { parameters.add(Param.SEARCH_TYPE, searchType.getPropertyString()); } - URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.MOVIE).buildUrl(parameters); + URL url = new ApiUrl(apiKey, MethodBase.SEARCH).subMethod(MethodSub.TV).buildUrl(parameters); WrapperGenericList wrapper = processWrapper(getTypeReference(TVBasic.class), url, "TV Show"); return wrapper.getResultsList(); } diff --git a/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java b/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java index 72225b971..ba138b6d1 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java +++ b/src/main/java/com/omertron/themoviedbapi/model/AbstractIdName.java @@ -19,8 +19,8 @@ */ package com.omertron.themoviedbapi.model; -import com.omertron.themoviedbapi.model.AbstractJsonMapping; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.wrapper.IWrapperId; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @@ -28,7 +28,7 @@ import org.apache.commons.lang3.builder.HashCodeBuilder; * * @author Stuart.Boston */ -public class AbstractIdName extends AbstractJsonMapping { +public class AbstractIdName extends AbstractJsonMapping implements IWrapperId { private static final long serialVersionUID = 2L; diff --git a/src/main/java/com/omertron/themoviedbapi/model/company/Company.java b/src/main/java/com/omertron/themoviedbapi/model/company/Company.java index f091fae9f..92c1c1869 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/company/Company.java +++ b/src/main/java/com/omertron/themoviedbapi/model/company/Company.java @@ -21,19 +21,20 @@ package com.omertron.themoviedbapi.model.company; import com.fasterxml.jackson.annotation.JsonProperty; import com.omertron.themoviedbapi.model.AbstractJsonMapping; +import com.omertron.themoviedbapi.wrapper.IWrapperId; /** * Company information * * @author Stuart */ -public class Company extends AbstractJsonMapping { +public class Company extends AbstractJsonMapping implements IWrapperId { private static final long serialVersionUID = 1L; private static final String DEFAULT_STRING = ""; // Properties @JsonProperty("id") - private int companyId = 0; + private int id = 0; @JsonProperty("name") private String name = DEFAULT_STRING; @JsonProperty("description") @@ -47,8 +48,8 @@ public class Company extends AbstractJsonMapping { @JsonProperty("parent_company") private Company parentCompany = null; - public int getCompanyId() { - return companyId; + public int getId() { + return id; } public String getDescription() { @@ -75,8 +76,8 @@ public class Company extends AbstractJsonMapping { return parentCompany; } - public void setCompanyId(int companyId) { - this.companyId = companyId; + public void setId(int id) { + this.id = id; } public void setDescription(String description) { @@ -105,7 +106,7 @@ public class Company extends AbstractJsonMapping { public void setParentCompany(int id, String name, String logoPath) { Company parent = new Company(); - parent.setCompanyId(id); + parent.setId(id); parent.setName(name); parent.setLogoPath(logoPath); this.parentCompany = parent; diff --git a/src/main/java/com/omertron/themoviedbapi/model/media/MediaBasic.java b/src/main/java/com/omertron/themoviedbapi/model/media/MediaBasic.java index 00d93d749..971af358f 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/media/MediaBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model/media/MediaBasic.java @@ -20,19 +20,21 @@ package com.omertron.themoviedbapi.model.media; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model.AbstractJsonMapping; +import com.omertron.themoviedbapi.wrapper.IWrapperId; /** * Basic media information * * @author stuart.boston */ -public class MediaBasic extends AbstractJsonMapping { +public class MediaBasic extends AbstractJsonMapping implements IWrapperId { @JsonProperty("id") private int id; - @JsonProperty("media_type") - private String mediaType; + private MediaType mediaType; @JsonProperty("backdrop_path") private String backdropPath; @JsonProperty("poster_path") @@ -52,11 +54,16 @@ public class MediaBasic extends AbstractJsonMapping { this.id = id; } - public String getMediaType() { + public MediaType getMediaType() { return mediaType; } + @JsonSetter("media_type") public void setMediaType(String mediaType) { + this.mediaType = MediaType.fromString(mediaType); + } + + public void setMediaType(MediaType mediaType) { this.mediaType = mediaType; } diff --git a/src/main/java/com/omertron/themoviedbapi/model/movie/MovieBasic.java b/src/main/java/com/omertron/themoviedbapi/model/movie/MovieBasic.java index 90f927047..94bbf84f3 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/movie/MovieBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model/movie/MovieBasic.java @@ -20,6 +20,7 @@ package com.omertron.themoviedbapi.model.movie; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model.media.MediaBasic; /** @@ -42,6 +43,10 @@ public class MovieBasic extends MediaBasic { @JsonProperty("rating") private float rating = -1f; + public MovieBasic() { + super.setMediaType(MediaType.MOVIE); + } + public boolean isAdult() { return adult; } diff --git a/src/main/java/com/omertron/themoviedbapi/model/person/PersonFind.java b/src/main/java/com/omertron/themoviedbapi/model/person/PersonFind.java index b5d04e7e0..fbf0bdd76 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/person/PersonFind.java +++ b/src/main/java/com/omertron/themoviedbapi/model/person/PersonFind.java @@ -27,12 +27,13 @@ import com.omertron.themoviedbapi.model.media.MediaBasic; import com.omertron.themoviedbapi.model.movie.MovieBasic; import com.omertron.themoviedbapi.model.tv.TVBasic; import com.omertron.themoviedbapi.model.tv.TVEpisodeBasic; +import com.omertron.themoviedbapi.wrapper.IWrapperId; import java.util.List; /** * @author stuart.boston */ -public class PersonFind extends PersonBasic { +public class PersonFind extends PersonBasic implements IWrapperId { private static final long serialVersionUID = 1L; @JsonProperty("adult") @@ -57,8 +58,8 @@ public class PersonFind extends PersonBasic { this.popularity = popularity; } - public List getKnownFor() { - return knownFor; + public List getKnownFor() { + return (List) knownFor; } @JsonTypeInfo( diff --git a/src/main/java/com/omertron/themoviedbapi/model/tv/TVBasic.java b/src/main/java/com/omertron/themoviedbapi/model/tv/TVBasic.java index 9e91d31cb..082c86916 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/tv/TVBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model/tv/TVBasic.java @@ -20,6 +20,7 @@ package com.omertron.themoviedbapi.model.tv; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model.media.MediaBasic; import java.util.List; @@ -41,6 +42,10 @@ public class TVBasic extends MediaBasic { @JsonProperty("rating") private float rating = -1f; + public TVBasic() { + super.setMediaType(MediaType.TV); + } + public String getName() { return name; } diff --git a/src/main/java/com/omertron/themoviedbapi/model/tv/TVEpisodeBasic.java b/src/main/java/com/omertron/themoviedbapi/model/tv/TVEpisodeBasic.java index ebcd70c5d..bcdd337d8 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/tv/TVEpisodeBasic.java +++ b/src/main/java/com/omertron/themoviedbapi/model/tv/TVEpisodeBasic.java @@ -20,6 +20,7 @@ package com.omertron.themoviedbapi.model.tv; import com.fasterxml.jackson.annotation.JsonProperty; +import com.omertron.themoviedbapi.enumeration.MediaType; import com.omertron.themoviedbapi.model.media.MediaBasic; /** @@ -44,6 +45,10 @@ public class TVEpisodeBasic extends MediaBasic { @JsonProperty("show_id") private String showId; + public TVEpisodeBasic() { + super.setMediaType(MediaType.EPISODE); + } + public String getAirDate() { return airDate; } diff --git a/src/main/java/com/omertron/themoviedbapi/results/AbstractResults.java b/src/main/java/com/omertron/themoviedbapi/results/AbstractResults.java index 9fb00b7ef..64b697334 100644 --- a/src/main/java/com/omertron/themoviedbapi/results/AbstractResults.java +++ b/src/main/java/com/omertron/themoviedbapi/results/AbstractResults.java @@ -19,6 +19,8 @@ */ package com.omertron.themoviedbapi.results; +import com.omertron.themoviedbapi.wrapper.IWrapperId; +import com.omertron.themoviedbapi.wrapper.IWrapperPages; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; @@ -27,7 +29,7 @@ import org.apache.commons.lang3.builder.ToStringStyle; * * @author Stuart */ -public abstract class AbstractResults { +public abstract class AbstractResults implements IWrapperId, IWrapperPages { private int id = 0; private int page = 0; diff --git a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMultiSearch.java b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMultiSearch.java index 7d92523fd..e08d79dc7 100644 --- a/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMultiSearch.java +++ b/src/main/java/com/omertron/themoviedbapi/wrapper/WrapperMultiSearch.java @@ -36,8 +36,8 @@ public class WrapperMultiSearch extends AbstractWrapperAll { private List results; - public List getResults() { - return results; + public List getResults() { + return (List) results; } @JsonTypeInfo( diff --git a/src/test/java/com/omertron/themoviedbapi/TestSuite.java b/src/test/java/com/omertron/themoviedbapi/TestSuite.java index 71a675bfd..bafa10d52 100644 --- a/src/test/java/com/omertron/themoviedbapi/TestSuite.java +++ b/src/test/java/com/omertron/themoviedbapi/TestSuite.java @@ -22,7 +22,12 @@ 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 com.omertron.themoviedbapi.results.ResultList; +import com.omertron.themoviedbapi.wrapper.IWrapperId; +import java.util.List; import static org.apache.commons.lang3.StringUtils.isNotBlank; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; public class TestSuite { @@ -31,6 +36,12 @@ public class TestSuite { throw new UnsupportedOperationException("Utility class"); } + public static void test(ResultList result) { + assertNotNull("Null results", result); + assertNotNull("Null collection", result.getResults()); + assertFalse("Empty results", result.isEmpty()); + } + public static void test(MovieBasic test) { assertTrue("No title", isNotBlank(test.getTitle())); assertTrue("No poster", isNotBlank(test.getPosterPath())); @@ -48,12 +59,18 @@ public class TestSuite { assertTrue("No first air date", isNotBlank(test.getFirstAirDate())); } - public static void test(int test) { + public static void testId(ResultList result, int id, String message) { + testId(result.getResults(), id, message); } - public static void test(float test) { - } - - public static void test(boolean test) { + public static void testId(List result, int id, String message) { + boolean found = false; + for (IWrapperId item : result) { + if (item.getId() == id) { + found = true; + break; + } + } + assertTrue(message + " ID " + id + " not found in list", found); } } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java index 9673d694c..aca000c3a 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbCompaniesTest.java @@ -72,7 +72,7 @@ public class TmdbCompaniesTest extends AbstractTests { public void testGetCompanyInfo() throws MovieDbException { LOG.info("getCompanyInfo"); Company company = instance.getCompanyInfo(ID_COMPANY); - assertTrue("No company information found", company.getCompanyId() > 0); + assertTrue("No company information found", company.getId() > 0); assertNotNull("No parent company found", company.getParentCompany()); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java index facb9f375..3f97b92f8 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbSearchTest.java @@ -21,6 +21,8 @@ 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.SearchType; import com.omertron.themoviedbapi.model.collection.Collection; import com.omertron.themoviedbapi.model.company.Company; @@ -31,12 +33,7 @@ import com.omertron.themoviedbapi.model.movie.MovieInfo; import com.omertron.themoviedbapi.model.person.PersonFind; import com.omertron.themoviedbapi.model.tv.TVBasic; import com.omertron.themoviedbapi.results.ResultList; -import org.junit.After; -import org.junit.AfterClass; -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.Test; @@ -47,7 +44,6 @@ import org.junit.Test; public class TmdbSearchTest extends AbstractTests { private static TmdbSearch instance; - private static final String COMPANY_NAME = "Marvel Studios"; public TmdbSearchTest() { } @@ -58,18 +54,6 @@ public class TmdbSearchTest extends AbstractTests { instance = new TmdbSearch(getApiKey(), getHttpTools()); } - @AfterClass - public static void tearDownClass() { - } - - @Before - public void setUp() throws Exception { - } - - @After - public void tearDown() throws Exception { - } - /** * Test of searchCompanies method, of class TheMovieDbApi. * @@ -78,10 +62,9 @@ public class TmdbSearchTest extends AbstractTests { @Test public void testSearchCompanies() throws MovieDbException { LOG.info("searchCompanies"); - ResultList result = instance.searchCompanies(COMPANY_NAME, 0); - assertNotNull("Null results", result); - assertNotNull("Null company", result.getResults()); - assertFalse("Empty company", result.isEmpty()); + ResultList result = instance.searchCompanies("Marvel Studios", 0); + TestSuite.test(result); + TestSuite.testId(result, 420, "Company"); } /** @@ -95,9 +78,17 @@ public class TmdbSearchTest extends AbstractTests { String query = "batman"; int page = 0; ResultList result = instance.searchCollection(query, page, LANGUAGE_DEFAULT); - assertNotNull("Null results", result); - assertNotNull("Null collection", result.getResults()); - assertFalse("Empty collection", result.isEmpty()); + TestSuite.test(result); + + // Make sure we find at least the "Dark Knight" collection, ID: 263 + boolean found = false; + for (Collection c : result.getResults()) { + if (c.getId() == 263) { + found = true; + break; + } + } + assertTrue("Collection not found", found); } /** @@ -111,9 +102,8 @@ public class TmdbSearchTest extends AbstractTests { String query = "action"; int page = 0; ResultList result = instance.searchKeyword(query, page); - assertNotNull("Null results", result); - assertNotNull("Null keyword", result.getResults()); - assertFalse("Empty keyword", result.isEmpty()); + TestSuite.test(result); + TestSuite.testId(result, 207600, "Keyword"); } /** @@ -127,9 +117,7 @@ public class TmdbSearchTest extends AbstractTests { String query = "watch"; int page = 0; ResultList result = instance.searchList(query, page, null); - assertNotNull("Null results", result); - assertNotNull("Null list", result.getResults()); - assertFalse("Empty list", result.isEmpty()); + TestSuite.test(result); } /** @@ -143,14 +131,17 @@ public class TmdbSearchTest extends AbstractTests { // Try a movie with less than 1 page of results ResultList movieList = instance.searchMovie("Blade Runner", 0, "", null, 0, 0, SearchType.PHRASE); + TestSuite.test(movieList); 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); + TestSuite.test(movieList); 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); + TestSuite.test(movieList); assertTrue("Not enough movies found, should be over 15, found " + movieList.getResults().size(), movieList.getResults().size() >= 15); } @@ -161,15 +152,31 @@ public class TmdbSearchTest extends AbstractTests { */ @Test public void testSearchMulti() throws MovieDbException { - System.out.println("searchMulti"); - String query = "j"; + LOG.info("searchMulti"); + String query = "babylon"; Integer page = null; String language = ""; Boolean includeAdult = null; ResultList result = instance.searchMulti(query, page, language, includeAdult); + TestSuite.test(result); + + boolean foundTV = false; + boolean foundMovie = false; for (MediaBasic item : result.getResults()) { - LOG.info("{}", item); + if (foundMovie && foundTV) { + break; + } + + if (item.getMediaType() == MediaType.MOVIE) { + foundMovie = true; + } + + if (item.getMediaType() == MediaType.TV) { + foundTV = true; + } } + assertTrue("Movies not found", foundMovie); + assertTrue("TV not found", foundTV); } /** @@ -182,9 +189,8 @@ public class TmdbSearchTest extends AbstractTests { LOG.info("searchPeople"); String personName = "Bruce Willis"; ResultList result = instance.searchPeople(personName, null, null, SearchType.PHRASE); - assertNotNull("Null results", result); - assertNotNull("Null people", result.getResults()); - assertFalse("Empty people", result.isEmpty()); + TestSuite.test(result); + TestSuite.testId(result.getResults(), 62, "People"); } /** @@ -194,16 +200,15 @@ public class TmdbSearchTest extends AbstractTests { */ @Test public void testSearchTV() throws MovieDbException { - System.out.println("searchTV"); + LOG.info("searchTV"); String query = "The Walking Dead"; Integer page = null; String language = LANGUAGE_ENGLISH; Integer firstAirDateYear = null; SearchType searchType = SearchType.PHRASE; ResultList result = instance.searchTV(query, page, language, firstAirDateYear, searchType); - assertNotNull("Null results", result); - assertNotNull("Null TV", result.getResults()); - assertFalse("Empty TV", result.isEmpty()); + TestSuite.test(result); + TestSuite.testId(result, 1402, "TV Show"); } }