| 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.hibernate; |
| 22 |
|
|
| 23 |
|
import java.text.*; |
| 24 |
|
|
| 25 |
|
import junit.framework.*; |
| 26 |
|
|
| 27 |
|
import org.perfectjpattern.example.datamodel.*; |
| 28 |
|
import org.perfectjpattern.jee.api.integration.dao.*; |
| 29 |
|
import org.perfectjpattern.jee.integration.dao.*; |
| 30 |
|
import org.slf4j.*; |
| 31 |
|
|
| 32 |
|
import static org.easymock.EasyMock.*; |
| 33 |
|
|
| 34 |
|
|
| 35 |
|
|
| 36 |
|
|
| 37 |
|
@author |
| 38 |
|
@version |
| 39 |
|
|
| 40 |
|
public |
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 2 |
Complexity Density: 0.12 |
|
| 41 |
|
class TestExample |
| 42 |
|
extends TestCase |
| 43 |
|
{ |
| 44 |
|
|
| 45 |
|
|
| 46 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1
PASS
|
|
| 47 |
1
|
public void... |
| 48 |
|
testHibernateGenericDao() |
| 49 |
|
throws ParseException |
| 50 |
|
{ |
| 51 |
1
|
Logger myLoggerMock = createNiceMock(Logger.class); |
| 52 |
1
|
Example.setLogger(myLoggerMock); |
| 53 |
|
|
| 54 |
1
|
String myLogging = LINE_BREAK + |
| 55 |
|
"**************************************************************" + |
| 56 |
|
LINE_BREAK + |
| 57 |
|
"| Customer(id='1', name='Ernesto')" + LINE_BREAK + |
| 58 |
|
"|--> Order(id='1', date='3/14/07 8:00 AM')" + LINE_BREAK + |
| 59 |
|
"| |-> Product(id='2', name='Nikon D300', list price='2,000')" + |
| 60 |
|
LINE_BREAK + |
| 61 |
|
"| |-> Product(id='3', name='Nikon 80-400mm', list price='1,500')" + |
| 62 |
|
LINE_BREAK + |
| 63 |
|
"|--> Order(id='2', date='10/19/07 8:00 AM')" + LINE_BREAK + |
| 64 |
|
"| |-> Product(id='4', name='Nikon Fisheye 10mm', " + |
| 65 |
|
"list price='900')" + LINE_BREAK + |
| 66 |
|
"**************************************************************"; |
| 67 |
|
|
| 68 |
1
|
myLoggerMock.debug(myLogging); |
| 69 |
|
|
| 70 |
1
|
replay(myLoggerMock); |
| 71 |
|
|
| 72 |
1
|
Example.main(new String[0]); |
| 73 |
|
|
| 74 |
1
|
verify(myLoggerMock); |
| 75 |
|
} |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
|
| 81 |
|
@inheritDoc |
| 82 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0.1 |
|
| 83 |
1
|
@Override... |
| 84 |
|
protected void |
| 85 |
|
tearDown() |
| 86 |
|
throws Exception |
| 87 |
|
{ |
| 88 |
1
|
super.tearDown(); |
| 89 |
|
|
| 90 |
1
|
IGenericDaoFactory myDaoFactory = HibernateDaoFactory.getInstance(); |
| 91 |
|
|
| 92 |
1
|
try |
| 93 |
|
{ |
| 94 |
|
|
| 95 |
1
|
HibernateCurrentSessionStrategy mySessionStrategy = |
| 96 |
|
new HibernateCurrentSessionStrategy(); |
| 97 |
1
|
HibernateConfiguredTransactionStrategy myTransactionStrategy = |
| 98 |
|
new HibernateConfiguredTransactionStrategy(mySessionStrategy); |
| 99 |
|
|
| 100 |
1
|
myDaoFactory.setDaoSessionStrategy(mySessionStrategy); |
| 101 |
1
|
myDaoFactory.setDaoTransactionStrategy(myTransactionStrategy); |
| 102 |
|
|
| 103 |
1
|
IGenericDao<Long, Customer> myCustomerDao = myDaoFactory. |
| 104 |
|
createDao(Customer.class); |
| 105 |
1
|
myCustomerDao.deleteAll(); |
| 106 |
|
} |
| 107 |
|
finally |
| 108 |
|
{ |
| 109 |
1
|
myDaoFactory.shutdown(); |
| 110 |
|
} |
| 111 |
|
} |
| 112 |
|
|
| 113 |
|
|
| 114 |
|
|
| 115 |
|
|
| 116 |
|
private static final String LINE_BREAK = System.getProperty( |
| 117 |
|
"line.separator"); |
| 118 |
|
} |