The MailReader application manages several persistent objects. Using data access objects (DAOs) can help separate the persistence services from the business serivces.
Marvin creates a MessageDao class to see if data access objects will help manage the MailReader code. Spring supports the @PersistenceContext annotation, meaning that an EntityManager can be injected into the DAO.
He starts by taking the existing MessageTestCase and converting the heart of each test to a DAO method. In the end, the MessageDao class has methods like count, create, find, update, delete.
To prove to Ford that all the DAO work, Marvin creates a JUnit test that exercises the DAO operations automatically. Instead of setting up an EntityManager member, the test setUp retrieves the messageDao from a Spring catalog that has been updated to recognize the @PersistenceContext annotation.
|Goal||Create, retrieve, update, and delete entity objects.|
|Level||Subfunction||(User Goal, Summary, Subfunction)|
|Trigger||System needs to invoke a CRUD operation.|
|1||Copy MessageTestCase as MessageDao|
|2||Add an EntityManager setter with a @PersistenceContext annotation|
|3||Rework MessageDao tests into data access methods that use the manager field|
|4|| Update spring.xml to add an LocalEntityManagerFactoryBean, |
PersistenceAnnotationBeanPostProcessor, and MessageDao reference
|5||Copy MessageTestCase as MessageDaoTestCase and rework to utilize MessageDao|