Example usage for org.json JSONObject has

List of usage examples for org.json JSONObject has

Introduction

In this page you can find the example usage for org.json JSONObject has.

Prototype

public boolean has(String key) 

Source Link

Document

Determine if the JSONObject contains a specific key.

Usage

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// w w w . ja va2 s.c o  m
 * @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 createCustomDimension method with optional parameters.
 *
 * @throws org.json.JSONException//w ww  . ja  v a  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 optional parameters.
 *
 * @throws org.json.JSONException//from   w w w  .j av a2s.  com
 * @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 createCustomMetrics 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 {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 optional parameters.
 *
 * @throws org.json.JSONException/*from  w ww.  j  a  va 2  s  .co m*/
 * @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 getExperiment method with optional parameters.
 *
 * @throws org.json.JSONException/* w w  w.  j  a v  a2s .  co  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 listConfigurationData method with optional parameters.
 *
 * @throws org.json.JSONException//from w  w w  .  j av  a  2  s  . c o  m
 * @throws java.io.IOException
 */
@Test(groups = {
        "wso2.esb" }, description = "googleanalytics {listConfigurationData} integration test with optional parameters.", dependsOnMethods = {
                "testListAccountSummariesWithMandatoryParameters" })
public void testListConfigurationDataWithOptionalParameters() throws IOException, JSONException {

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

    final JSONObject esbResponse = esbRestResponse.getBody();

    final String apiEndpoint = apiEndpointUrl + "/metadata/" + connectorProperties.getProperty("reportType")
            + "/columns?fields=" + connectorProperties.getProperty("configFields");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndpoint, "GET", apiRequestHeadersMap);

    final String apiEndpoint1 = apiEndpointUrl + "/metadata/" + connectorProperties.getProperty("reportType")
            + "/columns";
    RestResponse<JSONObject> apiRestResponseWithoutFields = sendJsonRestRequest(apiEndpoint1, "GET",
            apiRequestHeadersMap);

    final JSONObject apiResponse = apiRestResponse.getBody();

    Assert.assertEquals(esbResponse.getString("kind"), apiResponse.getString("kind"));
    Assert.assertEquals(esbResponse.getString("etag"), apiResponse.getString("etag"));
    Assert.assertFalse(esbResponse.has("totalResults"));
    Assert.assertFalse(apiResponse.has("totalResults"));
    Assert.assertTrue(apiRestResponseWithoutFields.getBody().has("totalResults"));
}

From source file:com.hyphenated.pokerplayerclient.domain.PlayerStatus.java

public PlayerStatus(JSONObject json) {
    try {//from   w  w w .  j  a  v  a  2 s . c om
        status = PlayerStatusType.valueOf(json.getString("status"));
        if (json.has("card1")) {
            this.card1 = Card.getCardByIdentifier(json.getString("card1"));
            this.card2 = Card.getCardByIdentifier(json.getString("card2"));
        }
        if (json.has("chips")) {
            this.chips = json.getInt("chips");
        }
        if (json.has("amountBetRound")) {
            this.amountBetRound = json.getInt("amountBetRound");
        }
        if (json.has("amountToCall")) {
            this.amountToCall = json.getInt("amountToCall");
        }
        if (json.has("smallBlind")) {
            this.smallBlind = json.getInt("smallBlind");
        }
        if (json.has("bigBlind")) {
            this.bigBlind = json.getInt("bigBlind");
        }
    } catch (JSONException e) {
        Log.e("Poker", e.getMessage());
    }
}

From source file:com.imaginary.home.cloud.device.Device.java

static void mapDevice(@Nonnull ControllerRelay relay, @Nonnull JSONObject json,
        @Nonnull Map<String, Object> state) throws JSONException {
    state.put("relayId", relay.getControllerRelayId());
    state.put("deviceId", UUID.randomUUID().toString());
    if (json.has("name") && !json.isNull("name")) {
        state.put("name", json.getString("name"));
    }/* w  w  w  .j  a v  a 2  s. com*/
    if (json.has("description") && !json.isNull("description")) {
        state.put("description", json.getString("description"));
    }
    if (json.has("model") && !json.isNull("model")) {
        state.put("model", json.getString("model"));
    }
    if (json.has("deviceId") && !json.isNull("deviceId")) {
        state.put("vendorDeviceId", json.getString("deviceId"));
    }
    if (json.has("systemId") && !json.isNull("systemId")) {
        state.put("homeAutomationSystemId", json.getString("systemId"));
    }
}

From source file:com.flurry.samples.tumblrsharing.PhotoFeedActivity.java

/**
 * Method to display photo feed./*from w  w  w .  ja  v  a  2s.  c  om*/
 * */
private void fetchPhotoFeed() {
    flickrClient = new FlickrClient();

    HashMap<String, String> fetchPhotosEventParams = new HashMap<>(1);
    fetchPhotosEventParams.put(AnalyticsHelper.PARAM_LOCATION, String.valueOf(lastLocation));
    AnalyticsHelper.logEvent(AnalyticsHelper.EVENT_FETCH_PHOTOS, fetchPhotosEventParams, true);

    flickrClient.getPhotoFeed(lastLocation, new JsonHttpResponseHandler() {

        @Override
        public void onSuccess(int code, Header[] headers, JSONObject body) {

            AnalyticsHelper.endTimedEvent(AnalyticsHelper.EVENT_FETCH_PHOTOS);

            JSONObject photosObject = null;
            if (body != null) {
                try {
                    if (body.has("photos")) {
                        photosObject = body.getJSONObject("photos");
                        JSONArray photoArray = photosObject.getJSONArray("photo");
                        List<Photo> photosList = Photo.fromJson(photoArray);
                        photoAdapter.addPhotos(photosList);
                        photoAdapter.notifyDataSetChanged();
                    } else {
                        Toast.makeText(getApplicationContext(), "Flickr Api error.", Toast.LENGTH_LONG).show();
                        finish();
                    }
                } catch (JSONException e) {
                    AnalyticsHelper.logError(LOG_TAG, "Photo Feed JSON Error", e);
                }
            } else {
                Toast.makeText(getApplicationContext(), "Flickr Api error.", Toast.LENGTH_LONG).show();
                AnalyticsHelper.logError(LOG_TAG, "Response body is null", null);
                finish();
            }

        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            super.onFailure(statusCode, headers, responseString, throwable);
            Toast.makeText(getApplicationContext(), "Flickr Api error.", Toast.LENGTH_LONG).show();
            AnalyticsHelper.logError(LOG_TAG, "Failure in fetching photo feed", null);
            finish();
        }
    });
}