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 "maxResults", "orderBy", "fields" check
 *
 * @throws Exception/* w  w w  .j a  v a  2 s .co m*/
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListPeopleWithMandatoryParams" }, description = "GooglePlus {listPeople} integration test with optional parameter maxResults, orderBy, fields.")
public void testListPeopleThreeOptionalParam2() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listPeopleOptionalParams.txt";
    String methodName = "listPeople";
    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("pageToken", googlePlusConnectorProperties.getProperty("listPeoplePageToken"));
    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);
        junit.framework.Assert.assertEquals("plus#peopleFeed", 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//from   ww w .  j a  v a 2  s.  c  o  m
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListPeopleWithMandatoryParams" }, description = "GooglePlus {listPeople} integration test with optional parameter maxResults, pageToken, fields.")
public void testListPeopleThreeOptionalParam3() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listPeopleOptionalParams.txt";
    String methodName = "listPeople";
    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("pageToken", googlePlusConnectorProperties.getProperty("listPeoplePageToken"));
    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 = { "orderBy" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter "maxResults", "pageToken", "orderBy" check
 *
 * @throws Exception/* ww w  . j  a v  a 2  s .c o  m*/
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListPeopleWithMandatoryParams" }, description = "GooglePlus {listPeople} integration test with optional parameter maxResults, pageToken, orderBy.")
public void testListPeopleThreeOptionalParam4() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listPeopleOptionalParams.txt";
    String methodName = "listPeople";
    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("pageToken", googlePlusConnectorProperties.getProperty("listPeoplePageToken"));
    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);
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Mandatory parameter test case for listPeople method.
 *//* ww  w  .  ja va 2 s.  co  m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListActivityWithMandatoryParams" }, description = "GooglePlus {listByActivity} integration test with mandatory parameters.")
public void testListByActivityWithMandatoryParams() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivity.txt";
    String methodName = "listByActivity";
    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("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("listByActivityPageToken",
                    responseJson.getString("nextPageToken"));
        } else {
            googlePlusConnectorProperties.setProperty("listByActivityPageToken", "");
        }
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for listPeople method.
 *//*w  ww.  j ava  2 s . co m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListByActivityWithMandatoryParams" }, description = "GooglePlus {listByActivity} integration test with mandatory and optional parameters.")
public void testListByActivityWithOptionalParams() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivityOptionalParams.txt";
    String methodName = "listByActivity";
    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("listByActivityPageToken"));
    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#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for listByActivity method with maxResults Optional Parameter.
 *///ww w  .ja  v a  2  s.  c  o m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListByActivityWithMandatoryParams" }, description = "GooglePlus {listByActivity} integration test with mandatory and maxResults optional parameter.")
public void testListByActivityWithOneOptionalParam1() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivityOptionalParams.txt";
    String methodName = "listByActivity";
    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("listByActivityPageToken"));
    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", "fields" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for listByActivity method with pageToken Optional Parameter.
 *//*from   ww w .  j  a v  a 2s. c om*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListByActivityWithMandatoryParams" }, description = "GooglePlus {listByActivity} integration test with mandatory and pageToken optional parameter.")
public void testListByActivityWithOneOptionalParam2() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivityOptionalParams.txt";
    String methodName = "listByActivity";
    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("listByActivityPageToken"));
    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", "fields" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for listByActivity method with fields Optional Parameter.
 *//* w  ww  .  j a va 2s.  c  om*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListByActivityWithMandatoryParams" }, description = "GooglePlus {listByActivity} integration test with mandatory and fields optional parameter.")
public void testListByActivityWithOneOptionalParam3() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivityOptionalParams.txt";
    String methodName = "listByActivity";
    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("listByActivityPageToken"));
    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);
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for listByActivity method with maxResults,pageToken Optional Parameters.
 *//*from  w w  w.  j a  v  a  2s .co  m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListByActivityWithMandatoryParams" }, description = "GooglePlus {listByActivity} integration test with mandatory and maxResults,pageToken optional parameters.")
public void testListByActivityWithTwoOptionalParam1() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivityOptionalParams.txt";
    String methodName = "listByActivity";
    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("listByActivityPageToken"));
    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);
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for listByActivity method with pageToken,fields Optional Parameters.
 *//*from   w  ww  .j a  v  a2  s.c  o  m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListByActivityWithMandatoryParams" }, description = "GooglePlus {listByActivity} integration test with mandatory and pageToken,,fields optional parameters.")
public void testListByActivityWithTwoOptionalParam2() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listByActivityOptionalParams.txt";
    String methodName = "listByActivity";
    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("listByActivityPageToken"));
    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);
        junit.framework.Assert.assertEquals("plus#peopleFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}