Raible's Wiki

Raible Designs
Wiki Home
News
Recent Changes

AppFuse

Homepage
  - Korean
  - Chinese
  - Italian
  - Japanese

QuickStart Guide
  - Chinese
  - French
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish
  - Japanese

User Guide
  - Korean
  - Chinese

Tutorials
  - Chinese
  - German
  - Italian
  - Korean
  - Portuguese
  - Spanish

FAQ
  - Korean

Latest Downloads

Other Applications

Struts Resume
Security Example
Struts Menu

Set your name in
UserPreferences


Referenced by
Articles
Articles_pt
CreateDAO_es
CreateDAO_pt
CreateDAO_sp
CreateDAOiBATIS
CreateManager
CreateManager_es
CreateManager_ko
CreateManager_zh
...and 3 more




JSPWiki v2.2.33

[RSS]


Hide Menu

CreateDAO


Difference between version 136 and version 135:

At line 183 changed 1 line.
To start, create a {{PersonDaoTest.java}} class in the {{test/dao/**/dao}} directory. This class should extend [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html], a subclass of JUnit's [TestCase|http://junit.sourceforge.net/javadoc/junit/framework/TestCase.html] which already exists in this package. This parent class is used to load [Spring's|http://www.springframework.org] ApplicationContext (since Spring binds the layers together), and for (optionally) loading a .properties file (ResourceBundle) that has the same name as your {{*Test.class}}. In this example, if you put a {{PersonDaoTest.properties}} file in the same directory as {{PersonDaoTest.java}}, this file's properties will be available via an "rb" variable.
To start, create a {{PersonDaoTest.java}} class in the {{test/dao/**/dao}} directory. This class should extend [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html], a subclass of Spring's [AbstractDependencyInjectionSpringContextTests|http://www.springframework.org/docs/api/org/springframework/test/AbstractDependencyInjectionSpringContextTests.html] which already exists in this package. This parent class is used to load [Spring's|http://www.springframework.org] ApplicationContext (since Spring binds the layers together), and for (optionally) loading a .properties file (ResourceBundle) that has the same name as your {{*Test.class}}. In this example, if you put a {{PersonDaoTest.properties}} file in the same directory as {{PersonDaoTest.java}}, this file's properties will be available via an "rb" variable.
At line 199 changed 3 lines.
protected void setUp() throws Exception {
super.setUp();
dao = (PersonDao) ctx.getBean("personDao");
public void setPersonDao(PersonDao dao) {
this.dao = dao;
At line 203 removed 5 lines.
protected void tearDown() throws Exception {
super.tearDown();
dao = null;
}
At line 211 changed 1 line.
The code you see above is what we need for a basic JUnit test that initializes and destroys our PersonDao. The "ctx" object is a reference to Spring's ApplicationContext, which is initialized in a static block of the [BaseDaoTestCase's|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html] class.
The code you see above is what we need for a basic Spring integration test that initializes and destroys our PersonDao. Spring will use autowiring byType to call the ''setPersonDao()'' method and set the "personDao" bean as a dependency of this class.

Back to CreateDAO, or to the Page History.