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
.store
.operations
;
13 import org
.apache
.log4j
.Logger
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.junit
.Assert
;
16 import org
.junit
.Before
;
17 import org
.junit
.Test
;
19 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
21 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
31 public class CreateSynonymInExisitingHomotypicalGroupOperationTest
extends AbstractTaxeditorOperationTest
{
32 private static final Logger logger
= Logger
33 .getLogger(CreateSynonymInExisitingHomotypicalGroupOperationTest
.class);
35 private String newSynonymText
;
37 private HomotypicalGroup homotypicalGroup
;
40 private NonViralName taxonName
;
43 * @throws java.lang.Exception
46 public void setUp() throws Exception
{
48 taxonName
= NonViralName
.NewInstance(null);
49 taxon
= Taxon
.NewInstance(taxonName
, null);
51 homotypicalGroup
= HomotypicalGroup
.NewInstance();
54 operation
= new CreateSynonymInExisitingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
55 undoContext
, taxon
, homotypicalGroup
, newSynonymText
, postOperation
);
59 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.CreateSynonymInExisitingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
61 * Homotypic group is the Taxons homotypic group, so we expect the synonym to be homotypic to the accepted taxon.
63 * @throws ExecutionException
66 public void testExecuteTaxonHomotypicGroup() throws ExecutionException
{
67 homotypicalGroup
.addTypifiedName(taxonName
);
68 operation
.execute(monitor
, info
);
70 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
71 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
75 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.CreateSynonymInExisitingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
77 * Homotypic group is not the accepted taxons. Heterotypic synonym should be created.
79 * @throws ExecutionException
82 public void testExecuteSynonymHomotypicGroup() throws ExecutionException
{
83 // test heterotypic synonym
84 operation
.execute(monitor
, info
);
86 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
87 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
88 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonymRelations().toArray(new SynonymRelationship
[0])[0].getType());
93 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.CreateSynonymInExisitingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
94 * @throws ExecutionException
97 public void testUndoTaxonHomotypicGroup() throws ExecutionException
{
98 homotypicalGroup
.addTypifiedName(taxonName
);
100 operation
.execute(monitor
, info
);
101 operation
.undo(monitor
, info
);
103 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
107 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.CreateSynonymInExisitingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
108 * @throws ExecutionException
111 public void testUndoSynonymHomotypicGroup() throws ExecutionException
{
112 operation
.execute(monitor
, info
);
113 operation
.undo(monitor
, info
);
115 Assert
.assertTrue("There should not be synonym relationships for the taxon", taxon
.getSynonyms().size() == 0);
119 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.CreateSynonymInExisitingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
120 * @throws ExecutionException
123 public void testRedoTaxonHomotypicGroup() throws ExecutionException
{
124 homotypicalGroup
.addTypifiedName(taxonName
);
126 operation
.execute(monitor
, info
);
127 operation
.undo(monitor
, info
);
128 operation
.redo(monitor
, info
);
130 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
131 Assert
.assertTrue("Taxon should have a homotypic synonym now", taxon
.getHomotypicSynonymsByHomotypicGroup().size() > 0);
135 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.CreateSynonymInExisitingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
136 * @throws ExecutionException
139 public void testRedoSynonymHomotypicGroup() throws ExecutionException
{
140 operation
.execute(monitor
, info
);
141 operation
.undo(monitor
, info
);
142 operation
.redo(monitor
, info
);
144 Assert
.assertTrue("Taxon should have a synonym now.", taxon
.getSynonyms().size() > 0);
145 Assert
.assertTrue("Taxon should have a homotypic group", taxon
.getHomotypicSynonymyGroups().size() > 0);
146 Assert
.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType
.HETEROTYPIC_SYNONYM_OF(), taxon
.getSynonymRelations().toArray(new SynonymRelationship
[0])[0].getType());