1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2015 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
|
package eu.etaxonomy.cdm.vaadin.presenter;
|
11
|
|
12
|
import java.sql.SQLException;
|
13
|
import java.util.Collection;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.junit.Assert;
|
17
|
import org.junit.BeforeClass;
|
18
|
import org.junit.Ignore;
|
19
|
import org.junit.Test;
|
20
|
import org.unitils.dbunit.annotation.DataSet;
|
21
|
|
22
|
import com.vaadin.data.Item;
|
23
|
import com.vaadin.data.util.sqlcontainer.RowId;
|
24
|
|
25
|
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
|
26
|
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
|
27
|
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
|
28
|
import eu.etaxonomy.cdm.vaadin.view.IStatusComposite;
|
29
|
|
30
|
|
31
|
/**
|
32
|
* @author cmathew
|
33
|
* @date 10 Mar 2015
|
34
|
*/
|
35
|
@DataSet
|
36
|
public class StatusPresenterTest extends CdmVaadinBaseTest {
|
37
|
|
38
|
private static final Logger logger = Logger.getLogger(StatusPresenterTest.class);
|
39
|
|
40
|
private static StatusPresenter sp;
|
41
|
|
42
|
@BeforeClass
|
43
|
public static void init() {
|
44
|
sp = new StatusPresenter();
|
45
|
}
|
46
|
|
47
|
|
48
|
|
49
|
@Test
|
50
|
public void testLoadTaxa() throws SQLException {
|
51
|
LeafNodeTaxonContainer container = sp.loadTaxa(11);
|
52
|
|
53
|
Collection<?> itemIds = container.rootItemIds();
|
54
|
|
55
|
Assert.assertEquals(3, itemIds.size());
|
56
|
|
57
|
sp.setUnplacedFilter();
|
58
|
itemIds = container.getItemIds();
|
59
|
Assert.assertEquals(1, itemIds.size());
|
60
|
|
61
|
sp.removeUnplacedFilter();
|
62
|
itemIds = container.getItemIds();
|
63
|
Assert.assertEquals(3, itemIds.size());
|
64
|
|
65
|
sp.setNameFilter("Taxon A");
|
66
|
itemIds = container.getItemIds();
|
67
|
Assert.assertEquals(1, itemIds.size());
|
68
|
|
69
|
}
|
70
|
|
71
|
@Test
|
72
|
public void testSynonyms() throws SQLException {
|
73
|
LeafNodeTaxonContainer container = sp.loadTaxa(11);
|
74
|
|
75
|
RowId taxonId10 = new RowId(10);
|
76
|
RowId taxonId11 = new RowId(11);
|
77
|
Collection<?> childIds = container.getChildren(taxonId10);
|
78
|
Assert.assertEquals(2, childIds.size());
|
79
|
|
80
|
Assert.assertEquals(true, container.areChildrenAllowed(taxonId10));
|
81
|
Assert.assertEquals(false, container.areChildrenAllowed(taxonId11));
|
82
|
}
|
83
|
|
84
|
@Test
|
85
|
public void updatePublishFlag() throws SQLException {
|
86
|
LeafNodeTaxonContainer container = sp.loadTaxa(11);
|
87
|
RowId taxonId = new RowId(10);
|
88
|
boolean pb = (Boolean) container.getItem(taxonId).getItemProperty(LeafNodeTaxonContainer.PB_ID).getValue();
|
89
|
Assert.assertTrue(pb);
|
90
|
sp.updatePublished(false, taxonId);
|
91
|
container.refresh();
|
92
|
pb = (Boolean) container.getItem(taxonId).getItemProperty(LeafNodeTaxonContainer.PB_ID).getValue();
|
93
|
Assert.assertFalse(pb);
|
94
|
}
|
95
|
|
96
|
@Test
|
97
|
public void testGetClassificationId() throws SQLException {
|
98
|
CdmSQLContainer container = sp.loadClassifications();
|
99
|
Object classificationId = sp.getClassificationId("Classification1");
|
100
|
Assert.assertEquals("11", classificationId.toString());
|
101
|
classificationId = sp.getClassificationId("ClassificationDoesNotExist");
|
102
|
Assert.assertNull(classificationId);
|
103
|
}
|
104
|
|
105
|
@Ignore
|
106
|
@Test
|
107
|
public void testLoadClassifications() throws SQLException {
|
108
|
CdmSQLContainer container = sp.loadClassifications();
|
109
|
Collection<?> itemIds = container.getItemIds();
|
110
|
String[] uuids = {"6595638e-4993-421a-9fe5-76b09d94f36a", "1ef8aada-de72-4023-bbe1-14465b6bc60d"};
|
111
|
int count = 0;
|
112
|
for(Object itemId : itemIds) {
|
113
|
Item item = container.getItem(itemId);
|
114
|
|
115
|
String uuid = (String)item.getItemProperty("UUID").getValue();
|
116
|
Assert.assertEquals(uuids[count], uuid);
|
117
|
String titleCache = (String)item.getItemProperty("TITLECACHE").getValue();
|
118
|
logger.info("titleCache : " + titleCache);
|
119
|
count++;
|
120
|
|
121
|
}
|
122
|
}
|
123
|
|
124
|
public static class MockStatusComposite implements IStatusComposite {
|
125
|
|
126
|
/* (non-Javadoc)
|
127
|
* @see eu.etaxonomy.cdm.vaadin.view.IStatusComposite#setListener(eu.etaxonomy.cdm.vaadin.view.IStatusComposite.StatusComponentListener)
|
128
|
*/
|
129
|
@Override
|
130
|
public void setListener(StatusComponentListener listener) {
|
131
|
// TODO Auto-generated method stub
|
132
|
|
133
|
}
|
134
|
|
135
|
}
|
136
|
}
|