Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. package com.wellsmith;
  2.  
  3. import io.restassured.response.Response;
  4. import org.json.JSONObject;
  5.  
  6. import java.io.File;
  7.  
  8. import static io.restassured.RestAssured.given;
  9.  
  10. //import org.junit.Test;
  11. //import org.testng.annotations.BeforeTest;
  12.  
  13.  
  14. public class WellSmithApiCall {
  15.  
  16. private static String BASE_URL = "https://staging.wellsmith.com";
  17. private String token;
  18.  
  19. public WellSmithApiCall() {
  20.  
  21. token = getAccessToken();
  22. }
  23.  
  24. //Get the access token for API call
  25. private String getAccessToken() {
  26. JSONObject jsonObj = new JSONObject().put("password", "temp123!")
  27. //.put("Authorization","Basic R29saWF0aGFwcDpteVNlY3JldE9BdXRoU2VjcmV0")
  28. .put("grant_tye", "password")
  29. .put("scope", "read write")
  30. .put("username", "coachbridgit")
  31. .put("client_id", "Goliathapp")
  32. .put("client_secret", "mySecretOAuthSecret");
  33.  
  34. Response resp =
  35. given()
  36. .accept("application/json")
  37. .header("Authorization", "Basic R29saWF0aGFwcDpteVNlY3JldE9BdXRoU2VjcmV0")
  38. .contentType("application/x-www-form-urlencoded")
  39. // .body(jsonObj.toString())
  40. .body("username=coachbridgit&password=temp123!&grant_type=password&scope=read%20write&client_secret=mySecretOAuthSecret&client_id=Goliathapp")
  41. .log().all()
  42. .when()
  43. .post("https://staging.wellsmith.com/oauth/token")
  44. .then()
  45. .log().all()
  46. .extract().response();
  47.  
  48. String auth_token = resp.path("access_token").toString();
  49. System.out.println(auth_token);
  50. return auth_token;
  51.  
  52. }
  53.  
  54. //Get the current users account info
  55. public Response getAccounts() {
  56. return
  57. given()
  58. .accept("application/json")
  59. .header("Authorization", "Bearer" + getAccessToken())
  60. .log().all()
  61. .when()
  62. .get("https://staging.wellsmith.com/api/account")
  63. .then()
  64. .log().all()
  65. .extract().response();
  66.  
  67. }
  68.  
  69. //verify a new patient is created
  70. public Response getGetResponse(String path) {
  71.  
  72. Response resp =
  73. given()
  74. .accept("application/json")
  75. .header("Authorization", "Bearer " + token)
  76. .contentType("application/json")
  77. .log().all()
  78. .when()
  79. .get(BASE_URL + path)
  80. .then()
  81. .log().all()
  82. .extract().response();
  83.  
  84. return resp;
  85.  
  86. }
  87.  
  88. //Return the new patients
  89. public Response getPostResponse(String path, File file) {
  90.  
  91. Response resp =
  92. given()
  93. .accept("application/json")
  94. .header("Authorization", "Bearer " + token)
  95. .contentType("application/json")
  96. .body(file)
  97. .log().all()
  98. .when()
  99. .post(BASE_URL + path)
  100. .then()
  101. .log().all()
  102. .extract().response();
  103.  
  104. return resp;
  105.  
  106. }
  107.  
  108. //Get the playbook info
  109. public Response getGetPlaybook(String path) {
  110.  
  111. Response resp =
  112. given()
  113. .accept("application/json")
  114. .header("Authorization", "Bearer " + token)
  115. .contentType("application/json")
  116. .log().all()
  117. .when()
  118. .get(BASE_URL + path)
  119. .then()
  120. .log().all()
  121. .extract().response();
  122.  
  123. return resp;
  124.  
  125. }
  126.  
  127.  
  128.  
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement