1
|
package eu.dnetlib.enabling.is.sn.resourcestate.hib;
|
2
|
|
3
|
import java.util.Collection;
|
4
|
|
5
|
import eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionDAOImplTest;
|
6
|
import eu.dnetlib.enabling.is.sn.resourcestate.ResourceStateSubscription;
|
7
|
import eu.dnetlib.test.utils.EPRTestUtil;
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.junit.After;
|
11
|
import org.junit.Test;
|
12
|
import org.junit.runner.RunWith;
|
13
|
import org.springframework.beans.factory.annotation.Autowired;
|
14
|
import org.springframework.orm.hibernate5.HibernateJdbcException;
|
15
|
import org.springframework.test.annotation.DirtiesContext;
|
16
|
import org.springframework.test.context.ContextConfiguration;
|
17
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
18
|
|
19
|
import static org.junit.Assert.*;
|
20
|
|
21
|
/**
|
22
|
* test HibernateResourceStateSubscriptionDAOImplTest.
|
23
|
*
|
24
|
* @author marko
|
25
|
*
|
26
|
*/
|
27
|
@RunWith(SpringJUnit4ClassRunner.class)
|
28
|
@ContextConfiguration
|
29
|
public class HibernateResourceStateSubscriptionDAOImplTest extends AbstractResourceStateSubscriptionDAOImplTest {
|
30
|
/**
|
31
|
* logger.
|
32
|
*/
|
33
|
private static final Log log = LogFactory.getLog(HibernateResourceStateSubscriptionDAOImplTest.class); // NOPMD by marko on 11/24/08 5:02 PM
|
34
|
|
35
|
/**
|
36
|
* instance under test.
|
37
|
*/
|
38
|
@Autowired
|
39
|
private transient HibernateResourceStateSubscriptionDAOImpl hibdao;
|
40
|
|
41
|
/**
|
42
|
* cleanup db.
|
43
|
*/
|
44
|
@After
|
45
|
public void tearDown() {
|
46
|
final Collection<ResourceStateSubscription> subs = hibdao.listSubscriptions();
|
47
|
if (subs != null)
|
48
|
for (ResourceStateSubscription r : subs)
|
49
|
hibdao.removeSubscription(r.getSubscriptionId());
|
50
|
|
51
|
// for (ResourceStateSubscription r : subs)
|
52
|
// log.info("deleted: " + r);
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* test addition.
|
57
|
*/
|
58
|
@Test
|
59
|
public void testAddSubscription() {
|
60
|
assertNotNull("check dao", getDao());
|
61
|
|
62
|
getDao().addSubscription(getSub());
|
63
|
|
64
|
log.info("sub id: " + getSub().getSubscriptionId());
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* test encoding of endpoint references.
|
69
|
*/
|
70
|
@Test
|
71
|
@DirtiesContext
|
72
|
public void testEndpoint() {
|
73
|
getSub().setSubscriber(EPRTestUtil.getTestEpr());
|
74
|
|
75
|
getDao().addSubscription(getSub());
|
76
|
|
77
|
final ResourceStateSubscription fresh = getDao().getSubscription(getSub().getSubscriptionId());
|
78
|
|
79
|
assertNotNull("check", fresh);
|
80
|
assertTrue("equals", compare(getSub(), fresh));
|
81
|
|
82
|
assertNotNull("epr", getSub().getSubscriber());
|
83
|
assertNotNull("fetched epr", fresh.getSubscriber());
|
84
|
|
85
|
assertEquals("eprs", getSub().getSubscriber().toString(), fresh.getSubscriber().toString());
|
86
|
}
|
87
|
|
88
|
/**
|
89
|
* multiple subscriptions should not be allowed.
|
90
|
*/
|
91
|
@Test(expected = HibernateJdbcException.class)
|
92
|
@DirtiesContext
|
93
|
public void testMultiple() { // NOPMD
|
94
|
getDao().addSubscription(getSub());
|
95
|
getDao().addSubscription(getSub());
|
96
|
}
|
97
|
|
98
|
|
99
|
/**
|
100
|
* {@inheritDoc}
|
101
|
*
|
102
|
* @see eu.dnetlib.enabling.is.sn.resourcestate.AbstractResourceStateSubscriptionDAOImplTest#prepareDao()
|
103
|
*/
|
104
|
@Override
|
105
|
protected void prepareDao() {
|
106
|
setDao(hibdao);
|
107
|
}
|
108
|
|
109
|
}
|