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.api.service;
|
12
|
|
13
|
import java.util.Set;
|
14
|
|
15
|
import junit.framework.Assert;
|
16
|
|
17
|
import org.junit.Before;
|
18
|
import org.junit.Test;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
21
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
22
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
23
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
24
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
|
25
|
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
27
|
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
|
28
|
|
29
|
/**
|
30
|
* This test checks of all the business logic methods do what they are expected to do.
|
31
|
*
|
32
|
* @author n.hoffmann
|
33
|
* @created Dec 16, 2010
|
34
|
* @version 1.0
|
35
|
*/
|
36
|
public class TaxonServiceImplBusinessTest {
|
37
|
|
38
|
private Synonym s1;
|
39
|
private Taxon t2;
|
40
|
private Taxon t1;
|
41
|
private TaxonServiceImpl service;
|
42
|
private String referenceDetail;
|
43
|
private Reference reference;
|
44
|
private SynonymRelationshipType synonymRelationshipType;
|
45
|
private NonViralName s1n;
|
46
|
private NonViralName t2n;
|
47
|
private NonViralName t1n;
|
48
|
|
49
|
/**
|
50
|
* @throws java.lang.Exception
|
51
|
*/
|
52
|
@Before
|
53
|
public void setUp() throws Exception {
|
54
|
service = new TaxonServiceImpl();
|
55
|
|
56
|
t1n = NonViralName.NewInstance(null);
|
57
|
t1 = Taxon.NewInstance(t1n, reference);
|
58
|
|
59
|
t2n = NonViralName.NewInstance(null);
|
60
|
t2 = Taxon.NewInstance(t2n, reference);
|
61
|
|
62
|
s1n = NonViralName.NewInstance(null);
|
63
|
s1 = Synonym.NewInstance(s1n, reference);
|
64
|
|
65
|
// referencing
|
66
|
synonymRelationshipType = SynonymRelationshipType.HOMOTYPIC_SYNONYM_OF();
|
67
|
reference = ReferenceFactory.newGeneric();
|
68
|
referenceDetail = "test";
|
69
|
}
|
70
|
|
71
|
|
72
|
/**
|
73
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#swapSynonymAndAcceptedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon)}.
|
74
|
*/
|
75
|
@Test
|
76
|
public final void testSwapSynonymAndAcceptedTaxon() {
|
77
|
t1.addSynonym(s1, synonymRelationshipType);
|
78
|
|
79
|
service.swapSynonymAndAcceptedTaxon(s1, t1);
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#changeSynonymToAcceptedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon)}.
|
84
|
*/
|
85
|
@Test
|
86
|
public final void testChangeSynonymToAcceptedTaxon() {
|
87
|
t1.addSynonym(s1, synonymRelationshipType);
|
88
|
Taxon taxon = service.changeSynonymToAcceptedTaxon(s1, t1);
|
89
|
|
90
|
Assert.assertTrue("Former accepted taxon should not have synonyms anymore", t1.getSynonyms().isEmpty());
|
91
|
Assert.assertNotNull(taxon);
|
92
|
Assert.assertEquals(s1n, taxon.getName());
|
93
|
}
|
94
|
|
95
|
/**
|
96
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#changeSynonymToRelatedTaxon(eu.etaxonomy.cdm.model.taxon.Synonym, eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
|
97
|
*/
|
98
|
@Test
|
99
|
public final void testChangeSynonymToRelatedTaxon() {
|
100
|
t1.addSynonym(s1, synonymRelationshipType);
|
101
|
service.changeSynonymToRelatedTaxon(s1, t2, TaxonRelationshipType.CONGRUENT_OR_EXCLUDES(), reference, referenceDetail);
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* Test method for {@link eu.etaxonomy.cdm.api.service.TaxonServiceImpl#moveSynonymToAnotherTaxon(eu.etaxonomy.cdm.model.taxon.SynonymRelationship, eu.etaxonomy.cdm.model.taxon.Taxon, eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType, eu.etaxonomy.cdm.model.reference.Reference, java.lang.String)}.
|
106
|
*/
|
107
|
@Test
|
108
|
public final void testMoveSynonymToAnotherTaxon() {
|
109
|
t1.addSynonym(s1, synonymRelationshipType);
|
110
|
|
111
|
SynonymRelationship synonymRelation = t1.getSynonymRelations().iterator().next();
|
112
|
|
113
|
service.moveSynonymToAnotherTaxon(synonymRelation, t2, synonymRelationshipType, reference, referenceDetail);
|
114
|
|
115
|
Assert.assertTrue("t1 should have no synonym relationships", t1.getSynonymRelations().isEmpty());
|
116
|
|
117
|
Set<SynonymRelationship> synonymRelations = t2.getSynonymRelations();
|
118
|
Assert.assertTrue("t2 should have exactly one synonym relationship", synonymRelations.size() == 1);
|
119
|
|
120
|
synonymRelation = synonymRelations.iterator().next();
|
121
|
|
122
|
Assert.assertEquals(t2, synonymRelation.getAcceptedTaxon());
|
123
|
Assert.assertEquals(synonymRelationshipType, synonymRelation.getType());
|
124
|
Assert.assertEquals(reference, synonymRelation.getCitation());
|
125
|
Assert.assertEquals(referenceDetail, synonymRelation.getCitationMicroReference());
|
126
|
}
|
127
|
|
128
|
}
|