Example usage for org.json JSONObject append

List of usage examples for org.json JSONObject append

Introduction

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

Prototype

public JSONObject append(String key, Object value) throws JSONException 

Source Link

Document

Append values to the array under a key.

Usage

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Optional parameter test case for ListComments method with pageToken,fields optional parameter
 *///from   w  ww  . j  a va  2 s  .  c om
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListCommentsWithMandatoryParams" }, description = "GooglePlus {ListComments} integration test with mandatory and language,fields optional parameters.")
public void testListCommentsWithTwoOptionalParams5() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listCommentsOptionalParams.txt";
    String methodName = "listComments";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("activityId", googlePlusConnectorProperties.getProperty("activityId"));
    jsonObject.append("pageToken", googlePlusConnectorProperties.getProperty("listCommentsPageToken"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        String[] unneededOptionalParameters = { "maxResults", "sortOrder" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#commentFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Optional parameter test case for ListComments method with sortOrder,fields optional parameter.
 *//*  w  ww .j av a 2  s . c  om*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListCommentsWithMandatoryParams" }, description = "GooglePlus {ListComments} integration test with mandatory and sortOrder,fields optional parameters.")
public void testListCommentsWithTwoOptionalParams6() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listCommentsOptionalParams.txt";
    String methodName = "listComments";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("activityId", googlePlusConnectorProperties.getProperty("activityId"));
    jsonObject.append("pageToken", googlePlusConnectorProperties.getProperty("listCommentsPageToken"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        String[] unneededOptionalParameters = { "maxResults", "pageToken" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#commentFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Optional parameter "pageToken", "sortOrder", "fields"  check
 *
 * @throws Exception/* w  w w.  j a  v  a2  s. c  o  m*/
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with optional parameter pageToken, sortOrder, fields.")
public void testListCommentsThreeOptionalParam1() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listCommentsOptionalParams.txt";
    String methodName = "listComments";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("activityId", googlePlusConnectorProperties.getProperty("activityId"));
    jsonObject.append("pageToken", googlePlusConnectorProperties.getProperty("listCommentsPageToken"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        String[] unneededOptionalParameters = { "maxResults" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#commentFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Optional parameter "maxResults", "sortOrder", "fields" check
 *
 * @throws Exception//w  w w .j  a  v a 2  s. com
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with optional parameter maxResults, sortOrder, fields.")
public void testListCommentsThreeOptionalParam2() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listCommentsOptionalParams.txt";
    String methodName = "listComments";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("activityId", googlePlusConnectorProperties.getProperty("activityId"));
    jsonObject.append("pageToken", googlePlusConnectorProperties.getProperty("listCommentsPageToken"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        String[] unneededOptionalParameters = { "pageToken" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#commentFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Optional parameter "maxResults", "pageToken", "fields"  check
 *
 * @throws Exception//w w w . j a va2 s.  com
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with optional parameter maxResults, pageToken, fields.")
public void testListCommentsThreeOptionalParam3() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listCommentsOptionalParams.txt";
    String methodName = "listComments";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("activityId", googlePlusConnectorProperties.getProperty("activityId"));
    jsonObject.append("pageToken", googlePlusConnectorProperties.getProperty("listCommentsPageToken"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        String[] unneededOptionalParameters = { "sortOrder" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#commentFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Optional parameter "maxResults", "pageToken", "sortOrder" check
 *
 * @throws Exception//from  w  ww  .j av  a 2s  .  co m
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with optional parameter maxResults, pageToken, sortOrder.")
public void testListCommentsThreeOptionalParam4() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listCommentsOptionalParams.txt";
    String methodName = "listComments";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("activityId", googlePlusConnectorProperties.getProperty("activityId"));
    jsonObject.append("pageToken", googlePlusConnectorProperties.getProperty("listCommentsPageToken"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        String[] unneededOptionalParameters = { "fields" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#commentFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Mandatory parameter test case for getPeople method.
 *///w  w  w.  j  a v a 2s . c om
@Test(groups = {
        "wso2.esb" }, description = "GooglePlus {getPeople} integration test with mandatory parameters.")
public void testGetPeopleWithMandatoryParams() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "getPeople.txt";
    String methodName = "getPeople";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("userId", googlePlusConnectorProperties.getProperty("userId"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {

        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                modifiedJsonString);
        junit.framework.Assert.assertEquals("plus#person", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Optional parameter test case for getPeople method.
 *///  w ww. j a va 2  s.  c  o  m
@Test(groups = {
        "wso2.esb" }, description = "GooglePlus {getPeople} integration test with mandatory and optional parameters.")
public void testGetPeopleWithOptionalParams() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "getPeopleOptionalParams.txt";
    String methodName = "getPeople";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("userId", googlePlusConnectorProperties.getProperty("userId"));
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                modifiedJsonString);
        junit.framework.Assert.assertEquals("plus#person", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Negative parameter test case for getPeople method.
 *//* ww w. j a v  a  2  s.com*/
@Test(groups = {
        "wso2.esb" }, description = "GooglePlus {getPeople} integration test with Negative parameters.")
public void testGetPeopleWithNegativeParams() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "getPeopleUnhappy.txt";
    String methodName = "getPeople";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {

        int statusCode = ConnectorIntegrationUtil.sendRequestToRetrieveHeaders(getProxyServiceURL(methodName),
                modifiedJsonString);
        junit.framework.Assert.assertTrue(statusCode == 404 || statusCode == 403);
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java

/**
 * Mandatory parameter test case for searchPeople method.
 *///ww w.  j  a  v a 2  s  .com
@Test(groups = {
        "wso2.esb" }, description = "GooglePlus {searchPeople} integration test with mandatory parameters.")
public void testSearchPeopleWithMandatoryParams() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "searchPeople.txt";
    String methodName = "searchPeople";
    final String requestJsonString = ConnectorIntegrationUtil.getFileContent(jsonRequestFilePath);
    final String proxyFilePath = "file:///" + pathToProxiesDirectory + methodName + ".xml";
    proxyAdmin.addProxyService(new DataHandler(new URL(proxyFilePath)));
    JSONObject jsonObject = new JSONObject(requestJsonString);
    jsonObject.append("apiUrl", googlePlusConnectorProperties.getProperty("apiUrl"));
    jsonObject.append("clientId", googlePlusConnectorProperties.getProperty("clientId"));
    jsonObject.append("clientSecret", googlePlusConnectorProperties.getProperty("clientSecret"));
    jsonObject.append("refreshToken", googlePlusConnectorProperties.getProperty("refreshToken"));
    String modifiedJsonString = jsonObject.toString().replace("[", "").replace("]", "");
    try {
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                modifiedJsonString);
        if (responseJson.has("nextPageToken")) {
            googlePlusConnectorProperties.setProperty("searchPeoplePageToken",
                    responseJson.getString("nextPageToken"));
        } else {
            googlePlusConnectorProperties.setProperty("searchPeoplePageToken", "");
        }
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}