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
;
35 public class SwapSynonymAndAcceptedOperationTest
extends AbstractTaxeditorOperationTest
{
36 private static final Logger logger
= Logger
37 .getLogger(SwapSynonymAndAcceptedOperationTest
.class);
39 private static AbstractPostOperation operation
;
41 private static Taxon oldTaxon
;
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 oldTaxon
= Taxon
.NewInstance(oldTaxonName
, null);
78 // Create its parent taxon
79 parentTaxon
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
80 parentTaxon
.addTaxonomicChild(oldTaxon
, null, null);
82 // Give it a child taxon
83 childTaxon
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
84 childTaxon
.setTaxonomicParent(oldTaxon
, null, null);
86 // Create a homotypic synonym for the accepted taxon
87 oldTaxon
.addHomotypicSynonymName(NonViralName
.NewInstance(null), null, 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 oldTaxon
.addSynonym(oldHeterotypicSynonym
, SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF());
101 // Create a misapplication
102 misapplication
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
103 oldTaxon
.addMisappliedName(misapplication
, null, null);
105 // Create a concept relation
106 concept
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
107 conceptRelationshipType
= new TaxonRelationshipType();
108 concept
.addTaxonRelation(oldTaxon
, conceptRelationshipType
, null, null);
110 // Create a description
111 description
= TaxonDescription
.NewInstance();
112 oldTaxon
.addDescription(description
);
114 operation
= new SwapSynonymAndAcceptedOperation
115 (null, undoContext
, oldTaxon
, oldHeterotypicSynonym
, postOperation
);
118 private Taxon newTaxon
;
122 * Test method for {@link eu.etaxonomy.taxeditor.store.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 newTaxon
= ((SwapSynonymAndAcceptedOperation
) operation
).getNewTaxon();
131 // New taxon has correct name?
132 Assert
.assertEquals(newTaxon
.getName(), oldSynonymName
);
134 // New taxon has correct parent?
135 Assert
.assertEquals(newTaxon
.getTaxonomicParent(), parentTaxon
);
137 // New taxon has correct child?
138 Assert
.assertTrue(newTaxon
.getTaxonomicChildren().contains(childTaxon
));
140 // New taxon has 2 synonyms?
141 Assert
.assertEquals(newTaxon
.getSynonyms().size(), 2);
143 // New taxon has a synonym with the name of the previous accepted taxon?
144 Assert
.assertTrue(newTaxon
.getSynonymNames().contains(oldTaxonName
));
146 // New taxon has misapplication?
147 Assert
.assertTrue(newTaxon
.getMisappliedNames().contains(misapplication
));
149 // New taxon has 1 concept relation?
150 int conceptRelCount
= 0;
151 for (TaxonRelationship relation
: newTaxon
.getTaxonRelations()) {
152 if (relation
.getType().equals(TaxonRelationshipType
.MISAPPLIED_NAME_FOR()) ||
153 relation
.getType().equals(TaxonRelationshipType
.TAXONOMICALLY_INCLUDED_IN())) {
158 Assert
.assertEquals(conceptRelCount
, 1);
160 // New taxon has description?
161 newTaxon
.getDescriptions().contains(description
);
165 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
166 * @throws ExecutionException
169 public void testUndo() throws ExecutionException
{
170 operation
.undo(null, null);
172 // Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
176 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
177 * @throws ExecutionException
180 public void testRedo() throws ExecutionException
{
181 operation
.redo(null, null);
183 // Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
187 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.AbstractPostOperation#postExecute(CdmBase)}.
190 public void testPostExecute() {
191 // TODO there is not post operation functionality for this class
192 // at the moment. Implement test when there is.
193 logger
.warn("No post operation functionality for this class");