1
|
/**
|
2
|
* Copyright (C) 2015 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.presenter;
|
10
|
|
11
|
import java.sql.SQLException;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.Set;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.junit.Assert;
|
19
|
import org.junit.BeforeClass;
|
20
|
import org.junit.Test;
|
21
|
import org.unitils.dbunit.annotation.DataSet;
|
22
|
import org.unitils.dbunit.annotation.DataSets;
|
23
|
|
24
|
import com.vaadin.data.util.sqlcontainer.RowId;
|
25
|
|
26
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
28
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
29
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
30
|
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
|
31
|
import eu.etaxonomy.cdm.vaadin.component.taxon.INewTaxonBaseComponentListener;
|
32
|
import eu.etaxonomy.cdm.vaadin.component.taxon.INewTaxonBaseComposite;
|
33
|
import eu.etaxonomy.cdm.vaadin.component.taxon.NewTaxonBasePresenter;
|
34
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
35
|
|
36
|
/**
|
37
|
* @author cmathew
|
38
|
* @since 2 Apr 2015
|
39
|
*/
|
40
|
@DataSets({
|
41
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class),
|
42
|
@DataSet("/eu/etaxonomy/cdm/database/FirstData_UsersAndPermissions.xml")
|
43
|
})
|
44
|
public class NewTaxonBasePresenterTest extends CdmVaadinBaseTest {
|
45
|
|
46
|
@SuppressWarnings("unused")
|
47
|
private static final Logger logger = Logger.getLogger(NewTaxonBasePresenterTest.class);
|
48
|
|
49
|
private static NewTaxonBasePresenter newTaxonBasePresenter;
|
50
|
|
51
|
@BeforeClass
|
52
|
public static void init() throws SQLException {
|
53
|
newTaxonBasePresenter = new NewTaxonBasePresenter();
|
54
|
}
|
55
|
|
56
|
@Test
|
57
|
//NOTE by AM: I fixed property path sec=>secSource.citation (#9327), not sure if this is correct
|
58
|
// but as the test does not say what is meant to be tested I can't proof it
|
59
|
public void testNewTaxonBase(){
|
60
|
RowId refId20 = new RowId(20);
|
61
|
RowId refId21 = new RowId(21);
|
62
|
UUID newTaxonUuid = newTaxonBasePresenter.newTaxon("Taxon h", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
63
|
List<String> ACC_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
|
64
|
"secSource.citation",
|
65
|
"synonyms"
|
66
|
});
|
67
|
Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
68
|
|
69
|
UUID newSynonymUuid = newTaxonBasePresenter.newSynonym("Synonym ofe", refId20, refId21, newTaxonUuid).getUuid();
|
70
|
taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
71
|
|
72
|
Set<Synonym> synonyms = taxon.getSynonyms();
|
73
|
Assert.assertEquals(1,synonyms.size());
|
74
|
Synonym synonymOfTaxon = synonyms.iterator().next();
|
75
|
List<String> SYN_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
|
76
|
"secSource.citation"
|
77
|
});
|
78
|
Synonym synonym = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newSynonymUuid, SYN_TAXON_INIT_STRATEGY),Synonym.class);
|
79
|
Assert.assertEquals(synonym, synonymOfTaxon);
|
80
|
|
81
|
Assert.assertEquals(synonym.getSec().getId(), 20);
|
82
|
|
83
|
taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
84
|
|
85
|
Assert.assertEquals(taxon.getSec().getId(), 21);
|
86
|
}
|
87
|
|
88
|
@Test
|
89
|
public void testNewTaxonBaseWhenNameAlreadyExists() {
|
90
|
RowId refId20 = new RowId(20);
|
91
|
// test taxa
|
92
|
try {
|
93
|
newTaxonBasePresenter.newTaxon("Taxon e", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
94
|
Assert.fail("Exception should be thrown as name already exists");
|
95
|
} catch (IllegalArgumentException iae) {
|
96
|
|
97
|
}
|
98
|
|
99
|
try {
|
100
|
newTaxonBasePresenter.newTaxon("Taxon e", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
101
|
Assert.fail("Exception should be thrown as name already exists");
|
102
|
} catch (IllegalArgumentException iae) {
|
103
|
|
104
|
}
|
105
|
try{
|
106
|
newTaxonBasePresenter.newTaxon("Taxon e Me.", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
107
|
Assert.fail("Exception should be thrown as name already exists");
|
108
|
} catch (IllegalArgumentException iae) {
|
109
|
|
110
|
}
|
111
|
|
112
|
// test synonym
|
113
|
RowId refId21 = new RowId(21);
|
114
|
UUID newTaxonUuid = newTaxonBasePresenter.newTaxon("Taxon h", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
115
|
List<String> ACC_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
|
116
|
"secSource.citation",
|
117
|
"synonymRelations"
|
118
|
});
|
119
|
Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
120
|
try {
|
121
|
newTaxonBasePresenter.newSynonym("Htsynonym bofa", refId20, refId21, newTaxonUuid);
|
122
|
Assert.fail("Exception should be thrown as name already exists");
|
123
|
} catch (IllegalArgumentException iae) {
|
124
|
|
125
|
}
|
126
|
|
127
|
try {
|
128
|
newTaxonBasePresenter.newSynonym("Htsynonym bofa", refId20, refId21, newTaxonUuid);
|
129
|
Assert.fail("Exception should be thrown as name already exists");
|
130
|
} catch (IllegalArgumentException iae) {
|
131
|
|
132
|
}
|
133
|
try{
|
134
|
newTaxonBasePresenter.newSynonym("Htsynonym bofa Me.", refId20, refId21, newTaxonUuid);
|
135
|
Assert.fail("Exception should be thrown as name already exists");
|
136
|
} catch (IllegalArgumentException iae) {
|
137
|
|
138
|
}
|
139
|
}
|
140
|
|
141
|
public static class MockNewTaxonBaseComposite implements INewTaxonBaseComposite {
|
142
|
|
143
|
@Override
|
144
|
public void setListener(INewTaxonBaseComponentListener listener) {
|
145
|
// TODO Auto-generated method stub
|
146
|
}
|
147
|
}
|
148
|
}
|