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