e55c22831e04fc9324b06516073a664e46a1b049
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / test / java / eu / etaxonomy / taxeditor / editor / name / operation / ChangeConceptToSynonymOperationTest.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.taxeditor.editor.name.operation;
11
12 import org.apache.log4j.Logger;
13 import org.eclipse.core.commands.ExecutionException;
14 import org.junit.Assert;
15 import org.junit.BeforeClass;
16 import org.junit.Test;
17
18 import eu.etaxonomy.cdm.model.common.ICdmBase;
19 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
20 import eu.etaxonomy.cdm.model.name.INonViralName;
21 import eu.etaxonomy.cdm.model.name.TaxonName;
22 import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
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.AbstractTaxeditorOperationTestBase;
29
30 /**
31 * @author n.hoffmann
32 * @created 07.04.2009
33 */
34 public class ChangeConceptToSynonymOperationTest extends AbstractTaxeditorOperationTestBase {
35 private static final Logger logger = Logger.getLogger(ChangeConceptToSynonymOperationTest.class);
36
37 private static Taxon taxon;
38
39 private static Taxon concept;
40
41 private static AbstractPostOperation operation;
42
43 private static HomotypicalGroup homotypicalGroup;
44
45 private Synonym[] synonymType = new Synonym[0];
46 private Taxon[] taxonType = new Taxon[0];
47
48 /**
49 * @throws java.lang.Exception
50 */
51 @BeforeClass
52 public static void setUpBeforeClass() throws Exception {
53 taxon = Taxon.NewInstance(null, null);
54 concept = Taxon.NewInstance(TaxonNameFactory.NewNonViralInstance(null), null);
55 homotypicalGroup = HomotypicalGroup.NewInstance();
56
57 concept.addTaxonRelation(taxon, TaxonRelationshipType.MISAPPLIED_NAME_FOR(), null, null);
58
59 operation = new ChangeConceptToSynonymOperation("Change misapplication to synonym", null, taxon, concept, homotypicalGroup, postOperation);
60 }
61
62 /**
63 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
64 * @throws ExecutionException
65 */
66 @Test
67 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
68 operation.execute(null, null);
69
70 Assert.assertTrue(taxon.getSynonyms().size() == 1);
71 Assert.assertTrue(concept.getRelationsFromThisTaxon().size() == 0);
72 Assert.assertEquals(concept.getName(), taxon.getSynonyms().toArray(synonymType)[0].getName());
73
74 }
75
76 /**
77 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
78 * @throws ExecutionException
79 */
80 @Test
81 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
82 operation.undo(null, null);
83
84 Assert.assertTrue("There shouldn't be synonyms after undo operations", taxon.getSynonyms().size() == 0);
85 Assert.assertTrue(concept.getRelationsFromThisTaxon().size() > 0);
86 Assert.assertEquals(taxon, concept.getRelationsFromThisTaxon().toArray(taxonType)[0]);
87 }
88
89 /**
90 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeConceptToSynonymOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
91 * @throws ExecutionException
92 */
93 @Test
94 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
95 operation.redo(null, null);
96
97 Assert.assertTrue(taxon.getSynonyms().size() == 1);
98 Assert.assertTrue(concept.getRelationsFromThisTaxon().size() == 0);
99 Assert.assertEquals(concept.getName(), taxon.getSynonyms().toArray(synonymType)[0].getName());
100 }
101
102 /**
103 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
104 */
105 @Test
106 public void testPostExecute() {
107 // TODO there is not post operation functionality for this class
108 // at the moment. Implement test when there is.
109 logger.warn("No post operation functionality for this class");
110 }
111 }