Example usage for org.json JSONArray getJSONObject

List of usage examples for org.json JSONArray getJSONObject

Introduction

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

Prototype

public JSONObject getJSONObject(int index) throws JSONException 

Source Link

Document

Get the JSONObject associated with an index.

Usage

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

/**
 * Positive test case for listIssueComments method with mandatory parameters.
 *//*from   w w  w .j a v  a2  s. c o 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
 *///  w  ww . j a  v  a2 s . c o m
@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
 *///ww w .j a  va  2s  . 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
 *//* ww w  . ja va2 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  .c o  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.
 *///from  w  ww  .  ja v  a 2  s . c  o m
@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.
 *///from  www. jav  a 2  s . com
@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 . co  m*/
@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"));
    }
}

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

/**
 * Positive test case for getNotifications method with optional parameters.
 *//*from   w w  w.ja  va2 s. co m*/
@Test(priority = 1, dependsOnMethods = {
        "testGetNotificationsWithMandatoryParameters" }, description = "github {getNotifications} integration test with optional parameters.")
public void testGetNotificationsWithOptionalParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:getNotifications");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getNotifications_optional.json");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/notifications?all=true";
    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 getRepositoryNotifications method with mandatory parameters.
 *//* w  w w.ja  v  a2 s  . c o m*/
@Test(priority = 1, dependsOnMethods = {
        "testGetNotificationsWithNegativeCase" }, description = "github {getRepositoryNotifications} integration test with mandatory parameters.")
public void testGetRepositoryNotificationsWithMandatoryParameters() throws IOException, JSONException {
    esbRequestHeadersMap.put("Action", "urn:getRepositoryNotifications");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_getRepositoryNotifications_mandatory.json");
    String apiEndPoint = connectorProperties.getProperty("githubApiUrl") + "/repos/"
            + connectorProperties.getProperty("owner") + "/" + connectorProperties.getProperty("repo")
            + "/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"));
    }
}