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 listActivity method with fields Optional Parameter.
 *//*from  w ww  .ja v a 2s.  com*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListActivityWithMandatoryParams" }, description = "GooglePlus {listActivity} integration test with mandatory and fields optional parameter.")
public void testListActivityWithOneOptionalParam3() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listActivitiesOptionalParams.txt";
    String methodName = "listActivities";
    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("pageToken", googlePlusConnectorProperties.getProperty("listActivitiesPageToken"));
    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#activityFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for listActivity method with maxResults,fields Optional Parameters.
 */// w w  w. j  a v  a2 s . co  m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testListActivityWithMandatoryParams" }, description = "GooglePlus {listActivity} integration test with mandatory and maxResults,fields optional parameters.")
public void testListActivityWithTwoOptionalParam3() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "listActivitiesOptionalParams.txt";
    String methodName = "listActivities";
    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("pageToken", googlePlusConnectorProperties.getProperty("listActivitiesPageToken"));
    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#activityFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

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

    String jsonRequestFilePath = pathToRequestsDirectory + "listActivitiesUnhappy.txt";
    String methodName = "listActivities";
    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);
        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 searchActivities method.
 *//*from  www.  ja  v  a 2  s. c o  m*/
@Test(groups = {
        "wso2.esb" }, description = "GooglePlus {searchActivities} integration test with mandatory parameters.")
public void testSearchActivityWithMandatoryParams() throws Exception {

    String jsonRequestFilePath = pathToRequestsDirectory + "searchActivities.txt";
    String methodName = "searchActivities";
    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 {
        log.info("Sleep for 30 seconds");
        Thread.sleep(3000);

        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                modifiedJsonString);
        if (responseJson.has("nextPageToken")) {
            googlePlusConnectorProperties.setProperty("searchActivitiesPageToken",
                    responseJson.getString("nextPageToken"));
        } else {
            googlePlusConnectorProperties.setProperty("searchActivitiesPageToken", "");
        }
        Assert.assertEquals("plus#activityFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for searchActivities method.
 *//*w ww  .ja  v  a 2 s. co m*/

@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchActivityWithMandatoryParams" }, description = "GooglePlus {searchActivities} integration test with mandatory and optional parameters.")
public void testSearchActivityWithOptionalParams() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchActivitiesOptionalParams.txt";
    String methodName = "searchActivities";
    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("searchActivitiesPageToken"));
    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);
        Assert.assertEquals("plus#activityFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for searchActivities method with maxResults optional parameter.
 */// w w w.  ja va2 s .c  om
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchActivityWithMandatoryParams" }, description = "GooglePlus {searchActivities} integration test with mandatory and maxResults optional parameters.")
public void testSearchActivityWithOneOptionalParams1() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchActivitiesOptionalParams.txt";
    String methodName = "searchActivities";
    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("searchActivitiesPageToken"));
    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", "orderBy", "pageToken", "fields" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#activityFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for searchActivities method with orderBy optional parameter.
 *///from www .ja  v a  2 s.c o m
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchActivityWithMandatoryParams" }, description = "GooglePlus {searchActivities} integration test with mandatory and orderBy optional parameters.")
public void testSearchActivityWithOneOptionalParams2() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchActivitiesOptionalParams.txt";
    String methodName = "searchActivities";
    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("searchActivitiesPageToken"));
    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", "maxResults", "pageToken", "fields" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#activityFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

/**
 * Optional parameter test case for searchActivities method with pageToken optional parameter.
 *//*from   w w  w.j a v  a 2 s .  c o  m*/
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchActivityWithMandatoryParams" }, description = "GooglePlus {searchActivities} integration test with mandatory and pageToken optional parameters.")
public void testSearchActivityWithOneOptionalParams3() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchActivitiesOptionalParams.txt";
    String methodName = "searchActivities";
    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("searchActivitiesPageToken"));
    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", "maxResults", "orderBy", "fields" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#activityFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}

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

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

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

/**
 * Optional parameter test case for searchActivities method with language optional parameter
 *///from  ww w  . ja va  2s .  com
@Test(groups = { "wso2.esb" }, dependsOnMethods = {
        "testSearchActivityWithMandatoryParams" }, description = "GooglePlus {searchActivities} integration test with mandatory and language optional parameters.")
public void testSearchActivityWithOneOptionalParams5() throws Exception {
    String jsonRequestFilePath = pathToRequestsDirectory + "searchActivitiesOptionalParams.txt";
    String methodName = "searchActivities";
    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("searchActivitiesPageToken"));
    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", "maxResults", "orderBy", "pageToken" };
        String requiredJsonString = ConnectorIntegrationUtil.getRequiredJsonString(modifiedJsonString,
                unneededOptionalParameters);
        JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName),
                requiredJsonString);
        Assert.assertEquals("plus#activityFeed", responseJson.getString("kind"));
    } finally {
        proxyAdmin.deleteProxy(methodName);
    }
}