2 * Copyright (C) 2007 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
.taxeditor
.store
.operations
;
14 import junit
.framework
.Assert
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.junit
.BeforeClass
;
19 import org
.junit
.Test
;
21 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
22 import eu
.etaxonomy
.cdm
.model
.common
.DefaultTermInitializer
;
23 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
24 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
25 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
29 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
30 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
37 public class SwapSynonymAndAcceptedOperationTest
extends AbstractTaxeditorOperationTest
{
38 private static final Logger logger
= Logger
39 .getLogger(SwapSynonymAndAcceptedOperationTest
.class);
41 private static AbstractPostOperation operation
;
43 private static Taxon oldTaxon
;
45 private static Taxon parentTaxon
;
47 private static Synonym homotypicSynonym
;
49 private static Synonym oldHeterotypicSynonym
;
51 private static HomotypicalGroup heteroypicalGroup
;
53 private static Taxon misapplication
;
55 private static Taxon concept
;
57 private static TaxonRelationshipType conceptRelationshipType
;
59 private static Taxon childTaxon
;
61 private static TaxonDescription description
;
63 private static NonViralName oldSynonymName
;
65 private static NonViralName oldTaxonName
;
69 * @throws java.lang.Exception
72 public static void setUpBeforeClass() throws Exception
{
74 (new DefaultTermInitializer()).initialize();
76 // Create the original accepted taxon
77 oldTaxonName
= NonViralName
.NewInstance(null);
78 oldTaxon
= Taxon
.NewInstance(oldTaxonName
, null);
80 // Create its parent taxon
81 parentTaxon
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
82 parentTaxon
.addTaxonomicChild(oldTaxon
, null, null);
84 // Give it a child taxon
85 childTaxon
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
86 childTaxon
.setTaxonomicParent(oldTaxon
, null, null);
88 // Create a homotypic synonym for the accepted taxon
89 oldTaxon
.addHomotypicSynonymName(NonViralName
.NewInstance(null), null, null);
90 // homotypicSynonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
91 // HomotypicalGroup acceptedHomotypicalGroup = HomotypicalGroup.NewInstance();
92 // acceptedHomotypicalGroup.addTypifiedName(oldTaxon.getName());
93 // acceptedHomotypicalGroup.addTypifiedName(homotypicSynonym.getName());
95 // Create a heterotypic synonym that will be used to create the new accepted taxon
96 oldSynonymName
= NonViralName
.NewInstance(null);
97 oldHeterotypicSynonym
= Synonym
.NewInstance(oldSynonymName
, null);
98 // oldTaxon.addS .addHeterotypicSynonym(oldHeterotypicSynonym, null, null);
99 heteroypicalGroup
= HomotypicalGroup
.NewInstance();
100 heteroypicalGroup
.addTypifiedName(oldHeterotypicSynonym
.getName());
101 oldTaxon
.addSynonym(oldHeterotypicSynonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
103 // Create a misapplication
104 misapplication
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
105 oldTaxon
.addMisappliedName(misapplication
, null, null);
107 // Create a concept relation
108 concept
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
109 conceptRelationshipType
= new TaxonRelationshipType();
110 concept
.addTaxonRelation(oldTaxon
, conceptRelationshipType
, null, null);
112 // Create a description
113 description
= TaxonDescription
.NewInstance();
114 oldTaxon
.addDescription(description
);
116 operation
= new SwapSynonymAndAcceptedOperation
117 (null, undoContext
, oldTaxon
, oldHeterotypicSynonym
, postOperation
);
120 private Taxon newTaxon
;
124 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeHomotypicGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
125 * @throws ExecutionException
128 public void testExecute() throws ExecutionException
{
129 operation
.execute(null, null);
131 newTaxon
= ((SwapSynonymAndAcceptedOperation
) operation
).getNewTaxon();
133 // New taxon has correct name?
134 Assert
.assertEquals(newTaxon
.getName(), oldSynonymName
);
136 // New taxon has correct parent?
137 Assert
.assertEquals(newTaxon
.getTaxonomicParent(), parentTaxon
);
139 // New taxon has correct child?
140 Assert
.assertTrue(newTaxon
.getTaxonomicChildren().contains(childTaxon
));
142 // New taxon has 2 synonyms?
143 Assert
.assertEquals(newTaxon
.getSynonyms().size(), 2);
145 // New taxon has a synonym with the name of the previous accepted taxon?
146 Assert
.assertTrue(newTaxon
.getSynonymNames().contains(oldTaxonName
));
148 // New taxon has misapplication?
149 Assert
.assertTrue(newTaxon
.getMisappliedNames().contains(misapplication
));
151 // New taxon has 1 concept relation?
152 int conceptRelCount
= 0;
153 for (TaxonRelationship relation
: newTaxon
.getTaxonRelations()) {
154 if (relation
.getType().equals(TaxonRelationshipType
.MISAPPLIED_NAME_FOR()) ||
155 relation
.getType().equals(TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN())) {
160 Assert
.assertEquals(conceptRelCount
, 1);
162 // New taxon has description?
163 newTaxon
.getDescriptions().contains(description
);
167 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
168 * @throws ExecutionException
171 public void testUndo() throws ExecutionException
{
172 operation
.undo(null, null);
174 // Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
178 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
179 * @throws ExecutionException
182 public void testRedo() throws ExecutionException
{
183 operation
.redo(null, null);
185 // Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
189 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.AbstractPostOperation#postExecute(CdmBase)}.
192 public void testPostExecute() {
193 // TODO there is not post operation functionality for this class
194 // at the moment. Implement test when there is.
195 logger
.warn("No post operation functionality for this class");