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 |
|
|
| 97.7% |
Uncovered Elements: 1 (43) |
Complexity: 6 |
Complexity Density: 0.17 |
|
38 |
|
class TestJpaGenericDao |
39 |
|
extends TestCase |
40 |
|
{ |
41 |
|
|
42 |
|
|
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
44 |
1
|
public void... |
45 |
|
testCreate() |
46 |
|
{ |
47 |
|
|
48 |
1
|
IBaseDao<Long, Person> myPersonDao = JpaDaoFactory. |
49 |
|
getInstance().createDao(Person.class); |
50 |
|
|
51 |
|
|
52 |
1
|
Person myGiovanni = new Person("Giovanni", 32); |
53 |
|
|
54 |
1
|
myPersonDao.create(myGiovanni); |
55 |
|
|
56 |
|
|
57 |
1
|
List<Person> myPersons = myPersonDao.findAll(); |
58 |
|
|
59 |
1
|
assertNotNull("create seems not to work, record was not found.", |
60 |
|
myPersons); |
61 |
1
|
assertEquals("create seems not to work, record was not found.", |
62 |
|
1, myPersons.size()); |
63 |
1
|
assertEquals("create seems not to work, record was not found.", |
64 |
|
"Giovanni", myPersons.get(0).getName()); |
65 |
|
} |
66 |
|
|
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1
PASS
|
|
68 |
1
|
public void... |
69 |
|
testUpdate() |
70 |
|
{ |
71 |
|
|
72 |
1
|
IBaseDao<Long, Person> myPersonDao = JpaDaoFactory. |
73 |
|
getInstance().createDao(Person.class); |
74 |
|
|
75 |
|
|
76 |
1
|
Person myRosa = new Person("Rosa", 27); |
77 |
1
|
myPersonDao.create(myRosa); |
78 |
|
|
79 |
|
|
80 |
1
|
List<Person> myPersons = myPersonDao.findAll(); |
81 |
|
|
82 |
1
|
Person myUpdate = myPersons.get(0); |
83 |
1
|
myUpdate.setAge(28); |
84 |
1
|
myPersonDao.update(myUpdate); |
85 |
|
|
86 |
|
|
87 |
1
|
myPersons = myPersonDao.findAll(); |
88 |
|
|
89 |
1
|
assertNotNull("create seems not to work, record was not found.", |
90 |
|
myPersons); |
91 |
1
|
assertEquals("create seems not to work, record was not found.", |
92 |
|
"Rosa", myPersons.get(0).getName()); |
93 |
1
|
assertEquals("create seems not to work, record was not found.", |
94 |
|
28, myPersons.get(0).getAge()); |
95 |
|
} |
96 |
|
|
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1
PASS
|
|
98 |
1
|
public void... |
99 |
|
testDelete() |
100 |
|
{ |
101 |
|
|
102 |
1
|
IBaseDao<Long, Person> myPersonDao = JpaDaoFactory.getInstance(). |
103 |
|
createDao(Person.class); |
104 |
|
|
105 |
|
|
106 |
1
|
Person myErnesto = new Person("Ernesto", 35); |
107 |
1
|
myPersonDao.create(myErnesto); |
108 |
|
|
109 |
|
|
110 |
1
|
myPersonDao.getTransaction().commit(); |
111 |
|
|
112 |
1
|
Long myId = myErnesto.getId(); |
113 |
|
|
114 |
1
|
Person myDelete = myPersonDao.findById(myId); |
115 |
|
|
116 |
|
|
117 |
1
|
myPersonDao.delete(myDelete); |
118 |
|
|
119 |
1
|
boolean myContains = myPersonDao.contains(myDelete); |
120 |
|
|
121 |
|
|
122 |
1
|
assertFalse("There must be no Elements left matching the deleted.", |
123 |
|
myContains); |
124 |
|
} |
125 |
|
|
126 |
|
|
127 |
|
|
128 |
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
129 |
3
|
@Override... |
130 |
|
protected void |
131 |
|
setUp() |
132 |
|
throws Exception |
133 |
|
{ |
134 |
3
|
super.setUp(); |
135 |
|
|
136 |
|
|
137 |
3
|
IBaseDao<Long, Person> myPersonDao = JpaDaoFactory. |
138 |
|
getInstance().createDao(Person.class); |
139 |
|
|
140 |
3
|
ITransaction myTransaction = myPersonDao.getTransaction(); |
141 |
3
|
if (myTransaction.isActive()) |
142 |
|
{ |
143 |
3
|
myTransaction.rollback(); |
144 |
|
} |
145 |
|
|
146 |
3
|
if (myPersonDao.count() > 0) |
147 |
|
{ |
148 |
1
|
myPersonDao.deleteAll(); |
149 |
|
|
150 |
1
|
myTransaction.commit(); |
151 |
|
} |
152 |
|
} |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
|
159 |
|
|
160 |
|
@SuppressWarnings("unused") |
161 |
|
private final Logger theLogger = LoggerFactory.getLogger(this.getClass()); |
162 |
|
} |