Search in sources :

Example 1 with GeoResult

use of org.codice.ddf.spatial.geocoder.GeoResult in project ddf by codice.

the class TestGeoNamesLocalIndex method testWithNoResults.

@Test
public void testWithNoResults() throws GeoEntryQueryException {
    final List<GeoEntry> noResults = Collections.emptyList();
    doReturn(noResults).when(geoEntryQueryable).query("Tempe", 1);
    final GeoResult geoResult = geoNamesLocalIndex.getLocation("Tempe");
    assertThat(geoResult, is(nullValue()));
}
Also used : GeoEntry(org.codice.ddf.spatial.geocoding.GeoEntry) GeoResult(org.codice.ddf.spatial.geocoder.GeoResult) Test(org.junit.Test)

Example 2 with GeoResult

use of org.codice.ddf.spatial.geocoder.GeoResult in project ddf by codice.

the class GeoCoderServiceImpl method doQuery.

JSONObject doQuery(String query) {
    GeoCoder geoCoder = geoCoderFactory.getService();
    GeoResult geoResult = null;
    if (geoCoder != null) {
        geoResult = geoCoder.getLocation(query);
    }
    JSONObject jsonObject = new JSONObject();
    JSONArray resourceSets = new JSONArray();
    JSONObject resourceSet = new JSONObject();
    jsonObject.put("resourceSets", resourceSets);
    resourceSets.add(resourceSet);
    JSONArray resources = new JSONArray();
    resourceSet.put("resources", resources);
    if (geoResult != null) {
        transformGeoResult(geoResult, resources);
    }
    return jsonObject;
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) GeoResult(org.codice.ddf.spatial.geocoder.GeoResult)

Example 3 with GeoResult

use of org.codice.ddf.spatial.geocoder.GeoResult in project ddf by codice.

the class TestGeoNamesLocalIndex method testExceptionInQuery.

@Test
public void testExceptionInQuery() throws GeoEntryQueryException {
    doThrow(GeoEntryQueryException.class).when(geoEntryQueryable).query("Arizona", 1);
    final GeoResult geoResult = geoNamesLocalIndex.getLocation("Arizona");
    assertThat(geoResult, is(nullValue()));
}
Also used : GeoResult(org.codice.ddf.spatial.geocoder.GeoResult) Test(org.junit.Test)

Example 4 with GeoResult

use of org.codice.ddf.spatial.geocoder.GeoResult in project ddf by codice.

the class TestGeoNamesWebService method testGetLocation.

@Test
public void testGetLocation() throws IOException {
    String response = IOUtils.toString(TestGeoNamesWebService.class.getClassLoader().getResourceAsStream("getLocationTestResponse.json"));
    prepareWebClient(response);
    GeoResult result = webServiceSpy.getLocation("Phoenix");
    assertThat(result.getFullName(), is("Phoenix"));
}
Also used : GeoResult(org.codice.ddf.spatial.geocoder.GeoResult) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 5 with GeoResult

use of org.codice.ddf.spatial.geocoder.GeoResult in project ddf by codice.

the class GeoCoderEndpoint method doQuery.

JSONObject doQuery(String query) {
    GeoCoder geoCoder = geoCoderFactory.getService();
    GeoResult geoResult = null;
    if (geoCoder != null) {
        geoResult = geoCoder.getLocation(query);
    }
    JSONObject jsonObject = new JSONObject();
    JSONArray resourceSets = new JSONArray();
    JSONObject resourceSet = new JSONObject();
    jsonObject.put("resourceSets", resourceSets);
    resourceSets.add(resourceSet);
    JSONArray resources = new JSONArray();
    resourceSet.put("resources", resources);
    if (geoResult != null) {
        transformGeoResult(geoResult, resources);
    }
    return jsonObject;
}
Also used : GeoCoder(org.codice.ddf.spatial.geocoder.GeoCoder) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) GeoResult(org.codice.ddf.spatial.geocoder.GeoResult)

Aggregations

GeoResult (org.codice.ddf.spatial.geocoder.GeoResult)6 Test (org.junit.Test)4 JSONArray (net.minidev.json.JSONArray)2 JSONObject (net.minidev.json.JSONObject)2 GeoCoder (org.codice.ddf.spatial.geocoder.GeoCoder)2 GeoEntry (org.codice.ddf.spatial.geocoding.GeoEntry)2 DirectPositionImpl (org.geotools.geometry.jts.spatialschema.geometry.DirectPositionImpl)1 PointImpl (org.geotools.geometry.jts.spatialschema.geometry.primitive.PointImpl)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Point (org.opengis.geometry.primitive.Point)1