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 java
.util
.List
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.junit
.Assert
;
16 import org
.junit
.Before
;
17 import org
.junit
.BeforeClass
;
18 import org
.junit
.Test
;
20 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
21 import eu
.etaxonomy
.cdm
.model
.term
.DefaultTermInitializer
;
22 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTerm
;
23 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
24 import eu
.etaxonomy
.cdm
.model
.term
.TermVocabulary
;
31 public class DescriptionElementTest
{
32 @SuppressWarnings("unused")
33 private static Logger logger
= Logger
.getLogger(DescriptionElementTest
.class);
37 public static void setUpBeforeClass() {
38 if (Language
.DEFAULT() == null){
39 DefaultTermInitializer vocabularyStore
= new DefaultTermInitializer();
40 vocabularyStore
.initialize();
45 * @throws java.lang.Exception
48 public void setUp() throws Exception
{
52 /* ************************** TESTS **********************************************************/
56 public void testGetModifiersVocabulary(){
57 TaxonDescription desc
= TaxonDescription
.NewInstance();
58 CategoricalData data
= CategoricalData
.NewInstance();
59 desc
.addElement(data
);
60 StateData stateData
= StateData
.NewInstance();
61 data
.addStateData(stateData
);
63 TermType modifierType
= TermType
.Modifier
;
64 TermVocabulary
<DefinedTerm
> plantPartVoc
= TermVocabulary
.NewInstance(modifierType
,"plant parts", "plant parts", "parts", null);
65 DefinedTerm leaf
= DefinedTerm
.NewModifierInstance("leaf", "leaf", null);
66 plantPartVoc
.addTerm(leaf
);
67 data
.addModifier(leaf
);
68 DefinedTerm peduncle
= DefinedTerm
.NewModifierInstance("peduncle", "peduncle", null);
69 plantPartVoc
.addTerm(peduncle
);
70 data
.addModifier(peduncle
);
71 DefinedTerm notExistingPart
= DefinedTerm
.NewModifierInstance("not existing part", "not existing part", null);
72 plantPartVoc
.addTerm(notExistingPart
);
74 TermVocabulary
<DefinedTerm
> ethnicGroupVoc
= TermVocabulary
.NewInstance(TermType
.Modifier
,"An ethnic group", "ethnic group", null, null);
75 DefinedTerm scots
= DefinedTerm
.NewModifierInstance("Scots ", "Scots", null);
76 ethnicGroupVoc
.addTerm(scots
);
77 data
.addModifier(scots
);
80 List
<DefinedTerm
> modifiers
= data
.getModifiers(plantPartVoc
);
81 Assert
.assertEquals("There should be 2 modifiers of type 'plant part'", 2, modifiers
.size());
82 Assert
.assertEquals("There should be 3 terms in the 'plant part' vocabulary", 3, plantPartVoc
.size());
83 Assert
.assertEquals("There should be 1 modifiers of type 'ethnic group'", 1, data
.getModifiers(ethnicGroupVoc
).size());
84 Assert
.assertEquals("There should be 3 modifiers all together", 3, data
.getModifiers().size());