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
.SynonymType
;
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
;
34 public class SwapSynonymAndAcceptedOperationTest
extends AbstractTaxeditorOperationTestBase
{
35 private static final Logger logger
= Logger
36 .getLogger(SwapSynonymAndAcceptedOperationTest
.class);
38 private static AbstractPostOperation operation
;
40 private static Taxon taxon
;
42 private static Taxon parentTaxon
;
44 private static Synonym homotypicSynonym
;
46 private static Synonym oldHeterotypicSynonym
;
48 private static HomotypicalGroup heteroypicalGroup
;
50 private static Taxon misapplication
;
52 private static Taxon concept
;
54 private static TaxonRelationshipType conceptRelationshipType
;
56 private static Taxon childTaxon
;
58 private static TaxonDescription description
;
60 private static NonViralName
<?
> oldSynonymName
;
62 private static NonViralName
<?
> oldTaxonName
;
66 * @throws java.lang.Exception
69 public static void setUpBeforeClass() throws Exception
{
71 (new DefaultTermInitializer()).initialize();
73 // Create the original accepted taxon
74 oldTaxonName
= NonViralName
.NewInstance(null);
75 taxon
= Taxon
.NewInstance(oldTaxonName
, null);
77 // // Create its parent taxon
78 // parentTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
79 // parentTaxon.addTaxonomicChild(taxon, null, null);
81 // // Give it a child taxon
82 // childTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
83 // childTaxon.setTaxonomicParent(taxon, null, null);
85 // Create a homotypic synonym for the accepted taxon
86 taxon
.addHomotypicSynonymName(NonViralName
.NewInstance(null));
87 // homotypicSynonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
88 // HomotypicalGroup acceptedHomotypicalGroup = HomotypicalGroup.NewInstance();
89 // acceptedHomotypicalGroup.addTypifiedName(oldTaxon.getName());
90 // acceptedHomotypicalGroup.addTypifiedName(homotypicSynonym.getName());
92 // Create a heterotypic synonym that will be used to create the new accepted taxon
93 oldSynonymName
= NonViralName
.NewInstance(null);
94 oldHeterotypicSynonym
= Synonym
.NewInstance(oldSynonymName
, null);
95 // oldTaxon.addS .addHeterotypicSynonym(oldHeterotypicSynonym, null, null);
96 heteroypicalGroup
= HomotypicalGroup
.NewInstance();
97 heteroypicalGroup
.addTypifiedName(oldHeterotypicSynonym
.getName());
98 taxon
.addSynonym(oldHeterotypicSynonym
, SynonymType
.HETEROTYPIC_SYNONYM_OF());
100 // Create a misapplication
101 misapplication
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
102 taxon
.addMisappliedName(misapplication
, null, null);
104 // Create a concept relation
105 concept
= Taxon
.NewInstance(NonViralName
.NewInstance(null), null);
106 conceptRelationshipType
= TaxonRelationshipType
.CONGRUENT_TO();
107 concept
.addTaxonRelation(taxon
, conceptRelationshipType
, null, null);
109 // Create a description
110 description
= TaxonDescription
.NewInstance();
111 taxon
.addDescription(description
);
113 operation
= new SwapSynonymAndAcceptedOperation
114 (null, undoContext
, taxon
, oldHeterotypicSynonym
, postOperation
, cdmEntitySessionEnabled
);
119 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
120 * @throws ExecutionException
123 public void testExecute() throws ExecutionException
{
124 operation
.execute(null, null);
126 // New taxon has correct name?
127 Assert
.assertEquals(taxon
.getName(), oldSynonymName
);
129 // // New taxon has correct parent?
130 // Assert.assertEquals(taxon.getTaxonomicParent(), parentTaxon);
132 // // New taxon has correct child?
133 // Assert.assertTrue(taxon.getTaxonomicChildren().contains(childTaxon));
135 // New taxon has 2 synonyms?
136 Assert
.assertEquals(taxon
.getSynonyms().size(), 2);
138 // New taxon has a synonym with the name of the previous accepted taxon?
139 Assert
.assertTrue(taxon
.getSynonymNames().contains(oldTaxonName
));
141 // New taxon has misapplication?
142 Assert
.assertTrue(taxon
.getMisappliedNames().contains(misapplication
));
144 // // New taxon has 1 concept relation?
145 // int conceptRelCount = 0;
146 // for (TaxonRelationship relation : taxon.getTaxonRelations()) {
147 // if (relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
148 // relation.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
151 // conceptRelCount++;
153 // Assert.assertEquals(conceptRelCount, 1);
155 // New taxon has description?
156 taxon
.getDescriptions().contains(description
);
160 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
161 * @throws ExecutionException
164 public void testUndo() throws ExecutionException
{
165 operation
.undo(null, null);
167 // Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
171 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
172 * @throws ExecutionException
175 public void testRedo() throws ExecutionException
{
176 operation
.redo(null, null);
178 // Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
182 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
185 public void testPostExecute() {
186 // TODO there is not post operation functionality for this class
187 // at the moment. Implement test when there is.
188 logger
.warn("No post operation functionality for this class");