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
.editor
.name
.operation
;
12 import junit
.framework
.Assert
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.junit
.BeforeClass
;
17 import org
.junit
.Test
;
19 import eu
.etaxonomy
.cdm
.model
.common
.DefaultTermInitializer
;
20 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
21 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
22 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
23 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
27 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
28 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
29 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.SwapSynonymAndAcceptedOperation
;
30 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
31 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTest
;
38 public class SwapSynonymAndAcceptedOperationTest
extends AbstractTaxeditorOperationTest
{
39 private static final Logger logger
= Logger
40 .getLogger(SwapSynonymAndAcceptedOperationTest
.class);
42 private static AbstractPostOperation operation
;
44 private static Taxon taxon
;
46 private static Taxon parentTaxon
;
48 private static Synonym homotypicSynonym
;
50 private static Synonym oldHeterotypicSynonym
;
52 private static HomotypicalGroup heteroypicalGroup
;
54 private static Taxon misapplication
;
56 private static Taxon concept
;
58 private static TaxonRelationshipType conceptRelationshipType
;
60 private static Taxon childTaxon
;
62 private static TaxonDescription description
;
64 private static NonViralName
<?
> oldSynonymName
;
66 private static NonViralName
<?
> oldTaxonName
;
70 * @throws java.lang.Exception
73 public static void setUpBeforeClass() throws Exception
{
75 (new DefaultTermInitializer()).initialize();
77 // Create the original accepted taxon
78 oldTaxonName
= NonViralName
.NewInstance(null);
79 taxon
= Taxon
.NewInstance(oldTaxonName
, null);
81 // Create its parent taxon
82 parentTaxon
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
83 parentTaxon
.addTaxonomicChild(taxon
, null, null);
85 // Give it a child taxon
86 childTaxon
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
87 childTaxon
.setTaxonomicParent(taxon
, null, null);
89 // Create a homotypic synonym for the accepted taxon
90 taxon
.addHomotypicSynonymName(NonViralName
.NewInstance(null), null, null);
91 // homotypicSynonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
92 // HomotypicalGroup acceptedHomotypicalGroup = HomotypicalGroup.NewInstance();
93 // acceptedHomotypicalGroup.addTypifiedName(oldTaxon.getName());
94 // acceptedHomotypicalGroup.addTypifiedName(homotypicSynonym.getName());
96 // Create a heterotypic synonym that will be used to create the new accepted taxon
97 oldSynonymName
= NonViralName
.NewInstance(null);
98 oldHeterotypicSynonym
= Synonym
.NewInstance(oldSynonymName
, null);
99 // oldTaxon.addS .addHeterotypicSynonym(oldHeterotypicSynonym, null, null);
100 heteroypicalGroup
= HomotypicalGroup
.NewInstance();
101 heteroypicalGroup
.addTypifiedName(oldHeterotypicSynonym
.getName());
102 taxon
.addSynonym(oldHeterotypicSynonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
104 // Create a misapplication
105 misapplication
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
106 taxon
.addMisappliedName(misapplication
, null, null);
108 // Create a concept relation
109 concept
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
110 conceptRelationshipType
= new TaxonRelationshipType();
111 concept
.addTaxonRelation(taxon
, conceptRelationshipType
, null, null);
113 // Create a description
114 description
= TaxonDescription
.NewInstance();
115 taxon
.addDescription(description
);
117 operation
= new SwapSynonymAndAcceptedOperation
118 (null, undoContext
, taxon
, oldHeterotypicSynonym
, postOperation
);
123 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
124 * @throws ExecutionException
127 public void testExecute() throws ExecutionException
{
128 operation
.execute(null, null);
130 // New taxon has correct name?
131 Assert
.assertEquals(taxon
.getName(), oldSynonymName
);
133 // New taxon has correct parent?
134 Assert
.assertEquals(taxon
.getTaxonomicParent(), parentTaxon
);
136 // New taxon has correct child?
137 Assert
.assertTrue(taxon
.getTaxonomicChildren().contains(childTaxon
));
139 // New taxon has 2 synonyms?
140 Assert
.assertEquals(taxon
.getSynonyms().size(), 2);
142 // New taxon has a synonym with the name of the previous accepted taxon?
143 Assert
.assertTrue(taxon
.getSynonymNames().contains(oldTaxonName
));
145 // New taxon has misapplication?
146 Assert
.assertTrue(taxon
.getMisappliedNames().contains(misapplication
));
148 // New taxon has 1 concept relation?
149 int conceptRelCount
= 0;
150 for (TaxonRelationship relation
: taxon
.getTaxonRelations()) {
151 if (relation
.getType().equals(TaxonRelationshipType
.MISAPPLIED_NAME_FOR()) ||
152 relation
.getType().equals(TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN())) {
157 Assert
.assertEquals(conceptRelCount
, 1);
159 // New taxon has description?
160 taxon
.getDescriptions().contains(description
);
164 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
165 * @throws ExecutionException
168 public void testUndo() throws ExecutionException
{
169 operation
.undo(null, null);
171 // Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
175 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
176 * @throws ExecutionException
179 public void testRedo() throws ExecutionException
{
180 operation
.redo(null, null);
182 // Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
186 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation#postExecute(ICdmBase)}.
189 public void testPostExecute() {
190 // TODO there is not post operation functionality for this class
191 // at the moment. Implement test when there is.
192 logger
.warn("No post operation functionality for this class");