3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.editor
.name
.operation
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.junit
.Assert
;
15 import org
.junit
.Before
;
16 import org
.junit
.Test
;
18 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
30 public class CreateSynonymInExisitingHomotypicalGroupOperationTest
extends AbstractTaxeditorOperationTestBase
{
32 private NonViralName newSynonymName
;
34 private HomotypicalGroup homotypicalGroup
;
37 private NonViralName
<?
> taxonName
;
40 * @throws java.lang.Exception
43 public void setUp() throws Exception
{
45 taxonName
= NonViralName
.NewInstance(null);
46 taxon
= Taxon
.NewInstance(taxonName
, null);
48 homotypicalGroup
= HomotypicalGroup
.NewInstance();
49 newSynonymName
= NonViralName
.NewInstance(null);
51 operation
= new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
52 undoContext
, taxon
, homotypicalGroup
, newSynonymName
, postOperation
);
56 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
58 * Homotypic group is the Taxons homotypic group, so we expect the synonym to be homotypic to the accepted taxon.
60 * @throws ExecutionException
63 public void testExecuteTaxonHomotypicGroup() throws ExecutionException
{
64 homotypicalGroup
.addTypifiedName(taxonName
);
65 operation
.execute(monitor
, info
);
67 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
68 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
72 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
74 * Homotypic group is not the accepted taxons. Heterotypic synonym should be created.
76 * @throws ExecutionException
79 public void testExecuteSynonymHomotypicGroup() throws ExecutionException
{
80 // test heterotypic synonym
81 operation
.execute(monitor
, info
);
83 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
84 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
85 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonymRelations().toArray(new SynonymRelationship
[0])[0].getType());
90 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
91 * @throws ExecutionException
94 public void testUndoTaxonHomotypicGroup() throws ExecutionException
{
95 homotypicalGroup
.addTypifiedName(taxonName
);
97 operation
.execute(monitor
, info
);
98 operation
.undo(monitor
, info
);
100 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
104 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
105 * @throws ExecutionException
108 public void testUndoSynonymHomotypicGroup() throws ExecutionException
{
109 operation
.execute(monitor
, info
);
110 operation
.undo(monitor
, info
);
112 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
116 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
117 * @throws ExecutionException
120 public void testRedoTaxonHomotypicGroup() throws ExecutionException
{
121 homotypicalGroup
.addTypifiedName(taxonName
);
123 operation
.execute(monitor
, info
);
124 operation
.undo(monitor
, info
);
125 operation
.redo(monitor
, info
);
127 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
128 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
132 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
133 * @throws ExecutionException
136 public void testRedoSynonymHomotypicGroup() throws ExecutionException
{
137 operation
.execute(monitor
, info
);
138 operation
.undo(monitor
, info
);
139 operation
.redo(monitor
, info
);
141 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
142 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
143 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonymRelations().toArray(new SynonymRelationship
[0])[0].getType());