merge-update from trunk
[cdmlib.git] / cdmlib-services / src / test / java / eu / etaxonomy / cdm / api / service / OccurrenceServiceTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2014 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
9 */
10 package eu.etaxonomy.cdm.api.service;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertFalse;
14 import static org.junit.Assert.assertNotEquals;
15 import static org.junit.Assert.assertTrue;
16
17 import java.util.Set;
18 import java.util.UUID;
19
20 import org.apache.log4j.Logger;
21 import org.junit.Test;
22 import org.unitils.dbunit.annotation.DataSet;
23 import org.unitils.spring.annotation.SpringBeanByType;
24
25 import eu.etaxonomy.cdm.api.service.config.SpecimenDeleteConfigurator;
26 import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
27 import eu.etaxonomy.cdm.model.agent.Institution;
28 import eu.etaxonomy.cdm.model.agent.Person;
29 import eu.etaxonomy.cdm.model.common.DefinedTerm;
30 import eu.etaxonomy.cdm.model.common.IdentifiableSource;
31 import eu.etaxonomy.cdm.model.common.Language;
32 import eu.etaxonomy.cdm.model.common.TimePeriod;
33 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
34 import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
35 import eu.etaxonomy.cdm.model.description.TaxonDescription;
36 import eu.etaxonomy.cdm.model.location.Country;
37 import eu.etaxonomy.cdm.model.location.NamedArea;
38 import eu.etaxonomy.cdm.model.location.Point;
39 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
40 import eu.etaxonomy.cdm.model.molecular.DnaSample;
41 import eu.etaxonomy.cdm.model.molecular.Sequence;
42 import eu.etaxonomy.cdm.model.molecular.SingleRead;
43 import eu.etaxonomy.cdm.model.name.BotanicalName;
44 import eu.etaxonomy.cdm.model.name.Rank;
45 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
46 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
47 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
48 import eu.etaxonomy.cdm.model.occurrence.Collection;
49 import eu.etaxonomy.cdm.model.occurrence.DerivationEvent;
50 import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
51 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
52 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
53 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
54 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
55 import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
56 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
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.reference.ReferenceFactory;
61 import eu.etaxonomy.cdm.model.taxon.Taxon;
62 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
63 import eu.etaxonomy.cdm.test.integration.CdmTransactionalIntegrationTest;
64 import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
65
66 /**
67 * @author pplitzner
68 * @date 31.03.2014
69 *
70 */
71 public class OccurrenceServiceTest extends CdmTransactionalIntegrationTest {
72 @SuppressWarnings("unused")
73 private static final Logger logger = Logger.getLogger(OccurrenceServiceTest.class);
74
75 @SpringBeanByType
76 private IOccurrenceService occurrenceService;
77
78 @SpringBeanByType
79 private ISequenceService sequenceService;
80
81 @SpringBeanByType
82 private ITaxonService taxonService;
83
84 @SpringBeanByType
85 private INameService nameService;
86
87 @SpringBeanByType
88 private IDescriptionService descriptionService;
89
90 @Test
91 public void testGetNonCascadedAssociatedElements(){
92 //Collection
93 Collection collection = Collection.NewInstance();
94 Collection subCollection = Collection.NewInstance();
95 subCollection.setSuperCollection(collection);
96
97 Institution institution = Institution.NewInstance();
98 institution.addType(DefinedTerm.NewInstitutionTypeInstance("Research and teaching", "botanical garden", "BGBM"));
99 collection.setInstitute(institution);
100
101 //Source
102 Reference<?> article = ReferenceFactory.newArticle(getReference(), Person.NewInstance(), "title", "pages", "series", "volume", TimePeriod.NewInstance(2014));
103 IdentifiableSource source = IdentifiableSource.NewPrimarySourceInstance(article, "microCitation");
104
105 //FieldUnit
106 FieldUnit fieldUnit = FieldUnit.NewInstance();
107 Person primaryCollector = Person.NewInstance();
108 primaryCollector.setLifespan(TimePeriod.NewInstance(2014));
109 fieldUnit.setPrimaryCollector(primaryCollector);
110 fieldUnit.addSource(source);
111
112 //GatheringEvent
113 GatheringEvent gatheringEvent = GatheringEvent.NewInstance();
114 fieldUnit.setGatheringEvent(gatheringEvent);
115 gatheringEvent.putLocality(Language.ENGLISH(), "locality");
116 gatheringEvent.setExactLocation(Point.NewInstance(22.4, -34.2,
117 ReferenceSystem.NewInstance("MyReferenceSystem", "label", "labelAbbrev"), 33));
118 gatheringEvent.setCountry(Country.GERMANY());
119 gatheringEvent.addCollectingArea(NamedArea.EUROPE());
120
121 //Derived Unit
122 MediaSpecimen mediaSpecimen = MediaSpecimen.NewInstance(SpecimenOrObservationType.StillImage);
123 mediaSpecimen.setCollection(collection);
124 BotanicalName storedUnder = BotanicalName.NewInstance(Rank.SPECIES());
125 mediaSpecimen.setStoredUnder(storedUnder);
126 PreservationMethod preservation = PreservationMethod.NewInstance(null, "My preservation");
127 preservation.setMedium(DefinedTerm.NewDnaMarkerInstance("medium", "medium", "medium"));//dummy defined term
128 mediaSpecimen.setPreservation(preservation);
129
130 //DerivationEvent
131 DerivationEvent event = DerivationEvent.NewInstance(DerivationEventType.ACCESSIONING());
132 event.addOriginal(fieldUnit);
133 event.addDerivative(mediaSpecimen);
134
135 //SpecOrObservationBase
136 fieldUnit.setSex(DefinedTerm.SEX_FEMALE());
137 fieldUnit.setLifeStage(DefinedTerm.NewStageInstance("Live stage", "stage", null));
138 fieldUnit.setKindOfUnit(DefinedTerm.NewKindOfUnitInstance("Kind of unit", "Kind of unit", null));
139 fieldUnit.putDefinition(Language.ENGLISH(), "definition");
140
141 //Determination
142 DeterminationEvent determinationEvent = DeterminationEvent.NewInstance(getTaxon(), mediaSpecimen);
143 determinationEvent.setModifier(DefinedTerm.NewModifierInstance("modifierDescription", "modifierLabel", "mofifierLabelAbbrev"));
144 determinationEvent.setPreferredFlag(true);
145 Reference<?> reference = getReference();
146 determinationEvent.addReference(reference);
147
148 /*NonCascaded
149 * SOOB
150 * - sex (FEMALE)
151 * - stage (Live stage)
152 * - kindOfUnit (Kind of unit)
153 * GatheringEvent
154 * - country (GERMANY)
155 * - collectingArea (EUROPE)
156 * DerivedUnit
157 * - storedUnder (botanical name)
158 * DerivedUnit-> Collection -> institiute
159 * - type (botanical garden)
160 *
161 * */
162
163 assertEquals("Incorrect number of non cascaded CDM entities", 9, occurrenceService.getNonCascadedAssociatedElements(fieldUnit).size());
164 assertEquals("Incorrect number of non cascaded CDM entities", 9, occurrenceService.getNonCascadedAssociatedElements(mediaSpecimen).size());
165
166 }
167 private Reference<?> getReference() {
168 Reference<?> result = ReferenceFactory.newGeneric();
169 result.setTitle("some generic reference");
170 return result;
171 }
172 private Taxon getTaxon() {
173 Reference<?> sec = getReference();
174 TaxonNameBase<?,?> name = BotanicalName.NewInstance(Rank.GENUS());
175 Taxon taxon = Taxon.NewInstance(name, sec);
176 return taxon;
177
178 }
179
180 @Test
181 @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurenceServiceTest.move.xml")
182 public void testMoveDerivate(){
183 DerivedUnit specimenA = (DerivedUnit) occurrenceService.load(UUID.fromString("35cfb0b3-588d-4eee-9db6-ac9caa44e39a"));
184 DerivedUnit specimenB = (DerivedUnit) occurrenceService.load(UUID.fromString("09496534-efd0-44c8-b1ce-01a34a8a0229"));
185 DerivedUnit dnaSample = (DnaSample) occurrenceService.load(UUID.fromString("5995f852-0e78-405c-b849-d923bd6781d9"));
186
187
188 occurrenceService.saveOrUpdate(specimenA);
189 occurrenceService.saveOrUpdate(specimenB);
190 occurrenceService.saveOrUpdate(dnaSample);
191
192 DerivationEvent originalDerivedFromEvent = DerivationEvent.NewSimpleInstance(specimenA, dnaSample, DerivationEventType.DNA_EXTRACTION());
193
194 occurrenceService.moveDerivate(specimenA, specimenB, dnaSample);
195 assertTrue("DerivationEvent not removed from source!", specimenA.getDerivationEvents().isEmpty());
196 assertEquals("DerivationEvent not moved to source!", 1, specimenB.getDerivationEvents().size());
197 DerivationEvent derivationEvent = specimenB.getDerivationEvents().iterator().next();
198 assertEquals("Moved DerivationEvent not of same type!", DerivationEventType.DNA_EXTRACTION(), derivationEvent.getType());
199 assertEquals("Wrong number of derivation originals!", 1, derivationEvent.getOriginals().size());
200 SpecimenOrObservationBase<?> newOriginal = derivationEvent.getOriginals().iterator().next();
201 assertEquals("Origin of moved object not correct", specimenB, newOriginal);
202 assertEquals("Wrong number of derivatives!", 1, derivationEvent.getDerivatives().size());
203 DerivedUnit movedDerivate = derivationEvent.getDerivatives().iterator().next();
204 assertEquals("Moved derivate has wrong type", SpecimenOrObservationType.DnaSample, movedDerivate.getRecordBasis());
205 assertNotEquals("DerivationEvent 'derivedFrom' has not been changed after moving", originalDerivedFromEvent, movedDerivate.getDerivedFrom());
206
207 }
208
209 @Test
210 @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="OccurenceServiceTest.move.xml")
211 public void testMoveSequence(){
212 DnaSample dnaSampleA = (DnaSample) occurrenceService.load(UUID.fromString("5995f852-0e78-405c-b849-d923bd6781d9"));
213 DnaSample dnaSampleB = (DnaSample) occurrenceService.load(UUID.fromString("85fccc2f-c796-46b3-b2fc-6c9a4d68cfda"));
214 String consensusSequence = "ATTCG";
215 Sequence sequence = sequenceService.load(UUID.fromString("6da4f378-9861-4338-861b-7b8073763e7a"));
216
217 occurrenceService.saveOrUpdate(dnaSampleA);
218 occurrenceService.saveOrUpdate(dnaSampleB);
219 sequenceService.saveOrUpdate(sequence);
220
221 dnaSampleA.addSequence(sequence);
222
223 occurrenceService.moveSequence(dnaSampleA, dnaSampleB, sequence);
224 assertEquals("Number of sequences is wrong", 0, dnaSampleA.getSequences().size());
225 assertEquals("Number of sequences is wrong", 1, dnaSampleB.getSequences().size());
226 Sequence next = dnaSampleB.getSequences().iterator().next();
227 assertEquals("Sequences are not equals", sequence, next);
228 assertEquals("Sequences are not equals", consensusSequence, next.getSequenceString());
229 }
230
231 // @Test
232 // public void testDeleteDerivateHierarchy_FieldUnit(){
233 // String assertMessage = "Incorrect number of specimens after deletion.";
234 //
235 // FieldUnit fieldUnit = initDerivateHierarchy();
236 //
237 // //delete field unit
238 // occurrenceService.deleteDerivateHierarchy(fieldUnit);
239 // commit();
240 // assertEquals(assertMessage, 0, occurrenceService.count(SpecimenOrObservationBase.class));
241 // assertEquals(assertMessage, 0, occurrenceService.count(FieldUnit.class));
242 // assertEquals(assertMessage, 0, occurrenceService.count(DerivedUnit.class));
243 // assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
244 // }
245
246 // @Test
247 // public void testDeleteDerivateHierarchy_DerivedUnit(){
248 // String assertMessage = "Incorrect number of specimens after deletion.";
249 //
250 // FieldUnit fieldUnit = initDerivateHierarchy();
251 //
252 // //delete derived unit
253 // DerivedUnit derivedUnit = fieldUnit.getDerivationEvents().iterator().next().getDerivatives().iterator().next();
254 // occurrenceService.deleteDerivateHierarchy(derivedUnit);
255 // commit();
256 // assertEquals(assertMessage, 1, occurrenceService.count(SpecimenOrObservationBase.class));
257 // assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
258 // assertEquals(assertMessage, 0, occurrenceService.count(DerivedUnit.class));
259 // assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
260 // }
261
262 @Test
263 @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class) //loads OccurrenceServiceTest.xml as base DB
264 public void testDeleteIndividualAssociatedAndTypeSpecimen(){
265 FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(UUID.fromString("54a44310-e00a-45d3-aaf0-c0713cc12b45"));
266 DerivedUnit typeSpecimen = (DerivedUnit) occurrenceService.load(UUID.fromString("a1658d40-d407-4c44-818e-8aabeb0a84d8"));
267 BotanicalName name = (BotanicalName) nameService.load(UUID.fromString("8cf1e5da-c5c3-402d-9f71-57ca5929ce4e"));
268 TaxonDescription taxonDescription = (TaxonDescription) descriptionService.load(UUID.fromString("e9bad41a-33bb-46f0-86d3-d88ea3305ed0"));
269 //check initial state (IndividualsAssociation)
270 Set<DescriptionElementBase> elements = taxonDescription.getElements();
271 DescriptionElementBase descriptionElement = elements.iterator().next();
272 assertTrue("wrong type of description element", descriptionElement instanceof IndividualsAssociation);
273 assertEquals("associated specimen is incorrect", associatedFieldUnit, ((IndividualsAssociation)descriptionElement).getAssociatedSpecimenOrObservation());
274 //check initial state (Type Designation)
275 Set<TypeDesignationBase> typeDesignations = name.getTypeDesignations();
276 TypeDesignationBase typeDesignation = typeDesignations.iterator().next();
277 assertTrue("wrong type of type designation", typeDesignation instanceof SpecimenTypeDesignation);
278 assertEquals("type specimen is incorrect", typeSpecimen, ((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen());
279
280 SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
281 config.setDeleteChildren(false);
282 config.setShiftHierarchyUp(false);
283 //delete associated field unit from IndividualsAssociation
284 config.setDeleteFromIndividualsAssociation(true);
285 occurrenceService.delete(associatedFieldUnit, config);
286 assertTrue(((IndividualsAssociation)descriptionElement).getAssociatedSpecimenOrObservation()==null);
287 //delete type specimen from type designation
288 config.setdeleteFromTypeDesignation(true);
289 occurrenceService.delete(typeSpecimen, config);
290 assertTrue(((SpecimenTypeDesignation)typeDesignation).getTypeSpecimen()==null);
291
292 }
293
294
295 @Test
296 @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class) //loads OccurrenceServiceTest.xml as base DB
297 public void testDeleteDerivateHierarchy_StepByStep(){
298 String assertMessage = "Incorrect number of specimens after deletion.";
299 DeleteResult deleteResult = null;
300 SpecimenDeleteConfigurator config = new SpecimenDeleteConfigurator();
301 config.setDeleteChildren(false);
302 config.setShiftHierarchyUp(false);
303
304 FieldUnit fieldUnit = (FieldUnit) occurrenceService.load(UUID.fromString("54a44310-e00a-45d3-aaf0-c0713cc12b45"));
305 DerivedUnit derivedUnit = (DerivedUnit) occurrenceService.load(UUID.fromString("a1658d40-d407-4c44-818e-8aabeb0a84d8"));
306 DnaSample dnaSample = (DnaSample) occurrenceService.load(UUID.fromString("2f0e4257-0ce5-4518-b23d-8d87bb04ff7d"));
307 Sequence consensusSequence = sequenceService.load(UUID.fromString("e3cfdf82-d6bf-4b26-b172-6a057ea3651d"));
308
309 //check initial state
310 assertEquals(assertMessage, 3, occurrenceService.count(SpecimenOrObservationBase.class));
311 assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
312 assertEquals(assertMessage, 2, occurrenceService.count(DerivedUnit.class));
313 assertEquals(assertMessage, 1, occurrenceService.count(DnaSample.class));
314 assertEquals("number of sequences incorrect", 1, dnaSample.getSequences().size());
315
316 //delete sequence
317 deleteResult = occurrenceService.deleteDerivateHierarchy(consensusSequence, config);
318 assertTrue(deleteResult.toString(), DeleteResult.DeleteStatus.OK.equals(deleteResult.getStatus()));
319 assertEquals("number of sequences incorrect", 0, dnaSample.getSequences().size());
320
321
322 //delete dna sample
323 deleteResult = occurrenceService.deleteDerivateHierarchy(dnaSample, config);
324 assertTrue(deleteResult.toString(), DeleteResult.DeleteStatus.OK.equals(deleteResult.getStatus()));
325 assertEquals(assertMessage, 2, occurrenceService.count(SpecimenOrObservationBase.class));
326 assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
327 assertEquals(assertMessage, 1, occurrenceService.count(DerivedUnit.class));
328 assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
329
330 //delete derived unit
331 deleteResult = occurrenceService.deleteDerivateHierarchy(derivedUnit, config);
332 //deleting type specimen should fail
333 assertFalse(deleteResult.toString(), DeleteResult.DeleteStatus.OK.equals(deleteResult.getStatus()));
334 config.setdeleteFromTypeDesignation(true);
335 deleteResult = occurrenceService.deleteDerivateHierarchy(derivedUnit, config);
336 //deleting type specimen should work
337 assertTrue(deleteResult.toString(), DeleteResult.DeleteStatus.OK.equals(deleteResult.getStatus()));
338 assertEquals(assertMessage, 1, occurrenceService.count(SpecimenOrObservationBase.class));
339 assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
340 assertEquals(assertMessage, 0, occurrenceService.count(DerivedUnit.class));
341 assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
342
343 //delete field unit
344 deleteResult = occurrenceService.deleteDerivateHierarchy(fieldUnit, config);
345 //deleting specimen with IndividualsAssociation should fail
346 assertFalse(deleteResult.toString(), DeleteResult.DeleteStatus.OK.equals(deleteResult.getStatus()));
347 config.setDeleteFromIndividualsAssociation(true);
348 deleteResult = occurrenceService.deleteDerivateHierarchy(fieldUnit, config);
349 //deleting specimen with IndividualsAssociation should work
350 assertTrue(deleteResult.toString(), DeleteResult.DeleteStatus.OK.equals(deleteResult.getStatus()));
351 assertEquals(assertMessage, 0, occurrenceService.count(SpecimenOrObservationBase.class));
352 assertEquals(assertMessage, 0, occurrenceService.count(FieldUnit.class));
353 assertEquals(assertMessage, 0, occurrenceService.count(DerivedUnit.class));
354 assertEquals(assertMessage, 0, occurrenceService.count(DnaSample.class));
355 }
356
357 // @Test
358 // public void testDeleteDerivateHierarchy_Sequence(){
359 // String assertMessage = "Incorrect number of specimens after deletion.";
360 //
361 // FieldUnit fieldUnit = initDerivateHierarchy();
362 //
363 // //delete sequence
364 // Sequence consensusSequence = ((DnaSample)fieldUnit.getDerivationEvents().iterator().next().getDerivatives().iterator().next()
365 // .getDerivationEvents().iterator().next().getDerivatives().iterator().next()).getSequences().iterator().next();
366 // occurrenceService.deleteDerivateHierarchy(consensusSequence);
367 // commit();
368 // assertEquals(assertMessage, 3, occurrenceService.count(SpecimenOrObservationBase.class));
369 // assertEquals(assertMessage, 1, occurrenceService.count(FieldUnit.class));
370 // assertEquals(assertMessage, 2, occurrenceService.count(DerivedUnit.class));
371 // assertEquals(assertMessage, 1, occurrenceService.count(DnaSample.class));
372 // }
373
374 @Test
375 @DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class)
376 public void testListAssociatedAndTypedTaxa(){
377 //how the XML was generated
378 // FieldUnit associatedFieldUnit = FieldUnit.NewInstance();
379 // //sub derivates (DerivedUnit, DnaSample)
380 // DerivedUnit typeSpecimen = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
381 // DnaSample dnaSample = DnaSample.NewInstance();
382 //
383 // //derivation events
384 // DerivationEvent.NewSimpleInstance(associatedFieldUnit, typeSpecimen, DerivationEventType.ACCESSIONING());
385 // DerivationEvent.NewSimpleInstance(typeSpecimen, dnaSample, DerivationEventType.DNA_EXTRACTION());
386 //
387 // //DNA (Sequence, SingleRead)
388 // Sequence consensusSequence = Sequence.NewInstance(dnaSample, "ATTCG", 5);
389 // SingleRead singleRead = SingleRead.NewInstance();
390 // consensusSequence.addSingleRead(singleRead);
391 // dnaSample.addSequence(consensusSequence);
392 // occurrenceService.save(associatedFieldUnit);
393 // occurrenceService.save(typeSpecimen);
394 // occurrenceService.save(dnaSample);
395 // //create name with type specimen
396 // BotanicalName name = BotanicalName.PARSED_NAME("Campanula patual sec L.");
397 // SpecimenTypeDesignation typeDesignation = SpecimenTypeDesignation.NewInstance();
398 // typeDesignation.setTypeSpecimen(typeSpecimen);
399 //
400 // //create taxon with name and taxon description
401 // Taxon taxon = Taxon.NewInstance(name, null);
402 // TaxonDescription taxonDescription = TaxonDescription.NewInstance();
403 // taxonDescription.addElement(IndividualsAssociation.NewInstance(associatedFieldUnit));
404 // taxon.addDescription(taxonDescription);
405 // //add type designation to name
406 // name.addTypeDesignation(typeDesignation, false);
407 // //add another taxon description to taxon to create which should not be taken into account
408 // taxon.addDescription(TaxonDescription.NewInstance());
409 // taxonService.saveOrUpdate(taxon);
410 //
411 //
412 // commitAndStartNewTransaction(new String[]{"SpecimenOrObservationBase",
413 // "DerivationEvent",
414 // "Sequence",
415 // "Sequence_SingleRead",
416 // "SingleRead",
417 // "DescriptionElementBase",
418 // "DescriptionBase",
419 // "TaxonBase",
420 // "TypeDesignationBase",
421 // "TaxonNameBase",
422 // "TaxonNameBase_TypeDesignationBase",
423 // "HomotypicalGroup"});
424
425 FieldUnit associatedFieldUnit = (FieldUnit) occurrenceService.load(UUID.fromString("54a44310-e00a-45d3-aaf0-c0713cc12b45"));
426 DerivedUnit typeSpecimen = (DerivedUnit) occurrenceService.load(UUID.fromString("a1658d40-d407-4c44-818e-8aabeb0a84d8"));
427 Taxon taxon = (Taxon) taxonService.load(UUID.fromString("222ebc0a-6b7c-4aab-93c6-f32e99e94e89"));
428 //check for FieldUnit (IndividualsAssociation)
429 java.util.Collection<TaxonBase<?>> associatedTaxa = occurrenceService.listAssociatedTaxa(associatedFieldUnit, null, null, null,null);
430 assertEquals("Number of associated taxa is incorrect", 1, associatedTaxa.size());
431 TaxonBase<?> associatedTaxon = associatedTaxa.iterator().next();
432 assertEquals("Associated taxon is incorrect", taxon, associatedTaxon);
433
434
435 //check for DerivedUnit (Type Designation should exist)
436 java.util.Collection<TaxonBase<?>> typedTaxa = occurrenceService.listTypedTaxa(typeSpecimen, null, null, null,null);
437 assertEquals("Number of typed taxa is incorrect", 1, typedTaxa.size());
438 TaxonBase<?> typedTaxon = typedTaxa.iterator().next();
439 assertEquals("Typed taxon is incorrect", taxon, typedTaxon);
440 }
441
442 @Deprecated
443 private FieldUnit initDerivateHierarchy(){
444 FieldUnit fieldUnit = FieldUnit.NewInstance();
445 //sub derivates (DerivedUnit, DnaSample)
446 DerivedUnit derivedUnit = DerivedUnit.NewInstance(SpecimenOrObservationType.Fossil);
447 DnaSample dnaSample = DnaSample.NewInstance();
448
449 //derivation events
450 DerivationEvent.NewSimpleInstance(fieldUnit, derivedUnit, DerivationEventType.ACCESSIONING());
451 DerivationEvent.NewSimpleInstance(derivedUnit, dnaSample, DerivationEventType.DNA_EXTRACTION());
452
453 //DNA (Sequence, SingleRead)
454 Sequence consensusSequence = Sequence.NewInstance(dnaSample, "ATTCG", 5);
455 SingleRead singleRead = SingleRead.NewInstance();
456 consensusSequence.addSingleRead(singleRead);
457 dnaSample.addSequence(consensusSequence);
458 occurrenceService.save(fieldUnit);
459 occurrenceService.save(derivedUnit);
460 occurrenceService.save(dnaSample);
461 commitAndStartNewTransaction(new String[]{"SpecimenOrObservationBase",
462 "DerivationEvent",
463 "Sequence",
464 "Sequence_SingleRead",
465 "SingleRead"});
466 return fieldUnit;
467 }
468
469 }