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