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