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 5.
It is not the current version, and thus it cannot be edited. Teil II: Neue Manager erzeugen - Eine Anleitung für die Erzeugung von Business Facades, die mit der Datenbank Schicht (DAOs) kommuniziert und das Transaktionsmanagement verwaltet.
About this TutorialDieses Tutorial erklärt, wie mann eine Business Facade Klaasse (Und den dazugehörigen JUnit Test) erzeugt, um mit der DAO Schicht zu kommunizieren, die wir in Teil I erzeugt haben.Im Kontext von AppFuse wird diese Klasse Manager Klasse genannt. Die hauptsächliche Aufgabe der Klasse besteht darin, die Verbindung zwischen WebLayer und DAO Schicht zu bilden. Sie unterstützt einen auch dabei, die Präsentationsschicht von der Datenbankschicht zu trennen (z.B. für Swing Anwendungen). Businesslogik der Anwendung sollte in die Manager gelegt werden.
Beginnen wir mit dem Erstellen eines neuen Manager Tests und der Manager in der Architektur von AppFuse. Inhaltsverzeichnis
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 similar functionality as the BaseDaoTestCase.
The code below is what you need for a basic JUnit test of your Manager. Unlike the DaoTest, this test uses jMock to isolate the Manager from its dependencies and make it a true "unit" test. This can be very helpful because it allows you to test your business logic w/o worrying about other dependencies. The code below simply sets up the Manger and its dependencies (as Mocks) for testing.
Now that you have the skeleton done for this class, you need to add the meat: the test methods to make sure everything works. Here's a snippet from the DAO Tutorial tutorial to help you understand what we're about to do.
Add the following methods to your PersonManagerTest.java file:
This class won't compile at this point because we have not created our PersonManager interface.
Create a new Manager to talk to the DAO [#2]First off, create a PersonManager.java interface in the src/service/**/service directory and specify the basic CRUD methods for any implementation classes. I've eliminated the JavaDocs in the class below for display purposes. The setPersonDao() method is not used in most cases - its just exists so the PersonManagerTest can set the DAO on the interface.
Now let's create a PersonManagerImpl class that implements the methods in PersonManager. To do this, create a new class in src/service/**/service/impl and name it PersonManagerImpl.java. It should extend BaseManager and implement PersonManager.
One thing to note is the setPersonDao() method. This is used by Spring to bind the PersonDao to this Manager. This is configured in the applicationContext-service.xml file. We'll get to configuring that in Step 3[3]. You should be able to compile everything now using "ant compile-service". Now you need to edit Spring's config file for our services layer so it will know about this new Manager. Configure Spring for this Manager and Transactions [#3]To notify Spring of this our PersonManager interface and its implementation, open the src/service/**/service/applicationContext-service.xml file. In here, you should see a commented out definition for the "personManager" bean. Uncomment this, or add the following to the bottom of this file.
The "parent" attribute refers to a bean definition for a TransactionProxyFactoryBean that has all the basic transaction attributes set. Run the ManagerTest [#4]Save all your edited files and try running ant test-service -Dtestcase=PersonManager. Yeah Baby, Yeah:
BUILD SUCCESSFUL The files that were modified and added to this point are available for download. Next Up: Part III: Creating Actions and JSPs - A HowTo for creating Actions and JSPs in the AppFuse architecture.
|