Project

General

Profile

« Previous | Next » 

Revision 5c6cfa03

Added by Andreas Müller almost 7 years ago

Fix Gbif test

View differences:

cdmlib-ext/src/test/java/eu/etaxonomy/cdm/ext/occurrence/gbif/GbifQueryServiceWrapperTest.java
19 19
import org.apache.http.NameValuePair;
20 20
import org.apache.http.client.ClientProtocolException;
21 21
import org.apache.http.message.BasicNameValuePair;
22
import org.junit.Assert;
22 23
import org.junit.Ignore;
23 24
import org.junit.Test;
24 25

  
25 26
import eu.etaxonomy.cdm.ext.occurrence.OccurenceQuery;
26
import junit.framework.TestCase;
27 27

  
28 28
/**
29 29
 * @author pplitzner
30 30
 * @date 20.05.2014
31 31
 *
32 32
 */
33
public class GbifQueryServiceWrapperTest extends TestCase{
33
public class GbifQueryServiceWrapperTest {
34 34

  
35 35
    private static final String LOCALITY_STRING = "Saddington Reservoir, Saddington Reservoir";
36 36

  
......
97 97
    @Test
98 98
    public void testJsonToCdmObject() throws URISyntaxException{
99 99
        Collection<GbifResponse> records = GbifJsonOccurrenceParser.parseJsonRecords(dummyJsonRecords);
100
        assertEquals("number of records found is incorrect", 1, records.size());
100
        Assert.assertEquals("number of records found is incorrect", 1, records.size());
101 101
        GbifResponse gbifResponse = records.iterator().next();
102
        assertEquals("Locality is incorrect", LOCALITY_STRING, gbifResponse.getDerivedUnitFacade().getLocalityText());
103
        assertEquals("protocol is wrong", GbifDataSetProtocol.BIOCASE, gbifResponse.getDataSetProtocol());
104
        assertEquals("protocol is wrong", new URI("http://api.gbif.org/v1/dataset/26a49731-9457-45b2-9105-1b96063deb26/endpoint"), gbifResponse.getDataSetUri());
102
        Assert.assertEquals("Locality is incorrect", LOCALITY_STRING, gbifResponse.getDerivedUnitFacade().getLocalityText());
103
        Assert.assertEquals("protocol is wrong", GbifDataSetProtocol.BIOCASE, gbifResponse.getDataSetProtocol());
104
        Assert.assertEquals("protocol is wrong", new URI("http://api.gbif.org/v1/dataset/26a49731-9457-45b2-9105-1b96063deb26/endpoint"), gbifResponse.getDataSetUri());
105 105
    }
106 106

  
107 107
    @Test
108 108
    public void testJsonOriginalDataSetUriParsing(){
109 109
        DataSetResponse response = GbifJsonOccurrenceParser.parseOriginalDataSetUri(dummyJsonDataset);
110
        assertEquals("Response protocol is incorrect!", GbifDataSetProtocol.BIOCASE, response.getProtocol());
111
        assertEquals("Response endpoint is incorrect!", URI.create("http://www.flora-mv.de/biocase/pywrapper.cgi?dsa=hoeherePflanzen"), response.getEndpoint());
110
        Assert.assertEquals("Response protocol is incorrect!", GbifDataSetProtocol.BIOCASE, response.getProtocol());
111
        Assert.assertEquals("Response endpoint is incorrect!", URI.create("http://www.flora-mv.de/biocase/pywrapper.cgi?dsa=hoeherePflanzen"), response.getEndpoint());
112 112
    }
113 113

  
114 114
    @Test
......
116 116
        OccurenceQuery query = new OccurenceQuery("Campanula persicifolia", "T. Henning", "1234", "ACC-2", "BGBM", "DE", "pollen herbarium", new GregorianCalendar(2014, 05, 27), new GregorianCalendar(2014,05,28));
117 117
        List<NameValuePair> queryParams = new GbifQueryGenerator().generateQueryParams(query);
118 118
        NameValuePair pair = new BasicNameValuePair("scientificName", "Campanula persicifolia");
119
        assertTrue("query parameter is missing", queryParams.contains(pair));
119
        Assert.assertTrue("query parameter is missing", queryParams.contains(pair));
120 120
        //FIXME this will currently always fail because eventDate is still not supported by GBIF
121 121
        //"basisOfRecord" and "limit" is always set
122 122
        // + 8 from query (collectorsNumber will be represented in the two parameters "recordNumber" and "fieldNumber";
......
132 132
        GbifQueryServiceWrapper service = new GbifQueryServiceWrapper();
133 133
        try {
134 134
            Collection<GbifResponse> gbifResponse = service.query(query);
135
            assertEquals("Usually this query retrieves at least two units. " +
135
            Assert.assertEquals("Usually this query retrieves at least two units. " +
136 136
            		"Test failure may also be due to GBIF!" +
137 137
            		"Check http://api.gbif.org/v1/occurrence/search?basisOfRecord=PRESERVED_SPECIMEN&limit=100&recordedBy=E.+J.+Palmer&scientificName=Campanula+persicifolia", 2, gbifResponse.size());
138 138
        } catch (ClientProtocolException e) {
139
            fail(e.getMessage());
139
            Assert.fail(e.getMessage());
140 140
        } catch (IOException e) {
141
            fail(e.getMessage());
141
            Assert.fail(e.getMessage());
142 142
        } catch (URISyntaxException e) {
143
            fail(e.getMessage());
143
            Assert.fail(e.getMessage());
144 144
        }
145 145

  
146 146
    }

Also available in: Unified diff