Example usage for org.json JSONObject getString

List of usage examples for org.json JSONObject getString

Introduction

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

Prototype

public String getString(String key) throws JSONException 

Source Link

Document

Get the string associated with a key.

Usage

From source file:com.amazon.android.contentbrowser.helper.AuthHelper.java

/**
 * Retrieves the list of possible MVPD providers from the URL found at R.string.mvpd_url in
 * custom.xml and gives them to ContentBrowser.
 *//*from  ww  w . j  av  a2  s  .c  om*/
public void setupMvpdList() {

    try {

        String mvpdUrl = mAppContext.getResources().getString(R.string.mvpd_url);

        // The user has no MVPD URL set up.
        if (mvpdUrl.equals(DEFAULT_MVPD_URL)) {
            Log.d(TAG, "MVPD feature not used.");
            return;
        }
        String jsonStr = NetworkUtils.getDataLocatedAtUrl(mvpdUrl);

        JSONObject json = new JSONObject(jsonStr);
        JSONArray mvpdWhiteList = json.getJSONArray(MVPD_WHITE_LIST);

        for (int i = 0; i < mvpdWhiteList.length(); i++) {

            JSONObject mvpdItem = mvpdWhiteList.getJSONObject(i);
            mContentBrowser.addPoweredByLogoUrlByName(mvpdItem.getString(PreferencesConstants.MVPD_LOGO_URL),
                    mvpdItem.getString(LOGGED_IN_IMAGE));
        }

    } catch (Exception e) {
        Log.e(TAG, "Get MVPD logo urls failed!!!", e);

    }
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for getReportData method with mandatory parameters.
 *
 * @throws org.json.JSONException//  w ww .j  a va 2 s  .  c  om
 * @throws java.io.IOException
 */

@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {getReportData} integration test with mandatory parameters.", dependsOnMethods = {
                "testListAccountSummariesWithMandatoryParameters" })
