Update tests

master
Stuart Boston 12 years ago
parent a57e7eeb37
commit f64786e506

@ -1061,16 +1061,19 @@ public class TheMovieDbApi {
apiUrl.addArgument(PARAM_SESSION, sessionId); apiUrl.addArgument(PARAM_SESSION, sessionId);
if (rating < 0 || rating > 10) { if (rating < 0 || rating > 10) {
throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "rating out of range"); throw new MovieDbException(MovieDbExceptionType.UNKNOWN_CAUSE, "Rating out of range");
} }
String jsonBody = WebBrowser.convertToJson(Collections.singletonMap("value", rating)); String jsonBody = WebBrowser.convertToJson(Collections.singletonMap("value", rating));
LOG.info("Body: {}", jsonBody);
URL url = apiUrl.buildUrl(); URL url = apiUrl.buildUrl();
String webpage = WebBrowser.request(url, jsonBody); String webpage = WebBrowser.request(url, jsonBody);
try { try {
return mapper.readValue(webpage, StatusCode.class).getStatusCode() == 12; StatusCode status = mapper.readValue(webpage, StatusCode.class);
LOG.info("Status: {}", status);
int code = status.getStatusCode();
return code == 12;
} catch (IOException ex) { } catch (IOException ex) {
LOG.warn(FAILED_KEYWORD, ex.getMessage()); LOG.warn(FAILED_KEYWORD, ex.getMessage());
throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex); throw new MovieDbException(MovieDbExceptionType.MAPPING_FAILED, webpage, ex);

@ -58,7 +58,6 @@ public class TheMovieDbApiTest {
private static final String LANGUAGE_DEFAULT = ""; private static final String LANGUAGE_DEFAULT = "";
private static final String LANGUAGE_ENGLISH = "en"; private static final String LANGUAGE_ENGLISH = "en";
private static final String LANGUAGE_RUSSIAN = "ru"; private static final String LANGUAGE_RUSSIAN = "ru";
// session and account id of test users named 'apitests' // session and account id of test users named 'apitests'
private static final String SESSION_ID_APITESTS = "63c85deb39337e29b69d78265eb28d639cbd6f72"; private static final String SESSION_ID_APITESTS = "63c85deb39337e29b69d78265eb28d639cbd6f72";
private static final int ACCOUNT_ID_APITESTS = 6065849; private static final int ACCOUNT_ID_APITESTS = 6065849;
@ -100,7 +99,6 @@ public class TheMovieDbApiTest {
LOG.info(tmdbConfig.toString()); LOG.info(tmdbConfig.toString());
} }
@Test @Test
public void testAccount() throws MovieDbException { public void testAccount() throws MovieDbException {
Account account = tmdb.getAccount(SESSION_ID_APITESTS); Account account = tmdb.getAccount(SESSION_ID_APITESTS);
@ -110,7 +108,7 @@ public class TheMovieDbApiTest {
assertEquals(account.getId(), ACCOUNT_ID_APITESTS); assertEquals(account.getId(), ACCOUNT_ID_APITESTS);
} }
@Test @Ignore("Session required")
public void testWatchList() throws MovieDbException { public void testWatchList() throws MovieDbException {
// make sure it's empty (because it's just a test account // make sure it's empty (because it's just a test account
Assert.assertTrue(tmdb.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty()); Assert.assertTrue(tmdb.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty());
@ -119,7 +117,8 @@ public class TheMovieDbApiTest {
tmdb.addToWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, 550); tmdb.addToWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, 550);
List<MovieDb> watchList = tmdb.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); List<MovieDb> watchList = tmdb.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertTrue(watchList.size()==1); assertNotNull("Empty watch list returned", watchList);
assertEquals("Watchlist wrong size", 1, watchList.size());
// clean up again // clean up again
tmdb.removeFromWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, 550); tmdb.removeFromWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, 550);
@ -127,7 +126,7 @@ public class TheMovieDbApiTest {
Assert.assertTrue(tmdb.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty()); Assert.assertTrue(tmdb.getWatchList(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty());
} }
@Test @Ignore("Session required")
public void testFavorites() throws MovieDbException { public void testFavorites() throws MovieDbException {
// make sure it's empty (because it's just a test account // make sure it's empty (because it's just a test account
Assert.assertTrue(tmdb.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty()); Assert.assertTrue(tmdb.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS).isEmpty());
@ -136,7 +135,8 @@ public class TheMovieDbApiTest {
tmdb.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, 550, true); tmdb.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, 550, true);
List<MovieDb> watchList = tmdb.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); List<MovieDb> watchList = tmdb.getFavoriteMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertTrue(watchList.size()==1); assertNotNull("Empty watch list returned", watchList);
assertEquals("Watchlist wrong size", 1, watchList.size());
// clean up again // clean up again
tmdb.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, 550, false); tmdb.changeFavoriteStatus(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS, 550, false);
@ -534,12 +534,13 @@ public class TheMovieDbApiTest {
* *
* TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication
*/ */
@Ignore("Session required")
public void testGetSessionToken() throws Exception { public void testGetSessionToken() throws Exception {
LOG.info("getSessionToken"); LOG.info("getSessionToken");
TokenAuthorisation token = tmdb.getAuthorisationToken(); TokenAuthorisation token = tmdb.getAuthorisationToken();
assertFalse("Token is null", token == null); assertFalse("Token is null", token == null);
assertTrue("Token is not valid", token.getSuccess()); assertTrue("Token is not valid", token.getSuccess());
LOG.info(token.toString()); LOG.info("Token: {}", token.toString());
TokenSession result = tmdb.getSessionToken(token); TokenSession result = tmdb.getSessionToken(token);
assertFalse("Session token is null", result == null); assertFalse("Session token is null", result == null);
@ -642,25 +643,26 @@ public class TheMovieDbApiTest {
* *
* TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication * TODO: Cannot be tested without a HTTP authorisation: http://help.themoviedb.org/kb/api/user-authentication
*/ */
@Test @Ignore("Session required")
public void testMovieRating() throws Exception { public void testMovieRating() throws Exception {
LOG.info("postMovieRating"); LOG.info("postMovieRating");
Integer movieID = 68724; Integer movieID = 68724;
Integer rating = new Random().nextInt(10)+1; Integer rating = new Random().nextInt(10) + 1;
boolean wasPosted = tmdb.postMovieRating(SESSION_ID_APITESTS, movieID, rating); boolean wasPosted = tmdb.postMovieRating(SESSION_ID_APITESTS, movieID, rating);
assertNotNull(wasPosted);
assertTrue(wasPosted); assertTrue(wasPosted);
// get all rated movies // get all rated movies
List<MovieDb> ratedMovies = tmdb.getRatedMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS); List<MovieDb> ratedMovies = tmdb.getRatedMovies(SESSION_ID_APITESTS, ACCOUNT_ID_APITESTS);
assertTrue(ratedMovies.size()>0); assertTrue(ratedMovies.size() > 0);
// make sure that we find the movie and it is rated correctly // make sure that we find the movie and it is rated correctly
boolean foundMovie = false; boolean foundMovie = false;
for (MovieDb movie : ratedMovies) { for (MovieDb movie : ratedMovies) {
if(movie.getId()==movieID){ if (movie.getId() == movieID) {
assertEquals(movie.getUserRating(), (float) rating, 0); assertEquals(movie.getUserRating(), (float) rating, 0);
foundMovie = true; foundMovie = true;
} }
@ -668,7 +670,7 @@ public class TheMovieDbApiTest {
assertTrue(foundMovie); assertTrue(foundMovie);
} }
@Test @Ignore("Session required")
public void testMovieLists() throws Exception { public void testMovieLists() throws Exception {
Integer movieID = 68724; Integer movieID = 68724;
@ -681,22 +683,23 @@ public class TheMovieDbApiTest {
// add a movie, and test that it is on the list now // add a movie, and test that it is on the list now
tmdb.addMovieToList(SESSION_ID_APITESTS, listId, movieID); tmdb.addMovieToList(SESSION_ID_APITESTS, listId, movieID);
MovieDbList list = tmdb.getList(listId); MovieDbList list = tmdb.getList(listId);
Assert.assertEquals(list.getItemCount(), 1); assertNotNull("Movie list returned was null", list);
Assert.assertEquals(list.getItems().get(0).getId(), (int) movieID); assertEquals("Unexpected number of items returned", 1, list.getItemCount());
assertEquals((int) movieID, list.getItems().get(0).getId());
// now remove the movie // now remove the movie
tmdb.removeMovieFromList(SESSION_ID_APITESTS, listId, movieID); tmdb.removeMovieFromList(SESSION_ID_APITESTS, listId, movieID);
Assert.assertEquals(tmdb.getList(listId).getItemCount(), 0); assertEquals(tmdb.getList(listId).getItemCount(), 0);
// delete the test list // delete the test list
StatusCode statusCode = tmdb.deleteMovieList(SESSION_ID_APITESTS, listId); StatusCode statusCode = tmdb.deleteMovieList(SESSION_ID_APITESTS, listId);
assertEquals(statusCode.getStatusCode(), 13); assertEquals(statusCode.getStatusCode(), 13);
} }
/** /**
* Test of getPersonChanges method, of class TheMovieDbApi. * Test of getPersonChanges method, of class TheMovieDbApi.
* *
*/ */
@Ignore("Not ready yet") @Ignore("Not ready yet")
public void testGetPersonChanges() throws Exception { public void testGetPersonChanges() throws Exception {
LOG.info("getPersonChanges"); LOG.info("getPersonChanges");

Loading…
Cancel
Save