Example usage for org.json.simple JSONObject toString

List of usage examples for org.json.simple JSONObject toString

Introduction

In this page you can find the example usage for org.json.simple JSONObject toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:org.disit.servicemap.test.ServiceMapApiTest.java

@Test
public void test_municipality_services() throws Exception {
    JSONObject jobj = getJSON(urlPrefix
            + "selection=COMUNE%20di%20FIRENZE&categorie=boarding_house%3Bagritourism%3Bhotel%3Bbed_and_breakfast%3Bcamping%3Brest_home%3Breligiuos_guest_house%3Bsummer_residence%3Bday_care_center%3Bhostel%3Bvacation_resort%3Bfarm_house%3Bhistoric_residence%3Bmountain_dew%3Bbeach_resort%3Bholiday_village%3BRoadSensor%3BNearBusStops&risultati=100&raggio=100&format=json");
    System.out.println(jobj.toString());
    assertNotNull(jsonPath(jobj, "Sensori.features"));
    assertEquals("FeatureCollection", jsonPath(jobj, "Sensori.type"));
    assertNotNull(jsonPath(jobj, "Servizi.features"));
    assertEquals("FeatureCollection", jsonPath(jobj, "Servizi.type"));
    assertNotNull(jsonPath(jobj, "Fermate.features"));
    assertEquals("FeatureCollection", jsonPath(jobj, "Fermate.type"));
    assertNotNull(jsonPath(jobj, "Sensori.features.0"));
    assertNotNull(jsonPath(jobj, "Servizi.features.0"));
    assertNotNull(jsonPath(jobj, "Fermate.features.0"));
}

From source file:org.disit.servicemap.test.ServiceMapApiTest.java

@Test
public void test_latlng_services() throws Exception {
    JSONObject jobj = getJSON(urlPrefix
            + "selection=43.7923;11.2841&categorie=Boarding_house%3BAgritourism%3BHotel%3BBed_and_breakfast%3BCamping%3BRest_home%3BReligiuos_guest_house%3BSummer_residence%3BDay_care_center%3BHostel%3BVacation_resort%3BFarm_house%3BHistoric_residence%3BMountain_dew%3BBeach_resort%3BHoliday_village%3BRoadSensor%3BNearBusStops&maxResults=100&maxDists=0.5&format=json");
    System.out.println(jobj.toString());
    assertNotNull(jsonPath(jobj, "Sensori.features"));
    assertEquals("FeatureCollection", jsonPath(jobj, "Sensori.type"));
    assertNotNull(jsonPath(jobj, "Servizi.features"));
    assertEquals("FeatureCollection", jsonPath(jobj, "Servizi.type"));
    assertNotNull(jsonPath(jobj, "Fermate.features"));
    assertEquals("FeatureCollection", jsonPath(jobj, "Fermate.type"));
    assertEquals(0, ((JSONArray) jsonPath(jobj, "Sensori.features")).size());
    assertNotNull(jsonPath(jobj, "Servizi.features.0"));
    assertNotNull(jsonPath(jobj, "Fermate.features.0"));
}

From source file:org.disit.servicemap.test.ServiceMapApiTest.java

@Test
public void test_meteo() throws Exception {
    JSONObject jobj = getJSON(
            urlPrefix + "serviceUri=http://www.disit.org/km4city/resource/048017&format=json");

    System.out.println(jobj.toString());
    assertNotNull(jsonPath(jobj, "results"));
    Object bindings = jsonPath(jobj, "results.bindings");
    assertNotNull(bindings);/*from   w  w  w.  j  av  a 2s. c o m*/
    for (Object x : ((JSONArray) bindings)) {
        assertTrue(((String) jsonPath((JSONObject) x, "maxTemp.value")).matches("[0-9]*"));
        assertEquals("literal", jsonPath((JSONObject) x, "maxTemp.type"));
        assertTrue(((String) jsonPath((JSONObject) x, "minTemp.value")).matches("[0-9]*"));
        assertEquals("literal", jsonPath((JSONObject) x, "minTemp.type"));
        assertTrue(((String) jsonPath((JSONObject) x, "giorno.value"))
                .matches("(Lunedi)|(Martedi)|(Mercoledi)|(Giovedi)|(Venerdi)|(Sabato)|(Domenica)"));
        assertEquals("literal", jsonPath((JSONObject) x, "giorno.type"));
        assertNotNull(jsonPath((JSONObject) x, "descrizione.value"));
        assertEquals("literal", jsonPath((JSONObject) x, "descrizione.type"));
        assertNotNull(jsonPath((JSONObject) x, "instantDateTime.value"));
        assertEquals("literal", jsonPath((JSONObject) x, "instantDateTime.type"));
    }
    assertEquals("FIRENZE", jsonPath(jobj, "head.location"));
}

From source file:org.disit.servicemap.test.ServiceMapApiTest.java

