/** * Test Update Supplier via URL. * * @throws IOException * @throws JSONException */ @Test public void testUpdateSupplierViaREST() throws IOException, JSONException { String supplierXml = StreamHelper.readFromFile(FILENAME); String newPhoneNumber = "111111"; 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()); supplierXml = supplierXml.replace( "<d:PhoneNumber>5899428367</d:PhoneNumber>", "<d:PhoneNumber>" + newPhoneNumber + "</d:PhoneNumber>"); resp = RequestExecutionHelper.executePutRequest(ENTITY_NAME + "('" + id + "')", supplierXml, true); assertEquals( "Unable to update Supplier via URL Response Message:" + resp.getResponseMessage(), HttpURLConnection.HTTP_NO_CONTENT, resp.getResponseCode()); resp = RequestExecutionHelper.executeGetRequest( ENTITY_NAME + "?$format=json&$filter=SupplierId%20eq%20'" + id + "'", true); JSONArray ja = RequestExecutionHelper.getJSONArrayofResults(resp.getBody()); assertNotNull("Unable to parse JSON response", ja); JSONObject jo = (JSONObject) ja.get(0); assertEquals( "Updated Supplier via URL not persisted in db", newPhoneNumber, jo.getString("PhoneNumber")); 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()); }
/** * 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()); }