Project

General

Profile

Download (8.89 KB) Statistics
| Branch: | Tag: | Revision:
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.Ignore;
14
import org.junit.Test;
15

    
16
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
17
import eu.etaxonomy.cdm.common.UriUtils;
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.Reference;
25

    
26
/**
27
 * @author a.mueller
28
 *
29
 */
30
@Ignore
31
public class IpniServiceTest {
32
	@SuppressWarnings("unused")
33
	private static final Logger logger = Logger.getLogger(IpniServiceTest.class);
34

    
35
	private IpniService service1;
36
	private static boolean internetIsAvailable = true;
37

    
38
	@BeforeClass
39
	public static void setUpClass() throws Exception {
40
		internetIsAvailable = true;
41
	}
42

    
43

    
44

    
45
	/**
46
	 * @throws java.lang.Exception
47
	 */
48
	@Before
49
	public void setUp() throws Exception {
50
		service1 = new IpniService();
51
	}
52

    
53
// ******************************* TESTS ******************************************************/
54

    
55
	/**
56
	 * Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#IpniService(java.net.URL)}.
57
	 */
58
	@Test
59
	public void testIpniService() {
60
		Assert.assertNotNull("Service should not be null", service1);
61
		Assert.assertNotNull("URL1 should not be null", service1.getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL));
62
	}
63

    
64
	@Test
65
	public void testGetAuthors(){
66
		ICdmApplicationConfiguration services = null;
67
		IpniServiceAuthorConfigurator config = new IpniServiceAuthorConfigurator();
68
		config.setFormat(DelimitedFormat.EXTENDED);
69
		List<Person> authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
70
		//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
71

    
72
		if (testInternetConnectivity(authorList)){
73
			Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
74
			Person author = authorList.get(0);
75
			//title cache
76
			Assert.assertEquals("Title Cache for Greuter should be 'Werner Rodolfo Greuter'", "Werner Rodolfo Greuter", author.getTitleCache());
77
			//alternative names
78
			Assert.assertEquals("One extension for the alternative name should exist", 1, author.getExtensions().size());
79
			Extension alternativeName = author.getExtensions().iterator().next();
80
			Assert.assertEquals("Alternative name should be ", "Greuter, Werner Rodolfo", alternativeName.getValue());
81
			//dates
82
			String year = author.getLifespan().getYear();
83
			Assert.assertNotNull("Year should be not null", year);
84
			Assert.assertEquals("Year should be 1938", "1938", year);
85

    
86
			authorList = service1.getAuthors(null, "Greu*", null, null, null, config);
87

    
88
			//29367-1%1.1%Greuet%Claude%Greuet%A%%>Greuet, Claude
89
			//20000981-1%1.1%Greuning%J.V. van%Greuning%M%1993%>Greuning, J.V. van
90
			//3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
91
			Assert.assertEquals("There should be exactly 3 result for 'Greu*'. But maybe this changes over time", 3, authorList.size());
92
	//			for (Person person : authorList){
93
	//			System.out.println(person.getTitleCache() + ";  " + person.getNomenclaturalTitle());
94
	//		}
95
	//
96
			config.setFormat(DelimitedFormat.MINIMAL);
97
			authorList = service1.getAuthors(null, "Greuter", null, null, services, config);
98
			Assert.assertEquals("There should be exactly 1 result for 'Greuter'", 1, authorList.size());
99
			author = authorList.get(0);
100
			Assert.assertTrue("No alternative names should exist in the minimal version", author.getExtensions().isEmpty());
101
		}
102
	}
103

    
104

    
105
	@Test
106
	public void testGetNamesSimple(){
107
		ICdmApplicationConfiguration services = null;
108
		IpniServiceNamesConfigurator config = null;
109
		List<BotanicalName> nameList = service1.getNamesSimple("Abies albertiana", services, config);
110
		//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
111

    
112
		if (testInternetConnectivity(nameList)){
113
			Assert.assertEquals("There should be exactly 1 result for 'Abies albertiana'", 1, nameList.size());
114
			BotanicalName name = nameList.get(0);
115
			//title cache
116
			Assert.assertEquals("Title Cache for Abies albertiana should be 'Abies albertiana'", "Abies albertiana A.Murr.", name.getTitleCache());
117

    
118
//			for (BotanicalName listName : nameList){
119
//				System.out.println(name.getFullTitleCache());
120
//			}
121
		}
122

    
123
	}
124

    
125
	@Test
