Advertisement
Atanasov_88

Untitled

Aug 18th, 2017
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. import com.google.gson.Gson;
  2. import com.jayway.restassured.RestAssured;
  3. import com.jayway.restassured.response.Response;
  4. import com.sun.net.httpserver.Authenticator;
  5. import org.junit.BeforeClass;
  6. import org.junit.Test;
  7.  
  8. public class TestPutClient {
  9.  
  10.     @BeforeClass
  11.     public static void beforeClass() {
  12.  
  13.         RestAssured.baseURI = "https://st2016.inv.bg";
  14.         RestAssured.basePath = "/RESTapi";
  15.     }
  16.  
  17.     @Test
  18.     public void updateClientApi() {
  19.  
  20.         ClientDto client = new ClientDto();
  21.         client.setFirm_name("Adidas4e");
  22.         client.setFirm_town("Burgas");
  23.         client.setFirm_addr("Mol Paradise");
  24.         client.setFirm_is_reg_vat(false);
  25.         client.setFirm_mol("312312");
  26.  
  27.         Gson gson = new Gson();
  28.         String body = gson.toJson(client);
  29.  
  30.         System.out.println("createResponse = " + post(body, "/client").getBody().asString());
  31.  
  32.         Success success = gson.fromJson(post(body, "/client").getBody().asString(), Success.class);
  33.  
  34.         int clientId = success.getSuccess().getId();
  35.  
  36.         client.setFirm_town("Ravda");
  37.  
  38.         Gson updateConvertFromJavaToJson = new Gson();
  39.         String updatedBody = updateConvertFromJavaToJson.toJson(client);
  40.  
  41.         System.out.println("updateResponse = " + put(updatedBody, "/client/" + clientId).getBody().asString());
  42.     }
  43.  
  44.     private Response post(String body, String path) {
  45.  
  46.         return RestAssured.given().auth().basic("Karamfilovs@gmail.com", "123456").contentType("application/json").body(body).
  47.                 when().log().all().post(path);
  48.     }
  49.  
  50.     private Response put(String body, String path) {
  51.  
  52.         return RestAssured.given().auth().basic("Karamfilovs@gmail.com", "123456").contentType("application/json").body(body).
  53.                 when().log().all().put(path);
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement