update factory methods for original sources #1549
[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.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;
42
43
44 /**
45 * @author k.luther
46 * @created 11.04.2011
47 * @version 1.0
48 */
49 public class DescriptionElementTest {
50 @SuppressWarnings("unused")
51 private static Logger logger = Logger.getLogger(DescriptionElementTest.class);
52
53
54 private CategoricalData categorialData;
55 private IndividualsAssociation indAssociation;
56 private QuantitativeData quantData;
57 private Taxon taxon;
58 private TaxonInteraction taxonInteraction;
59
60 @BeforeClass
61 public static void setUpBeforeClass() {
62 DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
63 vocabularyStore.initialize();
64 }
65
66 /**
67 * @throws java.lang.Exception
68 */
69 @Before
70 public void setUp() throws Exception {
71 categorialData = CategoricalData.NewInstance();
72 Media media = Media.NewInstance(null, 1000, "jpeg", null);
73 categorialData.addMedia(media);
74
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);
82
83 indAssociation = IndividualsAssociation.NewInstance();
84
85 Specimen associatedSpecimen = Specimen.NewInstance();
86 associatedSpecimen.setIndividualCount(2);
87
88 indAssociation.setAssociatedSpecimenOrObservation(associatedSpecimen);
89 LanguageString langString = LanguageString.NewInstance("Test", Language.ENGLISH());
90
91 indAssociation.putDescription(langString);
92
93 quantData = QuantitativeData.NewInstance();
94
95 StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance();
96
97 statisticalValue.setType(StatisticalMeasure.AVERAGE() );
98
99 statisticalValue.setValue((float) 23.8);
100
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());
106
107 taxonInteraction.putDescription(langString);
108
109 }
110
111 /* ************************** TESTS **********************************************************/
112 @Test
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);
118
119 }
120
121 @Test
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()));
126 }
127
128
129 @Test
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());
134
135 }
136
137 @Test
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())));
142 }
143
144 @Test
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);
151
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);
161
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);
166
167
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());
173
174 }
175
176
177
178
179
180 }
181
182