Example usage for org.json JSONObject getJSONObject

List of usage examples for org.json JSONObject getJSONObject

Introduction

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

Prototype

public JSONObject getJSONObject(String key) throws JSONException 

Source Link

Document

Get the JSONObject value associated with a key.

Usage

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

/**
 * Positive test case for createBill method with mandatory parameters.
 *///  ww w .  j  ava 2  s . co m
@Test(priority = 2, dependsOnMethods = { "testCreateAccountWithMandatoryParameters",
        "testCreateVendorWithOptionalParameters" }, description = "quickbooks {createBill} integration test with mandatory parameters.")
public void testCreateBillWithMandatoryParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createBill");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createBill_mandatory.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Bill");
    String billId = esbResponseObject.getString("Id");
    connectorProperties.put("billPaymentTxn1Id", billId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/bill/"
            + billId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Bill");
    Assert.assertEquals(billId, apiResponseObject.getString("Id"));
    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));

}

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

/**
 * Positive test case for createBill method with optional parameters
 *//*from w  ww  .  ja  v  a 2s  .  c  om*/
@Test(priority = 2, dependsOnMethods = { "testCreateAccountWithMandatoryParameters",
        "testCreateVendorWithOptionalParameters" }, description = "quickbooks {createBill} integration test with optional parameters.")
public void testCreateBillWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createBill");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createBill_optional.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Bill");
    String billId = esbResponseObject.getString("Id");
    connectorProperties.put("billPaymentTxn2Id", billId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/bill/"
            + billId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Bill");

    Assert.assertEquals(billId, apiResponseObject.getString("Id"));
    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));

}

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

/**
 * Positive test case for createInvoice method with mandatory parameters.
 *///from w ww .  ja v  a 2s .  c  om
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithMandatoryParameters",
        "tesCreateItemWithOptionalParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createInvoice} integration test with mandatory parameters.")
public void testCreateInvoiceWithMandatoryParameters() throws IOException, JSONException {

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

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createInvoice_mandatory.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Invoice");
    String invoiceId = esbResponseObject.getString("Id");
    connectorProperties.put("invoiceIdMandatory", invoiceId);
    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/invoice/"
            + invoiceId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Invoice");
    Assert.assertEquals(invoiceId, apiResponseObject.getString("Id"));
    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));

}

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

/**
 * Positive test case for createInvoice method with optional parameters
 *///from   w w  w . j a  v  a2 s . c  o  m
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithMandatoryParameters",
        "tesCreateItemWithOptionalParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createInvoice} integration test with optional parameters.")
public void testCreateInvoiceWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createInvoice");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createInvoice_optional.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Invoice");
    String invoiceId = esbResponseObject.getString("Id");
    connectorProperties.put("invoiceIdOptional", invoiceId);
    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/invoice/"
            + invoiceId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Invoice");
    Assert.assertEquals(invoiceId, apiResponseObject.getString("Id"));
    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals(connectorProperties.getProperty("docNumber"), apiResponseObject.getString("DocNumber"));
}

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

/**
 * Positive test case for createMemo method with mandatory parameters.
 *//* w  w  w .  j a  v a2  s  . c o m*/
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithOptionalParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createMemo} integration test with mandatory parameters.")
public void testCreateMemoWithMandatoryParameters() throws IOException, JSONException {

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

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createMemo_mandatory.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("CreditMemo");
    String creditMemoId = esbResponseObject.getString("Id");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/creditmemo/"
            + creditMemoId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("CreditMemo");
    Assert.assertEquals(creditMemoId, apiResponseObject.getString("Id"));
    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));

}

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

/**
 * Positive test case for createMemo method with optional parameters
 *//* w ww . j  a  v a2s .  c  o  m*/
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithOptionalParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createMemo} integration test with optional parameters.")
public void testCreateMemoWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createMemo");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createMemo_optional.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("CreditMemo");
    String creditMemoId = esbResponseObject.getString("Id");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/creditmemo/"
            + creditMemoId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("CreditMemo");
    Assert.assertEquals(creditMemoId, apiResponseObject.getString("Id"));
    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals(esbResponseObject.getString("PrivateNote"), apiResponseObject.getString("PrivateNote"));
    Assert.assertEquals(esbResponseObject.getString("CustomerMemo"),
            apiResponseObject.getString("CustomerMemo"));
}

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

/**
 * Positive test case for createSalesReceipt method with mandatory parameters.
 *//*www  .  j av  a  2 s .  c  o  m*/
@Test(priority = 1, dependsOnMethods = {
        "tesCreateItemWithMandatoryParameters" }, description = "quickbooks {createSalesReceipt} integration test with mandatory parameters.")
public void testCreateSalesReceiptWithMandatoryParameters() throws IOException, JSONException {

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

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createSalesReceipt_mandatory.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("SalesReceipt");
    String salesReceiptId = esbResponseObject.getString("Id");
    connectorProperties.setProperty("salesReceiptIdMandatory", salesReceiptId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId
            + "/salesreceipt/" + salesReceiptId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("SalesReceipt");
    Assert.assertEquals(salesReceiptId, apiResponseObject.getString("Id"));
    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));

}

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

/**
 * Positive test case for createSalesReceipt method with optional parameters
 *///www. j  ava2s  .  c  o  m
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithMandatoryParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createSalesReceipt} integration test with optional parameters.")
public void testCreateSalesReceiptWithOptionalParameters() throws IOException, JSONException {

    esbRequestHeadersMap.put("Action", "urn:createSalesReceipt");
    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createSalesReceipt_optional.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("SalesReceipt");
    String salesReceiptId = esbResponseObject.getString("Id");
    connectorProperties.setProperty("salesReceiptIdOptional", salesReceiptId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId
            + "/salesreceipt/" + salesReceiptId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);
    RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap);
    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("SalesReceipt");
    Assert.assertEquals(salesReceiptId, apiResponseObject.getString("Id"));
    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals(esbResponseObject.getString("PrivateNote"), apiResponseObject.getString("PrivateNote"));
    Assert.assertEquals(connectorProperties.getProperty("docNumber"), apiResponseObject.getString("DocNumber"));
}

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

/**
 * Positive test case for createPayment method with mandatory parameters.
 *///from   www  .  ja va 2  s . co  m
@Test(priority = 1, description = "quickbooks {createPayment} integration test with mandatory parameters.")
public void testCreatePaymentWithMandatoryParameters() throws IOException, JSONException {

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

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createPayment_mandatory.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Payment");
    String paymentId = esbResponseObject.getString("Id");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/payment/"
            + paymentId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Payment");

    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals(esbResponseObject.getString("TxnDate"), apiResponseObject.getString("TxnDate"));
}

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

/**
 * Positive test case for createPayment method with optional parameters.
 *//* ww w .  j  ava2 s. co  m*/
@Test(priority = 1, description = "quickbooks {createPayment} integration test with optional parameters.")
public void testCreatePaymentWithOptionalParameters() throws IOException, JSONException {

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

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createPayment_optional.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Payment");
    String paymentId = esbResponseObject.getString("Id");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/payment/"
            + paymentId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Payment");

    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals(esbResponseObject.getString("TxnDate"), apiResponseObject.getString("TxnDate"));
    Assert.assertEquals(esbResponseObject.getString("ProcessPayment"),
            apiResponseObject.getString("ProcessPayment"));
    Assert.assertEquals(esbResponseObject.getString("PrivateNote"), apiResponseObject.getString("PrivateNote"));
}