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
CreateManager_pt
LeftMenu




JSPWiki v2.2.33

[RSS]


Hide Menu

CreateDAO_pt


Difference between version 32 and version 31:

At line 183 removed 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 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 185 removed 1 line.
;:%%(color: blue)''I usually copy (open → save as) an existing test (i.e. UserDaoTest.java) and find/replace [[Uu]ser with [[Pp]erson, or whatever the name of my object is.''%%
At line 187 removed 18 lines.
[{Java2HtmlPlugin
package org.appfuse.dao;
import org.appfuse.model.Person;
import org.springframework.dao.DataAccessException;
public class PersonDaoTest extends BaseDaoTestCase {
private Person person = null;
private PersonDao dao = null;
public void setPersonDao(PersonDao dao) {
this.dao = dao;
}
}
}]
At line 266 changed 1 line.
Para começar, crie uma classe PessoaDaoTest.java no diretório test/dao/**/dao. Esta classe deve estender [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDAOTestCase.java.html], que já existe neste pacote. Esta classe pai é usada para carregar ApplicationContext do [Spring's|http://www.springframework.org] (Spring une todas as camadas), e para automaticamente carregar um arquivo .properties (ResourceBundle) que tem o mesmo nome que sua classe *Test.class. Neste exemplo, se você colocar um arquivo PessoaDAOTest.properties no mesmo diretório que PessoaDAOTest.java, este arquivo de propriedades estará disponível via uma variável “rb”.
Para começar, crie uma classe PessoaDaoTest.java no diretório test/dao/**/dao. Esta classe deve estender [BaseDaoTestCase|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDAOTestCase.java.html], sub-classe da[AbstractDependencyInjectionSpringContextTests|http://www.springframework.org/docs/api/org/springframework/test/AbstractDependencyInjectionSpringContextTests.html] do Spring que já existe neste pacote. Esta classe pai é usada para carregar ApplicationContext do [Spring's|http://www.springframework.org] (Spring une todas as camadas), e para (opcionalmente) carregar um arquivo .properties (ResourceBundle) que tem o mesmo nome que sua classe *Test.class. Neste exemplo, se você colocar um arquivo PessoaDAOTest.properties no mesmo diretório que PessoaDAOTest.java, este arquivo de propriedades estará disponível via uma variável “rb”.
At line 282 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 286 removed 5 lines.
protected void tearDown() throws Exception {
super.tearDown();
dao = null;
}
At line 294 changed 1 line.
O código que você vê acima é o que precisamos para um teste JUnit básico, que inicializa e destrói nosso PessoaDAO. O objeto “ctx” é uma referência ao ApplicationContext do Spring, o qual é inicializado em um bloco estático da classe [BaseDaoTestCase's|http://raibledesigns.com/downloads/appfuse/api/org/appfuse/dao/BaseDaoTestCase.java.html] class.
O código que você vê acima é o que precisamos para um teste JUnit básico, que inicializa e destrói nosso PessoaDAO. Spring irá usar autowiring (auto-ligamento) por tipo para chamar o método ''setPersonDao()'' e atribuir o bean "personDao" como uma dependência desta classe.

Back to CreateDAO_pt, or to the Page History.