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:org.wso2.carbon.connector.integration.test.googleanalytics.GoogleanalyticsConnectorIntegrationTest.java

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

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customDimensions/"
            + connectorProperties.getProperty("dimensionId") + "?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/"
            + connectorProperties.getProperty("dimensionId");
    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 listCustomDimensions method with mandatory parameters.
 *
 * @throws org.json.JSONException/*www  .  j a va2s. c  om*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {listCustomDimensions} integration test with mandatory parameters.", dependsOnMethods = {
                "testCreateCustomDimensionWithMandatoryParameters",
                "testListAccountSummariesWithMandatoryParameters" })
public void testListCustomDimensionsWithMandatoryParameters() throws IOException, JSONException {

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customDimensions";
    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 listCustomDimensions method with optional parameters.
 *
 * @throws org.json.JSONException/* www .  j  a  v  a2s  . c om*/
 * @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 updateCustomDimension method with mandatory parameters.
 *
 * @throws org.json.JSONException/*from   www . jav  a 2  s.  c  o m*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {updateCustomDimension} integration test with mandatory parameters.", dependsOnMethods = {
                "testCreateCustomDimensionWithMandatoryParameters",
                "testListAccountSummariesWithMandatoryParameters" })
public void testUpdateCustomDimensionWithMandatoryParameters() throws IOException, JSONException {

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customDimensions/"
            + connectorProperties.getProperty("dimensionId");
    RestResponse<JSONObject> apiRestResponseBefore = sendJsonRestRequest(apiEndpoint, "GET",
            apiRequestHeadersMap);

    esbRequestHeadersMap.put("Action", "urn:updateCustomDimension");
    sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_updateCustomDimension_mandatory.json");

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

    final JSONObject apiResponseBefore = apiRestResponseBefore.getBody();
    final JSONObject apiResponseAfter = apiRestResponseAfter.getBody();

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

    Assert.assertEquals(connectorProperties.getProperty("updatedDimensionName"),
            apiResponseAfter.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("updatedDimensionScope"),
            apiResponseAfter.getString("scope"));
    Assert.assertEquals(connectorProperties.getProperty("updatedDimensionActive"),
            apiResponseAfter.getString("active"));

}

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

/**
 * Positive test case for patchCustomDimension method with optional parameters.
 *
 * @throws org.json.JSONException/*from  www. j a  v a  2 s.c o m*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {patchCustomDimension} integration test with optional parameters.", dependsOnMethods = {
                "testCreateCustomDimensionWithOptionalParameters",
                "testListAccountSummariesWithMandatoryParameters" })
public void testPatchCustomDimensionWithOptinalParameters() throws IOException, JSONException {

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customDimensions/"
            + connectorProperties.getProperty("dimensionIdOpt");
    RestResponse<JSONObject> apiRestResponseBefore = sendJsonRestRequest(apiEndpoint, "GET",
            apiRequestHeadersMap);

    esbRequestHeadersMap.put("Action", "urn:patchCustomDimension");
    sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_patchCustomDimension_optional.json");

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

    final JSONObject apiResponseBefore = apiRestResponseBefore.getBody();
    final JSONObject apiResponseAfter = apiRestResponseAfter.getBody();

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

    Assert.assertEquals(connectorProperties.getProperty("patchDimensionName"),
            apiResponseAfter.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("patchDimensionScope"),
            apiResponseAfter.getString("scope"));
    Assert.assertEquals(connectorProperties.getProperty("patchDimensionActive"),
            apiResponseAfter.getString("active"));

}

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

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

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String metricsId = esbResponse.getString("id");
    connectorProperties.put("metricsId", metricsId);

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customMetrics/" + metricsId;
    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("metricsName"), apiResponse.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("metricsScope"), apiResponse.getString("scope"));
    Assert.assertEquals(connectorProperties.getProperty("metricsType"), 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 createCustomMetrics method with optional parameters.
 *
 * @throws org.json.JSONException/*  w w  w  . j a v  a 2s . c o m*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {createCustomMetrics} integration test with optional parameters.", dependsOnMethods = {
                "testListAccountSummariesWithMandatoryParameters" })
public void testCreateCustomMetricsWithOptionalParameters() throws IOException, JSONException {

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

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

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

    final String apiEndpoint1 = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customMetrics/" + metricsOptId;
    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 getCustomMetrics method with mandatory parameters.
 *
 * @throws org.json.JSONException//from   w w w  .j  a v  a2 s .  c om
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {getCustomMetrics} integration test with mandatory parameters.", dependsOnMethods = {
                "testCreateCustomMetricsWithMandatoryParameters",
                "testListAccountSummariesWithMandatoryParameters" })
public void testGetCustomMetricsWithMandatoryParameters() throws IOException, JSONException {

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customMetrics/"
            + connectorProperties.getProperty("metricsId");
    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"));
}

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

/**
 * Positive test case for getCustomMetrics method with optional parameters.
 *
 * @throws org.json.JSONException/*from   w  w w  .  j av  a  2s.com*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {getCustomMetrics} integration test with optional parameters.", dependsOnMethods = {
                "testCreateCustomMetricsWithMandatoryParameters",
                "testListAccountSummariesWithMandatoryParameters" })
public void testGetCustomMetricsWithOptionalParameters() throws IOException, JSONException {

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

    final JSONObject esbResponse = esbRestResponse.getBody();

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

    final String apiEndpoint1 = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customMetrics/"
            + connectorProperties.getProperty("metricsId");
    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 listCustomMetrics method with mandatory parameters.
 *
 * @throws org.json.JSONException/*from  www .ja va2 s .  c  o m*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {listCustomMetrics} integration test with mandatory parameters.", dependsOnMethods = {
                "testCreateCustomMetricsWithMandatoryParameters",
                "testListAccountSummariesWithMandatoryParameters" })
public void testListCustomMetricsWithMandatoryParameters() throws IOException, JSONException {

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/customMetrics";
    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"));
}