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