Raible's Wiki
Raible Designs AppFuseHomepage- Korean - Chinese - Italian - Japanese QuickStart Guide User Guide Tutorials Other ApplicationsStruts ResumeSecurity Example Struts Menu
Set your name in
UserPreferences
Referenced by
JSPWiki v2.2.33
Hide Menu |
This is version 41.
It is not the current version, and thus it cannot be edited. Part II: Creating new Managers - A HowTo for creating Business Delegates that talk to the database tier (DAOs) and the web tier (Struts Actions).
About this TutorialThis tutorial will show you how to create a Business Delegate class (and a JUnit Test) to talk to the DAO we created in Part I.In the context of AppFuse, this is called a Manager class. It's main responsibility is converting backend data (POJOs) into front-end data (Struts ActionForms). The main reason I even use Managers, rather than just calling the DAOs directly is testability. It's nice to be able to populate a Form manually (in the test) and call the DAO to persist it, and verify the database gets the proper results. The Business Delegate pattern from Sun says that these objects are useful for de-coupling your presentation layer from your database layer (i.e. for Swing apps). Managers should also be where you put any business logic for your application.
Let's get started by creating a new ManagerTest and Manager in AppFuse's architecture. Table of Contents
Create a new ManagerTest to run JUnit tests on the Manager [#1]In Part I, we created a Person object and PersonDao - so let's continue developing this entity. First, let's create a JUnit test for the PersonManager. Create PersonManagerTest in the test/service/**/service directory. We'll want to test the same basic methods (get, save, remove) that our DAO has.
This class should extend BaseManagerTestCase, which already exists in the service package. The parent class (BaseManagerTestCase) serves the same functionality as the BaseDaoTestCase - to load a properties file that has the same name as your *Test.class, as well as to initialize Spring's ApplicationContext.
The code below is what we need for a basic JUnit test of our Managers. It created and destroys our PersonManager. The
|