Example usage for org.json JSONObject getJSONObject

List of usage examples for org.json JSONObject getJSONObject

Introduction

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

Prototype

public JSONObject getJSONObject(String key) throws JSONException 

Source Link

Document

Get the JSONObject value associated with a key.

Usage

From source file:com.nikitaend.instafeed.sola.instagram.InstagramSession.java

public Tag getTag(String tagName) throws Exception {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("tag_name", tagName);
    String uri = uriConstructor.constructUri(UriFactory.Tags.GET_TAG, map, true);
    JSONObject object = (new GetMethod(uri)).call().getJSON();
    return new Tag(object.getJSONObject("data"), getAccessToken());
}

From source file:com.nikitaend.instafeed.sola.instagram.InstagramSession.java

public Location getLocation(int locationId) throws Exception {
    HashMap<String, Object> map = new HashMap<String, Object>();
    map.put("location_id", locationId);
    String uriString = uriConstructor.constructUri(UriFactory.Locations.GET_LOCATION, map, true);
    JSONObject object = (new GetMethod().setMethodURI(uriString)).call().getJSON();
    return new Location(object.getJSONObject("data"), getAccessToken());
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for listContacts method with mandatory parameters.
 *///from   w w w  .  j  a  v a 2s  . c o m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSetContactNegativeCase" }, description = "BaseCRM {listContacts} integration test with mandatory parameters.")
public void testListContactsWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listContacts_mandatory.json", parametersMap);

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    JSONArray esbContactsArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    JSONObject esbContactObject = new JSONObject(esbContactsArray.getString(0));

    String apiEndPoint = salesApiEndpoint + "contacts.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiContactsArray = new JSONArray(apiRestResponse.getBody().getString("output"));
    JSONObject apiContactObject = new JSONObject(apiContactsArray.getString(0));

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbContactObject.getJSONObject("contact").getString("id"),
            apiContactObject.getJSONObject("contact").getString("id"));
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for getContactNotes method with mandatory parameters.
 *///from  w ww .jav  a2s .c om
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testCreateContactNoteNegativeCase" }, description = "BaseCRM {getContactNotes} integration test with mandatory parameters.")
public void testGetContactNotesWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getContactNotes_mandatory.json", parametersMap);

    JSONArray esbJsonArray = new JSONArray(esbRestResponse.getBody().getString("output"));

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    String apiEndPoint = salesApiEndpoint + "contacts/" + connectorProperties.getProperty("contactIdMandatory")
            + "/notes.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiJsonArray = new JSONArray(apiRestResponse.getBody().getString("output"));

    String esbNoteContent = new JSONObject(esbJsonArray.getString(0)).getJSONObject("note")
            .getString("content");
    String esbNoteId = new JSONObject(esbJsonArray.getString(0)).getJSONObject("note").getString("id");

    int esbNotesCount = new JSONArray(esbRestResponse.getBody().getString("output")).length();

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbNotesCount, apiJsonArray.getJSONObject(0).length());

    boolean matchContents = false;

    for (int i = 0; i < apiJsonArray.length(); i++) {
        JSONObject object = apiJsonArray.getJSONObject(i);
        if (esbNoteId.equals(object.getJSONObject("note").getString("id"))
                && esbNoteContent.equals(object.getJSONObject("note").getString("content"))) {
            matchContents = true;
            break;
        }
    }
    Assert.assertTrue(matchContents);
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for getContactReminders method with mandatory parameters.
 *///from  ww  w.  ja  v a  2s.c  o  m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testCreateContactReminderNegativeCase" }, description = "BaseCRM {getContactReminders} integration test with mandatory parameters.")
