Example usage for org.json JSONArray JSONArray

List of usage examples for org.json JSONArray JSONArray

Introduction

In this page you can find the example usage for org.json JSONArray JSONArray.

Prototype

public JSONArray(Object array) throws JSONException 

Source Link

Document

Construct a JSONArray from an array

Usage

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listRepositoryIssues method with mandatory parameters.
 *//*from   w  ww.ja  v a2  s  . c  o m*/
@Test(priority = 1, dependsOnMethods = {
        "testSearchIssuesWithNegativeCase" }, description = "github {listRepositoryIssues} integration test with mandatory parameters.")
public void testListRepositoryIssuesWithMandatoryParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:listRepositoryIssues");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/issues";
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listRepositoryIssues_mandatory.json");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    JSONArray apiArray = new JSONArray(apiRestResponse.getBody().getString("output"));
    Assert.assertEquals(esbArray.length(), apiArray.length());
    if (esbArray.length() > 0 && apiArray.length() > 0) {
        JSONObject esbFirstElement = esbArray.getJSONObject(0);
        JSONObject apiFirstElement = apiArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("number"), apiFirstElement.get("number"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listRepositoryIssues method with optional parameters.
 *///from   www .ja  v a 2  s.com
@Test(priority = 1, dependsOnMethods = {
        "testListRepositoryIssuesWithMandatoryParameters" }, description = "github {listRepositoryIssues} integration test with optional parameters.")
public void testListRepositoryIssuesWithOptionalParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:listRepositoryIssues");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/issues?milestone=*&state=open&assignee=" + connectorProperties.getProperty("owner")
            + "&creator=" + connectorProperties.getProperty("owner") + "&sort=created&direction=asc";
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listRepositoryIssues_optional.json");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    JSONArray apiArray = new JSONArray(apiRestResponse.getBody().getString("output"));
    Assert.assertEquals(esbArray.length(), apiArray.length());
    if (esbArray.length() > 0 && apiArray.length() > 0) {
        JSONObject esbFirstElement = esbArray.getJSONObject(0);
        JSONObject apiFirstElement = apiArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("number"), apiFirstElement.get("number"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listIssueComments method with mandatory parameters.
 *//*from www .j av a  2  s  .co  m*/
@Test(priority = 1, dependsOnMethods = {
        "testCreateIssueCommentWithNegativeCase" }, description = "github {listIssueComments} integration test with mandatory parameters.")
public void testListIssueCommentsWithMandatoryParameters()
        throws IOException, JSONException, InterruptedException {
    esbRequestHeadersMap.put("Action", "urn:listIssueComments");
    Thread.sleep(timeOut);
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/issues/" + connectorProperties.getProperty("issueNumber") + "/comments";
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listIssueComments_mandatory.json");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbArray = new JSONArray(esbRestResponse.getBody().getString("output"));
    JSONArray apiArray = new JSONArray(apiRestResponse.getBody().getString("output"));
    Assert.assertEquals(esbArray.length(), apiArray.length());
    if (esbArray.length() > 0 && apiArray.length() > 0) {
        JSONObject esbFirstElement = esbArray.getJSONObject(0);
        JSONObject apiFirstElement = apiArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listPullRequests method with mandatory parameters
 *//*from   www  . j  a  v a 2s.  com*/
@Test(priority = 1, dependsOnMethods = {
        "testGetPullRequestNegativeCase" }, description = "github {listPullRequests} integration test with mandatory parameters.")
public void listPullRequestsWithMandatoryParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:listPullRequests");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/pulls";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listPullRequests_mandatory.json");
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("number"), apiFirstElement.get("number"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listPullRequests method with optional parameters
 *///from w w w.j a  v  a2 s  .co m
@Test(priority = 1, dependsOnMethods = {
        "listPullRequestsWithMandatoryParameters" }, description = "github {listPullRequests} integration test with optional parameters.")
public void listPullRequestsWithOptionalParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:listPullRequests");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/pulls?state=open";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listPullRequests_optional.json");
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("number"), apiFirstElement.get("number"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listPullRequestCommits method with mandatory parameters
 *//*www .j  a  v a 2 s  . c  o m*/
@Test(priority = 1, dependsOnMethods = {
        "listPullRequestsNegativeCase" }, description = "github {listPullRequestsFiles} integration test case with mandatory parameters.")
public void listPullRequestsCommitsWithMandatoryParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:listPullRequestCommits");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/pulls/" + connectorProperties.getProperty("pullRequestNumber") + "/commits";
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listPullRequestCommits_mandatory.json");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("sha"), apiFirstElement.get("sha"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listForks method with mandatory parameters.
 *//* www. j a v  a 2 s  .co  m*/
@Test(priority = 1, dependsOnMethods = {
        "testGetTagWithNegativeCase" }, description = "github {listForks} integration test with mandatory parameters.")
public void testListForksWithMandatoryParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:listForks");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/forks";
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listForks_mandatory.json");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listForks method with optional parameters.
 *//*ww w  .  j  av a  2s.com*/
@Test(priority = 1, dependsOnMethods = {
        "testListForksWithMandatoryParameters" }, description = "github {listForks} integration test with optional parameters.")
public void testListForksWithOptionalParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:listForks");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/forks?sort=newest";
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listForks_optional.json");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for listCollaborators method with mandatory parameters.
 *///  www  .jav a 2 s.  c  o  m
@Test(priority = 1, dependsOnMethods = {
        "testListForksIssuesNegativeCase" }, description = "github {listCollaborators} integration test with mandatory parameters.")
public void testListCollaboratorsWithMandatoryParameters()
        throws IOException, JSONException, InterruptedException {
    esbRequestHeadersMap.put("Action", "urn:listCollaborators");
    Thread.sleep(timeOut);
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/collaborators";
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_listCollaborators_mandatory.json");
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}

From source file:org.wso2.carbon.connector.integration.test.github.GithubConnectorIntegrationTest.java

/**
 * Positive test case for getNotifications method with mandatory parameters.
 *///from  w  w w.ja  v  a 2  s  . com
@Test(priority = 1, dependsOnMethods = {
        "testListCollaboratorsWithNegativeCase" }, description = "github {getNotifications} integration test with mandatory parameters.")
public void testGetNotificationsWithMandatoryParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:getNotifications");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getNotifications_mandatory.json");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/notifications";
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONArray esbResponseJsonArray = new JSONArray(esbRestResponse.getBody().get("output").toString());
    JSONArray apiResponseJsonArray = new JSONArray(apiRestResponse.getBody().get("output").toString());
    Assert.assertEquals(esbResponseJsonArray.length(), apiResponseJsonArray.length());
    if (esbResponseJsonArray.length() > 0 && apiResponseJsonArray.length() > 0) {
        JSONObject esbFirstElement = esbResponseJsonArray.getJSONObject(0);
        JSONObject apiFirstElement = apiResponseJsonArray.getJSONObject(0);
        Assert.assertEquals(esbFirstElement.get("id"), apiFirstElement.get("id"));
    }
}