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 createAccount method with optional parameters.
 *//*  w ww . j av a 2s .  co  m*/
@Test(priority = 1, description = "quickbooks {createAccount} integration test with optional parameters.")
public void testCreateAccountWithOptionalParameters() throws IOException, JSONException {

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

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

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Account");
    String accountId = esbResponseObject.getString("Id");
    connectorProperties.put("bankAccoutId", accountId);

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

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

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

    Assert.assertEquals(connectorProperties.getProperty("accountNameOptional"),
            apiResponseObject.getString("Name"));
    Assert.assertEquals("LKR", apiResponseObject.getJSONObject("CurrencyRef").getString("value"));
    Assert.assertEquals("Savings", apiResponseObject.getString("AccountSubType"));
    Assert.assertEquals("Test description", apiResponseObject.getString("Description"));

}

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

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

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

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

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Customer");
    String customerId = esbResponseObject.getString("Id");
    connectorProperties.setProperty("customerId", customerId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/customer/"
            + customerId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

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

    Assert.assertEquals(connectorProperties.getProperty("customerNameMandatory"),
            apiResponseObject.getString("FamilyName"));
    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 createCustomer method with optional parameters.
 *///ww w . j  a v a  2  s.  c  o  m
@Test(priority = 1, description = "quickbooks {createCustomer} integration test with optional parameters.")
public void testCreateCustomerWithOptionalParameters() throws IOException, JSONException {

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

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

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Customer");
    String customerId = esbResponseObject.getString("Id");
    connectorProperties.put("customerRef", customerId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/customer/"
            + customerId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

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

    Assert.assertEquals(connectorProperties.getProperty("customerNameOptional"),
            apiResponseObject.getString("FamilyName"));
    Assert.assertEquals("+947111", apiResponseObject.getJSONObject("PrimaryPhone").getString("FreeFormNumber"));
    Assert.assertEquals("WSO2", apiResponseObject.getString("CompanyName"));

}

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

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

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

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createVendor_mandatory.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Vendor");
    String vendorId = esbResponseObject.getString("Id");
    connectorProperties.setProperty("vendorId", vendorId);
    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/vendor/"
            + vendorId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);
    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

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

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

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

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

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

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createVendor_optional.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Vendor");

    String vendorId = esbResponseObject.getString("Id");
    connectorProperties.put("vendorRef", vendorId);

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

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

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

    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals(esbResponseObject.getString("TaxIdentifier"),
            apiResponseObject.getString("TaxIdentifier"));
    Assert.assertEquals(esbResponseObject.getString("GivenName"), apiResponseObject.getString("GivenName"));
    Assert.assertEquals(esbResponseObject.getJSONObject("AlternatePhone").getString("FreeFormNumber"),
            apiResponseObject.getJSONObject("AlternatePhone").getString("FreeFormNumber"));
}

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

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

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

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

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Item");
    String itemId = esbResponseObject.getString("Id");
    connectorProperties.put("ItemRef1", itemId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/item/"
            + itemId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

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

    Assert.assertEquals(connectorProperties.getProperty("itemNameMandatory"),
            apiResponseObject.getString("Name"));
    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 createPurchase method with mandatory parameters.
 *//*www. java  2  s  . c  o m*/
@Test(priority = 1, dependsOnMethods = { "testCreateAccountWithMandatoryParameters",
        "testCreateAccountWithOptionalParameters" }, description = "quickbooks {createPurchase} integration test with mandatory parameters.")
public void tesCreatePurchaseWithMandatoryParameters() throws IOException, JSONException {

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

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

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Purchase");
    String purchaseId = esbResponseObject.getString("Id");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/purchase/"
            + purchaseId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("Purchase");
    JSONArray apiLineArray = apiResponseObject.getJSONArray("Line");

    Assert.assertEquals(connectorProperties.getProperty("expenseAccountRef"), apiLineArray.getJSONObject(0)
            .getJSONObject("AccountBasedExpenseLineDetail").getJSONObject("AccountRef").getString("value"));
    Assert.assertEquals(connectorProperties.getProperty("bankAccoutId"),
            apiResponseObject.getJSONObject("AccountRef").getString("value"));
    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 createPurchase method with optional parameters.
 */// w  w w  .j  av a2  s.  co  m
@Test(priority = 1, dependsOnMethods = { "testCreateCustomerWithOptionalParameters",
        "tesCreatePurchaseWithMandatoryParameters" }, description = "quickbooks {createPurchase} integration test with optional parameters.")
public void tesCreatePurchaseWithOptionalParameters() throws IOException, JSONException {

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

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Purchase");
    String purchaseId = esbResponseObject.getString("Id");

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId + "/purchase/"
            + purchaseId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

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

    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals("LKR", apiResponseObject.getJSONObject("CurrencyRef").getString("value"));
    Assert.assertEquals("Private Note", apiResponseObject.getString("PrivateNote"));
    Assert.assertEquals("NeedToPrint", apiResponseObject.getString("PrintStatus"));
    Assert.assertEquals(connectorProperties.getProperty("customerRef"),
            apiResponseObject.getJSONObject("EntityRef").getString("value"));

}

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

/**
 * Positive test case for createPurchaseOrder method with mandatory parameters.
 */// w  w w.  ja  v  a 2 s.co m
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithOptionalParameters",
        "testCreateVendorWithOptionalParameters" }, description = "quickbooks {createPurchaseOrder} integration test with mandatory parameters.")
public void tesCreatePurchaseOrderWithMandatoryParameters() throws IOException, JSONException {

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

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

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("PurchaseOrder");
    String purchaseOrderId = esbResponseObject.getString("Id");
    connectorProperties.setProperty("purchaseOrderId", purchaseOrderId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId
            + "/purchaseorder/" + purchaseOrderId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

    JSONObject apiResponseObject = apiRestResponse.getBody().getJSONObject("PurchaseOrder");
    JSONArray apiLineArray = apiResponseObject.getJSONArray("Line");

    Assert.assertEquals(connectorProperties.getProperty("ItemRef2"), apiLineArray.getJSONObject(0)
            .getJSONObject("ItemBasedExpenseLineDetail").getJSONObject("ItemRef").getString("value"));
    Assert.assertEquals(connectorProperties.getProperty("vendorRef"),
            apiResponseObject.getJSONObject("VendorRef").getString("value"));
    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 createPurchaseOrder method with optional parameters.
 *///w  ww .  j  a v  a  2 s  . c  om
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithOptionalParameters",
        "testCreateVendorWithOptionalParameters" }, description = "quickbooks {createPurchaseOrder} integration test with optional parameters.")
public void tesCreatePurchaseOrderWithOptionalParameters() throws IOException, JSONException {

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

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

    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("PurchaseOrder");
    String purchaseOrderId = esbResponseObject.getString("Id");
    connectorProperties.setProperty("purchaseOrderIdOptional", purchaseOrderId);

    String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/v3/company/" + companyId
            + "/purchaseorder/" + purchaseOrderId;
    String OAuthHeader = getOAuthHeader("GET", apiEndPoint);

    apiRequestHeadersMap.put("Authorization", OAuthHeader);

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

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

    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals("LKR", apiResponseObject.getJSONObject("CurrencyRef").getString("value"));
    Assert.assertEquals("Private Note", apiResponseObject.getString("PrivateNote"));
    Assert.assertEquals(connectorProperties.getProperty("txnDate"), apiResponseObject.getString("TxnDate"));
    Assert.assertEquals("Open", apiResponseObject.getString("POStatus"));

}