List of usage examples for org.json JSONObject getString
public String getString(String key) throws JSONException
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for patchFilter method with optional parameters. * * @throws org.json.JSONException/*from ww w. j a v a 2 s. c o m*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {patchFilter} integration test with optional parameters.", dependsOnMethods = { "testCreateFilterWithOptionalParameters" }) public void testPatchFilterWithOptinalParameters() throws IOException, JSONException { final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/filters/" + connectorProperties.getProperty("filterIdOpt"); RestResponse<JSONObject> apiRestResponseBefore = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponseBefore = apiRestResponseBefore.getBody(); esbRequestHeadersMap.put("Action", "urn:patchFilter"); sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_patchFilter_optional.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")); }
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//from ww w . ja va2 s .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 w w w . j a va2s . 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 createAccountUserLink method with mandatory parameters. * * @throws org.json.JSONException/*from w w w . jav a2 s.com*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {createAccountUserLink} integration test with mandatory parameters.", dependsOnMethods = { "testListAccountSummariesWithMandatoryParameters" }) public void testCreateAccountUserLinkWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createAccountUserLink"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createAccountUserLink_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String userLinkId = esbResponse.getString("id"); connectorProperties.put("userLinkId", userLinkId); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/entityUserLinks"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONArray itemArray = apiRestResponse.getBody().getJSONArray("items"); String id; String email = ""; String permissions = ""; String selfLink = ""; for (int i = 0; i < itemArray.length(); i++) { id = itemArray.getJSONObject(i).getString("id"); if (id.equals(userLinkId)) { permissions = itemArray.getJSONObject(i).getJSONObject("permissions").toString(); email = itemArray.getJSONObject(i).getJSONObject("userRef").getString("email"); selfLink = itemArray.getJSONObject(i).getString("selfLink"); break; } } Assert.assertEquals(connectorProperties.getProperty("userLinkEmail"), email); Assert.assertEquals(esbResponse.getJSONObject("permissions").toString(), permissions); Assert.assertEquals(esbResponse.getString("selfLink"), selfLink); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for listAccountUserLinks method with mandatory parameters. * * @throws org.json.JSONException/* ww w. ja va2 s . c om*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listAccountUserLinks} integration test with mandatory parameters.", dependsOnMethods = { "testCreateAccountUserLinkWithMandatoryParameters", "testListAccountSummariesWithMandatoryParameters" }) public void testListAccountUserLinksWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listAccountUserLinks"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listAccountUserLinks_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/entityUserLinks"; 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.getString("startIndex"), apiResponse.getString("startIndex")); }
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/*w w w .j a va2 s . co m*/ * @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 listSegments method with mandatory parameters. * * @throws org.json.JSONException//from www . j av a 2s.c om * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listSegments} integration test with mandatory parameters.") public void testListSegmentsWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listSegments"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listSegments_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/segments"; 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 listSegments method with optional parameters. * * @throws org.json.JSONException/* w ww .j a v a 2s .c o m*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listSegments} integration test with optional parameters.") public void testListSegmentsWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listSegments"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listSegments_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/segments?max-results=" + connectorProperties.getProperty("segmentMaxResults") + "&start-index=" + connectorProperties.getProperty("segmentStartIndex"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponse = apiRestResponse.getBody(); Assert.assertEquals(connectorProperties.getProperty("segmentStartIndex"), apiResponse.getString("startIndex")); Assert.assertEquals(connectorProperties.getProperty("segmentMaxResults"), 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 listCustomDataSources method with mandatory parameters. * * @throws org.json.JSONException//from w w w . jav 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 listCustomDataSources method with optional parameters. * * @throws org.json.JSONException//from w ww. ja v a2 s. c o m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listCustomDataSources} integration test with optional parameters.") public void testListCustomDataSourcesWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listCustomDataSources"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listCustomDataSources_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/customDataSources?max-results=" + connectorProperties.getProperty("customDataSourceMaxResults") + "&start-index=" + connectorProperties.getProperty("customDataSourceStartIndex"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponse = apiRestResponse.getBody(); Assert.assertEquals(connectorProperties.getProperty("customDataSourceStartIndex"), apiResponse.getString("startIndex")); Assert.assertEquals(connectorProperties.getProperty("customDataSourceMaxResults"), apiResponse.getString("itemsPerPage")); Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind")); Assert.assertEquals(esbResponse.getString("username"), apiResponse.getString("username")); }