0fbc234de95847acccba77b3a783b86bf0cff643
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / test / java / eu / etaxonomy / taxeditor / editor / name / operation / ChangeSynonymToConceptOperationTest.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
6 *
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.
9 */
10
11 package eu.etaxonomy.taxeditor.editor.name.operation;
12
13 import junit.framework.Assert;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.junit.BeforeClass;
18 import org.junit.Test;
19
20 import eu.etaxonomy.cdm.model.common.ICdmBase;
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;
27 import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation;
28 import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTest;
29
30 /**
31 * @author n.hoffmann
32 * @created 07.04.2009
33 * @version 1.0
34 */
35 public class ChangeSynonymToConceptOperationTest extends AbstractTaxeditorOperationTest{
36 private static final Logger logger = Logger
37 .getLogger(ChangeSynonymToConceptOperationTest.class);
38
39 private static TaxonRelationshipType taxonRelationshipType;
40
41 private static Synonym synonym;
42
43
44 /**
45 * @throws java.lang.Exception
46 */
47 @BeforeClass
48 public static void setUpBeforeClass() throws Exception {
49
50 taxon = Taxon.NewInstance(null, null);
51 synonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
52 taxonRelationshipType = TaxonRelationshipType.CONTRADICTION();
53
54 taxon.addSynonym(synonym, SynonymRelationshipType.SYNONYM_OF());
55
56 operation = new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon, synonym, taxonRelationshipType, postOperation);
57 }
58
59 /**
60 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
61 * @throws ExecutionException
62 */
63 @Test
64 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
65 operation.execute(monitor, info);
66
67 Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
68 Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
69 Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
70 Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
71 }
72
73 /**
74 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
75 * @throws ExecutionException
76 */
77 @Test
78 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
79 operation.undo(monitor, info);
80
81 Assert.assertTrue("There should be synonyms now.", taxon.getSynonyms().size() > 0);
82 Assert.assertEquals("Synonym is not the expected.", synonym, taxon.getSynonyms().toArray(new Synonym[0]));
83 Assert.assertTrue("There should not be taxon relationships.", taxon.getRelationsToThisTaxon().size() == 0);
84 }
85
86 /**
87 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
88 * @throws ExecutionException
89 */
90 @Test
91 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
92 operation.redo(monitor, info);
93
94 Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
95 Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
96 Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
97 Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
98 }
99
100 /**
101 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation#postExecute(ICdmBase)}.
102 */
103 @Test
104 public void testPostExecute() {
105 // TODO there is not post operation functionality for this class
106 // at the moment. Implement test when there is.
107 logger.warn("No post operation functionality for this class");
108 }
109 }