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