Updated Models & Test cases
This commit is contained in:
@@ -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<TVBasic> wrapper = processWrapper(getTypeReference(TVBasic.class), url, "TV Show");
|
||||
return wrapper.getResultsList();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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<? extends MediaBasic> getKnownFor() {
|
||||
return knownFor;
|
||||
public List<MediaBasic> getKnownFor() {
|
||||
return (List<MediaBasic>) knownFor;
|
||||
}
|
||||
|
||||
@JsonTypeInfo(
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -36,8 +36,8 @@ public class WrapperMultiSearch extends AbstractWrapperAll {
|
||||
|
||||
private List<? extends MediaBasic> results;
|
||||
|
||||
public List<? extends MediaBasic> getResults() {
|
||||
return results;
|
||||
public List<MediaBasic> getResults() {
|
||||
return (List<MediaBasic>) results;
|
||||
}
|
||||
|
||||
@JsonTypeInfo(
|
||||
|
||||
@@ -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<? extends IWrapperId> 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<? extends IWrapperId> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Company> result = instance.searchCompanies(COMPANY_NAME, 0);
|
||||
assertNotNull("Null results", result);
|
||||
assertNotNull("Null company", result.getResults());
|
||||
assertFalse("Empty company", result.isEmpty());
|
||||
ResultList<Company> 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<Collection> 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<Keyword> 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<UserList> 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<MovieInfo> 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<MediaBasic> 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<PersonFind> 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<TVBasic> 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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user