AppendToResponse: Movie methods
This commit is contained in:
@@ -24,11 +24,13 @@ import com.omertron.themoviedbapi.model.media.Translation;
|
||||
import com.omertron.themoviedbapi.model.media.AlternativeTitle;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonSetter;
|
||||
import com.omertron.themoviedbapi.enumeration.MovieMethod;
|
||||
import com.omertron.themoviedbapi.interfaces.IIdentification;
|
||||
import com.omertron.themoviedbapi.model.AbstractJsonMapping;
|
||||
import com.omertron.themoviedbapi.model.Genre;
|
||||
import com.omertron.themoviedbapi.model.Language;
|
||||
import com.omertron.themoviedbapi.model.artwork.Artwork;
|
||||
import com.omertron.themoviedbapi.model.change.ChangeKeyItem;
|
||||
import com.omertron.themoviedbapi.model.collection.Collection;
|
||||
import com.omertron.themoviedbapi.model.keyword.Keyword;
|
||||
import com.omertron.themoviedbapi.model.list.UserList;
|
||||
@@ -37,6 +39,7 @@ import com.omertron.themoviedbapi.model.credits.MediaCreditCrew;
|
||||
import com.omertron.themoviedbapi.model.media.MediaCreditList;
|
||||
import com.omertron.themoviedbapi.model.review.Review;
|
||||
import com.omertron.themoviedbapi.results.WrapperAlternativeTitles;
|
||||
import com.omertron.themoviedbapi.results.WrapperChanges;
|
||||
import com.omertron.themoviedbapi.results.WrapperGenericList;
|
||||
import com.omertron.themoviedbapi.results.WrapperImages;
|
||||
import com.omertron.themoviedbapi.results.WrapperMovieKeywords;
|
||||
@@ -45,7 +48,9 @@ import com.omertron.themoviedbapi.results.WrapperTranslations;
|
||||
import com.omertron.themoviedbapi.results.WrapperVideos;
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
@@ -110,18 +115,20 @@ public class MovieInfo extends AbstractJsonMapping implements Serializable, IIde
|
||||
private String status;
|
||||
@JsonProperty("video")
|
||||
private Boolean video = null;
|
||||
// AppendToResponse
|
||||
private final Set<MovieMethod> methods = EnumSet.noneOf(MovieMethod.class);
|
||||
// AppendToResponse Properties
|
||||
private List<AlternativeTitle> alternativeTitles = Collections.emptyList();
|
||||
@JsonProperty("casts")
|
||||
private MediaCreditList credits;
|
||||
private MediaCreditList credits = new MediaCreditList();
|
||||
private List<Artwork> images = Collections.emptyList();
|
||||
private List<Keyword> keywords = Collections.emptyList();
|
||||
private List<ReleaseInfo> releases = Collections.emptyList();
|
||||
private List<Video> trailers = Collections.emptyList();
|
||||
private List<Video> videos = Collections.emptyList();
|
||||
private List<Translation> translations = Collections.emptyList();
|
||||
private List<MovieInfo> similarMovies = Collections.emptyList();
|
||||
private List<Review> reviews = Collections.emptyList();
|
||||
private List<UserList> lists = Collections.emptyList();
|
||||
private List<ChangeKeyItem> changes = Collections.emptyList();
|
||||
|
||||
// <editor-fold defaultstate="collapsed" desc="Getter methods">
|
||||
public String getBackdropPath() {
|
||||
@@ -363,7 +370,7 @@ public class MovieInfo extends AbstractJsonMapping implements Serializable, IIde
|
||||
}
|
||||
|
||||
public List<Video> getVideos() {
|
||||
return trailers;
|
||||
return videos;
|
||||
}
|
||||
|
||||
public List<Translation> getTranslations() {
|
||||
@@ -381,56 +388,76 @@ public class MovieInfo extends AbstractJsonMapping implements Serializable, IIde
|
||||
public List<Review> getReviews() {
|
||||
return reviews;
|
||||
}
|
||||
|
||||
public List<ChangeKeyItem> getChanges() {
|
||||
return changes;
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="AppendToResponse Setters">
|
||||
@JsonSetter("alternative_titles")
|
||||
public void setAlternativeTitles(WrapperAlternativeTitles alternativeTitles) {
|
||||
this.alternativeTitles = alternativeTitles.getTitles();
|
||||
addMethod(MovieMethod.ALTERNATIVE_TITLES);
|
||||
}
|
||||
|
||||
@JsonSetter("credits")
|
||||
public void setCredits(MediaCreditList credits) {
|
||||
this.credits = credits;
|
||||
addMethod(MovieMethod.CREDITS);
|
||||
}
|
||||
|
||||
@JsonSetter("images")
|
||||
public void setImages(WrapperImages images) {
|
||||
this.images = images.getAll();
|
||||
addMethod(MovieMethod.IMAGES);
|
||||
}
|
||||
|
||||
@JsonSetter("keywords")
|
||||
public void setKeywords(WrapperMovieKeywords keywords) {
|
||||
this.keywords = keywords.getKeywords();
|
||||
addMethod(MovieMethod.KEYWORDS);
|
||||
}
|
||||
|
||||
@JsonSetter("releases")
|
||||
public void setReleases(WrapperReleaseInfo releases) {
|
||||
this.releases = releases.getCountries();
|
||||
addMethod(MovieMethod.RELEASES);
|
||||
}
|
||||
|
||||
@JsonSetter("trailers")
|
||||
public void setTrailers(WrapperVideos trailers) {
|
||||
this.trailers = trailers.getVideos();
|
||||
@JsonSetter("videos")
|
||||
public void setVideos(WrapperVideos trailers) {
|
||||
this.videos = trailers.getVideos();
|
||||
addMethod(MovieMethod.VIDEOS);
|
||||
}
|
||||
|
||||
@JsonSetter("translations")
|
||||
public void setTranslations(WrapperTranslations translations) {
|
||||
this.translations = translations.getTranslations();
|
||||
addMethod(MovieMethod.TRANSLATIONS);
|
||||
}
|
||||
|
||||
@JsonSetter("similar_movies")
|
||||
@JsonSetter("similar")
|
||||
public void setSimilarMovies(WrapperGenericList<MovieInfo> similarMovies) {
|
||||
this.similarMovies = similarMovies.getResults();
|
||||
addMethod(MovieMethod.SIMILAR);
|
||||
}
|
||||
|
||||
@JsonSetter("lists")
|
||||
public void setLists(WrapperGenericList<UserList> lists) {
|
||||
this.lists = lists.getResults();
|
||||
addMethod(MovieMethod.LISTS);
|
||||
}
|
||||
|
||||
@JsonSetter("reviews")
|
||||
public void setReviews(WrapperGenericList<Review> reviews) {
|
||||
this.reviews = reviews.getResults();
|
||||
addMethod(MovieMethod.REVIEWS);
|
||||
}
|
||||
|
||||
@JsonSetter("changes")
|
||||
public void setChanges(WrapperChanges changes) {
|
||||
this.changes = changes.getChangedItems();
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
@@ -458,4 +485,12 @@ public class MovieInfo extends AbstractJsonMapping implements Serializable, IIde
|
||||
.toHashCode();
|
||||
}
|
||||
// </editor-fold>
|
||||
|
||||
private void addMethod(MovieMethod method) {
|
||||
methods.add(method);
|
||||
}
|
||||
|
||||
public boolean hasMethod(MovieMethod method) {
|
||||
return methods.contains(method);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,9 @@ import com.omertron.themoviedbapi.model.movie.MovieBasic;
|
||||
import com.omertron.themoviedbapi.model.tv.TVBasic;
|
||||
import com.omertron.themoviedbapi.results.ResultList;
|
||||
import com.omertron.themoviedbapi.interfaces.IIdentification;
|
||||
import com.omertron.themoviedbapi.model.media.MediaCreditList;
|
||||
import com.omertron.themoviedbapi.model.movie.MovieInfo;
|
||||
import com.omertron.themoviedbapi.model.person.ExternalID;
|
||||
import com.omertron.themoviedbapi.model.person.Person;
|
||||
import com.omertron.themoviedbapi.model.tv.TVEpisodeInfo;
|
||||
import com.omertron.themoviedbapi.model.tv.TVInfo;
|
||||
@@ -129,6 +131,27 @@ public class TestSuite {
|
||||
assertTrue(message + ": Missing episodes", test.getEpisodes().size() > 0);
|
||||
}
|
||||
|
||||
public static void test(ExternalID test) {
|
||||
String message = test.getClass().getSimpleName();
|
||||
assertTrue(message + ": Missing ID", test.getId() > 0);
|
||||
assertTrue(message + ": Missing IMDB ID", StringUtils.isNotBlank(test.getImdbId()));
|
||||
boolean found = false;
|
||||
found |= StringUtils.isNotBlank(test.getFreebaseId());
|
||||
found |= StringUtils.isNotBlank(test.getFreebaseMid());
|
||||
found |= StringUtils.isNotBlank(test.getTvdbId());
|
||||
found |= StringUtils.isNotBlank(test.getTvrageId());
|
||||
assertTrue(message + ": Missing one of the other IDs", found);
|
||||
}
|
||||
|
||||
public static void test(MediaCreditList test) {
|
||||
String message = test.getClass().getSimpleName();
|
||||
boolean found = false;
|
||||
found |= test.getCast().isEmpty();
|
||||
found |= test.getCrew().isEmpty();
|
||||
found |= test.getGuestStars().isEmpty();
|
||||
assertTrue(message + ": Missing cast/crew/guest stars information", found);
|
||||
}
|
||||
|
||||
public static void testId(ResultList<? extends IIdentification> result, int id, String message) {
|
||||
testId(result.getResults(), id, message);
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.omertron.themoviedbapi.MovieDbException;
|
||||
import com.omertron.themoviedbapi.TestID;
|
||||
import com.omertron.themoviedbapi.TestSuite;
|
||||
import com.omertron.themoviedbapi.enumeration.ArtworkType;
|
||||
import com.omertron.themoviedbapi.enumeration.MovieMethod;
|
||||
import com.omertron.themoviedbapi.model.StatusCode;
|
||||
import com.omertron.themoviedbapi.model.artwork.Artwork;
|
||||
import com.omertron.themoviedbapi.model.change.ChangeKeyItem;
|
||||
@@ -78,6 +79,53 @@ public class TmdbMoviesTest extends AbstractTests {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of Append_To_Response method, of class TmdbMovies.
|
||||
*
|
||||
* @throws com.omertron.themoviedbapi.MovieDbException
|
||||
*/
|
||||
@Test
|
||||
public void testAppendToResponse() throws MovieDbException {
|
||||
LOG.info("appendToResponse");
|
||||
|
||||
String language = LANGUAGE_DEFAULT;
|
||||
|
||||
boolean first = true;
|
||||
StringBuilder appendToResponse = new StringBuilder();
|
||||
for (MovieMethod method : MovieMethod.values()) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
appendToResponse.append(",");
|
||||
}
|
||||
appendToResponse.append(method.getPropertyString());
|
||||
}
|
||||
|
||||
for (TestID test : FILM_IDS) {
|
||||
// Just test Blade Runner
|
||||
if (test.getTmdb() != 78) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MovieInfo result = instance.getMovieInfo(test.getTmdb(), language, appendToResponse.toString());
|
||||
assertEquals("Wrong IMDB ID", test.getImdb(), result.getImdbID());
|
||||
assertEquals("Wrong title", test.getName(), result.getTitle());
|
||||
TestSuite.test(result);
|
||||
TestSuite.test(result.getAlternativeTitles(), "Alt titles");
|
||||
TestSuite.test(result.getCast(), "Cast");
|
||||
TestSuite.test(result.getCrew(), "Crew");
|
||||
TestSuite.test(result.getImages(), "Images");
|
||||
TestSuite.test(result.getKeywords(), "Keywords");
|
||||
TestSuite.test(result.getReleases(), "Releases");
|
||||
TestSuite.test(result.getVideos(), "Videos");
|
||||
TestSuite.test(result.getTranslations(), "Translations");
|
||||
TestSuite.test(result.getSimilarMovies(), "Similar");
|
||||
TestSuite.test(result.getLists(), "Lists");
|
||||
TestSuite.test(result.getReviews(), "Reviews");
|
||||
// There are rarely any changes, so skip this test
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test of getMovieInfo method, of class TmdbMovies.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user