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.
Day | Date | |
---|---|---|
Release | Thu | SEP 17 |
Due | Thu | SEP 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:
Similar to the existing
AuthorDao
, add a new interface under the same java package namedBookDao
.Similar to the existing
Sql2oAuthorDao
class, implement a class namedSql2oBookDao
that implements theBookDao
interface defined in step 1.To make our DAO classes support all basic CRUD operations, add the following methods to both
AuthorDao
andBookDao
interfaces and implement them in their corresponding implementing classes (i.e.Sql2oAuthorDao
andSql2oBookDao
):boolean delete(Book book) / boolean delete(Author author)
: when called, the record in the correspoding table withbook.isbn
/author.name
is removed. If thesql
query is successfully executed,true
is returned. If something goes wrong with query execution,DaoException
is thrown.boolean update(Book book)
/boolean update(Author author)
: when called, the record in the correspoding table withbook.isbn
/author.name
should be located and get upated. As an example, ifauthor.name
is "Franz Kafka", then callingupdate(author)
will result in the author withname
"Franz Kafka" in theAuthors
table get updated withauthor.numOfBooks
andauthor.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 itsisbn
. Remember,name
inAuthors
table andisbn
inBooks
table are unique!
Write at least four different unit test cases for
Sql2oAuthorDao
in Junit and another four forSql2oBookDao
; 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
undersrc/test/java/
folder.tip
Your test class
DBDaoCRUDTest.java
should be self-sufficient, meaning that before unit tests get executed, if needed, a database withBooks
andAuthors
tables should be created whereAuthors
table is parent ofBooks
. 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.