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
|
package eu.etaxonomy.cdm.io.specimen.abcd206.in;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotNull;
|
13
|
import static org.junit.Assert.assertTrue;
|
14
|
|
15
|
import java.io.FileNotFoundException;
|
16
|
import java.net.URISyntaxException;
|
17
|
import java.net.URL;
|
18
|
import java.text.ParseException;
|
19
|
import java.util.Collection;
|
20
|
import java.util.List;
|
21
|
import java.util.Set;
|
22
|
import java.util.UUID;
|
23
|
|
24
|
import org.joda.time.DateTime;
|
25
|
import org.junit.Assert;
|
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.IOccurrenceService;
|
34
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
35
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
36
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
37
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
38
|
import eu.etaxonomy.cdm.api.service.config.FindOccurrencesConfigurator;
|
39
|
import eu.etaxonomy.cdm.common.URI;
|
40
|
import eu.etaxonomy.cdm.io.common.CdmApplicationAwareDefaultImport;
|
41
|
import eu.etaxonomy.cdm.model.media.MediaUtils;
|
42
|
import eu.etaxonomy.cdm.model.molecular.Amplification;
|
43
|
import eu.etaxonomy.cdm.model.molecular.AmplificationResult;
|
44
|
import eu.etaxonomy.cdm.model.molecular.DnaQuality;
|
45
|
import eu.etaxonomy.cdm.model.molecular.DnaSample;
|
46
|
import eu.etaxonomy.cdm.model.molecular.Primer;
|
47
|
import eu.etaxonomy.cdm.model.molecular.Sequence;
|
48
|
import eu.etaxonomy.cdm.model.molecular.SequenceDirection;
|
49
|
import eu.etaxonomy.cdm.model.molecular.SequenceString;
|
50
|
import eu.etaxonomy.cdm.model.molecular.SingleRead;
|
51
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
|
52
|
import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
|
53
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
54
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
55
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
56
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
|
57
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
58
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
59
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
60
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
61
|
import eu.etaxonomy.cdm.model.term.DefinedTerm;
|
62
|
import eu.etaxonomy.cdm.persistence.query.MatchMode;
|
63
|
import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
|
64
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
65
|
|
66
|
/**
|
67
|
* @author a.mueller
|
68
|
* @since 29.01.2009
|
69
|
*/
|
70
|
public class AbcdGgbnImportTest extends CdmTransactionalIntegrationTest {
|
71
|
|
72
|
@SpringBeanByName
|
73
|
private CdmApplicationAwareDefaultImport<?> defaultImport;
|
74
|
|
75
|
@SpringBeanByType
|
76
|
private IOccurrenceService occurrenceService;
|
77
|
|
78
|
@SpringBeanByType
|
79
|
private IReferenceService referenceService;
|
80
|
|
81
|
@SpringBeanByType
|
82
|
private ITermService termService;
|
83
|
|
84
|
@SpringBeanByType
|
85
|
private ITaxonService taxonService;
|
86
|
|
87
|
@SpringBeanByType
|
88
|
private ITaxonNodeService taxonNodeService;
|
89
|
|
90
|
/**
|
91
|
* Tests import import of two DNA unit belonging to two different taxa
|
92
|
* @throws ParseException
|
93
|
*/
|
94
|
@Test
|
95
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
96
|
public void testImportTwoDnaUnitsWithTwoTaxa() throws ParseException {
|
97
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_2taxa.xml";
|
98
|
URL url = this.getClass().getResource(inputFile);
|
99
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
100
|
|
101
|
Abcd206ImportConfigurator importConfigurator = null;
|
102
|
try {
|
103
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
104
|
importConfigurator.setGetSiblings(false);
|
105
|
} catch (URISyntaxException e) {
|
106
|
e.printStackTrace();
|
107
|
Assert.fail();
|
108
|
}
|
109
|
assertNotNull("Configurator could not be created", importConfigurator);
|
110
|
|
111
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
112
|
assertTrue("Return value for import.invoke should be true", result);
|
113
|
assertEquals("Number of derived units is incorrect", 4, occurrenceService.count(DerivedUnit.class));
|
114
|
assertEquals("Number of dna samples is incorrect", 2, occurrenceService.count(DnaSample.class));
|
115
|
assertEquals("Number of field units is incorrect", 2, occurrenceService.count(FieldUnit.class));
|
116
|
/*
|
117
|
* Default classification
|
118
|
* - Campanula
|
119
|
* - Campanula glomerata
|
120
|
* - Campanula bononiensis
|
121
|
*/
|
122
|
List<TaxonNode> nodes = taxonNodeService.list(TaxonNode.class, 100, 0, null, null);
|
123
|
// TODO: this needs to be fixed, the sortindex should never be -1
|
124
|
for (TaxonNode node: nodes){
|
125
|
if (node.getTaxon() != null){
|
126
|
assertTrue("The sortindex should not be smaller than 0", node.getSortIndex() > -1 );
|
127
|
}
|
128
|
}
|
129
|
assertEquals("Number of taxon nodes is incorrect", 4, taxonNodeService.count(TaxonNode.class));
|
130
|
assertEquals("Number of taxa is incorrect", 3, taxonService.count(TaxonBase.class));
|
131
|
assertEquals(1, taxonService.findByTitleWithRestrictions(Taxon.class, "Campanula bononiensis", MatchMode.ANYWHERE, null, null, null, null, null).getRecords().size());
|
132
|
assertEquals(1, taxonService.findByTitleWithRestrictions(Taxon.class, "Campanula isaurica", MatchMode.ANYWHERE, null, null, null, null, null).getRecords().size());
|
133
|
|
134
|
//test for sortindex=-1
|
135
|
|
136
|
|
137
|
}
|
138
|
|
139
|
/**
|
140
|
* Added this test because there was a unique key on the citations_id column of table
|
141
|
* SEQUENCE_REFERENCE which makes no sense.
|
142
|
*/
|
143
|
@Test
|
144
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
145
|
public void testImportTwoSequencesWithSameReference() {
|
146
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_DNA_CAM_90-91.xml";
|
147
|
URL url = this.getClass().getResource(inputFile);
|
148
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
149
|
|
150
|
Abcd206ImportConfigurator importConfigurator = null;
|
151
|
try {
|
152
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
153
|
} catch (URISyntaxException e) {
|
154
|
e.printStackTrace();
|
155
|
Assert.fail();
|
156
|
}
|
157
|
assertNotNull("Configurator could not be created", importConfigurator);
|
158
|
|
159
|
importConfigurator.setMapUnitIdToCatalogNumber(true);
|
160
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
161
|
assertTrue("Return value for import.invoke should be true", result);
|
162
|
}
|
163
|
|
164
|
/**
|
165
|
* Tests import import of 59 DNA unit
|
166
|
*/
|
167
|
@Test
|
168
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
169
|
@Ignore //TODO this test takes very long therefore I keep it on ignore, also it fails as the
|
170
|
//derived unit count returns 117 not 118 as assumed; this needs to be fixed and we have to check
|
171
|
//why importing 59 units takes so long
|
172
|
public void testImport59Units() {
|
173
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/Campanula_59taxa.xml";
|
174
|
URL url = this.getClass().getResource(inputFile);
|
175
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
176
|
|
177
|
Abcd206ImportConfigurator importConfigurator = null;
|
178
|
try {
|
179
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
180
|
} catch (URISyntaxException e) {
|
181
|
e.printStackTrace();
|
182
|
Assert.fail();
|
183
|
}
|
184
|
assertNotNull("Configurator could not be created", importConfigurator);
|
185
|
|
186
|
importConfigurator.setIgnoreAuthorship(true);
|
187
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
188
|
// assertTrue("Return value for import.invoke should be true", result);
|
189
|
assertEquals("Number of derived units is incorrect", 118, occurrenceService.count(DerivedUnit.class));
|
190
|
assertEquals("Number of dna samples is incorrect", 59, occurrenceService.count(DnaSample.class));
|
191
|
}
|
192
|
|
193
|
/**
|
194
|
* Tests import import of DNA unit and all its parameters
|
195
|
* and sub derivatives (sequence, amplification, etc.)
|
196
|
* @throws ParseException
|
197
|
*/
|
198
|
@Test
|
199
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
200
|
public void testImportGgbn() throws ParseException {
|
201
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_without_association.xml";
|
202
|
URL url = this.getClass().getResource(inputFile);
|
203
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
204
|
|
205
|
Abcd206ImportConfigurator importConfigurator = null;
|
206
|
try {
|
207
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
208
|
} catch (URISyntaxException e) {
|
209
|
e.printStackTrace();
|
210
|
Assert.fail();
|
211
|
}
|
212
|
assertNotNull("Configurator could not be created", importConfigurator);
|
213
|
|
214
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
215
|
assertTrue("Return value for import.invoke should be true", result);
|
216
|
assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
|
217
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
218
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
219
|
|
220
|
//dna sample
|
221
|
FindOccurrencesConfigurator dnaConfig = new FindOccurrencesConfigurator();
|
222
|
dnaConfig.setSignificantIdentifier("DB 6");
|
223
|
List<SpecimenOrObservationBase> dnaRecords = occurrenceService.findByTitle(dnaConfig).getRecords();
|
224
|
assertEquals(1, dnaRecords.size());
|
225
|
SpecimenOrObservationBase dnaSpecimen = dnaRecords.iterator().next();
|
226
|
assertEquals(DnaSample.class, dnaSpecimen.getClass());
|
227
|
DnaSample dnaSample = (DnaSample) dnaSpecimen;
|
228
|
DerivationEvent derivedFrom = dnaSample.getDerivedFrom();
|
229
|
assertNotNull(derivedFrom);
|
230
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), derivedFrom.getType());
|
231
|
assertEquals("Wrong number of originals", 1, derivedFrom.getOriginals().size());
|
232
|
assertTrue(derivedFrom.getOriginals().iterator().next() instanceof FieldUnit);
|
233
|
assertEquals("DNA Bank", dnaSample.getCollection().getCode());
|
234
|
assertEquals(SpecimenOrObservationType.DnaSample, dnaSample.getRecordBasis());
|
235
|
//preservation/preparation
|
236
|
assertNotNull(derivedFrom.getActor());
|
237
|
assertEquals("Bansemer, Jana", derivedFrom.getActor().getTitleCache());
|
238
|
assertNotNull(derivedFrom.getTimeperiod());
|
239
|
assertEquals((Integer)2002,derivedFrom.getTimeperiod().getStartYear());
|
240
|
assertEquals((Integer)8,derivedFrom.getTimeperiod().getStartMonth());
|
241
|
assertEquals((Integer)13,derivedFrom.getTimeperiod().getStartDay());
|
242
|
assertNotNull(dnaSample.getPreservation());
|
243
|
assertEquals("DNeasy Plant Mini Spin Kit Qiagen", derivedFrom.getDescription());
|
244
|
//sample designation
|
245
|
Set<String> identifiers = dnaSample.getIdentifiers((DefinedTerm) termService.find(UUID.fromString("fadeba12-1be3-4bc7-9ff5-361b088d86fc")));
|
246
|
assertNotNull(identifiers);
|
247
|
assertEquals(1, identifiers.size());
|
248
|
assertEquals("CAM010", identifiers.iterator().next());
|
249
|
|
250
|
|
251
|
//dna quality
|
252
|
DnaQuality dnaQuality = dnaSample.getDnaQuality();
|
253
|
assertNotNull("Dna quality is null", dnaQuality!=null);
|
254
|
assertEquals(new Double("0.77"),dnaQuality.getRatioOfAbsorbance260_230());
|
255
|
assertEquals(new Double("1.38"),dnaQuality.getRatioOfAbsorbance260_280());
|
256
|
assertEquals(new DateTime(2008, 4, 15, 0, 0),dnaQuality.getQualityCheckDate());
|
257
|
// assertEquals(MeasurementUnit.NewInstance(, label, labelAbbrev)DateTime(2008, 4, 15, 0, 0),dnaQuality.getQualityCheckDate());
|
258
|
|
259
|
//amplifications
|
260
|
Set<AmplificationResult> amplificationResults = dnaSample.getAmplificationResults();
|
261
|
assertNotNull(amplificationResults);
|
262
|
assertEquals(1, amplificationResults.size());
|
263
|
AmplificationResult amplificationResult = amplificationResults.iterator().next();
|
264
|
Amplification amplification = amplificationResult.getAmplification();
|
265
|
assertNotNull("Amplification is null", amplification);
|
266
|
DefinedTerm dnaMarker = amplification.getDnaMarker();
|
267
|
assertNotNull(dnaMarker);
|
268
|
assertEquals("ITS (ITS1, 5.8S rRNA, ITS2)", dnaMarker.getLabel());
|
269
|
|
270
|
//amplification primers
|
271
|
Primer forwardPrimer = amplification.getForwardPrimer();
|
272
|
assertNotNull(forwardPrimer);
|
273
|
assertEquals("PIpetB1411F", forwardPrimer.getLabel());
|
274
|
assertEquals("5´-GCCGTMTTTATGTTAATGC-3´", forwardPrimer.getSequence().getString());
|
275
|
assertNotNull(forwardPrimer.getPublishedIn());
|
276
|
assertEquals("Löhne & Borsch 2005", forwardPrimer.getPublishedIn().getTitle());
|
277
|
|
278
|
Primer reversePrimer = amplification.getReversePrimer();
|
279
|
assertNotNull(reversePrimer);
|
280
|
assertEquals("PIpetD738R", reversePrimer.getLabel());
|
281
|
assertEquals("5´-AATTTAGCYCTTAATACAGG-3´", reversePrimer.getSequence().getString());
|
282
|
|
283
|
//sequencing
|
284
|
Set<Sequence> sequences = dnaSample.getSequences();
|
285
|
assertNotNull(sequences);
|
286
|
assertEquals(1, sequences.size());
|
287
|
Sequence sequence = sequences.iterator().next();
|
288
|
SequenceString consensusSequence = sequence.getConsensusSequence();
|
289
|
assertNotNull(consensusSequence);
|
290
|
assertEquals(
|
291
|
"TTTCGGGTCC TTTATAGTGA AGATATAGCA TAGATAGTTG TAATCCATTA" +
|
292
|
" TGTATCATTG GGGAAGGAAG GAGAATATTT TTTTGATAGA ATACAAGTAT" +
|
293
|
" GGATTATTGA AACTAATACG CCATGTATTT GGATATTTCC CTTGAACTGC" +
|
294
|
" ATAATATTCT TTATTTTCCA TGAATAGTGT AAGGGAATTT TTCGAAGAGA" +
|
295
|
" AAATGGATTA TGGGAGTGTG TGACTTGAGC TATTGATTGG TCTGTGCAGA" +
|
296
|
" TACGGGCTTT TATCTATCTG CCACATTGTA ATTCACAAAC CAATGTGTCT" +
|
297
|
" TTGTTCCAAC CATCGCGTAA GCCCCATACA GAAGATAGGC TGGTTCGCTT" +
|
298
|
" GAAGAGAATC TTTTCTATGA TCAGATCCGA ATTATGTCGT ACATGAGCAG" +
|
299
|
" GCTCCGTAAG ATCTAGTTGA CTTAAGTCAA ACTTCAATAG TATAAAAATG" +
|
300
|
" CACTCATTTC CTCTGCATTG ACACGAGCTA TGAGACTATC GGAGTGAAAG" +
|
301
|
" AAAGGGTCTA AAGAAGAAGA AAGCTTGGGC TAGATTAGTA ACAAGTAAAT" +
|
302
|
" CCTTTGTGTG TGTGTTTGTA ATTAGTAAAT GGGCTCTCAA TATTTTGGGG" +
|
303
|
" CTAATTACTG ATCCTAAGGT TTGAGACGAC CCAGAAAGCA CTTGATCATA" +
|
304
|
" TCACGATTGA CTTTGTAAGC CTACTTGGGT ATTGAGTATT TACTTGTAAG" +
|
305
|
" AACCGAATTC TTTGGGGGAT AGTTGCAAAA AGAATCCAGT CAATTGTTCT" +
|
306
|
" TACGTAAAAC CATTCATATC TCGTATATGG ATATGTCTAG ATAGGCTATC" +
|
307
|
" GATTTTCGAT GGATTCGTTT GGTTCTTTTG ATTATTGCTC GAGCTGGATG" +
|
308
|
" ATGAAAAATT ATCATGTCCG GTTCCTTCG",consensusSequence.getString());
|
309
|
// assertEquals((Integer)912, consensusSequence.getLength());
|
310
|
assertNotNull(sequence.getContigFile());
|
311
|
assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_Campa_drabifolia.pde"), MediaUtils.getFirstMediaRepresentationPart(sequence.getContigFile()).getUri());
|
312
|
assertEquals(1, sequence.getCitations().size());
|
313
|
Reference reference = sequence.getCitations().iterator().next();
|
314
|
assertEquals("Gemeinholzer,B., Bachmann,K. (2005): Examining morphological "
|
315
|
+ "and molecular diagnostic character states in "
|
316
|
+ "Cichorium intybus L. (Asteraceae) and Cichorium spinosum L."
|
317
|
+ " Plant Systematics and Evolution 253 (1-3): 105-123.", reference.getTitle());
|
318
|
|
319
|
//single reads
|
320
|
Set<SingleRead> singleReads = sequence.getSingleReads();
|
321
|
assertNotNull(singleReads);
|
322
|
assertEquals(2, singleReads.size());
|
323
|
for (SingleRead singleRead : singleReads) {
|
324
|
if(singleRead.getDirection().equals(SequenceDirection.Forward)){
|
325
|
assertNotNull(singleRead.getPherogram());
|
326
|
assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_GM312-petD_F.ab1"), MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri());
|
327
|
}
|
328
|
else{
|
329
|
assertNotNull(singleRead.getPherogram());
|
330
|
assertEquals(URI.create("http://ww2.biocase.org/websvn/filedetails.php?repname=campanula&path=%2FCAM385_GM312-petD_R.ab1"), MediaUtils.getFirstMediaRepresentationPart(singleRead.getPherogram()).getUri());
|
331
|
}
|
332
|
}
|
333
|
assertNotNull(amplificationResult.getSingleReads());
|
334
|
assertEquals(amplificationResult.getSingleReads(), singleReads);
|
335
|
|
336
|
|
337
|
}
|
338
|
|
339
|
/**
|
340
|
* Tests import of DNA unit which is associated to a specimen being its parent derivative
|
341
|
* @throws ParseException
|
342
|
*/
|
343
|
@Test
|
344
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
345
|
public void testImportAssociatedSpecimenSameIndividual() throws ParseException {
|
346
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_parent_child_association.xml";
|
347
|
URL url = this.getClass().getResource(inputFile);
|
348
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
349
|
|
350
|
Abcd206ImportConfigurator importConfigurator = null;
|
351
|
try {
|
352
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
353
|
} catch (URISyntaxException e) {
|
354
|
e.printStackTrace();
|
355
|
Assert.fail();
|
356
|
}
|
357
|
assertNotNull("Configurator could not be created", importConfigurator);
|
358
|
|
359
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
360
|
assertTrue("Return value for import.invoke should be true", result);
|
361
|
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
|
362
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
363
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
364
|
|
365
|
//associated specimen
|
366
|
FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
|
367
|
config.setSignificantIdentifier("B 10 0066577");
|
368
|
List<SpecimenOrObservationBase> records = occurrenceService.findByTitle(config).getRecords();
|
369
|
assertEquals(1, records.size());
|
370
|
SpecimenOrObservationBase derivedUnitSpecimen = records.iterator().next();
|
371
|
assertEquals(DerivedUnit.class, derivedUnitSpecimen.getClass());
|
372
|
DerivedUnit specimen = (DerivedUnit) derivedUnitSpecimen;
|
373
|
assertEquals("Herbarium Berolinense", specimen.getCollection().getCode());
|
374
|
assertTrue(SpecimenOrObservationType.DnaSample!=specimen.getRecordBasis());
|
375
|
|
376
|
//dna sample
|
377
|
FindOccurrencesConfigurator dnaConfig = new FindOccurrencesConfigurator();
|
378
|
dnaConfig.setSignificantIdentifier("DB 6");
|
379
|
List<SpecimenOrObservationBase> dnaRecords = occurrenceService.findByTitle(dnaConfig).getRecords();
|
380
|
assertEquals(1, dnaRecords.size());
|
381
|
SpecimenOrObservationBase dnaSpecimen = dnaRecords.iterator().next();
|
382
|
assertEquals(DnaSample.class, dnaSpecimen.getClass());
|
383
|
DnaSample dnaSample = (DnaSample) dnaSpecimen;
|
384
|
DerivationEvent derivedFrom = dnaSample.getDerivedFrom();
|
385
|
assertNotNull(derivedFrom);
|
386
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), derivedFrom.getType());
|
387
|
assertEquals("Wrong number of originals", 1, derivedFrom.getOriginals().size());
|
388
|
assertTrue(derivedFrom.getOriginals().iterator().next() instanceof DerivedUnit);
|
389
|
assertEquals("DNA Bank", dnaSample.getCollection().getCode());
|
390
|
assertEquals(SpecimenOrObservationType.DnaSample, dnaSample.getRecordBasis());
|
391
|
}
|
392
|
|
393
|
/**
|
394
|
* Tests import of DNA unit which is associated to a specimen being its sibling
|
395
|
* by having the same field unit
|
396
|
*/
|
397
|
@Test
|
398
|
@DataSet( value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
399
|
// @Ignore
|
400
|
public void testImportAssociatedSpecimenSamePopulation() throws ParseException {
|
401
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_sibling_association.xml";
|
402
|
URL url = this.getClass().getResource(inputFile);
|
403
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
404
|
|
405
|
Abcd206ImportConfigurator importConfigurator = null;
|
406
|
try {
|
407
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
408
|
} catch (URISyntaxException e) {
|
409
|
e.printStackTrace();
|
410
|
Assert.fail();
|
411
|
}
|
412
|
assertNotNull("Configurator could not be created", importConfigurator);
|
413
|
|
414
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
415
|
assertTrue("Return value for import.invoke should be true", result);
|
416
|
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
|
417
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
418
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
419
|
|
420
|
//associated specimen
|
421
|
FindOccurrencesConfigurator config = new FindOccurrencesConfigurator();
|
422
|
config.setSignificantIdentifier("B 10 0066577");
|
423
|
List<SpecimenOrObservationBase> records = occurrenceService.findByTitle(config).getRecords();
|
424
|
assertEquals(1, records.size());
|
425
|
SpecimenOrObservationBase<?> derivedUnitSpecimen = records.iterator().next();
|
426
|
assertEquals(DerivedUnit.class, derivedUnitSpecimen.getClass());
|
427
|
DerivedUnit specimen = (DerivedUnit) derivedUnitSpecimen;
|
428
|
assertEquals("Herbarium Berolinense", specimen.getCollection().getCode());
|
429
|
assertTrue(SpecimenOrObservationType.DnaSample!=specimen.getRecordBasis());
|
430
|
|
431
|
//dna sample
|
432
|
FindOccurrencesConfigurator dnaConfig = new FindOccurrencesConfigurator();
|
433
|
dnaConfig.setSignificantIdentifier("DB 6");
|
434
|
List<SpecimenOrObservationBase> dnaRecords = occurrenceService.findByTitle(dnaConfig).getRecords();
|
435
|
assertEquals(1, dnaRecords.size());
|
436
|
SpecimenOrObservationBase<?> dnaSpecimen = dnaRecords.iterator().next();
|
437
|
assertEquals(DnaSample.class, dnaSpecimen.getClass());
|
438
|
DnaSample dnaSample = (DnaSample) dnaSpecimen;
|
439
|
DerivationEvent derivedFrom = dnaSample.getDerivedFrom();
|
440
|
assertNotNull(derivedFrom);
|
441
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), derivedFrom.getType());
|
442
|
assertEquals("Wrong number of originals", 1, derivedFrom.getOriginals().size());
|
443
|
//TODO
|
444
|
//assertTrue(derivedFrom.getOriginals().iterator().next() instanceof FieldUnit);
|
445
|
assertEquals("DNA Bank", dnaSample.getCollection().getCode());
|
446
|
assertEquals(SpecimenOrObservationType.DnaSample, dnaSample.getRecordBasis());
|
447
|
|
448
|
//TODO field unit
|
449
|
}
|
450
|
|
451
|
/**
|
452
|
* Tests import of DNA unit and attaching it to an existing specimen to
|
453
|
* which it has a parent-child UnitAssociation. The derived unit should not
|
454
|
* be imported because it already exists in the data base. The field unit
|
455
|
* should not be overwritten by the FieldUnit of the DnaSample.
|
456
|
*/
|
457
|
@Test
|
458
|
@DataSets({
|
459
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"),
|
460
|
@DataSet( value="AbcdGgbnImportTest.testAttachDnaSampleToDerivedUnit.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
461
|
})
|
462
|
public void testAttachDnaSampleToExistingDerivedUnit_parentChild(){
|
463
|
UUID fieldUnit1Uuid = UUID.fromString("0f896630-48d6-4352-9c91-278be28ce19c");
|
464
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
465
|
|
466
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_parent_child_association.xml";
|
467
|
URL url = this.getClass().getResource(inputFile);
|
468
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
469
|
|
470
|
Abcd206ImportConfigurator importConfigurator = null;
|
471
|
try {
|
472
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
473
|
} catch (URISyntaxException e) {
|
474
|
e.printStackTrace();
|
475
|
Assert.fail();
|
476
|
}
|
477
|
assertNotNull("Configurator could not be created", importConfigurator);
|
478
|
|
479
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
480
|
assertTrue("Return value for import.invoke should be true", result);occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
481
|
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
|
482
|
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
483
|
assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
|
484
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
485
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
486
|
|
487
|
|
488
|
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
|
489
|
assertTrue(derivedUnits.contains(derivedUnit));
|
490
|
|
491
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
492
|
DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
|
493
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
|
494
|
|
495
|
assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
|
496
|
|
497
|
FieldUnit specimenFieldUnit = (FieldUnit) occurrenceService.load(fieldUnit1Uuid);
|
498
|
Collection<FieldUnit> fieldUnits = occurrenceService.findFieldUnits(dnaSample.getUuid(), null);
|
499
|
assertEquals(1, fieldUnits.size());
|
500
|
FieldUnit dnaSampleFieldUnit = fieldUnits.iterator().next();
|
501
|
assertEquals(specimenFieldUnit, dnaSampleFieldUnit);
|
502
|
assertEquals("fieldUnit1", dnaSampleFieldUnit.getTitleCache());
|
503
|
|
504
|
}
|
505
|
|
506
|
/**
|
507
|
* Tests import of DNA unit and attaching it to an existing specimen to which
|
508
|
* it has a sibling UnitAssociation. The derived unit should not be imported because it already exists in the data base.
|
509
|
* The DnaSample should be attached to the existing FieldUnit of the DerivedUnit
|
510
|
*/
|
511
|
@Test
|
512
|
@DataSets({
|
513
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"),
|
514
|
@DataSet( value="AbcdGgbnImportTest.testAttachDnaSampleToDerivedUnit.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
515
|
})
|
516
|
public void testAttachDnaSampleToExistingDerivedUnit_sibling(){
|
517
|
UUID fieldUnit1Uuid = UUID.fromString("0f896630-48d6-4352-9c91-278be28ce19c");
|
518
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
519
|
|
520
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_parent_child_association.xml";
|
521
|
URL url = this.getClass().getResource(inputFile);
|
522
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
523
|
|
524
|
Abcd206ImportConfigurator importConfigurator = null;
|
525
|
try {
|
526
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
527
|
} catch (URISyntaxException e) {
|
528
|
e.printStackTrace();
|
529
|
Assert.fail();
|
530
|
}
|
531
|
assertNotNull("Configurator could not be created", importConfigurator);
|
532
|
|
533
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
534
|
assertTrue("Return value for import.invoke should be true", result);
|
535
|
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
536
|
for (DerivedUnit derivedUnit:derivedUnits){
|
537
|
System.out.println(derivedUnit.getTitleCache());
|
538
|
}
|
539
|
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
|
540
|
// List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
541
|
|
542
|
List<FieldUnit> fieldUnitsTemp = occurrenceService.list(FieldUnit.class, null, null, null, null);
|
543
|
assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
|
544
|
|
545
|
assertEquals("Number of field units is incorrect", 1, occurrenceService.count(FieldUnit.class));
|
546
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
547
|
|
548
|
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
|
549
|
assertTrue(derivedUnits.contains(derivedUnit));
|
550
|
|
551
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
552
|
DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
|
553
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
|
554
|
|
555
|
assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
|
556
|
FieldUnit specimenFieldUnit = (FieldUnit) occurrenceService.load(fieldUnit1Uuid);
|
557
|
Collection<FieldUnit> fieldUnits = occurrenceService.findFieldUnits(dnaSample.getUuid(), null);
|
558
|
assertEquals(1, fieldUnits.size());
|
559
|
FieldUnit dnaSampleFieldUnit = fieldUnits.iterator().next();
|
560
|
assertEquals(specimenFieldUnit, dnaSampleFieldUnit);
|
561
|
assertEquals("fieldUnit1", dnaSampleFieldUnit.getTitleCache());
|
562
|
}
|
563
|
|
564
|
@Test
|
565
|
public void testAvoidDuplicateMolecularData(){
|
566
|
|
567
|
}
|
568
|
|
569
|
/**
|
570
|
* Tests importing of DNA unit with an ABCD with only few fields filled.
|
571
|
* Should just check that no NPEs occur when some fields are missing.
|
572
|
*/
|
573
|
@Test
|
574
|
@DataSets({
|
575
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
576
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml"),
|
577
|
})
|
578
|
public void testImportGgbnSparseData(){
|
579
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_sparse_data.xml";
|
580
|
URL url = this.getClass().getResource(inputFile);
|
581
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
582
|
|
583
|
Abcd206ImportConfigurator importConfigurator = null;
|
584
|
try {
|
585
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
586
|
} catch (URISyntaxException e) {
|
587
|
e.printStackTrace();
|
588
|
Assert.fail();
|
589
|
}
|
590
|
assertNotNull("Configurator could not be created", importConfigurator);
|
591
|
|
592
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
593
|
assertTrue("Return value for import.invoke should be true", result);
|
594
|
}
|
595
|
|
596
|
/**
|
597
|
* Tests importing of DNA unit without attaching it to an existing specimen.
|
598
|
* Creates a FieldUnit with an attached DnaSample.
|
599
|
*/
|
600
|
@Test
|
601
|
@DataSets({
|
602
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDBDataSet.xml"),
|
603
|
@DataSet( value="AbcdGgbnImportTest.testNoAttachDnaSampleToDerivedUnit.xml", loadStrategy=CleanSweepInsertLoadStrategy.class)
|
604
|
})
|
605
|
public void testNoAttachDnaSampleToDerivedUnit(){
|
606
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
607
|
UUID fieldUnit1Uuid = UUID.fromString("b5f58da5-4442-4001-9d13-33f41518b72a");
|
608
|
|
609
|
// DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
|
610
|
// derivedUnit.setAccessionNumber("B 10 0066577");
|
611
|
// derivedUnit.setTitleCache("testUnit1", true);
|
612
|
//
|
613
|
// derivedUnit.setUuid(derivedUnit1Uuid );
|
614
|
//
|
615
|
// occurrenceService.save(derivedUnit);
|
616
|
//
|
617
|
// commitAndStartNewTransaction(null);
|
618
|
//
|
619
|
// setComplete();
|
620
|
// endTransaction();
|
621
|
//
|
622
|
//
|
623
|
// try {
|
624
|
// writeDbUnitDataSetFile(new String[] {
|
625
|
// "SpecimenOrObservationBase",
|
626
|
// }, "testAttachDnaSampleToDerivedUnit");
|
627
|
// } catch (FileNotFoundException e) {
|
628
|
// e.printStackTrace();
|
629
|
// }
|
630
|
|
631
|
|
632
|
String inputFile = "/eu/etaxonomy/cdm/io/specimen/abcd206/in/db6_without_association.xml";
|
633
|
URL url = this.getClass().getResource(inputFile);
|
634
|
assertNotNull("URL for the test file '" + inputFile + "' does not exist", url);
|
635
|
|
636
|
Abcd206ImportConfigurator importConfigurator = null;
|
637
|
try {
|
638
|
importConfigurator = Abcd206ImportConfigurator.NewInstance(new URI(url), null,false);
|
639
|
} catch (URISyntaxException e) {
|
640
|
e.printStackTrace();
|
641
|
Assert.fail();
|
642
|
}
|
643
|
assertNotNull("Configurator could not be created", importConfigurator);
|
644
|
|
645
|
assertEquals("Number of derived units is incorrect", 1, occurrenceService.count(DerivedUnit.class));
|
646
|
boolean result = defaultImport.invoke(importConfigurator).isSuccess();
|
647
|
assertTrue("Return value for import.invoke should be true", result);
|
648
|
assertEquals("Number of derived units is incorrect", 2, occurrenceService.count(DerivedUnit.class));
|
649
|
List<DerivedUnit> derivedUnits = occurrenceService.list(DerivedUnit.class, null, null, null, null);
|
650
|
assertEquals("Number of derived units is incorrect", 2, derivedUnits.size());
|
651
|
assertEquals("Number of field units is incorrect", 2, occurrenceService.count(FieldUnit.class));
|
652
|
assertEquals("Number of dna samples is incorrect", 1, occurrenceService.count(DnaSample.class));
|
653
|
|
654
|
DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(derivedUnit1Uuid);
|
655
|
assertTrue(derivedUnits.contains(derivedUnit));
|
656
|
|
657
|
DnaSample dnaSample = occurrenceService.list(DnaSample.class, null, null, null, null).get(0);
|
658
|
assertEquals("Wrong derivation type!", DerivationEventType.DNA_EXTRACTION(), dnaSample.getDerivedFrom().getType());
|
659
|
|
660
|
assertEquals("Wrong number of originals", 1, dnaSample.getDerivedFrom().getOriginals().size());
|
661
|
FieldUnit specimenFieldUnit = (FieldUnit) occurrenceService.load(fieldUnit1Uuid);
|
662
|
SpecimenOrObservationBase<?> dnaSampleFieldUnit = dnaSample.getDerivedFrom().getOriginals().iterator().next();
|
663
|
assertTrue(!specimenFieldUnit.equals(dnaSampleFieldUnit));
|
664
|
|
665
|
}
|
666
|
|
667
|
@Override
|
668
|
public void createTestDataSet() throws FileNotFoundException {
|
669
|
UUID derivedUnit1Uuid = UUID.fromString("eb40cb0f-efb2-4985-819e-a9168f6d61fe");
|
670
|
|
671
|
DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
|
672
|
derivedUnit.setAccessionNumber("B 10 0066577");
|
673
|
derivedUnit.setTitleCache("testUnit1", true);
|
674
|
|
675
|
derivedUnit.setUuid(derivedUnit1Uuid );
|
676
|
|
677
|
occurrenceService.save(derivedUnit);
|
678
|
|
679
|
commitAndStartNewTransaction(null);
|
680
|
|
681
|
setComplete();
|
682
|
endTransaction();
|
683
|
|
684
|
try {
|
685
|
writeDbUnitDataSetFile(new String[] {
|
686
|
"SpecimenOrObservationBase",
|
687
|
}, "testAttachDnaSampleToDerivedUnit", true);
|
688
|
} catch (FileNotFoundException e) {
|
689
|
e.printStackTrace();
|
690
|
}
|
691
|
}
|
692
|
}
|