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
Sql2oAuthorDaoclass, implement a class namedSql2oBookDaothat implements theBookDaointerface defined in step 1.To make our DAO classes support all basic CRUD operations, add the following methods to both
AuthorDaoandBookDaointerfaces and implement them in their corresponding implementing classes (i.e.Sql2oAuthorDaoandSql2oBookDao):boolean delete(Book book) / boolean delete(Author author): when called, the record in the correspoding table withbook.isbn/author.nameis removed. If thesqlquery is successfully executed,trueis returned. If something goes wrong with query execution,DaoExceptionis thrown.boolean update(Book book)/boolean update(Author author): when called, the record in the correspoding table withbook.isbn/author.nameshould be located and get upated. As an example, ifauthor.nameis "Franz Kafka", then callingupdate(author)will result in the author withname"Franz Kafka" in theAuthorstable get updated withauthor.numOfBooksandauthor.nationalityvalues. If the sql query is successfully executed,trueis returned. If something goes wrong with query execution,DaoExceptionis thrown.info
Note that an author is updated/deleted based on its
nameproperty and a book is updated/deleted based on itsisbn. Remember,nameinAuthorstable andisbninBookstable are unique!
Write at least four different unit test cases for
Sql2oAuthorDaoin 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.javaundersrc/test/java/folder.tip
Your test class
DBDaoCRUDTest.javashould be self-sufficient, meaning that before unit tests get executed, if needed, a database withBooksandAuthorstables should be created whereAuthorstable 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/@Beforeannotations 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.