use of com.google.code.geocoder.model.GeocoderStatus in project wildfly-camel by wildfly-extras.
the class GeocoderIntegrationTest method testGeocoderComponent.
@Test
public void testGeocoderComponent() throws Exception {
HttpClientConfigurer configurer = new GeocoderHttpClientConfigurer();
initialContext.bind("httpClientConfigurer", configurer);
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:start").to("geocoder:address:London, England?httpClientConfigurer=#httpClientConfigurer");
}
});
camelctx.start();
try {
// Geocoder API is sometimes flaky so retry the request if necessary
GeocodeResponse result = null;
int count = 0;
while (count < 5) {
ProducerTemplate template = camelctx.createProducerTemplate();
result = template.requestBody("direct:start", null, GeocodeResponse.class);
Assert.assertNotNull("Geocoder response is null", result);
// Skip further testing if we exceeded the API rate limit
GeocoderStatus status = result.getStatus();
Assume.assumeFalse("Geocoder API rate limit exceeded", status.equals(OVER_QUERY_LIMIT));
if (status.equals(OK)) {
break;
}
Thread.sleep(1000);
count++;
}
List<GeocoderResult> results = result.getResults();
Assert.assertNotNull("Geocoder results is null", result);
Assert.assertEquals("Expected 1 GeocoderResult to be returned", 1, results.size());
LatLng location = results.get(0).getGeometry().getLocation();
Assert.assertEquals("51.5073509", location.getLat().toPlainString());
Assert.assertEquals("-0.1277583", location.getLng().toPlainString());
} finally {
camelctx.stop();
initialContext.unbind("httpClientConfigurer");
}
}
Aggregations