Moving editor sources back into trunk
[taxeditor.git] / taxeditor-store / src / test / java / eu / etaxonomy / taxeditor / store / operations / CreateDescriptionElementOperationTest.java
1
2 package eu.etaxonomy.taxeditor.store.operations;
3
4 import junit.framework.Assert;
5
6 import org.apache.log4j.Logger;
7 import org.eclipse.core.commands.ExecutionException;
8 import org.junit.BeforeClass;
9 import org.junit.Test;
10
11 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
12 import eu.etaxonomy.cdm.model.description.Feature;
13 import eu.etaxonomy.cdm.model.description.TaxonDescription;
14 import eu.etaxonomy.cdm.model.taxon.Taxon;
15
16 public class CreateDescriptionElementOperationTest extends AbstractTaxeditorOperationTest {
17 private static final Logger logger = Logger
18 .getLogger(CreateDescriptionElementOperationTest.class);
19
20
21 private static TaxonDescription description;
22
23 private static Feature feature;
24
25 private DescriptionElementBase[] arrayType = new DescriptionElementBase[0];
26
27 @BeforeClass
28 public static void setUpBeforeClass() throws Exception {
29 taxon = Taxon.NewInstance(null, null);
30 description = TaxonDescription.NewInstance();
31 feature = Feature.NewInstance();
32
33 operation = new CreateDescriptionElementOperation("Add Element", null, taxon, description, feature, postOperation);
34 }
35
36
37 @Test
38 public void testExecute() throws ExecutionException {
39 operation.execute(monitor, info);
40
41 Assert.assertTrue(description.getElements().size() > 0);
42 Assert.assertEquals(feature, description.getElements().toArray(arrayType)[0].getFeature());
43 }
44
45 @Test
46 public void testUndo() throws ExecutionException {
47 operation.undo(monitor, info);
48
49 Assert.assertTrue(description.getElements().size() == 0);
50 }
51
52 @Test
53 public void testRedo() throws ExecutionException {
54 operation.redo(monitor, info);
55
56 Assert.assertTrue(description.getElements().size() > 0);
57 Assert.assertEquals(feature, description.getElements().toArray(arrayType)[0].getFeature());
58 }
59 }