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 listCustomMetrics method with optional parameters.
 *
 * @throws org.json.JSONException//from   w  w 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 updateCustomMetrics method with mandatory parameters.
 *
 * @throws org.json.JSONException/*from   w w w.  j  av  a2s .c om*/
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {updateCustomMetrics} integration test with mandatory parameters.", dependsOnMethods = {
                "testCreateCustomMetricsWithMandatoryParameters",
                "testListAccountSummariesWithMandatoryParameters" })
public void testUpdateCustomMetricsWithMandatoryParameters() throws IOException, JSONException {

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

    esbRequestHeadersMap.put("Action", "urn:updateCustomMetrics");
    sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_updateCustomMetrics_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("updatedMetricsName"),
            apiResponseAfter.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("updatedMetricsScope"),
            apiResponseAfter.getString("scope"));
    Assert.assertEquals(connectorProperties.getProperty("updatedMetricsActive"),
            apiResponseAfter.getString("active"));

}

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

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

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

    esbRequestHeadersMap.put("Action", "urn:patchCustomMetrics");
    sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_patchCustomMetrics_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("updatedMetricsName"),
            apiResponseAfter.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("updatedMetricsScope"),
            apiResponseAfter.getString("scope"));
    Assert.assertEquals(connectorProperties.getProperty("updatedMetricsActive"),
            apiResponseAfter.getString("active"));

}

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

/**
 * Positive test case for createExperiment 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 {createExperiment} integration test with mandatory parameters.")
public void testCreateExperimentWithMandatoryParameters() throws IOException, JSONException {

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

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

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/profiles/"
            + connectorProperties.getProperty("experimentProfileId") + "/experiments/" + experimentId;

    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("internalWebPropertyId"),
            apiResponse.getString("internalWebPropertyId"));
    Assert.assertEquals(connectorProperties.getProperty("experimentName"), apiResponse.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("experimentStatus"), apiResponse.getString("status"));

}

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

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

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

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

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/profiles/"
            + connectorProperties.getProperty("experimentProfileId") + "/experiments/" + experimentId;
    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("experimentName"), apiResponse.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("experimentStatus"), apiResponse.getString("status"));
    Assert.assertEquals(connectorProperties.getProperty("experimentDescription"),
            apiResponse.getString("description"));

}

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

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

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/profiles/"
            + connectorProperties.getProperty("experimentProfileId") + "/experiments/"
            + connectorProperties.getProperty("experimentId");
    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("status"), apiResponse.getString("status"));
}

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

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

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/profiles/"
            + connectorProperties.getProperty("experimentProfileId") + "/experiments/"
            + connectorProperties.getProperty("experimentId") + "?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") + "/profiles/"
            + connectorProperties.getProperty("experimentProfileId") + "/experiments/"
            + connectorProperties.getProperty("experimentId");
    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 listExperiments method with mandatory 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 {listExperiments} integration test with mandatory parameters.", dependsOnMethods = {
                "testCreateExperimentWithMandatoryParameters" })
public void testListExperimentsWithMandatoryParameters() throws IOException, JSONException {

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/profiles/"
            + connectorProperties.getProperty("experimentProfileId") + "/experiments";

    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 listExperiments method with optional parameters.
 *
 * @throws org.json.JSONException//from  www.ja  va  2 s .  co m
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {listExperiments} integration test with optional parameters.", dependsOnMethods = {
                "testCreateExperimentWithMandatoryParameters", "testCreateExperimentWithOptionalParameters" })
public void testListExperimentsWithOptionalParameters() throws IOException, JSONException {

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/management/accounts/"
            + connectorProperties.getProperty("accountId") + "/webproperties/"
            + connectorProperties.getProperty("webPropertyId") + "/profiles/"
            + connectorProperties.getProperty("experimentProfileId") + "/experiments?max-results="
            + connectorProperties.getProperty("experimentMaxResults") + "&start-index="
            + connectorProperties.getProperty("experimentStartIndex");

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

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(connectorProperties.getProperty("experimentStartIndex"),
            apiResponse.getString("startIndex"));
    Assert.assertEquals(connectorProperties.getProperty("experimentMaxResults"),
            apiResponse.getString("itemsPerPage"));
    Assert.assertEquals(esbResponse.getString("startIndex"), apiResponse.getString("startIndex"));
    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));

}

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

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

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

    final JSONObject apiResponseBefore = apiRestResponseBefore.getBody();

    esbRequestHeadersMap.put("Action", "urn:updateExperiment");
    sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_updateExperiment_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("status"), apiResponseAfter.getString("status"));

    Assert.assertEquals(connectorProperties.getProperty("experimentUpdatedName"),
            apiResponseAfter.getString("name"));
    Assert.assertEquals(connectorProperties.getProperty("experimentUpdatedStatus"),
            apiResponseAfter.getString("status"));

}