1
|
/**
|
2
|
* Copyright (C) 2013 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.ext.openurl;
|
10
|
|
11
|
import java.net.URISyntaxException;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.junit.Assert;
|
16
|
import org.junit.Before;
|
17
|
import org.junit.BeforeClass;
|
18
|
import org.junit.Ignore;
|
19
|
import org.junit.Test;
|
20
|
|
21
|
import eu.etaxonomy.cdm.common.URI;
|
22
|
import eu.etaxonomy.cdm.common.UriUtils;
|
23
|
|
24
|
/**
|
25
|
* @author a.mueller
|
26
|
*/
|
27
|
public class MobotOpenUrlServiceWrapperTest {
|
28
|
|
29
|
public static final Logger logger = Logger.getLogger(MobotOpenUrlServiceWrapperTest.class);
|
30
|
public static final String baseUrl = "http://www.biodiversitylibrary.org/openurl";
|
31
|
|
32
|
private MobotOpenUrlServiceWrapper openUrlServiceWrapper;
|
33
|
private static boolean internetIsAvailable = true;
|
34
|
|
35
|
@BeforeClass
|
36
|
public static void setUpClass() throws Exception {
|
37
|
internetIsAvailable = true;
|
38
|
}
|
39
|
|
40
|
@Before
|
41
|
public void setUp() throws Exception {
|
42
|
openUrlServiceWrapper = new MobotOpenUrlServiceWrapper();
|
43
|
openUrlServiceWrapper.setBaseUrl(baseUrl);
|
44
|
}
|
45
|
|
46
|
// ******************************* TESTS ******************************************************/
|
47
|
|
48
|
@Test
|
49
|
public void testDoResolveAndPage_1() {
|
50
|
|
51
|
try {
|
52
|
if(!UriUtils.isServiceAvailable(new URI(baseUrl), 1000)) {
|
53
|
logger.error("Test skipped due to " + baseUrl + " being unavailable");
|
54
|
return;
|
55
|
}
|
56
|
} catch (URISyntaxException e1) {
|
57
|
logger.error(e1);
|
58
|
}
|
59
|
MobotOpenUrlQuery query = new MobotOpenUrlQuery();
|
60
|
query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
|
61
|
query.authorFirstName = "Samuel Wendell";
|
62
|
query.authorFirstName = "Williston";
|
63
|
query.publicationDate = "1908";
|
64
|
query.startPage = "Page 16";
|
65
|
|
66
|
List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
|
67
|
|
68
|
if (testInternetConnectivity(refList)){
|
69
|
|
70
|
// Assert.assertEquals("There should be exactly 2 result for 'Linnaei Species Plantarum Europae'",
|
71
|
// 2, refList.size());
|
72
|
OpenUrlReference reference = refList.get(0);
|
73
|
logger.info(reference.toString());
|
74
|
// title cache
|
75
|
Assert.assertEquals("Manual of North American Diptera", reference.getTitleCache());
|
76
|
// TODO Authorship missing see #6939
|
77
|
// Assert.assertEquals("Williston, Samuel W. (Samuel Wendell),", reference.getAuthorship().getTitleCache());
|
78
|
Assert.assertEquals("Page 16", reference.getPages());
|
79
|
|
80
|
// -------------------------
|
81
|
|
82
|
try {
|
83
|
refList = openUrlServiceWrapper.doPage(reference, 2);
|
84
|
} catch (Exception e) {
|
85
|
refList = null;
|
86
|
}
|
87
|
Assert.assertNotNull(refList);
|
88
|
OpenUrlReference reference_plus1 = refList.get(0);
|
89
|
logger.info(reference_plus1.toString());
|
90
|
Assert.assertEquals("Manual of North American Diptera", reference_plus1.getTitleCache());
|
91
|
Assert.assertEquals("Page 18", reference_plus1.getPages());
|
92
|
Assert.assertTrue(reference.getItemUri().equals(reference_plus1.getItemUri()));
|
93
|
Assert.assertTrue(! reference.getUri().equals(reference_plus1.getUri()));
|
94
|
|
95
|
logger.info(reference_plus1.getJpegImage(null, null));
|
96
|
logger.info(reference_plus1.getJpegImage(400, 600));
|
97
|
}
|
98
|
}
|
99
|
|
100
|
@Test
|
101
|
@Ignore // it seems as if oclc number are no longer supported by the api. Email send to mobot to clarify (a.kohlbecker 2016-07-11)
|
102
|
public void testDoResolveAndPage_2() {
|
103
|
|
104
|
try {
|
105
|
if(!UriUtils.isServiceAvailable(new URI(baseUrl), 1000)) {
|
106
|
logger.error("Test skipped due to " + baseUrl + " being unavailable");
|
107
|
return;
|
108
|
}
|
109
|
} catch (URISyntaxException e1) {
|
110
|
logger.error(e1);
|
111
|
}
|
112
|
MobotOpenUrlQuery query = new MobotOpenUrlQuery();
|
113
|
query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
|
114
|
query.oclcNumber = "ocm05202749";
|
115
|
|
116
|
List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
|
117
|
|
118
|
if (testInternetConnectivity(refList)){
|
119
|
|
120
|
// Assert.assertEquals("There should be exactly 2 result for 'Linnaei Species Plantarum Europae'",
|
121
|
// 2, refList.size());
|
122
|
OpenUrlReference reference = refList.get(0);
|
123
|
logger.info(reference.toString());
|
124
|
Assert.assertEquals("1830", reference.getDatePublished().getEndYear().toString());
|
125
|
Assert.assertEquals("1797", reference.getDatePublished().getStartYear().toString());
|
126
|
logger.info(reference.getJpegImage(null, null));
|
127
|
}
|
128
|
}
|
129
|
|
130
|
@Test
|
131
|
public void testDoResolveAndPage_3() {
|
132
|
|
133
|
try {
|
134
|
if(!UriUtils.isServiceAvailable(new URI(baseUrl), 1000)) {
|
135
|
logger.error("Test skipped due to " + baseUrl + " being unavailable");
|
136
|
return;
|
137
|
}
|
138
|
} catch (URISyntaxException e1) {
|
139
|
logger.error(e1);
|
140
|
}
|
141
|
MobotOpenUrlQuery query = new MobotOpenUrlQuery();
|
142
|
query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
|
143
|
query.authorName = "Linn\u00E9"; //Linné
|
144
|
query.abbreviation = "Sp. Pl.";
|
145
|
query.publicationDate = "1753";
|
146
|
query.startPage = "813";
|
147
|
|
148
|
List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
|
149
|
if (testInternetConnectivity(refList)){
|
150
|
Assert.assertTrue("There should be at least one result", refList.size() > 0);
|
151
|
OpenUrlReference reference = refList.get(0);
|
152
|
}
|
153
|
}
|
154
|
|
155
|
private boolean testInternetConnectivity(List<?> list) {
|
156
|
if (list == null || list.isEmpty()){
|
157
|
boolean result = internetIsAvailable && UriUtils.isInternetAvailable(null);
|
158
|
internetIsAvailable = result;
|
159
|
return result;
|
160
|
}
|
161
|
return true;
|
162
|
}
|
163
|
}
|