2 * Copyright (C) 2011 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.model
.description
;
12 import static org
.junit
.Assert
.assertEquals
;
13 import static org
.junit
.Assert
.assertNotSame
;
14 import static org
.junit
.Assert
.assertSame
;
15 import static org
.junit
.Assert
.assertTrue
;
17 import java
.util
.List
;
19 import org
.junit
.Assert
;
24 import org
.apache
.log4j
.Logger
;
25 import org
.junit
.Before
;
26 import org
.junit
.BeforeClass
;
27 import org
.junit
.Test
;
29 import eu
.etaxonomy
.cdm
.model
.common
.DefaultTermInitializer
;
30 import eu
.etaxonomy
.cdm
.model
.common
.DescriptionElementSource
;
31 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
32 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
33 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceType
;
34 import eu
.etaxonomy
.cdm
.model
.common
.TermVocabulary
;
35 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
36 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
37 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
38 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
40 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
41 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
49 public class DescriptionElementTest
{
50 @SuppressWarnings("unused")
51 private static Logger logger
= Logger
.getLogger(DescriptionElementTest
.class);
54 private CategoricalData categorialData
;
55 private IndividualsAssociation indAssociation
;
56 private QuantitativeData quantData
;
58 private TaxonInteraction taxonInteraction
;
61 public static void setUpBeforeClass() {
62 DefaultTermInitializer vocabularyStore
= new DefaultTermInitializer();
63 vocabularyStore
.initialize();
67 * @throws java.lang.Exception
70 public void setUp() throws Exception
{
71 categorialData
= CategoricalData
.NewInstance();
72 Media media
= Media
.NewInstance(null, 1000, "jpeg", null);
73 categorialData
.addMedia(media
);
75 DescriptionElementSource source
= DescriptionElementSource
.NewInstance(OriginalSourceType
.Unknown
);
76 Reference
<?
> citation
= ReferenceFactory
.newArticle();
77 citation
.setTitle("Test");
78 source
.setCitation(citation
);
79 categorialData
.addSource(source
);
80 StateData state
= StateData
.NewInstance();
81 categorialData
.addState(state
);
83 indAssociation
= IndividualsAssociation
.NewInstance();
85 Specimen associatedSpecimen
= Specimen
.NewInstance();
86 associatedSpecimen
.setIndividualCount(2);
88 indAssociation
.setAssociatedSpecimenOrObservation(associatedSpecimen
);
89 LanguageString langString
= LanguageString
.NewInstance("Test", Language
.ENGLISH());
91 indAssociation
.putDescription(langString
);
93 quantData
= QuantitativeData
.NewInstance();
95 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
97 statisticalValue
.setType(StatisticalMeasure
.AVERAGE() );
99 statisticalValue
.setValue((float) 23.8);
101 quantData
.addStatisticalValue(statisticalValue
);
102 taxon
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.SPECIES(), "Abies", null, "alba", null, null, null, null, null), null);
103 taxonInteraction
= TaxonInteraction
.NewInstance();
104 taxonInteraction
.setTaxon2(taxon
);
105 langString
= LanguageString
.NewInstance("TestTaxonInteraction", Language
.ENGLISH());
107 taxonInteraction
.putDescription(langString
);
111 /* ************************** TESTS **********************************************************/
113 public void testCloneCategorialData(){
114 CategoricalData clone
= (CategoricalData
)categorialData
.clone();
115 assertEquals(clone
.getStates().size(),categorialData
.getStates().size() );
116 assertSame(clone
.getStates().get(0), categorialData
.getStates().get(0));
117 assertNotSame(clone
, categorialData
);
122 public void testCloneIndividualAssociation(){
123 IndividualsAssociation clone
= (IndividualsAssociation
) indAssociation
.clone();
124 assertEquals(clone
.getFeature(), indAssociation
.getFeature());
125 assertNotSame(clone
.getDescription().get(Language
.ENGLISH()), indAssociation
.getDescription().get(Language
.ENGLISH()));
130 public void testCloneQuantitativeData(){
131 QuantitativeData clone
= (QuantitativeData
) quantData
.clone();
132 assertTrue(clone
.getStatisticalValues().iterator().next().getValue() == quantData
.getStatisticalValues().iterator().next().getValue());
133 assertNotSame(clone
.getStatisticalValues().iterator().next(), quantData
.getStatisticalValues().iterator().next());
138 public void testCloneTaxonInteraction(){
139 TaxonInteraction clone
= (TaxonInteraction
)taxonInteraction
.clone();
140 assertNotSame(clone
.getDescriptions().get(Language
.ENGLISH()), taxonInteraction
.getDescriptions().get(Language
.ENGLISH()));
141 assertTrue(clone
.getDescription(Language
.ENGLISH()).equals(taxonInteraction
.getDescription(Language
.ENGLISH())));
145 public void testGetModifiersVocabulary(){
146 TaxonDescription desc
= TaxonDescription
.NewInstance();
147 CategoricalData data
= CategoricalData
.NewInstance();
148 desc
.addElement(data
);
149 StateData stateData
= StateData
.NewInstance();
150 data
.addState(stateData
);
152 TermVocabulary
<Modifier
> plantPartVoc
= TermVocabulary
.NewInstance("plant parts", "plant parts", "parts", null);
153 Modifier leaf
= Modifier
.NewInstance("leaf", "leaf", null);
154 plantPartVoc
.addTerm(leaf
);
155 data
.addModifier(leaf
);
156 Modifier peduncle
= Modifier
.NewInstance("peduncle", "peduncle", null);
157 plantPartVoc
.addTerm(peduncle
);
158 data
.addModifier(peduncle
);
159 Modifier notExistingPart
= Modifier
.NewInstance("not existing part", "not existing part", null);
160 plantPartVoc
.addTerm(notExistingPart
);
162 TermVocabulary
<Modifier
> ethnicGroupVoc
= TermVocabulary
.NewInstance("An ethnic group", "ethnic group", null, null);
163 Modifier scots
= Modifier
.NewInstance("Scots ", "Scots", null);
164 ethnicGroupVoc
.addTerm(scots
);
165 data
.addModifier(scots
);
168 List
<Modifier
> modifiers
= data
.getModifiers(plantPartVoc
);
169 Assert
.assertEquals("There should be 2 modifiers of type 'plant part'", 2, modifiers
.size());
170 Assert
.assertEquals("There should be 3 terms in the 'plant part' vocabulary", 3, plantPartVoc
.size());
171 Assert
.assertEquals("There should be 1 modifiers of type 'ethnic group'", 1, data
.getModifiers(ethnicGroupVoc
).size());
172 Assert
.assertEquals("There should be 3 modifiers all together", 3, data
.getModifiers().size());