1
|
/**
|
2
|
* Copyright (C) 2009 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.persistence.dao.hibernate.taxon;
|
11
|
|
12
|
import static junit.framework.Assert.assertNotNull;
|
13
|
|
14
|
import java.util.ArrayList;
|
15
|
import java.util.List;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.junit.After;
|
19
|
import org.junit.Before;
|
20
|
import org.junit.Test;
|
21
|
import org.unitils.dbunit.annotation.DataSet;
|
22
|
import org.unitils.spring.annotation.SpringBeanByType;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
25
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
26
|
import eu.etaxonomy.cdm.model.view.AuditEvent;
|
27
|
import eu.etaxonomy.cdm.model.view.context.AuditEventContextHolder;
|
28
|
import eu.etaxonomy.cdm.persistence.dao.common.IDefinedTermDao;
|
29
|
import eu.etaxonomy.cdm.persistence.dao.reference.IReferenceDao;
|
30
|
import eu.etaxonomy.cdm.persistence.dao.taxon.IClassificationDao;
|
31
|
import eu.etaxonomy.cdm.persistence.dao.taxon.ITaxonDao;
|
32
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
33
|
|
34
|
/**
|
35
|
* @author a.mueller
|
36
|
* @author ben.clark
|
37
|
*
|
38
|
*/
|
39
|
public class TaxonDaoHibernateImplBenchmark extends CdmTransactionalIntegrationTest {
|
40
|
|
41
|
// @Rule
|
42
|
// public MethodRule benchmarkRun = new BenchmarkRule();
|
43
|
|
44
|
|
45
|
@SpringBeanByType
|
46
|
private ITaxonDao taxonDao;
|
47
|
|
48
|
@SpringBeanByType
|
49
|
private IClassificationDao classificationDao;
|
50
|
|
51
|
@SpringBeanByType
|
52
|
private IReferenceDao referenceDao;
|
53
|
|
54
|
@SpringBeanByType
|
55
|
IDefinedTermDao definedTermDao;
|
56
|
|
57
|
private UUID uuid;
|
58
|
private UUID sphingidae;
|
59
|
private UUID acherontia;
|
60
|
private UUID mimas;
|
61
|
private UUID rethera;
|
62
|
private UUID retheraSecCdmtest;
|
63
|
private UUID atroposAgassiz;
|
64
|
private UUID atroposLeach;
|
65
|
private UUID acherontiaLachesis;
|
66
|
private AuditEvent previousAuditEvent;
|
67
|
private AuditEvent mostRecentAuditEvent;
|
68
|
|
69
|
private UUID northernAmericaUuid;
|
70
|
private UUID southernAmericaUuid;
|
71
|
private UUID antarcticaUuid;
|
72
|
|
73
|
private UUID classificationUuid;
|
74
|
|
75
|
private Taxon taxonAcherontia;
|
76
|
|
77
|
private static final int BENCHMARK_ROUNDS = 10;
|
78
|
|
79
|
|
80
|
@Before
|
81
|
public void setUp() {
|
82
|
|
83
|
uuid = UUID.fromString("496b1325-be50-4b0a-9aa2-3ecd610215f2");
|
84
|
sphingidae = UUID.fromString("54e767ee-894e-4540-a758-f906ecb4e2d9");
|
85
|
acherontia = UUID.fromString("c5cc8674-4242-49a4-aada-72d63194f5fa");
|
86
|
acherontiaLachesis = UUID.fromString("b04cc9cb-2b4a-4cc4-a94a-3c93a2158b06");
|
87
|
atroposAgassiz = UUID.fromString("d75b2e3d-7394-4ada-b6a5-93175b8751c1");
|
88
|
atroposLeach = UUID.fromString("3da4ab34-6c50-4586-801e-732615899b07");
|
89
|
rethera = UUID.fromString("a9f42927-e507-4fda-9629-62073a908aae");
|
90
|
retheraSecCdmtest = UUID.fromString("a9f42927-e507-433a-9629-62073a908aae");
|
91
|
|
92
|
|
93
|
mimas = UUID.fromString("900052b7-b69c-4e26-a8f0-01c215214c40");
|
94
|
previousAuditEvent = new AuditEvent();
|
95
|
previousAuditEvent.setRevisionNumber(1025);
|
96
|
previousAuditEvent.setUuid(UUID.fromString("a680fab4-365e-4765-b49e-768f2ee30cda"));
|
97
|
mostRecentAuditEvent = new AuditEvent();
|
98
|
mostRecentAuditEvent.setRevisionNumber(1026);
|
99
|
mostRecentAuditEvent.setUuid(UUID.fromString("afe8e761-8545-497b-9134-6a6791fc0b0d"));
|
100
|
AuditEventContextHolder.clearContext(); // By default we're in the current view (i.e. view == null)
|
101
|
|
102
|
northernAmericaUuid = UUID.fromString("2757e726-d897-4546-93bd-7951d203bf6f");
|
103
|
southernAmericaUuid = UUID.fromString("6310b3ba-96f4-4855-bb5b-326e7af188ea");
|
104
|
antarcticaUuid = UUID.fromString("791b3aa0-54dd-4bed-9b68-56b4680aad0c");
|
105
|
|
106
|
classificationUuid = UUID.fromString("aeee7448-5298-4991-b724-8d5b75a0a7a9");
|
107
|
|
108
|
taxonAcherontia = (Taxon)taxonDao.findByUuid(acherontia);
|
109
|
}
|
110
|
|
111
|
@After
|
112
|
public void tearDown() {
|
113
|
AuditEventContextHolder.clearContext();
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Test method for {@link eu.etaxonomy.cdm.persistence.dao.hibernate.taxon.TaxonDaoHibernateImpl#TaxonDaoHibernateImpl()}.
|
118
|
*/
|
119
|
@Test
|
120
|
@DataSet(value="TaxonDaoHibernateImplTest.xml")
|
121
|
public void testInit() {
|
122
|
logger.warn("testInit()");
|
123
|
assertNotNull("Instance of ITaxonDao expected",taxonDao);
|
124
|
assertNotNull("Instance of IReferenceDao expected",referenceDao);
|
125
|
}
|
126
|
|
127
|
@Test
|
128
|
@DataSet(value="TaxonDaoHibernateImplTest.xml")
|
129
|
public void testCreateDelete() {
|
130
|
Taxon parent = (Taxon)taxonDao.findByUuid(acherontiaLachesis);
|
131
|
assert parent != null : "taxon cannot be null";
|
132
|
List<Taxon> newTaxa = new ArrayList<Taxon>(BENCHMARK_ROUNDS);
|
133
|
|
134
|
for(int indx = 0; indx < BENCHMARK_ROUNDS; indx++){
|
135
|
Taxon child = Taxon.NewInstance(null, null);
|
136
|
child.setTitleCache("Acherontia lachesis benchmark_" + indx + " Eitschberger, 2003", true);
|
137
|
child.addTaxonRelation(parent, TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN(),null, null);
|
138
|
newTaxa.add(child);
|
139
|
logger.info("[" + indx + "] " + child.getTitleCache());
|
140
|
taxonDao.save(child);
|
141
|
//commitAndStartNewTransaction(null);
|
142
|
|
143
|
}
|
144
|
|
145
|
for(Taxon child: newTaxa){
|
146
|
taxonDao.delete(child);
|
147
|
}
|
148
|
|
149
|
// setComplete();
|
150
|
// endTransaction();
|
151
|
}
|
152
|
|
153
|
|
154
|
|
155
|
|
156
|
|
157
|
|
158
|
|
159
|
|
160
|
|
161
|
|
162
|
|
163
|
|
164
|
|
165
|
|
166
|
|
167
|
|
168
|
|
169
|
|
170
|
|
171
|
|
172
|
}
|