@Test
public void test_pensilina() throws MalformedURLException, IOException, Exception {
    JSONObject jobj = getJSON(
            urlPrefix + "serviceUri=http://www.disit.org/km4city/resource/FM0022&format=json");

    System.out.println(jobj.toString());
    assertEquals((long) 1, jsonPath(jobj, "Fermata.features.0.id"));
    assertEquals("http://www.disit.org/km4city/resource/FM0022",
            jsonPath(jobj, "Fermata.features.0.properties.serviceUri"));
    assertEquals("fermata", jsonPath(jobj, "Fermata.features.0.properties.tipo"));
    assertEquals("STAZIONE PENSILINA", jsonPath(jobj, "Fermata.features.0.properties.nome"));
    assertEquals("Point", jsonPath(jobj, "Fermata.features.0.geometry.type"));
    assertEquals(11.2491, jsonPath(jobj, "Fermata.features.0.geometry.coordinates.0"));
    assertEquals(43.7765, jsonPath(jobj, "Fermata.features.0.geometry.coordinates.1"));
    assertEquals("11", jsonPath(jobj, "linee.results.bindings.0.linea.value"));
    assertNotNull(jsonPath(jobj, "realtime.results.bindings.0.ride.value"));
    assertNotNull(jsonPath(jobj, "realtime.results.bindings.0.stato.value"));
    assertNotNull(jsonPath(jobj, "realtime.results.bindings.0.orario.value"));
    assertNotNull(jsonPath(jobj, "realtime.results.bindings.0.linea.value"));
    Object bindings = jsonPath(jobj, "realtime.results.bindings");
    assertNotNull(bindings);//  ww  w  .ja v  a2  s  .  c  o  m
    for (Object x : ((JSONArray) bindings)) {
        assertTrue(((String) jsonPath((JSONObject) x, "ride.value")).matches("[0-9]+"));
        assertTrue(((String) jsonPath((JSONObject) x, "orario.value"))
                .matches("[0-9][0-9]:[0-9][0-9]:[0-9][0-9]"));
        assertTrue(((String) jsonPath((JSONObject) x, "linea.value"))
                .matches("http://www.disit.org/km4city/resource/[0-9]+"));
        assertTrue(
                ((String) jsonPath((JSONObject) x, "stato.value")).matches("(In orario)|(Anticipo)|(Ritardo)"));
    }
}

From source file:org.disit.servicemap.test.ServiceMapApiTest.java

@Test
public void test_parcheggio() throws MalformedURLException, IOException, Exception {
    JSONObject jobj = getJSON(
            urlPrefix + "serviceUri=http://www.disit.org/km4city/resource/RT04801702315PO&format=json");

    System.out.println(jobj.toString());
    assertEquals((long) 1, jsonPath(jobj, "Service.features.0.id"));
    assertEquals("http://www.disit.org/km4city/resource/RT04801702315PO",
            jsonPath(jobj, "Service.features.0.properties.serviceUri"));
    assertEquals("Parcheggio_auto", jsonPath(jobj, "Service.features.0.properties.tipo"));
    assertEquals("Garage La Stazione Spa", jsonPath(jobj, "Service.features.0.properties.nome"));
    assertNotNull(jsonPath(jobj, "realtime.results.bindings.0"));
    assertEquals("610", jsonPath(jobj, "realtime.results.bindings.0.Capacit.value"));
}

From source file:org.disit.servicemap.test.ServiceMapApiTest.java

@Test
public void test_ferragamo() throws MalformedURLException, IOException, Exception {
    JSONObject jobj = getJSON(urlPrefix
            + "serviceUri=http://www.disit.org/km4city/resource/5967e716e49d6385518805e83e051854&format=json");

    System.out.println(jobj.toString());
    assertEquals((long) 1, jsonPath(jobj, "Service.features.0.id"));
    assertEquals("http://www.disit.org/km4city/resource/5967e716e49d6385518805e83e051854",
            jsonPath(jobj, "Service.features.0.properties.serviceUri"));
    assertEquals("palazzi", jsonPath(jobj, "Service.features.0.properties.tipo"));
    assertEquals("Palazzo Spini Feroni", jsonPath(jobj, "Service.features.0.properties.nome"));
    assertEquals("VIA D TORNABUONI", jsonPath(jobj, "Service.features.0.properties.indirizzo"));
    assertEquals("2", jsonPath(jobj, "Service.features.0.properties.numero"));
    assertEquals("http://www.florenceheritage.it/mobileApp/immagini/aebTornabuoni/20.jpg",
            jsonPath(jobj, "Service.features.0.properties.multimedia"));
    assertEquals("Point", jsonPath(jobj, "Service.features.0.geometry.type"));
    assertEquals(11.251, jsonPath(jobj, "Service.features.0.geometry.coordinates.0"));
    assertEquals(43.7698, jsonPath(jobj, "Service.features.0.geometry.coordinates.1"));
}