public void testGetReportDataWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:getReportData");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getReportData_mandatory.json");

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/data/ga?ids="
            + connectorProperties.getProperty("coreReportIds") + "&start-date="
            + connectorProperties.getProperty("coreReportStartDate") + "&end-date="
            + connectorProperties.getProperty("coreReportEndDate") + "&metrics="
            + connectorProperties.getProperty("coreReportMetrics");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap);

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("id"), apiResponse.getString("id"));
    Assert.assertEquals(esbResponse.getString("selfLink"), apiResponse.getString("selfLink"));
    Assert.assertEquals(esbResponse.getJSONObject("query").getString("start-date"),
            apiResponse.getJSONObject("query").getString("start-date"));
    Assert.assertEquals(esbResponse.getJSONObject("query").getString("end-date"),
            apiResponse.getJSONObject("query").getString("end-date"));
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for getReportData method with optional parameters.
 *
 * @throws org.json.JSONException/*from   w w w.  ja v a 2 s . c  om*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {getReportData} integration test with optional parameters.", dependsOnMethods = {
                "testListAccountSummariesWithMandatoryParameters" })
public void testGetReportDataWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:getReportData");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getReportData_optional.json");

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/data/ga?ids="
            + connectorProperties.getProperty("coreReportIds") + "&start-date="
            + connectorProperties.getProperty("coreReportStartDate") + "&end-date="
            + connectorProperties.getProperty("coreReportEndDate") + "&metrics="
            + connectorProperties.getProperty("coreReportMetrics") + "&max-results="
            + connectorProperties.getProperty("coreReportMaxResults") + "&start-index="
            + connectorProperties.getProperty("coreReportStartIndex");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap);

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("id"), apiResponse.getString("id"));
    Assert.assertEquals(esbResponse.getString("selfLink"), apiResponse.getString("selfLink"));
    Assert.assertEquals(connectorProperties.getProperty("coreReportMaxResults"),
            apiResponse.getJSONObject("query").getString("max-results"));
    Assert.assertEquals(connectorProperties.getProperty("coreReportStartIndex"),
            apiResponse.getJSONObject("query").getString("start-index"));
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for listAccountSummaries method with mandatory parameters.
 *
 * @throws org.json.JSONException/*w w  w .  j a va  2s  . c o m*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {listAccountSummaries} integration test with mandatory parameters.")
public void testListAccountSummariesWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:listAccountSummaries");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listAccountSummaries_mandatory.json");

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accountSummaries";

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

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("username"), apiResponse.getString("username"));
    Assert.assertEquals(esbResponse.getString("itemsPerPage"), apiResponse.getString("itemsPerPage"));
    Assert.assertEquals(esbResponse.getString("totalResults"), apiResponse.getString("totalResults"));
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for listAccountSummaries method with optional parameters.
 *
 * @throws org.json.JSONException/* ww  w. ja v  a2 s  .  com*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {listAccountSummaries} integration test with optional parameters.")
public void testListAccountSummariesWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:listAccountSummaries");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listAccountSummaries_optional.json");

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accountSummaries?max-results="
            + connectorProperties.getProperty("accountSumMaxResults") + "&start-index="
            + connectorProperties.getProperty("accountSumStartIndex");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap);

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(connectorProperties.getProperty("accountSumStartIndex"),
            apiResponse.getString("startIndex"));
    Assert.assertEquals(connectorProperties.getProperty("accountSumMaxResults"),
            apiResponse.getString("itemsPerPage"));
    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("username"), apiResponse.getString("username"));
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for listAccounts method with mandatory parameters.
 *
 * @throws org.json.JSONException// w ww. jav a 2s. c  o m
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {listAccounts} integration test with mandatory parameters.")
public void testListAccountsWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:listAccounts");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listAccounts_mandatory.json");

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts";

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

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("username"), apiResponse.getString("username"));
    Assert.assertEquals(esbResponse.getString("totalResults"), apiResponse.getString("totalResults"));
    Assert.assertEquals(esbResponse.getString("itemsPerPage"), apiResponse.getString("itemsPerPage"));
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for listAccounts method with optional parameters.
 *
 * @throws org.json.JSONException/*  ww w . j a  v  a  2 s.co m*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {listAccounts} integration test with optional parameters.")
public void testListAccountsWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:listAccounts");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listAccounts_optional.json");

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts?max-results="
            + connectorProperties.getProperty("accountMaxResults") + "&start-index="
            + connectorProperties.getProperty("accountStartIndex");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap);

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(connectorProperties.getProperty("accountStartIndex"),
            apiResponse.getString("startIndex"));
    Assert.assertEquals(connectorProperties.getProperty("accountMaxResults"),
            apiResponse.getString("itemsPerPage"));
    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("username"), apiResponse.getString("username"));
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for createFilter method with mandatory parameters.
 *
 * @throws org.json.JSONException/*from   w  w  w .ja v  a  2s .  c  o m*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {createFilter} integration test with mandatory parameters.")
public void testCreateFilterWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createFilter");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createFilter_mandatory.json");

    final JSONObject esbResponse = esbRestResponse.getBody();
    final String filterId = esbResponse.getString("id");
    connectorProperties.put("filterId", filterId);

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/filters/" + filterId;
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap);

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("id"), apiResponse.getString("id"));
    Assert.assertEquals(esbResponse.getString("selfLink"), apiResponse.getString("selfLink"));
    Assert.assertEquals(connectorProperties.getProperty("filterName"), apiResponse.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("filterType"), apiResponse.getString("type"));
    Assert.assertEquals(esbResponse.getString("created"), apiResponse.getString("created"));
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for createFilter method with optional parameters.
 *
 * @throws org.json.JSONException//from ww  w  . ja  v a2  s .c  o  m
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {createFilter} integration test with optional parameters.", dependsOnMethods = {
                "testListAccountSummariesWithMandatoryParameters" })
public void testCreateFilterWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createFilter");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createFilter_optional.json");

    final JSONObject esbResponse = esbRestResponse.getBody();
    final String filterId = esbResponse.getString("id");
    connectorProperties.put("filterIdOpt", filterId);

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/filters/" + filterId + "?fields="
            + connectorProperties.getProperty("fields");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap);

    final String apiEndpointField = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/filters/" + filterId;
    RestResponse<JSONObject> apiRestResponseWithField = sendJsonRestRequest(apiEndpointField, "GET",
            apiRequestHeadersMap);

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("id"), apiResponse.getString("id"));
    Assert.assertFalse(esbResponse.has("selfLink"));
    Assert.assertFalse(apiResponse.has("selfLink"));
    Assert.assertTrue(apiRestResponseWithField.getBody().has("selfLink"));
}

From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

/**
 * Positive test case for updateFilter method with mandatory parameters.
 *
 * @throws org.json.JSONException//from w  w  w  . j  a v  a2  s  .co  m
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {updateFilter} integration test with mandatory parameters.", dependsOnMethods = {
                "testCreateFilterWithMandatoryParameters" })
public void testUpdateFilterWithMandatoryParameters() throws IOException, JSONException {

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/filters/"
            + connectorProperties.getProperty("filterId");
    RestResponse<JSONObject> apiRestResponseBefore = sendJsonRestRequest(apiEndpoint, "GET",
            apiRequestHeadersMap);
    final JSONObject apiResponseBefore = apiRestResponseBefore.getBody();

    esbRequestHeadersMap.put("Action", "urn:updateFilter");
    sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_updateFilter_mandatory.json");

    RestResponse<JSONObject> apiRestResponseAfter = sendJsonRestRequest(apiEndpoint, "GET",
            apiRequestHeadersMap);

    final JSONObject apiResponseAfter = apiRestResponseAfter.getBody();

    Assert.assertNotEquals(apiResponseBefore.getString("name"), apiResponseAfter.getString("name"));
    Assert.assertNotEquals(apiResponseBefore.getString("type"), apiResponseAfter.getString("type"));

    Assert.assertEquals(connectorProperties.getProperty("filterUpdatedName"),
            apiResponseAfter.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("filterUpdatedType"),
            apiResponseAfter.getString("type"));

}