1
|
/**
|
2
|
* Copyright (C) 2007 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.io.specimen.abcd206.in;
|
11
|
|
12
|
import static org.junit.Assert.assertEquals;
|
13
|
import static org.junit.Assert.assertNotNull;
|
14
|
import static org.junit.Assert.assertTrue;
|
15
|
|
16
|
import java.io.FileNotFoundException;
|
17
|
import java.net.URISyntaxException;
|
18
|
import java.net.URL;
|
19
|
import java.text.ParseException;
|
20
|
import java.util.List;
|
21
|
import java.util.Set;
|
22
|
import java.util.UUID;
|
23
|
|
24
|
import org.junit.Assert;
|
25
|
import org.junit.Before;
|
26
|
import org.junit.Ignore;
|
27
|
import org.junit.Test;
|
28
|
import org.unitils.dbunit.annotation.DataSet;
|
29
|
import org.unitils.dbunit.annotation.DataSets;
|
30
|
import org.unitils.spring.annotation.SpringBeanByName;
|
31
|
import org.unitils.spring.annotation.SpringBeanByType;
|
32
|
|
33
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
34
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
35
|
import eu.etaxonomy.cdm.api.service.ICommonService;
|
36
|
import eu.etaxonomy.cdm.api.service.INameService;
|
37
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
38
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
39
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
40
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
41
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
42
|
import eu.etaxonomy.cdm.common.URI;
|
43
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
|
44
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
45
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
46
|
import eu.etaxonomy.cdm.model.agent.Person;
|
47
|
import eu.etaxonomy.cdm.model.molecular.DnaSample;
|
48
|
import eu.etaxonomy.cdm.model.name.Rank;
|
49
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
50
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
51
|
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
|
52
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
53
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
54
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
55
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
56
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
57
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
58
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
59
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
60
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
61
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
62
|
|
63
|
/**
|
64
|
* @author a.mueller
|
65
|
* @since 29.01.2009
|
66
|
*/
|
67
|
public class SpecimenImportConfiguratorTest extends CdmTransactionalIntegrationTest {
|
68
|
|
69
|
@SpringBeanByName
|
70
|
private CdmApplicationAwareDefaultImport<?> defaultImport;
|
71
|
|
72
|
@SpringBeanByType
|
73
|
private INameService nameService;
|
74
|
|
75
|
@SpringBeanByType
|
76
|
private ITaxonService taxonService;
|
77
|
|
78
|
@SpringBeanByType
|
79
|
private IOccurrenceService occurrenceService;
|
80
|
|
81
|
@SpringBeanByType
|
82
|
private ITermService termService;
|
83
|
|
84
|
@SpringBeanByType
|
85
|
private ICommonService commonService;
|
86
|
|
87
|
@SpringBeanByType
|
88
|
private ITaxonNodeService taxonNodeService;
|
89
|
|
90
|
@SpringBeanByType
|
91
|
private IAgentService agentService;
|
92
|
|
93
|
@SpringBeanByType
|
94
|
private IReferenceService referenceService;
|
95
|
|
96
|
@SpringBeanByType
|
97
|
private IClassificationService classificationService;
|
98
|
|
99
|
|
100
|
|
101
|
private IImportConfigurator configurator;
|
102
|
private IImportConfigurator configurator2;
|
103
|
|
104
|
@Before
|
105
|
public void setUp() {
|
106
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/AbcdImportTestCalvumPart1.xml";
|
107
|
URL url = this.getClass().getResource(inputFile);
|
108
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
109
|
try {
|
110
|
configurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
111
|
} catch (URISyntaxException e) {
|
112
|
e.printStackTrace();
|
113
|
Assert.fail();
|
114
|
}
|
115
|
assertNotNull("Configurator could not be created", configurator);
|
116
|
|
117
|
//test2
|
118
|
String inputFile2 = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_ABCD_import_3_taxa_11_units.xml";
|
119
|
URL url2 = this.getClass().getResource(inputFile2);
|
120
|
assertNotNull("URL for the test file '" + inputFile2 + "' does not exist", url2);
|
121
|
try {
|
122
|
configurator2 = Abcd206ImportConfigurator.NewInstance(new URI(url2), null,false);
|
123
|
} catch (URISyntaxException e) {
|
124
|
e.printStackTrace();
|
125
|
Assert.fail();
|
126
|
}
|
127
|
assertNotNull("Configurator2 could not be created", configurator2);
|
128
|
}
|
129
|
|
130
|
@Test
|
131
|
public void testInit() {
|
132
|
System.out.println("TEST INIT");
|
133
|
assertNotNull("import instance should not be null", defaultImport);
|
134
|
assertNotNull("nameService should not be null", nameService);
|
135
|
assertNotNull("occurence service should not be null", occurrenceService);
|
136
|
assertNotNull("term service should not be null", termService);
|
137
|
assertNotNull("common service should not be null", commonService);
|
138
|
assertNotNull("taxon node service should not be null", taxonNodeService);
|
139
|
assertNotNull("agent service should not be null", agentService);
|
140
|
assertNotNull("reference service should not be null", referenceService);
|
141
|
}
|
142
|
|
143
|
@Test
|
144
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
145
|
@Ignore
|
146
|
public void testDoInvoke() {
|
147
|
boolean result = defaultImport.invoke(configurator).isSuccess();
|
148
|
assertTrue("Return value for import.invoke should be true", result);
|
149
|
assertEquals("Number of TaxonNames is incorrect", 2, nameService.count(TaxonName.class));
|
150
|
/*
|
151
|
* Classification
|
152
|
* - Cichorium
|
153
|
* - Cichorium calvum
|
154
|
*/
|
155
|
assertEquals("Number of TaxonNodes is incorrect", 3, taxonNodeService.count(TaxonNode.class));
|
156
|
assertEquals("Number of specimen and observation is incorrect", 10, occurrenceService.count(DerivedUnit.class));
|
157
|
//Asch. + Mitarbeiter der Floristischen Kartierung Deutschlands
|
158
|
assertEquals("Number of persons is incorrect", 2, agentService.count(Person.class));
|
159
|
//BfN
|
160
|
assertEquals("Number of institutions is incorrect", 1, agentService.count(Institution.class));
|
161
|
}
|
162
|
|
163
|
|
164
|
@Test
|
165
|
@DataSet(value="SpecimenImportConfiguratorTest.doInvoke2.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
166
|
@Ignore
|
167
|
public void testDoInvoke2() {
|
168
|
boolean result = defaultImport.invoke(configurator2).isSuccess();
|
169
|
assertTrue("Return value for import.invoke should be true", result);
|
170
|
|
171
|
assertEquals("Number of TaxonNames is incorrect", 4, nameService.count(TaxonName.class));
|
172
|
List<TaxonName> listNames = nameService.list(TaxonName.class, 100, 0, null, null);
|
173
|
|
174
|
for (TaxonName name: listNames){
|
175
|
System.out.println(name.getTitleCache());
|
176
|
}
|
177
|
/*
|
178
|
* 5 taxon nodes:
|
179
|
*
|
180
|
* Classification
|
181
|
* - Campanula
|
182
|
* - Campanula patula
|
183
|
* - Campanula tridentata
|
184
|
* - Campanula lactiflora
|
185
|
*/
|
186
|
assertEquals("Number of TaxonNodes is incorrect", 5, taxonNodeService.count(TaxonNode.class));
|
187
|
assertEquals("Number of derived units is incorrect", 11, occurrenceService.count(DerivedUnit.class));
|
188
|
assertEquals("Number of field units is incorrect", 11, occurrenceService.count(FieldUnit.class));
|
189
|
assertEquals("Number of gathering agents is incorrect", 4, agentService.count(Person.class));
|
190
|
//BGBM
|
191
|
assertEquals("Number of institutions is incorrect", 1, agentService.count(Institution.class));
|
192
|
assertEquals("Number of references is incorrect", 1, referenceService.count(Reference.class));
|
193
|
}
|
194
|
|
195
|
@Test
|
196
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
197
|
@Ignore
|
198
|
public void testImportSubspecies() {
|
199
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/camapanula_abietina_subspecies.xml";
|
200
|
URL url = this.getClass().getResource(inputFile);
|
201
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
202
|
|
203
|
Abcd206ImportConfigurator importConfigurator = null;
|
204
|
try {
|
205
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
206
|
} catch (URISyntaxException e) {
|
207
|
e.printStackTrace();
|
208
|
Assert.fail();
|
209
|
}
|
210
|
assertNotNull("Configurator could not be created", importConfigurator);
|
211
|
|
212
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
213
|
assertTrue("Return value for import.invoke should be true", result);
|
214
|
assertEquals("Number of TaxonNames is incorrect", 3, nameService.count(TaxonName.class));
|
215
|
/*
|
216
|
* Classification
|
217
|
* - Campanula
|
218
|
* - Campanula patula
|
219
|
* - Campanula patula subsp. abietina
|
220
|
*/
|
221
|
assertEquals("Number of TaxonNodes is incorrect", 4, taxonNodeService.count(TaxonNode.class));
|
222
|
}
|
223
|
|
224
|
@Test
|
225
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
226
|
@Ignore
|
227
|
public void testImportVariety() {
|
228
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_variety.xml";
|
229
|
URL url = this.getClass().getResource(inputFile);
|
230
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
231
|
|
232
|
Abcd206ImportConfigurator importConfigurator = null;
|
233
|
try {
|
234
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
235
|
} catch (URISyntaxException e) {
|
236
|
e.printStackTrace();
|
237
|
Assert.fail();
|
238
|
}
|
239
|
assertNotNull("Configurator could not be created", importConfigurator);
|
240
|
|
241
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
242
|
assertTrue("Return value for import.invoke should be true", result);
|
243
|
|
244
|
/*
|
245
|
* Classification
|
246
|
* - Campanula
|
247
|
* - Campanula versicolor
|
248
|
* - Campanula versicolor var. tomentella Hal.
|
249
|
*/
|
250
|
assertEquals(4, taxonNodeService.count(TaxonNode.class));
|
251
|
assertEquals(3, nameService.count(TaxonName.class));
|
252
|
assertEquals(1, occurrenceService.count(DerivedUnit.class));
|
253
|
boolean varietyFound = false;
|
254
|
for(TaxonName name:nameService.list(TaxonName.class, null, null, null, null)){
|
255
|
if(name.getRank().equals(Rank.VARIETY())){
|
256
|
varietyFound = true;
|
257
|
}
|
258
|
}
|
259
|
assertTrue("Variety rank not set", varietyFound);
|
260
|
}
|
261
|
|
262
|
@Test
|
263
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
264
|
public void testMultipleIdentificationsPreferredFlag() {
|
265
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/MultipleIdentificationsPreferredFlag.xml";
|
266
|
URL url = this.getClass().getResource(inputFile);
|
267
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
268
|
|
269
|
Abcd206ImportConfigurator importConfigurator = null;
|
270
|
try {
|
271
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
272
|
} catch (URISyntaxException e) {
|
273
|
e.printStackTrace();
|
274
|
Assert.fail();
|
275
|
}
|
276
|
assertNotNull("Configurator could not be created", importConfigurator);
|
277
|
|
278
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
279
|
assertTrue("Return value for import.invoke should be true", result);
|
280
|
|
281
|
String nonPreferredNameCache = "Campanula flagellaris";
|
282
|
String preferredNameCache = "Campanula tymphaea";
|
283
|
//Campanula, "Campanula tymphaea Hausskn.", "Campanula flagellaris Halácsy"
|
284
|
assertEquals(3, nameService.count(TaxonName.class));
|
285
|
/*
|
286
|
* Classification
|
287
|
* - Campanula
|
288
|
* - Campanula tymphaea Hausskn.
|
289
|
*/
|
290
|
assertEquals(3, taxonNodeService.count(TaxonNode.class));
|
291
|
assertEquals(1, occurrenceService.count(DerivedUnit.class));
|
292
|
DerivedUnit derivedUnit = occurrenceService.list(DerivedUnit.class, null, null, null, null).get(0);
|
293
|
assertEquals(2, derivedUnit.getDeterminations().size());
|
294
|
for(DeterminationEvent determinationEvent:derivedUnit.getDeterminations()){
|
295
|
if(determinationEvent.getPreferredFlag()){
|
296
|
assertEquals(preferredNameCache,determinationEvent.getTaxonName().getNameCache());
|
297
|
}
|
298
|
else{
|
299
|
assertEquals(nonPreferredNameCache,determinationEvent.getTaxonName().getNameCache());
|
300
|
}
|
301
|
}
|
302
|
|
303
|
}
|
304
|
|
305
|
@Test
|
306
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
307
|
public void testImportForm() {
|
308
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/C_drabifolia_major.xml";
|
309
|
URL url = this.getClass().getResource(inputFile);
|
310
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
311
|
|
312
|
Abcd206ImportConfigurator importConfigurator = null;
|
313
|
try {
|
314
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
315
|
} catch (URISyntaxException e) {
|
316
|
e.printStackTrace();
|
317
|
Assert.fail();
|
318
|
}
|
319
|
assertNotNull("Configurator could not be created", importConfigurator);
|
320
|
|
321
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
322
|
assertTrue("Return value for import.invoke should be true", result);
|
323
|
}
|
324
|
|
325
|
@Test
|
326
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
327
|
public void testMapUnitIDAsBarcode() {
|
328
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_ABCD_import_3_taxa_11_units.xml";
|
329
|
URL url = this.getClass().getResource(inputFile);
|
330
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
331
|
|
332
|
Abcd206ImportConfigurator importConfigurator = null;
|
333
|
try {
|
334
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
335
|
} catch (URISyntaxException e) {
|
336
|
e.printStackTrace();
|
337
|
Assert.fail();
|
338
|
}
|
339
|
assertNotNull("Configurator could not be created", importConfigurator);
|
340
|
|
341
|
importConfigurator.setMapUnitIdToBarcode(true);
|
342
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
343
|
assertTrue("Return value for import.invoke should be true", result);
|
344
|
List<DerivedUnit> list = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
345
|
for (DerivedUnit derivedUnit : list) {
|
346
|
assertTrue(derivedUnit.getBarcode()!=null);
|
347
|
}
|
348
|
}
|
349
|
|
350
|
@Test
|
351
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
352
|
public void testMapUnitIDAsAccessionNumber() {
|
353
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_ABCD_import_3_taxa_11_units.xml";
|
354
|
URL url = this.getClass().getResource(inputFile);
|
355
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
356
|
|
357
|
Abcd206ImportConfigurator importConfigurator = null;
|
358
|
try {
|
359
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
360
|
} catch (URISyntaxException e) {
|
361
|
e.printStackTrace();
|
362
|
Assert.fail();
|
363
|
}
|
364
|
assertNotNull("Configurator could not be created", importConfigurator);
|
365
|
|
366
|
importConfigurator.setMapUnitIdToAccessionNumber(true);
|
367
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
368
|
assertTrue("Return value for import.invoke should be true", result);
|
369
|
List<DerivedUnit> list = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
370
|
for (DerivedUnit derivedUnit : list) {
|
371
|
assertTrue(derivedUnit.getAccessionNumber()!=null);
|
372
|
}
|
373
|
}
|
374
|
|
375
|
@Test
|
376
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
377
|
public void testMapUnitIDAsCatalogNumber() {
|
378
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_ABCD_import_3_taxa_11_units.xml";
|
379
|
URL url = this.getClass().getResource(inputFile);
|
380
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
381
|
|
382
|
Abcd206ImportConfigurator importConfigurator = null;
|
383
|
try {
|
384
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
385
|
} catch (URISyntaxException e) {
|
386
|
e.printStackTrace();
|
387
|
Assert.fail();
|
388
|
}
|
389
|
assertNotNull("Configurator could not be created", importConfigurator);
|
390
|
|
391
|
importConfigurator.setMapUnitIdToCatalogNumber(true);
|
392
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
393
|
assertTrue("Return value for import.invoke should be true", result);
|
394
|
List<DerivedUnit> list = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
395
|
for (DerivedUnit derivedUnit : list) {
|
396
|
assertTrue(derivedUnit.getCatalogNumber()!=null);
|
397
|
}
|
398
|
}
|
399
|
|
400
|
@Test
|
401
|
@DataSet( value="AbcdGgbnImportTest.testAttachDnaSampleToDerivedUnit.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
402
|
public void testIgnoreExistingSpecimens(){
|
403
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
404
|
|
405
|
// DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
|
406
|
// derivedUnit.setAccessionNumber("B 10 0066577");
|
407
|
// derivedUnit.setTitleCache("testUnit1", true);
|
408
|
//
|
409
|
// derivedUnit.setUuid(derivedUnit1Uuid );
|
410
|
//
|
411
|
// occurrenceService.save(derivedUnit);
|
412
|
//
|
413
|
// commitAndStartNewTransaction(null);
|
414
|
//
|
415
|
// setComplete();
|
416
|
// endTransaction();
|
417
|
//
|
418
|
//
|
419
|
// try {
|
420
|
// writeDbUnitDataSetFile(new String[] {
|
421
|
// "SpecimenOrObservationBase",
|
422
|
// }, "testAttachDnaSampleToDerivedUnit");
|
423
|
// } catch (FileNotFoundException e) {
|
424
|
// e.printStackTrace();
|
425
|
// }
|
426
|
|
427
|
|
428
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_B_10_0066577.xml";
|
429
|
URL url = this.getClass().getResource(inputFile);
|
430
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
431
|
|
432
|
Abcd206ImportConfigurator importConfigurator = null;
|
433
|
try {
|
434
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
435
|
importConfigurator.setDnaSoure(null);
|
436
|
} catch (URISyntaxException e) {
|
437
|
e.printStackTrace();
|
438
|
Assert.fail();
|
439
|
}
|
440
|
assertNotNull("Configurator could not be created", importConfigurator);
|
441
|
importConfigurator.setIgnoreImportOfExistingSpecimen(true);
|
442
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
443
|
assertTrue("Return value for import.invoke should be true", result);
|
444
|
assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
|
445
|
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
446
|
assertEquals("Number of derived units is incorrect", 1, derivedUnits.size());
|
447
|
|
448
|
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
|
449
|
assertTrue(derivedUnits.contains(derivedUnit));
|
450
|
|
451
|
}
|
452
|
|
453
|
@Test
|
454
|
@DataSet( value="AbcdGgbnImportTest.testAttachDnaSampleToDerivedUnit.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
455
|
public void testIgnoreExistingSpecimensWithDna(){
|
456
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
457
|
|
458
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_B_10_0066577.xml";
|
459
|
URL url = this.getClass().getResource(inputFile);
|
460
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
461
|
|
462
|
Abcd206ImportConfigurator importConfigurator = null;
|
463
|
try {
|
464
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
465
|
importConfigurator.setDnaSoure(URI.create("https://ww3.bgbm.org/biocase/pywrapper.cgi?dsa=DNA_Bank"));
|
466
|
|
467
|
} catch (URISyntaxException e) {
|
468
|
e.printStackTrace();
|
469
|
Assert.fail();
|
470
|
}
|
471
|
assertNotNull("Configurator could not be created", importConfigurator);
|
472
|
importConfigurator.setIgnoreImportOfExistingSpecimen(true);
|
473
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
474
|
assertTrue("Return value for import.invoke should be true", result);
|
475
|
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
|
476
|
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
477
|
assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
|
478
|
|
479
|
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
|
480
|
assertTrue(derivedUnits.contains(derivedUnit));
|
481
|
|
482
|
}
|
483
|
|
484
|
/**
|
485
|
* Test imports one unit with an already existing taxon and one with a new taxon.
|
486
|
* The new taxon should be added to a newly created default classification.
|
487
|
*/
|
488
|
@Test
|
489
|
@DataSets({
|
490
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"),
|
491
|
@DataSet( value="SpecimenImportConfiguratorTest.testIgnoreAuthorship.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
492
|
})
|
493
|
public void testImportNewTaxaToDefaultClassification(){
|
494
|
UUID taxonUUID = UUID.fromString("26f98a58-09ab-49a0-ab9f-7490757c86d2");
|
495
|
UUID classificationUUID = UUID.fromString("eee32748-5b89-4266-a99a-1edb3781d0eb");
|
496
|
|
497
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_B_10_0066577_two_units_almost_same.xml";
|
498
|
URL url = this.getClass().getResource(inputFile);
|
499
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
500
|
|
501
|
Abcd206ImportConfigurator importConfigurator = null;
|
502
|
try {
|
503
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
504
|
importConfigurator.setDnaSoure(null);
|
505
|
} catch (URISyntaxException e) {
|
506
|
e.printStackTrace();
|
507
|
Assert.fail();
|
508
|
}
|
509
|
assertNotNull("Configurator could not be created", importConfigurator);
|
510
|
|
511
|
//test initial state
|
512
|
Taxon taxon = (Taxon) taxonService.load(taxonUUID);
|
513
|
assertNotNull(taxon);
|
514
|
Classification classification = classificationService.load(classificationUUID);
|
515
|
assertNotNull(classification);
|
516
|
assertEquals(1, taxon.getTaxonNodes().size());
|
517
|
TaxonNode taxonNode = taxon.getTaxonNodes().iterator().next();
|
518
|
assertEquals(classification, taxonNode.getClassification());
|
519
|
|
520
|
assertEquals(1, classificationService.count(Classification.class));
|
521
|
assertEquals(1, taxonService.count(Taxon.class));
|
522
|
|
523
|
importConfigurator.setClassificationUuid(classificationUUID);
|
524
|
// importConfigurator.setIgnoreAuthorship(true);
|
525
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
526
|
assertTrue("Return value for import.invoke should be true", result);
|
527
|
|
528
|
//re-load classification to avoid session conflicts
|
529
|
classification = classificationService.load(classificationUUID);
|
530
|
|
531
|
assertEquals(2, occurrenceService.count(DerivedUnit.class));
|
532
|
// assertEquals(2, taxonService.count(Taxon.class));
|
533
|
assertEquals(2, classificationService.count(Classification.class));
|
534
|
|
535
|
//get default classification
|
536
|
List<Classification> list = classificationService.list(Classification.class, null, null, null, null);
|
537
|
Classification defaultClassification = null;
|
538
|
for (Classification c : list) {
|
539
|
if(c.getUuid()!=classificationUUID){
|
540
|
defaultClassification = c;
|
541
|
}
|
542
|
}
|
543
|
assertEquals(1, classification.getAllNodes().size());
|
544
|
assertEquals(2, defaultClassification.getAllNodes().size());
|
545
|
|
546
|
}
|
547
|
|
548
|
|
549
|
/**
|
550
|
* Test should NOT create new taxa of the same name but have different authors.
|
551
|
*/
|
552
|
@Test
|
553
|
@DataSets({
|
554
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"),
|
555
|
@DataSet( value="SpecimenImportConfiguratorTest.testIgnoreAuthorship.xml")
|
556
|
})
|
557
|
public void testIgnoreAuthorship(){
|
558
|
UUID taxonUUID = UUID.fromString("26f98a58-09ab-49a0-ab9f-7490757c86d2");
|
559
|
UUID classificationUUID = UUID.fromString("eee32748-5b89-4266-a99a-1edb3781d0eb");
|
560
|
|
561
|
// Classification classification = Classification.NewInstance("Checklist");
|
562
|
// classification.setUuid(classificationUUID);
|
563
|
//
|
564
|
// Reference<?> secReference = ReferenceFactory.newGeneric();
|
565
|
// Team team = Team.NewTitledInstance("different author", "different author");
|
566
|
// secReference.setAuthorship(team);
|
567
|
//
|
568
|
// INonViralName taxonName = TaxonNameFactory.NewNonViralInstance(Rank.VARIETY());
|
569
|
// taxonName.setGenusOrUninomial("Campanula");
|
570
|
// taxonName.setSpecificEpithet("versicolor");
|
571
|
// taxonName.setInfraSpecificEpithet("tomentella");
|
572
|
//
|
573
|
// Taxon taxon = Taxon.NewInstance(taxonName, secReference);
|
574
|
// taxon.setUuid(taxonUUID);
|
575
|
//
|
576
|
// classification.addChildTaxon(taxon, secReference, "");
|
577
|
//
|
578
|
// taxonService.save(taxon);
|
579
|
// nameService.save(taxonName);
|
580
|
// referenceService.save(secReference);
|
581
|
//
|
582
|
// commitAndStartNewTransaction(null);
|
583
|
//
|
584
|
// setComplete();
|
585
|
// endTransaction();
|
586
|
//
|
587
|
//
|
588
|
// try {
|
589
|
// writeDbUnitDataSetFile(new String[] {
|
590
|
// "SpecimenOrObservationBase",
|
591
|
// "SpecimenOrObservationBase_DerivationEvent",
|
592
|
// "DerivationEvent",
|
593
|
// "DescriptionElementBase",
|
594
|
// "DescriptionBase",
|
595
|
// "TaxonBase",
|
596
|
// "TypeDesignationBase",
|
597
|
// "TaxonName",
|
598
|
// "TaxonName_TypeDesignationBase",
|
599
|
// "HomotypicalGroup",
|
600
|
// "AgentBase",
|
601
|
// "AgentBase_AgentBase",
|
602
|
// "Reference",
|
603
|
// "TaxonNode",
|
604
|
// "Classification",
|
605
|
// "LanguageString"
|
606
|
// }, "testIgnoreAuthorship");
|
607
|
// } catch (FileNotFoundException e) {
|
608
|
// e.printStackTrace();
|
609
|
// }
|
610
|
|
611
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_B_10_0066577.xml";
|
612
|
URL url = this.getClass().getResource(inputFile);
|
613
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
614
|
|
615
|
Abcd206ImportConfigurator importConfigurator = null;
|
616
|
try {
|
617
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
618
|
} catch (URISyntaxException e) {
|
619
|
e.printStackTrace();
|
620
|
Assert.fail();
|
621
|
}
|
622
|
assertNotNull("Configurator could not be created", importConfigurator);
|
623
|
|
624
|
//test initial state
|
625
|
Taxon taxon = (Taxon) taxonService.load(taxonUUID);
|
626
|
assertNotNull(taxon);
|
627
|
Classification classification = classificationService.load(classificationUUID);
|
628
|
assertNotNull(classification);
|
629
|
assertEquals(1, classificationService.count(Classification.class));
|
630
|
assertEquals(1, classification.getAllNodes().size());//taxon node
|
631
|
assertEquals(2, taxonNodeService.count(TaxonNode.class));//root node + Taxon node = 2 nodes
|
632
|
|
633
|
importConfigurator.setIgnoreAuthorship(true);
|
634
|
importConfigurator.setClassificationUuid(classificationUUID);
|
635
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
636
|
assertTrue("Return value for import.invoke should be true", result);
|
637
|
|
638
|
assertEquals(1, classificationService.count(Classification.class));
|
639
|
assertEquals(1, classification.getAllNodes().size());//taxon node
|
640
|
assertEquals(2, taxonNodeService.count(TaxonNode.class));//root node + Taxon node = 2 nodes
|
641
|
|
642
|
}
|
643
|
|
644
|
/**
|
645
|
* Imports two DNA units belonging to the same taxon into an existing
|
646
|
* classification. The taxon is not part of the classification so the
|
647
|
* default classification will be created. The result should be:
|
648
|
* existing classification (0 taxa), default classification (2 taxa [genus+species])
|
649
|
*/
|
650
|
@Test
|
651
|
@DataSets({
|
652
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
653
|
@DataSet("/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
|
654
|
@DataSet( value="SpecimenImportConfiguratorTest.testImportTwoUnitsOfSameTaxonIntoExistingClassification.xml")
|
655
|
})
|
656
|
public void testImportTwoUnitsOfSameTaxonIntoExistingClassification(){
|
657
|
UUID classificationUUID = UUID.fromString("18d22d00-5f70-4c8e-a1ed-dc45fae5b816");
|
658
|
|
659
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_barbata.xml";
|
660
|
URL url = this.getClass().getResource(inputFile);
|
661
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
662
|
|
663
|
Abcd206ImportConfigurator importConfigurator = null;
|
664
|
try {
|
665
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
666
|
} catch (URISyntaxException e) {
|
667
|
e.printStackTrace();
|
668
|
Assert.fail();
|
669
|
}
|
670
|
assertNotNull("Configurator could not be created", importConfigurator);
|
671
|
|
672
|
//test initial state
|
673
|
Classification classification = classificationService.load(classificationUUID);
|
674
|
assertNotNull(classification);
|
675
|
assertEquals(0, classification.getAllNodes().size());
|
676
|
assertEquals(1, classificationService.count(Classification.class));
|
677
|
|
678
|
|
679
|
importConfigurator.setIgnoreAuthorship(true);
|
680
|
importConfigurator.setClassificationUuid(classificationUUID);
|
681
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
682
|
assertTrue("Return value for import.invoke should be true", result);
|
683
|
|
684
|
assertEquals(0, classification.getAllNodes().size());
|
685
|
assertEquals(2, classificationService.count(Classification.class));
|
686
|
|
687
|
Classification defaultClassification = null;
|
688
|
for (Classification c : classificationService.list(Classification.class, null, null, null, null)) {
|
689
|
if(!c.getUuid().equals(classificationUUID)){
|
690
|
defaultClassification = c;
|
691
|
}
|
692
|
}
|
693
|
assertNotNull(defaultClassification);
|
694
|
Set<TaxonNode> allNodes = defaultClassification.getAllNodes();
|
695
|
for (TaxonNode node:allNodes){
|
696
|
System.out.println(node.getTaxon().getTitleCache());
|
697
|
}
|
698
|
|
699
|
assertEquals(3, defaultClassification.getAllNodes().size());
|
700
|
|
701
|
}
|
702
|
|
703
|
/**
|
704
|
* Tests import of unit belonging to a taxon with a non-parsable name. Since
|
705
|
* no rank can be deduced from the name there will be no taxon hierarchy
|
706
|
* created but only the single taxon
|
707
|
*
|
708
|
* @throws ParseException
|
709
|
*/
|
710
|
@Test
|
711
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
712
|
public void testImportNonParsableName() {
|
713
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_americana.xml";
|
714
|
URL url = this.getClass().getResource(inputFile);
|
715
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
716
|
|
717
|
Abcd206ImportConfigurator importConfigurator = null;
|
718
|
try {
|
719
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
720
|
} catch (URISyntaxException e) {
|
721
|
e.printStackTrace();
|
722
|
Assert.fail();
|
723
|
}
|
724
|
assertNotNull("Configurator could not be created", importConfigurator);
|
725
|
|
726
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
727
|
assertTrue("Return value for import.invoke should be true", result);
|
728
|
assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
|
729
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
730
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
731
|
taxonNodeService.list(TaxonNode.class, null, null, null, null);
|
732
|
occurrenceService.list(SpecimenOrObservationBase.class, null, null, null, null);
|
733
|
/*
|
734
|
* Default classification
|
735
|
* - Campanula ..g... americana --- hort. ttt ex Steud.
|
736
|
*/
|
737
|
assertEquals("Number of taxon nodes is incorrect", 2, taxonNodeService.count(TaxonNode.class));
|
738
|
assertEquals("Number of taxa is incorrect", 1, taxonService.count(TaxonBase.class));
|
739
|
assertEquals(1, taxonService.findByTitleWithRestrictions(Taxon.class, "Campanula ..g... americana --- hort. ttt ex Steud.", MatchMode.ANYWHERE, null, null, null, null, null).getRecords().size());
|
740
|
}
|
741
|
|
742
|
@Test
|
743
|
@Ignore
|
744
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
745
|
public void testSetUnitIDAsBarcode() {
|
746
|
|
747
|
}
|
748
|
|
749
|
@Override
|
750
|
// @Test
|
751
|
public void createTestDataSet() throws FileNotFoundException {
|
752
|
UUID classificationUUID = UUID.fromString("18d22d00-5f70-4c8e-a1ed-dc45fae5b816");
|
753
|
|
754
|
Classification classification = Classification.NewInstance("Checklist");
|
755
|
classification.setUuid(classificationUUID);
|
756
|
|
757
|
classificationService.save(classification);
|
758
|
|
759
|
commitAndStartNewTransaction(null);
|
760
|
|
761
|
setComplete();
|
762
|
endTransaction();
|
763
|
|
764
|
|
765
|
try {
|
766
|
writeDbUnitDataSetFile(new String[] {
|
767
|
"SpecimenOrObservationBase",
|
768
|
"SpecimenOrObservationBase_DerivationEvent",
|
769
|
"DerivationEvent",
|
770
|
"DescriptionElementBase",
|
771
|
"DescriptionBase",
|
772
|
"TaxonBase",
|
773
|
"TypeDesignationBase",
|
774
|
"TaxonName",
|
775
|
"TaxonName_TypeDesignationBase",
|
776
|
"HomotypicalGroup",
|
777
|
"AgentBase",
|
778
|
"AgentBase_AgentBase",
|
779
|
"Reference",
|
780
|
"TaxonNode",
|
781
|
"Classification",
|
782
|
"LanguageString"
|
783
|
}, "testImportTwoUnitsOfSameTaxonIntoExistingClassification", true);
|
784
|
} catch (FileNotFoundException e) {
|
785
|
e.printStackTrace();
|
786
|
}
|
787
|
}
|
788
|
}
|