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
.TermVocabulary
;
34 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
35 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
36 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
37 import eu
.etaxonomy
.cdm
.model
.occurrence
.Specimen
;
38 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
39 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceFactory
;
40 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
48 public class DescriptionElementTest
{
49 @SuppressWarnings("unused")
50 private static Logger logger
= Logger
.getLogger(DescriptionElementTest
.class);
53 private CategoricalData categorialData
;
54 private IndividualsAssociation indAssociation
;
55 private QuantitativeData quantData
;
57 private TaxonInteraction taxonInteraction
;
60 public static void setUpBeforeClass() {
61 DefaultTermInitializer vocabularyStore
= new DefaultTermInitializer();
62 vocabularyStore
.initialize();
66 * @throws java.lang.Exception
69 public void setUp() throws Exception
{
70 categorialData
= CategoricalData
.NewInstance();
71 Media media
= Media
.NewInstance(null, 1000, "jpeg", null);
72 categorialData
.addMedia(media
);
74 DescriptionElementSource source
= DescriptionElementSource
.NewInstance();
75 Reference
<?
> citation
= ReferenceFactory
.newArticle();
76 citation
.setTitle("Test");
77 source
.setCitation(citation
);
78 categorialData
.addSource(source
);
79 StateData state
= StateData
.NewInstance();
80 categorialData
.addState(state
);
82 indAssociation
= IndividualsAssociation
.NewInstance();
84 Specimen associatedSpecimen
= Specimen
.NewInstance();
85 associatedSpecimen
.setIndividualCount(2);
87 indAssociation
.setAssociatedSpecimenOrObservation(associatedSpecimen
);
88 LanguageString langString
= LanguageString
.NewInstance("Test", Language
.ENGLISH());
90 indAssociation
.putDescription(langString
);
92 quantData
= QuantitativeData
.NewInstance();
94 StatisticalMeasurementValue statisticalValue
= StatisticalMeasurementValue
.NewInstance();
96 statisticalValue
.setType(StatisticalMeasure
.AVERAGE() );
98 statisticalValue
.setValue((float) 23.8);
100 quantData
.addStatisticalValue(statisticalValue
);
101 taxon
= Taxon
.NewInstance(BotanicalName
.NewInstance(Rank
.SPECIES(), "Abies", null, "alba", null, null, null, null, null), null);
102 taxonInteraction
= TaxonInteraction
.NewInstance();
103 taxonInteraction
.setTaxon2(taxon
);
104 langString
= LanguageString
.NewInstance("TestTaxonInteraction", Language
.ENGLISH());
106 taxonInteraction
.putDescription(langString
);
110 /* ************************** TESTS **********************************************************/
112 public void testCloneCategorialData(){
113 CategoricalData clone
= (CategoricalData
)categorialData
.clone();
114 assertEquals(clone
.getStates().size(),categorialData
.getStates().size() );
115 assertSame(clone
.getStates().get(0), categorialData
.getStates().get(0));
116 assertNotSame(clone
, categorialData
);
121 public void testCloneIndividualAssociation(){
122 IndividualsAssociation clone
= (IndividualsAssociation
) indAssociation
.clone();
123 assertEquals(clone
.getFeature(), indAssociation
.getFeature());
124 assertNotSame(clone
.getDescription().get(Language
.ENGLISH()), indAssociation
.getDescription().get(Language
.ENGLISH()));
129 public void testCloneQuantitativeData(){
130 QuantitativeData clone
= (QuantitativeData
) quantData
.clone();
131 assertTrue(clone
.getStatisticalValues().iterator().next().getValue() == quantData
.getStatisticalValues().iterator().next().getValue());
132 assertNotSame(clone
.getStatisticalValues().iterator().next(), quantData
.getStatisticalValues().iterator().next());
137 public void testCloneTaxonInteraction(){
138 TaxonInteraction clone
= (TaxonInteraction
)taxonInteraction
.clone();
139 assertNotSame(clone
.getDescriptions().get(Language
.ENGLISH()), taxonInteraction
.getDescriptions().get(Language
.ENGLISH()));
140 assertTrue(clone
.getDescription(Language
.ENGLISH()).equals(taxonInteraction
.getDescription(Language
.ENGLISH())));
144 public void testGetModifiersVocabulary(){
145 TaxonDescription desc
= TaxonDescription
.NewInstance();
146 CategoricalData data
= CategoricalData
.NewInstance();
147 desc
.addElement(data
);
148 StateData stateData
= StateData
.NewInstance();
149 data
.addState(stateData
);
151 TermVocabulary
<Modifier
> plantPartVoc
= TermVocabulary
.NewInstance("plant parts", "plant parts", "parts", null);
152 Modifier leaf
= Modifier
.NewInstance("leaf", "leaf", null);
153 plantPartVoc
.addTerm(leaf
);
154 data
.addModifier(leaf
);
155 Modifier peduncle
= Modifier
.NewInstance("peduncle", "peduncle", null);
156 plantPartVoc
.addTerm(peduncle
);
157 data
.addModifier(peduncle
);
158 Modifier notExistingPart
= Modifier
.NewInstance("not existing part", "not existing part", null);
159 plantPartVoc
.addTerm(notExistingPart
);
161 TermVocabulary
<Modifier
> ethnicGroupVoc
= TermVocabulary
.NewInstance("An ethnic group", "ethnic group", null, null);
162 Modifier scots
= Modifier
.NewInstance("Scots ", "Scots", null);
163 ethnicGroupVoc
.addTerm(scots
);
164 data
.addModifier(scots
);
167 List
<Modifier
> modifiers
= data
.getModifiers(plantPartVoc
);
168 Assert
.assertEquals("There should be 2 modifiers of type 'plant part'", 2, modifiers
.size());
169 Assert
.assertEquals("There should be 3 terms in the 'plant part' vocabulary", 3, plantPartVoc
.size());
170 Assert
.assertEquals("There should be 1 modifiers of type 'ethnic group'", 1, data
.getModifiers(ethnicGroupVoc
).size());
171 Assert
.assertEquals("There should be 3 modifiers all together", 3, data
.getModifiers().size());