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
;
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
.CdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.common
.DefaultTermInitializer
;
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
.operations
.AbstractPostOperation
;
30 import eu
.etaxonomy
.taxeditor
.operations
.SwapSynonymAndAcceptedOperation
;
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 taxon
;
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 taxon
= Taxon
.NewInstance(oldTaxonName
, null);
80 // Create its parent taxon
81 parentTaxon
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
82 parentTaxon
.addTaxonomicChild(taxon
, null, null);
84 // Give it a child taxon
85 childTaxon
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
86 childTaxon
.setTaxonomicParent(taxon
, null, null);
88 // Create a homotypic synonym for the accepted taxon
89 taxon
.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 taxon
.addSynonym(oldHeterotypicSynonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
103 // Create a misapplication
104 misapplication
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
105 taxon
.addMisappliedName(misapplication
, null, null);
107 // Create a concept relation
108 concept
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
109 conceptRelationshipType
= new TaxonRelationshipType();
110 concept
.addTaxonRelation(taxon
, conceptRelationshipType
, null, null);
112 // Create a description
113 description
= TaxonDescription
.NewInstance();
114 taxon
.addDescription(description
);
116 operation
= new SwapSynonymAndAcceptedOperation
117 (null, undoContext
, taxon
, oldHeterotypicSynonym
, postOperation
);
122 * Test method for {@link eu.etaxonomy.taxeditor.operations.ChangeHomotypicGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
123 * @throws ExecutionException
126 public void testExecute() throws ExecutionException
{
127 operation
.execute(null, null);
129 // New taxon has correct name?
130 Assert
.assertEquals(taxon
.getName(), oldSynonymName
);
132 // New taxon has correct parent?
133 Assert
.assertEquals(taxon
.getTaxonomicParent(), parentTaxon
);
135 // New taxon has correct child?
136 Assert
.assertTrue(taxon
.getTaxonomicChildren().contains(childTaxon
));
138 // New taxon has 2 synonyms?
139 Assert
.assertEquals(taxon
.getSynonyms().size(), 2);
141 // New taxon has a synonym with the name of the previous accepted taxon?
142 Assert
.assertTrue(taxon
.getSynonymNames().contains(oldTaxonName
));
144 // New taxon has misapplication?
145 Assert
.assertTrue(taxon
.getMisappliedNames().contains(misapplication
));
147 // New taxon has 1 concept relation?
148 int conceptRelCount
= 0;
149 for (TaxonRelationship relation
: taxon
.getTaxonRelations()) {
150 if (relation
.getType().equals(TaxonRelationshipType
.MISAPPLIED_NAME_FOR()) ||
151 relation
.getType().equals(TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN())) {
156 Assert
.assertEquals(conceptRelCount
, 1);
158 // New taxon has description?
159 taxon
.getDescriptions().contains(description
);
163 * Test method for {@link eu.etaxonomy.taxeditor.operations.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
164 * @throws ExecutionException
167 public void testUndo() throws ExecutionException
{
168 operation
.undo(null, null);
170 // Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
174 * Test method for {@link eu.etaxonomy.taxeditor.operations.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
175 * @throws ExecutionException
178 public void testRedo() throws ExecutionException
{
179 operation
.redo(null, null);
181 // Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
185 * Test method for {@link eu.etaxonomy.taxeditor.operations.AbstractPostOperation#postExecute(CdmBase)}.
188 public void testPostExecute() {
189 // TODO there is not post operation functionality for this class
190 // at the moment. Implement test when there is.
191 logger
.warn("No post operation functionality for this class");