Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.google.gson.Gson;
- import com.jayway.restassured.RestAssured;
- import com.jayway.restassured.response.Response;
- import com.sun.net.httpserver.Authenticator;
- import org.junit.BeforeClass;
- import org.junit.Test;
- public class TestPutClient {
- @BeforeClass
- public static void beforeClass() {
- RestAssured.baseURI = "https://st2016.inv.bg";
- RestAssured.basePath = "/RESTapi";
- }
- @Test
- public void updateClientApi() {
- ClientDto client = new ClientDto();
- client.setFirm_name("Adidas4e");
- client.setFirm_town("Burgas");
- client.setFirm_addr("Mol Paradise");
- client.setFirm_is_reg_vat(false);
- client.setFirm_mol("312312");
- Gson gson = new Gson();
- String body = gson.toJson(client);
- System.out.println("createResponse = " + post(body, "/client").getBody().asString());
- Success success = gson.fromJson(post(body, "/client").getBody().asString(), Success.class);
- int clientId = success.getSuccess().getId();
- client.setFirm_town("Ravda");
- Gson updateConvertFromJavaToJson = new Gson();
- String updatedBody = updateConvertFromJavaToJson.toJson(client);
- System.out.println("updateResponse = " + put(updatedBody, "/client/" + clientId).getBody().asString());
- }
- private Response post(String body, String path) {
- return RestAssured.given().auth().basic("Karamfilovs@gmail.com", "123456").contentType("application/json").body(body).
- when().log().all().post(path);
- }
- private Response put(String body, String path) {
- return RestAssured.given().auth().basic("Karamfilovs@gmail.com", "123456").contentType("application/json").body(body).
- when().log().all().put(path);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement