Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / test / java / eu / etaxonomy / taxeditor / editor / name / operation / ChangeSynonymToConceptOperationTest.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.cdm.model.taxon.TaxonRelationship;
23 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
24 import eu.etaxonomy.taxeditor.editor.name.operation.ChangeSynonymToConceptOperation;
25 import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
26
27 /**
28 * @author n.hoffmann
29 * @created 07.04.2009
30 */
31 public class ChangeSynonymToConceptOperationTest extends AbstractTaxeditorOperationTestBase{
32
33 private static final Logger logger = Logger.getLogger(ChangeSynonymToConceptOperationTest.class);
34
35 private static TaxonRelationshipType taxonRelationshipType;
36 private static Synonym synonym;
37
38 @BeforeClass
39 public static void setUpBeforeClass() throws Exception {
40
41 taxon = Taxon.NewInstance(null, null);
42 synonym = Synonym.NewInstance(TaxonNameFactory.NewNonViralInstance(null), null);
43 taxonRelationshipType = TaxonRelationshipType.CONTRADICTION();
44
45 taxon.addSynonym(synonym, SynonymType.SYNONYM_OF());
46
47 operation = new ChangeSynonymToConceptOperation("Change Synonym To Concept", null, taxon, synonym, taxonRelationshipType, postOperation);
48 }
49
50 @Test
51 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
52 operation.execute(monitor, info);
53
54 Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
55 Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
56 Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
57 Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
58 }
59
60 @Test
61 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
62 operation.undo(monitor, info);
63
64 Assert.assertTrue("There should be synonyms now.", taxon.getSynonyms().size() > 0);
65 Assert.assertEquals("Synonym is not the expected.", synonym, taxon.getSynonyms().toArray(new Synonym[0]));
66 Assert.assertTrue("There should not be taxon relationships.", taxon.getRelationsToThisTaxon().size() == 0);
67 }
68
69 @Test
70 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
71 operation.redo(monitor, info);
72
73 Assert.assertTrue("Synonym should be deleted from taxon.", taxon.getSynonyms().size() == 0);
74 Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
75 Assert.assertEquals("Relationship is not the expected", taxonRelationshipType, taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getType());
76 Assert.assertEquals("Name of synonym and newly created related taxon should be equal", synonym.getName(), taxon.getTaxonRelations().toArray(new TaxonRelationship[0])[0].getFromTaxon().getName());
77 }
78
79 @Test
80 public void testPostExecute() {
81 // TODO there is not post operation functionality for this class
82 // at the moment. Implement test when there is.
83 logger.warn("No post operation functionality for this class");
84 }
85 }