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 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
.CdmBase
;
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
;
33 public class ChangeSynonymToConceptOperationTest
extends AbstractTaxeditorOperationTest
{
34 private static final Logger logger
= Logger
35 .getLogger(ChangeSynonymToConceptOperationTest
.class);
37 private static TaxonRelationshipType taxonRelationshipType
;
39 private static Synonym synonym
;
43 * @throws java.lang.Exception
46 public static void setUpBeforeClass() throws Exception
{
48 taxon
= Taxon
.NewInstance(null, null);
49 synonym
= Synonym
.NewInstance(NonViralName
.NewInstance(null), null);
50 taxonRelationshipType
= TaxonRelationshipType
.CONTRADICTION();
52 taxon
.addSynonym(synonym
, SynonymRelationshipType
.SYNONYM_OF());
54 operation
= new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon
, synonym
, taxonRelationshipType
, postOperation
);
58 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToConceptOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
59 * @throws ExecutionException
62 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException
{
63 operation
.execute(monitor
, info
);
65 Assert
.assertTrue("Synonym should be deleted from taxon.", taxon
.getSynonyms().size() == 0);
66 Assert
.assertTrue("Taxon should have taxon relationships now.", taxon
.getRelationsToThisTaxon().size() > 0);
67 Assert
.assertEquals("Relationship is not the expected", taxonRelationshipType
, taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getType());
68 Assert
.assertEquals("Name of synonym and newly created related taxon should be equal", synonym
.getName(), taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getFromTaxon().getName());
72 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToConceptOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
73 * @throws ExecutionException
76 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException
{
77 operation
.undo(monitor
, info
);
79 Assert
.assertTrue("There should be synonyms now.", taxon
.getSynonyms().size() > 0);
80 Assert
.assertEquals("Synonym is not the expected.", synonym
, taxon
.getSynonyms().toArray(new Synonym
[0]));
81 Assert
.assertTrue("There should not be taxon relationships.", taxon
.getRelationsToThisTaxon().size() == 0);
85 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToConceptOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
86 * @throws ExecutionException
89 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException
{
90 operation
.redo(monitor
, info
);
92 Assert
.assertTrue("Synonym should be deleted from taxon.", taxon
.getSynonyms().size() == 0);
93 Assert
.assertTrue("Taxon should have taxon relationships now.", taxon
.getRelationsToThisTaxon().size() > 0);
94 Assert
.assertEquals("Relationship is not the expected", taxonRelationshipType
, taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getType());
95 Assert
.assertEquals("Name of synonym and newly created related taxon should be equal", synonym
.getName(), taxon
.getTaxonRelations().toArray(new TaxonRelationship
[0])[0].getFromTaxon().getName());
99 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.AbstractPostOperation#postExecute(CdmBase)}.
102 public void testPostExecute() {
103 // TODO there is not post operation functionality for this class
104 // at the moment. Implement test when there is.
105 logger
.warn("No post operation functionality for this class");