eb0c5701358a1faa2a286596ff6606457ad2fc19
[cdmlib.git] / cdmlib-ext / src / test / java / eu / etaxonomy / cdm / ext / ipni / IpniServiceTest.java
1 /**
2 *
3 */
4 package eu.etaxonomy.cdm.ext.ipni;
5
6 import java.util.List;
7
8 import org.junit.Assert;
9 import org.junit.Before;
10 import org.junit.Test;
11
12 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
13 import eu.etaxonomy.cdm.ext.ipni.IIpniService;
14 import eu.etaxonomy.cdm.ext.ipni.IpniService;
15 import eu.etaxonomy.cdm.ext.ipni.IpniServiceAuthorConfigurator;
16 import eu.etaxonomy.cdm.ext.ipni.IpniServiceNamesConfigurator;
17 import eu.etaxonomy.cdm.ext.ipni.IpniServicePublicationConfigurator;
18 import eu.etaxonomy.cdm.ext.ipni.IIpniService.DelimitedFormat;
19 import eu.etaxonomy.cdm.ext.ipni.IpniService.IpniRank;
20 import eu.etaxonomy.cdm.model.agent.Person;
21 import eu.etaxonomy.cdm.model.common.Extension;
22 import eu.etaxonomy.cdm.model.name.BotanicalName;
23 import eu.etaxonomy.cdm.model.name.Rank;
24 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
25
26 /**
27 * @author a.mueller
28 *
29 */
30 public class IpniServiceTest {
31
32 static String strUrl1;
33
34 private IpniService service1;
35
36 /**
37 * @throws java.lang.Exception
38 */
39 @Before
40 public void setUp() throws Exception {
41 service1 = new IpniService();
42 }
43
44 // ******************************* TESTS ******************************************************/
45
46 /**
47 * Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#IpniService(java.net.URL)}.
48 */
49 @Test
50 public void testIpniService() {
51 Assert.assertNotNull("Service should not be null", service1);
52 Assert.assertNotNull("URL1 should not be null", service1.getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL));
53 }
54
55 @Test
56 public void testGetAuthors(){
57 ICdmApplicationConfiguration services = null;
58 IpniServiceAuthorConfigurator config = new IpniServiceAuthorConfigurator();
59 config.setFormat(DelimitedFormat.EXTENDED);
60 List<Person> authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
61 //expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
62
63 Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
64 Person author = authorList.get(0);
65 //title cache
66 Assert.assertEquals("Title Cache for Greuter should be 'Werner Rodolfo Greuter'", "Werner Rodolfo Greuter", author.getTitleCache());
67 //alternative names
68 Assert.assertEquals("One extension for the alternative name should exist", 1, author.getExtensions().size());
69 Extension alternativeName = author.getExtensions().iterator().next();
70 Assert.assertEquals("Alternative name should be ", "Greuter, Werner Rodolfo", alternativeName.getValue());
71 //dates
72 String year = author.getLifespan().getYear();
73 Assert.assertNotNull("Year should be not null", year);
74 Assert.assertEquals("Year should be 1938", "1938", year);
75
76 authorList = service1.getAuthors(null, "Greu*", null, null, null, config);
77 //29367-1%1.1%Greuet%Claude%Greuet%A%%>Greuet, Claude
78 //20000981-1%1.1%Greuning%J.V. van%Greuning%M%1993%>Greuning, J.V. van
79 //3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
80 Assert.assertEquals("There should be exactly 3 result for 'Greu*'. But maybe this changes over time", 3, authorList.size());
81
82
83 // for (Person person : authorList){
84 // System.out.println(person.getTitleCache() + "; " + person.getNomenclaturalTitle());
85 // }
86 //
87 config.setFormat(DelimitedFormat.MINIMAL);
88 authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
89 Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
90 author = authorList.get(0);
91 Assert.assertTrue("No alternative names should exist in the minimal version", author.getExtensions().isEmpty());
92
93
94 }
95
96 @Test
97 public void testGetNamesSimple(){
98 ICdmApplicationConfiguration services = null;
99 IpniServiceNamesConfigurator config = null;
100 List<BotanicalName> nameList = service1.getNamesSimple("Abies albertiana", services, config);
101 //expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
102
103 Assert.assertEquals("There should be exactly 1 result for 'Abies albertiana'", 1, nameList.size());
104 BotanicalName name = nameList.get(0);
105 //title cache
106 Assert.assertEquals("Title Cache for Abies albertiana should be 'Abies albertiana'", "Abies albertiana A.Murr.", name.getTitleCache());
107
108 // for (BotanicalName listName : nameList){
109 // System.out.println(name.getFullTitleCache());
110 // }
111
112 }
113
114 @Test
115 public void testGetNamesAdvanced(){
116 ICdmApplicationConfiguration services = null;
117 IpniServiceNamesConfigurator config = new IpniServiceNamesConfigurator();
118
119 //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
120 String family = "";
121 String genus = "Abies";
122 String species = "alba";
123 String infraFamily = "";
124 String infraGenus = "";
125 String infraSpecies = "";
126 String authorAbbrev = "B*";
127 Boolean includePublicationAuthors = null;
128 Boolean includeBasionymAuthors = null;
129 String publicationTitle = "";
130 Boolean isAPNIRecord = null;
131 Boolean isGCIRecord = null;
132 Boolean isIKRecord = null;
133 IpniRank rankToReturn = IpniRank.valueOf(Rank.SUBSPECIES());
134 Boolean sortByFamily = null;
135
136 List<BotanicalName> nameList = service1.getNamesAdvanced(family, genus, species, infraFamily, infraGenus, infraSpecies, authorAbbrev, includePublicationAuthors, includeBasionymAuthors, publicationTitle, isAPNIRecord, isGCIRecord, isIKRecord, rankToReturn, sortByFamily, config, services);
137 //expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
138
139 Assert.assertEquals("There should be exactly 1 result for 'Abies', 'alba', 'B*', Infraspecific ", 1, nameList.size());
140 BotanicalName name = nameList.get(0);
141 //title cache
142 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());
143
144 // for (BotanicalName listName : nameList){
145 // System.out.println(name.getFullTitleCache());
146 // }
147
148 }
149
150 @Test
151 public void testPublications(){
152 ICdmApplicationConfiguration services = null;
153 IpniServicePublicationConfigurator config = null;
154 List<ReferenceBase> refList = service1.getPublications("Species Plantarum, Edition 3", "Sp. Pl.", services, config);
155 //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.
156
157 Assert.assertEquals("There should be exactly 1 result for 'Species Plantarum, Edition 3'", 1, refList.size());
158 ReferenceBase name = refList.get(0);
159 //title cache
160 Assert.assertEquals("Title Cache for Abies albertiana should be 'Species Plantarum, Edition 3'", "Species Plantarum, Edition 3. 1764", name.getTitleCache());
161
162 // for (ReferenceBase ref : refList){
163 // System.out.println(ref.getTitleCache());
164 // }
165
166 }
167
168 /**
169 * Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#getServiceUrl()}.
170 */
171 @Test
172 public void testGetServiceUrl() {
173 Assert.assertNotNull("Service should not be null", service1);
174 Assert.assertNotNull("URL1 should not be null", service1.getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL));
175 }
176
177
178 }