Example usage for org.json JSONObject toString

List of usage examples for org.json JSONObject toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Make a JSON text of this JSONObject.

Usage

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Positive test case for deleteComment method with mandatory parameters.
 *//*from   www.  j  a v a 2s  . c  om*/
@Test(dependsOnMethods = { "testFlickrAddCommentWithMandatoryParameters",
        "testFlickrEditCommentWithMandatoryParameters" }, priority = 1, groups = {
                "wso2.esb" }, description = "flickr {deleteComment} integration test with mandatory parameters")
public void testFlickrDeleteCommentWithMandatoryParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_deleteComment.txt";
    String methodName = "flickr_deleteComment";

    String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    rawString = rawString.replace("dummyvalue", addCommentMethodCommentId);
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json&nojsoncallback=1&method=flickr.photos.comments.getList&api_key="
                + flickrConnectorProperties.getProperty("consumerKey") + "&photo_id="
                + flickrConnectorProperties.getProperty("photoId");
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(!responseDirect.toString().contains(addCommentMethodCommentId));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Positive test case for getRecentCommentsForContacts method with mandatory parameters.
 *///from ww  w . j a va  2 s  .  co  m
@Test(priority = 1, groups = {
        "wso2.esb" }, description = "flickr {isLogged} integration test with mandatory parameters.")
public void testFlickrGetRecentCommentsForContactsWithMandatoryParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_getRecentCommentsForContacts.txt";
    String methodName = "flickr_getRecentCommentsForContacts";

    final String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json" + "&method=flickr.photos.comments.getRecentForContacts"
                + "&nojsoncallback=1" + "&oauth_consumer_key="
                + flickrConnectorProperties.getProperty("consumerKey") + "&oauth_nonce=dummynonce"
                + "&oauth_signature_method=HMAC-SHA1" + "&oauth_timestamp=dummytimestamp" + "&oauth_token="
                + flickrConnectorProperties.getProperty("accessToken") + "&oauth_version=1.0";
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(true, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(responseConnector.toString().equals(responseDirect.toString()));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Positive test case for getInfo method with mandatory parameters.
 *///  w w  w  . j a  v a  2 s.c  o m
@Test(priority = 1, groups = {
        "wso2.esb" }, description = "flickr {getInfo} integration test with mandatory parameters")
public void testFlickrGetInfoWithMandatoryParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_getInfo.txt";
    String methodName = "flickr_getInfo";

    String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    rawString = rawString.replace("dummyvalue", flickrConnectorProperties.getProperty("userId"));
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json&nojsoncallback=1&method=flickr.people.getInfo&api_key="
                + flickrConnectorProperties.getProperty("consumerKey") + "&user_id="
                + flickrConnectorProperties.getProperty("userId");
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(responseConnector.toString().equals(responseDirect.toString()));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Positive test case for getPhotos method with mandatory parameters.
 *///from w ww  .  j  a  va 2s  .c o m
@Test(priority = 1, groups = {
        "wso2.esb" }, description = "flickr {getPhotos} integration test with mandatory parameters")
public void testFlickrGetPhotosWithMandatoryParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_getPhotos.txt";
    String methodName = "flickr_getPhotos";

    String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    rawString = rawString.replace("dummyvalue", flickrConnectorProperties.getProperty("userId"));
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json&nojsoncallback=1&method=flickr.people.getPhotos&api_key="
                + flickrConnectorProperties.getProperty("consumerKey") + "&user_id="
                + flickrConnectorProperties.getProperty("userId");
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(responseConnector.toString().equals(responseDirect.toString()));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Positive test case for getPhotoInfo method with mandatory parameters.
 *///from   ww  w .  j a v a 2s  . com
@Test(priority = 1, groups = {
        "wso2.esb" }, description = "flickr {getPhotoInfo} integration test with mandatory parameters")
public void testFlickrGetPhotoInfoWithMandatoryParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_getPhotoInfo.txt";
    String methodName = "flickr_getPhotoInfo";

    String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    rawString = rawString.replace("dummyvalue", flickrConnectorProperties.getProperty("photoId"));
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json&nojsoncallback=1&method=flickr.photos.getInfo&api_key="
                + flickrConnectorProperties.getProperty("consumerKey") + "&photo_id="
                + flickrConnectorProperties.getProperty("photoId");
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(responseConnector.toString().equals(responseDirect.toString()));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Positive test case for getExif method with mandatory parameters.
 *//*from w  w  w.j  a  v  a 2  s  . c  o m*/
@Test(priority = 1, groups = {
        "wso2.esb" }, description = "flickr {getExif} integration test with mandatory parameters")
public void testFlickrGetExifWithMandatoryParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_getExif.txt";
    String methodName = "flickr_getExif";

    String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    rawString = rawString.replace("dummyvalue", flickrConnectorProperties.getProperty("photoId"));
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json&nojsoncallback=1&method=flickr.photos.getExif&api_key="
                + flickrConnectorProperties.getProperty("consumerKey") + "&photo_id="
                + flickrConnectorProperties.getProperty("photoId");
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(responseConnector.toString().equals(responseDirect.toString()));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Positive test case for addTags method with mandatory parameters.
 *///w ww  .  ja  va2  s .  c  om
@Test(priority = 1, groups = {
        "wso2.esb" }, description = "flickr {addTags} integration test with mandatory parameters")
public void testFlickrAddTagsWithMandatoryParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_addTags.txt";
    String methodName = "flickr_addTags";

    String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    rawString = rawString.replace("dummyvalue", flickrConnectorProperties.getProperty("photoId"));
    rawString = rawString.replace("tagName",
            flickrConnectorProperties.getProperty("tagName") + System.currentTimeMillis());
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json&nojsoncallback=1&method=flickr.photos.getInfo&api_key="
                + flickrConnectorProperties.getProperty("consumerKey") + "&photo_id="
                + flickrConnectorProperties.getProperty("photoId");
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters,
                flickrConnectorProperties);
        addTagMethodTagId = ((JSONObject) responseConnector.getJSONObject("tags").getJSONArray("tag").get(0))
                .getString("full_tag_id");
        Assert.assertTrue(responseDirect.toString().contains(addTagMethodTagId));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Positive test case for removeTag method with mandatory parameters.
 *///from   www.j  ava 2s  . c  o  m
