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.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Negative test case for createBill.//from ww w . ja  v  a 2 s . c  om
 */
@Test(priority = 2, description = "quickbooks {createBill} integration test negative case.")
public void testCreateBillNegativeCase() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createBill");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createBill_negative.json");

    JSONArray esbResponseArray = esbRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/bill/";
    String OAuthHeader = getOAuthHeader("POST", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap,
            "api_createBill_negative.json");

    JSONArray apiResponseArray = apiRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), apiRestResponse.getHttpStatusCode());
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("Message"),
            esbResponseArray.getJSONObject(0).getString("Message"));
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("code"),
            esbResponseArray.getJSONObject(0).getString("code"));
}

From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Negative test case for createInvoice.
 *//*  w w w .j  av  a  2 s . c  om*/
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithMandatoryParameters",
        "tesCreateItemWithOptionalParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createInvoice} integration test negative case.")
public void testCreateInvoiceNegativeCase() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createInvoice");

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createInvoice_negative.json");

    JSONArray esbResponseArray = esbRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/invoice/";
    String OAuthHeader = getOAuthHeader("POST", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap,
            "api_createInvoice_negative.json");

    JSONArray apiResponseArray = apiRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), apiRestResponse.getHttpStatusCode());
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("Message"),
            esbResponseArray.getJSONObject(0).getString("Message"));
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("code"),
            esbResponseArray.getJSONObject(0).getString("code"));
}

From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Negative test case for createMemo.//from   w  ww . java 2  s.c o  m
 */
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithOptionalParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createMemo} integration test negative case.")
public void testCreateMemoNegativeCase() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createMemo");

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createMemo_negative.json");

    JSONArray esbResponseArray = esbRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/invoice/";
    String OAuthHeader = getOAuthHeader("POST", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap,
            "api_createMemo_negative.json");

    JSONArray apiResponseArray = apiRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), apiRestResponse.getHttpStatusCode());
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("Message"),
            esbResponseArray.getJSONObject(0).getString("Message"));
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("code"),
            esbResponseArray.getJSONObject(0).getString("code"));
}

From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Negative test case for createSalesReceipt.
 *///  w  ww. ja  va2  s  .c  o  m
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithMandatoryParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createSalesReceipt} integration test negative case.")
public void testCreateSalesReceiptNegativeCase() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createSalesReceipt");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createSalesReceipt_negative.json");

    JSONArray esbResponseArray = esbRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId
            + "/salesreceipt/";
    String OAuthHeader = getOAuthHeader("POST", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap,
            "api_createSalesReceipt_negative.json");
    JSONArray apiResponseArray = apiRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");
    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), apiRestResponse.getHttpStatusCode());
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("Message"),
            esbResponseArray.getJSONObject(0).getString("Message"));
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("code"),
            esbResponseArray.getJSONObject(0).getString("code"));
}

From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Negative test case for createPayment.
 *///from  w w w .j a v  a2  s .  c  om
@Test(priority = 1, description = "quickbooks {createPayment} integration test with negative case.")
public void testCreatePaymentWithNegativeCase() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createPayment");

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createPayment_negative.json");

    JSONArray esbResponseArray = esbRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/payment/";
    String OAuthHeader = getOAuthHeader("POST", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap,
            "api_createPayment_negative.json");

    JSONArray apiResponseArray = apiRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), apiRestResponse.getHttpStatusCode());
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("Message"),
            esbResponseArray.getJSONObject(0).getString("Message"));
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("code"),
            esbResponseArray.getJSONObject(0).getString("code"));
}

From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Negative test case for createEstimate.
 *///from   w  w w  .  j  a va 2 s  .c  o  m
@Test(priority = 1, dependsOnMethods = {
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createEstimate} integration test with negative case.")
public void testCreateEstimateWithNegativeCase() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createEstimate");

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createEstimate_negative.json");

    JSONArray esbResponseArray = esbRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/estimate/";
    String OAuthHeader = getOAuthHeader("POST", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap,
            "api_createEstimate_negative.json");

    JSONArray apiResponseArray = apiRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), apiRestResponse.getHttpStatusCode());
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("Message"),
            esbResponseArray.getJSONObject(0).getString("Message"));
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("code"),
            esbResponseArray.getJSONObject(0).getString("code"));
}

From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Negative test case for createBillPayment.
 *///from  ww  w .  j a v  a2  s .c om
@Test(priority = 2, description = "quickbooks {createBillPayment} integration test with negative case.")
public void testCreateBillPaymentWithNegativeCase() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createBillPayment");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createBillPayment_negative.json");

    JSONArray esbResponseArray = esbRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId
            + "/billpayment/";
    String OAuthHeader = getOAuthHeader("POST", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "POST", apiRequestHeadersMap,
            "api_createBillPayment_negative.json");

    JSONArray apiResponseArray = apiRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), apiRestResponse.getHttpStatusCode());
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("Message"),
            esbResponseArray.getJSONObject(0).getString("Message"));
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("code"),
            esbResponseArray.getJSONObject(0).getString("code"));
}

From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Positive test case for query method with mandatory parameters.
 *//*w  ww  .  j a v  a 2s .c  o m*/
@Test(priority = 1, description = "quickbooks {query} integration test with mandatory parameters.")
public void testQueryWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:query");

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_query_mandatory.json");

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("QueryResponse");
    JSONArray esbAccountArray = esbResponseObject.getJSONArray("Account");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId
            + "/query?query=select%20*%20from%20Account%20ORDERBY%20Id%20MAXRESULTS%2010";
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("QueryResponse");
    JSONArray apiAccountArray = apiResponseObject.getJSONArray("Account");

    Assert.assertEquals(esbAccountArray.length(), apiAccountArray.length());
    Assert.assertEquals(esbAccountArray.getJSONObject(0).getString("Name"),
            apiAccountArray.getJSONObject(0).getString("Name"));
    Assert.assertEquals(esbAccountArray.getJSONObject(0).getString("AccountType"),
            apiAccountArray.getJSONObject(0).getString("AccountType"));
    Assert.assertEquals(esbResponseObject.getString("maxResults"), apiResponseObject.getString("maxResults"));
    Assert.assertEquals(esbResponseObject.getString("startPosition"),
            apiResponseObject.getString("startPosition"));

}

From source file:org.wso2.carbon.connector.integration.test.quickbooks.QuickbooksConnectorIntegrationTest.java

/**
 * Negative test case for query.//www  . jav a2s . co  m
 */
@Test(priority = 1, description = "quickbooks {query} integration test with negative case.")
public void testQueryWithNegativeCase() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:query");

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_query_negative.json");

    JSONArray esbResponseArray = esbRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId
            + "/query?query=%20";
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);

    JSONArray apiResponseArray = apiRestResponse.getBody().getJSONObject("Fault").getJSONArray("Error");

    Assert.assertEquals(esbRestResponse.getHttpStatusCode(), apiRestResponse.getHttpStatusCode());
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("Message"),
            esbResponseArray.getJSONObject(0).getString("Message"));
    Assert.assertEquals(apiResponseArray.getJSONObject(0).getString("code"),
            esbResponseArray.getJSONObject(0).getString("code"));
}

From source file:com.example.klaudia.myapplication.Searcher.java

public Recipe[] getRecipesFromArray(JSONArray array) {
    Recipe[] recipes = null;//from w  w w .j  a  v a 2 s.  co  m
    try {
        recipes = new Recipe[array.length()];
        for (int i = 0; i < array.length(); i++) {
            Recipe recipe = getRecipeById(array.getJSONObject(i).getInt("id"));
            recipes[i] = recipe;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return recipes;
}