Example usage for org.json JSONObject getString

List of usage examples for org.json JSONObject getString

Introduction

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

Prototype

public String getString(String key) throws JSONException 

Source Link

Document

Get the string associated with a key.

Usage

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

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

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

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

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

    RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap,
            "esb_createEstimate_mandatory.json");
    JSONObject esbResponseObject = esbRestResponse.getBody().getJSONObject("Estimate");
    String estimateId = esbResponseObject.getString("Id");
    connectorProperties.setProperty("estimateId", estimateId);

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

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

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

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

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

/**
 * Positive test case for createEstimate method with optional parameters.
 *//*from   w w  w . java2 s  . c  o  m*/
@Test(priority = 1, dependsOnMethods = { "tesCreateItemWithMandatoryParameters",
        "testCreateCustomerWithOptionalParameters" }, description = "quickbooks {createEstimate} integration test with optional parameters.")
public void testCreateEstimateWithOptionalParameters() throws IOException, JSONException {

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

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

    String estimateId = esbResponseObject.getString("Id");
    connectorProperties.setProperty("estimateIdOptional", estimateId);

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

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

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

    Assert.assertEquals(esbResponseObject.getJSONObject("MetaData").getString("CreateTime"),
            apiResponseObject.getJSONObject("MetaData").getString("CreateTime"));
    Assert.assertEquals(esbResponseObject.getString("DocNumber"), apiResponseObject.getString("DocNumber"));
    Assert.assertEquals(esbResponseObject.getString("ExpirationDate"),
            apiResponseObject.getString("ExpirationDate"));
    Assert.assertEquals(esbResponseObject.getJSONObject("BillAddr").getString("City"),
            apiResponseObject.getJSONObject("BillAddr").getString("City"));
    Assert.assertEquals(esbResponseObject.getString("ShipDate"), apiResponseObject.getString("ShipDate"));
    Assert.assertEquals(esbResponseObject.getJSONObject("BillEmail").getString("Address"),
            apiResponseObject.getJSONObject("BillEmail").getString("Address"));

}