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 (28) |
Complexity: 6 |
Complexity Density: 0.29 |
|
38 |
|
class TestJpaGenericReadOnlyDao |
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
|
IBaseReadOnlyDao<Long, Person> myPersonDao = JpaDaoFactory. |
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
|
IBaseReadOnlyDao<Long, Person> myPersonDao = JpaDaoFactory. |
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
|
IBaseReadOnlyDao<Long, Person> myPersonDao = JpaDaoFactory. |
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
|
IBaseReadOnlyDao<Long, Person> myPersonDao = JpaDaoFactory. |
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 |
|
|
109 |
|
|
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 2 |
Complexity Density: 0.33 |
|
111 |
4
|
@Override... |
112 |
|
protected void |
113 |
|
setUp() |
114 |
|
throws Exception |
115 |
|
{ |
116 |
4
|
super.setUp(); |
117 |
|
|
118 |
|
|
119 |
4
|
IBaseDao<Long, Person> myPersonDao = JpaDaoFactory. |
120 |
|
getInstance().createDao(Person.class); |
121 |
|
|
122 |
4
|
if (myPersonDao.count() == 0) |
123 |
|
{ |
124 |
1
|
myPersonDao.create(thePedro); |
125 |
1
|
myPersonDao.create(theManuela); |
126 |
|
|
127 |
1
|
myPersonDao.getTransaction().commit(); |
128 |
|
} |
129 |
|
} |
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
private static final Person thePedro = new Person("Pedro", 45); |
136 |
|
private static final Person theManuela = new Person("Manuela", 23); |
137 |
|
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
|
|
142 |
|
@SuppressWarnings("unused") |
143 |
|
private final Logger theLogger = LoggerFactory.getLogger(this.getClass()); |
144 |
|
} |