Clover Coverage Report - perfectjpattern(Aggregated)
Coverage timestamp: Sat Feb 28 2009 14:35:07 CET
46   170   6   7.67
0   102   0.13   6
6     1  
1    
 
  TestSpringGenericDao       Line # 37 46 0% 6 0 100% 1.0
 
  (4)
 
1    //----------------------------------------------------------------------
2    //
3    // PerfectJPattern: "Design patterns are good but components are better!"
4    // TestSpringGenericDao.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 org.perfectjpattern.example.datamodel.*;
26    import org.perfectjpattern.jee.api.integration.dao.*;
27    import org.slf4j.*;
28    import org.springframework.test.*;
29   
30    /**
31    * Test Suite for the {@link SpringGenericDao} implementation
32    *
33    * @author <a href="mailto:bravegag@hotmail.com">Giovanni Azua</a>
34    * @version $ $Date: Nov 6, 2008 2:20:15 PM $
35    */
36    public
 
37    class TestSpringGenericDao
38    extends AbstractTransactionalSpringContextTests
39    {
40    //------------------------------------------------------------------------
41    // public
42    //------------------------------------------------------------------------
 
43  1 toggle public void
44    testFindByName()
45    {
46    // create Generic DAO instance
47  1 IPersonDao myPersonDao = LocalDaoFactory.getInstance().
48    createPersonDao();
49   
50    // create fixture Person instances
51  1 Person myErnesto = new Person("Ernesto", 35);
52  1 myPersonDao.create(myErnesto);
53  1 Person myGiovanni = new Person("Giovanni", 33);
54  1 myPersonDao.create(myGiovanni);
55  1 Person myAlberto = new Person("Alberto", 33);
56  1 myPersonDao.create(myAlberto);
57   
58  1 List<Person> myMatches = myPersonDao.findByName("Ernesto");
59  1 assertNotNull("findByName did not work as expected", myMatches);
60  1 assertEquals("findByName did not work as expected", 1, myMatches.
61    size());
62  1 assertEquals("findByName did not work as expected", myErnesto,
63    myMatches.get(0));
64    }
65   
66    //------------------------------------------------------------------------
 
67  1 toggle public void
68    testFindByAge()
69    {
70    // create Generic DAO instance
71  1 IPersonDao myPersonDao = LocalDaoFactory.getInstance().
72    createPersonDao();
73   
74    // create fixture Person instances
75  1 Person myErnesto = new Person("Ernesto", 35);
76  1 myPersonDao.create(myErnesto);
77  1 Person myGiovanni = new Person("Giovanni", 33);
78  1 myPersonDao.create(myGiovanni);
79  1 Person myAlberto = new Person("Alberto", 33);
80  1 myPersonDao.create(myAlberto);
81   
82  1 List<Person> myMatches = myPersonDao.findByAge(33);
83  1 assertNotNull("findByAge did not work as expected", myMatches);
84  1 assertEquals("findByAge did not work as expected", 2, myMatches.
85    size());
86  1 assertEquals("findByAge did not work as expected", 33,
87    myMatches.get(0).getAge());
88  1 assertEquals("findByAge did not work as expected", 33,
89    myMatches.get(1).getAge());
90    }
91   
92    //------------------------------------------------------------------------
 
93  1 toggle public void
94    testFindByExample()
95    {
96    // create Generic DAO instance
97  1 IPersonDao myPersonDao = LocalDaoFactory.getInstance().
98    createPersonDao();
99   
100    // create fixture Person instances
101  1 Person myErnesto = new Person("Ernesto", 35);
102  1 myPersonDao.create(myErnesto);
103  1 Person myGiovanni = new Person("Giovanni", 33);
104  1 myPersonDao.create(myGiovanni);
105  1 Person myAlberto = new Person("Alberto", 33);
106  1 myPersonDao.create(myAlberto);
107   
108  1 Person myExample = new Person();
109  1 myExample.setAge(33);
110  1 List<Person> myMatches = myPersonDao.findByExample(myExample);
111  1 assertNotNull("findByExample did not work as expected", myMatches);
112  1 assertEquals("findByExample did not work as expected", 2, myMatches.
113    size());
114  1 assertEquals("findByExample did not work as expected", 33,
115    myMatches.get(0).getAge());
116  1 assertEquals("findByExample did not work as expected", 33,
117    myMatches.get(1).getAge());
118    }
119   
120    //------------------------------------------------------------------------
 
121  1 toggle public void
122    testFindById()
123    {
124    // create Generic DAO instance
125  1 IPersonDao myPersonDao = LocalDaoFactory.getInstance().
126    createPersonDao();
127   
128    // create fixture Person instances
129  1 Person myErnesto = new Person("Ernesto", 35);
130  1 myPersonDao.create(myErnesto);
131   
132  1 Person myMatch = myPersonDao.findById(myErnesto.getId());
133  1 assertNotNull("findById did not work as expected", myMatch);
134  1 assertEquals("findById did not work as expected", myErnesto,
135    myMatch);
136    }
137   
138    //------------------------------------------------------------------------
139    // protected
140    //------------------------------------------------------------------------
 
141  4 toggle protected String[]
142    getConfigLocations()
143    {
144  4 return new String[]
145    {
146    "file:src/main/resources/genericDao-applicationContext.xml",
147    "file:src/test/resources/test-applicationContext.xml"
148    };
149    }
150   
151    //------------------------------------------------------------------------
 
152  4 toggle protected void
153    onTearDownAfterTransaction()
154    throws Exception
155    {
156    // empty the Person table
157  4 IPersonDao myPersonDao = LocalDaoFactory.getInstance().
158    createPersonDao();
159  4 myPersonDao.deleteAll();
160    }
161   
162    //------------------------------------------------------------------------
163    // members
164    //------------------------------------------------------------------------
165    /**
166    * Provides logging services for this class
167    */
168    @SuppressWarnings("unused")
169    private final Logger theLogger = LoggerFactory.getLogger(this.getClass());
170    }