EJB3, Hibernate DAOs and JUnit tests plugin (beta)

This plugin generates the same files as the "EJB3 And Hibernate Daos" plugin , plus JUnit testcases for every generated daos.

Thanks to this plugin, you can directly test generated daos and have an example of how to use them.

Here is a sample generated testcase :

package com.salto.ejb3dao.test;

import junit.framework.TestCase;
import java.util.List;
import java.sql.Timestamp;

import com.salto.ejb3dao.DAOFactory;
import com.salto.ejb3dao.pojo.Person;
import com.salto.ejb3dao.PersonDAO;

/**
 * <p>Unit test for com.salto.ejb3dao.PersonDAO</p>
 * <p>Generated at Wed Feb 07 16:08:05 CET 2007</p>
 *
 * @author Salto-db Generator Ant v1.0.15 / EJB3 + Hibernate DAO + TestCases
 */
public class PersonDAOTest extends TestCase {

        private PersonDAO dao;

        private Integer existingId;

        private Person testEntityPerson;
        
        private String testName;
        
        private String testFirstName;
        
        private int testAge;
        
        private int testIdCity;
        
        
        public void setUp() throws Exception {
                setPersonDAO(DAOFactory.DEFAULT.buildPersonDAO());
                //TODO: call setExistingId() with an id that exists in database
                //TODO: call setTestPerson() with an Person instance
        }
        
        public void tearDown() {
        existingId = null;
        dao = null;
        testEntityPerson = null;
    }

        public void setPersonDAO(PersonDAO dao) {
                this.dao = dao;
        }

        public PersonDAO getPersonDAO() {
                return this.dao;
        }
        
        public void setExistingId(Integer id) {
                this.existingId = id;
        }

        public Integer getExistingId() {
                return this.existingId;
        }

        public Person getTestEntityPerson() {
                return testEntityPerson;
        }

        public void setTestEntityPerson(Person testEntityPerson) {
                this.testEntityPerson = testEntityPerson;
        }

        public void testGetById() {
                Person test = dao.getById(existingId);
        assertNotNull(test);
        }

        public void testFindAll() {
                List<Person> all = dao.findAll();
                assertNotNull(all);
                assertFalse(all.isEmpty());
        }

        public void testSaveAndRemove() {
                dao.save(testEntityPerson);
                Person test = dao.getById(testEntityPerson.getIdPerson());
        assertNotNull(testEntityPerson.getIdPerson());
        assertNotNull(test);
        dao.delete(testEntityPerson);
                test = dao.getById(testEntityPerson.getIdPerson());
        assertNull(test);
        }

        public String getTestName() {
                return testName;
        }

        public void setTestName(String testName) {
                this.testName = testName;
        }
        
        public void testFindByName() {
                List<Person> list = dao.findByName(testName);
                assertNotNull(list);
                assertFalse(list.isEmpty());
        }
        
        public String getTestFirstName() {
                return testFirstName;
        }

        public void setTestFirstName(String testFirstName) {
                this.testFirstName = testFirstName;
        }
        
        public void testFindByFirstName() {
                List<Person> list = dao.findByFirstName(testFirstName);
                assertNotNull(list);
                assertFalse(list.isEmpty());
        }
        
        public int getTestAge() {
                return testAge;
        }

        public void setTestAge(int testAge) {
                this.testAge = testAge;
        }
        
        public void testFindByAge() {
                List<Person> list = dao.findByAge(testAge);
                assertNotNull(list);
                assertFalse(list.isEmpty());
        }
        
        public int getTestIdCity() {
                return testIdCity;
        }

        public void setTestIdCity(int testIdCity) {
                this.testIdCity = testIdCity;
        }
        
        public void testFindByIdCity() {
                List<Person> list = dao.findByIdCity(testIdCity);
                assertNotNull(list);
                assertFalse(list.isEmpty());
        }
        

}