Project

General

Profile

Download (5.56 KB) Statistics
| Branch: | Tag: | Revision:
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.SynonymType;
21
import eu.etaxonomy.cdm.model.taxon.Taxon;
22
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
23

    
24
/**
25
 * @author n.hoffmann
26
 * @created 07.04.2009
27
 * @version 1.0
28
 */
29
public class CreateSynonymInExisitingHomotypicalGroupOperationTest extends AbstractTaxeditorOperationTestBase {
30

    
31
	private NonViralName newSynonymName;
32

    
33
	private HomotypicalGroup homotypicalGroup;
34

    
35

    
36
	private NonViralName<?> taxonName;
37

    
38
	/**
39
	 * @throws java.lang.Exception
40
	 */
41
	@Before
42
	public void setUp() throws Exception {
43

    
44
		taxonName = NonViralName.NewInstance(null);
45
		taxon = Taxon.NewInstance(taxonName, null);
46

    
47
		homotypicalGroup = HomotypicalGroup.NewInstance();
48
		newSynonymName = NonViralName.NewInstance(null);
49

    
50
		operation = new CreateSynonymInExistingHomotypicalGroupOperation("Create Synonym In Existing Homotypical Group",
51
							undoContext, taxon, homotypicalGroup, newSynonymName, postOperation);
52
	}
53

    
54
	/**
55
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
56
	 *
57
	 * Homotypic group is the Taxons homotypic group, so we expect the synonym to be homotypic to the accepted taxon.
58
	 *
59
	 * @throws ExecutionException
60
	 */
61
	@Test
62
	public void testExecuteTaxonHomotypicGroup() throws ExecutionException {
63
		homotypicalGroup.addTypifiedName(taxonName);
64
		operation.execute(monitor, info);
65

    
66
		Assert.assertTrue("Taxon should have a synonym now.", taxon.getSynonyms().size() > 0);
67
		Assert.assertTrue("Taxon should have a homotypic synonym now", taxon.getHomotypicSynonymsByHomotypicGroup().size() > 0);
68
	}
69

    
70
	/**
71
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
72
	 *
73
	 * Homotypic group is not the accepted taxons. Heterotypic synonym should be created.
74
	 *
75
	 * @throws ExecutionException
76
	 */
77
	@Test
78
	public void testExecuteSynonymHomotypicGroup() throws ExecutionException {
79
		// test heterotypic synonym
80
		operation.execute(monitor, info);
81

    
82
		Assert.assertTrue("Taxon should have a synonym now.", taxon.getSynonyms().size() > 0);
83
		Assert.assertTrue("Taxon should have a homotypic group", taxon.getHomotypicSynonymyGroups().size() > 0);
84
		Assert.assertEquals("Synonym relationship should be heterotypic", SynonymType.HETEROTYPIC_SYNONYM_OF(), taxon.getSynonyms().iterator().next().getType());
85
	}
86

    
87

    
88
	/**
89
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
90
	 * @throws ExecutionException
91
	 */
92
	@Test
93
	public void testUndoTaxonHomotypicGroup() throws ExecutionException {
94
		homotypicalGroup.addTypifiedName(taxonName);
95

    
96
		operation.execute(monitor, info);
97
		operation.undo(monitor, info);
98

    
99
		Assert.assertTrue("There should not be synonym relationships for the taxon", taxon.getSynonyms().size() == 0);
100
	}
101

    
102
	/**
103
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
104
	 * @throws ExecutionException
105
	 */
106
	@Test
107
	public void testUndoSynonymHomotypicGroup() throws ExecutionException {
108
		operation.execute(monitor, info);
109
		operation.undo(monitor, info);
110

    
111
		Assert.assertTrue("There should not be synonym relationships for the taxon", taxon.getSynonyms().size() == 0);
112
	}
113

    
114
	/**
115
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
116
	 * @throws ExecutionException
117
	 */
118
	@Test
119
	public void testRedoTaxonHomotypicGroup() throws ExecutionException {
120
		homotypicalGroup.addTypifiedName(taxonName);
121

    
122
		operation.execute(monitor, info);
123
		operation.undo(monitor, info);
124
		operation.redo(monitor, info);
125

    
126
		Assert.assertTrue("Taxon should have a synonym now.", taxon.getSynonyms().size() > 0);
127
		Assert.assertTrue("Taxon should have a homotypic synonym now", taxon.getHomotypicSynonymsByHomotypicGroup().size() > 0);
128
	}
129

    
130
	/**
131
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.CreateSynonymInExistingHomotypicalGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
132
	 * @throws ExecutionException
133
	 */
134
	@Test
135
	public void testRedoSynonymHomotypicGroup() throws ExecutionException {
136
		operation.execute(monitor, info);
137
		operation.undo(monitor, info);
138
		operation.redo(monitor, info);
139

    
140
		Assert.assertTrue("Taxon should have a synonym now.", taxon.getSynonyms().size() > 0);
141
		Assert.assertTrue("Taxon should have a homotypic group", taxon.getHomotypicSynonymyGroups().size() > 0);
142
		Assert.assertEquals("Synonym relationship should be heterotypic", SynonymType.HETEROTYPIC_SYNONYM_OF(), taxon.getSynonyms().iterator().next().getType());
143

    
144
	}
145
}
(10-10/16)