Project

General

Profile

Download (5.6 KB) Statistics
| Branch: | Tag: | Revision:
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

    
10
package eu.etaxonomy.taxeditor.editor.name.operation;
11

    
12
import org.eclipse.core.commands.ExecutionException;
13
import org.junit.Assert;
14
import org.junit.Before;
15
import org.junit.Test;
16

    
17
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
18
import eu.etaxonomy.cdm.model.name.TaxonName;
19
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
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
 */
28
public class CreateSynonymInExisitingHomotypicalGroupOperationTest extends AbstractTaxeditorOperationTestBase {
29

    
30
	private TaxonName newSynonymName;
31

    
32
	private HomotypicalGroup homotypicalGroup;
33

    
34

    
35
	private TaxonName taxonName;
36

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

    
43
		taxonName = TaxonNameFactory.NewNonViralInstance(null);
44
		taxon = Taxon.NewInstance(taxonName, null);
45

    
46
		homotypicalGroup = HomotypicalGroup.NewInstance();
47
		newSynonymName = TaxonNameFactory.NewNonViralInstance(null);
48

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

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

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

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

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

    
86

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

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

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

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

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

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

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

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

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

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

    
143
	}
144
}
(10-10/16)