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 3.
It is not the current version, and thus it cannot be edited. Parte II: Creating new Managers - Instrucciones para crear Fachadas de Logica de Negocios (Business Facades) que interaccionan con la capa de acceso a datos (DAO) y manejan todo lo relacionado con la gestion de transacciones.
Sobre este tutorialEste tutorial te mostrara como crear clases del tipo Business Facada (asi como test unitario ) para interactuar ,con la capa DAO creada in Part I.En el contexto de AppFuse, crearemos lo que se llama una clase Manager. Su principal objetivo es la de servir de puente entre la capa de persistencia DAO y la capa de presentacion. Tambien permite aislar la capa de presentacion de la capa de persistencia(i.e. para aplicaciones Swing ). Ademas, contienen toda la logica de la aplicacion.
Vamos a empezar creando una clase ManagerTest y otra clase Manager en la arquitectura de AppFuse. Tabla de Contenidos
Crear una nueva clase ManagerTest para ejecutar tests JUnit con relacion a la clase Manager. [#1]En Part I,creamos una clase Person y PersonDao - por lo que vamos a seguir desarrollando esta entidad. Primero, crearemos una nueva clase de prueba JUnit para probar la clase PersonManager. Crea la clase PersonManagerTest en el directorio test/service/**/service. Vamos a probar los metodos basicos (leer, anadir, eliminar) que contiene nuestra clase.
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.
|