1 |
445950fe
|
Andreas Müller
|
/**
|
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 |
7cdc874a
|
Katja Luther
|
import org.unitils.dbunit.annotation.DataSet;
|
15 |
|
|
import org.unitils.dbunit.annotation.DataSets;
|
16 |
445950fe
|
Andreas Müller
|
|
17 |
41356809
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
18 |
445950fe
|
Andreas Müller
|
import eu.etaxonomy.cdm.common.UriUtils;
|
19 |
|
|
import eu.etaxonomy.cdm.ext.ipni.IIpniService.DelimitedFormat;
|
20 |
|
|
import eu.etaxonomy.cdm.ext.ipni.IpniService.IpniRank;
|
21 |
|
|
import eu.etaxonomy.cdm.model.agent.Person;
|
22 |
913eceea
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
|
23 |
445950fe
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.Extension;
|
24 |
d7919b1c
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.IBotanicalName;
|
25 |
445950fe
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26 |
|
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
27 |
7cdc874a
|
Katja Luther
|
import eu.etaxonomy.cdm.test.unitils.CleanSweepInsertLoadStrategy;
|
28 |
445950fe
|
Andreas Müller
|
|
29 |
|
|
/**
|
30 |
|
|
* @author a.mueller
|
31 |
|
|
*
|
32 |
|
|
*/
|
33 |
88b16247
|
Andreas Müller
|
//@Ignore
|
34 |
445950fe
|
Andreas Müller
|
public class IpniServiceTest {
|
35 |
|
|
@SuppressWarnings("unused")
|
36 |
|
|
private static final Logger logger = Logger.getLogger(IpniServiceTest.class);
|
37 |
|
|
|
38 |
|
|
private IpniService service1;
|
39 |
|
|
private static boolean internetIsAvailable = true;
|
40 |
|
|
|
41 |
|
|
@BeforeClass
|
42 |
|
|
public static void setUpClass() throws Exception {
|
43 |
|
|
internetIsAvailable = true;
|
44 |
913eceea
|
Andreas Müller
|
//for standalone
|
45 |
|
|
if (Rank.SUBSPECIES() == null){
|
46 |
|
|
DefaultTermInitializer termInit = new DefaultTermInitializer();
|
47 |
|
|
termInit.initialize();
|
48 |
|
|
}
|
49 |
445950fe
|
Andreas Müller
|
}
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
|
|
/**
|
54 |
|
|
* @throws java.lang.Exception
|
55 |
|
|
*/
|
56 |
|
|
@Before
|
57 |
|
|
public void setUp() throws Exception {
|
58 |
d5020a07
|
Andreas Kohlbecker
|
service1 = new IpniService();
|
59 |
445950fe
|
Andreas Müller
|
}
|
60 |
|
|
|
61 |
|
|
// ******************************* TESTS ******************************************************/
|
62 |
|
|
|
63 |
|
|
/**
|
64 |
|
|
* Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#IpniService(java.net.URL)}.
|
65 |
|
|
*/
|
66 |
|
|
@Test
|
67 |
|
|
public void testIpniService() {
|
68 |
|
|
Assert.assertNotNull("Service should not be null", service1);
|
69 |
|
|
Assert.assertNotNull("URL1 should not be null", service1.getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL));
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
@Test
|
73 |
7cdc874a
|
Katja Luther
|
@DataSets({
|
74 |
|
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
75 |
|
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
76 |
|
|
})
|
77 |
445950fe
|
Andreas Müller
|
public void testGetAuthors(){
|
78 |
41356809
|
Andreas Kohlbecker
|
ICdmRepository services = null;
|
79 |
445950fe
|
Andreas Müller
|
IpniServiceAuthorConfigurator config = new IpniServiceAuthorConfigurator();
|
80 |
|
|
config.setFormat(DelimitedFormat.EXTENDED);
|
81 |
|
|
List<Person> authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
|
82 |
7cdc874a
|
Katja Luther
|
//List<Person> authorList = service1.getAuthors(null, "Greu*", null, null, null, config);
|
83 |
445950fe
|
Andreas Müller
|
//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
|
84 |
7cdc874a
|
Katja Luther
|
if(authorList == null){
|
85 |
|
|
Assert.fail("No results.");
|
86 |
|
|
}
|
87 |
445950fe
|
Andreas Müller
|
if (testInternetConnectivity(authorList)){
|
88 |
7cdc874a
|
Katja Luther
|
|
89 |
445950fe
|
Andreas Müller
|
Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
|
90 |
|
|
Person author = authorList.get(0);
|
91 |
74081bf8
|
Andreas Müller
|
//full title
|
92 |
|
|
Assert.assertEquals("Full title for Greuter should be 'Werner Rodolfo Greuter'", "Werner Rodolfo Greuter", author.getFullTitle());
|
93 |
|
|
//title cache
|
94 |
|
|
Assert.assertEquals("Title cache for Greuter should be 'Greuter, W.R.'", "Greuter, W.R.", author.getTitleCache());
|
95 |
445950fe
|
Andreas Müller
|
//alternative names
|
96 |
|
|
Assert.assertEquals("One extension for the alternative name should exist", 1, author.getExtensions().size());
|
97 |
|
|
Extension alternativeName = author.getExtensions().iterator().next();
|
98 |
|
|
Assert.assertEquals("Alternative name should be ", "Greuter, Werner Rodolfo", alternativeName.getValue());
|
99 |
|
|
//dates
|
100 |
|
|
String year = author.getLifespan().getYear();
|
101 |
|
|
Assert.assertNotNull("Year should be not null", year);
|
102 |
|
|
Assert.assertEquals("Year should be 1938", "1938", year);
|
103 |
|
|
|
104 |
|
|
authorList = service1.getAuthors(null, "Greu*", null, null, null, config);
|
105 |
|
|
|
106 |
|
|
//29367-1%1.1%Greuet%Claude%Greuet%A%%>Greuet, Claude
|
107 |
|
|
//20000981-1%1.1%Greuning%J.V. van%Greuning%M%1993%>Greuning, J.V. van
|
108 |
|
|
//3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
|
109 |
7cdc874a
|
Katja Luther
|
if(authorList == null){
|
110 |
|
|
Assert.fail("No results.");
|
111 |
|
|
}else{
|
112 |
|
|
Assert.assertEquals("There should be exactly 3 result for 'Greu*'. But maybe this changes over time", 3, authorList.size());
|
113 |
|
|
}
|
114 |
445950fe
|
Andreas Müller
|
// for (Person person : authorList){
|
115 |
|
|
// System.out.println(person.getTitleCache() + "; " + person.getNomenclaturalTitle());
|
116 |
|
|
// }
|
117 |
|
|
//
|
118 |
|
|
config.setFormat(DelimitedFormat.MINIMAL);
|
119 |
|
|
authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
|
120 |
|
|
Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
|
121 |
|
|
author = authorList.get(0);
|
122 |
|
|
Assert.assertTrue("No alternative names should exist in the minimal version", author.getExtensions().isEmpty());
|
123 |
|
|
}
|
124 |
|
|
}
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
@Test
|
128 |
7cdc874a
|
Katja Luther
|
@DataSets({
|
129 |
|
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
130 |
|
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
131 |
|
|
})
|
132 |
445950fe
|
Andreas Müller
|
public void testGetNamesSimple(){
|
133 |
41356809
|
Andreas Kohlbecker
|
ICdmRepository services = null;
|
134 |
445950fe
|
Andreas Müller
|
IpniServiceNamesConfigurator config = null;
|
135 |
6ecf5e6f
|
Andreas Müller
|
List<IBotanicalName> nameList = service1.getNamesSimple("Abies albertiana", services, config);
|
136 |
445950fe
|
Andreas Müller
|
//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
|
137 |
|
|
|
138 |
|
|
if (testInternetConnectivity(nameList)){
|
139 |
7cdc874a
|
Katja Luther
|
if(nameList == null){
|
140 |
|
|
Assert.fail("No results.");
|
141 |
|
|
}
|
142 |
445950fe
|
Andreas Müller
|
Assert.assertEquals("There should be exactly 1 result for 'Abies albertiana'", 1, nameList.size());
|
143 |
d7919b1c
|
Andreas Müller
|
IBotanicalName name = nameList.get(0);
|
144 |
445950fe
|
Andreas Müller
|
//title cache
|
145 |
c38ba443
|
Katja Luther
|
Assert.assertEquals("Title Cache for Abies albertiana should be 'Abies albertiana'", "Abies albertiana A.Murray bis", name.getTitleCache());
|
146 |
445950fe
|
Andreas Müller
|
|
147 |
d7919b1c
|
Andreas Müller
|
// for (IBotanicalName listName : nameList){
|
148 |
445950fe
|
Andreas Müller
|
// System.out.println(name.getFullTitleCache());
|
149 |
|
|
// }
|
150 |
|
|
}
|
151 |
|
|
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
@Test
|
155 |
7cdc874a
|
Katja Luther
|
@DataSets({
|
156 |
|
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
157 |
|
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
158 |
|
|
})
|
159 |
445950fe
|
Andreas Müller
|
public void testGetNamesAdvanced(){
|
160 |
41356809
|
Andreas Kohlbecker
|
ICdmRepository services = null;
|
161 |
43b500aa
|
Andreas Müller
|
IpniServiceNamesConfigurator config = IpniServiceNamesConfigurator.NewInstance();
|
162 |
445950fe
|
Andreas Müller
|
|
163 |
|
|
//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
|
164 |
|
|
String family = "";
|
165 |
|
|
String genus = "Abies";
|
166 |
|
|
String species = "alba";
|
167 |
|
|
String infraFamily = "";
|
168 |
|
|
String infraGenus = "";
|
169 |
|
|
String infraSpecies = "";
|
170 |
|
|
String authorAbbrev = "B*";
|
171 |
|
|
String publicationTitle = "";
|
172 |
|
|
IpniRank rankToReturn = IpniRank.valueOf(Rank.SUBSPECIES());
|
173 |
|
|
|
174 |
e6d7b501
|
Andreas Müller
|
List<IBotanicalName> nameList = service1.getNamesAdvanced(family, genus, species, infraFamily, infraGenus, infraSpecies, authorAbbrev, publicationTitle, rankToReturn, config, services);
|
175 |
445950fe
|
Andreas Müller
|
//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
|
176 |
|
|
|
177 |
|
|
|
178 |
|
|
if (testInternetConnectivity(nameList)){
|
179 |
7cdc874a
|
Katja Luther
|
if(nameList == null){
|
180 |
|
|
Assert.fail("No results.");
|
181 |
|
|
}
|
182 |
445950fe
|
Andreas Müller
|
Assert.assertEquals("There should be exactly 1 result for 'Abies', 'alba', 'B*', Infraspecific ", 1, nameList.size());
|
183 |
d7919b1c
|
Andreas Müller
|
IBotanicalName name = nameList.get(0);
|
184 |
445950fe
|
Andreas Müller
|
//title cache
|
185 |
|
|
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());
|
186 |
|
|
|
187 |
d7919b1c
|
Andreas Müller
|
// for (IBotanicalName listName : nameList){
|
188 |
445950fe
|
Andreas Müller
|
// System.out.println(name.getFullTitleCache());
|
189 |
|
|
// }
|
190 |
|
|
}
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
@Test
|
194 |
7cdc874a
|
Katja Luther
|
@DataSets({
|
195 |
|
|
@DataSet(loadStrategy=CleanSweepInsertLoadStrategy.class, value="/eu/etaxonomy/cdm/database/ClearDB_with_Terms_DataSet.xml"),
|
196 |
|
|
@DataSet(value="/eu/etaxonomy/cdm/database/TermsDataSet-with_auditing_info.xml")
|
197 |
|
|
})
|
198 |
445950fe
|
Andreas Müller
|
public void testPublications(){
|
199 |
41356809
|
Andreas Kohlbecker
|
ICdmRepository services = null;
|
200 |
445950fe
|
Andreas Müller
|
IpniServicePublicationConfigurator config = null;
|
201 |
|
|
List<Reference> refList = service1.getPublications("Species Plantarum, Edition 3", "Sp. Pl.", services, config);
|
202 |
|
|
//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.
|
203 |
|
|
|
204 |
|
|
if (testInternetConnectivity(refList)){
|
205 |
7cdc874a
|
Katja Luther
|
if (refList == null){
|
206 |
|
|
Assert.fail("The list is empty, maybe the ipni service is not available.");
|
207 |
|
|
}
|
208 |
445950fe
|
Andreas Müller
|
Assert.assertEquals("There should be exactly 1 result for 'Species Plantarum, Edition 3'", 1, refList.size());
|
209 |
|
|
Reference ref = refList.get(0);
|
210 |
|
|
//title cache
|
211 |
|
|
//the author title may be improved in future
|
212 |
|
|
Assert.assertEquals("Title Cache should be 'Linnaeus, Carl, Species Plantarum, Edition 3'", "Linnaeus, Carl, Species Plantarum, Edition 3. 1764", ref.getTitleCache());
|
213 |
|
|
|
214 |
|
|
|
215 |
|
|
refList = service1.getPublications("Flora of Macar", null, services, config);
|
216 |
7cdc874a
|
Katja Luther
|
if (refList == null){
|
217 |
|
|
Assert.fail("The list is empty, maybe the ipni service is not available.");
|
218 |
|
|
}
|
219 |
445950fe
|
Andreas Müller
|
Assert.assertNotNull("Empty resultset should not throw exception and should not be null", refList);
|
220 |
|
|
|
221 |
|
|
refList = service1.getPublications("Flora Europaea [ed. 2]", null, services, config);
|
222 |
7cdc874a
|
Katja Luther
|
if (refList == null){
|
223 |
|
|
Assert.fail("The list is empty, maybe the ipni service is not available.");
|
224 |
|
|
}
|
225 |
445950fe
|
Andreas Müller
|
Assert.assertEquals("There should be exactly 1 result for 'Flora Europaea [ed. 2]'", 1, refList.size());
|
226 |
|
|
ref = refList.get(0);
|
227 |
|
|
Assert.assertEquals("", "Tutin, Thomas Gaskell", ref.getAuthorship().getTitleCache());
|
228 |
|
|
|
229 |
|
|
|
230 |
|
|
// for (Reference ref : refList){
|
231 |
|
|
// System.out.println(ref.getTitleCache());
|
232 |
|
|
// }
|
233 |
|
|
}
|
234 |
|
|
|
235 |
|
|
}
|
236 |
|
|
|
237 |
|
|
@Test
|
238 |
|
|
public void testNameID(){
|
239 |
41356809
|
Andreas Kohlbecker
|
ICdmRepository services = null;
|
240 |
445950fe
|
Andreas Müller
|
IpniServiceNamesConfigurator config = null;
|
241 |
|
|
InputStream content = service1.getNamesById("416415-1");
|
242 |
|
|
|
243 |
|
|
|
244 |
|
|
Assert.assertNotNull(content);
|
245 |
|
|
}
|
246 |
|
|
|
247 |
|
|
|
248 |
|
|
/**
|
249 |
|
|
* Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#getServiceUrl()}.
|
250 |
|
|
*/
|
251 |
|
|
@Test
|
252 |
|
|
public void testGetServiceUrl() {
|
253 |
|
|
Assert.assertNotNull("Service should not be null", service1);
|
254 |
|
|
Assert.assertNotNull("URL1 should not be null", service1.getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL));
|
255 |
|
|
}
|
256 |
|
|
|
257 |
|
|
|
258 |
|
|
private boolean testInternetConnectivity(List<?> list) {
|
259 |
|
|
if (list == null || list.isEmpty()){
|
260 |
|
|
boolean result = internetIsAvailable && UriUtils.isInternetAvailable(null);
|
261 |
|
|
internetIsAvailable = result;
|
262 |
|
|
return result;
|
263 |
|
|
|
264 |
|
|
}
|
265 |
|
|
return true;
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
}
|