Revision c38734e6
Added by Andreas Müller over 8 years ago
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/name/BotanicalNameTest.java | ||
---|---|---|
21 | 21 |
import org.junit.Before; |
22 | 22 |
import org.junit.BeforeClass; |
23 | 23 |
import org.junit.Test; |
24 |
import org.springframework.beans.BeanUtils; |
|
24 | 25 |
|
25 | 26 |
import eu.etaxonomy.cdm.model.agent.Team; |
26 | 27 |
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase; |
... | ... | |
165 | 166 |
botanicalName1.setAnamorphic(false); |
166 | 167 |
clone = (BotanicalName)botanicalName1.clone(); |
167 | 168 |
Assert.assertEquals("Anamorphic should be equal", false, clone.isAnamorphic()); |
168 |
|
|
169 | 169 |
} |
170 | 170 |
|
171 |
@Test |
|
172 |
public void beanTests(){ |
|
173 |
// #5307 Test that BeanUtils does not fail |
|
174 |
BeanUtils.getPropertyDescriptors(BotanicalName.class); |
|
175 |
BeanUtils.getPropertyDescriptors(TaxonNameBase.class); |
|
176 |
BeanUtils.getPropertyDescriptors(NonViralName.class); |
|
177 |
BeanUtils.getPropertyDescriptors(ZoologicalName.class); |
|
178 |
BeanUtils.getPropertyDescriptors(ViralName.class); |
|
179 |
BeanUtils.getPropertyDescriptors(CultivarPlantName.class); |
|
180 |
} |
|
171 | 181 |
} |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/name/SpecimenTypeDesignationTest.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.model.name; |
|
12 |
|
|
13 |
|
|
14 |
import static org.junit.Assert.assertEquals; |
|
15 |
import static org.junit.Assert.assertNotNull; |
|
16 |
import static org.junit.Assert.assertTrue; |
|
17 |
|
|
18 |
import java.util.Set; |
|
19 |
|
|
20 |
import org.apache.log4j.Logger; |
|
21 |
import org.junit.Before; |
|
22 |
import org.junit.BeforeClass; |
|
23 |
import org.junit.Test; |
|
24 |
|
|
25 |
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer; |
|
26 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
27 |
|
|
28 |
/** |
|
29 |
* @author a.babadshanjan |
|
30 |
* @created 19.05.2009 |
|
31 |
* @version 1.0 |
|
32 |
*/ |
|
33 |
public class SpecimenTypeDesignationTest { |
|
34 |
@SuppressWarnings("unused") |
|
35 |
private static final Logger logger = Logger.getLogger(SpecimenTypeDesignationTest.class); |
|
36 |
|
|
37 |
private SpecimenTypeDesignation term1 = null; |
|
38 |
private SpecimenTypeDesignation term2 = null; |
|
39 |
|
|
40 |
@BeforeClass |
|
41 |
public static void setUpBeforeClass() { |
|
42 |
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer(); |
|
43 |
vocabularyStore.initialize(); |
|
44 |
} |
|
45 |
|
|
46 |
@Before |
|
47 |
public void setUp() { |
|
48 |
term1 = new SpecimenTypeDesignation(); |
|
49 |
term2 = new SpecimenTypeDesignation(DerivedUnit.NewPreservedSpecimenInstance(), |
|
50 |
SpecimenTypeDesignationStatus.ISOTYPE(), null, null, null, false); |
|
51 |
} |
|
52 |
|
|
53 |
@Test |
|
54 |
public void testSpecimenTypeDesignation() { |
|
55 |
assertNotNull(term1); |
|
56 |
assertNotNull(term2); |
|
57 |
} |
|
58 |
|
|
59 |
@Test |
|
60 |
public void testGetTypeStatus() { |
|
61 |
SpecimenTypeDesignationStatus std = term1.getTypeStatus(); |
|
62 |
std = term2.getTypeStatus(); |
|
63 |
term1.setTypeStatus(SpecimenTypeDesignationStatus.EPITYPE()); |
|
64 |
assertEquals(term1.getTypeStatus(), SpecimenTypeDesignationStatus.EPITYPE()); |
|
65 |
assertTrue(term1.getTypeStatus().isInstanceOf(SpecimenTypeDesignationStatus.class)); |
|
66 |
} |
|
67 |
|
|
68 |
@Test |
|
69 |
public void testBidirectionalRelationship(){ |
|
70 |
term2 = new SpecimenTypeDesignation(DerivedUnit.NewPreservedSpecimenInstance(), SpecimenTypeDesignationStatus.ISOTYPE(), |
|
71 |
null, null, null, false); |
|
72 |
DerivedUnit specimen = (DerivedUnit) term2.getTypeSpecimen(); |
|
73 |
Set<SpecimenTypeDesignation> set = specimen.getSpecimenTypeDesignations(); |
|
74 |
boolean contains = false; |
|
75 |
for (SpecimenTypeDesignation spec: set){ |
|
76 |
if (spec.equals(term2)){ |
|
77 |
contains = true; |
|
78 |
break; |
|
79 |
} |
|
80 |
} |
|
81 |
assertTrue(contains); |
|
82 |
} |
|
83 |
|
|
84 |
} |
|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.model.name; |
|
12 |
|
|
13 |
|
|
14 |
import static org.junit.Assert.assertEquals; |
|
15 |
import static org.junit.Assert.assertNotNull; |
|
16 |
import static org.junit.Assert.assertTrue; |
|
17 |
|
|
18 |
import java.util.Set; |
|
19 |
|
|
20 |
import org.apache.log4j.Logger; |
|
21 |
import org.junit.Before; |
|
22 |
import org.junit.BeforeClass; |
|
23 |
import org.junit.Test; |
|
24 |
import org.springframework.beans.BeanUtils; |
|
25 |
|
|
26 |
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer; |
|
27 |
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit; |
|
28 |
|
|
29 |
/** |
|
30 |
* @author a.babadshanjan |
|
31 |
* @created 19.05.2009 |
|
32 |
* @version 1.0 |
|
33 |
*/ |
|
34 |
public class SpecimenTypeDesignationTest { |
|
35 |
@SuppressWarnings("unused") |
|
36 |
private static final Logger logger = Logger.getLogger(SpecimenTypeDesignationTest.class); |
|
37 |
|
|
38 |
private SpecimenTypeDesignation term1 = null; |
|
39 |
private SpecimenTypeDesignation term2 = null; |
|
40 |
|
|
41 |
@BeforeClass |
|
42 |
public static void setUpBeforeClass() { |
|
43 |
DefaultTermInitializer vocabularyStore = new DefaultTermInitializer(); |
|
44 |
vocabularyStore.initialize(); |
|
45 |
} |
|
46 |
|
|
47 |
@Before |
|
48 |
public void setUp() { |
|
49 |
term1 = new SpecimenTypeDesignation(); |
|
50 |
term2 = new SpecimenTypeDesignation(DerivedUnit.NewPreservedSpecimenInstance(), |
|
51 |
SpecimenTypeDesignationStatus.ISOTYPE(), null, null, null, false); |
|
52 |
} |
|
53 |
|
|
54 |
@Test |
|
55 |
public void testSpecimenTypeDesignation() { |
|
56 |
assertNotNull(term1); |
|
57 |
assertNotNull(term2); |
|
58 |
} |
|
59 |
|
|
60 |
@Test |
|
61 |
public void testGetTypeStatus() { |
|
62 |
SpecimenTypeDesignationStatus std = term1.getTypeStatus(); |
|
63 |
std = term2.getTypeStatus(); |
|
64 |
term1.setTypeStatus(SpecimenTypeDesignationStatus.EPITYPE()); |
|
65 |
assertEquals(term1.getTypeStatus(), SpecimenTypeDesignationStatus.EPITYPE()); |
|
66 |
assertTrue(term1.getTypeStatus().isInstanceOf(SpecimenTypeDesignationStatus.class)); |
|
67 |
} |
|
68 |
|
|
69 |
@Test |
|
70 |
public void testBidirectionalRelationship(){ |
|
71 |
term2 = new SpecimenTypeDesignation(DerivedUnit.NewPreservedSpecimenInstance(), SpecimenTypeDesignationStatus.ISOTYPE(), |
|
72 |
null, null, null, false); |
|
73 |
DerivedUnit specimen = term2.getTypeSpecimen(); |
|
74 |
Set<SpecimenTypeDesignation> set = specimen.getSpecimenTypeDesignations(); |
|
75 |
boolean contains = false; |
|
76 |
for (SpecimenTypeDesignation spec: set){ |
|
77 |
if (spec.equals(term2)){ |
|
78 |
contains = true; |
|
79 |
break; |
|
80 |
} |
|
81 |
} |
|
82 |
assertTrue(contains); |
|
83 |
} |
|
84 |
|
|
85 |
@Test |
|
86 |
public void beanTests(){ |
|
87 |
// #5307 Test that BeanUtils does not fail |
|
88 |
BeanUtils.getPropertyDescriptors(SpecimenTypeDesignation.class); |
|
89 |
BeanUtils.getPropertyDescriptors(NameTypeDesignation.class); |
|
90 |
BeanUtils.getPropertyDescriptors(HomotypicalGroup.class); |
|
91 |
BeanUtils.getPropertyDescriptors(NomenclaturalStatusType.class); |
|
92 |
BeanUtils.getPropertyDescriptors(Rank.class); |
|
93 |
} |
|
94 |
|
|
95 |
|
|
96 |
} |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/occurrence/SpecimenTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.occurrence; |
|
11 |
|
|
12 |
import static org.junit.Assert.assertEquals; |
|
13 |
import static org.junit.Assert.assertFalse; |
|
14 |
import static org.junit.Assert.assertNotNull; |
|
15 |
import static org.junit.Assert.assertNotSame; |
|
16 |
import static org.junit.Assert.assertNull; |
|
17 |
import static org.junit.Assert.assertSame; |
|
18 |
import static org.junit.Assert.assertTrue; |
|
19 |
|
|
20 |
import java.util.Calendar; |
|
21 |
import java.util.UUID; |
|
22 |
|
|
23 |
import org.apache.log4j.Logger; |
|
24 |
import org.joda.time.DateTime; |
|
25 |
import org.junit.Assert; |
|
26 |
import org.junit.Before; |
|
27 |
import org.junit.Test; |
|
28 |
|
|
29 |
import com.ibm.lsid.MalformedLSIDException; |
|
30 |
|
|
31 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
32 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
33 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
34 |
import eu.etaxonomy.cdm.model.common.Extension; |
|
35 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
|
36 |
import eu.etaxonomy.cdm.model.common.LSID; |
|
37 |
import eu.etaxonomy.cdm.model.common.Language; |
|
38 |
import eu.etaxonomy.cdm.model.common.LanguageStringBase; |
|
39 |
import eu.etaxonomy.cdm.model.common.Marker; |
|
40 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
41 |
import eu.etaxonomy.cdm.model.common.OriginalSourceBase; |
|
42 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
|
43 |
import eu.etaxonomy.cdm.model.media.Media; |
|
44 |
import eu.etaxonomy.cdm.model.media.Rights; |
|
45 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
|
46 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
47 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
48 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
49 |
|
|
50 |
/** |
|
51 |
* @author a.mueller |
|
52 |
* @created 28.10.2008 |
|
53 |
*/ |
|
54 |
public class SpecimenTest { |
|
55 |
private static final Logger logger = Logger.getLogger(SpecimenTest.class); |
|
56 |
|
|
57 |
private DerivedUnit specimen; |
|
58 |
|
|
59 |
@Before |
|
60 |
public void setUp() throws Exception { |
|
61 |
specimen = DerivedUnit.NewPreservedSpecimenInstance(); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Test method for {@link eu.etaxonomy.cdm.model.occurrence.Specimen#NewInstance()}. |
|
66 |
*/ |
|
67 |
@Test |
|
68 |
public void testNewInstance() { |
|
69 |
DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance(); |
|
70 |
assertNotNull(specimen); |
|
71 |
assertTrue(specimen instanceof DerivedUnit); |
|
72 |
assertTrue(specimen.getRecordBasis().equals(SpecimenOrObservationType.PreservedSpecimen)); |
|
73 |
} |
|
74 |
|
|
75 |
/** |
|
76 |
* Test method for {@link eu.etaxonomy.cdm.model.occurrence.Specimen#getPreservation()} and |
|
77 |
* {@link eu.etaxonomy.cdm.model.occurrence.Specimen#setPreservation(eu.etaxonomy.cdm.model.occurrence.PreservationMethod)}. |
|
78 |
*/ |
|
79 |
@Test |
|
80 |
public void testGetSetPreservation() { |
|
81 |
PreservationMethod preservation = PreservationMethod.NewInstance(); |
|
82 |
specimen.setPreservation(preservation); |
|
83 |
assertSame(preservation, specimen.getPreservation()); |
|
84 |
specimen.setPreservation(null); |
|
85 |
} |
|
86 |
|
|
87 |
@Test |
|
88 |
public void testBidirectionalSpecimenDescription(){ |
|
89 |
Assert.assertNotNull("Specimen should exist", specimen); |
|
90 |
|
|
91 |
SpecimenDescription desc = SpecimenDescription.NewInstance(specimen); |
|
92 |
Assert.assertNotNull("Description should exist.", desc); |
|
93 |
Assert.assertSame("Descriptions specimen should be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
94 |
Assert.assertTrue("Specimen should contain description", specimen.getDescriptions().contains(desc)); |
|
95 |
|
|
96 |
SpecimenDescription desc2 = SpecimenDescription.NewInstance(); |
|
97 |
Assert.assertNotNull("Description should exist.", desc2); |
|
98 |
specimen.addDescription(desc2); |
|
99 |
Assert.assertSame("Description2 specimen should be set correctly", desc2.getDescribedSpecimenOrObservation(),specimen); |
|
100 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
101 |
Assert.assertTrue("Specimen should contain description2", specimen.getDescriptions().contains(desc2)); |
|
102 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
103 |
|
|
104 |
SpecimenDescription desc3 = SpecimenDescription.NewInstance(); |
|
105 |
Assert.assertNotNull("Description should exist.", desc3); |
|
106 |
desc3.setDescribedSpecimenOrObservation(specimen); |
|
107 |
Assert.assertSame("Description3 specimen should be set correctly", desc3.getDescribedSpecimenOrObservation(),specimen); |
|
108 |
Assert.assertSame("Descriptions2 specimen should still be set correctly", desc2.getDescribedSpecimenOrObservation(),specimen); |
|
109 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
110 |
Assert.assertTrue("Specimen should contain description3", specimen.getDescriptions().contains(desc3)); |
|
111 |
Assert.assertTrue("Specimen should still contain description2", specimen.getDescriptions().contains(desc2)); |
|
112 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
113 |
|
|
114 |
|
|
115 |
//change specimen of a given description |
|
116 |
DerivedUnit specimen2 = DerivedUnit.NewPreservedSpecimenInstance(); |
|
117 |
Assert.assertNotNull("Specimen should exist.", specimen2); |
|
118 |
desc3.setDescribedSpecimenOrObservation(specimen2); |
|
119 |
Assert.assertSame("Description3 new specimen should be set correctly", desc3.getDescribedSpecimenOrObservation(),specimen2); |
|
120 |
Assert.assertSame("Descriptions2 specimen should still be set correctly", desc2.getDescribedSpecimenOrObservation(),specimen); |
|
121 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
122 |
Assert.assertTrue("Specimen2 should contain description3", specimen2.getDescriptions().contains(desc3)); |
|
123 |
Assert.assertEquals("Specimen2 should contain exactly 1 description", 1, specimen2.getDescriptions().size()); |
|
124 |
Assert.assertFalse("Specimen should no longer contain description3", specimen.getDescriptions().contains(desc3)); |
|
125 |
Assert.assertTrue("Specimen should still contain description2", specimen.getDescriptions().contains(desc2)); |
|
126 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
127 |
|
|
128 |
//remove description which is not contained |
|
129 |
specimen.removeDescription(desc3); |
|
130 |
Assert.assertSame("Nothing should have changed", desc3.getDescribedSpecimenOrObservation(),specimen2); |
|
131 |
Assert.assertSame("Nothing should have changed", desc2.getDescribedSpecimenOrObservation(),specimen); |
|
132 |
Assert.assertSame("Nothing should have changed", desc.getDescribedSpecimenOrObservation(),specimen); |
|
133 |
Assert.assertTrue("Nothing should have changed", specimen2.getDescriptions().contains(desc3)); |
|
134 |
Assert.assertEquals("Nothing should have changed", 1, specimen2.getDescriptions().size()); |
|
135 |
Assert.assertFalse("Nothing should have changed", specimen.getDescriptions().contains(desc3)); |
|
136 |
Assert.assertTrue("Nothing should have changed", specimen.getDescriptions().contains(desc2)); |
|
137 |
Assert.assertTrue("Nothing should have changed", specimen.getDescriptions().contains(desc)); |
|
138 |
|
|
139 |
//remove description |
|
140 |
specimen.removeDescription(desc2); |
|
141 |
Assert.assertNull("Descriptions2 specimen should not exist anymore", desc2.getDescribedSpecimenOrObservation()); |
|
142 |
Assert.assertSame("Description3 specimen should still be set correctly", desc3.getDescribedSpecimenOrObservation(),specimen2); |
|
143 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
144 |
Assert.assertTrue("Specimen2 should still contain description3", specimen2.getDescriptions().contains(desc3)); |
|
145 |
Assert.assertEquals("Specimen2 should still contain exactly 1 description", 1, specimen2.getDescriptions().size()); |
|
146 |
Assert.assertFalse("Specimen should not contain description2 anymore", specimen.getDescriptions().contains(desc2)); |
|
147 |
Assert.assertFalse("Specimen should still no longer contain description3", specimen.getDescriptions().contains(desc3)); |
|
148 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
149 |
|
|
150 |
//remove description by setting null specimen |
|
151 |
desc3.setDescribedSpecimenOrObservation(null); |
|
152 |
Assert.assertNull("Description3 specimen should not exist anymore", desc3.getDescribedSpecimenOrObservation()); |
|
153 |
Assert.assertNull("Descriptions2 specimen should still not exist anymore", desc2.getDescribedSpecimenOrObservation()); |
|
154 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
155 |
Assert.assertFalse("Specimen2 should not contain description3 anymore", specimen2.getDescriptions().contains(desc3)); |
|
156 |
Assert.assertEquals("Specimen2 should contain no description now", 0, specimen2.getDescriptions().size()); |
|
157 |
Assert.assertFalse("Specimen should still no longer contain description2", specimen.getDescriptions().contains(desc2)); |
|
158 |
Assert.assertFalse("Specimen should still no longer contain description3", specimen.getDescriptions().contains(desc3)); |
|
159 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
160 |
|
|
161 |
|
|
162 |
} |
|
163 |
|
|
164 |
|
|
165 |
@Test |
|
166 |
public void testBidirectionalTypeDesignation(){ |
|
167 |
SpecimenTypeDesignation desig1 = SpecimenTypeDesignation.NewInstance(); |
|
168 |
SpecimenTypeDesignation desig2 = SpecimenTypeDesignation.NewInstance(); |
|
169 |
DerivedUnit specimen2 = DerivedUnit.NewPreservedSpecimenInstance(); |
|
170 |
|
|
171 |
specimen.addSpecimenTypeDesignation(desig1); |
|
172 |
Assert.assertEquals("Specimen1 should be the designations specimen", specimen, desig1.getTypeSpecimen()); |
|
173 |
Assert.assertEquals("specimen1 should have exactly 1 designation", 1, specimen.getSpecimenTypeDesignations().size()); |
|
174 |
Assert.assertEquals("specimen1's designation should be desig1", desig1, specimen.getSpecimenTypeDesignations().iterator().next()); |
|
175 |
|
|
176 |
specimen.addSpecimenTypeDesignation(desig2); |
|
177 |
Assert.assertEquals("Specimen1 should be the desig2's specimen", specimen, desig2.getTypeSpecimen()); |
|
178 |
Assert.assertEquals("specimen1 should have exactly 2 designation", 2, specimen.getSpecimenTypeDesignations().size()); |
|
179 |
|
|
180 |
specimen2.addSpecimenTypeDesignation(desig2); |
|
181 |
Assert.assertEquals("Specimen2 should have replaced specimen1 as desig2's specimen", specimen2, desig2.getTypeSpecimen()); |
|
182 |
Assert.assertEquals("Specimen2 should have exactly 1 designation", 1, specimen2.getSpecimenTypeDesignations().size()); |
|
183 |
Assert.assertEquals("Specimen1's designation should be desig2", desig2, specimen2.getSpecimenTypeDesignations().iterator().next()); |
|
184 |
Assert.assertEquals("specimen1 should have exactly 1 designation", 1, specimen.getSpecimenTypeDesignations().size()); |
|
185 |
|
|
186 |
specimen2.removeSpecimenTypeDesignation(desig2); |
|
187 |
Assert.assertEquals("Desig2 should not have a specimen anymore", null, desig2.getTypeSpecimen()); |
|
188 |
Assert.assertEquals("Specimen2 should have no designation", 0, specimen2.getSpecimenTypeDesignations().size()); |
|
189 |
Assert.assertEquals("specimen1 should have exactly 1 designation", 1, specimen.getSpecimenTypeDesignations().size()); |
|
190 |
|
|
191 |
specimen.addSpecimenTypeDesignation(desig2); |
|
192 |
Assert.assertEquals("Specimen1 should be the desig2's specimen", specimen, desig2.getTypeSpecimen()); |
|
193 |
Assert.assertEquals("specimen1 should have exactly 2 designation", 2, specimen.getSpecimenTypeDesignations().size()); |
|
194 |
|
|
195 |
desig1.setTypeSpecimen(null); |
|
196 |
Assert.assertEquals("Desig1 should not have a specimen anymore", null, desig1.getTypeSpecimen()); |
|
197 |
Assert.assertEquals("Specimen1 should have 1 designation", 1, specimen.getSpecimenTypeDesignations().size()); |
|
198 |
Assert.assertEquals("Specimen1's designation should be desig2", desig2, specimen.getSpecimenTypeDesignations().iterator().next()); |
|
199 |
|
|
200 |
desig1.setTypeSpecimen(specimen); |
|
201 |
Assert.assertEquals("Desig1 should have specimen1 as specimen again", specimen, desig1.getTypeSpecimen()); |
|
202 |
Assert.assertEquals("Specimen1 should have 2 designation", 2, specimen.getSpecimenTypeDesignations().size()); |
|
203 |
|
|
204 |
} |
|
205 |
|
|
206 |
|
|
207 |
/** |
|
208 |
* Test method for {@link eu.etaxonomy.cdm.model.occurrence.Specimen#clone()}. |
|
209 |
*/ |
|
210 |
@Test |
|
211 |
public void testClone() { |
|
212 |
logger.debug("Start testClone"); |
|
213 |
|
|
214 |
//Null test is not full implemented, but an error is thrown if null throws |
|
215 |
//null pointer exception somewhere |
|
216 |
DerivedUnit specimenNullClone = (DerivedUnit)specimen.clone(); |
|
217 |
|
|
218 |
String accessionNumber = "accNumber"; |
|
219 |
String catalogNumber = "catNumber"; |
|
220 |
Collection collection = Collection.NewInstance(); |
|
221 |
collection.setCode("code"); |
|
222 |
DateTime created = new DateTime(); |
|
223 |
Person createdBy = Person.NewTitledInstance("creator"); |
|
224 |
DerivationEvent derivedFrom = DerivationEvent.NewInstance(null); |
|
225 |
int id = 22; |
|
226 |
int individualCount = 25; |
|
227 |
DefinedTerm lifeStage = DefinedTerm.NewStageInstance(null, null, null); |
|
228 |
LSID lsid = null; |
|
229 |
try { |
|
230 |
lsid = new LSID("urn:lsid:example.com:foo:1"); |
|
231 |
} catch (MalformedLSIDException e) { |
|
232 |
// TODO Auto-generated catch block |
|
233 |
e.printStackTrace(); |
|
234 |
} |
|
235 |
DerivedUnit nextVersion = DerivedUnit.NewPreservedSpecimenInstance(); |
|
236 |
DerivedUnit previousVersion = DerivedUnit.NewPreservedSpecimenInstance(); |
|
237 |
PreservationMethod preservation = PreservationMethod.NewInstance(); |
|
238 |
boolean protectedTitleCache = true; |
|
239 |
DefinedTerm sex = DefinedTerm.SEX_FEMALE(); |
|
240 |
TaxonNameBase<?, ?> storedUnder = BotanicalName.NewInstance(Rank.GENUS()); |
|
241 |
String titleCache = "title"; |
|
242 |
Calendar updated = Calendar.getInstance(); |
|
243 |
Person updatedBy = Person.NewTitledInstance("updatedPerson"); |
|
244 |
UUID uuid = UUID.randomUUID(); |
|
245 |
|
|
246 |
Annotation annotation = Annotation.NewDefaultLanguageInstance("annotation"); |
|
247 |
String definition = "definition"; |
|
248 |
//TODO |
|
249 |
DerivationEvent derivationEvent = DerivationEvent.NewInstance(null); |
|
250 |
SpecimenDescription description = SpecimenDescription.NewInstance(); |
|
251 |
DeterminationEvent determination = DeterminationEvent.NewInstance(); |
|
252 |
Extension extension = Extension.NewInstance(); |
|
253 |
extension.setValue("extension"); |
|
254 |
Marker marker = Marker.NewInstance(MarkerType.COMPLETE(), false); |
|
255 |
Rights right = Rights.NewInstance("right", Language.DEFAULT()); |
|
256 |
Media media = Media.NewInstance(); |
|
257 |
IdentifiableSource source = IdentifiableSource.NewDataImportInstance("12", "idNamespace"); |
|
258 |
|
|
259 |
specimen.setAccessionNumber(accessionNumber); |
|
260 |
specimen.setCatalogNumber(catalogNumber); |
|
261 |
specimen.setCollection(collection); |
|
262 |
specimen.setCreated(created); |
|
263 |
// specimen.setCreatedBy(createdBy); |
|
264 |
specimen.setDerivedFrom(derivedFrom); |
|
265 |
specimen.setId(id); |
|
266 |
specimen.setIndividualCount(individualCount); |
|
267 |
specimen.setLifeStage(lifeStage); |
|
268 |
specimen.setLsid(lsid); |
|
269 |
specimen.setPreservation(preservation); |
|
270 |
specimen.setProtectedTitleCache(protectedTitleCache); |
|
271 |
specimen.setSex(sex); |
|
272 |
specimen.setStoredUnder(storedUnder); |
|
273 |
specimen.setTitleCache(titleCache, protectedTitleCache); |
|
274 |
// specimen.setUpdated(updated); |
|
275 |
// specimen.setUpdatedBy(updatedBy); |
|
276 |
specimen.setUuid(uuid); |
|
277 |
|
|
278 |
specimen.addAnnotation(annotation); |
|
279 |
specimen.putDefinition(Language.DEFAULT(), definition); |
|
280 |
specimen.addDerivationEvent(derivationEvent); |
|
281 |
specimen.addDescription(description); |
|
282 |
specimen.addDetermination(determination); |
|
283 |
specimen.addExtension(extension); |
|
284 |
specimen.addMarker(marker); |
|
285 |
// specimen.addMedia(media); #3597 |
|
286 |
specimen.addRights(right); |
|
287 |
specimen.addSource(source); |
|
288 |
|
|
289 |
try { |
|
290 |
Thread.sleep(200); |
|
291 |
} catch (InterruptedException e) { |
|
292 |
//ignore |
|
293 |
} |
|
294 |
DerivedUnit specimenClone = (DerivedUnit)specimen.clone(); |
|
295 |
|
|
296 |
assertFalse(id == specimenClone.getId()); |
|
297 |
assertFalse(created.equals(specimenClone.getCreated())); |
|
298 |
assertFalse(createdBy.equals(specimenClone.getCreatedBy())); |
|
299 |
assertFalse(updated.equals(specimenClone.getUpdated())); |
|
300 |
assertFalse(updatedBy.equals(specimenClone.getUpdatedBy())); |
|
301 |
assertNull(specimenClone.getUpdatedBy()); |
|
302 |
assertNull(specimenClone.getCreatedBy()); |
|
303 |
assertFalse(uuid.equals(specimenClone.getUuid())); |
|
304 |
|
|
305 |
|
|
306 |
assertEquals(accessionNumber, specimenClone.getAccessionNumber()); |
|
307 |
assertEquals(catalogNumber, specimenClone.getCatalogNumber()); |
|
308 |
assertEquals(collection, specimenClone.getCollection()); |
|
309 |
assertEquals(derivedFrom, specimenClone.getDerivedFrom()); |
|
310 |
assertEquals(lifeStage, specimenClone.getLifeStage()); |
|
311 |
assertEquals(lsid, specimenClone.getLsid()); |
|
312 |
assertEquals(preservation, specimenClone.getPreservation()); |
|
313 |
assertEquals(protectedTitleCache, specimenClone.isProtectedTitleCache()); |
|
314 |
assertEquals(storedUnder, specimenClone.getStoredUnder()); |
|
315 |
assertEquals(sex, specimenClone.getSex()); |
|
316 |
assertEquals(titleCache, specimenClone.getTitleCache()); |
|
317 |
|
|
318 |
Annotation clonedAnnotation = specimenClone.getAnnotations().iterator().next(); |
|
319 |
assertFalse(annotation.equals(clonedAnnotation)); |
|
320 |
assertEquals(annotation.getText(), ((LanguageStringBase)specimenClone.getAnnotations().iterator().next()).getText() ); |
|
321 |
assertNotSame(annotation, specimenClone.getAnnotations().iterator().next() ); |
|
322 |
|
|
323 |
assertEquals(definition, specimenClone.getDefinition().get(Language.DEFAULT()).getText()); |
|
324 |
//TODO |
|
325 |
// assertNotSame(definition, specimenClone.getDefinition().getText(Language.DEFAULT())); |
|
326 |
|
|
327 |
assertEquals(derivationEvent, specimenClone.getDerivationEvents().iterator().next()); |
|
328 |
assertSame(derivationEvent, specimenClone.getDerivationEvents().iterator().next()); |
|
329 |
|
|
330 |
assertEquals(description, specimenClone.getDescriptions().iterator().next()); |
|
331 |
// TODO ? |
|
332 |
assertSame(description, specimenClone.getDescriptions().iterator().next()); |
|
333 |
|
|
334 |
assertEquals(determination, specimenClone.getDeterminations().iterator().next()); |
|
335 |
// TODO ? |
|
336 |
assertSame(determination, specimenClone.getDeterminations().iterator().next()); |
|
337 |
|
|
338 |
assertFalse(extension.equals(specimenClone.getExtensions().iterator().next())); |
|
339 |
assertEquals(extension.getValue(), ((Extension)specimenClone.getExtensions().iterator().next()).getValue()); |
|
340 |
assertNotSame(extension, specimenClone.getExtensions().iterator().next()); |
|
341 |
assertEquals(1, specimen.getExtensions().size()); |
|
342 |
|
|
343 |
assertFalse(marker.equals(specimenClone.getMarkers().iterator().next())); |
|
344 |
assertEquals(marker.getFlag(), ((Marker)specimenClone.getMarkers().iterator().next()).getFlag()); |
|
345 |
assertNotSame(marker, specimenClone.getMarkers().iterator().next()); |
|
346 |
assertEquals(1, specimenClone.getMarkers().size()); |
|
347 |
|
|
348 |
// assertEquals(media, specimenClone.getMedia().iterator().next()); #3597 |
|
349 |
assertEquals(right, specimenClone.getRights().iterator().next()); |
|
350 |
|
|
351 |
assertFalse(source.equals(specimenClone.getSources().iterator().next())); |
|
352 |
assertEquals(source.getId(), ((OriginalSourceBase)specimenClone.getSources().iterator().next()).getId()); |
|
353 |
assertNotSame(source, specimenClone.getSources().iterator().next()); |
|
354 |
assertEquals(1, specimenClone.getSources().size()); |
|
355 |
} |
|
356 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.occurrence; |
|
11 |
|
|
12 |
import static org.junit.Assert.assertEquals; |
|
13 |
import static org.junit.Assert.assertFalse; |
|
14 |
import static org.junit.Assert.assertNotNull; |
|
15 |
import static org.junit.Assert.assertNotSame; |
|
16 |
import static org.junit.Assert.assertNull; |
|
17 |
import static org.junit.Assert.assertSame; |
|
18 |
import static org.junit.Assert.assertTrue; |
|
19 |
|
|
20 |
import java.util.Calendar; |
|
21 |
import java.util.UUID; |
|
22 |
|
|
23 |
import org.apache.log4j.Logger; |
|
24 |
import org.joda.time.DateTime; |
|
25 |
import org.junit.Assert; |
|
26 |
import org.junit.Before; |
|
27 |
import org.junit.Test; |
|
28 |
import org.springframework.beans.BeanUtils; |
|
29 |
|
|
30 |
import com.ibm.lsid.MalformedLSIDException; |
|
31 |
|
|
32 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
33 |
import eu.etaxonomy.cdm.model.common.Annotation; |
|
34 |
import eu.etaxonomy.cdm.model.common.DefinedTerm; |
|
35 |
import eu.etaxonomy.cdm.model.common.Extension; |
|
36 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
|
37 |
import eu.etaxonomy.cdm.model.common.LSID; |
|
38 |
import eu.etaxonomy.cdm.model.common.Language; |
|
39 |
import eu.etaxonomy.cdm.model.common.LanguageStringBase; |
|
40 |
import eu.etaxonomy.cdm.model.common.Marker; |
|
41 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
|
42 |
import eu.etaxonomy.cdm.model.common.OriginalSourceBase; |
|
43 |
import eu.etaxonomy.cdm.model.description.SpecimenDescription; |
|
44 |
import eu.etaxonomy.cdm.model.media.Media; |
|
45 |
import eu.etaxonomy.cdm.model.media.Rights; |
|
46 |
import eu.etaxonomy.cdm.model.molecular.DnaSample; |
|
47 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
|
48 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
49 |
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation; |
|
50 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
51 |
|
|
52 |
/** |
|
53 |
* @author a.mueller |
|
54 |
* @created 28.10.2008 |
|
55 |
*/ |
|
56 |
public class SpecimenTest { |
|
57 |
private static final Logger logger = Logger.getLogger(SpecimenTest.class); |
|
58 |
|
|
59 |
private DerivedUnit specimen; |
|
60 |
|
|
61 |
@Before |
|
62 |
public void setUp() throws Exception { |
|
63 |
specimen = DerivedUnit.NewPreservedSpecimenInstance(); |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Test method for {@link eu.etaxonomy.cdm.model.occurrence.Specimen#NewInstance()}. |
|
68 |
*/ |
|
69 |
@Test |
|
70 |
public void testNewInstance() { |
|
71 |
DerivedUnit specimen = DerivedUnit.NewPreservedSpecimenInstance(); |
|
72 |
assertNotNull(specimen); |
|
73 |
assertTrue(specimen instanceof DerivedUnit); |
|
74 |
assertTrue(specimen.getRecordBasis().equals(SpecimenOrObservationType.PreservedSpecimen)); |
|
75 |
} |
|
76 |
|
|
77 |
/** |
|
78 |
* Test method for {@link eu.etaxonomy.cdm.model.occurrence.Specimen#getPreservation()} and |
|
79 |
* {@link eu.etaxonomy.cdm.model.occurrence.Specimen#setPreservation(eu.etaxonomy.cdm.model.occurrence.PreservationMethod)}. |
|
80 |
*/ |
|
81 |
@Test |
|
82 |
public void testGetSetPreservation() { |
|
83 |
PreservationMethod preservation = PreservationMethod.NewInstance(); |
|
84 |
specimen.setPreservation(preservation); |
|
85 |
assertSame(preservation, specimen.getPreservation()); |
|
86 |
specimen.setPreservation(null); |
|
87 |
} |
|
88 |
|
|
89 |
@Test |
|
90 |
public void testBidirectionalSpecimenDescription(){ |
|
91 |
Assert.assertNotNull("Specimen should exist", specimen); |
|
92 |
|
|
93 |
SpecimenDescription desc = SpecimenDescription.NewInstance(specimen); |
|
94 |
Assert.assertNotNull("Description should exist.", desc); |
|
95 |
Assert.assertSame("Descriptions specimen should be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
96 |
Assert.assertTrue("Specimen should contain description", specimen.getDescriptions().contains(desc)); |
|
97 |
|
|
98 |
SpecimenDescription desc2 = SpecimenDescription.NewInstance(); |
|
99 |
Assert.assertNotNull("Description should exist.", desc2); |
|
100 |
specimen.addDescription(desc2); |
|
101 |
Assert.assertSame("Description2 specimen should be set correctly", desc2.getDescribedSpecimenOrObservation(),specimen); |
|
102 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
103 |
Assert.assertTrue("Specimen should contain description2", specimen.getDescriptions().contains(desc2)); |
|
104 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
105 |
|
|
106 |
SpecimenDescription desc3 = SpecimenDescription.NewInstance(); |
|
107 |
Assert.assertNotNull("Description should exist.", desc3); |
|
108 |
desc3.setDescribedSpecimenOrObservation(specimen); |
|
109 |
Assert.assertSame("Description3 specimen should be set correctly", desc3.getDescribedSpecimenOrObservation(),specimen); |
|
110 |
Assert.assertSame("Descriptions2 specimen should still be set correctly", desc2.getDescribedSpecimenOrObservation(),specimen); |
|
111 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
112 |
Assert.assertTrue("Specimen should contain description3", specimen.getDescriptions().contains(desc3)); |
|
113 |
Assert.assertTrue("Specimen should still contain description2", specimen.getDescriptions().contains(desc2)); |
|
114 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
115 |
|
|
116 |
|
|
117 |
//change specimen of a given description |
|
118 |
DerivedUnit specimen2 = DerivedUnit.NewPreservedSpecimenInstance(); |
|
119 |
Assert.assertNotNull("Specimen should exist.", specimen2); |
|
120 |
desc3.setDescribedSpecimenOrObservation(specimen2); |
|
121 |
Assert.assertSame("Description3 new specimen should be set correctly", desc3.getDescribedSpecimenOrObservation(),specimen2); |
|
122 |
Assert.assertSame("Descriptions2 specimen should still be set correctly", desc2.getDescribedSpecimenOrObservation(),specimen); |
|
123 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
124 |
Assert.assertTrue("Specimen2 should contain description3", specimen2.getDescriptions().contains(desc3)); |
|
125 |
Assert.assertEquals("Specimen2 should contain exactly 1 description", 1, specimen2.getDescriptions().size()); |
|
126 |
Assert.assertFalse("Specimen should no longer contain description3", specimen.getDescriptions().contains(desc3)); |
|
127 |
Assert.assertTrue("Specimen should still contain description2", specimen.getDescriptions().contains(desc2)); |
|
128 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
129 |
|
|
130 |
//remove description which is not contained |
|
131 |
specimen.removeDescription(desc3); |
|
132 |
Assert.assertSame("Nothing should have changed", desc3.getDescribedSpecimenOrObservation(),specimen2); |
|
133 |
Assert.assertSame("Nothing should have changed", desc2.getDescribedSpecimenOrObservation(),specimen); |
|
134 |
Assert.assertSame("Nothing should have changed", desc.getDescribedSpecimenOrObservation(),specimen); |
|
135 |
Assert.assertTrue("Nothing should have changed", specimen2.getDescriptions().contains(desc3)); |
|
136 |
Assert.assertEquals("Nothing should have changed", 1, specimen2.getDescriptions().size()); |
|
137 |
Assert.assertFalse("Nothing should have changed", specimen.getDescriptions().contains(desc3)); |
|
138 |
Assert.assertTrue("Nothing should have changed", specimen.getDescriptions().contains(desc2)); |
|
139 |
Assert.assertTrue("Nothing should have changed", specimen.getDescriptions().contains(desc)); |
|
140 |
|
|
141 |
//remove description |
|
142 |
specimen.removeDescription(desc2); |
|
143 |
Assert.assertNull("Descriptions2 specimen should not exist anymore", desc2.getDescribedSpecimenOrObservation()); |
|
144 |
Assert.assertSame("Description3 specimen should still be set correctly", desc3.getDescribedSpecimenOrObservation(),specimen2); |
|
145 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
146 |
Assert.assertTrue("Specimen2 should still contain description3", specimen2.getDescriptions().contains(desc3)); |
|
147 |
Assert.assertEquals("Specimen2 should still contain exactly 1 description", 1, specimen2.getDescriptions().size()); |
|
148 |
Assert.assertFalse("Specimen should not contain description2 anymore", specimen.getDescriptions().contains(desc2)); |
|
149 |
Assert.assertFalse("Specimen should still no longer contain description3", specimen.getDescriptions().contains(desc3)); |
|
150 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
151 |
|
|
152 |
//remove description by setting null specimen |
|
153 |
desc3.setDescribedSpecimenOrObservation(null); |
|
154 |
Assert.assertNull("Description3 specimen should not exist anymore", desc3.getDescribedSpecimenOrObservation()); |
|
155 |
Assert.assertNull("Descriptions2 specimen should still not exist anymore", desc2.getDescribedSpecimenOrObservation()); |
|
156 |
Assert.assertSame("Descriptions specimen should still be set correctly", desc.getDescribedSpecimenOrObservation(),specimen); |
|
157 |
Assert.assertFalse("Specimen2 should not contain description3 anymore", specimen2.getDescriptions().contains(desc3)); |
|
158 |
Assert.assertEquals("Specimen2 should contain no description now", 0, specimen2.getDescriptions().size()); |
|
159 |
Assert.assertFalse("Specimen should still no longer contain description2", specimen.getDescriptions().contains(desc2)); |
|
160 |
Assert.assertFalse("Specimen should still no longer contain description3", specimen.getDescriptions().contains(desc3)); |
|
161 |
Assert.assertTrue("Specimen should still contain description", specimen.getDescriptions().contains(desc)); |
|
162 |
|
|
163 |
|
|
164 |
} |
|
165 |
|
|
166 |
|
|
167 |
@Test |
|
168 |
public void testBidirectionalTypeDesignation(){ |
|
169 |
SpecimenTypeDesignation desig1 = SpecimenTypeDesignation.NewInstance(); |
|
170 |
SpecimenTypeDesignation desig2 = SpecimenTypeDesignation.NewInstance(); |
|
171 |
DerivedUnit specimen2 = DerivedUnit.NewPreservedSpecimenInstance(); |
|
172 |
|
|
173 |
specimen.addSpecimenTypeDesignation(desig1); |
|
174 |
Assert.assertEquals("Specimen1 should be the designations specimen", specimen, desig1.getTypeSpecimen()); |
|
175 |
Assert.assertEquals("specimen1 should have exactly 1 designation", 1, specimen.getSpecimenTypeDesignations().size()); |
|
176 |
Assert.assertEquals("specimen1's designation should be desig1", desig1, specimen.getSpecimenTypeDesignations().iterator().next()); |
|
177 |
|
|
178 |
specimen.addSpecimenTypeDesignation(desig2); |
|
179 |
Assert.assertEquals("Specimen1 should be the desig2's specimen", specimen, desig2.getTypeSpecimen()); |
|
180 |
Assert.assertEquals("specimen1 should have exactly 2 designation", 2, specimen.getSpecimenTypeDesignations().size()); |
|
181 |
|
|
182 |
specimen2.addSpecimenTypeDesignation(desig2); |
|
183 |
Assert.assertEquals("Specimen2 should have replaced specimen1 as desig2's specimen", specimen2, desig2.getTypeSpecimen()); |
|
184 |
Assert.assertEquals("Specimen2 should have exactly 1 designation", 1, specimen2.getSpecimenTypeDesignations().size()); |
|
185 |
Assert.assertEquals("Specimen1's designation should be desig2", desig2, specimen2.getSpecimenTypeDesignations().iterator().next()); |
|
186 |
Assert.assertEquals("specimen1 should have exactly 1 designation", 1, specimen.getSpecimenTypeDesignations().size()); |
|
187 |
|
|
188 |
specimen2.removeSpecimenTypeDesignation(desig2); |
|
189 |
Assert.assertEquals("Desig2 should not have a specimen anymore", null, desig2.getTypeSpecimen()); |
|
190 |
Assert.assertEquals("Specimen2 should have no designation", 0, specimen2.getSpecimenTypeDesignations().size()); |
|
191 |
Assert.assertEquals("specimen1 should have exactly 1 designation", 1, specimen.getSpecimenTypeDesignations().size()); |
|
192 |
|
|
193 |
specimen.addSpecimenTypeDesignation(desig2); |
|
194 |
Assert.assertEquals("Specimen1 should be the desig2's specimen", specimen, desig2.getTypeSpecimen()); |
|
195 |
Assert.assertEquals("specimen1 should have exactly 2 designation", 2, specimen.getSpecimenTypeDesignations().size()); |
|
196 |
|
|
197 |
desig1.setTypeSpecimen(null); |
|
198 |
Assert.assertEquals("Desig1 should not have a specimen anymore", null, desig1.getTypeSpecimen()); |
|
199 |
Assert.assertEquals("Specimen1 should have 1 designation", 1, specimen.getSpecimenTypeDesignations().size()); |
|
200 |
Assert.assertEquals("Specimen1's designation should be desig2", desig2, specimen.getSpecimenTypeDesignations().iterator().next()); |
|
201 |
|
|
202 |
desig1.setTypeSpecimen(specimen); |
|
203 |
Assert.assertEquals("Desig1 should have specimen1 as specimen again", specimen, desig1.getTypeSpecimen()); |
|
204 |
Assert.assertEquals("Specimen1 should have 2 designation", 2, specimen.getSpecimenTypeDesignations().size()); |
|
205 |
|
|
206 |
} |
|
207 |
|
|
208 |
|
|
209 |
/** |
|
210 |
* Test method for {@link eu.etaxonomy.cdm.model.occurrence.Specimen#clone()}. |
|
211 |
*/ |
|
212 |
@Test |
|
213 |
public void testClone() { |
|
214 |
logger.debug("Start testClone"); |
|
215 |
|
|
216 |
//Null test is not full implemented, but an error is thrown if null throws |
|
217 |
//null pointer exception somewhere |
|
218 |
DerivedUnit specimenNullClone = (DerivedUnit)specimen.clone(); |
|
219 |
|
|
220 |
String accessionNumber = "accNumber"; |
|
221 |
String catalogNumber = "catNumber"; |
|
222 |
Collection collection = Collection.NewInstance(); |
|
223 |
collection.setCode("code"); |
|
224 |
DateTime created = new DateTime(); |
|
225 |
Person createdBy = Person.NewTitledInstance("creator"); |
|
226 |
DerivationEvent derivedFrom = DerivationEvent.NewInstance(null); |
|
227 |
int id = 22; |
|
228 |
int individualCount = 25; |
|
229 |
DefinedTerm lifeStage = DefinedTerm.NewStageInstance(null, null, null); |
|
230 |
LSID lsid = null; |
|
231 |
try { |
|
232 |
lsid = new LSID("urn:lsid:example.com:foo:1"); |
|
233 |
} catch (MalformedLSIDException e) { |
|
234 |
// TODO Auto-generated catch block |
|
235 |
e.printStackTrace(); |
|
236 |
} |
|
237 |
DerivedUnit nextVersion = DerivedUnit.NewPreservedSpecimenInstance(); |
|
238 |
DerivedUnit previousVersion = DerivedUnit.NewPreservedSpecimenInstance(); |
|
239 |
PreservationMethod preservation = PreservationMethod.NewInstance(); |
|
240 |
boolean protectedTitleCache = true; |
|
241 |
DefinedTerm sex = DefinedTerm.SEX_FEMALE(); |
|
242 |
TaxonNameBase<?, ?> storedUnder = BotanicalName.NewInstance(Rank.GENUS()); |
|
243 |
String titleCache = "title"; |
|
244 |
Calendar updated = Calendar.getInstance(); |
|
245 |
Person updatedBy = Person.NewTitledInstance("updatedPerson"); |
|
246 |
UUID uuid = UUID.randomUUID(); |
|
247 |
|
|
248 |
Annotation annotation = Annotation.NewDefaultLanguageInstance("annotation"); |
|
249 |
String definition = "definition"; |
|
250 |
//TODO |
|
251 |
DerivationEvent derivationEvent = DerivationEvent.NewInstance(null); |
|
252 |
SpecimenDescription description = SpecimenDescription.NewInstance(); |
|
253 |
DeterminationEvent determination = DeterminationEvent.NewInstance(); |
|
254 |
Extension extension = Extension.NewInstance(); |
|
255 |
extension.setValue("extension"); |
|
256 |
Marker marker = Marker.NewInstance(MarkerType.COMPLETE(), false); |
|
257 |
Rights right = Rights.NewInstance("right", Language.DEFAULT()); |
|
258 |
Media media = Media.NewInstance(); |
|
259 |
IdentifiableSource source = IdentifiableSource.NewDataImportInstance("12", "idNamespace"); |
|
260 |
|
|
261 |
specimen.setAccessionNumber(accessionNumber); |
|
262 |
specimen.setCatalogNumber(catalogNumber); |
|
263 |
specimen.setCollection(collection); |
|
264 |
specimen.setCreated(created); |
|
265 |
// specimen.setCreatedBy(createdBy); |
|
266 |
specimen.setDerivedFrom(derivedFrom); |
|
267 |
specimen.setId(id); |
|
268 |
specimen.setIndividualCount(individualCount); |
|
269 |
specimen.setLifeStage(lifeStage); |
|
270 |
specimen.setLsid(lsid); |
|
271 |
specimen.setPreservation(preservation); |
|
272 |
specimen.setProtectedTitleCache(protectedTitleCache); |
|
273 |
specimen.setSex(sex); |
|
274 |
specimen.setStoredUnder(storedUnder); |
|
275 |
specimen.setTitleCache(titleCache, protectedTitleCache); |
|
276 |
// specimen.setUpdated(updated); |
|
277 |
// specimen.setUpdatedBy(updatedBy); |
|
278 |
specimen.setUuid(uuid); |
|
279 |
|
|
280 |
specimen.addAnnotation(annotation); |
|
281 |
specimen.putDefinition(Language.DEFAULT(), definition); |
|
282 |
specimen.addDerivationEvent(derivationEvent); |
|
283 |
specimen.addDescription(description); |
|
284 |
specimen.addDetermination(determination); |
|
285 |
specimen.addExtension(extension); |
|
286 |
specimen.addMarker(marker); |
|
287 |
// specimen.addMedia(media); #3597 |
|
288 |
specimen.addRights(right); |
|
289 |
specimen.addSource(source); |
|
290 |
|
|
291 |
try { |
|
292 |
Thread.sleep(200); |
|
293 |
} catch (InterruptedException e) { |
|
294 |
//ignore |
|
295 |
} |
|
296 |
DerivedUnit specimenClone = (DerivedUnit)specimen.clone(); |
|
297 |
|
|
298 |
assertFalse(id == specimenClone.getId()); |
|
299 |
assertFalse(created.equals(specimenClone.getCreated())); |
|
300 |
assertFalse(createdBy.equals(specimenClone.getCreatedBy())); |
|
301 |
assertFalse(updated.equals(specimenClone.getUpdated())); |
|
302 |
assertFalse(updatedBy.equals(specimenClone.getUpdatedBy())); |
|
303 |
assertNull(specimenClone.getUpdatedBy()); |
|
304 |
assertNull(specimenClone.getCreatedBy()); |
|
305 |
assertFalse(uuid.equals(specimenClone.getUuid())); |
|
306 |
|
|
307 |
|
|
308 |
assertEquals(accessionNumber, specimenClone.getAccessionNumber()); |
|
309 |
assertEquals(catalogNumber, specimenClone.getCatalogNumber()); |
|
310 |
assertEquals(collection, specimenClone.getCollection()); |
|
311 |
assertEquals(derivedFrom, specimenClone.getDerivedFrom()); |
|
312 |
assertEquals(lifeStage, specimenClone.getLifeStage()); |
|
313 |
assertEquals(lsid, specimenClone.getLsid()); |
|
314 |
assertEquals(preservation, specimenClone.getPreservation()); |
|
315 |
assertEquals(protectedTitleCache, specimenClone.isProtectedTitleCache()); |
|
316 |
assertEquals(storedUnder, specimenClone.getStoredUnder()); |
|
317 |
assertEquals(sex, specimenClone.getSex()); |
|
318 |
assertEquals(titleCache, specimenClone.getTitleCache()); |
|
319 |
|
|
320 |
Annotation clonedAnnotation = specimenClone.getAnnotations().iterator().next(); |
|
321 |
assertFalse(annotation.equals(clonedAnnotation)); |
|
322 |
assertEquals(annotation.getText(), ((LanguageStringBase)specimenClone.getAnnotations().iterator().next()).getText() ); |
|
323 |
assertNotSame(annotation, specimenClone.getAnnotations().iterator().next() ); |
|
324 |
|
|
325 |
assertEquals(definition, specimenClone.getDefinition().get(Language.DEFAULT()).getText()); |
|
326 |
//TODO |
|
327 |
// assertNotSame(definition, specimenClone.getDefinition().getText(Language.DEFAULT())); |
|
328 |
|
|
329 |
assertEquals(derivationEvent, specimenClone.getDerivationEvents().iterator().next()); |
|
330 |
assertSame(derivationEvent, specimenClone.getDerivationEvents().iterator().next()); |
|
331 |
|
|
332 |
assertEquals(description, specimenClone.getDescriptions().iterator().next()); |
|
333 |
// TODO ? |
|
334 |
assertSame(description, specimenClone.getDescriptions().iterator().next()); |
|
335 |
|
|
336 |
assertEquals(determination, specimenClone.getDeterminations().iterator().next()); |
|
337 |
// TODO ? |
|
338 |
assertSame(determination, specimenClone.getDeterminations().iterator().next()); |
|
339 |
|
|
340 |
assertFalse(extension.equals(specimenClone.getExtensions().iterator().next())); |
|
341 |
assertEquals(extension.getValue(), specimenClone.getExtensions().iterator().next().getValue()); |
|
342 |
assertNotSame(extension, specimenClone.getExtensions().iterator().next()); |
|
343 |
assertEquals(1, specimen.getExtensions().size()); |
|
344 |
|
|
345 |
assertFalse(marker.equals(specimenClone.getMarkers().iterator().next())); |
|
346 |
assertEquals(marker.getFlag(), specimenClone.getMarkers().iterator().next().getFlag()); |
|
347 |
assertNotSame(marker, specimenClone.getMarkers().iterator().next()); |
|
348 |
assertEquals(1, specimenClone.getMarkers().size()); |
|
349 |
|
|
350 |
// assertEquals(media, specimenClone.getMedia().iterator().next()); #3597 |
|
351 |
assertEquals(right, specimenClone.getRights().iterator().next()); |
|
352 |
|
|
353 |
assertFalse(source.equals(specimenClone.getSources().iterator().next())); |
|
354 |
assertEquals(source.getId(), ((OriginalSourceBase)specimenClone.getSources().iterator().next()).getId()); |
|
355 |
assertNotSame(source, specimenClone.getSources().iterator().next()); |
|
356 |
assertEquals(1, specimenClone.getSources().size()); |
|
357 |
} |
|
358 |
|
|
359 |
|
|
360 |
@Test |
|
361 |
public void beanTests(){ |
|
362 |
// #5307 Test that BeanUtils does not fail |
|
363 |
BeanUtils.getPropertyDescriptors(DerivedUnit.class); |
|
364 |
BeanUtils.getPropertyDescriptors(SpecimenOrObservationBase.class); |
|
365 |
BeanUtils.getPropertyDescriptors(FieldUnit.class); |
|
366 |
BeanUtils.getPropertyDescriptors(MediaSpecimen.class); |
|
367 |
BeanUtils.getPropertyDescriptors(DnaSample.class); |
|
368 |
} |
|
369 |
} |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/reference/PublicationBaseTest.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.reference; |
|
11 |
|
|
12 |
import static org.junit.Assert.*; |
|
13 |
|
|
14 |
import java.util.List; |
|
15 |
|
|
16 |
import org.apache.log4j.Logger; |
|
17 |
import org.junit.After; |
|
18 |
import org.junit.AfterClass; |
|
19 |
import org.junit.Before; |
|
20 |
import org.junit.BeforeClass; |
|
21 |
import org.junit.Ignore; |
|
22 |
import org.junit.Test; |
|
23 |
|
|
24 |
/** |
|
25 |
* @author a.mueller |
|
26 |
* @created 23.03.2009 |
|
27 |
* @version 1.0 |
|
28 |
*/ |
|
29 |
//@Ignore |
|
30 |
public class PublicationBaseTest { |
|
31 |
@SuppressWarnings("unused") |
|
32 |
private static Logger logger = Logger.getLogger(PublicationBaseTest.class); |
|
33 |
|
|
34 |
private IBook publicationBase; |
|
35 |
private IArticle publicationBase2; |
|
36 |
private String publisher1; |
|
37 |
private String publisher2; |
|
38 |
private String place1; |
|
39 |
private String place2; |
|
40 |
|
|
41 |
/** |
|
42 |
* @throws java.lang.Exception |
|
43 |
*/ |
|
44 |
@BeforeClass |
|
45 |
public static void setUpBeforeClass() throws Exception { |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* @throws java.lang.Exception |
|
50 |
*/ |
|
51 |
@AfterClass |
|
52 |
public static void tearDownAfterClass() throws Exception { |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* @throws java.lang.Exception |
|
57 |
*/ |
|
58 |
@Before |
|
59 |
public void setUp() throws Exception { |
|
60 |
publisher1 = "publisher1"; |
|
61 |
publisher2 = "publisher2"; |
|
62 |
place1 = "place1"; |
|
63 |
place2 = "place2"; |
|
64 |
|
|
65 |
|
|
66 |
publicationBase = ReferenceFactory.newBook(); |
|
67 |
|
|
68 |
publicationBase2 = ReferenceFactory.newArticle(); |
|
69 |
|
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* @throws java.lang.Exception |
|
74 |
*/ |
|
75 |
@After |
|
76 |
public void tearDown() throws Exception { |
|
77 |
} |
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
/** |
|
82 |
* Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#addPublisher(java.lang.String, java.lang.String)}. |
|
83 |
*/ |
|
84 |
@Test |
|
85 |
public void testAddPublisherStringString() { |
|
86 |
assertEquals("No publisher is set", null, publicationBase.getPublisher()); |
|
87 |
publicationBase.setPublisher(publisher1, place1); |
|
88 |
assertEquals("The publishers is publisher1", publisher1, publicationBase.getPublisher()); |
|
89 |
assertEquals("The place is place1", place1, publicationBase.getPlacePublished()); |
|
90 |
publicationBase.setPublisher(publisher2, place2); |
|
91 |
assertEquals("Second publisher must be publisher2", publisher2, publicationBase.getPublisher()); |
|
92 |
|
|
93 |
assertEquals("Second publication place must be place2", place2, publicationBase.getPlacePublished()); |
|
94 |
} |
|
95 |
|
|
96 |
@Test |
|
97 |
public void testInReferenceValidation(){ |
|
98 |
IJournal journal = ReferenceFactory.newJournal(); |
|
99 |
publicationBase2.setInJournal(journal); |
|
100 |
//TODO: to validate it, the object has to be saved to the db |
|
101 |
IBookSection booksection = ((Reference)publicationBase2).castReferenceToBookSection(); |
|
102 |
|
|
103 |
|
|
104 |
} |
|
105 |
|
|
106 |
|
|
107 |
// /** |
|
108 |
// * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#addPublisher(java.lang.String, java.lang.String, int)}. |
|
109 |
// */ |
|
110 |
// @Test(expected=IndexOutOfBoundsException.class) |
|
111 |
// public void testAddPublisherStringStringInt() { |
|
112 |
// publicationBase.addPublisher(publisher1, place1); |
|
113 |
// publicationBase.addPublisher(publisher2, place2); |
|
114 |
// assertEquals("Publishers list must contains exactly 2 entry", 2, publicationBase.getPublishers().size()); |
|
115 |
// String indexPublisher = "indexPublisher"; |
|
116 |
// String indexPlace = "indexPlace"; |
|
117 |
// publicationBase.addPublisher(indexPublisher, indexPlace, 1); |
|
118 |
// assertEquals("Publisher at position 1 (starting at 0) should be 'indexPublisher'", indexPublisher, publicationBase.getPublishers().get(1).getPublisherName()); |
|
119 |
// publicationBase.addPublisher(indexPublisher, indexPlace, 5); |
|
120 |
// } |
|
121 |
|
|
122 |
|
|
123 |
// /** |
|
124 |
// * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#getPublisher(java.lang.int}. |
|
125 |
// */ |
|
126 |
// @Test(expected=IndexOutOfBoundsException.class) |
|
127 |
// public void testGetPublisherInt() { |
|
128 |
// publicationBase.addPublisher(publisher1, place1); |
|
129 |
// publicationBase.addPublisher(publisher2, place2); |
|
130 |
// assertEquals("Publishers list must contains exactly 2 entry", 2, publicationBase.getPublishers().size()); |
|
131 |
// assertEquals("First publisher must be publisher1", publisher1, publicationBase.getPublisher(0).getPublisherName()); |
|
132 |
// publicationBase.getPublisher(2); |
|
133 |
// publicationBase.getPublisher(-1); |
|
134 |
// } |
|
135 |
|
|
136 |
// /** |
|
137 |
// * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#removePublisher(eu.etaxonomy.cdm.model.reference.Publisher)}. |
|
138 |
// */ |
|
139 |
// @Test |
|
140 |
// public void testRemovePublisher() { |
|
141 |
// publicationBase.addPublisher(publisher1, place1); |
|
142 |
// publicationBase.addPublisher(publisher2, place2); |
|
143 |
// assertEquals("Publishers list must contains exactly 2 entry", 2, publicationBase.getPublishers().size()); |
|
144 |
// publicationBase.removePublisher(publicationBase.getPublishers().get(0)); |
|
145 |
// assertEquals("Publishers list must contains exactly 1 entry", 1, publicationBase.getPublishers().size()); |
|
146 |
// List<Publisher> publishers = publicationBase.getPublishers(); |
|
147 |
// assertEquals("Only publisher must be publisher2", publisher2, publishers.get(0).getPublisherName()); |
|
148 |
// assertEquals("only publication place must be place2", place2, publishers.get(0).getPlace()); |
|
149 |
// } |
|
150 |
|
|
151 |
// /** |
|
152 |
// * Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#clone()}. |
|
153 |
// */ |
|
154 |
// @Test |
|
155 |
// public void testClone() { |
|
156 |
// publicationBase.addPublisher(publisher1, place1); |
|
157 |
// publicationBase.addPublisher(publisher2, place2); |
|
158 |
// assertEquals("Publishers list must contains exactly 2 entry", 2, publicationBase.getPublishers().size()); |
|
159 |
// CdDvd clone = (CdDvd)publicationBase.clone(); |
|
160 |
// assertEquals("Publisher place must be equal in original publication and cloned publication", place1, clone.getPublisher(0).getPlace()); |
|
161 |
// assertNotSame(place1, publicationBase.getPublisher(0), clone.getPublisher(0)); |
|
162 |
// } |
|
163 |
} |
|
1 |
/** |
|
2 |
* Copyright (C) 2007 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.reference; |
|
11 |
|
|
12 |
import static org.junit.Assert.assertEquals; |
|
13 |
|
|
14 |
import org.apache.log4j.Logger; |
|
15 |
import org.junit.After; |
|
16 |
import org.junit.AfterClass; |
|
17 |
import org.junit.Assert; |
|
18 |
import org.junit.Before; |
|
19 |
import org.junit.BeforeClass; |
|
20 |
import org.junit.Test; |
|
21 |
import org.springframework.beans.BeanUtils; |
|
22 |
|
|
23 |
/** |
|
24 |
* @author a.mueller |
|
25 |
* @created 23.03.2009 |
|
26 |
* @version 1.0 |
|
27 |
*/ |
|
28 |
//@Ignore |
|
29 |
public class PublicationBaseTest { |
|
30 |
@SuppressWarnings("unused") |
|
31 |
private static Logger logger = Logger.getLogger(PublicationBaseTest.class); |
|
32 |
|
|
33 |
private IBook reference; |
|
34 |
private IArticle reference2; |
|
35 |
private String publisher1; |
|
36 |
private String publisher2; |
|
37 |
private String place1; |
|
38 |
private String place2; |
|
39 |
|
|
40 |
/** |
|
41 |
* @throws java.lang.Exception |
|
42 |
*/ |
|
43 |
@BeforeClass |
|
44 |
public static void setUpBeforeClass() throws Exception { |
|
45 |
} |
|
46 |
|
|
47 |
/** |
|
48 |
* @throws java.lang.Exception |
|
49 |
*/ |
|
50 |
@AfterClass |
|
51 |
public static void tearDownAfterClass() throws Exception { |
|
52 |
} |
|
53 |
|
|
54 |
/** |
|
55 |
* @throws java.lang.Exception |
|
56 |
*/ |
|
57 |
@Before |
|
58 |
public void setUp() throws Exception { |
|
59 |
publisher1 = "publisher1"; |
|
60 |
publisher2 = "publisher2"; |
|
61 |
place1 = "place1"; |
|
62 |
place2 = "place2"; |
|
63 |
reference = ReferenceFactory.newBook(); |
|
64 |
reference2 = ReferenceFactory.newArticle(); |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
/** |
|
69 |
* @throws java.lang.Exception |
|
70 |
*/ |
|
71 |
@After |
|
72 |
public void tearDown() throws Exception { |
|
73 |
} |
|
74 |
|
|
75 |
|
|
76 |
|
|
77 |
/** |
|
78 |
* Test method for {@link eu.etaxonomy.cdm.model.reference.PublicationBase#addPublisher(java.lang.String, java.lang.String)}. |
|
79 |
*/ |
|
80 |
@Test |
|
81 |
public void testAddPublisherStringString() { |
|
82 |
assertEquals("No publisher is set", null, reference.getPublisher()); |
|
83 |
reference.setPublisher(publisher1, place1); |
|
84 |
assertEquals("The publishers is publisher1", publisher1, reference.getPublisher()); |
|
85 |
assertEquals("The place is place1", place1, reference.getPlacePublished()); |
|
86 |
reference.setPublisher(publisher2, place2); |
|
87 |
assertEquals("Second publisher must be publisher2", publisher2, reference.getPublisher()); |
|
88 |
|
|
89 |
assertEquals("Second publication place must be place2", place2, reference.getPlacePublished()); |
|
90 |
} |
|
91 |
|
|
92 |
@Test |
|
93 |
public void testInReferenceValidation(){ |
|
94 |
IJournal journal = ReferenceFactory.newJournal(); |
|
95 |
reference2.setInJournal(journal); |
|
96 |
//TODO: to validate it, the object has to be saved to the db |
|
97 |
IBookSection booksection = ((Reference)reference2).castReferenceToBookSection(); |
|
98 |
|
|
99 |
} |
|
100 |
|
|
101 |
|
|
102 |
/** |
|
103 |
* Test method for {@link eu.etaxonomy.cdm.model.reference.Reference#clone()}. |
|
104 |
* This test was originally designed for the case when publisher was still |
|
105 |
* a subclass holding publishing information. The current model is simplified |
|
106 |
* and therefore this test is more or less obsolet |
|
107 |
*/ |
|
108 |
@Test |
|
109 |
public void testClone() { |
|
110 |
reference.setPublisher(publisher1, place1); |
|
111 |
// publicationBase.addPublisher(publisher2, place2); |
|
112 |
Reference<?> clone = (Reference<?>)reference.clone(); |
|
113 |
assertEquals("Publisher place must be equal in original publication and cloned publication", place1, clone.getPlacePublished()); |
|
114 |
Assert.assertSame(place1, reference.getPublisher(), clone.getPublisher()); |
|
115 |
} |
|
116 |
|
|
117 |
@Test |
|
118 |
public void beanTests(){ |
|
119 |
// #5307 Test that BeanUtils does not fail |
|
120 |
BeanUtils.getPropertyDescriptors(Reference.class); |
|
121 |
} |
|
122 |
} |
cdmlib-model/src/test/java/eu/etaxonomy/cdm/model/taxon/ClassificationTest.java | ||
---|---|---|
1 |
// $Id$ |
|
2 |
/** |
|
3 |
* Copyright (C) 2007 EDIT |
|
4 |
* European Distributed Institute of Taxonomy |
|
5 |
* http://www.e-taxonomy.eu |
|
6 |
* |
|
7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
9 |
*/ |
|
10 |
|
|
11 |
package eu.etaxonomy.cdm.model.taxon; |
|
12 |
|
|
13 |
import static org.junit.Assert.assertEquals; |
|
14 |
import static org.junit.Assert.assertFalse; |
|
15 |
import static org.junit.Assert.assertNotSame; |
|
16 |
import static org.junit.Assert.assertNull; |
|
17 |
import static org.junit.Assert.assertSame; |
|
18 |
import static org.junit.Assert.assertTrue; |
|
19 |
|
|
20 |
import java.lang.reflect.Field; |
|
21 |
import java.lang.reflect.Method; |
|
22 |
import java.lang.reflect.Modifier; |
|
23 |
import java.util.HashSet; |
|
24 |
import java.util.Iterator; |
|
25 |
import java.util.List; |
|
26 |
import java.util.Set; |
|
27 |
|
|
28 |
import org.junit.Assert; |
|
29 |
|
|
30 |
import org.apache.commons.lang.StringUtils; |
|
31 |
import org.apache.log4j.Logger; |
|
32 |
import org.junit.After; |
|
33 |
import org.junit.AfterClass; |
|
34 |
import org.junit.Before; |
|
35 |
import org.junit.BeforeClass; |
|
36 |
import org.junit.Test; |
|
37 |
|
|
38 |
import eu.etaxonomy.cdm.model.agent.Person; |
|
39 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
40 |
import eu.etaxonomy.cdm.model.name.BotanicalName; |
|
41 |
import eu.etaxonomy.cdm.model.name.Rank; |
|
42 |
import eu.etaxonomy.cdm.model.name.TaxonNameBase; |
|
43 |
import eu.etaxonomy.cdm.model.name.ZoologicalName; |
|
44 |
//import eu.etaxonomy.cdm.model.reference.Book; |
|
45 |
//import eu.etaxonomy.cdm.model.reference.Journal; |
|
46 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
47 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
48 |
|
|
49 |
/** |
|
50 |
* @author a.mueller |
|
51 |
* @created 01.04.2009 |
|
52 |
* @version 1.0 |
|
53 |
*/ |
|
54 |
public class ClassificationTest { |
|
55 |
private static final Logger logger = Logger.getLogger(ClassificationTest.class); |
|
56 |
|
|
57 |
private static String treeName1; |
|
58 |
private static Classification classification1; |
|
59 |
private static TaxonNode taxonNode1; |
|
60 |
private static TaxonNode taxonNode2; |
|
61 |
private static TaxonNode taxonNode3; |
|
62 |
private static TaxonNode taxonNode12; |
|
63 |
private static TaxonNode taxonNode121; |
|
64 |
private static Taxon taxon1; |
|
65 |
private static Taxon taxon2; |
|
66 |
private static Taxon taxon3; |
|
67 |
private static Taxon taxon12; |
|
68 |
private static Taxon taxon121; |
|
69 |
private static TaxonNameBase<?,?> taxonName1; |
|
70 |
private static TaxonNameBase<?,?> taxonName2; |
|
71 |
private static TaxonNameBase<?,?> taxonName3; |
|
72 |
private static TaxonNameBase<?,?> taxonName12; |
|
73 |
private static TaxonNameBase<?,?> taxonName121; |
|
74 |
private static Reference<?> ref1; |
|
75 |
private static Reference<?> ref2; |
|
76 |
private static Reference<?> ref3; |
|
77 |
//private ReferenceFactory refFactory; |
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
/** |
|
82 |
* @throws java.lang.Exception |
|
83 |
*/ |
|
84 |
@BeforeClass |
|
85 |
public static void setUpBeforeClass() throws Exception { |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* @throws java.lang.Exception |
|
90 |
*/ |
|
91 |
@AfterClass |
|
92 |
public static void tearDownAfterClass() throws Exception { |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* @throws java.lang.Exception |
|
97 |
*/ |
|
98 |
@Before |
|
99 |
public void setUp() throws Exception { |
|
100 |
treeName1 = "Greuther, 1993"; |
|
101 |
//refFactory = ReferenceFactory.newInstance(); |
|
102 |
classification1 = Classification.NewInstance(treeName1); |
|
103 |
taxonName12 = BotanicalName.NewInstance(Rank.SPECIES()); |
|
104 |
taxonName121 = BotanicalName.NewInstance(Rank.SUBSPECIES()); |
|
105 |
taxonName1 = BotanicalName.NewInstance(Rank.GENUS()); |
|
106 |
taxonName2 = ZoologicalName.NewInstance(Rank.GENUS()); |
|
107 |
taxonName3 = BotanicalName.NewInstance(Rank.SPECIES()); |
|
108 |
ref1 = ReferenceFactory.newJournal(); |
|
109 |
ref2 = ReferenceFactory.newJournal(); |
|
110 |
ref3 = ReferenceFactory.newJournal(); |
|
111 |
taxon1 = Taxon.NewInstance(taxonName1, ref1); |
|
112 |
taxon2 = Taxon.NewInstance(taxonName2, ref2); |
|
113 |
taxon3 = Taxon.NewInstance(taxonName3, ref3); |
|
114 |
taxon12 = Taxon.NewInstance(taxonName12, ref3); |
|
115 |
taxon121 = Taxon.NewInstance(taxonName121, ref3); |
|
116 |
|
|
117 |
//taxonNode1 = new TaxonNode(taxon1, taxonomicView1); |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* @throws java.lang.Exception |
|
122 |
*/ |
|
123 |
@After |
|
124 |
public void tearDown() throws Exception { |
|
125 |
} |
|
126 |
|
|
127 |
//****************************** TESTS *****************************************/ |
|
128 |
|
|
129 |
/** |
|
130 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.Classification#addRoot(eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String, eu.etaxonomy.cdm.model.taxon.Synonym)}. |
|
131 |
*/ |
|
132 |
@Test |
|
133 |
public void testAddRoot() { |
|
134 |
TaxonNameBase<?,?> synonymName = BotanicalName.NewInstance(Rank.SPECIES()); |
|
135 |
Synonym synonym = Synonym.NewInstance(synonymName, ref1); |
|
136 |
TaxonNode taxonNode1 = classification1.addChildTaxon(taxon1, null, null); |
|
137 |
taxonNode1.setSynonymToBeUsed(synonym); |
|
138 |
|
|
139 |
|
|
140 |
|
|
141 |
//test root node |
|
142 |
List<TaxonNode> rootNodes = classification1.getChildNodes(); |
|
143 |
assertFalse("List of root nodes should not be empty", rootNodes.isEmpty()); |
|
144 |
assertEquals("Number of root nodes should be 1", 1, rootNodes.size()); |
|
145 |
TaxonNode root = rootNodes.iterator().next(); |
|
146 |
assertEquals(taxon1, root.getTaxon()); |
|
147 |
assertSame(taxonNode1, root); |
|
148 |
assertNull(root.getReference()); |
|
149 |
assertNull(root.getMicroReference()); |
|
150 |
assertEquals(synonym, root.getSynonymToBeUsed()); |
|
151 |
|
|
152 |
//any node |
|
153 |
List<TaxonNode> allNodes = classification1.getChildNodes(); |
|
154 |
assertFalse("List of root nodes should not be empty", allNodes.isEmpty()); |
|
155 |
assertEquals("Number of root nodes should be 1", 1, allNodes.size()); |
|
156 |
TaxonNode anyNode = allNodes.iterator().next(); |
|
157 |
assertSame("Taxon for TaxonNode should be the same added to the view", taxon1, anyNode.getTaxon()); |
|
158 |
assertSame("TaxonNode should be the same added to the view", taxonNode1, anyNode); |
|
159 |
|
|
160 |
} |
|
161 |
|
|
162 |
/** |
|
163 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.Classification#isTaxonInView(eu.etaxonomy.cdm.model.taxon.Taxon)}. |
|
164 |
*/ |
|
165 |
@Test |
|
166 |
public void testIsTaxonInTree() { |
|
167 |
classification1.addChildTaxon(taxon1, null, null); |
|
168 |
|
|
169 |
assertTrue(classification1.isTaxonInTree(taxon1)); |
|
170 |
Taxon anyTaxon = Taxon.NewInstance(null, null); |
|
171 |
assertFalse(classification1.isTaxonInTree(anyTaxon)); |
|
172 |
} |
|
173 |
|
|
174 |
|
|
175 |
/** |
|
176 |
* Test method for {@link eu.etaxonomy.cdm.model.taxon.Classification#makeRootChildOfOtherNode(eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.taxon.TaxonNode, eu.etaxonomy.cdm.model.reference.Reference, java.util.String)}. |
|
177 |
*/ |
|
178 |
@Test |
|
179 |
public void testMakeRootChildOfOtherNode() { |
|
180 |
TaxonNode root1 = classification1.addChildTaxon(taxon1, null, null); |
|
181 |
TaxonNode root2 = classification1.addChildTaxon(taxon2, null, null); |
|
182 |
Taxon taxon3 = Taxon.NewInstance(null, null); |
|
183 |
root2.addChildTaxon(taxon3, null, null); |
|
184 |
String microRef = "p55"; |
|
185 |
|
|
186 |
assertFalse("Root1 must not yet be child of root 2", root2.getChildNodes().contains(root1)); |
|
187 |
assertNotSame("Root2 must not yet be parent of root 1", root2, root1.getParent()); |
|
188 |
assertEquals("view must contain 3 nodes", 3, classification1.getAllNodes().size()); |
|
189 |
assertEquals("view must still contain 2 root", 2, classification1.getChildNodes().size()); |
|
190 |
assertEquals("root2 must have 1 child", 1, root2.getChildNodes().size()); |
|
191 |
|
|
192 |
classification1.makeTopmostNodeChildOfOtherNode(root1, root2, ref1, microRef); |
|
193 |
assertTrue("Root1 must be child of root 2", root2.getChildNodes().contains(root1)); |
|
194 |
assertSame("Root2 must be parent of root 1", root2, root1.getParent()); |
|
195 |
assertEquals("view must contain 3 nodes", 3, classification1.getAllNodes().size()); |
|
196 |
assertEquals("view must contain 1 root", 1, classification1.getChildNodes().size()); |
|
197 |
assertEquals("new child node must have the expected reference for parent child relationship", ref1, root1.getReference()); |
|
198 |
assertEquals("new child node must have the expected micro reference for parent child relationship", microRef, root1.getMicroReference()); |
|
199 |
assertEquals("root2 must have 2 children", 2, root2.getChildNodes().size()); |
|
200 |
|
|
201 |
} |
|
202 |
|
|
203 |
@Test |
|
204 |
public void testIsTopmostInTree() { |
|
205 |
TaxonNode root = classification1.addChildTaxon(taxon1, null, null); |
|
206 |
|
|
207 |
assertTrue(classification1.isTaxonInTree(taxon1)); |
|
208 |
assertTrue(classification1.isTopmostInTree(taxon1)); |
|
209 |
Taxon anyTaxon = Taxon.NewInstance(null, null); |
|
210 |
assertFalse(classification1.isTaxonInTree(anyTaxon)); |
|
211 |
assertFalse(classification1.isTopmostInTree(anyTaxon)); |
|
212 |
Taxon child = Taxon.NewInstance(null, null); |
|
213 |
root.addChildTaxon(child, null, null); |
|
214 |
assertTrue(classification1.isTaxonInTree(child)); |
|
215 |
assertFalse(classification1.isTopmostInTree(child)); |
|
216 |
} |
|
217 |
|
|
218 |
@Test |
|
219 |
public void testGetTopmostNode() { |
|
220 |
TaxonNode root = classification1.addChildTaxon(taxon1, null, null); |
|
221 |
|
|
222 |
assertEquals(root, classification1.getTopmostNode(taxon1)); |
|
223 |
Taxon anyTaxon = Taxon.NewInstance(null, null); |
|
224 |
assertFalse(classification1.isTaxonInTree(anyTaxon)); |
|
225 |
assertNull(classification1.getTopmostNode(anyTaxon)); |
|
226 |
Taxon child = Taxon.NewInstance(null, null); |
|
227 |
root.addChildTaxon(child, null, null); |
|
228 |
assertTrue(classification1.isTaxonInTree(child)); |
|
229 |
assertNull(classification1.getTopmostNode(child)); |
|
230 |
} |
|
231 |
|
|
232 |
@Test |
|
233 |
public void testAddParentChild() { |
|
234 |
|
|
235 |
TaxonNameBase<?,?> synonymName = BotanicalName.NewInstance(Rank.SPECIES()); |
|
236 |
Synonym synonym = Synonym.NewInstance(synonymName, ref1); |
|
237 |
TaxonNode rootNode = classification1.addChildTaxon(taxon1, null, null); |
|
238 |
rootNode.setSynonymToBeUsed(synonym); |
|
239 |
Assert.assertEquals(0,rootNode.getChildNodes().size()); |
|
240 |
|
|
241 |
//add child to existing root |
|
242 |
classification1.addParentChild(taxon1, taxon2, ref1, "Micro1"); |
|
243 |
Assert.assertTrue(classification1.isTaxonInTree(taxon2)); |
|
244 |
Assert.assertFalse(classification1.isTopmostInTree(taxon2)); |
|
245 |
Assert.assertEquals(1,rootNode.getChildNodes().size()); |
|
246 |
TaxonNode childNode = rootNode.getChildNodes().iterator().next(); |
|
247 |
Assert.assertEquals(taxon2, childNode.getTaxon()); |
|
248 |
|
|
249 |
//relationship already exists |
|
250 |
classification1.addParentChild(taxon1, taxon2, ref2, "Micro2"); |
|
251 |
Assert.assertTrue(classification1.isTaxonInTree(taxon2)); |
|
252 |
Assert.assertFalse(classification1.isTopmostInTree(taxon2)); |
|
253 |
Assert.assertEquals(2, classification1.getAllNodes().size()); |
|
254 |
Assert.assertEquals(1,rootNode.getChildNodes().size()); |
|
255 |
childNode = rootNode.getChildNodes().iterator().next(); |
Also available in: Unified diff
Add some more BeanUtil test to other classes #5307