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
.SynonymType
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
28 public class CreateSynonymInExisitingHomotypicalGroupOperationTest
extends AbstractTaxeditorOperationTestBase
{
30 private NonViralName
<?
> newSynonymName
;
32 private HomotypicalGroup homotypicalGroup
;
35 private NonViralName
<?
> taxonName
;
38 * @throws java.lang.Exception
41 public void setUp() throws Exception
{
43 taxonName
= NonViralName
.NewInstance(null);
44 taxon
= Taxon
.NewInstance(taxonName
, null);
46 homotypicalGroup
= HomotypicalGroup
.NewInstance();
47 newSynonymName
= NonViralName
.NewInstance(null);
49 operation
= new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
50 undoContext
, taxon
, homotypicalGroup
, newSynonymName
, postOperation
);
54 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
56 * Homotypic group is the Taxons homotypic group, so we expect the synonym to be homotypic to the accepted taxon.
58 * @throws ExecutionException
61 public void testExecuteTaxonHomotypicGroup() throws ExecutionException
{
62 homotypicalGroup
.addTypifiedName(taxonName
);
63 operation
.execute(monitor
, info
);
65 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
66 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
70 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
72 * Homotypic group is not the accepted taxons. Heterotypic synonym should be created.
74 * @throws ExecutionException
77 public void testExecuteSynonymHomotypicGroup() throws ExecutionException
{
78 // test heterotypic synonym
79 operation
.execute(monitor
, info
);
81 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
82 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
83 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonyms().iterator().next().getType());
88 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
89 * @throws ExecutionException
92 public void testUndoTaxonHomotypicGroup() throws ExecutionException
{
93 homotypicalGroup
.addTypifiedName(taxonName
);
95 operation
.execute(monitor
, info
);
96 operation
.undo(monitor
, info
);
98 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
102 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
103 * @throws ExecutionException
106 public void testUndoSynonymHomotypicGroup() throws ExecutionException
{
107 operation
.execute(monitor
, info
);
108 operation
.undo(monitor
, info
);
110 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
114 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
115 * @throws ExecutionException
118 public void testRedoTaxonHomotypicGroup() throws ExecutionException
{
119 homotypicalGroup
.addTypifiedName(taxonName
);
121 operation
.execute(monitor
, info
);
122 operation
.undo(monitor
, info
);
123 operation
.redo(monitor
, info
);
125 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
126 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
130 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
131 * @throws ExecutionException
134 public void testRedoSynonymHomotypicGroup() throws ExecutionException
{
135 operation
.execute(monitor
, info
);
136 operation
.undo(monitor
, info
);
137 operation
.redo(monitor
, info
);
139 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
140 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
141 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonyms().iterator().next().getType());