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
.name
.TaxonNameBase
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.CreateSynonymInExistingHomotypicalGroupOperation
;
25 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
32 public class CreateSynonymInExisitingHomotypicalGroupOperationTest
extends AbstractTaxeditorOperationTestBase
{
34 private TaxonNameBase newSynonymName
;
36 private HomotypicalGroup homotypicalGroup
;
39 private NonViralName
<?
> taxonName
;
42 * @throws java.lang.Exception
45 public void setUp() throws Exception
{
47 taxonName
= NonViralName
.NewInstance(null);
48 taxon
= Taxon
.NewInstance(taxonName
, null);
50 homotypicalGroup
= HomotypicalGroup
.NewInstance();
51 newSynonymName
= NonViralName
.NewInstance(null);
53 operation
= new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
54 undoContext
, taxon
, homotypicalGroup
, newSynonymName
, postOperation
);
58 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
60 * Homotypic group is the Taxons homotypic group, so we expect the synonym to be homotypic to the accepted taxon.
62 * @throws ExecutionException
65 public void testExecuteTaxonHomotypicGroup() throws ExecutionException
{
66 homotypicalGroup
.addTypifiedName(taxonName
);
67 operation
.execute(monitor
, info
);
69 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
70 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
74 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
76 * Homotypic group is not the accepted taxons. Heterotypic synonym should be created.
78 * @throws ExecutionException
81 public void testExecuteSynonymHomotypicGroup() throws ExecutionException
{
82 // test heterotypic synonym
83 operation
.execute(monitor
, info
);
85 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
86 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
87 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonymRelations().toArray(new SynonymRelationship
[0])[0].getType());
92 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
93 * @throws ExecutionException
96 public void testUndoTaxonHomotypicGroup() throws ExecutionException
{
97 homotypicalGroup
.addTypifiedName(taxonName
);
99 operation
.execute(monitor
, info
);
100 operation
.undo(monitor
, info
);
102 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
106 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
107 * @throws ExecutionException
110 public void testUndoSynonymHomotypicGroup() throws ExecutionException
{
111 operation
.execute(monitor
, info
);
112 operation
.undo(monitor
, info
);
114 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
118 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
119 * @throws ExecutionException
122 public void testRedoTaxonHomotypicGroup() throws ExecutionException
{
123 homotypicalGroup
.addTypifiedName(taxonName
);
125 operation
.execute(monitor
, info
);
126 operation
.undo(monitor
, info
);
127 operation
.redo(monitor
, info
);
129 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
130 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
134 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
135 * @throws ExecutionException
138 public void testRedoSynonymHomotypicGroup() throws ExecutionException
{
139 operation
.execute(monitor
, info
);
140 operation
.undo(monitor
, info
);
141 operation
.redo(monitor
, info
);
143 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
144 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
145 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonymRelations().toArray(new SynonymRelationship
[0])[0].getType());