AppendToResponse: People Methods

master
Stuart Boston 11 years ago
parent 7c72a1fa92
commit 5a1719c662

@ -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);
}
}

@ -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<PeopleMethod> methods = EnumSet.noneOf(PeopleMethod.class);
// AppendToResponse Properties
private List<ChangeKeyItem> changes = Collections.emptyList();
// TODO: Add COMBINED_CREDITS
private ExternalID externalIDs = new ExternalID();
private List<Artwork> images = Collections.emptyList();
private PersonCreditList<CreditMovieBasic> movieCredits = new PersonCreditList<CreditMovieBasic>();
private List<ArtworkMedia> taggedImages = Collections.emptyList();
private PersonCreditList<CreditTVBasic> tvCredits = new PersonCreditList<CreditTVBasic>();
//<editor-fold defaultstate="collapsed" desc="Getters and Setters">
public boolean isAdult() {
return adult;
}
@ -120,5 +144,79 @@ public class PersonInfo extends PersonBasic implements Serializable {
public void setPopularity(float popularity) {
this.popularity = popularity;
}
//</editor-fold>
private void addMethod(PeopleMethod method) {
methods.add(method);
}
public boolean hasMethod(PeopleMethod method) {
return methods.contains(method);
}
//<editor-fold defaultstate="collapsed" desc="AppendToResponse Setters">
@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<CreditMovieBasic> movieCredits) {
this.movieCredits = movieCredits;
addMethod(PeopleMethod.MOVIE_CREDITS);
}
@JsonSetter("tagged_images")
public void setTaggedImages(WrapperGenericList<ArtworkMedia> taggedImages) {
this.taggedImages = taggedImages.getResults();
addMethod(PeopleMethod.TAGGED_IMAGES);
}
@JsonSetter("tv_credits")
public void setTvCredits(PersonCreditList<CreditTVBasic> tvCredits) {
this.tvCredits = tvCredits;
addMethod(PeopleMethod.TV_CREDITS);
}
//</editor-fold>
//<editor-fold defaultstate="collapsed" desc="AppendToResponse Getters">
public List<ChangeKeyItem> getChanges() {
return changes;
}
public ExternalID getExternalIDs() {
return externalIDs;
}
public List<Artwork> getImages() {
return images;
}
public PersonCreditList<CreditMovieBasic> getMovieCredits() {
return movieCredits;
}
public List<ArtworkMedia> getTaggedImages() {
return taggedImages;
}
public PersonCreditList<CreditTVBasic> getTvCredits() {
return tvCredits;
}
//</editor-fold>
}

@ -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<? extends IIdentification> result, int id, String message) {
testId(result.getResults(), id, message);
}

@ -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<TestID> testIDs = new ArrayList<TestID>();
private static final List<TestID> TEST_IDS = new ArrayList<TestID>();
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<CreditMovieBasic> 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<CreditTVBasic> 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<CreditBasic> 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<Artwork> 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<ArtworkMedia> 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();

Loading…
Cancel
Save