Homework 2

You will be completing the implementation of persistence with SQLite database for MyBooksApp as well as writing some unit tests to make sure your implementations work as expected.

DayDate
ReleaseThuSEP 17
DueThuSEP 24 @ 11pm (EST)

Task

Grab a copy of the MyBookApp repo available under jhu-oose github organization. The current implemetation contains a couple of data persistence functionalities, namely add and listAll, for Author class under src/main/java/persistence folder. Your task is to:

  1. Similar to the existing AuthorDao, add a new interface under the same java package named BookDao.

  2. Similar to the existing Sql2oAuthorDao class, implement a class named Sql2oBookDao that implements the BookDao interface defined in step 1.

  3. To make our DAO classes support all basic CRUD operations, add the following methods to both AuthorDao and BookDao interfaces and implement them in their corresponding implementing classes (i.e. Sql2oAuthorDao and Sql2oBookDao):

    1. boolean delete(Book book) / boolean delete(Author author): when called, the record in the correspoding table with book.isbn/author.name is removed. If the sql query is successfully executed, true is returned. If something goes wrong with query execution, DaoException is thrown.
    2. boolean update(Book book) / boolean update(Author author): when called, the record in the correspoding table with book.isbn/author.name should be located and get upated. As an example, if author.name is "Franz Kafka", then calling update(author) will result in the author with name "Franz Kafka" in the Authors table get updated with author.numOfBooks and author.nationality values. If the sql query is successfully executed, true is returned. If something goes wrong with query execution, DaoException is thrown.
      info

      Note that an author is updated/deleted based on its name property and a book is updated/deleted based on its isbn. Remember, name in Authors table and isbn in Books table are unique!

  4. Write at least four different unit test cases for Sql2oAuthorDao in Junit and another four for Sql2oBookDao; that is to write at least one junit test case for each of the CRUD operations for each of the classes. Feel free to write more (creative!) test cases.

    info

    Write your unit tests in a new java class named DBDaoCRUDTest.java under src/test/java/ folder.

    tip

    Your test class DBDaoCRUDTest.java should be self-sufficient, meaning that before unit tests get executed, if needed, a database with Books and Authors tables should be created where Authors table is parent of Books. Also, again if needed, you may need to insert few rows into these tables before running tests. Hint: Method(s) with @BeforeClass/@Before annotations can be helpful to set things up the way you want before tests are executed.

caution

If you had copied MyBooksApp repo before, make sure to get a fresh copy to start with as there have been a few minor adjustments to the code!

Submission

In your group repo, create a new folder named homeworks. Under homeworks, create a subfolder named hw2. Push all your files under homeworks/hw2 folder. Create a README.md in homeworks/hw2 folder and include in it all the assumptions made, work done, etc. When finished, zip the hw2 folder and submit it as a single file to Gradescope.

info

Note that moving forward with homeworks, each group makes one submission.