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.
 *//*from   w  w w  .j  av  a  2 s  .c om*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with mandatory and optional parameters.")
public void testSearchPeopleWithOptionalParams() 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 {
        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 searchPeople method.
 *//* w  w w  .  j a va 2  s. c om*/
@Test(groups = {
        "wso2.esb" }, description = "GooglePlus {searchPeople} integration test with Negative parameters.")
public void testSearchPeopleWithNegativeParams() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "searchPeopleUnhappy.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 {

        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/*from w w  w.j a  v  a  2 s. com*/
 *
 * @throws Exception
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with optional parameter maxResults.")
public void testSearchPeopleOneOptionalParam1() 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", "language", "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 pageToken check/*from   w  w  w.  j  ava  2  s  . c o m*/
 *
 * @throws Exception
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with optional parameter pageToken.")
public void testSearchPeopleOneOptionalParam2() 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", "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 language check/*from w  w  w  .  j  a  va  2s  .  co m*/
 *
 * @throws Exception
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with optional parameter language.")
public void testSearchPeopleOneOptionalParam3() 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", "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 fields check//from  w w w  . j  a va2  s .  com
 *
 * @throws Exception
 */

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {searchPeople} integration test with optional parameter fields.")
public void testSearchPeopleOneOptionalParam4() 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", "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 maxResults,pageToken  optional parameter.
 *///from   w w w.j  ava  2s.c o  m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {SearchPeople} integration test with mandatory and maxResults,pageToken optional parameters.")
public void testSearchPeopleWithTwoOptionalParams1() 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", "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 SearchPeople method with maxResults,language optional parameter.
 *//*from  w w w  .j ava 2s  . c  om*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {SearchPeople} integration test with mandatory and maxResults,language optional parameters.")
public void testSearchPeopleWithTwoOptionalParams2() 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", "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 SearchPeople method with maxResults,fields optional parameter.
 *///from ww  w.  j  a  v a  2  s.  c o m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {SearchPeople} integration test with mandatory and maxResults,fields optional parameters.")
public void testSearchPeopleWithTwoOptionalParams3() 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", "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 SearchPeople method with pageToken,language.
 *///from w ww  .ja  v  a2s . co  m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchPeopleWithMandatoryParams" }, description = "GooglePlus {SearchPeople} integration test with mandatory and pageToken,language optional parameters.")
public void testSearchPeopleWithTwoOptionalParams4() 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", "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);
    }
}