|
|
|
|
@ -21,25 +21,33 @@ package com.omertron.themoviedbapi.methods;
|
|
|
|
|
|
|
|
|
|
import com.omertron.themoviedbapi.AbstractTests;
|
|
|
|
|
import com.omertron.themoviedbapi.MovieDbException;
|
|
|
|
|
import com.omertron.themoviedbapi.model.MovieDbList;
|
|
|
|
|
import com.omertron.themoviedbapi.model2.StatusCode;
|
|
|
|
|
import com.omertron.themoviedbapi.tools.MethodSub;
|
|
|
|
|
import com.omertron.themoviedbapi.model2.list.ListItem;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
import org.junit.After;
|
|
|
|
|
import org.junit.AfterClass;
|
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
|
import static org.junit.Assert.assertFalse;
|
|
|
|
|
import static org.junit.Assert.fail;
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
import org.junit.Before;
|
|
|
|
|
import org.junit.BeforeClass;
|
|
|
|
|
import org.junit.FixMethodOrder;
|
|
|
|
|
import org.junit.Ignore;
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import org.junit.runners.MethodSorters;
|
|
|
|
|
import org.junit.rules.ExpectedException;
|
|
|
|
|
|
|
|
|
|
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
|
|
|
|
//@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
|
|
|
|
public class TmdbListsTest extends AbstractTests {
|
|
|
|
|
|
|
|
|
|
private static TmdbLists instance;
|
|
|
|
|
private static final int ID_JUPITER_ASCENDING = 76757;
|
|
|
|
|
private static final int ID_BIG_HERO_6 = 177572;
|
|
|
|
|
// Status codes
|
|
|
|
|
private static final int SC_SUCCESS_UPD = 12;
|
|
|
|
|
private static final int SC_SUCCESS_DEL = 13;
|
|
|
|
|
// Expected exception
|
|
|
|
|
@Rule
|
|
|
|
|
public ExpectedException exception = ExpectedException.none();
|
|
|
|
|
|
|
|
|
|
public TmdbListsTest() {
|
|
|
|
|
}
|
|
|
|
|
@ -62,100 +70,120 @@ public class TmdbListsTest extends AbstractTests {
|
|
|
|
|
public void tearDown() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void testSuite() throws MovieDbException {
|
|
|
|
|
// Test the list creation
|
|
|
|
|
String listId = testCreateList();
|
|
|
|
|
|
|
|
|
|
// Add two items to the list
|
|
|
|
|
testAddItem(listId, ID_JUPITER_ASCENDING);
|
|
|
|
|
testAddItem(listId, ID_BIG_HERO_6);
|
|
|
|
|
|
|
|
|
|
// Get information on the list
|
|
|
|
|
testGetList(listId);
|
|
|
|
|
|
|
|
|
|
// Check item status on the list
|
|
|
|
|
testCheckItemStatus(listId, ID_JUPITER_ASCENDING);
|
|
|
|
|
|
|
|
|
|
// Delete an item from the list
|
|
|
|
|
testRemoveItem(listId, ID_BIG_HERO_6);
|
|
|
|
|
|
|
|
|
|
// Clear the list
|
|
|
|
|
testClear(listId);
|
|
|
|
|
|
|
|
|
|
// Delete the list
|
|
|
|
|
testDeleteList(listId);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test of createList method, of class TmdbList.
|
|
|
|
|
* Test of getList method, of class TmdbLists.
|
|
|
|
|
*
|
|
|
|
|
* @throws com.omertron.themoviedbapi.MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
@Ignore("Not working")
|
|
|
|
|
public void test1CreateList() throws MovieDbException {
|
|
|
|
|
private void testGetList(String listId) throws MovieDbException {
|
|
|
|
|
LOG.info("getList");
|
|
|
|
|
|
|
|
|
|
ListItem result = instance.getList(listId);
|
|
|
|
|
LOG.info("Found {} movies on list", result.getItems().size());
|
|
|
|
|
assertFalse("No movies in list", result.getItems().isEmpty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test of createList method, of class TmdbLists.
|
|
|
|
|
*
|
|
|
|
|
* @throws com.omertron.themoviedbapi.MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
private String testCreateList() throws MovieDbException {
|
|
|
|
|
LOG.info("createList");
|
|
|
|
|
String name = "My Totally Awesome List";
|
|
|
|
|
String description = "This list was created to share all of the totally awesome movies I've seen.";
|
|
|
|
|
int r = new Random().nextInt();
|
|
|
|
|
|
|
|
|
|
String name = "Random list name #" + r;
|
|
|
|
|
String description = "This is random list number " + r + " used for testing purposes";
|
|
|
|
|
String result = instance.createList(getSessionId(), name, description);
|
|
|
|
|
LOG.info(result);
|
|
|
|
|
// TODO review the generated test code and remove the default call to fail.
|
|
|
|
|
fail("The test case is a prototype.");
|
|
|
|
|
assertTrue("No list ID returned", StringUtils.isNotBlank(result));
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test of getList method, of class TheMovieDbApi.
|
|
|
|
|
* Test of checkItemStatus method, of class TmdbLists.
|
|
|
|
|
*
|
|
|
|
|
* @throws MovieDbException
|
|
|
|
|
* @throws com.omertron.themoviedbapi.MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
@Test
|
|
|
|
|
public void test2GetList() throws MovieDbException {
|
|
|
|
|
LOG.info("getList");
|
|
|
|
|
String listId = "509ec17b19c2950a0600050d";
|
|
|
|
|
MovieDbList result = instance.getList(listId);
|
|
|
|
|
assertFalse("List not found", result.getItems().isEmpty());
|
|
|
|
|
private void testCheckItemStatus(String listId, int mediaId) throws MovieDbException {
|
|
|
|
|
LOG.info("checkItemStatus");
|
|
|
|
|
boolean expResult = true;
|
|
|
|
|
boolean result = instance.checkItemStatus(listId, mediaId);
|
|
|
|
|
assertEquals("Item is not on list!", expResult, result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test of addMovieToList method, of class TmdbList.
|
|
|
|
|
* Test of deleteList method, of class TmdbLists.
|
|
|
|
|
*
|
|
|
|
|
* @throws com.omertron.themoviedbapi.MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
@Ignore("Not working")
|
|
|
|
|
public void test3AddMovieToList() throws MovieDbException {
|
|
|
|
|
LOG.info("addMovieToList");
|
|
|
|
|
String listId = "";
|
|
|
|
|
Integer movieId = null;
|
|
|
|
|
StatusCode expResult = null;
|
|
|
|
|
StatusCode result = instance.modifyMovieList(getSessionId(), listId, movieId, MethodSub.MOVIE);
|
|
|
|
|
assertEquals(expResult, result);
|
|
|
|
|
// TODO review the generated test code and remove the default call to fail.
|
|
|
|
|
fail("The test case is a prototype.");
|
|
|
|
|
private void testDeleteList(String listId) throws MovieDbException {
|
|
|
|
|
LOG.info("deleteList");
|
|
|
|
|
StatusCode result = instance.deleteList(getSessionId(), listId);
|
|
|
|
|
LOG.info("Result: {}", result);
|
|
|
|
|
|
|
|
|
|
// We expect there to be an exception thrown here
|
|
|
|
|
exception.expect(MovieDbException.class);
|
|
|
|
|
ListItem result2 = instance.getList(listId);
|
|
|
|
|
LOG.info("Result: {}", result2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test of isMovieOnList method, of class TmdbList.
|
|
|
|
|
* Test of addItem method, of class TmdbLists.
|
|
|
|
|
*
|
|
|
|
|
* @throws com.omertron.themoviedbapi.MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
@Ignore("Not working")
|
|
|
|
|
public void test4IsMovieOnList() throws MovieDbException {
|
|
|
|
|
LOG.info("isMovieOnList");
|
|
|
|
|
String listId = "";
|
|
|
|
|
Integer movieId = null;
|
|
|
|
|
boolean expResult = false;
|
|
|
|
|
boolean result = instance.isMovieOnList(listId, movieId);
|
|
|
|
|
assertEquals(expResult, result);
|
|
|
|
|
// TODO review the generated test code and remove the default call to fail.
|
|
|
|
|
fail("The test case is a prototype.");
|
|
|
|
|
private void testAddItem(String listId, int mediaId) throws MovieDbException {
|
|
|
|
|
LOG.info("addItem");
|
|
|
|
|
StatusCode result = instance.addItem(getSessionId(), listId, mediaId);
|
|
|
|
|
assertEquals("Invalid response: " + result.toString(), SC_SUCCESS_UPD, result.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test of removeMovieFromList method, of class TmdbList.
|
|
|
|
|
* Test of removeItem method, of class TmdbLists.
|
|
|
|
|
*
|
|
|
|
|
* @throws com.omertron.themoviedbapi.MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
@Ignore("Not working")
|
|
|
|
|
public void test5RemoveMovieFromList() throws MovieDbException {
|
|
|
|
|
LOG.info("removeMovieFromList");
|
|
|
|
|
String listId = "";
|
|
|
|
|
Integer movieId = null;
|
|
|
|
|
StatusCode expResult = null;
|
|
|
|
|
StatusCode result = instance.modifyMovieList(getSessionId(), listId, movieId, MethodSub.MOVIE);
|
|
|
|
|
assertEquals(expResult, result);
|
|
|
|
|
// TODO review the generated test code and remove the default call to fail.
|
|
|
|
|
fail("The test case is a prototype.");
|
|
|
|
|
private void testRemoveItem(String listId, int mediaId) throws MovieDbException {
|
|
|
|
|
LOG.info("removeItem");
|
|
|
|
|
StatusCode result = instance.removeItem(getSessionId(), listId, mediaId);
|
|
|
|
|
assertEquals("Invalid response: " + result.toString(), SC_SUCCESS_DEL, result.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Test of deleteMovieList method, of class TmdbList.
|
|
|
|
|
* Test of clear method, of class TmdbLists.
|
|
|
|
|
*
|
|
|
|
|
* @throws com.omertron.themoviedbapi.MovieDbException
|
|
|
|
|
*/
|
|
|
|
|
@Ignore("Not working")
|
|
|
|
|
public void test6DeleteMovieList() throws MovieDbException {
|
|
|
|
|
LOG.info("deleteMovieList");
|
|
|
|
|
String listId = "";
|
|
|
|
|
StatusCode expResult = null;
|
|
|
|
|
StatusCode result = instance.deleteMovieList(getSessionId(), listId);
|
|
|
|
|
assertEquals(expResult, result);
|
|
|
|
|
// TODO review the generated test code and remove the default call to fail.
|
|
|
|
|
fail("The test case is a prototype.");
|
|
|
|
|
private void testClear(String listId) throws MovieDbException {
|
|
|
|
|
LOG.info("clear");
|
|
|
|
|
StatusCode result = instance.clear(getSessionId(), listId, true);
|
|
|
|
|
assertEquals("Invalid response: " + result.toString(), SC_SUCCESS_UPD, result.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|