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 junit
.framework
.Assert
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.core
.commands
.ExecutionException
;
17 import org
.junit
.BeforeClass
;
18 import org
.junit
.Test
;
20 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
21 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
27 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToConceptOperation
;
28 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTest
;
35 public class ChangeSynonymToConceptOperationTest
extends AbstractTaxeditorOperationTest
{
36 private static final Logger logger
= Logger
37 .getLogger(ChangeSynonymToConceptOperationTest
.class);
39 private static TaxonRelationshipType taxonRelationshipType
;
41 private static Synonym synonym
;
45 * @throws java.lang.Exception
48 public static void setUpBeforeClass() throws Exception
{
50 taxon
= Taxon
.NewInstance(null, null);
51 synonym
= Synonym
.NewInstance(NonViralName
.NewInstance(null), null);
52 taxonRelationshipType
= TaxonRelationshipType
.CONTRADICTION();
54 taxon
.addSynonym(synonym
, SynonymRelationshipType
.SYNONYM_OF());
56 operation
= new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon
, synonym
, taxonRelationshipType
, postOperation
);
60 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
61 * @throws ExecutionException
64 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException
{
65 operation
.execute(monitor
, info
);
67 Assert
.assertTrue("Synonym should be deleted from taxon.", taxon
.getSynonyms().size() == 0);
68 Assert
.assertTrue("Taxon should have taxon relationships now.", taxon
.getRelationsToThisTaxon().size() > 0);
69 Assert
.assertEquals("Relationship is not the expected", taxonRelationshipType
, taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getType());
70 Assert
.assertEquals("Name of synonym and newly created related taxon should be equal", synonym
.getName(), taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getFromTaxon().getName());
74 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
75 * @throws ExecutionException
78 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException
{
79 operation
.undo(monitor
, info
);
81 Assert
.assertTrue("There should be synonyms now.", taxon
.getSynonyms().size() > 0);
82 Assert
.assertEquals("Synonym is not the expected.", synonym
, taxon
.getSynonyms().toArray(new Synonym
[0]));
83 Assert
.assertTrue("There should not be taxon relationships.", taxon
.getRelationsToThisTaxon().size() == 0);
87 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
88 * @throws ExecutionException
91 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException
{
92 operation
.redo(monitor
, info
);
94 Assert
.assertTrue("Synonym should be deleted from taxon.", taxon
.getSynonyms().size() == 0);
95 Assert
.assertTrue("Taxon should have taxon relationships now.", taxon
.getRelationsToThisTaxon().size() > 0);
96 Assert
.assertEquals("Relationship is not the expected", taxonRelationshipType
, taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getType());
97 Assert
.assertEquals("Name of synonym and newly created related taxon should be equal", synonym
.getName(), taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getFromTaxon().getName());
101 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation#postExecute(ICdmBase)}.
104 public void testPostExecute() {
105 // TODO there is not post operation functionality for this class
106 // at the moment. Implement test when there is.
107 logger
.warn("No post operation functionality for this class");