use of net.minidev.json.JSONObject in project scheduler by btrplace.
the class ActionConverterTest method testKillVM.
@Test
public void testKillVM() throws JSONConverterException {
KillVM a = new KillVM(vm1, n1, 3, 5);
JSONObject o = ac.toJSON(a);
System.out.println(o);
Assert.assertEquals(a, ac.fromJSON(o));
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class GeoNamesWebService method getLocation.
@Override
public GeoResult getLocation(String location) {
location = getUrlEncodedLocation(location);
String urlStr = String.format("%s://%s/searchJSON?q=%s&username=%s", GEONAMES_PROTOCOL, GEONAMES_API_ADDRESS, location, USERNAME);
Object result = query(urlStr);
if (result != null) {
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
JSONArray geonames = (JSONArray) jsonResult.get(GEONAMES_KEY);
if (geonames != null && geonames.size() > 0) {
JSONObject firstResult = (JSONObject) geonames.get(0);
if (firstResult != null) {
double lat = Double.valueOf((String) firstResult.get(LAT_KEY));
double lon = Double.valueOf((String) firstResult.get(LON_KEY));
Long population = (Long) firstResult.get(POPULATION_KEY);
String adminCode = (String) firstResult.get(ADMIN_CODE_KEY);
return GeoResultCreator.createGeoResult((String) firstResult.get(PLACENAME_KEY), lat, lon, adminCode, population);
}
}
}
}
return null;
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class GeoNamesWebService method getNearbyCity.
@Override
public NearbyLocation getNearbyCity(String locationWkt) {
notNull(locationWkt, "argument locationWkt may not be null");
Point wktCenterPoint = createPointFromWkt(locationWkt);
String urlStr = String.format("%s://%s/findNearbyPlaceNameJSON?lat=%f&lng=%f&maxRows=1&username=%s&cities=cities5000", GEONAMES_PROTOCOL, GEONAMES_API_ADDRESS, wktCenterPoint.getY(), wktCenterPoint.getX(), USERNAME);
Object result = query(urlStr);
if (result instanceof JSONObject) {
JSONObject jsonResult = (JSONObject) result;
JSONArray geonames = (JSONArray) jsonResult.get(GEONAMES_KEY);
if (geonames != null && geonames.size() > 0) {
JSONObject firstResult = (JSONObject) geonames.get(0);
if (firstResult != null) {
double lat = Double.valueOf((String) firstResult.get(LAT_KEY));
double lon = Double.valueOf((String) firstResult.get(LON_KEY));
String cityName = (String) firstResult.get(PLACENAME_KEY);
Point cityPoint = new PointImpl(lon, lat, SpatialContext.GEO);
return new NearbyLocationImpl(wktCenterPoint, cityPoint, cityName);
}
}
}
return null;
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class TestGeoJsonQueryResponseTransformer method testGoodResponse.
@Test
public void testGoodResponse() throws CatalogTransformerException, IOException, ParseException {
final int resultCount = 3;
final int hitCount = 12;
SourceResponse sourceResponse = setupResponse(resultCount, hitCount);
JSONObject obj = transform(sourceResponse, resultCount, hitCount);
verifyResponse(obj, resultCount, hitCount);
}
use of net.minidev.json.JSONObject in project ddf by codice.
the class TestGeoCoderEndpoint method testQuery.
@Test
public void testQuery() {
JSONObject jsonObject = this.geoCoderEndpoint.doQuery("Phoenix");
JSONArray resourceSets = (JSONArray) jsonObject.get("resourceSets");
assertThat(resourceSets.size(), is(1));
JSONObject resources = (JSONObject) resourceSets.get(0);
JSONArray resourceElements = (JSONArray) resources.get("resources");
assertThat(resourceElements.size(), is(1));
JSONObject resource = (JSONObject) resourceElements.get(0);
JSONObject point = (JSONObject) resource.get("point");
JSONArray bbox = (JSONArray) resource.get("bbox");
String name = (String) resource.get("name");
assertThat(name, is("Phoenix"));
assertThat(bbox.size(), is(4));
String type = (String) point.get("type");
assertThat(type, is("Point"));
JSONArray coordinates = (JSONArray) point.get("coordinates");
assertThat(coordinates.size(), is(2));
}
Aggregations