List of usage examples for org.json JSONObject append
public JSONObject append(String key, Object value) throws JSONException
From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java
/** * Optional parameter test case for listComments method. */// w w w . j av a 2s. c om @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with mandatory and optional parameters.") public void testListCommentsWithOptionalParams() 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 { JSONObject responseJson = ConnectorIntegrationUtil.sendRequest(getProxyServiceURL(methodName), modifiedJsonString); Assert.assertEquals("plus#commentFeed", responseJson.getString("kind")); } finally { proxyAdmin.deleteProxy(methodName); } }
From source file:org.wso2.carbon.connector.integration.test.gplus.GooglePlusTestCase.java
/** * Negative parameter test case for listComments method. *///w w w . ja va2 s . c o m @Test(groups = { "wso2.esb" }, description = "GooglePlus {listComments} integration test with Negative parameters.") public void testListCommentsWithNegativeParams() throws Exception { String jsonRequestFilePath = pathToRequestsDirectory + "listCommentsUnhappy.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("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
/** * Optional parameter maxResults check/*ww w . ja v a2s. c om*/ * * @throws Exception */ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with optional parameter maxResults.") public void testListCommentsOneOptionalParam1() 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", "sortOrder", "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
/** * Optional parameter pageToken check//from w ww . j a v a 2 s .c om * * @throws Exception */ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with optional parameter pageToken.") public void testListCommentsOneOptionalParam2() 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", "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
/** * Optional parameter sortOrder check// w w w . ja v a 2 s . c o m * * @throws Exception */ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with optional parameter sortOrder.") public void testListCommentsOneOptionalParam3() 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", "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
/** * Optional parameter fields check/*from w w w .j a va 2 s. co m*/ * * @throws Exception */ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {listComments} integration test with optional parameter fields.") public void testListCommentsOneOptionalParam4() 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", "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 maxResults,pageToken optional parameter. *//* w w w .ja v a 2 s. co m*/ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {ListComments} integration test with mandatory and maxResults,pageToken optional parameters.") public void testListCommentsWithTwoOptionalParams1() 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", "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
/** * Optional parameter test case for ListComments method with maxResults,sortOrder optional parameter. *//*ww w . j av a 2 s.c om*/ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {ListComments} integration test with mandatory and maxResults,sortOrder optional parameters.") public void testListCommentsWithTwoOptionalParams2() 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", "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 test case for ListComments method with maxResults,fields optional parameter. */// www. j av a2 s . c o m @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {ListComments} integration test with mandatory and maxResults,fields optional parameters.") public void testListCommentsWithTwoOptionalParams3() 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", "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 test case for ListComments method with pageToken,sortOrder. *//*from w w w .j a v a 2 s . c o m*/ @Test(groups = { "wso2.esb" }, dependsOnMethods = { "testListCommentsWithMandatoryParams" }, description = "GooglePlus {ListComments} integration test with mandatory and pageToken,sortOrder optional parameters.") public void testListCommentsWithTwoOptionalParams4() 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", "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); } }