126
	public void testGetNamesAdvanced(){
127
		ICdmApplicationConfiguration services = null;
128
		IpniServiceNamesConfigurator config = new IpniServiceNamesConfigurator();
129

    
130
		//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
131
		String family = "";
132
		String genus = "Abies";
133
		String species = "alba";
134
		String infraFamily = "";
135
		String infraGenus = "";
136
		String infraSpecies = "";
137
		String authorAbbrev = "B*";
138
		Boolean includePublicationAuthors = null;
139
		Boolean includeBasionymAuthors = null;
140
		String publicationTitle = "";
141
		Boolean isAPNIRecord = null;
142
		Boolean isGCIRecord = null;
143
		Boolean isIKRecord = null;
144
		IpniRank rankToReturn = IpniRank.valueOf(Rank.SUBSPECIES());
145
		Boolean sortByFamily = null;
146

    
147
		List<BotanicalName> nameList = service1.getNamesAdvanced(family, genus, species, infraFamily, infraGenus, infraSpecies, authorAbbrev, includePublicationAuthors, includeBasionymAuthors, publicationTitle, isAPNIRecord, isGCIRecord, isIKRecord, rankToReturn, sortByFamily, config, services);
148
		//expected web service result: 3379-1%1.1%Greuter%Werner Rodolfo%Greuter%PS%1938-%>Greuter, Werner Rodolfo
149

    
150

    
151
		if (testInternetConnectivity(nameList)){
152

    
153
			Assert.assertEquals("There should be exactly 1 result for 'Abies', 'alba', 'B*', Infraspecific ", 1, nameList.size());
154
			BotanicalName name = nameList.get(0);
155
			//title cache
156
			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());
157

    
158
	//		for (BotanicalName listName : nameList){
159
	//			System.out.println(name.getFullTitleCache());
160
	//		}
161
		}
162
	}
163

    
164
	@Test
165
	public void testPublications(){
166
		ICdmApplicationConfiguration services = null;
167
		IpniServicePublicationConfigurator config = null;
168
		List<Reference> refList = service1.getPublications("Species Plantarum, Edition 3", "Sp. Pl.", services, config);
169
		//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.
170

    
171
		if (testInternetConnectivity(refList)){
172

    
173
			Assert.assertEquals("There should be exactly 1 result for 'Species Plantarum, Edition 3'", 1, refList.size());
174
			Reference ref = refList.get(0);
175
			//title cache
176
			//the author title may be improved in future
177
			Assert.assertEquals("Title Cache should be 'Linnaeus, Carl, Species Plantarum, Edition 3'", "Linnaeus, Carl, Species Plantarum, Edition 3. 1764", ref.getTitleCache());
178

    
179

    
180
			refList = service1.getPublications("Flora of Macar", null, services, config);
181
			Assert.assertNotNull("Empty resultset should not throw exception and should not be null", refList);
182

    
183
			refList = service1.getPublications("Flora Europaea [ed. 2]", null, services, config);
184
			Assert.assertEquals("There should be exactly 1 result for 'Flora Europaea [ed. 2]'", 1, refList.size());
185
			ref = refList.get(0);
186
			Assert.assertEquals("", "Tutin, Thomas Gaskell", ref.getAuthorship().getTitleCache());
187

    
188

    
189
	//		for (Reference ref : refList){
190
	//			System.out.println(ref.getTitleCache());
191
	//		}
192
		}
193

    
194
	}
195

    
196
	@Test
197
	public void testNameID(){
198
		ICdmApplicationConfiguration services = null;
199
		IpniServiceNamesConfigurator config = null;
200
		InputStream content = service1.getNamesById("416415-1");
201

    
202

    
203
		Assert.assertNotNull(content);
204
	}
205

    
206

    
207
	/**
208
	 * Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#getServiceUrl()}.
209
	 */
210
	@Test
211
	public void testGetServiceUrl() {
212
		Assert.assertNotNull("Service should not be null", service1);
213
		Assert.assertNotNull("URL1 should not be null", service1.getServiceUrl(IIpniService.ADVANCED_NAME_SERVICE_URL));
214
	}
215

    
216

    
217
	private boolean testInternetConnectivity(List<?> list) {
218
		if (list == null || list.isEmpty()){
219
			boolean result = internetIsAvailable && UriUtils.isInternetAvailable(null);
220
			internetIsAvailable = result;
221
			return result;
222

    
223
		}
224
		return true;
225
	}
226

    
227
}
    (1-1/1)