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