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