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 static org
.junit
.Assert
.fail
;
14 import junit
.framework
.Assert
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.core
.commands
.ExecutionException
;
18 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
19 import org
.junit
.BeforeClass
;
20 import org
.junit
.Test
;
22 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
23 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
33 public class ChangeSynonymToTaxonOperationTest
{
34 private static final Logger logger
= Logger
35 .getLogger(ChangeSynonymToTaxonOperationTest
.class);
37 private static AbstractPostOperation operation
;
39 private static Taxon taxon
;
41 private static Synonym synonym
;
43 private static SynonymRelationshipType synonymRelationshipType
;
47 * @throws java.lang.Exception
50 public static void setUpBeforeClass() throws Exception
{
52 taxon
= Taxon
.NewInstance(null, null);
53 synonym
= Synonym
.NewInstance(NonViralName
.NewInstance(null), null);
54 synonymRelationshipType
= SynonymRelationshipType
.SYNONYM_OF();
56 taxon
.addSynonym(synonym
, synonymRelationshipType
);
58 operation
= new ChangeSynonymToTaxonOperation("Change Synonym To Taxon", null, taxon
, synonym
);
62 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToTaxonOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
63 * @throws ExecutionException
66 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException
{
67 operation
.execute(null, null);
69 Assert
.assertTrue("Synonym should be deleted from taxon", taxon
.getSynonyms().size() == 0);
73 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToTaxonOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
74 * @throws ExecutionException
77 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException
{
78 operation
.undo(null, null);
80 Assert
.assertTrue("Taxon should have a synonym.", taxon
.getSynonyms().size() > 0);
81 Assert
.assertEquals("Synonym is not the expexted.", synonym
, taxon
.getSynonyms().toArray(new Synonym
[0])[0]);
85 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToTaxonOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
86 * @throws ExecutionException
89 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException
{
90 operation
.redo(null, null);
92 Assert
.assertTrue("Synonym should be deleted from taxon", taxon
.getSynonyms().size() == 0);
96 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.AbstractPostOperation#postExecute(CdmBase)}.
99 public void testPostExecute() {
100 // TODO there is not post operation functionality for this class
101 // at the moment. Implement test when there is.
102 logger
.warn("No post operation functionality for this class");