Project

General

Profile

Download (5.27 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.cdm.ext.openurl;
5

    
6
import java.net.URI;
7
import java.net.URISyntaxException;
8
import java.util.List;
9

    
10
import org.apache.log4j.Logger;
11
import org.junit.Assert;
12
import org.junit.Before;
13
import org.junit.BeforeClass;
14
import org.junit.Ignore;
15
import org.junit.Test;
16

    
17
import eu.etaxonomy.cdm.common.UriUtils;
18

    
19
/**
20
 * @author a.mueller
21
 *
22
 */
23
public class MobotOpenUrlServiceWrapperTest {
24
	public static final Logger logger = Logger.getLogger(MobotOpenUrlServiceWrapperTest.class);
25
	public static final String baseUrl = "http://www.biodiversitylibrary.org/openurl";
26

    
27

    
28
	private MobotOpenUrlServiceWrapper openUrlServiceWrapper;
29
	private static boolean internetIsAvailable = true;
30

    
31
	@BeforeClass
32
	public static void setUpClass() throws Exception {
33
		internetIsAvailable = true;
34
	}
35

    
36
	/**
37
	 * @throws java.lang.Exception
38
	 */
39
	@Before
40
	public void setUp() throws Exception {
41
		openUrlServiceWrapper = new MobotOpenUrlServiceWrapper();
42
		openUrlServiceWrapper.setBaseUrl(baseUrl);
43
	}
44

    
45
// ******************************* TESTS ******************************************************/
46

    
47

    
48
	@Test
49
	@Ignore
50
	public void testDoResolveAndPage_1() {
51

    
52
	    try {
53
            if(!UriUtils.isServiceAvailable(new URI(baseUrl), 1000)) {
54
                logger.error("Test skipped due to " + baseUrl + " being unavailable");
55
                return;
56
            }
57
        } catch (URISyntaxException e1) {
58
            logger.error(e1);
59
        }
60
		MobotOpenUrlQuery query  = new MobotOpenUrlQuery();
61
		query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
62
		query.authorFirstName = "Samuel Wendell";
63
		query.authorFirstName = "Williston";
64
		query.publicationDate = "1908";
65
		query.startPage = "Page 16";
66

    
67
		List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
68

    
69
		if (testInternetConnectivity(refList)){
70

    
71

    
72
			// Assert.assertEquals("There should be exactly 2 result for 'Linnaei Species Plantarum Europae'",
73
			// 2, refList.size());
74
			OpenUrlReference reference = refList.get(0);
75
			logger.info(reference.toString());
76
			// title cache
77
			Assert.assertEquals("Manual of North American Diptera /", reference.getTitleCache());
78
			// TODO Authorship missing see #6939
79
			// Assert.assertEquals("Williston, Samuel W. (Samuel Wendell),", reference.getAuthorship().getTitleCache());
80
			Assert.assertEquals("Page 16", reference.getPages());
81

    
82
			// -------------------------
83

    
84
			try {
85
				refList = openUrlServiceWrapper.doPage(reference, 2);
86
			} catch (Exception e) {
87
				refList = null;
88
			}
89
			Assert.assertNotNull(refList);
90
			OpenUrlReference reference_plus1 = refList.get(0);
91
			logger.info(reference_plus1.toString());
92
			Assert.assertEquals("Manual of North American Diptera /", reference_plus1.getTitleCache());
93
			Assert.assertEquals("Page 18", reference_plus1.getPages());
94
			Assert.assertTrue(reference.getItemUri().equals(reference_plus1.getItemUri()));
95
			Assert.assertTrue(! reference.getUri().equals(reference_plus1.getUri()));
96

    
97
			logger.info(reference_plus1.getJpegImage(null, null));
98
			logger.info(reference_plus1.getJpegImage(400, 600));
99
		}
100
	}
101

    
102
	@Test
103
	@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)
104
	public void testDoResolveAndPage_2() {
105

    
106

    
107
	    try {
108
            if(!UriUtils.isServiceAvailable(new URI(baseUrl), 1000)) {
109
                logger.error("Test skipped due to " + baseUrl + " being unavailable");
110
                return;
111
            }
112
        } catch (URISyntaxException e1) {
113
            logger.error(e1);
114
        }
115
		MobotOpenUrlQuery query  = new MobotOpenUrlQuery();
116
		query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
117
		query.oclcNumber = "ocm05202749";
118

    
119
		List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
120

    
121
		if (testInternetConnectivity(refList)){
122

    
123

    
124
			// Assert.assertEquals("There should be exactly 2 result for 'Linnaei Species Plantarum Europae'",
125
			// 2, refList.size());
126
			OpenUrlReference reference = refList.get(0);
127
			logger.info(reference.toString());
128
			Assert.assertEquals("1830", reference.getDatePublished().getEndYear().toString());
129
			Assert.assertEquals("1797", reference.getDatePublished().getStartYear().toString());
130
		    logger.info(reference.getJpegImage(null, null));
131
		}
132
	}
133

    
134
	@Test
135
	public void testDoResolveAndPage_3() {
136

    
137
	    try {
138
            if(!UriUtils.isServiceAvailable(new URI(baseUrl), 1000)) {
139
                logger.error("Test skipped due to " + baseUrl + " being unavailable");
140
                return;
141
            }
142
        } catch (URISyntaxException e1) {
143
            logger.error(e1);
144
        }
145
		MobotOpenUrlQuery query  = new MobotOpenUrlQuery();
146
		query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
147
		query.authorName = "Linn\u00E9"; //Linné
148
		query.abbreviation = "Sp. Pl.";
149
		query.publicationDate = "1753";
150
		query.startPage = "813";
151

    
152
		List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
153

    
154
		if (testInternetConnectivity(refList)){
155

    
156
			Assert.assertTrue("There should be at least one result", refList.size() > 0);
157
			OpenUrlReference reference = refList.get(0);
158
		}
159
	}
160

    
161

    
162
	private boolean testInternetConnectivity(List<?> list) {
163
		if (list == null || list.isEmpty()){
164
			boolean result = internetIsAvailable && UriUtils.isInternetAvailable(null);
165
			internetIsAvailable = result;
166
			return result;
167

    
168
		}
169
		return true;
170
	}
171

    
172
}
    (1-1/1)