1
|
/**
|
2
|
* Copyright (C) 2009 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
|
package eu.etaxonomy.cdm.model.description;
|
10
|
|
11
|
import static org.junit.Assert.assertEquals;
|
12
|
import static org.junit.Assert.assertNotEquals;
|
13
|
import static org.junit.Assert.assertNotSame;
|
14
|
import static org.junit.Assert.assertSame;
|
15
|
|
16
|
import java.util.ArrayList;
|
17
|
import java.util.Arrays;
|
18
|
import java.util.List;
|
19
|
|
20
|
import org.junit.Assert;
|
21
|
import org.junit.Before;
|
22
|
import org.junit.Test;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.DefinedTerm;
|
25
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
26
|
import eu.etaxonomy.cdm.model.common.TermType;
|
27
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
28
|
import eu.etaxonomy.cdm.model.media.Media;
|
29
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
30
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
31
|
|
32
|
/**
|
33
|
* @author a.mueller
|
34
|
\* @since 22.11.2011
|
35
|
*
|
36
|
*/
|
37
|
public class CategoricalDataTest {
|
38
|
|
39
|
private CategoricalData categorialData;
|
40
|
|
41
|
/**
|
42
|
* @throws java.lang.Exception
|
43
|
*/
|
44
|
@Before
|
45
|
public void setUp() throws Exception {
|
46
|
categorialData = CategoricalData.NewInstance();
|
47
|
Media media = Media.NewInstance(null, 1000, "jpeg", null);
|
48
|
categorialData.addMedia(media);
|
49
|
|
50
|
DescriptionElementSource source = DescriptionElementSource.NewInstance(OriginalSourceType.Unknown);
|
51
|
Reference citation = ReferenceFactory.newArticle();
|
52
|
citation.setTitle("Test");
|
53
|
source.setCitation(citation);
|
54
|
categorialData.addSource(source );
|
55
|
StateData state = StateData.NewInstance();
|
56
|
categorialData.addStateData(state);
|
57
|
}
|
58
|
|
59
|
//************************ TESTS ********************************************
|
60
|
|
61
|
/**
|
62
|
* Test method for {@link eu.etaxonomy.cdm.model.description.CategoricalData#getStatesOnly()}.
|
63
|
*/
|
64
|
@Test
|
65
|
public void testGetStatesOnly() {
|
66
|
TaxonDescription desc = TaxonDescription.NewInstance();
|
67
|
CategoricalData data = CategoricalData.NewInstance();
|
68
|
desc.addElement(data);
|
69
|
TermVocabulary<State> useCategoryVocabulary = TermVocabulary.NewInstance(TermType.Feature, "Use category vocabulary", "use categories", null, null);
|
70
|
State useCategory1 = State.NewInstance("My first use category", "use category 1", null);
|
71
|
useCategoryVocabulary.addTerm(useCategory1);
|
72
|
State useCategory2 = State.NewInstance("My favorite use category", "use category 2", null);
|
73
|
useCategoryVocabulary.addTerm(useCategory2);
|
74
|
|
75
|
StateData stateData = StateData.NewInstance(useCategory1);
|
76
|
data.addStateData(stateData);
|
77
|
StateData stateData2 = StateData.NewInstance(useCategory2);
|
78
|
stateData2.addModifier(DefinedTerm.NewModifierInstance(null, "Any modifer", null));
|
79
|
data.addStateData(stateData2);
|
80
|
|
81
|
List<State> states = data.getStatesOnly();
|
82
|
Assert.assertEquals("There should be 2 states", 2, states.size());
|
83
|
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Test method for {@link eu.etaxonomy.cdm.model.description.CategoricalData#setStateDataOnly(List)}.
|
88
|
*/
|
89
|
@Test
|
90
|
public void testSetStatesOnly() {
|
91
|
TaxonDescription desc = TaxonDescription.NewInstance();
|
92
|
CategoricalData data = CategoricalData.NewInstance();
|
93
|
desc.addElement(data);
|
94
|
TermVocabulary<State> useCategoryVocabulary = TermVocabulary.NewInstance(TermType.Feature,"Use category vocabulary", "use categories", null, null);
|
95
|
State useCategory1 = State.NewInstance("My first use category", "use category 1", null);
|
96
|
useCategoryVocabulary.addTerm(useCategory1);
|
97
|
data.addStateData(useCategory1);
|
98
|
Assert.assertEquals("There should be 1 state now", 1, data.getStateData().size());
|
99
|
|
100
|
State useCategory2 = State.NewInstance("My favorite use category", "use category 2", null);
|
101
|
useCategoryVocabulary.addTerm(useCategory2);
|
102
|
State useCategory3 = State.NewInstance("My 3rd use category", "use category 3", null);
|
103
|
useCategoryVocabulary.addTerm(useCategory3);
|
104
|
List<State> newStates = new ArrayList<State>();
|
105
|
newStates.addAll(Arrays.asList(useCategory2, useCategory3));
|
106
|
|
107
|
// setting new states and thus removing useCategory1
|
108
|
List<StateData> stateDataList = data.setStateDataOnly(newStates);
|
109
|
Assert.assertEquals("There should be 2 StateData objects", 2, stateDataList.size());
|
110
|
Assert.assertEquals("There should be 2 StateData objects", 2, data.getStateData().size());
|
111
|
Assert.assertFalse("Category 1 should not be included anymore", data.getStatesOnly().contains(useCategory1));
|
112
|
Assert.assertTrue("Category 2 should be included", data.getStatesOnly().contains(useCategory2));
|
113
|
|
114
|
}
|
115
|
|
116
|
@Test
|
117
|
public void testClone(){
|
118
|
CategoricalData clone = (CategoricalData)categorialData.clone();
|
119
|
assertNotSame(clone, categorialData);
|
120
|
assertEquals(1, clone.getStateData().size());
|
121
|
assertEquals(clone.getStateData().size(), categorialData.getStateData().size() );
|
122
|
StateData stateOrig = categorialData.getStateData().get(0);
|
123
|
StateData stateClone = clone.getStateData().get(0);
|
124
|
assertNotEquals(stateOrig, stateClone);
|
125
|
assertSame(stateOrig.getState(), stateClone.getState());
|
126
|
assertNotEquals(stateOrig.getCategoricalData(), stateClone.getCategoricalData());
|
127
|
}
|
128
|
|
129
|
}
|