@Test(dependsOnMethods = { "testFlickrAddTagsWithMandatoryParameters" }, priority = 1, groups = {
        "wso2.esb" }, description = "flickr {removeTag} integration test with mandatory parameters")
public void testFlickrRemoveTagWithMandatoryParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_removeTag.txt";
    String methodName = "flickr_removeTag";

    String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    rawString = rawString.replace("dummyvalue", addTagMethodTagId);
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json&nojsoncallback=1&method=flickr.photos.getInfo&api_key="
                + flickrConnectorProperties.getProperty("consumerKey") + "&photo_id="
                + flickrConnectorProperties.getProperty("photoId");
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(!responseDirect.toString().contains(addTagMethodTagId));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Negative test case for echo method with Negative parameters.
 *///from  w w w  . j  av  a2 s .  co  m
@Test(priority = 2, groups = {
        "wso2.esb" }, description = "flickr {echo} integration test with Negative parameters")
public void testFlickrEchoWithNegativeParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_echo.txt";
    String methodName = "flickr_echo";

    final String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + "/negetive/" + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json&nojsoncallback=1&method=flickr.test.echo&api_key="
                + flickrConnectorProperties.getProperty("invalidConsumerKey") + "&value=wso2-esb";
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(false, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(responseConnector.getString("stat").equals("fail")
                && responseConnector.toString().equals(responseDirect.toString()));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.flickr.FlickrConnectoreIntegrationTest.java

/**
 * Negative test case for isLogged method with Negative parameters.
 *///from w w  w .  ja v  a2 s . c  om
@Test(priority = 2, groups = {
        "wso2.esb" }, description = "flickr {isLogged} integration test with Negative parameters.")
public void testFlickrIsLoggedWithNegativeParameters() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "flickr_isLogged.txt";
    String methodName = "flickr_isLogged";

    final String rawString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String jsonString = addCredentials(rawString);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + "/negetive/" + methodName + ".xml";

    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));

    try {
        JSONObject responseConnector = ConnectorIntegrationUtil.sendRequest("POST",
                getProxyServiceURL(methodName), jsonString);

        String httpMethod = "GET";
        String parameters = "format=json" + "&method=flickr.test.login" + "&nojsoncallback=1"
                + "&oauth_consumer_key=" + flickrConnectorProperties.getProperty("consumerKey")
                + "&oauth_nonce=dummynonce" + "&oauth_signature_method=HMAC-SHA1"
                + "&oauth_timestamp=dummytimestamp" + "&oauth_token="
                + flickrConnectorProperties.getProperty("invalidAccessToken") + "&oauth_version=1.0";
        JSONObject responseDirect = ConnectorIntegrationUtil.sendRestRequest(true, httpMethod, parameters,
                flickrConnectorProperties);
        Assert.assertTrue(responseConnector.getString("stat").equals("fail")
                && responseConnector.toString().equals(responseDirect.toString()));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}