Improved PrintPublisher Wizard; Integrated SpecimenCdmExcel import
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / test / java / eu / etaxonomy / taxeditor / editor / name / operation / CreateSynonymInExisitingHomotypicalGroupOperationTest.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 org.eclipse.core.commands.ExecutionException;
14 import org.junit.Assert;
15 import org.junit.Before;
16 import org.junit.Test;
17
18 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
19 import eu.etaxonomy.cdm.model.name.NonViralName;
20 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
21 import eu.etaxonomy.cdm.model.taxon.SynonymRelationship;
22 import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
23 import eu.etaxonomy.cdm.model.taxon.Taxon;
24 import eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation;
25 import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
26
27 /**
28 * @author n.hoffmann
29 * @created 07.04.2009
30 * @version 1.0
31 */
32 public class CreateSynonymInExisitingHomotypicalGroupOperationTest extends AbstractTaxeditorOperationTestBase {
33
34 private TaxonNameBase newSynonymName;
35
36 private HomotypicalGroup homotypicalGroup;
37
38
39 private NonViralName<?> taxonName;
40
41 /**
42 * @throws java.lang.Exception
43 */
44 @Before
45 public void setUp() throws Exception {
46
47 taxonName = NonViralName.NewInstance(null);
48 taxon = Taxon.NewInstance(taxonName, null);
49
50 homotypicalGroup = HomotypicalGroup.NewInstance();
51 newSynonymName = NonViralName.NewInstance(null);
52
53 operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
54 undoContext, taxon, homotypicalGroup, newSynonymName, postOperation);
55 }
56
57 /**
58 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
59 *
60 * Homotypic group is the Taxons homotypic group, so we expect the synonym to be homotypic to the accepted taxon.
61 *
62 * @throws ExecutionException
63 */
64 @Test
65 public void testExecuteTaxonHomotypicGroup() throws ExecutionException {
66 homotypicalGroup.addTypifiedName(taxonName);
67 operation.execute(monitor, info);
68
69 Assert.assertTrue("Taxon should have a synonym now.", taxon.getSynonyms().size() > 0);
70 Assert.assertTrue("Taxon should have a homotypic synonym now", taxon.getHomotypicSynonymsByHomotypicGroup().size() > 0);
71 }
72
73 /**
74 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
75 *
76 * Homotypic group is not the accepted taxons. Heterotypic synonym should be created.
77 *
78 * @throws ExecutionException
79 */
80 @Test
81 public void testExecuteSynonymHomotypicGroup() throws ExecutionException {
82 // test heterotypic synonym
83 operation.execute(monitor, info);
84
85 Assert.assertTrue("Taxon should have a synonym now.", taxon.getSynonyms().size() > 0);
86 Assert.assertTrue("Taxon should have a homotypic group", taxon.getHomotypicSynonymyGroups().size() > 0);
87 Assert.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), taxon.getSynonymRelations().toArray(new SynonymRelationship[0])[0].getType());
88 }
89
90
91 /**
92 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
93 * @throws ExecutionException
94 */
95 @Test
96 public void testUndoTaxonHomotypicGroup() throws ExecutionException {
97 homotypicalGroup.addTypifiedName(taxonName);
98
99 operation.execute(monitor, info);
100 operation.undo(monitor, info);
101
102 Assert.assertTrue("There should not be synonym relationships for the taxon", taxon.getSynonyms().size() == 0);
103 }
104
105 /**
106 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
107 * @throws ExecutionException
108 */
109 @Test
110 public void testUndoSynonymHomotypicGroup() throws ExecutionException {
111 operation.execute(monitor, info);
112 operation.undo(monitor, info);
113
114 Assert.assertTrue("There should not be synonym relationships for the taxon", taxon.getSynonyms().size() == 0);
115 }
116
117 /**
118 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
119 * @throws ExecutionException
120 */
121 @Test
122 public void testRedoTaxonHomotypicGroup() throws ExecutionException {
123 homotypicalGroup.addTypifiedName(taxonName);
124
125 operation.execute(monitor, info);
126 operation.undo(monitor, info);
127 operation.redo(monitor, info);
128
129 Assert.assertTrue("Taxon should have a synonym now.", taxon.getSynonyms().size() > 0);
130 Assert.assertTrue("Taxon should have a homotypic synonym now", taxon.getHomotypicSynonymsByHomotypicGroup().size() > 0);
131 }
132
133 /**
134 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
135 * @throws ExecutionException
136 */
137 @Test
138 public void testRedoSynonymHomotypicGroup() throws ExecutionException {
139 operation.execute(monitor, info);
140 operation.undo(monitor, info);
141 operation.redo(monitor, info);
142
143 Assert.assertTrue("Taxon should have a synonym now.", taxon.getSynonyms().size() > 0);
144 Assert.assertTrue("Taxon should have a homotypic group", taxon.getHomotypicSynonymyGroups().size() > 0);
145 Assert.assertEquals("Synonym relationship should be heterotypic", SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), taxon.getSynonymRelations().toArray(new SynonymRelationship[0])[0].getType());
146
147 }
148 }