cef62f0ceea71179e037e48606ef7daf6f57b67b
[cdmlib.git] / cdmlib-model / src / test / java / eu / etaxonomy / cdm / model / description / DescriptionElementTest.java
1 /**
2 * Copyright (C) 2011 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.model.description;
11
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;
16
17 import java.util.List;
18
19 import org.junit.Assert;
20
21
22
23
24 import org.apache.log4j.Logger;
25 import org.junit.Before;
26 import org.junit.BeforeClass;
27 import org.junit.Test;
28
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;
41
42
43 /**
44 * @author k.luther
45 * @created 11.04.2011
46 * @version 1.0
47 */
48 public class DescriptionElementTest {
49 @SuppressWarnings("unused")
50 private static Logger logger = Logger.getLogger(DescriptionElementTest.class);
51
52
53 private CategoricalData categorialData;
54 private IndividualsAssociation indAssociation;
55 private QuantitativeData quantData;
56 private Taxon taxon;
57 private TaxonInteraction taxonInteraction;
58
59 @BeforeClass
60 public static void setUpBeforeClass() {
61 DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
62 vocabularyStore.initialize();
63 }
64
65 /**
66 * @throws java.lang.Exception
67 */
68 @Before
69 public void setUp() throws Exception {
70 categorialData = CategoricalData.NewInstance();
71 Media media = Media.NewInstance(null, 1000, "jpeg", null);
72 categorialData.addMedia(media);
73
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);
81
82 indAssociation = IndividualsAssociation.NewInstance();
83
84 Specimen associatedSpecimen = Specimen.NewInstance();
85 associatedSpecimen.setIndividualCount(2);
86
87 indAssociation.setAssociatedSpecimenOrObservation(associatedSpecimen);
88 LanguageString langString = LanguageString.NewInstance("Test", Language.ENGLISH());
89
90 indAssociation.putDescription(langString);
91
92 quantData = QuantitativeData.NewInstance();
93
94 StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance();
95
96 statisticalValue.setType(StatisticalMeasure.AVERAGE() );
97
98 statisticalValue.setValue((float) 23.8);
99
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());
105
106 taxonInteraction.putDescription(langString);
107
108 }
109
110 /* ************************** TESTS **********************************************************/
111 @Test
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);
117
118 }
119
120 @Test
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()));
125 }
126
127
128 @Test
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());
133
134 }
135
136 @Test
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())));
141 }
142
143 @Test
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);
150
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);
160
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);
165
166
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());
172
173 }
174
175
176
177
178
179 }
180
181