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.
10 package eu
.etaxonomy
.taxeditor
.editor
.name
.operation
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.junit
.Assert
;
15 import org
.junit
.BeforeClass
;
16 import org
.junit
.Test
;
18 import eu
.etaxonomy
.cdm
.model
.common
.ICdmBase
;
19 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
20 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
21 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.Synonym
;
24 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationshipType
;
26 import eu
.etaxonomy
.taxeditor
.editor
.name
.operation
.ChangeConceptToSynonymOperation
;
27 import eu
.etaxonomy
.taxeditor
.operation
.AbstractPostOperation
;
28 import eu
.etaxonomy
.taxeditor
.store
.operations
.AbstractTaxeditorOperationTestBase
;
34 public class ChangeConceptToSynonymOperationTest
extends AbstractTaxeditorOperationTestBase
{
35 private static final Logger logger
= Logger
.getLogger(ChangeConceptToSynonymOperationTest
.class);
37 private static Taxon taxon
;
39 private static Taxon concept
;
41 private static AbstractPostOperation operation
;
43 private static HomotypicalGroup homotypicalGroup
;
45 private Synonym
[] synonymType
= new Synonym
[0];
46 private Taxon
[] taxonType
= new Taxon
[0];
49 * @throws java.lang.Exception
52 public static void setUpBeforeClass() throws Exception
{
53 taxon
= Taxon
.NewInstance(null, null);
54 concept
= Taxon
.NewInstance(TaxonNameFactory
.NewNonViralInstance(null), null);
55 homotypicalGroup
= HomotypicalGroup
.NewInstance();
57 concept
.addTaxonRelation(taxon
, TaxonRelationshipType
.MISAPPLIED_NAME_FOR(), null, null);
59 operation
= new ChangeConceptToSynonymOperation("Change misapplication to synonym", null, taxon
, concept
, homotypicalGroup
, postOperation
);
63 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
64 * @throws ExecutionException
67 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException
{
68 operation
.execute(null, null);
70 Assert
.assertTrue(taxon
.getSynonyms().size() == 1);
71 Assert
.assertTrue(concept
.getRelationsFromThisTaxon().size() == 0);
72 Assert
.assertEquals(concept
.getName(), taxon
.getSynonyms().toArray(synonymType
)[0].getName());
77 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
78 * @throws ExecutionException
81 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException
{
82 operation
.undo(null, null);
84 Assert
.assertTrue("There shouldn't be synonyms after undo operations", taxon
.getSynonyms().size() == 0);
85 Assert
.assertTrue(concept
.getRelationsFromThisTaxon().size() > 0);
86 Assert
.assertEquals(taxon
, concept
.getRelationsFromThisTaxon().toArray(taxonType
)[0]);
90 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
91 * @throws ExecutionException
94 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException
{
95 operation
.redo(null, null);
97 Assert
.assertTrue(taxon
.getSynonyms().size() == 1);
98 Assert
.assertTrue(concept
.getRelationsFromThisTaxon().size() == 0);
99 Assert
.assertEquals(concept
.getName(), taxon
.getSynonyms().toArray(synonymType
)[0].getName());
103 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
106 public void testPostExecute() {
107 // TODO there is not post operation functionality for this class
108 // at the moment. Implement test when there is.
109 logger
.warn("No post operation functionality for this class");