ref #5974 Remove synonym relationships (rename synRelType to synRel and others)
[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 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;
18
19 import eu.etaxonomy.cdm.model.common.ICdmBase;
20 import eu.etaxonomy.cdm.model.name.NonViralName;
21 import eu.etaxonomy.cdm.model.taxon.Synonym;
22 import eu.etaxonomy.cdm.model.taxon.SynonymType;
23 import eu.etaxonomy.cdm.model.taxon.Taxon;
24 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
25 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
26 import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation;
27 import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
28
29 /**
30 * @author n.hoffmann
31 * @created 07.04.2009
32 * @version 1.0
33 */
34 public class ChangeSynonymToConceptOperationTest extends AbstractTaxeditorOperationTestBase{
35 private static final Logger logger = Logger
36 .getLogger(ChangeSynonymToConceptOperationTest.class);
37
38 private static TaxonRelationshipType taxonRelationshipType;
39
40 private static Synonym synonym;
41
42
43 /**
44 * @throws java.lang.Exception
45 */
46 @BeforeClass
47 public static void setUpBeforeClass() throws Exception {
48
49 taxon = Taxon.NewInstance(null, null);
50 synonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
51 taxonRelationshipType = TaxonRelationshipType.CONTRADICTION();
52
53 taxon.addSynonym(synonym, SynonymType.SYNONYM_OF());
54
55 operation = new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon, synonym, taxonRelationshipType, postOperation);
56 }
57
58 /**
59 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
60 * @throws ExecutionException
61 */
62 @Test
63 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
64 operation.execute(monitor, info);
65
66 Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
67 Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
68 Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
69 Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
70 }
71
72 /**
73 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
74 * @throws ExecutionException
75 */
76 @Test
77 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
78 operation.undo(monitor, info);
79
80 Assert.assertTrue("There should be synonyms now.", taxon.getSynonyms().size() > 0);
81 Assert.assertEquals("Synonym is not the expected.", synonym, taxon.getSynonyms().toArray(new Synonym[0]));
82 Assert.assertTrue("There should not be taxon relationships.", taxon.getRelationsToThisTaxon().size() == 0);
83 }
84
85 /**
86 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
87 * @throws ExecutionException
88 */
89 @Test
90 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
91 operation.redo(monitor, info);
92
93 Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
94 Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
95 Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
96 Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
97 }
98
99 /**
100 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
101 */
102 @Test
103 public void testPostExecute() {
104 // TODO there is not post operation functionality for this class
105 // at the moment. Implement test when there is.
106 logger.warn("No post operation functionality for this class");
107 }
108 }