Moving editor sources back into trunk
[taxeditor.git] / taxeditor-store / src / test / java / eu / etaxonomy / taxeditor / store / operations / DeleteDescriptionElementOperationTest.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 static org.junit.Assert.*;
14
15 import org.apache.log4j.Logger;
16 import org.eclipse.core.commands.ExecutionException;
17 import org.eclipse.core.commands.operations.IUndoContext;
18 import org.eclipse.core.runtime.IAdaptable;
19 import org.eclipse.core.runtime.IProgressMonitor;
20 import org.junit.Assert;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23
24 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
25 import eu.etaxonomy.cdm.model.description.TaxonDescription;
26 import eu.etaxonomy.cdm.model.description.TextData;
27 import eu.etaxonomy.cdm.model.taxon.Taxon;
28
29 /**
30 * @author n.hoffmann
31 * @created 08.04.2009
32 * @version 1.0
33 */
34 public class DeleteDescriptionElementOperationTest extends AbstractTaxeditorOperationTest {
35 private static final Logger logger = Logger
36 .getLogger(DeleteDescriptionElementOperationTest.class);
37
38 private static DescriptionElementBase descriptionElement;
39
40 private static TaxonDescription description;
41
42 /**
43 * @throws java.lang.Exception
44 */
45 @BeforeClass
46 public static void setUpBeforeClass() throws Exception {
47 taxon = Taxon.NewInstance(null, null);
48 descriptionElement = TextData.NewInstance();
49
50 description = TaxonDescription.NewInstance();
51
52 description.addElement(descriptionElement);
53
54 taxon.addDescription(description);
55
56
57 operation = new DeleteDescriptionElementOperation("", undoContext, taxon, descriptionElement, postOperation);
58 }
59
60 /**
61 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.DeleteDescriptionElementOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
62 * @throws ExecutionException
63 */
64 @Test
65 public void testExecuteIProgressMonitorIAdaptable() throws ExecutionException {
66 operation.execute(monitor, info);
67
68 Assert.assertTrue(taxon.getDescriptions().toArray(new TaxonDescription[0])[0].getElements().size() == 0);
69 }
70
71 /**
72 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.DeleteDescriptionElementOperation#undo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
73 * @throws ExecutionException
74 */
75 @Test
76 public void testUndoIProgressMonitorIAdaptable() throws ExecutionException {
77 operation.undo(monitor, info);
78
79 Assert.assertTrue(taxon.getDescriptions().toArray(new TaxonDescription[0])[0].getElements().size() > 0);
80 Assert.assertEquals(descriptionElement, taxon.getDescriptions().toArray(new TaxonDescription[0])[0].getElements().toArray(new DescriptionElementBase[0])[0]);
81 }
82
83 /**
84 * Test method for {@link eu.etaxonomy.taxeditor.store.operations.DeleteDescriptionElementOperation#redo(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable)}.
85 * @throws ExecutionException
86 */
87 @Test
88 public void testRedoIProgressMonitorIAdaptable() throws ExecutionException {
89 operation.redo(monitor, info);
90
91 Assert.assertTrue(taxon.getDescriptions().toArray(new TaxonDescription[0])[0].getElements().size() == 0);
92 }
93 }