be3ca5264b61a88da3ae4c7eba4ac0b5fa45268e
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / test / java / eu / etaxonomy / taxeditor / editor / name / operation / ChangeConceptToSynonymOperationTest.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.HomotypicalGroup;
22 import eu.etaxonomy.cdm.model.name.NonViralName;
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.AbstractTaxeditorOperationTest;
29
30 /**
31 * @author n.hoffmann
32 * @created 07.04.2009
33 * @version 1.0
34 */
35 public class ChangeConceptToSynonymOperationTest extends AbstractTaxeditorOperationTest {
36 private static final Logger logger = Logger
37 .getLogger(ChangeConceptToSynonymOperationTest.class);
38
39 private static Taxon taxon;
40
41 private static Taxon concept;
42
43 private static AbstractPostOperation operation;
44
45 private static HomotypicalGroup homotypicalGroup;
46
47 private Synonym[] synonymType = new Synonym[0];
48 private Taxon[] taxonType = new Taxon[0];
49
50 /**
51 * @throws java.lang.Exception
52 */
53 @BeforeClass
54 public static void setUpBeforeClass() throws Exception {
55 taxon = Taxon.NewInstance(null, null);
56 concept = Taxon.NewInstance(NonViralName.NewInstance(null), null);
57 homotypicalGroup = HomotypicalGroup.NewInstance();
58
59 concept.addTaxonRelation(taxon, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null);
60
61 operation = new ChangeConceptToSynonymOperation("Change misapplication to synonym", null, taxon, concept, homotypicalGroup, postOperation);
62 }
63
64 /**
65 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
66 * @throws ExecutionException
67 */
68 @Test
69 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
70 operation.execute(null, null);
71
72 Assert.assertTrue(taxon.getSynonyms().size() == 1);
73 Assert.assertTrue(concept.getRelationsFromThisTaxon().size() == 0);
74 Assert.assertEquals(concept.getName(), taxon.getSynonyms().toArray(synonymType)[0].getName());
75
76 }
77
78 /**
79 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
80 * @throws ExecutionException
81 */
82 @Test
83 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
84 operation.undo(null, null);
85
86 Assert.assertTrue("There shouldn't be synonyms after undo operations", taxon.getSynonyms().size() == 0);
87 Assert.assertTrue(concept.getRelationsFromThisTaxon().size() > 0);
88 Assert.assertEquals(taxon, concept.getRelationsFromThisTaxon().toArray(taxonType)[0]);
89 }
90
91 /**
92 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
93 * @throws ExecutionException
94 */
95 @Test
96 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
97 operation.redo(null, null);
98
99 Assert.assertTrue(taxon.getSynonyms().size() == 1);
100 Assert.assertTrue(concept.getRelationsFromThisTaxon().size() == 0);
101 Assert.assertEquals(concept.getName(), taxon.getSynonyms().toArray(synonymType)[0].getName());
102 }
103
104 /**
105 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostOperation#postExecute(ICdmBase)}.
106 */
107 @Test
108 public void testPostExecute() {
109 // TODO there is not post operation functionality for this class
110 // at the moment. Implement test when there is.
111 logger.warn("No post operation functionality for this class");
112 }
113 }