4 package eu
.etaxonomy
.cdm
.ext
.ipni
;
6 import java
.io
.InputStream
;
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
.Ignore
;
14 import org
.junit
.Test
;
16 import eu
.etaxonomy
.cdm
.api
.application
.ICdmApplicationConfiguration
;
17 import eu
.etaxonomy
.cdm
.common
.UriUtils
;
18 import eu
.etaxonomy
.cdm
.ext
.ipni
.IIpniService
;
19 import eu
.etaxonomy
.cdm
.ext
.ipni
.IpniService
;
20 import eu
.etaxonomy
.cdm
.ext
.ipni
.IpniServiceAuthorConfigurator
;
21 import eu
.etaxonomy
.cdm
.ext
.ipni
.IpniServiceNamesConfigurator
;
22 import eu
.etaxonomy
.cdm
.ext
.ipni
.IpniServicePublicationConfigurator
;
23 import eu
.etaxonomy
.cdm
.ext
.ipni
.IIpniService
.DelimitedFormat
;
24 import eu
.etaxonomy
.cdm
.ext
.ipni
.IpniService
.IpniRank
;
25 import eu
.etaxonomy
.cdm
.model
.agent
.Person
;
26 import eu
.etaxonomy
.cdm
.model
.common
.Extension
;
27 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
28 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
29 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
36 public class IpniServiceTest
{
37 @SuppressWarnings("unused")
38 private static final Logger logger
= Logger
.getLogger(IpniServiceTest
.class);
40 private IpniService service1
;
41 private static boolean internetIsAvailable
= true;
44 public static void setUpClass() throws Exception
{
45 internetIsAvailable
= true;
51 * @throws java.lang.Exception
54 public void setUp() throws Exception
{
55 service1
= new IpniService();
58 // ******************************* TESTS ******************************************************/
61 * Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#IpniService(java.net.URL)}.
64 public void testIpniService() {
65 Assert
.assertNotNull("Service should not be null", service1
);
66 Assert
.assertNotNull("URL1 should not be null", service1
.getServiceUrl(IIpniService
.ADVANCED_NAME_SERVICE_URL
));
70 public void testGetAuthors(){
71 ICdmApplicationConfiguration services
= null;
72 IpniServiceAuthorConfigurator config
= new IpniServiceAuthorConfigurator();
73 config
.setFormat(DelimitedFormat
.EXTENDED
);
74 List
<Person
> authorList
= service1
.getAuthors(null, "Greuter", null, null, services
, config
);
75 //expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
77 if (testInternetConnectivity(authorList
)){
78 Assert
.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList
.size());
79 Person author
= authorList
.get(0);
81 Assert
.assertEquals("Title Cache for Greuter should be 'Werner Rodolfo Greuter'", "Werner Rodolfo Greuter", author
.getTitleCache());
83 Assert
.assertEquals("One extension for the alternative name should exist", 1, author
.getExtensions().size());
84 Extension alternativeName
= author
.getExtensions().iterator().next();
85 Assert
.assertEquals("Alternative name should be ", "Greuter, Werner Rodolfo", alternativeName
.getValue());
87 String year
= author
.getLifespan().getYear();
88 Assert
.assertNotNull("Year should be not null", year
);
89 Assert
.assertEquals("Year should be 1938", "1938", year
);
91 authorList
= service1
.getAuthors(null, "Greu*", null, null, null, config
);
93 //29367-1%1.1%Greuet%Claude%Greuet%A%%>Greuet, Claude
94 //20000981-1%1.1%Greuning%J.V. van%Greuning%M%1993%>Greuning, J.V. van
95 //3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
96 Assert
.assertEquals("There should be exactly 3 result for 'Greu*'. But maybe this changes over time", 3, authorList
.size());
97 // for (Person person : authorList){
98 // System.out.println(person.getTitleCache() + "; " + person.getNomenclaturalTitle());
101 config
.setFormat(DelimitedFormat
.MINIMAL
);
102 authorList
= service1
.getAuthors(null, "Greuter", null, null, services
, config
);
103 Assert
.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList
.size());
104 author
= authorList
.get(0);
105 Assert
.assertTrue("No alternative names should exist in the minimal version", author
.getExtensions().isEmpty());
111 public void testGetNamesSimple(){
112 ICdmApplicationConfiguration services
= null;
113 IpniServiceNamesConfigurator config
= null;
114 List
<BotanicalName
> nameList
= service1
.getNamesSimple("Abies albertiana", services
, config
);
115 //expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
117 if (testInternetConnectivity(nameList
)){
118 Assert
.assertEquals("There should be exactly 1 result for 'Abies albertiana'", 1, nameList
.size());
119 BotanicalName name
= nameList
.get(0);
121 Assert
.assertEquals("Title Cache for Abies albertiana should be 'Abies albertiana'", "Abies albertiana A.Murr.", name
.getTitleCache());
123 // for (BotanicalName listName : nameList){
124 // System.out.println(name.getFullTitleCache());
131 public void testGetNamesAdvanced(){
132 ICdmApplicationConfiguration services
= null;
133 IpniServiceNamesConfigurator config
= new IpniServiceNamesConfigurator();
135 //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
137 String genus
= "Abies";
138 String species
= "alba";
139 String infraFamily
= "";
140 String infraGenus
= "";
141 String infraSpecies
= "";
142 String authorAbbrev
= "B*";
143 Boolean includePublicationAuthors
= null;
144 Boolean includeBasionymAuthors
= null;
145 String publicationTitle
= "";
146 Boolean isAPNIRecord
= null;
147 Boolean isGCIRecord
= null;
148 Boolean isIKRecord
= null;
149 IpniRank rankToReturn
= IpniRank
.valueOf(Rank
.SUBSPECIES());
150 Boolean sortByFamily
= null;
152 List
<BotanicalName
> nameList
= service1
.getNamesAdvanced(family
, genus
, species
, infraFamily
, infraGenus
, infraSpecies
, authorAbbrev
, includePublicationAuthors
, includeBasionymAuthors
, publicationTitle
, isAPNIRecord
, isGCIRecord
, isIKRecord
, rankToReturn
, sortByFamily
, config
, services
);
153 //expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
156 if (testInternetConnectivity(nameList
)){
158 Assert
.assertEquals("There should be exactly 1 result for 'Abies', 'alba', 'B*', Infraspecific ", 1, nameList
.size());
159 BotanicalName name
= nameList
.get(0);
161 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());
163 // for (BotanicalName listName : nameList){
164 // System.out.println(name.getFullTitleCache());
170 public void testPublications(){
171 ICdmApplicationConfiguration services
= null;
172 IpniServicePublicationConfigurator config
= null;
173 List
<Reference
> refList
= service1
.getPublications("Species Plantarum, Edition 3", "Sp. Pl.", services
, config
);
174 //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.
176 if (testInternetConnectivity(refList
)){
178 Assert
.assertEquals("There should be exactly 1 result for 'Species Plantarum, Edition 3'", 1, refList
.size());
179 Reference ref
= refList
.get(0);
181 //the author title may be improved in future
182 Assert
.assertEquals("Title Cache should be 'Linnaeus, Carl, Species Plantarum, Edition 3'", "Linnaeus, Carl, Species Plantarum, Edition 3. 1764", ref
.getTitleCache());
185 refList
= service1
.getPublications("Flora of Macar", null, services
, config
);
186 Assert
.assertNotNull("Empty resultset should not throw exception and should not be null", refList
);
188 refList
= service1
.getPublications("Flora Europaea [ed. 2]", null, services
, config
);
189 Assert
.assertEquals("There should be exactly 1 result for 'Flora Europaea [ed. 2]'", 1, refList
.size());
190 ref
= refList
.get(0);
191 Assert
.assertEquals("", "Tutin, Thomas Gaskell", ref
.getAuthorTeam().getTitleCache());
194 // for (Reference ref : refList){
195 // System.out.println(ref.getTitleCache());
203 public void testNameID(){
204 ICdmApplicationConfiguration services
= null;
205 IpniServiceNamesConfigurator config
= null;
206 InputStream content
= service1
.getNamesById("416415-1");
209 Assert
.assertNotNull(content
);
214 * Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#getServiceUrl()}.
217 public void testGetServiceUrl() {
218 Assert
.assertNotNull("Service should not be null", service1
);
219 Assert
.assertNotNull("URL1 should not be null", service1
.getServiceUrl(IIpniService
.ADVANCED_NAME_SERVICE_URL
));
223 private boolean testInternetConnectivity(List
<?
> list
) {
224 if (list
== null || list
.isEmpty()){
225 boolean result
= internetIsAvailable
&& UriUtils
.isInternetAvailable(null);
226 internetIsAvailable
= result
;