/**
  * Test if Suppliers are preloaded.
  *
  * @throws IOException
  * @throws JSONException
  */
 @Test
 public void testPreloadedSuppliersExists() throws IOException, JSONException {
   HttpResponse resp =
       RequestExecutionHelper.executeGetRequest(
           ENTITY_NAME + "?$inlinecount=allpages&$format=json", true);
   assertEquals(
       "Mismatch in the number of preloaded suppliers",
       9,
       RequestExecutionHelper.getInlineCount(resp.getBody()));
 }
 /**
  * Test Supplier Url filter Service Query option.
  *
  * @throws IOException
  * @throws JSONException
  */
 @Test
 public void testSupplierUrlFilter() throws IOException, JSONException {
   JSONObject jo;
   HttpResponse resp =
       RequestExecutionHelper.executeGetRequest(
           ENTITY_NAME
               + "?$format=json&$filter=EmailAddress%20eq%20'*****@*****.**'&$top=1",
           true);
   JSONArray ja = RequestExecutionHelper.getJSONArrayofResults(resp.getBody());
   assertNotNull("Unable to parse JSON response", ja);
   jo = (JSONObject) ja.get(0);
   assertEquals("Supplier not filtered Supplier Id", "100000045", jo.getString("SupplierId"));
 }
 /**
  * Test if Supplier URL Skip Service Query Option.
  *
  * @throws JSONException
  * @throws IOException
  */
 @Test
 public void testSupplierUrlSkip() throws JSONException, IOException {
   JSONObject jo;
   HttpResponse resp =
       RequestExecutionHelper.executeGetRequest(
           ENTITY_NAME + "?$format=json&$orderby=SupplierId&$skip=1", true);
   JSONArray ja = RequestExecutionHelper.getJSONArrayofResults(resp.getBody());
   assertNotNull("Unable to parse JSON response", ja);
   jo = (JSONObject) ja.get(0);
   assertEquals(
       "First Supplier in the ordered response not skipped",
       "100000042",
       jo.getString("SupplierId"));
 }
 /**
  * Test Supplier Url Top and Orderby Service Query option.
  *
  * @throws IOException
  * @throws JSONException
  */
 @Test
 public void testSupplierUrlTopOrderby() throws IOException, JSONException {
   JSONObject jo;
   HttpResponse resp =
       RequestExecutionHelper.executeGetRequest(
           ENTITY_NAME + "?$format=json&$orderby=SupplierId&$top=1", true);
   JSONArray ja = RequestExecutionHelper.getJSONArrayofResults(resp.getBody());
   assertNotNull("Unable to parse JSON response", ja);
   jo = (JSONObject) ja.get(0);
   assertEquals(
       "Suppliers not orderedby Supplier Id in ascending order",
       "100000041",
       jo.getString("SupplierId"));
 }
 /**
  * Test if Supplier URL Select Service Query Option.
  *
  * @throws IOException
  * @throws JSONException
  */
 @Test
 public void testSupplierUrlSelect() throws IOException, JSONException {
   HttpResponse resp =
       RequestExecutionHelper.executeGetRequest(
           ENTITY_NAME
               + "?$format=json&$orderby=SupplierId&$skip=1&$top=1&$select=SupplierId,Country",
           true);
   JSONArray ja = RequestExecutionHelper.getJSONArrayofResults(resp.getBody());
   assertNotNull("Unable to parse JSON response", ja);
   ja.get(0);
   assertTrue(
       "Selected property Country does not exist in the odata service",
       resp.getBody().contains("Country"));
   assertTrue(
       "Non selected property City still exists in the odata service",
       !resp.getBody().contains("City"));
 }
 /**
  * Test Delete Supplier via URL.
  *
  * @throws IOException
  * @throws JSONException
  */
 @Test
 public void testDeleteSupplierViaREST() throws IOException, JSONException {
   String supplierXml = StreamHelper.readFromFile(FILENAME);
   String email = rand.nextInt(200) + "@sap.com";
   supplierXml =
       supplierXml.replace(
           "<d:EmailAddress>email</d:EmailAddress>",
           "<d:EmailAddress>" + email + "</d:EmailAddress>");
   String id = RequestExecutionHelper.createEntityViaREST(ENTITY_NAME, supplierXml, true);
   HttpResponse resp =
       RequestExecutionHelper.executeGetRequest(
           ENTITY_NAME + "?$format=json&$filter=SupplierId%20eq%20'" + id + "'", true);
   assertEquals("Supplier not persisted", HttpURLConnection.HTTP_OK, resp.getResponseCode());
   resp = RequestExecutionHelper.executeDeleteRequest(ENTITY_NAME + "('" + id + "')", true);
   assertEquals(
       "Unable to delete Customer via REST or incorrect HTTP Response Code:"
           + resp.getResponseMessage(),
       HttpURLConnection.HTTP_OK,
       resp.getResponseCode());
 }
 /**
  * Test Create and Read Supplier via URL.
  *
  * @throws IOException
  * @throws JSONException
  */
 @Test
 public void testCreateSupplierViaREST() throws IOException, JSONException {
   String supplierXml = StreamHelper.readFromFile(FILENAME);
   String email = rand.nextInt(200) + "@sap.com";
   supplierXml =
       supplierXml.replace(
           "<d:EmailAddress>email</d:EmailAddress>",
           "<d:EmailAddress>" + email + "</d:EmailAddress>");
   String id = RequestExecutionHelper.createEntityViaREST(ENTITY_NAME, supplierXml, true);
   HttpResponse resp =
       RequestExecutionHelper.executeGetRequest(
           ENTITY_NAME + "?$format=json&$filter=SupplierId%20eq%20'" + id + "'", true);
   assertEquals("Supplier not persisted", HttpURLConnection.HTTP_OK, resp.getResponseCode());
   JSONArray ja = RequestExecutionHelper.getJSONArrayofResults(resp.getBody());
   assertNotNull("Unable to parse JSON response", ja);
   JSONObject jo = (JSONObject) ja.get(0);
   assertEquals("Added Supplier via REST not persisted in db", id, jo.getString("SupplierId"));
   resp = RequestExecutionHelper.executeDeleteRequest(ENTITY_NAME + "('" + id + "')", true);
   assertEquals(
       "Unable to delete Supplier via REST or incorrect HTTP Response Code:"
           + resp.getResponseMessage(),
       HttpURLConnection.HTTP_OK,
       resp.getResponseCode());
 }