1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.cdm.ext.ipni;
|
5
|
|
6
|
import java.io.InputStream;
|
7
|
import java.util.List;
|
8
|
|
9
|
import org.apache.log4j.Logger;
|
10
|
import org.junit.Assert;
|
11
|
import org.junit.Before;
|
12
|
import org.junit.BeforeClass;
|
13
|
import org.junit.Test;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
|
16
|
import eu.etaxonomy.cdm.common.UriUtils;
|
17
|
import eu.etaxonomy.cdm.ext.ipni.IIpniService.DelimitedFormat;
|
18
|
import eu.etaxonomy.cdm.ext.ipni.IpniService.IpniRank;
|
19
|
import eu.etaxonomy.cdm.model.agent.Person;
|
20
|
import eu.etaxonomy.cdm.model.common.Extension;
|
21
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
22
|
import eu.etaxonomy.cdm.model.name.Rank;
|
23
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
24
|
|
25
|
/**
|
26
|
* @author a.mueller
|
27
|
*
|
28
|
*/
|
29
|
//@Ignore
|
30
|
public class IpniServiceTest {
|
31
|
@SuppressWarnings("unused")
|
32
|
private static final Logger logger = Logger.getLogger(IpniServiceTest.class);
|
33
|
|
34
|
private IpniService service1;
|
35
|
private static boolean internetIsAvailable = true;
|
36
|
|
37
|
@BeforeClass
|
38
|
public static void setUpClass() throws Exception {
|
39
|
internetIsAvailable = true;
|
40
|
}
|
41
|
|
42
|
|
43
|
|
44
|
/**
|
45
|
* @throws java.lang.Exception
|
46
|
*/
|
47
|
@Before
|
48
|
public void setUp() throws Exception {
|
49
|
service1 = new IpniService();
|
50
|
}
|
51
|
|
52
|
// ******************************* TESTS ******************************************************/
|
53
|
|
54
|
/**
|
55
|
* Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#IpniService(java.net.URL)}.
|
56
|
*/
|
57
|
@Test
|
58
|
public void testIpniService() {
|
59
|
Assert.assertNotNull("Service should not be null", service1);
|
60
|
Assert.assertNotNull("URL1 should not be null", service1.getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL));
|
61
|
}
|
62
|
|
63
|
@Test
|
64
|
public void testGetAuthors(){
|
65
|
ICdmApplicationConfiguration services = null;
|
66
|
IpniServiceAuthorConfigurator config = new IpniServiceAuthorConfigurator();
|
67
|
config.setFormat(DelimitedFormat.EXTENDED);
|
68
|
List<Person> authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
|
69
|
//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
|
70
|
|
71
|
if (testInternetConnectivity(authorList)){
|
72
|
Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
|
73
|
Person author = authorList.get(0);
|
74
|
//title cache
|
75
|
Assert.assertEquals("Title Cache for Greuter should be 'Werner Rodolfo Greuter'", "Werner Rodolfo Greuter", author.getTitleCache());
|
76
|
//alternative names
|
77
|
Assert.assertEquals("One extension for the alternative name should exist", 1, author.getExtensions().size());
|
78
|
Extension alternativeName = author.getExtensions().iterator().next();
|
79
|
Assert.assertEquals("Alternative name should be ", "Greuter, Werner Rodolfo", alternativeName.getValue());
|
80
|
//dates
|
81
|
String year = author.getLifespan().getYear();
|
82
|
Assert.assertNotNull("Year should be not null", year);
|
83
|
Assert.assertEquals("Year should be 1938", "1938", year);
|
84
|
|
85
|
authorList = service1.getAuthors(null, "Greu*", null, null, null, config);
|
86
|
|
87
|
//29367-1%1.1%Greuet%Claude%Greuet%A%%>Greuet, Claude
|
88
|
//20000981-1%1.1%Greuning%J.V. van%Greuning%M%1993%>Greuning, J.V. van
|
89
|
//3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
|
90
|
Assert.assertEquals("There should be exactly 3 result for 'Greu*'. But maybe this changes over time", 3, authorList.size());
|
91
|
// for (Person person : authorList){
|
92
|
// System.out.println(person.getTitleCache() + "; " + person.getNomenclaturalTitle());
|
93
|
// }
|
94
|
//
|
95
|
config.setFormat(DelimitedFormat.MINIMAL);
|
96
|
authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
|
97
|
Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
|
98
|
author = authorList.get(0);
|
99
|
Assert.assertTrue("No alternative names should exist in the minimal version", author.getExtensions().isEmpty());
|
100
|
}
|
101
|
}
|
102
|
|
103
|
|
104
|
@Test
|
105
|
public void testGetNamesSimple(){
|
106
|
ICdmApplicationConfiguration services = null;
|
107
|
IpniServiceNamesConfigurator config = null;
|
108
|
List<BotanicalName> nameList = service1.getNamesSimple("Abies albertiana", services, config);
|
109
|
//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
|
110
|
|
111
|
if (testInternetConnectivity(nameList)){
|
112
|
Assert.assertEquals("There should be exactly 1 result for 'Abies albertiana'", 1, nameList.size());
|
113
|
BotanicalName name = nameList.get(0);
|
114
|
//title cache
|
115
|
Assert.assertEquals("Title Cache for Abies albertiana should be 'Abies albertiana'", "Abies albertiana A.Murr.", name.getTitleCache());
|
116
|
|
117
|
// for (BotanicalName listName : nameList){
|
118
|
// System.out.println(name.getFullTitleCache());
|
119
|
// }
|
120
|
}
|
121
|
|
122
|
}
|
123
|
|
124
|
@Test
|
125
|
public void testGetNamesAdvanced(){
|
126
|
ICdmApplicationConfiguration services = null;
|
127
|
IpniServiceNamesConfigurator config = new IpniServiceNamesConfigurator();
|
128
|
|
129
|
//http://www.uk.ipni.org/ipni/advPlantNameSearch.do?find_family=&find_genus=Abies&find_species=alba&find_infrafamily=&find_infragenus=&find_infraspecies=&find_authorAbbrev=B*&find_includePublicationAuthors=on&find_includePublicationAuthors=off&find_includeBasionymAuthors=on&find_includeBasionymAuthors=off&find_publicationTitle=&find_isAPNIRecord=on&find_isAPNIRecord=false&find_isGCIRecord=on&find_isGCIRecord=false&find_isIKRecord=on&find_isIKRecord=false&find_rankToReturn=infraspec&output_format=normal&find_sortByFamily=on&find_sortByFamily=off&query_type=by_query&back_page=plantsearch
|
130
|
String family = "";
|
131
|
String genus = "Abies";
|
132
|
String species = "alba";
|
133
|
String infraFamily = "";
|
134
|
String infraGenus = "";
|
135
|
String infraSpecies = "";
|
136
|
String authorAbbrev = "B*";
|
137
|
Boolean includePublicationAuthors = null;
|
138
|
Boolean includeBasionymAuthors = null;
|
139
|
String publicationTitle = "";
|
140
|
Boolean isAPNIRecord = null;
|
141
|
Boolean isGCIRecord = null;
|
142
|
Boolean isIKRecord = null;
|
143
|
IpniRank rankToReturn = IpniRank.valueOf(Rank.SUBSPECIES());
|
144
|
Boolean sortByFamily = null;
|
145
|
|
146
|
List<BotanicalName> nameList = service1.getNamesAdvanced(family, genus, species, infraFamily, infraGenus, infraSpecies, authorAbbrev, includePublicationAuthors, includeBasionymAuthors, publicationTitle, isAPNIRecord, isGCIRecord, isIKRecord, rankToReturn, sortByFamily, config, services);
|
147
|
//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
|
148
|
|
149
|
|
150
|
if (testInternetConnectivity(nameList)){
|
151
|
|
152
|
Assert.assertEquals("There should be exactly 1 result for 'Abies', 'alba', 'B*', Infraspecific ", 1, nameList.size());
|
153
|
BotanicalName name = nameList.get(0);
|
154
|
//title cache
|
155
|
Assert.assertEquals("Title Cache for 'Abies', 'alba', 'ap*' should be 'Abies alba subsp. apennina Brullo, Scelsi & Spamp.'", "Abies alba subsp. apennina Brullo, Scelsi & Spamp.", name.getTitleCache());
|
156
|
|
157
|
// for (BotanicalName listName : nameList){
|
158
|
// System.out.println(name.getFullTitleCache());
|
159
|
// }
|
160
|
}
|
161
|
}
|
162
|
|
163
|
@Test
|
164
|
public void testPublications(){
|
165
|
ICdmApplicationConfiguration services = null;
|
166
|
IpniServicePublicationConfigurator config = null;
|
167
|
List<Reference> refList = service1.getPublications("Species Plantarum, Edition 3", "Sp. Pl.", services, config);
|
168
|
//20009158-1%1.2%Pinaceae%%N%Abies%%N%alba%apennina%subsp.%Brullo, Scelsi & Spamp.%%Brullo, Scelsi & Spamp.%Abies alba subsp. apennina%Vegetaz. Aspromonte%41 (2001)%2001%%%%%%Italy%tax. nov.
|
169
|
|
170
|
if (testInternetConnectivity(refList)){
|
171
|
|
172
|
Assert.assertEquals("There should be exactly 1 result for 'Species Plantarum, Edition 3'", 1, refList.size());
|
173
|
Reference ref = refList.get(0);
|
174
|
//title cache
|
175
|
//the author title may be improved in future
|
176
|
Assert.assertEquals("Title Cache should be 'Linnaeus, Carl, Species Plantarum, Edition 3'", "Linnaeus, Carl, Species Plantarum, Edition 3. 1764", ref.getTitleCache());
|
177
|
|
178
|
|
179
|
refList = service1.getPublications("Flora of Macar", null, services, config);
|
180
|
Assert.assertNotNull("Empty resultset should not throw exception and should not be null", refList);
|
181
|
|
182
|
refList = service1.getPublications("Flora Europaea [ed. 2]", null, services, config);
|
183
|
Assert.assertEquals("There should be exactly 1 result for 'Flora Europaea [ed. 2]'", 1, refList.size());
|
184
|
ref = refList.get(0);
|
185
|
Assert.assertEquals("", "Tutin, Thomas Gaskell", ref.getAuthorship().getTitleCache());
|
186
|
|
187
|
|
188
|
// for (Reference ref : refList){
|
189
|
// System.out.println(ref.getTitleCache());
|
190
|
// }
|
191
|
}
|
192
|
|
193
|
}
|
194
|
|
195
|
@Test
|
196
|
public void testNameID(){
|
197
|
ICdmApplicationConfiguration services = null;
|
198
|
IpniServiceNamesConfigurator config = null;
|
199
|
InputStream content = service1.getNamesById("416415-1");
|
200
|
|
201
|
|
202
|
Assert.assertNotNull(content);
|
203
|
}
|
204
|
|
205
|
|
206
|
/**
|
207
|
* Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#getServiceUrl()}.
|
208
|
*/
|
209
|
@Test
|
210
|
public void testGetServiceUrl() {
|
211
|
Assert.assertNotNull("Service should not be null", service1);
|
212
|
Assert.assertNotNull("URL1 should not be null", service1.getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL));
|
213
|
}
|
214
|
|
215
|
|
216
|
private boolean testInternetConnectivity(List<?> list) {
|
217
|
if (list == null || list.isEmpty()){
|
218
|
boolean result = internetIsAvailable && UriUtils.isInternetAvailable(null);
|
219
|
internetIsAvailable = result;
|
220
|
return result;
|
221
|
|
222
|
}
|
223
|
return true;
|
224
|
}
|
225
|
|
226
|
}
|