Update tests

master
Stuart Boston 12 years ago
parent a57e7eeb37
commit f64786e506

@ -1061,16 +1061,19 @@ public class TheMovieDbApi {
apiUrl.addArgument(PARAM_SESSION, sessionId);
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));
LOG.info("Body: {}", jsonBody);
URL url = apiUrl.buildUrl();
String webpage = WebBrowser.request(url, jsonBody);
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) {
LOG.warn(FAILED_KEYWORD, ex.getMessage());
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_ENGLISH = "en";
private static final String LANGUAGE_RUSSIAN = "ru";
// session and account id of test users named 'apitests'
private static final String SESSION_ID_APITESTS = "63c85deb39337e29b69d78265eb28d639cbd6f72";
private static final int ACCOUNT_ID_APITESTS = 6065849;
@ -100,7 +99,6 @@ public class TheMovieDbApiTest {
LOG.info(tmdbConfig.toString());
}
@Test
public void testAccount() throws MovieDbException {
Account account = tmdb.getAccount(SESSION_ID_APITESTS);
@ -110,7 +108,7 @@ public class TheMovieDbApiTest {
assertEquals(account.getId(), ACCOUNT_ID_APITESTS);
}
@Test
@Ignore("Session required")
public void testWatchList() throws MovieDbException {
// make sure it's empty (because it's just a test account
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);
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
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());
}
@Test
@Ignore("Session required")
public void testFavorites() throws MovieDbException {
// make sure it's empty (because it's just a test account
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);
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
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
*/
@Ignore("Session required")
public void testGetSessionToken() throws Exception {
LOG.info("getSessionToken");
TokenAuthorisation token = tmdb.getAuthorisationToken();
assertFalse("Token is null", token == null);
assertTrue("Token is not valid", token.getSuccess());
LOG.info(token.toString());
LOG.info("Token: {}", token.toString());
TokenSession result = tmdb.getSessionToken(token);
assertFalse("Session token is null", result == null);
@ -642,7 +643,7 @@ public class TheMovieDbApiTest {
*
* 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 {
LOG.info("postMovieRating");
Integer movieID = 68724;
@ -650,6 +651,7 @@ public class TheMovieDbApiTest {
boolean wasPosted = tmdb.postMovieRating(SESSION_ID_APITESTS, movieID, rating);
assertNotNull(wasPosted);
assertTrue(wasPosted);
// get all rated movies
@ -668,7 +670,7 @@ public class TheMovieDbApiTest {
assertTrue(foundMovie);
}
@Test
@Ignore("Session required")
public void testMovieLists() throws Exception {
Integer movieID = 68724;
@ -681,12 +683,13 @@ public class TheMovieDbApiTest {
// add a movie, and test that it is on the list now
tmdb.addMovieToList(SESSION_ID_APITESTS, listId, movieID);
MovieDbList list = tmdb.getList(listId);
Assert.assertEquals(list.getItemCount(), 1);
Assert.assertEquals(list.getItems().get(0).getId(), (int) movieID);
assertNotNull("Movie list returned was null", list);
assertEquals("Unexpected number of items returned", 1, list.getItemCount());
assertEquals((int) movieID, list.getItems().get(0).getId());
// now remove the movie
tmdb.removeMovieFromList(SESSION_ID_APITESTS, listId, movieID);
Assert.assertEquals(tmdb.getList(listId).getItemCount(), 0);
assertEquals(tmdb.getList(listId).getItemCount(), 0);
// delete the test list
StatusCode statusCode = tmdb.deleteMovieList(SESSION_ID_APITESTS, listId);

Loading…
Cancel
Save