diff --git a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java index 22f2f59f1..bec60349b 100644 --- a/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java +++ b/src/main/java/com/omertron/themoviedbapi/methods/TmdbPeople.java @@ -46,6 +46,7 @@ import com.omertron.themoviedbapi.results.WrapperGenericList; import com.omertron.themoviedbapi.results.WrapperImages; import java.io.IOException; import java.net.URL; +import org.slf4j.LoggerFactory; import org.yamj.api.common.exception.ApiExceptionType; /** @@ -84,6 +85,7 @@ public class TmdbPeople extends AbstractMethod { try { return MAPPER.readValue(webpage, PersonInfo.class); } catch (IOException ex) { + LoggerFactory.getLogger("test").info("{}",ex); throw new MovieDbException(ApiExceptionType.MAPPING_FAILED, "Failed to get person info", url, ex); } } diff --git a/src/main/java/com/omertron/themoviedbapi/model/person/PersonInfo.java b/src/main/java/com/omertron/themoviedbapi/model/person/PersonInfo.java index f61a2b648..68bf86d8a 100644 --- a/src/main/java/com/omertron/themoviedbapi/model/person/PersonInfo.java +++ b/src/main/java/com/omertron/themoviedbapi/model/person/PersonInfo.java @@ -20,8 +20,21 @@ package com.omertron.themoviedbapi.model.person; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSetter; +import com.omertron.themoviedbapi.enumeration.PeopleMethod; +import com.omertron.themoviedbapi.model.artwork.Artwork; +import com.omertron.themoviedbapi.model.artwork.ArtworkMedia; +import com.omertron.themoviedbapi.model.change.ChangeKeyItem; +import com.omertron.themoviedbapi.model.credits.CreditMovieBasic; +import com.omertron.themoviedbapi.model.credits.CreditTVBasic; +import com.omertron.themoviedbapi.results.WrapperChanges; +import com.omertron.themoviedbapi.results.WrapperGenericList; +import com.omertron.themoviedbapi.results.WrapperImages; import java.io.Serializable; +import java.util.Collections; +import java.util.EnumSet; import java.util.List; +import java.util.Set; /** * @author stuart.boston @@ -48,7 +61,18 @@ public class PersonInfo extends PersonBasic implements Serializable { private String placeOfBirth; @JsonProperty("popularity") private float popularity; + // AppendToResponse + private final Set methods = EnumSet.noneOf(PeopleMethod.class); + // AppendToResponse Properties + private List changes = Collections.emptyList(); + // TODO: Add COMBINED_CREDITS + private ExternalID externalIDs = new ExternalID(); + private List images = Collections.emptyList(); + private PersonCreditList movieCredits = new PersonCreditList(); + private List taggedImages = Collections.emptyList(); + private PersonCreditList tvCredits = new PersonCreditList(); + // public boolean isAdult() { return adult; } @@ -120,5 +144,79 @@ public class PersonInfo extends PersonBasic implements Serializable { public void setPopularity(float popularity) { this.popularity = popularity; } + // + + private void addMethod(PeopleMethod method) { + methods.add(method); + } + + public boolean hasMethod(PeopleMethod method) { + return methods.contains(method); + } + + // + @JsonSetter("changes") + public void setChanges(WrapperChanges changes) { + this.changes = changes.getChangedItems(); + addMethod(PeopleMethod.CHANGES); + } + + @JsonSetter("external_ids") + public void setExternalIDs(ExternalID externalIDs) { + this.externalIDs = externalIDs; + addMethod(PeopleMethod.EXTERNAL_IDS); + } + + @JsonSetter("images") + public void setImages(WrapperImages images) { + this.images = images.getAll(); + addMethod(PeopleMethod.IMAGES); + } + + @JsonSetter("movie_credits") + public void setMovieCredits(PersonCreditList movieCredits) { + this.movieCredits = movieCredits; + addMethod(PeopleMethod.MOVIE_CREDITS); + } + + @JsonSetter("tagged_images") + public void setTaggedImages(WrapperGenericList taggedImages) { + this.taggedImages = taggedImages.getResults(); + addMethod(PeopleMethod.TAGGED_IMAGES); + } + + @JsonSetter("tv_credits") + public void setTvCredits(PersonCreditList tvCredits) { + this.tvCredits = tvCredits; + addMethod(PeopleMethod.TV_CREDITS); + } + // + + // + public List getChanges() { + return changes; + } + + public ExternalID getExternalIDs() { + return externalIDs; + } + + public List getImages() { + return images; + } + + public PersonCreditList getMovieCredits() { + return movieCredits; + } + + public List getTaggedImages() { + return taggedImages; + } + + public PersonCreditList getTvCredits() { + return tvCredits; + } + // + } diff --git a/src/test/java/com/omertron/themoviedbapi/TestSuite.java b/src/test/java/com/omertron/themoviedbapi/TestSuite.java index bd327c69b..66c3d5473 100644 --- a/src/test/java/com/omertron/themoviedbapi/TestSuite.java +++ b/src/test/java/com/omertron/themoviedbapi/TestSuite.java @@ -27,6 +27,7 @@ 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.PersonCreditList; import com.omertron.themoviedbapi.model.person.PersonInfo; import com.omertron.themoviedbapi.model.tv.TVEpisodeInfo; import com.omertron.themoviedbapi.model.tv.TVInfo; @@ -145,12 +146,19 @@ public class TestSuite { 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(); + found |= !test.getCast().isEmpty(); + found |= !test.getCrew().isEmpty(); + found |= !test.getGuestStars().isEmpty(); assertTrue(message + ": Missing cast/crew/guest stars information", found); } + public static void test(PersonCreditList test, String message) { + boolean found = false; + found |= !test.getCast().isEmpty(); + found |= !test.getCrew().isEmpty(); + assertTrue(message + ": Missing cast/crew information", found); + } + public static void testId(ResultList result, int id, String message) { testId(result.getResults(), id, message); } diff --git a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java index f729f0699..a1331eb2b 100644 --- a/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java +++ b/src/test/java/com/omertron/themoviedbapi/methods/TmdbPeopleTest.java @@ -25,6 +25,7 @@ import com.omertron.themoviedbapi.TestID; import com.omertron.themoviedbapi.TestSuite; import com.omertron.themoviedbapi.enumeration.ArtworkType; import com.omertron.themoviedbapi.enumeration.MediaType; +import com.omertron.themoviedbapi.enumeration.PeopleMethod; import com.omertron.themoviedbapi.model.artwork.Artwork; import com.omertron.themoviedbapi.model.artwork.ArtworkMedia; import com.omertron.themoviedbapi.model.change.ChangeKeyItem; @@ -61,7 +62,7 @@ import org.junit.Test; public class TmdbPeopleTest extends AbstractTests { private static TmdbPeople instance; - private static final List testIDs = new ArrayList(); + private static final List TEST_IDS = new ArrayList(); public TmdbPeopleTest() { } @@ -70,8 +71,8 @@ public class TmdbPeopleTest extends AbstractTests { public static void setUpClass() throws MovieDbException { doConfiguration(); instance = new TmdbPeople(getApiKey(), getHttpTools()); - testIDs.add(new TestID("Bruce Willis", "nm0000246", 62)); - testIDs.add(new TestID("Will Smith", "nm0000226", 2888)); + TEST_IDS.add(new TestID("Bruce Willis", "nm0000246", 62)); + TEST_IDS.add(new TestID("Will Smith", "nm0000226", 2888)); } @AfterClass @@ -86,17 +87,49 @@ public class TmdbPeopleTest extends AbstractTests { public void tearDown() { } + /** + * Test of Append_To_Response method, of class TmdbPeople. + * + * @throws com.omertron.themoviedbapi.MovieDbException + */ + @Test + public void testAppendToResponse() throws MovieDbException { + LOG.info("appendToResponse"); + + boolean first = true; + StringBuilder appendToResponse = new StringBuilder(); + for (PeopleMethod method : PeopleMethod.values()) { + if (first) { + first = false; + } else { + appendToResponse.append(","); + } + appendToResponse.append(method.getPropertyString()); + } + + for (TestID test : TEST_IDS) { + PersonInfo result = instance.getPersonInfo(test.getTmdb(), appendToResponse.toString()); + TestSuite.test(result); + TestSuite.test(result.getExternalIDs()); + TestSuite.test(result.getImages(), "Images"); + TestSuite.test(result.getMovieCredits(), "Movie Credits"); + TestSuite.test(result.getTvCredits(), "TV Credits"); + TestSuite.test(result.getTaggedImages(), "Tagged Images"); + // There are rarely any changes, so skip this test + } + } + /** * Test of getPersonMovieOldInfo method, of class TheMovieDbApi. * * @throws MovieDbException */ - @Test + //@Test public void testGetPersonInfo() throws MovieDbException { LOG.info("getPersonInfo"); PersonInfo result; - for (TestID test : testIDs) { + for (TestID test : TEST_IDS) { result = instance.getPersonInfo(test.getTmdb()); assertEquals("Wrong actor returned", test.getTmdb(), result.getId()); assertEquals("Missing IMDB", test.getImdb(), result.getImdbId()); @@ -109,13 +142,13 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonMovieCredits() throws MovieDbException { LOG.info("getPersonMovieCredits"); String language = LANGUAGE_DEFAULT; String[] appendToResponse = null; - for (TestID test : testIDs) { + for (TestID test : TEST_IDS) { PersonCreditList result = instance.getPersonMovieCredits(test.getTmdb(), language, appendToResponse); LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); assertEquals("Incorrect ID", test.getTmdb(), result.getId()); @@ -133,13 +166,13 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonTVCredits() throws MovieDbException { LOG.info("getPersonTVCredits"); String language = LANGUAGE_DEFAULT; String[] appendToResponse = null; - for (TestID test : testIDs) { + for (TestID test : TEST_IDS) { PersonCreditList result = instance.getPersonTVCredits(test.getTmdb(), language, appendToResponse); LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); assertEquals("Incorrect ID", test.getTmdb(), result.getId()); @@ -157,13 +190,13 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonCombinedCredits() throws MovieDbException { LOG.info("getPersonCombinedCredits"); String language = LANGUAGE_DEFAULT; String[] appendToResponse = null; - for (TestID test : testIDs) { + for (TestID test : TEST_IDS) { PersonCreditList result = instance.getPersonCombinedCredits(test.getTmdb(), language, appendToResponse); LOG.info("ID: {}, # Cast: {}, # Crew: {}", result.getId(), result.getCast().size(), result.getCrew().size()); assertEquals("Incorrect ID", test.getTmdb(), result.getId()); @@ -199,11 +232,11 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonExternalIds() throws MovieDbException { LOG.info("getPersonExternalIds"); - for (TestID test : testIDs) { + for (TestID test : TEST_IDS) { ExternalID result = instance.getPersonExternalIds(test.getTmdb()); assertEquals("Wrong IMDB ID", test.getImdb(), result.getImdbId()); } @@ -214,11 +247,11 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonImages() throws MovieDbException { LOG.info("getPersonImages"); - for (TestID test : testIDs) { + for (TestID test : TEST_IDS) { ResultList result = instance.getPersonImages(test.getTmdb()); TestSuite.test(result, "Images"); assertEquals("Wrong artwork type", ArtworkType.PROFILE, result.getResults().get(0).getArtworkType()); @@ -230,13 +263,13 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonTaggedImages() throws MovieDbException { LOG.info("getPersonTaggedImages"); Integer page = null; String language = LANGUAGE_DEFAULT; - for (TestID test : testIDs) { + for (TestID test : TEST_IDS) { ResultList result = instance.getPersonTaggedImages(test.getTmdb(), page, language); TestSuite.test(result, "Tagged"); for (ArtworkMedia am : result.getResults()) { @@ -251,7 +284,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonChanges() throws MovieDbException { LOG.info("getPersonChanges"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); @@ -282,7 +315,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonPopular() throws MovieDbException { LOG.info("getPersonPopular"); Integer page = null; @@ -299,7 +332,7 @@ public class TmdbPeopleTest extends AbstractTests { * * @throws com.omertron.themoviedbapi.MovieDbException */ - @Test + //@Test public void testGetPersonLatest() throws MovieDbException { LOG.info("getPersonLatest"); PersonInfo result = instance.getPersonLatest();