2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.editor
.name
.operation
;
11 import org
.apache
.log4j
.Logger
;
12 import org
.eclipse
.core
.commands
.ExecutionException
;
13 import org
.junit
.Assert
;
14 import org
.junit
.BeforeClass
;
15 import org
.junit
.Test
;
17 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
18 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymType
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
24 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeSynonymToConceptOperation
;
25 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
31 public class ChangeSynonymToConceptOperationTest
extends AbstractTaxeditorOperationTestBase
{
33 private static final Logger logger
= Logger
.getLogger(ChangeSynonymToConceptOperationTest
.class);
35 private static TaxonRelationshipType taxonRelationshipType
;
36 private static Synonym synonym
;
39 public static void setUpBeforeClass() throws Exception
{
41 taxon
= Taxon
.NewInstance(null, null);
42 synonym
= Synonym
.NewInstance(TaxonNameFactory
.NewNonViralInstance(null), null);
43 taxonRelationshipType
= TaxonRelationshipType
.CONTRADICTION();
45 taxon
.addSynonym(synonym
, SynonymType
.SYNONYM_OF());
47 operation
= new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon
, synonym
, taxonRelationshipType
, postOperation
);
51 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException
{
52 operation
.execute(monitor
, info
);
54 Assert
.assertTrue("Synonym should be deleted from taxon.", taxon
.getSynonyms().size() == 0);
55 Assert
.assertTrue("Taxon should have taxon relationships now.", taxon
.getRelationsToThisTaxon().size() > 0);
56 Assert
.assertEquals("Relationship is not the expected", taxonRelationshipType
, taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getType());
57 Assert
.assertEquals("Name of synonym and newly created related taxon should be equal", synonym
.getName(), taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getFromTaxon().getName());
61 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException
{
62 operation
.undo(monitor
, info
);
64 Assert
.assertTrue("There should be synonyms now.", taxon
.getSynonyms().size() > 0);
65 Assert
.assertEquals("Synonym is not the expected.", synonym
, taxon
.getSynonyms().toArray(new Synonym
[0]));
66 Assert
.assertTrue("There should not be taxon relationships.", taxon
.getRelationsToThisTaxon().size() == 0);
70 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException
{
71 operation
.redo(monitor
, info
);
73 Assert
.assertTrue("Synonym should be deleted from taxon.", taxon
.getSynonyms().size() == 0);
74 Assert
.assertTrue("Taxon should have taxon relationships now.", taxon
.getRelationsToThisTaxon().size() > 0);
75 Assert
.assertEquals("Relationship is not the expected", taxonRelationshipType
, taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getType());
76 Assert
.assertEquals("Name of synonym and newly created related taxon should be equal", synonym
.getName(), taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getFromTaxon().getName());
80 public void testPostExecute() {
81 // TODO there is not post operation functionality for this class
82 // at the moment. Implement test when there is.
83 logger
.warn("No post operation functionality for this class");