Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / test / java / eu / etaxonomy / taxeditor / editor / name / operation / ChangeSynonymToMisapplicationOperationTest.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 package eu.etaxonomy.taxeditor.editor.name.operation;
10
11 import org.apache.log4j.Logger;
12 import org.eclipse.core.commands.ExecutionException;
13 import org.junit.Assert;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16
17 import eu.etaxonomy.cdm.model.common.ICdmBase;
18 import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
19 import eu.etaxonomy.cdm.model.taxon.Synonym;
20 import eu.etaxonomy.cdm.model.taxon.SynonymType;
21 import eu.etaxonomy.cdm.model.taxon.Taxon;
22 import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
23 import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
24
25 /**
26 * @author n.hoffmann
27 * @created 07.04.2009
28 */
29 public class ChangeSynonymToMisapplicationOperationTest extends AbstractTaxeditorOperationTestBase {
30
31 private static final Logger logger = Logger.getLogger(ChangeSynonymToMisapplicationOperationTest.class);
32
33 private static AbstractPostOperation<Taxon> operation;
34
35 private static Synonym synonym;
36 private static Taxon taxon;
37 private static SynonymType synonymType;
38
39 @BeforeClass
40 public static void setUpBeforeClass() throws Exception {
41 taxon = Taxon.NewInstance(null, null);
42 synonym = Synonym.NewInstance(TaxonNameFactory.NewNonViralInstance(null), null);
43 synonymType = SynonymType.SYNONYM_OF();
44 taxon.addSynonym(synonym, synonymType);
45
46 operation = new ChangeSynonymToMisapplicationOperation("Change Synonym To Misapplication", null, taxon, synonym, postOperation);
47 }
48
49 @Test
50 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
51 operation.execute(null, null);
52
53 Assert.assertTrue("Synonym should be deleted from taxon", taxon.getSynonyms().size() == 0);
54 Assert.assertTrue("Taxon should have misapplications", taxon.getMisappliedNames(false).size() > 0);
55 Assert.assertEquals("The name of synonym and misapplication should be equal", synonym.getName(), taxon.getMisappliedNames(false).toArray(new Taxon[0])[0].getName());
56 }
57
58 @Test
59 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
60 operation.undo(null, null);
61
62 Assert.assertTrue("Taxon should have synonyms.", taxon.getSynonyms().size() > 0);
63 Assert.assertTrue("Taxon should not have taxon relationship.", taxon.getTaxonRelations().size() == 0);
64 Assert.assertEquals("Not the expected synonym.", synonym, taxon.getSynonyms().toArray(new Synonym[0])[0]);
65 Assert.assertEquals("SynonymType is not the expected.", synonymType, taxon.getSynonyms().iterator().next().getType());
66 }
67
68 @Test
69 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
70 operation.redo(null, null);
71
72 Assert.assertTrue("Synonym should be deleted from taxon", taxon.getSynonyms().size() == 0);
73 Assert.assertTrue("Taxon should have misapplications", taxon.getMisappliedNames(false).size() > 0);
74 Assert.assertEquals("The name of synonym and misapplication should be equal", synonym.getName(), taxon.getMisappliedNames(false).toArray(new Taxon[0])[0].getName());
75 }
76
77 @Test
78 public void testPostExecute() {
79 // TODO there is not post operation functionality for this class
80 // at the moment. Implement test when there is.
81 logger.warn("No post operation functionality for this class");
82 }
83 }