ref #8162 adapt cdmlip to new term package structure
[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 java.util.List;
13
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;
19
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;
25
26
27 /**
28 * @author k.luther
29 * @since 11.04.2011
30 */
31 public class DescriptionElementTest {
32 @SuppressWarnings("unused")
33 private static Logger logger = Logger.getLogger(DescriptionElementTest.class);
34
35
36 @BeforeClass
37 public static void setUpBeforeClass() {
38 if (Language.DEFAULT() == null){
39 DefaultTermInitializer vocabularyStore = new DefaultTermInitializer();
40 vocabularyStore.initialize();
41 }
42 }
43
44 /**
45 * @throws java.lang.Exception
46 */
47 @Before
48 public void setUp() throws Exception {
49
50 }
51
52 /* ************************** TESTS **********************************************************/
53
54
55 @Test
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);
62
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);
73
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);
78
79
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());
85
86 }
87
88 }
89
90