Search in sources :

Example 16 with JSONObject

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));
}
Also used : JSONObject(net.minidev.json.JSONObject) Test(org.testng.annotations.Test)

Example 17 with JSONObject

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;
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject)

Example 18 with JSONObject

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;
}
Also used : NearbyLocationImpl(org.codice.ddf.spatial.geocoding.context.impl.NearbyLocationImpl) JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) JSONObject(net.minidev.json.JSONObject) Point(org.locationtech.spatial4j.shape.Point) PointImpl(org.locationtech.spatial4j.shape.impl.PointImpl)

Example 19 with JSONObject

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);
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) JSONObject(net.minidev.json.JSONObject) Test(org.junit.Test)

Example 20 with JSONObject

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));
}
Also used : JSONObject(net.minidev.json.JSONObject) JSONArray(net.minidev.json.JSONArray) Mockito.anyString(org.mockito.Mockito.anyString) Test(org.junit.Test)

Aggregations

JSONObject (net.minidev.json.JSONObject)254 JSONArray (net.minidev.json.JSONArray)49 Test (org.junit.Test)39 Test (org.testng.annotations.Test)38 JSONParser (net.minidev.json.parser.JSONParser)23 HashMap (java.util.HashMap)22 MockFlowFile (org.apache.nifi.util.MockFlowFile)16 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)14 Test (org.junit.jupiter.api.Test)14 Map (java.util.Map)13 ParseException (net.minidev.json.parser.ParseException)13 JSONConverterException (org.btrplace.json.JSONConverterException)13 SignedJWT (com.nimbusds.jwt.SignedJWT)12 Node (org.btrplace.model.Node)12 VM (org.btrplace.model.VM)12 JWSHeader (com.nimbusds.jose.JWSHeader)10 RSASSASigner (com.nimbusds.jose.crypto.RSASSASigner)10 AuthenticationContext (org.wso2.carbon.apimgt.gateway.handlers.security.AuthenticationContext)10 OpenAPI (io.swagger.v3.oas.models.OpenAPI)9 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)9