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