Moving editor sources back into trunk
[taxeditor.git] / taxeditor-store / src / test / java / eu / etaxonomy / taxeditor / store / operations / ChangeSynonymToMisapplicationOperationTest.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 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.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;
24
25 /**
26 * @author n.hoffmann
27 * @created 07.04.2009
28 * @version 1.0
29 */
30 public class ChangeSynonymToMisapplicationOperationTest extends AbstractTaxeditorOperationTest {
31 private static final Logger logger = Logger
32 .getLogger(ChangeSynonymToMisapplicationOperationTest.class);
33
34 private static Synonym synonym;
35
36 private static Taxon taxon;
37
38 private static AbstractPostOperation operation;
39
40 private static SynonymRelationshipType synonymRelationshipType;
41
42 /**
43 * @throws java.lang.Exception
44 */
45 @BeforeClass
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);
51
52 operation = new ChangeSynonymToMisapplicationOperation("Change Synonym To Misapplication", null, taxon, synonym, postOperation);
53 }
54
55 /**
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
58 */
59 @Test
60 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
61 operation.execute(null, null);
62
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());
66 }
67
68 /**
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
71 */
72 @Test
73 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
74 operation.undo(null, null);
75
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));
80 }
81
82 /**
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
85 */
86 @Test
87 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
88 operation.redo(null, null);
89
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());
93 }
94
95 /**
96 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.AbstractPostOperation#postExecute(CdmBase)}.
97 */
98 @Test
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");
103 }
104 }