d5319af2377a41e8a4ec20a122e66941e60d3cd1
[cdmlib.git] / cdmlib-ext / src / test / java / eu / etaxonomy / cdm / ext / sru / SruServiceWrapperTest.java
1 /**
2 *
3 */
4 package eu.etaxonomy.cdm.ext.sru;
5
6 import java.util.List;
7
8 import org.apache.logging.log4j.LogManager;
9 import org.apache.logging.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.common.UriUtils;
17 import eu.etaxonomy.cdm.ext.dc.DublinCoreSchemaAdapter;
18 import eu.etaxonomy.cdm.model.reference.Reference;
19
20 /**
21 * @author a.mueller
22 *
23 */
24 public class SruServiceWrapperTest {
25 public static final Logger logger = LogManager.getLogger(SruServiceWrapperTest.class);
26
27 private static final String baseUrl = "http://gso.gbv.de/sru/DB=1.83/";
28
29
30 private SruServiceWrapper sruServiceWrapper;
31
32 private static boolean internetIsAvailable = true;
33
34 @BeforeClass
35 public static void setUpClass() throws Exception {
36 internetIsAvailable = true;
37 }
38
39 /**
40 * @throws java.lang.Exception
41 */
42 @Before
43 public void setUp() throws Exception {
44 sruServiceWrapper = new SruServiceWrapper();
45 sruServiceWrapper.setBaseUrl(baseUrl);
46 sruServiceWrapper.addSchemaAdapter(new DublinCoreSchemaAdapter());
47 }
48
49 // ******************************* TESTS ******************************************************/
50
51 @Test
52 @Ignore // ignoring since Global References Index to Biodiversity has problems
53 public void testDoSearchRetrieve(){
54
55 List<Reference> refList_1 = sruServiceWrapper.doSearchRetrieve("pica.tit=\"Linnaei Species Plantarum\"", "dc");
56 // -> http://gso.gbv.de/sru/DB=2.1/?version=1.1&operation=searchRetrieve&query=pica.tit%3D%22Species+Plantarum%22&recordSchema=dc
57
58 if (testInternetConnectivity(refList_1)){
59
60 Assert.assertEquals("There should be exactly 5 results for 'Linnaei Species Plantarum'", 5, refList_1.size());
61 Reference reference_1 = refList_1.get(0);
62 logger.info(reference_1.toString());
63 //title cache
64 Assert.assertEquals("Title of first entry should be 'Caroli Linnaei species plantarum'", "Caroli Linnaei species plantarum", reference_1.getTitleCache());
65
66 //--------------------------
67
68 List<Reference> refList_2 = sruServiceWrapper.doSearchRetrieve("pica.all = \"Species+plantarum\" and pica.dst = \"8305\"", "dc");
69 // -> http://gso.gbv.de/sru/DB=2.1/?version=1.1&operation=searchRetrieve&query=pica.tit%3D%22Species+Plantarum%22&recordSchema=dc
70
71 Assert.assertTrue("There should be at least 1 result for 'species+plantarum' and digitized", refList_2.size() > 0);
72 Reference reference_2 = refList_2.get(0);
73 logger.info(reference_2.toString());
74 }
75 }
76
77 private boolean testInternetConnectivity(List<?> list) {
78 if (list == null || list.isEmpty()){
79 boolean result = internetIsAvailable && UriUtils.isInternetAvailable(null);
80 internetIsAvailable = result;
81 return result;
82
83 }
84 return true;
85 }
86
87
88 }