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 org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.junit
.Assert
;
15 import org
.junit
.BeforeClass
;
16 import org
.junit
.Test
;
18 import eu
.etaxonomy
.cdm
.model
.common
.DefaultTermInitializer
;
19 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
21 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
22 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
27 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
28 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
35 public class SwapSynonymAndAcceptedOperationTest
extends AbstractTaxeditorOperationTestBase
{
36 private static final Logger logger
= Logger
37 .getLogger(SwapSynonymAndAcceptedOperationTest
.class);
39 private static AbstractPostOperation operation
;
41 private static Taxon taxon
;
43 private static Taxon parentTaxon
;
45 private static Synonym homotypicSynonym
;
47 private static Synonym oldHeterotypicSynonym
;
49 private static HomotypicalGroup heteroypicalGroup
;
51 private static Taxon misapplication
;
53 private static Taxon concept
;
55 private static TaxonRelationshipType conceptRelationshipType
;
57 private static Taxon childTaxon
;
59 private static TaxonDescription description
;
61 private static NonViralName
<?
> oldSynonymName
;
63 private static NonViralName
<?
> oldTaxonName
;
67 * @throws java.lang.Exception
70 public static void setUpBeforeClass() throws Exception
{
72 (new DefaultTermInitializer()).initialize();
74 // Create the original accepted taxon
75 oldTaxonName
= NonViralName
.NewInstance(null);
76 taxon
= Taxon
.NewInstance(oldTaxonName
, null);
78 // // Create its parent taxon
79 // parentTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
80 // parentTaxon.addTaxonomicChild(taxon, null, null);
82 // // Give it a child taxon
83 // childTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
84 // childTaxon.setTaxonomicParent(taxon, null, null);
86 // Create a homotypic synonym for the accepted taxon
87 taxon
.addHomotypicSynonymName(NonViralName
.NewInstance(null));
88 // homotypicSynonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
89 // HomotypicalGroup acceptedHomotypicalGroup = HomotypicalGroup.NewInstance();
90 // acceptedHomotypicalGroup.addTypifiedName(oldTaxon.getName());
91 // acceptedHomotypicalGroup.addTypifiedName(homotypicSynonym.getName());
93 // Create a heterotypic synonym that will be used to create the new accepted taxon
94 oldSynonymName
= NonViralName
.NewInstance(null);
95 oldHeterotypicSynonym
= Synonym
.NewInstance(oldSynonymName
, null);
96 // oldTaxon.addS .addHeterotypicSynonym(oldHeterotypicSynonym, null, null);
97 heteroypicalGroup
= HomotypicalGroup
.NewInstance();
98 heteroypicalGroup
.addTypifiedName(oldHeterotypicSynonym
.getName());
99 taxon
.addSynonym(oldHeterotypicSynonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
101 // Create a misapplication
102 misapplication
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
103 taxon
.addMisappliedName(misapplication
, null, null);
105 // Create a concept relation
106 concept
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
107 conceptRelationshipType
= TaxonRelationshipType
.CONGRUENT_TO();
108 concept
.addTaxonRelation(taxon
, conceptRelationshipType
, null, null);
110 // Create a description
111 description
= TaxonDescription
.NewInstance();
112 taxon
.addDescription(description
);
114 operation
= new SwapSynonymAndAcceptedOperation
115 (null, undoContext
, taxon
, oldHeterotypicSynonym
, postOperation
, cdmEntitySessionEnabled
);
120 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
121 * @throws ExecutionException
124 public void testExecute() throws ExecutionException
{
125 operation
.execute(null, null);
127 // New taxon has correct name?
128 Assert
.assertEquals(taxon
.getName(), oldSynonymName
);
130 // // New taxon has correct parent?
131 // Assert.assertEquals(taxon.getTaxonomicParent(), parentTaxon);
133 // // New taxon has correct child?
134 // Assert.assertTrue(taxon.getTaxonomicChildren().contains(childTaxon));
136 // New taxon has 2 synonyms?
137 Assert
.assertEquals(taxon
.getSynonyms().size(), 2);
139 // New taxon has a synonym with the name of the previous accepted taxon?
140 Assert
.assertTrue(taxon
.getSynonymNames().contains(oldTaxonName
));
142 // New taxon has misapplication?
143 Assert
.assertTrue(taxon
.getMisappliedNames().contains(misapplication
));
145 // // New taxon has 1 concept relation?
146 // int conceptRelCount = 0;
147 // for (TaxonRelationship relation : taxon.getTaxonRelations()) {
148 // if (relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
149 // relation.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
152 // conceptRelCount++;
154 // Assert.assertEquals(conceptRelCount, 1);
156 // New taxon has description?
157 taxon
.getDescriptions().contains(description
);
161 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
162 * @throws ExecutionException
165 public void testUndo() throws ExecutionException
{
166 operation
.undo(null, null);
168 // Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
172 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
173 * @throws ExecutionException
176 public void testRedo() throws ExecutionException
{
177 operation
.redo(null, null);
179 // Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
183 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
186 public void testPostExecute() {
187 // TODO there is not post operation functionality for this class
188 // at the moment. Implement test when there is.
189 logger
.warn("No post operation functionality for this class");