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 createAdWordsLink method with mandatory parameters. * * @throws org.json.JSONException/* ww w . j a v a2s .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 getAdWordsLink method with mandatory parameters. * * @throws org.json.JSONException//from w ww.j a va 2s . c o m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {getAdWordsLink} integration test with mandatory parameters.", dependsOnMethods = { "testCreateAdWordsLinkWithMandatoryParameters" }) public void testGetAdWordsLinkWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:getAdWordsLink"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_getAdWordsLink_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/entityAdWordsLinks/" + connectorProperties.getProperty("adWordsLinkId"); 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")); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for getAdWordsLink method with optional parameters. * * @throws org.json.JSONException// www. j a v a 2 s . c om * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {getAdWordsLink} integration test with optional parameters.", dependsOnMethods = { "testCreateAdWordsLinkWithMandatoryParameters" }) public void testGetAdWordsLinkWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:getAdWordsLink"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_getAdWordsLink_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/entityAdWordsLinks/" + connectorProperties.getProperty("adWordsLinkId") + "?prettyPrint=" + connectorProperties.getProperty("prettyPrint") + "&fields=" + connectorProperties.getProperty("fields"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final String apiEndpointNoFields = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/entityAdWordsLinks/" + connectorProperties.getProperty("adWordsLinkId"); RestResponse<JSONObject> apiRestResponseWithField = sendJsonRestRequest(apiEndpointNoFields, "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 listAdWordsLinks method with mandatory parameters. * * @throws org.json.JSONException/*from w w w .j a v a 2s . com*/ * @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 listAdWordsLinks method with optional parameters. * * @throws org.json.JSONException//from w ww .ja v a2 s . co m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {listAdWordsLinks} integration test with optional parameters.", dependsOnMethods = { "testGetAdWordsLinkWithMandatoryParameters" }) public void testListAdWordsLinksWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:listAdWordsLinks"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listAdWordsLinks_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/entityAdWordsLinks?max-results=" + connectorProperties.getProperty("adWordsLinkMaxResults") + "&start-index=" + connectorProperties.getProperty("adWordsLinkStartIndex"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponse = apiRestResponse.getBody(); Assert.assertEquals(connectorProperties.getProperty("adWordsLinkMaxResults"), apiResponse.getString("itemsPerPage")); Assert.assertEquals(connectorProperties.getProperty("adWordsLinkStartIndex"), apiResponse.getString("startIndex")); Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind")); Assert.assertEquals(esbResponse.getString("totalResults"), apiResponse.getString("totalResults")); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for updateAdWordsLink method with mandatory parameters. * * @throws org.json.JSONException/* w w w. j av a 2s . co m*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {updateAdWordsLink} integration test with mandatory parameters.", dependsOnMethods = { "testCreateAdWordsLinkWithMandatoryParameters" }) public void testUpdateAdWordsLinkWithMandatoryParameters() throws IOException, JSONException { final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/entityAdWordsLinks/" + connectorProperties.getProperty("adWordsLinkId"); RestResponse<JSONObject> apiRestResponseBefore = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponseBefore = apiRestResponseBefore.getBody(); esbRequestHeadersMap.put("Action", "urn:updateAdWordsLink"); sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_updateAdWordsLink_mandatory.json"); RestResponse<JSONObject> apiRestResponseAfter = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponseAfter = apiRestResponseAfter.getBody(); Assert.assertNotEquals(apiResponseBefore.getString("name"), apiResponseAfter.getString("name")); Assert.assertEquals(connectorProperties.getProperty("adWordsLinkUpdatedName"), apiResponseAfter.getString("name")); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for patchAdWordsLink method with optional parameters. * * @throws org.json.JSONException/*from w w w. j av a2 s . c o m*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {patchAdWordsLink} integration test with optional parameters.", dependsOnMethods = { "testCreateAdWordsLinkWithMandatoryParameters" }) public void testPatchAdWordsLinkWithOptinalParameters() throws IOException, JSONException { final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/entityAdWordsLinks/" + connectorProperties.getProperty("adWordsLinkId"); RestResponse<JSONObject> apiRestResponseBefore = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); esbRequestHeadersMap.put("Action", "urn:patchAdWordsLink"); sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_patchAdWordsLink_optional.json"); RestResponse<JSONObject> apiRestResponseAfter = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final JSONObject apiResponseAfter = apiRestResponseAfter.getBody(); Assert.assertNotEquals(apiRestResponseBefore.getBody().getString("name"), apiRestResponseAfter.getBody().getString("name")); Assert.assertEquals(connectorProperties.getProperty("adWordsLinkPatchName"), apiResponseAfter.getString("name")); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for createCustomDimension method with mandatory parameters. * * @throws org.json.JSONException//from ww w. ja va 2 s .c om * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {createCustomDimension} integration test with mandatory parameters.", dependsOnMethods = { "testListAccountSummariesWithMandatoryParameters" }) public void testCreateCustomDimensionWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createCustomDimension"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createCustomDimension_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String dimensionId = esbResponse.getString("id"); connectorProperties.put("dimensionId", dimensionId); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/customDimensions/" + dimensionId; 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("dimensionName"), apiResponse.getString("name")); Assert.assertEquals(connectorProperties.getProperty("dimensionScope"), apiResponse.getString("scope")); Assert.assertEquals(connectorProperties.getProperty("dimensionActive"), apiResponse.getString("active")); }
From source file:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java
/** * Positive test case for createCustomDimension method with optional parameters. * * @throws org.json.JSONException// w w w . j a va 2 s .c o m * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {createCustomDimension} integration test with optional parameters.", dependsOnMethods = { "testListAccountSummariesWithMandatoryParameters" }) public void testCreateCustomDimensionWithOptionalParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:createCustomDimension"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_createCustomDimension_optional.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String dimensionIdOpt = esbResponse.getString("id"); connectorProperties.put("dimensionIdOpt", dimensionIdOpt); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/customDimensions/" + dimensionIdOpt + "?fields=" + connectorProperties.getProperty("fields"); RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap); final String apiEndpoint1 = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/customDimensions/" + dimensionIdOpt; RestResponse<JSONObject> apiRestResponseWithField = sendJsonRestRequest(apiEndpoint1, "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 getCustomDimension method with mandatory parameters. * * @throws org.json.JSONException/*from w ww. j a v a 2 s . co m*/ * @throws java.io.IOException */ @Test(groups = { "wso2.esb" }, description = "googleanalytics {getCustomDimension} integration test with mandatory parameters.", dependsOnMethods = { "testCreateCustomDimensionWithMandatoryParameters", "testListAccountSummariesWithMandatoryParameters" }) public void testGetCustomDimensionWithMandatoryParameters() throws IOException, JSONException { esbRequestHeadersMap.put("Action", "urn:getCustomDimension"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_getCustomDimension_mandatory.json"); final JSONObject esbResponse = esbRestResponse.getBody(); final String apiEndpoint = apiEndpointUrl + "/management/accounts/" + connectorProperties.getProperty("accountId") + "/webproperties/" + connectorProperties.getProperty("webPropertyId") + "/customDimensions/" + connectorProperties.getProperty("dimensionId"); 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.getString("name"), apiResponse.getString("name")); Assert.assertEquals(esbResponse.getString("created"), apiResponse.getString("created")); }