public void testGetContactRemindersWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getContactReminders_mandatory.json", parametersMap);
    JSONArray esbJsonArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    String apiEndPoint = salesApiEndpoint + "contacts/" + connectorProperties.getProperty("contactIdMandatory")
            + "/reminders.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiJsonArray = new JSONArray(apiRestResponse.getBody().getString("output"));

    int esbRemindersCount = new JSONArray(esbRestResponse.getBody().getString("output")).length();
    String esbReminderContent = new JSONObject(esbJsonArray.getString(0)).getJSONObject("reminder")
            .getString("content");
    String esbReminderId = new JSONObject(esbJsonArray.getString(0)).getJSONObject("reminder").getString("id");

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbRemindersCount, apiJsonArray.getJSONObject(0).length());

    boolean matchContents = false;

    for (int i = 0; i < apiJsonArray.length(); i++) {
        JSONObject object = apiJsonArray.getJSONObject(i);
        if (esbReminderId.equals(object.getJSONObject("reminder").getString("id"))
                && esbReminderContent.equals(object.getJSONObject("reminder").getString("content"))) {
            matchContents = true;
            break;
        }
    }
    Assert.assertTrue(matchContents);
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for getDealNotes method with mandatory parameters.
 *///from   www.ja v a2s  . c o m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testCreateDealNoteNegativeCase" }, description = "BaseCRM {getDealNotes} integration test with mandatory parameters.")
public void testGetDealNotesWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getDealNotes_mandatory.json", parametersMap);

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    String apiEndPoint = salesApiEndpoint + "deals/" + connectorProperties.getProperty("dealIdMandatory")
            + "/notes.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiJsonArray = new JSONArray(apiRestResponse.getBody().getString("output"));

    int esbNotesCount = new JSONArray(esbRestResponse.getBody().getString("output")).length();
    JSONArray esbJsonArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    String esbNoteContent = new JSONObject(esbJsonArray.getString(0)).getJSONObject("note")
            .getString("content");
    String esbNoteId = new JSONObject(esbJsonArray.getString(0)).getJSONObject("note").getString("id");

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbNotesCount, apiJsonArray.getJSONObject(0).length());

    boolean matchContents = false;

    for (int i = 0; i < apiJsonArray.length(); i++) {
        JSONObject object = apiJsonArray.getJSONObject(i);
        if (esbNoteId.equals(object.getJSONObject("note").getString("id"))
                && esbNoteContent.equals(object.getJSONObject("note").getString("content"))) {
            matchContents = true;
            break;
        }
    }
    Assert.assertTrue(matchContents);
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for getDealReminders method with mandatory parameters.
 *//*from   w  w w . ja  v a 2 s. c  om*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testCreateDealReminderNegativeCase" }, description = "BaseCRM {getDealReminders} integration test with mandatory parameters.")
public void testGetDealRemindersWithMandatoryParameters() throws Exception {

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getDealReminders_mandatory.json", parametersMap);

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    String apiEndPoint = salesApiEndpoint + "deals/" + connectorProperties.getProperty("dealIdMandatory")
            + "/reminders.json";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiJsonArray = new JSONArray(apiRestResponse.getBody().getString("output"));

    int esbRemindersCount = new JSONArray(esbRestResponse.getBody().getString("output")).length();
    JSONArray esbJsonArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    String esbReminderContent = new JSONObject(esbJsonArray.getString(0)).getJSONObject("reminder")
            .getString("content");
    String esbReminderId = new JSONObject(esbJsonArray.getString(0)).getJSONObject("reminder").getString("id");

    Assert.assertEquals(apiRestResponse.getHttpStatusCode(), 200);
    Assert.assertEquals(esbRemindersCount, apiJsonArray.getJSONObject(0).length());

    boolean matchContents = false;

    for (int i = 0; i < apiJsonArray.length(); i++) {
        JSONObject object = apiJsonArray.getJSONObject(i);
        if (esbReminderId.equals(object.getJSONObject("reminder").getString("id"))
                && esbReminderContent.equals(object.getJSONObject("reminder").getString("content"))) {
            matchContents = true;
            break;
        }
    }
    Assert.assertTrue(matchContents);
}

From source file:org.wso2.carbon.connector.integration.test.basecrm.BasecrmConnectorIntegrationTest.java

