Merge branch 'release/5.19.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / test / java / eu / etaxonomy / taxeditor / editor / name / operation / CreateConceptRelationOperationTest.java
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 package eu.etaxonomy.taxeditor.editor.name.operation;
10
11 import org.apache.log4j.Logger;
12 import org.eclipse.core.commands.ExecutionException;
13 import org.junit.Assert;
14 import org.junit.BeforeClass;
15 import org.junit.Test;
16
17 import eu.etaxonomy.cdm.model.common.ICdmBase;
18 import eu.etaxonomy.cdm.model.taxon.Taxon;
19 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
20 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
21 import eu.etaxonomy.taxeditor.editor.view.concept.operation.CreateConceptRelationOperation;
22 import eu.etaxonomy.taxeditor.store.operations.AbstractTaxeditorOperationTestBase;
23
24 /**
25 * @author n.hoffmann
26 * @created 07.04.2009
27 */
28 public class CreateConceptRelationOperationTest extends AbstractTaxeditorOperationTestBase {
29
30 private static final Logger logger = Logger.getLogger(CreateConceptRelationOperationTest.class);
31
32 private static TaxonRelationshipType taxonRelationshipType;
33 private static Taxon concept;
34
35 @BeforeClass
36 public static void setUpBeforeClass() throws Exception {
37
38 taxon = Taxon.NewInstance(null, null);
39 concept = Taxon.NewInstance(null, null);
40 taxonRelationshipType = TaxonRelationshipType.CONTRADICTION();
41
42 operation = new CreateConceptRelationOperation("Create Concept Relation", null, taxon, concept, taxonRelationshipType, postOperation);
43 }
44
45 @Test
46 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
47 operation.execute(monitor, info);
48
49 Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
50 Assert.assertEquals("Relationship type is not the expected", taxonRelationshipType, taxon.getRelationsToThisTaxon().toArray(new TaxonRelationship[0])[0].getType());
51 }
52
53 @Test
54 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
55 operation.undo(monitor, info);
56
57 Assert.assertTrue("There should not be taxon relationships", taxon.getTaxonRelations().size() == 0);
58 }
59
60 @Test
61 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
62 operation.redo(monitor, info);
63
64 Assert.assertTrue("Taxon should have taxon relationships now.", taxon.getRelationsToThisTaxon().size() > 0);
65 Assert.assertEquals("Relationship type is not the expected", taxonRelationshipType, taxon.getRelationsToThisTaxon().toArray(new TaxonRelationship[0])[0].getType());
66 }
67
68 @Test
69 public void testPostExecute() {
70 // TODO there is not post operation functionality for this class
71 // at the moment. Implement test when there is.
72 logger.warn("No post operation functionality for this class");
73 }
74 }