Project

General

Profile

Download (6.61 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.apache.log4j.Logger;
13
import org.eclipse.core.commands.ExecutionException;
14
import org.junit.Assert;
15
import org.junit.BeforeClass;
16
import org.junit.Test;
17

    
18
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
19
import eu.etaxonomy.cdm.model.common.ICdmBase;
20
import eu.etaxonomy.cdm.model.description.TaxonDescription;
21
import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
22
import eu.etaxonomy.cdm.model.name.NonViralName;
23
import eu.etaxonomy.cdm.model.taxon.Synonym;
24
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
25
import eu.etaxonomy.cdm.model.taxon.Taxon;
26
import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
27
import eu.etaxonomy.taxeditor.operation.AbstractPostOperation;
28
import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
29

    
30
/**
31
 * @author n.hoffmann
32
 * @created 02.04.2009
33
 * @version 1.0
34
 */
35
public class SwapSynonymAndAcceptedOperationTest extends AbstractTaxeditorOperationTestBase {
36
	private static final Logger logger = Logger
37
			.getLogger(SwapSynonymAndAcceptedOperationTest.class);
38

    
39
	private static AbstractPostOperation operation;
40

    
41
	private static Taxon taxon;
42

    
43
	private static Taxon parentTaxon;
44

    
45
	private static Synonym homotypicSynonym;
46

    
47
	private static Synonym oldHeterotypicSynonym;
48

    
49
	private static HomotypicalGroup heteroypicalGroup;
50

    
51
	private static Taxon misapplication;
52

    
53
	private static Taxon concept;
54

    
55
	private static TaxonRelationshipType conceptRelationshipType;
56

    
57
	private static Taxon childTaxon;
58

    
59
	private static TaxonDescription description;
60

    
61
	private static NonViralName<?> oldSynonymName;
62

    
63
	private static NonViralName<?> oldTaxonName;
64

    
65

    
66
	/**
67
	 * @throws java.lang.Exception
68
	 */
69
	@BeforeClass
70
	public static void setUpBeforeClass() throws Exception {
71

    
72
		(new DefaultTermInitializer()).initialize();
73

    
74
		// Create the original accepted taxon
75
		oldTaxonName = NonViralName.NewInstance(null);
76
		taxon = Taxon.NewInstance(oldTaxonName, null);
77

    
78
//		// Create its parent taxon
79
//		parentTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
80
//		parentTaxon.addTaxonomicChild(taxon, null, null);
81
//
82
//		// Give it a child taxon
83
//		childTaxon = Taxon.NewInstance(NonViralName.NewInstance(null), null);
84
//		childTaxon.setTaxonomicParent(taxon, null, null);
85

    
86
		// Create a homotypic synonym for the accepted taxon
87
		taxon.addHomotypicSynonymName(NonViralName.NewInstance(null));
88
//		homotypicSynonym = Synonym.NewInstance(NonViralName.NewInstance(null), null);
89
//		HomotypicalGroup acceptedHomotypicalGroup = HomotypicalGroup.NewInstance();
90
//		acceptedHomotypicalGroup.addTypifiedName(oldTaxon.getName());
91
//		acceptedHomotypicalGroup.addTypifiedName(homotypicSynonym.getName());
92

    
93
		// Create a heterotypic synonym that will be used to create the new accepted taxon
94
		oldSynonymName = NonViralName.NewInstance(null);
95
		oldHeterotypicSynonym = Synonym.NewInstance(oldSynonymName, null);
96
//		oldTaxon.addS .addHeterotypicSynonym(oldHeterotypicSynonym, null, null);
97
		heteroypicalGroup = HomotypicalGroup.NewInstance();
98
		heteroypicalGroup.addTypifiedName(oldHeterotypicSynonym.getName());
99
		taxon.addSynonym(oldHeterotypicSynonym, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF());
100

    
101
		// Create a misapplication
102
		misapplication = Taxon.NewInstance(NonViralName.NewInstance(null), null);
103
		taxon.addMisappliedName(misapplication, null, null);
104

    
105
		// Create a concept relation
106
		concept = Taxon.NewInstance(NonViralName.NewInstance(null), null);
107
		conceptRelationshipType = TaxonRelationshipType.CONGRUENT_TO();
108
		concept.addTaxonRelation(taxon, conceptRelationshipType, null, null);
109

    
110
		// Create a description
111
		description = TaxonDescription.NewInstance();
112
		taxon.addDescription(description);
113

    
114
		operation = new SwapSynonymAndAcceptedOperation
115
				(null, undoContext, taxon, oldHeterotypicSynonym, postOperation, cdmEntitySessionEnabled);
116
	}
117

    
118

    
119
	/**
120
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
121
	 * @throws ExecutionException
122
	 */
123
	@Test
124
	public void testExecute() throws ExecutionException {
125
		operation.execute(null, null);
126

    
127
		// New taxon has correct name?
128
		Assert.assertEquals(taxon.getName(), oldSynonymName);
129

    
130
//		// New taxon has correct parent?
131
//		Assert.assertEquals(taxon.getTaxonomicParent(), parentTaxon);
132
//
133
//		// New taxon has correct child?
134
//		Assert.assertTrue(taxon.getTaxonomicChildren().contains(childTaxon));
135

    
136
		// New taxon has 2 synonyms?
137
		Assert.assertEquals(taxon.getSynonyms().size(), 2);
138

    
139
		// New taxon has a synonym with the name of the previous accepted taxon?
140
		Assert.assertTrue(taxon.getSynonymNames().contains(oldTaxonName));
141

    
142
		// New taxon has misapplication?
143
		Assert.assertTrue(taxon.getMisappliedNames().contains(misapplication));
144

    
145
//		// New taxon has 1 concept relation?
146
//		int conceptRelCount = 0;
147
//		for (TaxonRelationship relation : taxon.getTaxonRelations()) {
148
//			if (relation.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR()) ||
149
//					relation.getType().equals(TaxonRelationshipType.TAXONOMICALLY_INCLUDED_IN())) {
150
//				continue;
151
//			}
152
//			conceptRelCount++;
153
//		}
154
//		Assert.assertEquals(conceptRelCount, 1);
155

    
156
		// New taxon has description?
157
		taxon.getDescriptions().contains(description);
158
	}
159

    
160
	/**
161
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
162
	 * @throws ExecutionException
163
	 */
164
	@Test
165
	public void testUndo() throws ExecutionException {
166
		operation.undo(null, null);
167

    
168
//		Assert.assertEquals(oldHomotypicalGroup, synonym.getHomotypicGroup());
169
	}
170

    
171
	/**
172
	 * Test method for {@link eu.etaxonomy.taxeditor.editor.name.operation.ChangeHomotypicGroupOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
173
	 * @throws ExecutionException
174
	 */
175
	@Test
176
	public void testRedo() throws ExecutionException {
177
		operation.redo(null, null);
178

    
179
//		Assert.assertEquals(newHomotypicalGroup, synonym.getHomotypicGroup());
180
	}
181

    
182
	/**
183
	 * Test method for {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation#postExecute(ICdmBase)}.
184
	 */
185
	@Test
186
	public void testPostExecute() {
187
		// TODO there is not post operation functionality for this class
188
		// at the moment. Implement test when there is.
189
		logger.warn("No post operation functionality for this class");
190
	}
191
}
(17-17/17)