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 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
.CdmBase
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationshipType
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
30 public class ChangeSynonymToMisapplicationOperationTest
extends AbstractTaxeditorOperationTest
{
31 private static final Logger logger
= Logger
32 .getLogger(ChangeSynonymToMisapplicationOperationTest
.class);
34 private static Synonym synonym
;
36 private static Taxon taxon
;
38 private static AbstractPostOperation operation
;
40 private static SynonymRelationshipType synonymRelationshipType
;
43 * @throws java.lang.Exception
46 public static void setUpBeforeClass() throws Exception
{
47 taxon
= Taxon
.NewInstance(null, null);
48 synonym
= Synonym
.NewInstance(NonViralName
.NewInstance(null), null);
49 synonymRelationshipType
= SynonymRelationshipType
.SYNONYM_OF();
50 taxon
.addSynonym(synonym
, synonymRelationshipType
);
52 operation
= new ChangeSynonymToMisapplicationOperation("Change Synonym To Misapplication", null, taxon
, synonym
, postOperation
);
56 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToMisapplicationOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
57 * @throws ExecutionException
60 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException
{
61 operation
.execute(null, null);
63 Assert
.assertTrue("Synonym should be deleted from taxon", taxon
.getSynonyms().size() == 0);
64 Assert
.assertTrue("Taxon should have misapplications", taxon
.getMisappliedNames().size() > 0);
65 Assert
.assertEquals("The name of synonym and misapplication should be equal", synonym
.getName(), taxon
.getMisappliedNames().toArray(new Taxon
[0])[0].getName());
69 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToMisapplicationOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
70 * @throws ExecutionException
73 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException
{
74 operation
.undo(null, null);
76 Assert
.assertTrue("Taxon should have synonyms.", taxon
.getSynonyms().size() > 0);
77 Assert
.assertTrue("Taxon should not have taxon relationship.", taxon
.getTaxonRelations().size() == 0);
78 Assert
.assertEquals("Not the expected synonym.", synonym
, taxon
.getSynonyms().toArray(new Synonym
[0])[0]);
79 Assert
.assertEquals("SynonymRelationshipType is not the expected.", synonymRelationshipType
, taxon
.getSynonyms().toArray(new Synonym
[0])[0].getRelationType(taxon
));
83 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.ChangeSynonymToMisapplicationOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
84 * @throws ExecutionException
87 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException
{
88 operation
.redo(null, null);
90 Assert
.assertTrue("Synonym should be deleted from taxon", taxon
.getSynonyms().size() == 0);
91 Assert
.assertTrue("Taxon should have misapplications", taxon
.getMisappliedNames().size() > 0);
92 Assert
.assertEquals("The name of synonym and misapplication should be equal", synonym
.getName(), taxon
.getMisappliedNames().toArray(new Taxon
[0])[0].getName());
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");