From source file:org.disit.servicemap.test.ServiceMapApiTest.java

@Test
public void test_sensore() throws MalformedURLException, IOException, Exception {
    JSONObject jobj = getJSON(
            urlPrefix + "serviceUri=http://www.disit.org/km4city/resource/EM0100102&format=json");

    System.out.println(jobj.toString());
    assertEquals((long) 1, jsonPath(jobj, "Sensore.features.0.id"));
    assertEquals("http://www.disit.org/km4city/resource/EM0100102",
            jsonPath(jobj, "Sensore.features.0.properties.serviceUri"));
    assertEquals("sensore", jsonPath(jobj, "Sensore.features.0.properties.tipo"));
    assertEquals("EM0100102", jsonPath(jobj, "Sensore.features.0.properties.nome"));
    assertEquals("VIALE GIOVANNI BOCCACCIO", jsonPath(jobj, "Sensore.features.0.properties.indirizzo"));
    assertEquals("Point", jsonPath(jobj, "Sensore.features.0.geometry.type"));
    assertEquals(10.9286, jsonPath(jobj, "Sensore.features.0.geometry.coordinates.0"));
    assertEquals(43.7232, jsonPath(jobj, "Sensore.features.0.geometry.coordinates.1"));
    assertNotNull(jsonPath(jobj, "realtime.results.bindings.0.instantTime.value"));
    assertTrue(((String) jsonPath(jobj, "realtime.results.bindings.0.concentration.value"))
            .matches("([0-9]+\\.[0-9]+)|(NAN)|(Not Available)"));
    assertTrue(((String) jsonPath(jobj, "realtime.results.bindings.0.speedPercentile.value"))
            .matches("([0-9]+\\.[0-9]+)|(NAN)|(Not Available)"));
    assertTrue(((String) jsonPath(jobj, "realtime.results.bindings.0.avgDistance.value"))
            .matches("([0-9]+\\.[0-9]+)|(NAN)|(Not Available)"));
    assertTrue(((String) jsonPath(jobj, "realtime.results.bindings.0.averageSpeed.value"))
            .matches("([0-9]+\\.[0-9]+)|(NAN)|(Not Available)"));
    assertTrue(((String) jsonPath(jobj, "realtime.results.bindings.0.occupancy.value"))
            .matches("([0-9]+\\.[0-9]+)|(NAN)|(Not Available)"));
    assertTrue(((String) jsonPath(jobj, "realtime.results.bindings.0.avgTime.value"))
            .matches("([0-9]+\\.[0-9]+)|(NAN)|(Not Available)"));
    assertTrue(((String) jsonPath(jobj, "realtime.results.bindings.0.thresholdPerc.value"))
            .matches("([0-9]+\\.[0-9]+)|(NAN)|(Not Available)"));
    assertTrue(((String) jsonPath(jobj, "realtime.results.bindings.0.vehicleFlow.value"))
            .matches("([0-9]+\\.[0-9]+)|(NAN)|(Not Available)"));
}

From source file:org.disit.servicemap.test.ServiceMapApiTest.java

@Test
public void test_fulltext() throws Exception {
    JSONObject jobj = getJSON(urlPrefix + "search=ferragamo&limit=10&format=json");
    System.out.println(jobj.toString());
    assertEquals((long) 1, jsonPath(jobj, "features.0.id"));
}

From source file:org.eclipse.paho.android.service.sample.JSONFormatController.java

public static String createJSONmessage(String owner, String text) {
    JSONObject obj = new JSONObject();
    obj.put("owner", owner);
    obj.put("text", text);
    obj.put("corre-id", null);
    return obj.toString();

}

From source file:org.geotools.data.couchdb.CouchDBDataStoreTest.java

@Test
public void testFeatureWriterAdd() throws Exception {
    // currently require some data to exist due to construction of featuretype from existing feature...
    db.postBulk(loadJSON("morocco.json", "countries"));

    JSONArray data = loadJSON("italy.json", "countries");
    JSONObject italy = (JSONObject) data.get(0);
    FeatureJSON json = new FeatureJSON();
    json.setFeatureType(CouchDBUtils.createFeatureType(italy, "countries"));
    Feature feature = json.readFeature(italy.toString());

    ContentFeatureStore featureStore = (ContentFeatureStore) store.getFeatureSource("gttestdb.countries");
    featureStore.addFeatures(Collections.singleton(feature));

    // single add case
    ContentFeatureCollection features = featureStore.getFeatures();
    assertEquals(2, features.size());//from   w ww  . ja  va  2s.  c  o m

    // double add (we can add the same features repeatedly at the moment 
    // since the id is opaque to the feature
    featureStore.addFeatures(Arrays.asList(feature, feature));
    assertEquals(4, features.size());

}