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
|
|
23
|
import com.vaadin.data.util.sqlcontainer.RowId;
|
24
|
|
25
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
26
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
27
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
28
|
import eu.etaxonomy.cdm.vaadin.CdmVaadinBaseTest;
|
29
|
import eu.etaxonomy.cdm.vaadin.component.taxon.INewTaxonBaseComponentListener;
|
30
|
import eu.etaxonomy.cdm.vaadin.component.taxon.INewTaxonBaseComposite;
|
31
|
import eu.etaxonomy.cdm.vaadin.component.taxon.NewTaxonBasePresenter;
|
32
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
33
|
|
34
|
/**
|
35
|
* @author cmathew
|
36
|
* @date 2 Apr 2015
|
37
|
*
|
38
|
*/
|
39
|
|
40
|
@DataSet
|
41
|
public class NewTaxonBasePresenterTest extends CdmVaadinBaseTest {
|
42
|
|
43
|
@SuppressWarnings("unused")
|
44
|
private static final Logger logger = Logger.getLogger(NewTaxonBasePresenterTest.class);
|
45
|
|
46
|
private static NewTaxonBasePresenter ntbp;
|
47
|
|
48
|
@BeforeClass
|
49
|
public static void init() throws SQLException {
|
50
|
ntbp = new NewTaxonBasePresenter();
|
51
|
}
|
52
|
|
53
|
|
54
|
@Test
|
55
|
public void testNewTaxonBase(){
|
56
|
RowId refId20 = new RowId(20);
|
57
|
RowId refId21 = new RowId(21);
|
58
|
UUID newTaxonUuid = ntbp.newTaxon("Taxon h", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
59
|
List<String> ACC_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
|
60
|
"sec",
|
61
|
"synonyms"
|
62
|
});
|
63
|
Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
64
|
|
65
|
UUID newSynonymUuid = ntbp.newSynonym("Synonym ofe", refId20, refId21, newTaxonUuid).getUuid();
|
66
|
taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
67
|
|
68
|
Set<Synonym> synonyms = taxon.getSynonyms();
|
69
|
Assert.assertEquals(1,synonyms.size());
|
70
|
Synonym synonymOfTaxon = synonyms.iterator().next();
|
71
|
|
72
|
Synonym synonym = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newSynonymUuid),Synonym.class);
|
73
|
Assert.assertEquals(synonym, synonymOfTaxon);
|
74
|
|
75
|
Assert.assertEquals(synonym.getSec().getId(), 20);
|
76
|
|
77
|
taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
78
|
|
79
|
Assert.assertEquals(taxon.getSec().getId(), 21);
|
80
|
}
|
81
|
|
82
|
@Test
|
83
|
public void testNewTaxonBaseWhenNameAlreadyExists() {
|
84
|
RowId refId20 = new RowId(20);
|
85
|
// test taxa
|
86
|
try {
|
87
|
ntbp.newTaxon("Taxon e", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
88
|
Assert.fail("Exception should be thrown as name already exists");;
|
89
|
} catch (IllegalArgumentException iae) {
|
90
|
|
91
|
}
|
92
|
|
93
|
try {
|
94
|
ntbp.newTaxon("Taxon e", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
95
|
Assert.fail("Exception should be thrown as name already exists");;
|
96
|
} catch (IllegalArgumentException iae) {
|
97
|
|
98
|
}
|
99
|
try{
|
100
|
ntbp.newTaxon("Taxon e Me.", 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
|
|
106
|
// test synonym
|
107
|
RowId refId21 = new RowId(21);
|
108
|
UUID newTaxonUuid = ntbp.newTaxon("Taxon h", refId20, UUID.fromString("6595638e-4993-421a-9fe5-76b09d94f36a")).getUuid();
|
109
|
List<String> ACC_TAXON_INIT_STRATEGY = Arrays.asList(new String []{
|
110
|
"sec",
|
111
|
"synonymRelations"
|
112
|
});
|
113
|
Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService().load(newTaxonUuid,ACC_TAXON_INIT_STRATEGY),Taxon.class);
|
114
|
try {
|
115
|
ntbp.newSynonym("Htsynonym bofa", refId20, refId21, newTaxonUuid);
|
116
|
Assert.fail("Exception should be thrown as name already exists");;
|
117
|
} catch (IllegalArgumentException iae) {
|
118
|
|
119
|
}
|
120
|
|
121
|
try {
|
122
|
ntbp.newSynonym("Htsynonym bofa", refId20, refId21, newTaxonUuid);
|
123
|
Assert.fail("Exception should be thrown as name already exists");;
|
124
|
} catch (IllegalArgumentException iae) {
|
125
|
|
126
|
}
|
127
|
try{
|
128
|
ntbp.newSynonym("Htsynonym bofa Me.", refId20, refId21, newTaxonUuid);
|
129
|
Assert.fail("Exception should be thrown as name already exists");;
|
130
|
} catch (IllegalArgumentException iae) {
|
131
|
|
132
|
}
|
133
|
|
134
|
}
|
135
|
|
136
|
public static class MockNewTaxonBaseComposite implements INewTaxonBaseComposite {
|
137
|
|
138
|
/* (non-Javadoc)
|
139
|
* @see eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComposite#setListener(eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComponentListener)
|
140
|
*/
|
141
|
@Override
|
142
|
public void setListener(INewTaxonBaseComponentListener listener) {
|
143
|
// TODO Auto-generated method stub
|
144
|
|
145
|
}
|
146
|
|
147
|
|
148
|
|
149
|
}
|
150
|
}
|