diff --git a/LOG.md b/LOG.md index 1fedc6c..85a680e 100644 --- a/LOG.md +++ b/LOG.md @@ -202,3 +202,4 @@ Ahan: Converted postgresql data to json files, finished CommentStubDB.java implementation and added more tests for CommentDaoImpl.java. Also updated ReadMe/ Wiki with updated feature list and latest screenshots. Eric: Added ability for user to navigate to comic book pgae by clicking on comic book in their reading / read table in profile Oscar: Finished implementing cancel button for "About Me" section and created test case for updating the field in database. + Hashir: Final touches for submission criteria for ITR2 + adding more tests for stories and integration + refactoring diff --git a/design_documents/planning/ITR2_Updated_Plan_V2.pdf b/design_documents/planning/ITR2_Updated_Plan_V2.pdf new file mode 100644 index 0000000..15d3828 Binary files /dev/null and b/design_documents/planning/ITR2_Updated_Plan_V2.pdf differ diff --git a/src/main/java/org/longbox/Main.java b/src/main/java/org/longbox/Main.java index 858de14..1ffacd5 100644 --- a/src/main/java/org/longbox/Main.java +++ b/src/main/java/org/longbox/Main.java @@ -12,49 +12,5 @@ public class Main { public static void main(String[] args) { - // This entry point is used to test methods informally and - // build stub database entries for the JSON files used with GSON - // sample code is shown below in the two comment blocks. -/* UserDaoImpl u = new UserDaoImpl(); - ComicBookDaoImpl cb = new ComicBookDaoImpl(); - - ComicBook cbdto = cb.getComicBookById(5); - - User user; - - ComicBookFinishedListDaoImpl finishedListDao = new ComicBookFinishedListDaoImpl();*/ - -/* try { - user = u.getUserById(2); - System.out.println(user); - } catch (UserIDDoesNotExistException e) { - e.printStackTrace(); - throw new RuntimeException(e); - } - - boolean success; - - - try { - success = finishedListDao.saveToFinished(user, cbdto); - System.out.println(success); - } catch (UserIDDoesNotExistException e) { - e.printStackTrace(); - throw new RuntimeException(e); - }*/ - -/* int result; - - try { - finishedListDao.removeFromFinished(Long.valueOf(2),Long.valueOf(3)); - } - catch (Exception e) { - e.printStackTrace(); - throw new RuntimeException(); - } - - System.out.println(finishedListDao.getUsersFinishedList(Long.valueOf(2)));*/ - - } } \ No newline at end of file diff --git a/src/main/java/org/longbox/config/HibernateUtils.java b/src/main/java/org/longbox/config/HibernateUtils.java index b4c672c..e8dee6d 100644 --- a/src/main/java/org/longbox/config/HibernateUtils.java +++ b/src/main/java/org/longbox/config/HibernateUtils.java @@ -22,5 +22,4 @@ public static SessionFactory getSessionFactory() { } return sessionFactory; } - } diff --git a/src/main/java/org/longbox/persistence/dao/ComicBookFavouritesListDao.java b/src/main/java/org/longbox/persistence/dao/ComicBookFavouritesListDao.java index 8746c3c..f18ed53 100644 --- a/src/main/java/org/longbox/persistence/dao/ComicBookFavouritesListDao.java +++ b/src/main/java/org/longbox/persistence/dao/ComicBookFavouritesListDao.java @@ -13,6 +13,8 @@ public interface ComicBookFavouritesListDao { void removeFromFavorites(long userId, long comicBookId); + boolean doesRecordExist(Long userId, Long comicBookId); + List getFavoritesByUser(long userId); List getUsersByComicBook(long comicBookId); diff --git a/src/main/java/org/longbox/persistence/dao/ComicBookFavouritesListDaoImpl.java b/src/main/java/org/longbox/persistence/dao/ComicBookFavouritesListDaoImpl.java index a3f4ae9..028d4ba 100644 --- a/src/main/java/org/longbox/persistence/dao/ComicBookFavouritesListDaoImpl.java +++ b/src/main/java/org/longbox/persistence/dao/ComicBookFavouritesListDaoImpl.java @@ -82,6 +82,16 @@ public void removeFromFavorites(long userId, long comicBookId) { } } + public boolean doesRecordExist(Long userId, Long comicBookId) { + Session session = sessionFactory.openSession(); + Query query = session.createQuery( + "SELECT COUNT(*) FROM ComicBookFavoritesList c WHERE c.user.id = :userId AND c.comicBook.id = :comicBookId", Long.class); + query.setParameter("userId", userId); + query.setParameter("comicBookId", comicBookId); + Long count = query.uniqueResult(); + return count != null && count > 0; + } + @Override public List getFavoritesByUser(long userId) { // Implement retrieving favorite comic books for a given user from the database diff --git a/src/main/java/org/longbox/persistence/stubdatabase/ComicBookFavoritesListStubDb.java b/src/main/java/org/longbox/persistence/stubdatabase/ComicBookFavoritesListStubDb.java index 3bd8270..57137e9 100644 --- a/src/main/java/org/longbox/persistence/stubdatabase/ComicBookFavoritesListStubDb.java +++ b/src/main/java/org/longbox/persistence/stubdatabase/ComicBookFavoritesListStubDb.java @@ -46,6 +46,11 @@ public void removeFromFavorites(long userId, long comicBookId) { serializeStubData(); } + @Override + public boolean doesRecordExist(Long userId, Long comicBookId) { + return false; + } + @Override public List getFavoritesByUser(long userId) { return null; diff --git a/src/main/java/org/longbox/persistence/stubdatabase/ComicBookFinishedListStubDb.java b/src/main/java/org/longbox/persistence/stubdatabase/ComicBookFinishedListStubDb.java index 23f6b24..ca082ae 100644 --- a/src/main/java/org/longbox/persistence/stubdatabase/ComicBookFinishedListStubDb.java +++ b/src/main/java/org/longbox/persistence/stubdatabase/ComicBookFinishedListStubDb.java @@ -18,6 +18,8 @@ import java.io.PrintStream; import java.lang.reflect.Type; import java.util.List; +import java.util.Objects; + @Getter @Setter public class ComicBookFinishedListStubDb implements ComicBookFinishedListDao, JsonConvertor { @@ -37,7 +39,7 @@ public void saveToFinished(Long userId, Long comicBookId) throws UserIDDoesNotEx public void removeFromFinished(Long userId, Long comicBookId) { List finishedList = deserializeStubData(ABSOLUTE_FILE_PATH); for (int i = 0; i < finishedList.size(); i++) { - if (finishedList.get(i).getUserId() == userId && finishedList.get(i).getComicBookId() == comicBookId) { + if (Objects.equals(finishedList.get(i).getUserId(), userId) && Objects.equals(finishedList.get(i).getComicBookId(), comicBookId)) { finishedList.remove(i); } } @@ -47,6 +49,12 @@ public void removeFromFinished(Long userId, Long comicBookId) { @Override public boolean doesRecordExist(Long userId, Long comicBookId) { + List finishedList = deserializeStubData(ABSOLUTE_FILE_PATH); + for (ComicBookListItemFinishedDto record : finishedList) { + if (Objects.equals(record.getUserId(), userId) && Objects.equals(record.getComicBookId(), comicBookId)) { + return true; + } + } return false; } diff --git a/src/main/java/org/longbox/persistence/stubdatabase/UserStubDbTest.java b/src/main/java/org/longbox/persistence/stubdatabase/UserStubDbTest.java new file mode 100644 index 0000000..1b1433c --- /dev/null +++ b/src/main/java/org/longbox/persistence/stubdatabase/UserStubDbTest.java @@ -0,0 +1,4 @@ +package org.longbox.persistence.stubdatabase; + +public class UserStubDbTest { +} diff --git a/src/main/resources/ComicBookReadingListStubDb.json b/src/main/resources/ComicBookReadingListStubDb.json index cc4243c..3362aa6 100644 --- a/src/main/resources/ComicBookReadingListStubDb.json +++ b/src/main/resources/ComicBookReadingListStubDb.json @@ -1,19 +1,97 @@ -[{"user_id":6,"comic_book_id":1,"date_started":"2024-03-10T18:08:54.959"}, -{"user_id":6,"comic_book_id":10,"date_started":"2024-03-10T18:09:11.459"}, -{"user_id":6,"comic_book_id":21,"date_started":"2024-03-10T18:09:24.145"}, -{"user_id":6,"comic_book_id":27,"date_started":"2024-03-10T18:09:28.183"}, -{"user_id":1,"comic_book_id":5,"date_started":"2024-03-10T18:10:02.415"}, -{"user_id":1,"comic_book_id":19,"date_started":"2024-03-10T18:10:22.265"}, -{"user_id":1,"comic_book_id":24,"date_started":"2024-03-10T18:10:28.782"}, -{"user_id":1,"comic_book_id":35,"date_started":"2024-03-10T18:10:44.147"}, -{"user_id":4,"comic_book_id":5,"date_started":"2024-03-10T18:11:25.824"}, -{"user_id":4,"comic_book_id":16,"date_started":"2024-03-10T18:11:34.679"}, -{"user_id":4,"comic_book_id":24,"date_started":"2024-03-10T18:11:38.495"}, -{"user_id":4,"comic_book_id":33,"date_started":"2024-03-10T18:11:53.08"}, -{"user_id":2,"comic_book_id":15,"date_started":"2024-03-10T18:12:57.025"}, -{"user_id":2,"comic_book_id":22,"date_started":"2024-03-10T18:13:00.802"}, -{"user_id":2,"comic_book_id":8,"date_started":"2024-03-10T18:13:15.79"}, -{"user_id":3,"comic_book_id":7,"date_started":"2024-03-10T18:13:55.67"}, -{"user_id":3,"comic_book_id":18,"date_started":"2024-03-10T18:14:05.857"}, -{"user_id":3,"comic_book_id":25,"date_started":"2024-03-10T18:14:13.846"}, -{"user_id":3,"comic_book_id":31,"date_started":"2024-03-10T18:14:16.45"}] \ No newline at end of file +[ + { + "user_id": 6, + "comic_book_id": 1, + "date_started": "2024-03-10T18:08:54.959" + }, + { + "user_id": 6, + "comic_book_id": 10, + "date_started": "2024-03-10T18:09:11.459" + }, + { + "user_id": 6, + "comic_book_id": 21, + "date_started": "2024-03-10T18:09:24.145" + }, + { + "user_id": 6, + "comic_book_id": 27, + "date_started": "2024-03-10T18:09:28.183" + }, + { + "user_id": 1, + "comic_book_id": 5, + "date_started": "2024-03-10T18:10:02.415" + }, + { + "user_id": 1, + "comic_book_id": 19, + "date_started": "2024-03-10T18:10:22.265" + }, + { + "user_id": 1, + "comic_book_id": 24, + "date_started": "2024-03-10T18:10:28.782" + }, + { + "user_id": 1, + "comic_book_id": 35, + "date_started": "2024-03-10T18:10:44.147" + }, + { + "user_id": 4, + "comic_book_id": 5, + "date_started": "2024-03-10T18:11:25.824" + }, + { + "user_id": 4, + "comic_book_id": 16, + "date_started": "2024-03-10T18:11:34.679" + }, + { + "user_id": 4, + "comic_book_id": 24, + "date_started": "2024-03-10T18:11:38.495" + }, + { + "user_id": 4, + "comic_book_id": 33, + "date_started": "2024-03-10T18:11:53.08" + }, + { + "user_id": 2, + "comic_book_id": 15, + "date_started": "2024-03-10T18:12:57.025" + }, + { + "user_id": 2, + "comic_book_id": 22, + "date_started": "2024-03-10T18:13:00.802" + }, + { + "user_id": 2, + "comic_book_id": 8, + "date_started": "2024-03-10T18:13:15.79" + }, + { + "user_id": 3, + "comic_book_id": 7, + "date_started": "2024-03-10T18:13:55.67" + }, + { + "user_id": 3, + "comic_book_id": 18, + "date_started": "2024-03-10T18:14:05.857" + }, + { + "user_id": 3, + "comic_book_id": 25, + "date_started": "2024-03-10T18:14:13.846" + }, + { + "user_id": 3, + "comic_book_id": 31, + "date_started": "2024-03-10T18:14:16.45" + } +] \ No newline at end of file diff --git a/src/test/java/org/longbox/integration/persistence/dao/ComicBookFavoritesListDaoImplTest.java b/src/test/java/org/longbox/integration/persistence/dao/ComicBookFavoritesListDaoImplTest.java new file mode 100644 index 0000000..0cde7a3 --- /dev/null +++ b/src/test/java/org/longbox/integration/persistence/dao/ComicBookFavoritesListDaoImplTest.java @@ -0,0 +1,48 @@ +package org.longbox.integration.persistence.dao; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.longbox.businesslogic.exception.UserIDDoesNotExistException; +import org.longbox.persistence.dao.ComicBookFavouritesListDaoImpl; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ComicBookFavoritesListDaoImplTest { + + ComicBookFavouritesListDaoImpl favouritesListDao; + + @BeforeEach + void setup() { + favouritesListDao = new ComicBookFavouritesListDaoImpl(); + favouritesListDao.removeFromFavorites(5L,30L); + } + + @Test + void saveToFavoritesTest() { + try { + favouritesListDao.removeFromFavorites(6L,20L); + favouritesListDao.saveToFavorites(6L,20L); + } catch (UserIDDoesNotExistException e) { + throw new RuntimeException(e); + } + assertTrue(favouritesListDao.doesRecordExist(6L,20L)); + } + + @Test + void removeFromFavoritesTest() { + try { + favouritesListDao.saveToFavorites(5L,30L); + favouritesListDao.removeFromFavorites(5L,30L); + } catch (UserIDDoesNotExistException e) { + throw new RuntimeException(e); + } + assertFalse(favouritesListDao.doesRecordExist(5L,30L)); + } + + @Test + void doesRecordExistTest() { + assertFalse(favouritesListDao.doesRecordExist(5L,30L)); + } + +} diff --git a/src/test/java/org/longbox/integration/persistence/dao/ComicBookFinishedListDaoImplTest.java b/src/test/java/org/longbox/integration/persistence/dao/ComicBookFinishedListDaoImplTest.java new file mode 100644 index 0000000..2770fa4 --- /dev/null +++ b/src/test/java/org/longbox/integration/persistence/dao/ComicBookFinishedListDaoImplTest.java @@ -0,0 +1,70 @@ +package org.longbox.integration.persistence.dao; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.longbox.businesslogic.exception.UserIDDoesNotExistException; +import org.longbox.persistence.dao.ComicBookFinishedListDaoImpl; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ComicBookFinishedListDaoImplTest { + ComicBookFinishedListDaoImpl finishedListDao; + + @BeforeEach + void setup() { + finishedListDao = new ComicBookFinishedListDaoImpl(); + } + + /* + * This test should always pass + * The first run will not have an exception + * The second run will not insert as it is already inserted but insertion will pass + */ + @Test + void saveToFinishedTest() { + Long userId = 1L; + Long comicId = 1L; + try { + finishedListDao.removeFromFinished(userId,comicId); + finishedListDao.saveToFinished(userId, comicId); + } catch (UserIDDoesNotExistException e) { + throw new RuntimeException(e); + } + assertTrue(finishedListDao.doesRecordExist(userId,comicId)); + } + + /* + * This test should always pass + * The first run will not have an exception + * The second run will not insert as it is already inserted but insertion will pass + */ + @Test + void removeFromFinishedTest() { + Long userId = 1L; + Long comicId = 1L; + try { + finishedListDao.saveToFinished(userId, comicId); + finishedListDao.removeFromFinished(userId,comicId); + } catch (UserIDDoesNotExistException e) { + throw new RuntimeException(e); + } + assertFalse(finishedListDao.doesRecordExist(userId,comicId)); + } + + @Test + void removeFromFinishedListNoRecord() { + Long userId = 20L; + Long comicId = 100L; + finishedListDao.removeFromFinished(userId,comicId); + assertTrue(true); + } + + @Test + void doesRecordExistNoRecord() { + Long userId = 20L; + Long comicId = 100L; + assertFalse(finishedListDao.doesRecordExist(userId,comicId)); + } + +} diff --git a/src/test/java/org/longbox/integration/persistence/dao/ComicBookReadingListDaoImplTest.java b/src/test/java/org/longbox/integration/persistence/dao/ComicBookReadingListDaoImplTest.java new file mode 100644 index 0000000..7a4b90e --- /dev/null +++ b/src/test/java/org/longbox/integration/persistence/dao/ComicBookReadingListDaoImplTest.java @@ -0,0 +1,68 @@ +package org.longbox.integration.persistence.dao; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.longbox.businesslogic.exception.UserIDDoesNotExistException; +import org.longbox.persistence.dao.ComicBookReadingListDaoImpl; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class ComicBookReadingListDaoImplTest { + ComicBookReadingListDaoImpl readingListDao; + + @BeforeEach + void setup() { + readingListDao = new ComicBookReadingListDaoImpl(); + } + + /* + * This test should always pass + * The first run will not have an exception + * The second run will not insert as it is already inserted but insertion will pass + */ + @Test + void saveToReadingTest() { + Long userId = 1L; + Long comicId = 1L; + try { + readingListDao.removeFromReading(userId,comicId); + readingListDao.saveToReading(userId, comicId); + } catch (UserIDDoesNotExistException e) { + throw new RuntimeException(e); + } + assertTrue(readingListDao.doesRecordExist(userId,comicId)); + } + + /* + * This test should always pass + * The first run will not have an exception + * The second run will not insert as it is already inserted but insertion will pass + */ + @Test + void removeFromReadingTest() { + Long userId = 1L; + Long comicId = 1L; + try { + readingListDao.saveToReading(userId, comicId); + readingListDao.removeFromReading(userId,comicId); + } catch (UserIDDoesNotExistException e) { + throw new RuntimeException(e); + } + assertFalse(readingListDao.doesRecordExist(userId,comicId)); + } + + @Test + void removeFromReadingNoRecord() { + Long userId = 20L; + Long comicId = 100L; + readingListDao.removeFromReading(userId, comicId); + assertTrue(true); + } + + @Test + void doesRecordExistNoRecord() { + Long userId = 20L; + Long comicId = 100L; + assertFalse(readingListDao.doesRecordExist(userId, comicId)); + } +} diff --git a/src/test/java/org/longbox/unit/config/HibernateUtilsTest.java b/src/test/java/org/longbox/unit/config/HibernateUtilsTest.java deleted file mode 100644 index d31b96d..0000000 --- a/src/test/java/org/longbox/unit/config/HibernateUtilsTest.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.longbox.unit.config; - -public class HibernateUtilsTest { -} diff --git a/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookFavoritesListStubDbTest.java b/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookFavoritesListStubDbTest.java new file mode 100644 index 0000000..f6f857d --- /dev/null +++ b/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookFavoritesListStubDbTest.java @@ -0,0 +1,4 @@ +package org.longbox.unit.persistence.stubdatabase; + +public class ComicBookFavoritesListStubDbTest { +} diff --git a/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookFinishedListStubDbTest.java b/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookFinishedListStubDbTest.java new file mode 100644 index 0000000..e7c889b --- /dev/null +++ b/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookFinishedListStubDbTest.java @@ -0,0 +1,23 @@ +package org.longbox.unit.persistence.stubdatabase; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.longbox.persistence.stubdatabase.ComicBookFinishedListStubDb; + +import static org.junit.jupiter.api.Assertions.assertFalse; + +public class ComicBookFinishedListStubDbTest { + + ComicBookFinishedListStubDb finishedListStubDb; + + @BeforeEach + void setup() { + finishedListStubDb = new ComicBookFinishedListStubDb(); + } + + @Test + void doesRecordExist() { + assertFalse(finishedListStubDb.doesRecordExist(100L,200L)); + } + +} diff --git a/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookReadingListStubDbTest.java b/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookReadingListStubDbTest.java new file mode 100644 index 0000000..54db41e --- /dev/null +++ b/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookReadingListStubDbTest.java @@ -0,0 +1,6 @@ +package org.longbox.unit.persistence.stubdatabase; + +public class ComicBookReadingListStubDbTest { + + +} diff --git a/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookStubDbTest.java b/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookStubDbTest.java index 4eaa3ba..610e83d 100644 --- a/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookStubDbTest.java +++ b/src/test/java/org/longbox/unit/persistence/stubdatabase/ComicBookStubDbTest.java @@ -1,4 +1,18 @@ package org.longbox.unit.persistence.stubdatabase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.longbox.persistence.stubdatabase.ComicBookStubDb; + +import static org.junit.jupiter.api.Assertions.assertEquals; + public class ComicBookStubDbTest { + + ComicBookStubDb comicBookStubDb; + + @BeforeEach + void setup() { + comicBookStubDb = new ComicBookStubDb(); + } + } diff --git a/src/test/java/org/longbox/unit/persistence/stubdatabase/CommentStubDbTest.java b/src/test/java/org/longbox/unit/persistence/stubdatabase/CommentStubDbTest.java new file mode 100644 index 0000000..574c0ac --- /dev/null +++ b/src/test/java/org/longbox/unit/persistence/stubdatabase/CommentStubDbTest.java @@ -0,0 +1,4 @@ +package org.longbox.unit.persistence.stubdatabase; + +public class CommentStubDbTest { +}