Project

General

Profile

Download (2.98 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
 *
3
 */
4
package eu.etaxonomy.cdm.ext.sru;
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.Ignore;
13
import org.junit.Test;
14

    
15
import eu.etaxonomy.cdm.common.UriUtils;
16
import eu.etaxonomy.cdm.ext.dc.DublinCoreSchemaAdapter;
17
import eu.etaxonomy.cdm.model.reference.Reference;
18

    
19
/**
20
 * @author a.mueller
21
 *
22
 */
23
public class SruServiceWrapperTest {
24
    public static final Logger logger = Logger.getLogger(SruServiceWrapperTest.class);
25

    
26
    private static final String baseUrl = "http://gso.gbv.de/sru/DB=1.83/";
27

    
28

    
29
    private SruServiceWrapper sruServiceWrapper;
30

    
31
    private static boolean internetIsAvailable = true;
32

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

    
38
    /**
39
     * @throws java.lang.Exception
40
     */
41
    @Before
42
    public void setUp() throws Exception {
43
        sruServiceWrapper = new SruServiceWrapper();
44
        sruServiceWrapper.setBaseUrl(baseUrl);
45
        sruServiceWrapper.addSchemaAdapter(new DublinCoreSchemaAdapter());
46
    }
47

    
48
// ******************************* TESTS ******************************************************/
49

    
50
    @Test
51
    @Ignore // ignoring since Global References Index to Biodiversity has problems
52
    public void testDoSearchRetrieve(){
53

    
54
        List<Reference> refList_1 = sruServiceWrapper.doSearchRetrieve("pica.tit=\"Linnaei Species Plantarum\"", "dc");
55
        // -> http://gso.gbv.de/sru/DB=2.1/?version=1.1&operation=searchRetrieve&query=pica.tit%3D%22Species+Plantarum%22&recordSchema=dc
56

    
57
        if (testInternetConnectivity(refList_1)){
58

    
59
            Assert.assertEquals("There should be exactly 5 results for 'Linnaei Species Plantarum'", 5, refList_1.size());
60
            Reference reference_1 = refList_1.get(0);
61
            logger.info(reference_1.toString());
62
            //title cache
63
            Assert.assertEquals("Title of first entry should be 'Caroli Linnaei species plantarum'", "Caroli Linnaei species plantarum", reference_1.getTitleCache());
64

    
65
            //--------------------------
66

    
67
            List<Reference> refList_2 = sruServiceWrapper.doSearchRetrieve("pica.all = \"Species+plantarum\" and pica.dst = \"8305\"", "dc");
68
            // -> http://gso.gbv.de/sru/DB=2.1/?version=1.1&operation=searchRetrieve&query=pica.tit%3D%22Species+Plantarum%22&recordSchema=dc
69

    
70
            Assert.assertTrue("There should be at least 1 result for 'species+plantarum' and digitized", refList_2.size() > 0);
71
            Reference reference_2 = refList_2.get(0);
72
            logger.info(reference_2.toString());
73
        }
74
    }
75

    
76
    private boolean testInternetConnectivity(List<?> list) {
77
        if (list == null || list.isEmpty()){
78
            boolean result = internetIsAvailable && UriUtils.isInternetAvailable(null);
79
            internetIsAvailable = result;
80
            return result;
81

    
82
        }
83
        return true;
84
    }
85

    
86

    
87
}
    (1-1/1)