List of usage examples for org.json JSONObject getJSONArray
public JSONArray getJSONArray(String key) throws JSONException
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listFilters method with mandatory parameters. * * @throws org.json.JSONException// w w w . ja va 2s. c o m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listFilters} integration test with mandatory parameters.", dependsOnMethods = { "testCreateFilterWithMandatoryParameters", "testCreateFilterWithOptionalParameters" }) public void testListFiltersWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listFilters"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listFilters_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/filters"; 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")); String filterId = esbResponse.getJSONArray("items").getJSONObject(1).getString("id"); connectorProperties.setProperty("filterId", filterId); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listFilters method with optional parameters. * * @throws org.json.JSONException/*from ww w . j a va 2s . c o m*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listFilters} integration test with optional parameters.", dependsOnMethods = { "testCreateFilterWithOptionalParameters" }) public void testListFiltersWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listFilters"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listFilters_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/filters?max-results=" + connectorProperties.getProperty("coreReportMaxResults") + "&start-index=" + connectorProperties.getProperty("coreReportStartIndex") + "&prettyPrint=true"; 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(connectorProperties.getProperty("coreReportStartIndex"), apiResponse.getString("startIndex")); Assert.assertEquals(connectorProperties.getProperty("coreReportMaxResults"), apiResponse.getString("itemsPerPage")); Assert.assertEquals(esbResponse.getJSONArray("items").length(), apiResponse.getJSONArray("items").length()); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listAccountUserLinks method with optional parameters. * * @throws org.json.JSONException// ww w. j av a 2s. c om * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listAccountUserLinks} integration test with optional parameters.", dependsOnMethods = { "testCreateFilterWithMandatoryParameters", "testCreateFilterWithOptionalParameters", "testListAccountSummariesWithMandatoryParameters" }) public void testListAccountUserLinksWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listAccountUserLinks"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listAccountUserLinks_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/entityUserLinks?max-results=" + connectorProperties.getProperty("linksMaxResults") + "&start-index=" + connectorProperties.getProperty("coreReportStartIndex") + "&prettyPrint=true" + "&fields=" + connectorProperties.getProperty("listLinkFields"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponse = apiRestResponse.getBody(); Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind")); Assert.assertEquals(esbResponse.getString("totalResults"), apiResponse.getString("totalResults")); Assert.assertEquals(connectorProperties.getProperty("coreReportStartIndex"), apiResponse.getString("startIndex")); Assert.assertEquals(esbResponse.getJSONArray("items").length(), Integer.parseInt(connectorProperties.getProperty("linksMaxResults"))); Assert.assertEquals(esbResponse.getJSONArray("items").length(), apiResponse.getJSONArray("items").length()); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listCustomDataSources method with mandatory parameters. * * @throws org.json.JSONException// ww w. j av a2 s. co m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listCustomDataSources} integration test with mandatory parameters.") public void testListCustomDataSourcesWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCustomDataSources"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCustomDataSources_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/customDataSources"; 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")); String customDataSourceId = esbResponse.getJSONArray("items").getJSONObject(0).getString("id"); connectorProperties.setProperty("customDataSourceId", customDataSourceId); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for createAdWordsLink method with mandatory parameters. * * @throws org.json.JSONException//from w w w. j a v a 2 s. c o m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {createAdWordsLink} integration test with mandatory parameters.") public void testCreateAdWordsLinkWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createAdWordsLink"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createAdWordsLink_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String adWordsLinkId = esbResponse.getString("id"); connectorProperties.put("adWordsLinkId", adWordsLinkId); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/entityAdWordsLinks/"; 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(connectorProperties.getProperty("adWordsLinkName"), apiResponse.getString("name")); Assert.assertEquals(connectorProperties.getProperty("adWordsLinkCustomerId"), apiResponse.getJSONArray("adWordsAccounts").getJSONObject(0).getString("customerId")); Assert.assertEquals(esbResponse.getString("selfLink"), apiResponse.getString("selfLink")); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listAdWordsLinks method with mandatory parameters. * * @throws org.json.JSONException//www.ja va2 s . c o m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listAdWordsLinks} integration test with mandatory parameters.", dependsOnMethods = { "testGetAdWordsLinkWithMandatoryParameters" }) public void testListAdWordsLinksWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listAdWordsLinks"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listAdWordsLinks_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/entityAdWordsLinks"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponse = apiRestResponse.getBody(); Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind")); Assert.assertEquals(esbResponse.getString("totalResults"), apiResponse.getString("totalResults")); Assert.assertEquals(esbResponse.getString("itemsPerPage"), apiResponse.getString("itemsPerPage")); Assert.assertEquals(esbResponse.getJSONArray("items").length(), apiResponse.getJSONArray("items").length()); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listCustomDimensions method with optional parameters. * * @throws org.json.JSONException//ww w. j av a 2s.co m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listCustomDimensions} integration test with optional parameters.", dependsOnMethods = { "testCreateCustomDimensionWithMandatoryParameters", "testCreateCustomDimensionWithOptionalParameters", "testListAccountSummariesWithMandatoryParameters" }) public void testListCustomDimensionsWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCustomDimensions"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCustomDimensions_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/customDimensions?max-results=" + connectorProperties.getProperty("coreReportMaxResults") + "&start-index=" + connectorProperties.getProperty("coreReportStartIndex") + "&prettyPrint=true" + "&fields=" + connectorProperties.getProperty("listFields"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponse = apiRestResponse.getBody(); Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind")); Assert.assertEquals(connectorProperties.getProperty("coreReportStartIndex"), apiResponse.getString("startIndex")); Assert.assertEquals(esbResponse.getJSONArray("items").length(), Integer.parseInt(connectorProperties.getProperty("coreReportMaxResults"))); Assert.assertEquals(esbResponse.getJSONArray("items").length(), apiResponse.getJSONArray("items").length()); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listCustomMetrics method with optional parameters. * * @throws org.json.JSONException// ww w. java2 s. c o m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listCustomMetrics} integration test with optional parameters.", dependsOnMethods = { "testCreateCustomMetricsWithOptionalParameters", "testCreateCustomMetricsWithMandatoryParameters", "testListAccountSummariesWithMandatoryParameters" }) public void testListCustomMetricsWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCustomMetrics"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCustomMetrics_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/customMetrics?max-results=" + connectorProperties.getProperty("coreReportMaxResults") + "&start-index=" + connectorProperties.getProperty("coreReportStartIndex") + "&prettyPrint=true" + "&fields=" + connectorProperties.getProperty("listFields"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponse = apiRestResponse.getBody(); Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind")); Assert.assertEquals(connectorProperties.getProperty("coreReportStartIndex"), apiResponse.getString("startIndex")); Assert.assertEquals(esbResponse.getJSONArray("items").length(), Integer.parseInt(connectorProperties.getProperty("coreReportMaxResults"))); Assert.assertEquals(esbResponse.getJSONArray("items").length(), apiResponse.getJSONArray("items").length()); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listConfigurationData method with mandatory parameters. * * @throws org.json.JSONException/* ww w . java 2 s.c om*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listConfigurationData} integration test with mandatory parameters.", dependsOnMethods = { "testListAccountSummariesWithMandatoryParameters" }) public void testListConfigurationDataWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listConfigurationData"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listConfigurationData_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/metadata/" + connectorProperties.getProperty("reportType") + "/columns"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponse = apiRestResponse.getBody(); Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind")); Assert.assertEquals(esbResponse.getString("etag"), apiResponse.getString("etag")); Assert.assertEquals(esbResponse.getString("totalResults"), apiResponse.getString("totalResults")); Assert.assertEquals(esbResponse.getJSONArray("items").length(), apiResponse.getJSONArray("items").length()); }
From source file:com.streaming.sweetplayer.fragment.TopFragment.java
private void getTopList() { JSONParser jsonParser = new JSONParser(); JSONArray jsonArray;/*from w w w. j av a2s .c o m*/ try { JSONObject json = jsonParser.getJSONFromUrl(Config.TOP_URL); if (json != null) { jsonArray = json.getJSONArray(Config.SONGS_ITEM); int array_length = jsonArray.length(); if (array_length > 0) { for (int i = 0; i < array_length; i++) { HashMap<String, String> map = new HashMap<String, String>(); JSONObject jsonObject = jsonArray.getJSONObject(i); map.put(Config.ID, jsonObject.getString(Config.ID)); map.put(Config.ARTIST, jsonObject.getString(Config.ARTIST)); map.put(Config.NAME, jsonObject.getString(Config.SONG)); map.put(Config.MP3, jsonObject.getString(Config.MP3)); map.put(Config.DURATION, jsonObject.getString(Config.DURATION)); map.put(Config.URL, jsonObject.getString(Config.URL)); map.put(Config.IMAGE, jsonObject.getString(Config.IMAGE)); mTopList.add(map); } } else { // Showing a message should be done in the UI thread. mActivity.runOnUiThread(new Runnable() { public void run() { Utils.showUserMessage(mActivity.getApplicationContext(), mActivity.getString(R.string.search_empty)); } }); } } } catch (JSONException e) { e.printStackTrace(); } }