| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 33 |
|
|
| 34 |
|
@author |
| 35 |
|
@version |
| 36 |
|
|
| 37 |
|
public |
|
|
|
| 100% |
Uncovered Elements: 0 (42) |
Complexity: 7 |
Complexity Density: 0.21 |
|
| 38 |
|
class TestHibernateGenericReadOnlyDao |
| 39 |
|
extends TestCase |
| 40 |
|
{ |
| 41 |
|
|
| 42 |
|
|
| 43 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 44 |
1
|
public void... |
| 45 |
|
testContains() |
| 46 |
|
{ |
| 47 |
|
|
| 48 |
1
|
IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory. |
| 49 |
|
getInstance().createReadOnlyDao(Person.class); |
| 50 |
|
|
| 51 |
|
|
| 52 |
1
|
List<Person> myPersons = myPersonDao.findAll(); |
| 53 |
1
|
boolean myContains = myPersonDao.contains(myPersons.get(0)); |
| 54 |
|
|
| 55 |
|
|
| 56 |
1
|
assertTrue("contains did not work as expected", myContains); |
| 57 |
|
} |
| 58 |
|
|
| 59 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1
PASS
|
|
| 60 |
1
|
public void... |
| 61 |
|
testCount() |
| 62 |
|
{ |
| 63 |
|
|
| 64 |
1
|
IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory. |
| 65 |
|
getInstance().createReadOnlyDao(Person.class); |
| 66 |
|
|
| 67 |
|
|
| 68 |
1
|
int myCount = myPersonDao.count(); |
| 69 |
|
|
| 70 |
|
|
| 71 |
1
|
assertEquals("count did not work as expected", 2, myCount); |
| 72 |
|
} |
| 73 |
|
|
| 74 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 75 |
1
|
public void... |
| 76 |
|
testFindById() |
| 77 |
|
{ |
| 78 |
|
|
| 79 |
1
|
IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory. |
| 80 |
|
getInstance().createReadOnlyDao(Person.class); |
| 81 |
|
|
| 82 |
|
|
| 83 |
1
|
Person myPedro = myPersonDao.findById(thePedro.getId()); |
| 84 |
|
|
| 85 |
|
|
| 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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1
PASS
|
|
| 92 |
1
|
public void... |
| 93 |
|
testFindAll() |
| 94 |
|
{ |
| 95 |
|
|
| 96 |
1
|
IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory. |
| 97 |
|
getInstance().createReadOnlyDao(Person.class); |
| 98 |
|
|
| 99 |
|
|
| 100 |
1
|
List<Person> myPersons = myPersonDao.findAll(); |
| 101 |
|
|
| 102 |
|
|
| 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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1
PASS
|
|
| 109 |
1
|
public void... |
| 110 |
|
testFindByExample() |
| 111 |
|
{ |
| 112 |
|
|
| 113 |
1
|
IGenericReadOnlyDao<Long, Person> myPersonDao = HibernateDaoFactory. |
| 114 |
|
getInstance().createReadOnlyDao(Person.class); |
| 115 |
|
|
| 116 |
|
|
| 117 |
1
|
Person myExample = new Person(); |
| 118 |
1
|
myExample.setName("Pedro"); |
| 119 |
1
|
myExample.setAge(45); |
| 120 |
|
|
| 121 |
|
|
| 122 |
1
|
List<Person> myPersons = myPersonDao.findByExample(myExample); |
| 123 |
|
|
| 124 |
|
|
| 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 |
|
|
| 133 |
1
|
myExample.setAge(-1); |
| 134 |
1
|
myPersons = myPersonDao.findByExample(myExample, "age"); |
| 135 |
|
|
| 136 |
|
|
| 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 |
|
|
| 147 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
| 148 |
5
|
@Override... |
| 149 |
|
protected void |
| 150 |
|
setUp() |
| 151 |
|
throws Exception |
| 152 |
|
{ |
| 153 |
5
|
super.setUp(); |
| 154 |
|
|
| 155 |
|
|
| 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 |
|
|
| 170 |
|
|
| 171 |
|
|
| 172 |
|
private static final Person thePedro = new Person("Pedro", 45); |
| 173 |
|
private static final Person theManuela = new Person("Manuela", 23); |
| 174 |
|
|
| 175 |
|
|
| 176 |
|
|
| 177 |
|
|
| 178 |
|
|
| 179 |
|
@SuppressWarnings("unused") |
| 180 |
|
private final Logger theLogger = LoggerFactory.getLogger(this.getClass()); |
| 181 |
|
} |