Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
34   181   7   5.67
2   91   0.21   6
6     1.17  
1    
 
  TestHibernateGenericReadOnlyDao       Line # 38 34 0% 7 0 100% 1.0
 
  (5)
 
1    //----------------------------------------------------------------------
2    //
3    // PerfectJPattern: "Design patterns are good but components are better!"
4    // TestHibernateReadOnlyDao.java Copyright (c) 2009 Giovanni Azua Garcia
5    // bravegag@hotmail.com
6    //
7    // This program is free software; you can redistribute it and/or
8    // modify it under the terms of the GNU General Public License
9    // as published by the Free Software Foundation; either version 3
10    // of the License, or (at your option) any later version.
11    //
12    // This program is distributed in the hope that it will be useful,
13    // but WITHOUT ANY WARRANTY; without even the implied warranty of
14    // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    // GNU General Public License for more details.
16    //
17    // You should have received a copy of the GNU General Public License
18    // along with this program; if not, see <http://www.gnu.org/licenses/>.
19    //
20    //----------------------------------------------------------------------
21    package org.perfectjpattern.jee.integration.dao;
22   
23    import java.util.*;
24   
25    import junit.framework.*;
26   
27    import org.perfectjpattern.example.datamodel.*;
28    import org.perfectjpattern.jee.api.integration.dao.*;
29    import org.slf4j.*;
30   
31    /**
32    * Test Suite for the {@link HibernateGenericDao} implementation
33    *
34    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
35    * @version $Revision: 1.0 $ $Date: Nov 26, 2007 9:29:34 PM $
36    */
37    public
 
38    class TestHibernateGenericReadOnlyDao
39    extends TestCase
40    {
41    //------------------------------------------------------------------------
42    // public
43    //------------------------------------------------------------------------
 
44  1 toggle public void
45    testContains()
46    {
47    // create generic read-only Dao instance
48  1 IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory.
49    getInstance().createReadOnlyDao(Person.class);
50   
51    // contains
52  1 List<Person> myPersons = myPersonDao.findAll();
53  1 boolean myContains = myPersonDao.contains(myPersons.get(0));
54   
55    // run assertions
56  1 assertTrue("contains did not work as expected", myContains);
57    }
58   
59    //------------------------------------------------------------------------
 
60  1 toggle public void
61    testCount()
62    {
63    // create generic read-only Dao instance
64  1 IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory.
65    getInstance().createReadOnlyDao(Person.class);
66   
67    // contains
68  1 int myCount = myPersonDao.count();
69   
70    // run assertions
71  1 assertEquals("count did not work as expected", 2, myCount);
72    }
73   
74    //------------------------------------------------------------------------
 
75  1 toggle public void
76    testFindById()
77    {
78    // create generic read-only Dao instance
79  1 IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory.
80    getInstance().createReadOnlyDao(Person.class);
81   
82    // find by Id
83  1 Person myPedro = myPersonDao.findById(thePedro.getId());
84   
85    // run assertions
86  1 assertNotNull("findById did not find the expected Person", myPedro);
87  1 assertEquals("findById did not find the expected Person", "Pedro",
88    myPedro.getName());
89    }
90   
91    //------------------------------------------------------------------------
 
92  1 toggle public void
93    testFindAll()
94    {
95    // create generic read-only Dao instance
96  1 IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory.
97    getInstance().createReadOnlyDao(Person.class);
98   
99    // find All
100  1 List<Person> myPersons = myPersonDao.findAll();
101   
102    // run assertions
103  1 assertNotNull("findAll did not find the expected Persons", myPersons);
104  1 assertEquals("findAll did not find the expected Persons", 2, myPersons.
105    size());
106    }
107   
108    //------------------------------------------------------------------------
 
109  1 toggle public void
110    testFindByExample()
111    {
112    // create generic read-only Dao instance
113  1 IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory.
114    getInstance().createReadOnlyDao(Person.class);
115   
116    // prepare example
117  1 Person myExample = new Person();
118  1 myExample.setName("Pedro");
119  1 myExample.setAge(45);
120   
121    // find by example
122  1 List<Person> myPersons = myPersonDao.findByExample(myExample);
123   
124    // run assertions
125  1 assertNotNull("findByExample did not find the expected Persons",
126    myPersons);
127  1 assertEquals("findByExample did not find the expected Persons", 1,
128    myPersons.size());
129  1 assertEquals("findByExample did not find the expected Persons",
130    "Pedro", myPersons.get(0).getName());
131   
132    // find by example excluding properties
133  1 myExample.setAge(-1);
134  1 myPersons = myPersonDao.findByExample(myExample, "age");
135   
136    // run assertions
137  1 assertNotNull("findByExample did not find the expected Persons",
138    myPersons);
139  1 assertEquals("findByExample did not find the expected Persons", 1,
140    myPersons.size());
141  1 assertEquals("findByExample did not find the expected Persons",
142    "Pedro", myPersons.get(0).getName());
143    }
144   
145    //------------------------------------------------------------------------
146    // protected
147    //------------------------------------------------------------------------
 
148  5 toggle @Override
149    protected void
150    setUp()
151    throws Exception
152    {
153  5 super.setUp();
154   
155    // create the two example Persons
156  5 IGenericDao<Long, Person> myPersonDao = HibernateDaoFactory.
157    getInstance().createDao(Person.class);
158   
159  5 if (myPersonDao.count() == 0)
160    {
161  1 myPersonDao.create(thePedro);
162  1 myPersonDao.create(theManuela);
163   
164  1 myPersonDao.getTransaction().commit();
165    }
166    }
167   
168    //------------------------------------------------------------------------
169    // members
170    //------------------------------------------------------------------------
171    // CHECKSTYLE:OFF
172    private static final Person thePedro = new Person("Pedro", 45);
173    private static final Person theManuela = new Person("Manuela", 23);
174    // CHECKSTYLE:ON
175   
176    /**
177    * Provides logging services for this class.
178    */
179    @SuppressWarnings("unused")
180    private final Logger theLogger = LoggerFactory.getLogger(this.getClass());
181    }