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 SearchPeople method with pageToken,fields optional parameter
 *///  w w w  .j  a va  2 s  .c  o m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {SearchPeople} integration test with mandatory and language,fields optional parameters.")
public void testSearchPeopleWithTwoOptionalParams5() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchPeopleOptionalParams.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("pageToken", googlePlusConnectorProperties.getProperty("searchPeoplePageToken"));
    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", "language" };
        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 SearchPeople method with language,fields optional parameter.
 *//*from w  w w  .j  av a2s .  co m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {SearchPeople} integration test with mandatory and language,fields optional parameters.")
public void testSearchPeopleWithTwoOptionalParams6() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchPeopleOptionalParams.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("pageToken", googlePlusConnectorProperties.getProperty("searchPeoplePageToken"));
    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 "pageToken", "language", "fields"  check
 *
 * @throws Exception//from w  ww . ja v  a  2 s . co  m
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with optional parameter pageToken, language, fields.")
public void testSearchPeopleThreeOptionalParam1() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchPeopleOptionalParams.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("pageToken", googlePlusConnectorProperties.getProperty("searchPeoplePageToken"));
    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);
    }
}

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

/**
 * Optional parameter "maxResults", "language", "fields" check
 *
 * @throws Exception/*from  www. ja va  2s.c  o m*/
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with optional parameter maxResults, language, fields.")
public void testSearchPeopleThreeOptionalParam2() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchPeopleOptionalParams.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("pageToken", googlePlusConnectorProperties.getProperty("searchPeoplePageToken"));
    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  www  .j  a  v  a2  s .  c  om
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with optional parameter maxResults, pageToken, fields.")
public void testSearchPeopleThreeOptionalParam3() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchPeopleOptionalParams.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("pageToken", googlePlusConnectorProperties.getProperty("searchPeoplePageToken"));
    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 = { "language" };
        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", "language" check
 *
 * @throws Exception/*from w w w  . j  a  v a  2 s  .  c  om*/
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with optional parameter maxResults, pageToken, language.")
public void testSearchPeopleThreeOptionalParam4() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchPeopleOptionalParams.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("pageToken", googlePlusConnectorProperties.getProperty("searchPeoplePageToken"));
    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.
 *///from  w w  w.ja  v a  2  s .c o m
@Test(groups = {
        "wso2.esb" }, description = "GooglePlus {listPeople} integration test with mandatory parameters.")
public void testListPeopleWithMandatoryParams() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "listPeople.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("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("listPeoplePageToken",
                    responseJson.getString("nextPageToken"));
        } else {
            googlePlusConnectorProperties.setProperty("listPeoplePageToken", "");
        }
        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.
 *///from w  w  w  . j a  v  a2s  . com
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListPeopleWithMandatoryParams" }, description = "GooglePlus {listPeople} integration test with mandatory and optional parameters.")
public void testListPeopleWithOptionalParams() 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 {
        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

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

    String jsonRequestFilePath = pathToRequestsDirectory + "listPeopleUnhappy.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("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.assertEquals(statusCode, 400);
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter maxResults check/*  w  w w .j  a  va2 s .  co m*/
 *
 * @throws Exception
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListPeopleWithMandatoryParams" }, description = "GooglePlus {listPeople} integration test with optional parameter maxResults.")
public void testListPeopleOneOptionalParam1() 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", "orderBy", "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);
    }
}