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
.apache
.log4j
.Logger
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.junit
.Assert
;
16 import org
.junit
.BeforeClass
;
17 import org
.junit
.Test
;
19 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymType
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
26 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToConceptOperation
;
27 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
34 public class ChangeSynonymToConceptOperationTest
extends AbstractTaxeditorOperationTestBase
{
35 private static final Logger logger
= Logger
36 .getLogger(ChangeSynonymToConceptOperationTest
.class);
38 private static TaxonRelationshipType taxonRelationshipType
;
40 private static Synonym synonym
;
44 * @throws java.lang.Exception
47 public static void setUpBeforeClass() throws Exception
{
49 taxon
= Taxon
.NewInstance(null, null);
50 synonym
= Synonym
.NewInstance(NonViralName
.NewInstance(null), null);
51 taxonRelationshipType
= TaxonRelationshipType
.CONTRADICTION();
53 taxon
.addSynonym(synonym
, SynonymType
.SYNONYM_OF());
55 operation
= new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon
, synonym
, taxonRelationshipType
, postOperation
);
59 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
60 * @throws ExecutionException
63 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException
{
64 operation
.execute(monitor
, info
);
66 Assert
.assertTrue("Synonym should be deleted from taxon.", taxon
.getSynonyms().size() == 0);
67 Assert
.assertTrue("Taxon should have taxon relationships now.", taxon
.getRelationsToThisTaxon().size() > 0);
68 Assert
.assertEquals("Relationship is not the expected", taxonRelationshipType
, taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getType());
69 Assert
.assertEquals("Name of synonym and newly created related taxon should be equal", synonym
.getName(), taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getFromTaxon().getName());
73 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
74 * @throws ExecutionException
77 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException
{
78 operation
.undo(monitor
, info
);
80 Assert
.assertTrue("There should be synonyms now.", taxon
.getSynonyms().size() > 0);
81 Assert
.assertEquals("Synonym is not the expected.", synonym
, taxon
.getSynonyms().toArray(new Synonym
[0]));
82 Assert
.assertTrue("There should not be taxon relationships.", taxon
.getRelationsToThisTaxon().size() == 0);
86 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
87 * @throws ExecutionException
90 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException
{
91 operation
.redo(monitor
, info
);
93 Assert
.assertTrue("Synonym should be deleted from taxon.", taxon
.getSynonyms().size() == 0);
94 Assert
.assertTrue("Taxon should have taxon relationships now.", taxon
.getRelationsToThisTaxon().size() > 0);
95 Assert
.assertEquals("Relationship is not the expected", taxonRelationshipType
, taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getType());
96 Assert
.assertEquals("Name of synonym and newly created related taxon should be equal", synonym
.getName(), taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getFromTaxon().getName());
100 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
103 public void testPostExecute() {
104 // TODO there is not post operation functionality for this class
105 // at the moment. Implement test when there is.
106 logger
.warn("No post operation functionality for this class");