Project

General

Profile

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

    
6
import java.util.List;
7

    
8
import org.apache.log4j.Logger;
9
import org.junit.Assert;
10
import org.junit.Before;
11
import org.junit.BeforeClass;
12
import org.junit.Test;
13

    
14
import eu.etaxonomy.cdm.common.UriUtils;
15

    
16
/**
17
 * @author a.mueller
18
 *
19
 */
20
public class MobotOpenUrlServiceWrapperTest {
21
	public static final Logger logger = Logger.getLogger(MobotOpenUrlServiceWrapperTest.class);
22
	private static final String baseUrl = "http://www.biodiversitylibrary.org/openurl";
23
	
24
	
25
	private MobotOpenUrlServiceWrapper openUrlServiceWrapper;
26
	private static boolean internetIsAvailable = true;
27
	
28
	@BeforeClass
29
	public static void setUpClass() throws Exception {
30
		internetIsAvailable = true;
31
	}
32
	
33
	/**
34
	 * @throws java.lang.Exception
35
	 */
36
	@Before
37
	public void setUp() throws Exception {
38
		openUrlServiceWrapper = new MobotOpenUrlServiceWrapper();
39
		openUrlServiceWrapper.setBaseUrl(baseUrl);
40
	}
41

    
42
// ******************************* TESTS ******************************************************/
43

    
44
	
45
	@Test
46
	//@Ignore // ignore web accessing tests
47
	public void testDoResolveAndPage_1() {
48

    
49
		MobotOpenUrlQuery query  = new MobotOpenUrlQuery();
50
		query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
51
		query.authorFirstName = "Samuel Wendell";
52
		query.authorFirstName = "Williston";
53
		query.publicationDate = "1908";
54
		query.startPage = "Page 16";
55
		
56
		List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
57

    
58
		if (testInternetConnectivity(refList)){
59

    
60
			
61
			// Assert.assertEquals("There should be exactly 2 result for 'Linnaei Species Plantarum Europae'",
62
			// 2, refList.size());
63
			OpenUrlReference reference = refList.get(0);
64
			logger.info(reference.toString());
65
			// title cache
66
			Assert.assertEquals("Manual of North American Diptera /  by Samuel W. Williston.", reference.getTitleCache());
67
			Assert.assertEquals("Page 16", reference.getPages());
68
			
69
			// -------------------------
70
			
71
			try {
72
				refList = openUrlServiceWrapper.doPage(reference, 2);
73
			} catch (Exception e) {
74
				refList = null;
75
			}
76
			Assert.assertNotNull(refList);
77
			OpenUrlReference reference_plus1 = refList.get(0);
78
			logger.info(reference_plus1.toString());
79
			Assert.assertEquals("Manual of North American Diptera /  by Samuel W. Williston.", reference_plus1.getTitleCache());
80
			Assert.assertEquals("Page 18", reference_plus1.getPages());
81
			Assert.assertTrue(reference.getItemUri().equals(reference_plus1.getItemUri()));
82
			Assert.assertTrue(! reference.getUri().equals(reference_plus1.getUri()));
83
			
84
			logger.info(reference_plus1.getJpegImage(null, null));
85
			logger.info(reference_plus1.getJpegImage(400, 600));
86
		}
87
	}
88

    
89
	@Test
90
	public void testDoResolveAndPage_2() {
91

    
92
		MobotOpenUrlQuery query  = new MobotOpenUrlQuery();
93
		query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
94
		query.oclcNumber = "ocm05202749";
95
		
96
		List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
97

    
98
		if (testInternetConnectivity(refList)){
99

    
100
		
101
			// Assert.assertEquals("There should be exactly 2 result for 'Linnaei Species Plantarum Europae'",
102
			// 2, refList.size());
103
			OpenUrlReference reference = refList.get(0);
104
			logger.info(reference.toString());
105
			Assert.assertEquals("1830", reference.getDatePublished().getEndYear().toString());
106
			Assert.assertEquals("1797", reference.getDatePublished().getStartYear().toString()); 
107
		    logger.info(reference.getJpegImage(null, null));
108
		}
109
	}
110
	
111
	@Test
112
	public void testDoResolveAndPage_3() {
113

    
114
		MobotOpenUrlQuery query  = new MobotOpenUrlQuery();
115
		query.refType = MobotOpenUrlServiceWrapper.ReferenceType.book;
116
		query.authorName = "Linné";
117
		query.abbreviation = "Sp. Pl.";
118
		query.publicationDate = "1753";
119
		query.startPage = "813";
120
		
121
		List<OpenUrlReference> refList = openUrlServiceWrapper.doResolve(query);
122

    
123
		if (testInternetConnectivity(refList)){
124

    
125
			Assert.assertTrue("There should be at least one result", refList.size() > 0);
126
			OpenUrlReference reference = refList.get(0);
127
		}
128
	}
129
	
130
	
131
	private boolean testInternetConnectivity(List<?> list) {
132
		if (list == null || list.isEmpty()){
133
			boolean result = internetIsAvailable && UriUtils.isInternetAvailable(null);
134
			internetIsAvailable = result;
135
			return result;
136
			
137
		}
138
		return true;
139
	}
140

    
141
}
    (1-1/1)