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
.SynonymRelationshipType
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
29 public class CreateSynonymInExisitingHomotypicalGroupOperationTest
extends AbstractTaxeditorOperationTestBase
{
31 private NonViralName newSynonymName
;
33 private HomotypicalGroup homotypicalGroup
;
36 private NonViralName
<?
> taxonName
;
39 * @throws java.lang.Exception
42 public void setUp() throws Exception
{
44 taxonName
= NonViralName
.NewInstance(null);
45 taxon
= Taxon
.NewInstance(taxonName
, null);
47 homotypicalGroup
= HomotypicalGroup
.NewInstance();
48 newSynonymName
= NonViralName
.NewInstance(null);
50 operation
= new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
51 undoContext
, taxon
, homotypicalGroup
, newSynonymName
, postOperation
);
55 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
57 * Homotypic group is the Taxons homotypic group, so we expect the synonym to be homotypic to the accepted taxon.
59 * @throws ExecutionException
62 public void testExecuteTaxonHomotypicGroup() throws ExecutionException
{
63 homotypicalGroup
.addTypifiedName(taxonName
);
64 operation
.execute(monitor
, info
);
66 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
67 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
71 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
73 * Homotypic group is not the accepted taxons. Heterotypic synonym should be created.
75 * @throws ExecutionException
78 public void testExecuteSynonymHomotypicGroup() throws ExecutionException
{
79 // test heterotypic synonym
80 operation
.execute(monitor
, info
);
82 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
83 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
84 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonyms().iterator().next().getType());
89 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
90 * @throws ExecutionException
93 public void testUndoTaxonHomotypicGroup() throws ExecutionException
{
94 homotypicalGroup
.addTypifiedName(taxonName
);
96 operation
.execute(monitor
, info
);
97 operation
.undo(monitor
, info
);
99 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
103 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
104 * @throws ExecutionException
107 public void testUndoSynonymHomotypicGroup() throws ExecutionException
{
108 operation
.execute(monitor
, info
);
109 operation
.undo(monitor
, info
);
111 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
115 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
116 * @throws ExecutionException
119 public void testRedoTaxonHomotypicGroup() throws ExecutionException
{
120 homotypicalGroup
.addTypifiedName(taxonName
);
122 operation
.execute(monitor
, info
);
123 operation
.undo(monitor
, info
);
124 operation
.redo(monitor
, info
);
126 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
127 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
131 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
132 * @throws ExecutionException
135 public void testRedoSynonymHomotypicGroup() throws ExecutionException
{
136 operation
.execute(monitor
, info
);
137 operation
.undo(monitor
, info
);
138 operation
.redo(monitor
, info
);
140 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
141 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
142 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonyms().iterator().next().getType());