/**
 * Positive test case for listLeads method with optional parameters.
 *///from w  w w  .  jav  a  2  s . c om
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListLeadsWithMandatoryParameters" }, description = "BaseCRM {listLeads} integration test with optional parameters.")
public void testListLeadsWithOptionalParameters() throws Exception {

    parametersMap.put("sortBy", "first_name");

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listLeads_optional.json", parametersMap);

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), 200);

    boolean esbLeadsSuccess = Boolean.parseBoolean(esbRestResponse.getBody().getString("success"));
    int esbLeadsCount = esbRestResponse.getBody().getJSONObject("metadata").getInt("count");
    JSONObject esbLeadFirstElement = new JSONObject(
            esbRestResponse.getBody().getJSONArray("items").getString(0));

    String apiEndPoint = leadsApiEndpoint + "leads.json?sort_by=" + parametersMap.get("sortBy");

    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    boolean apiLeadsSuccess = Boolean.parseBoolean(apiRestResponse.getBody().getString("success"));
    int apiLeadsCount = esbRestResponse.getBody().getJSONObject("metadata").getInt("count");
    JSONObject apiLeadFirstElement = new JSONObject(
            apiRestResponse.getBody().getJSONArray("items").getString(0));

    Assert.assertEquals(esbLeadsSuccess, apiLeadsSuccess);
    Assert.assertEquals(esbLeadsCount, apiLeadsCount);
    Assert.assertEquals(esbLeadFirstElement.getJSONObject("lead").getString("first_name"),
            apiLeadFirstElement.getJSONObject("lead").getString("first_name"));
}

From source file:com.scigames.slidegame.Registration4PhotoActivity.java

public void onResultsSucceeded(String[] serverResponseStrings, JSONObject serverResponseJSON)
        throws JSONException {
    Log.d(TAG, "...resultsSucceeded");
    Log.d(TAG, "QUERY SUCCEEDED: ");
    setProgressBarIndeterminateVisibility(false);

    for (int i = 0; i < serverResponseStrings.length; i++) { //just print everything returned as a String[] for fun
        Log.d(TAG, "[" + i + "] " + serverResponseStrings[i]);
    }/*from  w ww  .ja v  a 2s.  c o m*/

    JSONObject thisStudent;
    thisStudent = serverResponseJSON.getJSONObject("student");

    Log.d(TAG, "this student: ");
    Log.d(TAG, thisStudent.toString());
    Intent i = new Intent(Registration4PhotoActivity.this, Registration5EmailActivity.class); //THIS IS RIGHT
    //Intent i = new Intent(Registration4PhotoActivity.this, ProfileActivity.class);
    Log.d(TAG, "new Intent");
    i.putExtra("fName", serverResponseStrings[2]);
    i.putExtra("lName", serverResponseStrings[3]);
    i.putExtra("studentId", serverResponseStrings[0]);
    i.putExtra("mass", thisStudent.getString("mass"));
    //i.putExtra("visitId",serverResponseStrings[1]);
    i.putExtra("photoUrl", serverResponseStrings[1]);
    Log.d(TAG, "startActivity...");
    Registration4PhotoActivity.this.startActivity(i);
    Log.d(TAG, "...startActivity");

}

From source file:org.openqa.selenium.logging.SessionLogHandler.java

/**
 * Creates a session logs map, with session logs mapped to session IDs, given
 * a raw session log map as a JSON object.
 *  //from w  w w .  j  av  a  2s .  c o m
 * @param rawSessionMap The raw session map.
 * @return The session logs mapped to session IDs.
 * @throws Exception If something goes wrong in server communication or JSON parsing.
 */
public static Map<String, SessionLogs> getSessionLogs(JSONObject rawSessionMap) throws JSONException {
    Map<String, SessionLogs> sessionLogsMap = new HashMap<String, SessionLogs>();
    for (Iterator keyItr = rawSessionMap.keys(); keyItr.hasNext();) {
        String sessionId = (String) keyItr.next();
        SessionLogs sessionLogs = SessionLogs.fromJSON(rawSessionMap.getJSONObject(sessionId));
        sessionLogsMap.put(sessionId, sessionLogs);
    }
    return sessionLogsMap;
}