├── S1 ├── Thumbs.db └── Course Outcome.pptx ├── S2 ├── Thumbs.db ├── 2 - Steps To Set Java Home On MAC.pdf ├── Java Version - Important Information.pdf └── 3 - Java JDK Installation And Configuration.pdf ├── S3 ├── Thumbs.db ├── RestAPI Architecture.docx ├── RestAPI Architecture.pdf ├── rest.txt └── Rest API Information Text File.txt ├── S21 └── 1 - GitHub.pptx ├── S23 ├── 3-Maven Setup.pdf ├── 7-Build Lifecycle.pdf └── 3-Steps-To-Set-Java-Home-On-MAC.pdf ├── S16 ├── 3-Path.java ├── 3-EndPoints.java └── 3-Auth.java ├── S20 └── Complete Framework Code Download - twitterapis.zip ├── S7 ├── 1-GetRequestDemo.java ├── 4-ValidateResponse.java ├── 2-GetRequestDemo.java ├── 5-POSTRequestDemo.java ├── 6-PlacesAddModel.java └── 6-POSTRequestWithPOJO.java ├── S8 └── 5-TwitterPOSTRequest.java ├── S12 ├── 3-ResponseLoggingExample.java └── 2-RequestLoggingExample.java ├── LICENSE ├── S11 ├── 1-GoogleExtractResponse.java └── 2-GoogleExtractResponse.java ├── S9 ├── 1-TwitterExtractResponse.java └── 2 - TwitterExtractResponse.java ├── S13 ├── 3-TwitterSoftAssertExample.java └── 2-TwitterHardAssertExample.java ├── S17 ├── 1-RestUtilities.java ├── 2-RestUtilities.java ├── 3-RestUtilities.java └── 4-RestUtilities.java ├── S18 ├── 1-UserTimelineTest.java ├── 2-UserTimelineTest.java └── 3-UserTimelineTest.java ├── S14 ├── 1-TwitterRootPathExample.java └── 2-TwitterCheckResponseTime.java ├── S15 ├── 3-ResponseSpecificationDemo.java ├── 2-RequestSpecificationDemo.java └── 4-SpecificationWithTime.java ├── S10 ├── 1-TwitterGETRequest.java ├── 2-TwitterEndToEndWorkflow.java └── 3-TwitterEndToEndWorkflow.java ├── S19 ├── 1-TwitterEndToEndWorkflow.java └── 2-TwitterWorkflowTest.java └── README.md /S1/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S1/Thumbs.db -------------------------------------------------------------------------------- /S2/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S2/Thumbs.db -------------------------------------------------------------------------------- /S3/Thumbs.db: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S3/Thumbs.db -------------------------------------------------------------------------------- /S21/1 - GitHub.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S21/1 - GitHub.pptx -------------------------------------------------------------------------------- /S1/Course Outcome.pptx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S1/Course Outcome.pptx -------------------------------------------------------------------------------- /S23/3-Maven Setup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S23/3-Maven Setup.pdf -------------------------------------------------------------------------------- /S23/7-Build Lifecycle.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S23/7-Build Lifecycle.pdf -------------------------------------------------------------------------------- /S3/RestAPI Architecture.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S3/RestAPI Architecture.docx -------------------------------------------------------------------------------- /S3/RestAPI Architecture.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S3/RestAPI Architecture.pdf -------------------------------------------------------------------------------- /S2/2 - Steps To Set Java Home On MAC.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S2/2 - Steps To Set Java Home On MAC.pdf -------------------------------------------------------------------------------- /S23/3-Steps-To-Set-Java-Home-On-MAC.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S23/3-Steps-To-Set-Java-Home-On-MAC.pdf -------------------------------------------------------------------------------- /S2/Java Version - Important Information.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S2/Java Version - Important Information.pdf -------------------------------------------------------------------------------- /S2/3 - Java JDK Installation And Configuration.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S2/3 - Java JDK Installation And Configuration.pdf -------------------------------------------------------------------------------- /S16/3-Path.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.constants; 2 | 3 | public class Path { 4 | public static final String BASE_URI = "https://api.twitter.com"; 5 | public static final String STATUSES = "/1.1/statuses"; 6 | } 7 | -------------------------------------------------------------------------------- /S20/Complete Framework Code Download - twitterapis.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Rest-API-Automation-With-Rest-Assured---Novice-To-Ninja/HEAD/S20/Complete Framework Code Download - twitterapis.zip -------------------------------------------------------------------------------- /S16/3-EndPoints.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.constants; 2 | 3 | public class EndPoints { 4 | public static final String STATUSES_USER_TIMELINE = "/user_timeline.json"; 5 | public static final String STATUSES_TWEET_POST = "/update.json"; 6 | public static final String STATUSES_TWEET_READ_SINGLE = "/show.json"; 7 | public static final String STATUSES_TWEET_DESTROY = "/destroy/{id}.json"; 8 | } -------------------------------------------------------------------------------- /S16/3-Auth.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.constants; 2 | 3 | public class Auth { 4 | public static final String CONSUMER_KEY = "ubhe5nnmztzlJMzdLihtKEgsT"; 5 | public static final String CONSUMER_SECRET = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 6 | public static final String ACCESS_TOKEN = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 7 | public static final String ACCESS_SECRET = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 8 | } -------------------------------------------------------------------------------- /S7/1-GetRequestDemo.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.response.Response; 8 | 9 | public class GetRequestDemo { 10 | /*** 11 | * Given I have this information 12 | When I perform this action 13 | Then this should be the output 14 | */ 15 | @BeforeClass 16 | public void setup() { 17 | RestAssured.baseURI = "https://maps.googleapis.com"; 18 | RestAssured.basePath = "/maps/api"; 19 | } 20 | 21 | @Test 22 | public void statusCodeVerification() { 23 | given() 24 | .param("units", "imperial") 25 | .param("origins", "Washington,DC") 26 | .param("destinations", "New+York+City,NY") 27 | .param("key", "AIzaSyAFNxOzcDNEZ9coJzPc_9N-CA8Euun2fDA") 28 | .when() 29 | .get("/distancematrix/json") 30 | .then() 31 | .statusCode(200); 32 | } 33 | } -------------------------------------------------------------------------------- /S7/4-ValidateResponse.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.http.ContentType; 8 | 9 | import static org.hamcrest.Matchers.equalTo; 10 | 11 | public class ValidateResponse { 12 | @BeforeClass 13 | public void setup() { 14 | RestAssured.baseURI = "https://maps.googleapis.com"; 15 | RestAssured.basePath = "/maps/api"; 16 | } 17 | 18 | @Test 19 | public void statusCodeVerification() { 20 | given() 21 | .param("units", "imperial") 22 | .param("origins", "Washington,DC") 23 | .param("destinations", "New+York+City,NY") 24 | .param("key", "AIzaSyAFNxOzcDNEZ9coJzPc_9N-CA8Euun2fDA") 25 | .when() 26 | .get("/distancematrix/json") 27 | .then() 28 | .statusCode(200) 29 | .and() 30 | .body("rows[0].elements[0].distance.text", equalTo("225 mi")) 31 | .contentType(ContentType.JSON); 32 | } 33 | } -------------------------------------------------------------------------------- /S8/5-TwitterPOSTRequest.java: -------------------------------------------------------------------------------- 1 | package twitterapiexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | 8 | public class TwitterPOSTRequest { 9 | 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | 15 | @BeforeClass 16 | public void setup() { 17 | RestAssured.baseURI = "https://api.twitter.com"; 18 | RestAssured.basePath = "/1.1/statuses"; 19 | } 20 | 21 | @Test 22 | public void statusCodeVerification() { 23 | given() 24 | .auth() 25 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 26 | .queryParam("status", "My First Tweet") 27 | .when() 28 | .post("/update.json") 29 | .then() 30 | .statusCode(200); 31 | } 32 | } -------------------------------------------------------------------------------- /S12/3-ResponseLoggingExample.java: -------------------------------------------------------------------------------- 1 | package loggingexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | 8 | public class ResponseLoggingExample { 9 | 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | 15 | @BeforeClass 16 | public void setup() { 17 | RestAssured.baseURI = "https://api.twitter.com"; 18 | RestAssured.basePath = "/1.1/statuses"; 19 | } 20 | 21 | @Test 22 | public void testMethod() { 23 | given() 24 | .auth() 25 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 26 | .queryParam("status", "My First Tweet 11") 27 | .when() 28 | .post("/update.json") 29 | .then() 30 | .log() 31 | //.headers() 32 | //.body() 33 | //.all() 34 | .ifError() 35 | .statusCode(200); 36 | } 37 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /S11/1-GoogleExtractResponse.java: -------------------------------------------------------------------------------- 1 | package extractresponse; 2 | import static io.restassured.RestAssured.given; 3 | import org.testng.annotations.BeforeClass; 4 | import org.testng.annotations.Test; 5 | import io.restassured.RestAssured; 6 | import io.restassured.response.Response; 7 | 8 | public class GoogleExtractResponse { 9 | @BeforeClass 10 | public void setup() { 11 | RestAssured.baseURI = "https://maps.googleapis.com"; 12 | RestAssured.basePath = "/maps/api"; 13 | } 14 | @Test 15 | public void extractResponse() { 16 | Response response = given() 17 | .queryParam("units", "imperial") 18 | .queryParam("origins", "Washington,DC") 19 | .queryParam("destinations", "New+York+City,NY") 20 | .queryParam("key", "AIzaSyAFNxOzcDNEZ9coJzPc_9N-CA8Euun2fDA") 21 | .when() 22 | .get("/distancematrix/xml") 23 | .then() 24 | .statusCode(200).extract().response(); 25 | String responseString = response.asString(); 26 | System.out.println(responseString); 27 | 28 | String value = response.path("distancematrixresponse.row.element.duration.value"); 29 | System.out.println("The duration value is: " + value); 30 | } 31 | } -------------------------------------------------------------------------------- /S12/2-RequestLoggingExample.java: -------------------------------------------------------------------------------- 1 | package loggingexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | 8 | public class RequestLoggingExample { 9 | 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | 15 | @BeforeClass 16 | public void setup() { 17 | RestAssured.baseURI = "https://api.twitter.com"; 18 | RestAssured.basePath = "/1.1/statuses"; 19 | } 20 | 21 | @Test 22 | public void testMethod() { 23 | given() 24 | .log() 25 | //.headers() 26 | //.body() 27 | //.parameters() 28 | //.all() 29 | .ifValidationFails() 30 | .auth() 31 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 32 | .queryParam("status", "My First Tweet 3") 33 | .when() 34 | .post("/update.json") 35 | .then() 36 | .statusCode(200); 37 | } 38 | } -------------------------------------------------------------------------------- /S9/1-TwitterExtractResponse.java: -------------------------------------------------------------------------------- 1 | package twitterapiexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.response.Response; 8 | 9 | public class TwitterExtractResponse { 10 | 11 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 12 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 13 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 14 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 15 | 16 | @BeforeClass 17 | public void setup() { 18 | RestAssured.baseURI = "https://api.twitter.com"; 19 | RestAssured.basePath = "/1.1/statuses"; 20 | } 21 | 22 | @Test 23 | public void extractResponse() { 24 | Response response = given() 25 | .auth() 26 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 27 | .queryParam("status", "My First Tweet") 28 | .when() 29 | .post("/update.json") 30 | .then() 31 | .statusCode(200) 32 | .extract().response(); 33 | 34 | String id = response.path("id_str"); 35 | System.out.println(id); 36 | } 37 | } -------------------------------------------------------------------------------- /S13/3-TwitterSoftAssertExample.java: -------------------------------------------------------------------------------- 1 | package assertexamples; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import static org.hamcrest.Matchers.*; 8 | 9 | public class TwitterSoftAssertExample { 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | 15 | @BeforeClass 16 | public void setup() { 17 | RestAssured.baseURI = "https://api.twitter.com"; 18 | RestAssured.basePath = "/1.1/statuses"; 19 | } 20 | 21 | @Test 22 | public void readTweets() { 23 | given() 24 | .auth() 25 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 26 | .queryParam("user_id", "apiautomation") 27 | .when() 28 | .get("/user_timeline.json") 29 | .then() 30 | .statusCode(200) 31 | .body("user.name", hasItem("RestAPI Automation")) 32 | .body("entities.hashtags[0].text", hasItem("multiple1"), 33 | "entities.hashtags[0].size()", equalTo(3), 34 | "entities.hashtags[1].size()", lessThan(2)); 35 | } 36 | } -------------------------------------------------------------------------------- /S13/2-TwitterHardAssertExample.java: -------------------------------------------------------------------------------- 1 | package assertexamples; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import static org.hamcrest.Matchers.*; 8 | 9 | public class TwitterHardAssertExample { 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | 15 | @BeforeClass 16 | public void setup() { 17 | RestAssured.baseURI = "https://api.twitter.com"; 18 | RestAssured.basePath = "/1.1/statuses"; 19 | } 20 | 21 | @Test 22 | public void readTweets() { 23 | given() 24 | .auth() 25 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 26 | .queryParam("user_id", "apiautomation") 27 | .when() 28 | .get("/user_timeline.json") 29 | .then() 30 | .statusCode(200) 31 | .body("user.name", hasItem("RestAPI Automation")) 32 | .body("entities.hashtags[0].text", hasItem("multiple1")) 33 | .body("entities.hashtags[0].size()", equalTo(3)) 34 | .body("entities.hashtags[1].size()", lessThan(2)); 35 | } 36 | } -------------------------------------------------------------------------------- /S17/1-RestUtilities.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.common; 2 | 3 | import com.letskodeit.constants.Auth; 4 | import com.letskodeit.constants.Path; 5 | import io.restassured.RestAssured; 6 | import io.restassured.authentication.AuthenticationScheme; 7 | import io.restassured.builder.RequestSpecBuilder; 8 | import io.restassured.builder.ResponseSpecBuilder; 9 | import io.restassured.specification.RequestSpecification; 10 | import io.restassured.specification.ResponseSpecification; 11 | 12 | public class RestUtilities { 13 | 14 | public static String ENDPOINT; 15 | public static RequestSpecBuilder REQUEST_BUILDER; 16 | public static RequestSpecification REQUEST_SPEC; 17 | public static ResponseSpecBuilder RESPONSE_BUILDER; 18 | public static ResponseSpecification RESPONSE_SPEC; 19 | 20 | public static void setEndPoint(String epoint) { 21 | ENDPOINT = epoint; 22 | } 23 | 24 | public static RequestSpecification getRequestSpecification() { 25 | AuthenticationScheme authScheme = 26 | RestAssured.oauth(Auth.CONSUMER_KEY, Auth.CONSUMER_SECRET, Auth.ACCESS_TOKEN, 27 | Auth.ACCESS_SECRET); 28 | REQUEST_BUILDER = new RequestSpecBuilder(); 29 | REQUEST_BUILDER.setBaseUri(Path.BASE_URI); 30 | REQUEST_BUILDER.setAuth(authScheme); 31 | REQUEST_SPEC = REQUEST_BUILDER.build(); 32 | return REQUEST_SPEC; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /S18/1-UserTimelineTest.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.statuses; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.Assert; 5 | import org.testng.annotations.BeforeClass; 6 | import org.testng.annotations.Test; 7 | import com.letskodeit.common.RestUtilities; 8 | import com.letskodeit.constants.EndPoints; 9 | import com.letskodeit.constants.Path; 10 | import io.restassured.response.Response; 11 | import io.restassured.specification.RequestSpecification; 12 | import io.restassured.specification.ResponseSpecification; 13 | import static org.hamcrest.Matchers.*; 14 | import java.util.ArrayList; 15 | 16 | 17 | public class UserTimelineTest { 18 | 19 | RequestSpecification reqSpec; 20 | ResponseSpecification resSpec; 21 | 22 | @BeforeClass 23 | public void setup() { 24 | reqSpec = RestUtilities.getRequestSpecification(); 25 | reqSpec.queryParam("user_id", "apiautomation"); 26 | reqSpec.basePath(Path.STATUSES); 27 | 28 | resSpec = RestUtilities.getResponseSpecification(); 29 | } 30 | 31 | @Test 32 | public void readTweets1() { 33 | given() 34 | .spec(RestUtilities.createQueryParam(reqSpec, "count", "1")) 35 | .when() 36 | .get(EndPoints.STATUSES_USER_TIMELINE) 37 | .then() 38 | .log().all() 39 | .spec(resSpec) 40 | .body("user.screen_name", hasItem("apiautomation")); 41 | } 42 | } -------------------------------------------------------------------------------- /S18/2-UserTimelineTest.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.statuses; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.Assert; 5 | import org.testng.annotations.BeforeClass; 6 | import org.testng.annotations.Test; 7 | import com.letskodeit.common.RestUtilities; 8 | import com.letskodeit.constants.EndPoints; 9 | import com.letskodeit.constants.Path; 10 | import io.restassured.response.Response; 11 | import io.restassured.specification.RequestSpecification; 12 | import io.restassured.specification.ResponseSpecification; 13 | import static org.hamcrest.Matchers.*; 14 | import java.util.ArrayList; 15 | 16 | 17 | public class UserTimelineTest { 18 | 19 | RequestSpecification reqSpec; 20 | ResponseSpecification resSpec; 21 | 22 | @BeforeClass 23 | public void setup() { 24 | reqSpec = RestUtilities.getRequestSpecification(); 25 | reqSpec.queryParam("user_id", "apiautomation"); 26 | reqSpec.basePath(Path.STATUSES); 27 | 28 | resSpec = RestUtilities.getResponseSpecification(); 29 | } 30 | 31 | @Test 32 | public void readTweets1() { 33 | given() 34 | .spec(RestUtilities.createQueryParam(reqSpec, "count", "1")) 35 | .when() 36 | .get(EndPoints.STATUSES_USER_TIMELINE) 37 | .then() 38 | .log().all() 39 | .spec(resSpec) 40 | .body("user.screen_name", hasItem("apiautomation")); 41 | } 42 | } -------------------------------------------------------------------------------- /S7/2-GetRequestDemo.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.response.Response; 8 | 9 | public class GetRequestDemo { 10 | /*** 11 | * Given I have this information 12 | When I perform this action 13 | Then this should be the output 14 | */ 15 | @BeforeClass 16 | public void setup() { 17 | RestAssured.baseURI = "https://maps.googleapis.com"; 18 | RestAssured.basePath = "/maps/api"; 19 | } 20 | 21 | @Test(enabled=false) 22 | public void statusCodeVerification() { 23 | given() 24 | .param("units", "imperial") 25 | .param("origins", "Washington,DC") 26 | .param("destinations", "New+York+City,NY") 27 | .param("key", "AIzaSyAFNxOzcDNEZ9coJzPc_9N-CA8Euun2fDA") 28 | .when() 29 | .get("/distancematrix/json") 30 | .then() 31 | .statusCode(200); 32 | } 33 | 34 | @Test 35 | public void getResponseBody() { 36 | Response res = 37 | given() 38 | .param("units", "imperial") 39 | .param("origins", "Washington,DC") 40 | .param("destinations", "New+York+City,NY") 41 | .param("key", "AIzaSyAFNxOzcDNEZ9coJzPc_9N-CA8Euun2fDA") 42 | .when() 43 | .get("/distancematrix/json"); 44 | 45 | System.out.println(res.body().prettyPrint()); 46 | } 47 | } -------------------------------------------------------------------------------- /S14/1-TwitterRootPathExample.java: -------------------------------------------------------------------------------- 1 | package usefultricks; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import static org.hamcrest.Matchers.*; 8 | 9 | public class TwitterRootPathExample { 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | 15 | @BeforeClass 16 | public void setup() { 17 | RestAssured.baseURI = "https://api.twitter.com"; 18 | RestAssured.basePath = "/1.1/statuses"; 19 | RestAssured.rootPath = "entities.hashtags[0]"; 20 | } 21 | 22 | @Test 23 | public void readTweets() { 24 | given() 25 | .auth() 26 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 27 | .queryParam("user_id", "apiautomation") 28 | .when() 29 | .get("/user_timeline.json") 30 | .then() 31 | .statusCode(200) 32 | .log().body() 33 | //.rootPath("user") 34 | // .body("user.name", hasItem("RestAPI Automation")) 35 | // .body("user.screen_name", hasItem("apiautomation")) 36 | //.rootPath("entities.hashtags[0]") 37 | .body("text", hasItem("multiple")) 38 | .body("size()", equalTo(2)); 39 | } 40 | } -------------------------------------------------------------------------------- /S11/2-GoogleExtractResponse.java: -------------------------------------------------------------------------------- 1 | package extractresponse; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.path.xml.XmlPath; 8 | import io.restassured.response.Response; 9 | 10 | public class GoogleExtractResponse { 11 | 12 | @BeforeClass 13 | public void setup() { 14 | RestAssured.baseURI = "https://maps.googleapis.com"; 15 | RestAssured.basePath = "/maps/api"; 16 | } 17 | 18 | @Test 19 | public void extractResponse() { 20 | Response response = given() 21 | .queryParam("units", "imperial") 22 | .queryParam("origins", "Washington,DC") 23 | .queryParam("destinations", "New+York+City,NY") 24 | .queryParam("key", "AIzaSyAFNxOzcDNEZ9coJzPc_9N-CA8Euun2fDA") 25 | .when() 26 | .get("/distancematrix/xml") 27 | .then() 28 | .statusCode(200).extract().response(); 29 | 30 | String responseString = response.asString(); 31 | System.out.println(responseString); 32 | 33 | String value = response.path("distancematrixresponse.row.element.duration.value"); 34 | System.out.println("The duration value is: " + value); 35 | 36 | XmlPath xmlPath = new XmlPath(responseString); 37 | String text = xmlPath.get("distancematrixresponse.row.element.duration.text"); 38 | System.out.println("The duration text using XMLPath is: " + text); 39 | } 40 | } -------------------------------------------------------------------------------- /S7/5-POSTRequestDemo.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.http.ContentType; 8 | import io.restassured.response.Response; 9 | import static org.hamcrest.Matchers.equalTo; 10 | 11 | public class POSTRequestDemo { 12 | 13 | @BeforeClass 14 | public void setup() { 15 | RestAssured.baseURI = "https://maps.googleapis.com"; 16 | RestAssured.basePath = "/maps/api"; 17 | } 18 | 19 | @Test 20 | public void statusCodeVerification() { 21 | Response res = given() 22 | .queryParam("key", "AIzaSyAFNxOzcDNEZ9coJzPc_9N-CA8Euun2fDA") 23 | .body("{" 24 | + "\"location\": {" 25 | + "\"lat\": -33.8669710," 26 | + "\"lng\": 151.1958750" 27 | + "}," 28 | + "\"accuracy\": 50," 29 | + "\"name\": \"Google Shoes!\"," 30 | + "\"phone_number\": \"(02) 9374 4000\"," 31 | + "\"address\": \"48 Pirrama Road, Pyrmont, NSW 2009, Australia\"," 32 | + "\"types\": [\"shoe_store\"]," 33 | + "\"website\": \"http://www.google.com.au/\"," 34 | + "\"language\": \"en-AU\"" 35 | + "}") 36 | .when() 37 | .post("/place/add/json"); 38 | System.out.println(res.body().asString()); 39 | // .then() 40 | // .statusCode(200).and() 41 | // .contentType(ContentType.JSON).and() 42 | // .body("scope", equalTo("APP")).and() 43 | // .body("status", equalTo("OK")); 44 | } 45 | } -------------------------------------------------------------------------------- /S9/2 - TwitterExtractResponse.java: -------------------------------------------------------------------------------- 1 | package twitterapiexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.path.json.JsonPath; 8 | import io.restassured.response.Response; 9 | 10 | 11 | public class TwitterExtractResponse { 12 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 13 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 14 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 15 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 16 | 17 | @BeforeClass 18 | public void setup() { 19 | RestAssured.baseURI = "https://api.twitter.com"; 20 | RestAssured.basePath = "/1.1/statuses"; 21 | } 22 | 23 | @Test 24 | public void extractResponse() { 25 | Response response = 26 | given() 27 | .auth() 28 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 29 | .queryParam("status", "My First Tweet") 30 | .when() 31 | .post("/update.json") 32 | .then() 33 | .statusCode(200) 34 | .extract() 35 | .response(); 36 | 37 | String id = response.path("id_str"); 38 | System.out.println("The response.path: " + id); 39 | 40 | String responseString = response.asString(); 41 | System.out.println(responseString); 42 | 43 | JsonPath jsPath = new JsonPath(responseString); 44 | String name = jsPath.get("user.name"); 45 | System.out.println("The username is: " + name); 46 | } 47 | } -------------------------------------------------------------------------------- /S15/3-ResponseSpecificationDemo.java: -------------------------------------------------------------------------------- 1 | package specs; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.builder.ResponseSpecBuilder; 8 | import io.restassured.specification.ResponseSpecification; 9 | 10 | import static org.hamcrest.Matchers.*; 11 | 12 | public class ResponseSpecificationDemo { 13 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 14 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 15 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 16 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 17 | 18 | ResponseSpecBuilder responseBuilder; 19 | static ResponseSpecification responseSpec; 20 | 21 | @BeforeClass 22 | public void setup() { 23 | RestAssured.baseURI = "https://api.twitter.com"; 24 | RestAssured.basePath = "/1.1/statuses"; 25 | responseBuilder = new ResponseSpecBuilder(); 26 | responseBuilder.expectStatusCode(200); 27 | responseBuilder.expectBody("user.name", hasItem("RestAPI Automation")); 28 | responseSpec = responseBuilder.build(); 29 | } 30 | 31 | @Test 32 | public void readTweets() { 33 | given() 34 | .auth() 35 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 36 | .queryParam("user_id", "apiautomation") 37 | .when() 38 | .get("/user_timeline.json") 39 | .then() 40 | // .statusCode(200) 41 | // .body("user.name", hasItem("RestAPI Automation")) 42 | // .body("user.screen_name", hasItem("apiautomation")); 43 | .spec(responseSpec) 44 | .body("user.screen_name", hasItem("apiautomation")); 45 | } 46 | } -------------------------------------------------------------------------------- /S7/6-PlacesAddModel.java: -------------------------------------------------------------------------------- 1 | package models; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | public class PlacesAddModel { 7 | 8 | private Map location; 9 | private int accuracy; 10 | private String name; 11 | private String phone_number; 12 | private String address; 13 | private List types; 14 | private String website; 15 | private String language; 16 | 17 | public Map getLocation() { 18 | return location; 19 | } 20 | 21 | public void setLocation(Map location) { 22 | this.location = location; 23 | } 24 | 25 | public int getAccuracy() { 26 | return accuracy; 27 | } 28 | 29 | public void setAccuracy(int accuracy) { 30 | this.accuracy = accuracy; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | 41 | public String getPhone_number() { 42 | return phone_number; 43 | } 44 | 45 | public void setPhone_number(String phone_number) { 46 | this.phone_number = phone_number; 47 | } 48 | 49 | public String getAddress() { 50 | return address; 51 | } 52 | 53 | public void setAddress(String address) { 54 | this.address = address; 55 | } 56 | 57 | public List getTypes() { 58 | return types; 59 | } 60 | 61 | public void setTypes(List types) { 62 | this.types = types; 63 | } 64 | 65 | public String getWebsite() { 66 | return website; 67 | } 68 | 69 | public void setWebsite(String website) { 70 | this.website = website; 71 | } 72 | 73 | public String getLanguage() { 74 | return language; 75 | } 76 | 77 | public void setLanguage(String language) { 78 | this.language = language; 79 | } 80 | } -------------------------------------------------------------------------------- /S18/3-UserTimelineTest.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.statuses; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.Assert; 5 | import org.testng.annotations.BeforeClass; 6 | import org.testng.annotations.Test; 7 | import com.letskodeit.common.RestUtilities; 8 | import com.letskodeit.constants.EndPoints; 9 | import com.letskodeit.constants.Path; 10 | import io.restassured.response.Response; 11 | import io.restassured.specification.RequestSpecification; 12 | import io.restassured.specification.ResponseSpecification; 13 | import static org.hamcrest.Matchers.*; 14 | import java.util.ArrayList; 15 | 16 | 17 | public class UserTimelineTest { 18 | 19 | RequestSpecification reqSpec; 20 | ResponseSpecification resSpec; 21 | 22 | @BeforeClass 23 | public void setup() { 24 | reqSpec = RestUtilities.getRequestSpecification(); 25 | reqSpec.queryParam("user_id", "apiautomation"); 26 | reqSpec.basePath(Path.STATUSES); 27 | 28 | resSpec = RestUtilities.getResponseSpecification(); 29 | } 30 | 31 | @Test 32 | public void readTweets1() { 33 | given() 34 | .spec(RestUtilities.createQueryParam(reqSpec, "count", "1")) 35 | .when() 36 | .get(EndPoints.STATUSES_USER_TIMELINE) 37 | .then() 38 | .log().all() 39 | .spec(resSpec) 40 | .body("user.screen_name", hasItem("apiautomation")); 41 | } 42 | 43 | @Test 44 | public void readTweets2() { 45 | RestUtilities.setEndPoint(EndPoints.STATUSES_USER_TIMELINE); 46 | Response res = RestUtilities.getResponse( 47 | RestUtilities.createQueryParam(reqSpec, "count", "2"), "get"); 48 | ArrayList screenNameList = res.path("user.screen_name"); 49 | System.out.println("Read Tweets 2 Method"); 50 | Assert.assertTrue(screenNameList.contains("apiautomation")); 51 | } 52 | } -------------------------------------------------------------------------------- /S15/2-RequestSpecificationDemo.java: -------------------------------------------------------------------------------- 1 | package specs; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.authentication.AuthenticationScheme; 8 | import io.restassured.builder.RequestSpecBuilder; 9 | import io.restassured.specification.RequestSpecification; 10 | 11 | public class RequestSpecificationDemo { 12 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 13 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 14 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 15 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 16 | 17 | RequestSpecBuilder requestBuilder; 18 | static RequestSpecification requestSpec; 19 | 20 | @BeforeClass 21 | public void setup() { 22 | // RestAssured.baseURI = "https://api.twitter.com"; 23 | // RestAssured.basePath = "/1.1/statuses"; 24 | AuthenticationScheme authScheme = 25 | RestAssured.oauth(consumerKey, consumerSecret, accessToken, accessSecret); 26 | requestBuilder = new RequestSpecBuilder(); 27 | requestBuilder.setBaseUri("https://api.twitter.com"); 28 | requestBuilder.setBasePath("/1.1/statuses"); 29 | requestBuilder.addQueryParam("user_id", "apiautomation"); 30 | requestBuilder.setAuth(authScheme); 31 | requestSpec = requestBuilder.build(); 32 | } 33 | 34 | @Test 35 | public void readTweets() { 36 | given() 37 | .spec(requestSpec) 38 | // .auth() 39 | // .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 40 | // .queryParam("user_id", "apiautomation") 41 | .when() 42 | .get("/user_timeline.json") 43 | .then() 44 | .statusCode(200); 45 | } 46 | } -------------------------------------------------------------------------------- /S10/1-TwitterGETRequest.java: -------------------------------------------------------------------------------- 1 | package twitterapiexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.path.json.JsonPath; 8 | import io.restassured.response.Response; 9 | 10 | 11 | public class TwitterGETRequest { 12 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 13 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 14 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 15 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 16 | String tweetId = ""; 17 | 18 | @BeforeClass 19 | public void setup() { 20 | RestAssured.baseURI = "https://api.twitter.com"; 21 | RestAssured.basePath = "/1.1/statuses"; 22 | } 23 | 24 | @Test 25 | public void postTweet() { 26 | Response response = 27 | given() 28 | .auth() 29 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 30 | .queryParam("status", "My First Tweet") 31 | .when() 32 | .post("/update.json") 33 | .then() 34 | .statusCode(200) 35 | .extract() 36 | .response(); 37 | 38 | tweetId = response.path("id_str"); 39 | System.out.println("The response.path: " + tweetId); 40 | } 41 | 42 | @Test(dependsOnMethods={"postTweet"}) 43 | public void readTweet() { 44 | Response response = 45 | given() 46 | .auth() 47 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 48 | .queryParam("id", tweetId) 49 | .when() 50 | .get("/show.json") 51 | .then() 52 | .extract() 53 | .response(); 54 | 55 | String text = response.path("text"); 56 | System.out.println("The tweet text is: " + text); 57 | } 58 | } -------------------------------------------------------------------------------- /S14/2-TwitterCheckResponseTime.java: -------------------------------------------------------------------------------- 1 | package usefultricks; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import static org.hamcrest.Matchers.*; 8 | 9 | import java.util.concurrent.TimeUnit; 10 | 11 | public class TwitterCheckResponseTime { 12 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 13 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 14 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 15 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 16 | 17 | @BeforeClass 18 | public void setup() { 19 | RestAssured.baseURI = "https://api.twitter.com"; 20 | RestAssured.basePath = "/1.1/statuses"; 21 | } 22 | 23 | @Test 24 | public void readTweets() { 25 | // long responseTime = 26 | // given() 27 | // .auth() 28 | // .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 29 | // .queryParam("user_id", "apiautomation") 30 | // .when() 31 | // .get("/user_timeline.json") 32 | // //.time(); 33 | // .timeIn(TimeUnit.SECONDS); 34 | // System.out.println("Response Time: " + responseTime); 35 | 36 | given() 37 | .auth() 38 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 39 | .queryParam("user_id", "apiautomation") 40 | .when() 41 | .get("/user_timeline.json") 42 | .then() 43 | .statusCode(200) 44 | .time(lessThan(1L), TimeUnit.SECONDS) 45 | .log().body() 46 | .body("user.name", hasItem("RestAPI Automation")) 47 | .body("user.screen_name", hasItem("apiautomation")) 48 | .body("entities.hashtags[0].text", hasItem("multiple")) 49 | .body("entities.hashtags[0].size()", equalTo(2)); 50 | } 51 | } -------------------------------------------------------------------------------- /S7/6-POSTRequestWithPOJO.java: -------------------------------------------------------------------------------- 1 | package basic; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | 7 | import groovyjarjarantlr.collections.List; 8 | import io.restassured.RestAssured; 9 | import io.restassured.http.ContentType; 10 | import io.restassured.response.Response; 11 | import models.PlacesAddModel; 12 | 13 | import static org.hamcrest.Matchers.equalTo; 14 | 15 | import java.util.ArrayList; 16 | import java.util.HashMap; 17 | import java.util.Map; 18 | 19 | public class POSTRequestWithPOJO { 20 | 21 | @BeforeClass 22 | public void setup() { 23 | RestAssured.baseURI = "https://maps.googleapis.com"; 24 | RestAssured.basePath = "/maps/api"; 25 | } 26 | 27 | @Test 28 | public void statusCodeVerification() { 29 | Map locationMap = new HashMap(); 30 | locationMap.put("lat", -33.8669710); 31 | locationMap.put("lng", 151.1958750); 32 | 33 | ArrayList types = new ArrayList(); 34 | types.add("shoe_store"); 35 | 36 | PlacesAddModel places = new PlacesAddModel(); 37 | places.setLocation(locationMap); 38 | places.setAccuracy(50); 39 | places.setName("Google Shoes!"); 40 | places.setPhone_number("(02) 9374 4000"); 41 | places.setAddress("48 Pirrama Road, Pyrmont, NSW 2009, Australia"); 42 | places.setTypes(types); 43 | places.setWebsite("http://www.google.com.au/"); 44 | places.setLanguage("en-AU"); 45 | 46 | // jackson or gson -> They serialize the object into JSON format 47 | //Response res = 48 | given() 49 | .queryParam("key", "AIzaSyAFNxOzcDNEZ9coJzPc_9N-CA8Euun2fDA") 50 | .body(places) 51 | .when() 52 | .post("/place/add/json") 53 | //System.out.println(res.body().asString()); 54 | .then() 55 | .statusCode(200).and() 56 | .contentType(ContentType.JSON).and() 57 | .body("scope", equalTo("APP")).and() 58 | .body("status", equalTo("OK")); 59 | } 60 | } -------------------------------------------------------------------------------- /S10/2-TwitterEndToEndWorkflow.java: -------------------------------------------------------------------------------- 1 | package twitterapiexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.response.Response; 8 | 9 | public class TwitterEndToEndWorkflow { 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | String tweetId = ""; 15 | 16 | @BeforeClass 17 | public void setup() { 18 | RestAssured.baseURI = "https://api.twitter.com"; 19 | RestAssured.basePath = "/1.1/statuses"; 20 | } 21 | 22 | @Test 23 | public void postTweet() { 24 | Response response = 25 | given() 26 | .auth() 27 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 28 | .queryParam("status", "My First Tweet") 29 | .when() 30 | .post("/update.json") 31 | .then() 32 | .statusCode(200) 33 | .extract() 34 | .response(); 35 | 36 | tweetId = response.path("id_str"); 37 | System.out.println("The response.path: " + tweetId); 38 | } 39 | 40 | @Test(dependsOnMethods={"postTweet"}) 41 | public void readTweet() { 42 | Response response = 43 | given() 44 | .auth() 45 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 46 | .queryParam("id", tweetId) 47 | .when() 48 | .get("/show.json") 49 | .then() 50 | .extract() 51 | .response(); 52 | 53 | String text = response.path("text"); 54 | System.out.println("The tweet text is: " + text); 55 | } 56 | 57 | @Test(dependsOnMethods={"readTweet"}) 58 | public void deleteTweet() { 59 | given() 60 | .auth() 61 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 62 | .queryParam("id", tweetId) 63 | .when() 64 | .post("/destroy.json") 65 | .then() 66 | .statusCode(200); 67 | } 68 | } -------------------------------------------------------------------------------- /S19/1-TwitterEndToEndWorkflow.java: -------------------------------------------------------------------------------- 1 | package twitterapiexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.response.Response; 8 | 9 | public class TwitterEndToEndWorkflow { 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | String tweetId = ""; 15 | 16 | @BeforeClass 17 | public void setup() { 18 | RestAssured.baseURI = "https://api.twitter.com"; 19 | RestAssured.basePath = "/1.1/statuses"; 20 | } 21 | 22 | @Test 23 | public void postTweet() { 24 | Response response = 25 | given() 26 | .auth() 27 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 28 | .queryParam("status", "My First Tweet") 29 | .when() 30 | .post("/update.json") 31 | .then() 32 | .statusCode(200) 33 | .extract() 34 | .response(); 35 | 36 | tweetId = response.path("id_str"); 37 | System.out.println("The response.path: " + tweetId); 38 | } 39 | 40 | @Test(dependsOnMethods={"postTweet"}) 41 | public void readTweet() { 42 | Response response = 43 | given() 44 | .auth() 45 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 46 | .queryParam("id", tweetId) 47 | .when() 48 | .get("/show.json") 49 | .then() 50 | .extract() 51 | .response(); 52 | 53 | String text = response.path("text"); 54 | System.out.println("The tweet text is: " + text); 55 | } 56 | 57 | @Test(dependsOnMethods={"readTweet"}) 58 | public void deleteTweet() { 59 | given() 60 | .auth() 61 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 62 | .pathParam("id", tweetId) 63 | .when() 64 | .post("/destroy/{id}.json") 65 | .then() 66 | .statusCode(200); 67 | } 68 | } -------------------------------------------------------------------------------- /S10/3-TwitterEndToEndWorkflow.java: -------------------------------------------------------------------------------- 1 | package twitterapiexample; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.response.Response; 8 | 9 | public class TwitterEndToEndWorkflow { 10 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 11 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 12 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 13 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 14 | String tweetId = ""; 15 | 16 | @BeforeClass 17 | public void setup() { 18 | RestAssured.baseURI = "https://api.twitter.com"; 19 | RestAssured.basePath = "/1.1/statuses"; 20 | } 21 | 22 | @Test 23 | public void postTweet() { 24 | Response response = 25 | given() 26 | .auth() 27 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 28 | .queryParam("status", "My First Tweet") 29 | .when() 30 | .post("/update.json") 31 | .then() 32 | .statusCode(200) 33 | .extract() 34 | .response(); 35 | 36 | tweetId = response.path("id_str"); 37 | System.out.println("The response.path: " + tweetId); 38 | } 39 | 40 | @Test(dependsOnMethods={"postTweet"}) 41 | public void readTweet() { 42 | Response response = 43 | given() 44 | .auth() 45 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 46 | .queryParam("id", tweetId) 47 | .when() 48 | .get("/show.json") 49 | .then() 50 | .extract() 51 | .response(); 52 | 53 | String text = response.path("text"); 54 | System.out.println("The tweet text is: " + text); 55 | } 56 | 57 | @Test(dependsOnMethods={"readTweet"}) 58 | public void deleteTweet() { 59 | given() 60 | .auth() 61 | .oauth(consumerKey, consumerSecret, accessToken, accessSecret) 62 | .pathParam("id", tweetId) 63 | .when() 64 | .post("/destroy/{id}.json") 65 | .then() 66 | .statusCode(200); 67 | } 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | } -------------------------------------------------------------------------------- /S17/2-RestUtilities.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.common; 2 | 3 | import static org.hamcrest.Matchers.lessThan; 4 | 5 | import java.util.Map; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import com.letskodeit.constants.Auth; 9 | import com.letskodeit.constants.Path; 10 | import io.restassured.RestAssured; 11 | import io.restassured.authentication.AuthenticationScheme; 12 | import io.restassured.builder.RequestSpecBuilder; 13 | import io.restassured.builder.ResponseSpecBuilder; 14 | import io.restassured.specification.RequestSpecification; 15 | import io.restassured.specification.ResponseSpecification; 16 | 17 | public class RestUtilities { 18 | 19 | public static String ENDPOINT; 20 | public static RequestSpecBuilder REQUEST_BUILDER; 21 | public static RequestSpecification REQUEST_SPEC; 22 | public static ResponseSpecBuilder RESPONSE_BUILDER; 23 | public static ResponseSpecification RESPONSE_SPEC; 24 | 25 | public static void setEndPoint(String epoint) { 26 | ENDPOINT = epoint; 27 | } 28 | 29 | public static RequestSpecification getRequestSpecification() { 30 | AuthenticationScheme authScheme = 31 | RestAssured.oauth(Auth.CONSUMER_KEY, Auth.CONSUMER_SECRET, Auth.ACCESS_TOKEN, 32 | Auth.ACCESS_SECRET); 33 | REQUEST_BUILDER = new RequestSpecBuilder(); 34 | REQUEST_BUILDER.setBaseUri(Path.BASE_URI); 35 | REQUEST_BUILDER.setAuth(authScheme); 36 | REQUEST_SPEC = REQUEST_BUILDER.build(); 37 | return REQUEST_SPEC; 38 | } 39 | 40 | public static ResponseSpecification getResponseSpecification() { 41 | RESPONSE_BUILDER = new ResponseSpecBuilder(); 42 | RESPONSE_BUILDER.expectStatusCode(200); 43 | RESPONSE_BUILDER.expectResponseTime(lessThan(3L), TimeUnit.SECONDS); 44 | RESPONSE_SPEC = RESPONSE_BUILDER.build(); 45 | return RESPONSE_SPEC; 46 | } 47 | 48 | public static RequestSpecification createQueryParam(RequestSpecification rspec, 49 | String param, String value) { 50 | return rspec.queryParam(param, value); 51 | } 52 | 53 | public static RequestSpecification createQueryParam(RequestSpecification rspec, 54 | Map queryMap) { 55 | return rspec.queryParams(queryMap); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /S15/4-SpecificationWithTime.java: -------------------------------------------------------------------------------- 1 | package specs; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | import io.restassured.RestAssured; 7 | import io.restassured.authentication.AuthenticationScheme; 8 | import io.restassured.builder.RequestSpecBuilder; 9 | import io.restassured.builder.ResponseSpecBuilder; 10 | import io.restassured.specification.RequestSpecification; 11 | import io.restassured.specification.ResponseSpecification; 12 | 13 | import static org.hamcrest.Matchers.*; 14 | 15 | import java.util.concurrent.TimeUnit; 16 | 17 | public class SpecificationWithTime { 18 | String consumerKey = "ubhe5nnmztzlJMzdLihtKEgsT"; 19 | String consumerSecret = "KjDJDSJw2o882K71cK33PqUdRbIlp5DNxCxYknDrSvQwNsb2S1"; 20 | String accessToken = "886092793365409792-mBtgcXzcn9IOC1WmWp5c1fXMn3HDZHr"; 21 | String accessSecret = "jUIEOAnEiZLlICLBlpR6UhVKZ98CMpQ7banbfcP5gW3eS"; 22 | 23 | RequestSpecBuilder requestBuilder; 24 | static RequestSpecification requestSpec; 25 | ResponseSpecBuilder responseBuilder; 26 | static ResponseSpecification responseSpec; 27 | 28 | @BeforeClass 29 | public void setup() { 30 | AuthenticationScheme authScheme = 31 | RestAssured.oauth(consumerKey, consumerSecret, accessToken, accessSecret); 32 | requestBuilder = new RequestSpecBuilder(); 33 | requestBuilder.setBaseUri("https://api.twitter.com"); 34 | requestBuilder.setBasePath("/1.1/statuses"); 35 | requestBuilder.addQueryParam("user_id", "apiautomation"); 36 | requestBuilder.setAuth(authScheme); 37 | requestSpec = requestBuilder.build(); 38 | 39 | responseBuilder = new ResponseSpecBuilder(); 40 | responseBuilder.expectStatusCode(200); 41 | responseBuilder.expectResponseTime(lessThan(1L), TimeUnit.SECONDS); 42 | responseBuilder.expectBody("user.name", hasItem("RestAPI Automation")); 43 | responseSpec = responseBuilder.build(); 44 | } 45 | 46 | @Test 47 | public void readTweets() { 48 | given() 49 | .spec(requestSpec) 50 | .when() 51 | .get("/user_timeline.json") 52 | .then() 53 | .spec(responseSpec) 54 | .body("user.screen_name", hasItem("apiautomation")); 55 | } 56 | } -------------------------------------------------------------------------------- /S19/2-TwitterWorkflowTest.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.statuses; 2 | 3 | import static io.restassured.RestAssured.given; 4 | import org.testng.annotations.BeforeClass; 5 | import org.testng.annotations.Test; 6 | 7 | import com.letskodeit.common.RestUtilities; 8 | import com.letskodeit.constants.EndPoints; 9 | import com.letskodeit.constants.Path; 10 | 11 | import io.restassured.path.json.JsonPath; 12 | import io.restassured.response.Response; 13 | import io.restassured.specification.RequestSpecification; 14 | import io.restassured.specification.ResponseSpecification; 15 | 16 | public class TwitterWorkflowTest { 17 | RequestSpecification reqSpec; 18 | ResponseSpecification resSpec; 19 | String tweetId = ""; 20 | 21 | @BeforeClass 22 | public void setup() { 23 | reqSpec = RestUtilities.getRequestSpecification(); 24 | reqSpec.basePath(Path.STATUSES); 25 | 26 | resSpec = RestUtilities.getResponseSpecification(); 27 | } 28 | 29 | @Test 30 | public void postTweet() { 31 | Response response = 32 | given() 33 | .spec(RestUtilities.createQueryParam(reqSpec, "status", "My First Tweet")) 34 | .when() 35 | .post(EndPoints.STATUSES_TWEET_POST) 36 | .then() 37 | .spec(resSpec) 38 | .extract() 39 | .response(); 40 | JsonPath jsPath = RestUtilities.getJsonPath(response); 41 | tweetId = jsPath.get("id_str"); 42 | System.out.println("The response.path: " + tweetId); 43 | } 44 | 45 | @Test(dependsOnMethods={"postTweet"}) 46 | public void readTweet() { 47 | RestUtilities.setEndPoint(EndPoints.STATUSES_TWEET_READ_SINGLE); 48 | Response res = RestUtilities.getResponse( 49 | RestUtilities.createQueryParam(reqSpec, "id", tweetId), "get"); 50 | String text = res.path("text"); 51 | System.out.println("The tweet text is: " + text); 52 | } 53 | 54 | @Test(dependsOnMethods={"readTweet"}) 55 | public void deleteTweet() { 56 | given() 57 | .spec(RestUtilities.createPathParam(reqSpec, "id", tweetId)) 58 | .when() 59 | .post(EndPoints.STATUSES_TWEET_DESTROY) 60 | .then() 61 | .spec(resSpec); 62 | } 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | } -------------------------------------------------------------------------------- /S3/rest.txt: -------------------------------------------------------------------------------- 1 | Request -> What front end sends 2 | Response -> What it receives back 3 | 4 | Rest -> Stateless > Client data is not stored on the server 5 | 6 | Home Number 7 | Street Add 8 | City 9 | Zip 10 | State 11 | Country 12 | 13 | Endpoints: 14 | URI -> Street add 15 | Resources -> Specific page 16 | Parameters -> some data to filter the resources 17 | We can have more than one resources 18 | baseURI/resourcePath?parameters 19 | 20 | 4 important CRUD Create, Read, Update, Delete 21 | Get -> Read -> Reading the information 22 | Post -> Create -> New Information 23 | Put -> Update -> Modifying exiting information 24 | Delete -> Delete -> Delete information from the application 25 | 26 | Headers: 27 | Contains the information about request and response 28 | 29 | 30 | What to verify? 31 | 1. Status Code 32 | 2. Response Message/Error Message 33 | 3. Few other response details 34 | 35 | —————————————————RestAssured———————————— 36 | 37 | given() -> Initialization / Auth 38 | Login to application 39 | Request header 40 | Parameters, cookies 41 | Body 42 | 43 | When() -> Resources 44 | GET(resource path) 45 | POST(resource path) 46 | PUT(resource path) 47 | DELTE(resource path) 48 | 49 | Then() -> Validation 50 | validate status code 51 | assert 52 | Extract the response, header 53 | 54 | Given I have this information 55 | When I perform this action 56 | Then this should be the output 57 | 58 | 59 | 60 | ——————————Query Parameters vs Path Parameters——————————— 61 | 62 | • Query parameters: These are appended at the end of the RESTApi Endpoint. They can be identified by the use of ? 63 | Example: 64 | https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=Washington,DC&destinations=New+York+City,NY&key=YOUR_API_KEY 65 | 66 | • Path parameters: These are part of the RESTApi endpoint. 67 | Example: 68 | https://maps.googleapis.com/maps/api/{json}?queryparameters 69 | https://baseURI/{year}/sports 70 | 71 | Form Parameters: 72 | All the data from UI/Rest can go using two ways: 73 | 1. PayLoad -> Google Places 74 | 2. Form Parameters 75 | 76 | https://stackoverflow.com/questions/11552248/when-to-use-queryparam-vs-pathparam 77 | 78 | 79 | ———————————————JSON———————————————— 80 | 81 | Dictionary: 82 | Key: Value 83 | 84 | { -> Starting Point 85 | } -> Ending Point 86 | 87 | [ -> Starting List 88 | ] -> Ending List 89 | It means, that value is a list of items 90 | Index -> Starting from 0 index 91 | 92 | 93 | 94 | String 95 | Double quotes has a special meaning 96 | 1st double quotes represents start of string 97 | 2nd double quotes represent end of string 98 | 99 | “ in between string ” 100 | 101 | \ -> Escape Character, \” -> Escape special meaning of double quotes 102 | 103 | 104 | 105 | 106 | 107 | ———————————————Rest Assured Logging———————————————— 108 | 109 | https://github.com/rest-assured/rest-assured/wiki/Usage#logging 110 | -------------------------------------------------------------------------------- /S3/Rest API Information Text File.txt: -------------------------------------------------------------------------------- 1 | Request -> What front end sends 2 | Response -> What it receives back 3 | 4 | Rest -> Stateless > Client data is not stored on the server 5 | 6 | Home Number 7 | Street Add 8 | City 9 | Zip 10 | State 11 | Country 12 | 13 | Endpoints: 14 | URI -> Street add 15 | Resources -> Specific page 16 | Parameters -> some data to filter the resources 17 | We can have more than one resources 18 | baseURI/resourcePath?parameters 19 | 20 | 4 important CRUD Create, Read, Update, Delete 21 | Get -> Read -> Reading the information 22 | Post -> Create -> New Information 23 | Put -> Update -> Modifying exiting information 24 | Delete -> Delete -> Delete information from the application 25 | 26 | Headers: 27 | Contains the information about request and response 28 | 29 | 30 | What to verify? 31 | 1. Status Code 32 | 2. Response Message/Error Message 33 | 3. Few other response details 34 | 35 | —————————————————RestAssured———————————— 36 | 37 | given() -> Initialization / Auth 38 | Login to application 39 | Request header 40 | Parameters, cookies 41 | Body 42 | 43 | When() -> Resources 44 | GET(resource path) 45 | POST(resource path) 46 | PUT(resource path) 47 | DELTE(resource path) 48 | 49 | Then() -> Validation 50 | validate status code 51 | assert 52 | Extract the response, header 53 | 54 | Given I have this information 55 | When I perform this action 56 | Then this should be the output 57 | 58 | 59 | 60 | ——————————Query Parameters vs Path Parameters——————————— 61 | 62 | • Query parameters: These are appended at the end of the RESTApi Endpoint. They can be identified by the use of ? 63 | Example: 64 | https://protect-eu.mimecast.com/s/P3d8CX70XtX0vosxYB1a?domain=maps.googleapis.com 65 | 66 | • Path parameters: These are part of the RESTApi endpoint. 67 | Example: 68 | https://protect-eu.mimecast.com/s/FGMACYQnYcLOR2trtfn9?domain=maps.googleapis.com 69 | https://baseURI/{year}/sports 70 | 71 | Form Parameters: 72 | All the data from UI/Rest can go using two ways: 73 | 1. PayLoad -> Google Places 74 | 2. Form Parameters 75 | 76 | https://protect-eu.mimecast.com/s/0MQFCZwoGf52Z9CV09QK?domain=stackoverflow.com 77 | 78 | 79 | ———————————————JSON———————————————— 80 | 81 | Dictionary: 82 | Key: Value 83 | 84 | { -> Starting Point 85 | } -> Ending Point 86 | 87 | [ -> Starting List 88 | ] -> Ending List 89 | It means, that value is a list of items 90 | Index -> Starting from 0 index 91 | 92 | 93 | 94 | String 95 | Double quotes has a special meaning 96 | 1st double quotes represents start of string 97 | 2nd double quotes represent end of string 98 | 99 | “ in between string ” 100 | 101 | \ -> Escape Character, \” -> Escape special meaning of double quotes 102 | 103 | 104 | 105 | 106 | 107 | ———————————————Rest Assured Logging———————————————— 108 | 109 | https://protect-eu.mimecast.com/s/xm4FC1YnptM5yNfKdweF?domain=github.com 110 | 111 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | # Rest API Automation With Rest Assured - Novice To Ninja [Video] 5 | This is the code repository for [Rest API Automation With Rest Assured - Novice To Ninja [Video]](https://www.packtpub.com/application-development/restful-services-delphi-video?utm_source=github&utm_medium=repository&utm_campaign=9781789951882), published by [Packt](https://www.packtpub.com/?utm_source=github). It contains all the supporting project files necessary to work through the video course from start to finish. 6 | ## About the Video Course 7 | REST Assured is a powerful set of APIs used to automate RESTful APIs/RESTful Web services (just like Selenium WebDriver for Web applications). Almost all web applications use REST APIs to communicate with the back-end and it has gained a lot of popularity in modern-day application architecture. It is very important for QA/automation engineers to understand how to automate REST API tests. Automating REST API tests is crucial for projects because REST API tests are quick to run and more stable, unlike web automation. 90% of the IT industry is now moving towards REST API Automation. We assume that students have no experience in automation/coding and start every topic from scratch. Examples are taken from testing real-time hosted REST APIs to understand how different components can be automated, to give you an idea of industry-level frameworks and to give you confidence 8 | 9 |

What You Will Learn

10 |
11 |
    12 |
  • Design a Windows desktop application using VCL 13 |
  • Code an Android application with FMX 14 |
  • Build a RESTful application on DataSnap with WebBroker 15 |
  • Work with data sources and embedded SQL Databases: FireDAC and dbExpress 16 |
  • Know how to solve a complex business problem of courier (delivery) services
17 | 18 | ## Instructions and Navigation 19 | ### Assumed Knowledge 20 | To fully benefit from the coverage included in this course, you will need:
21 | Quality assurance professionals and manual testers looking to start a career in test automation. Quality assurance automation professionals wishing to intensify their current test automation skill sets. Fresh graduates who want to make a dream career in software engineering. Quality assurance team leads and managers 22 | ### Technical Requirements 23 | This course has the following software requirements:
24 | NA 25 | 26 | ## Related Products 27 | * [RESTful API Design with Node, Express, and MongoDB [Video]](https://www.packtpub.com/application-development/restful-services-delphi-video?utm_source=github&utm_medium=repository&utm_campaign=9781789951882) 28 | 29 | * [Mastering REST APIs in Node.js: Zero To Hero [Video]](https://www.packtpub.com/application-development/restful-services-delphi-video?utm_source=github&utm_medium=repository&utm_campaign=9781789951882) 30 | 31 | * [RESTful Services with Delphi [Video]](https://www.packtpub.com/application-development/restful-services-delphi-video?utm_source=github&utm_medium=repository&utm_campaign=9781789951882) 32 | 33 | -------------------------------------------------------------------------------- /S17/3-RestUtilities.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.common; 2 | 3 | import static org.hamcrest.Matchers.lessThan; 4 | import static io.restassured.RestAssured.given; 5 | import java.util.Map; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import com.letskodeit.constants.Auth; 9 | import com.letskodeit.constants.Path; 10 | import io.restassured.RestAssured; 11 | import io.restassured.authentication.AuthenticationScheme; 12 | import io.restassured.builder.RequestSpecBuilder; 13 | import io.restassured.builder.ResponseSpecBuilder; 14 | import io.restassured.response.Response; 15 | import io.restassured.specification.RequestSpecification; 16 | import io.restassured.specification.ResponseSpecification; 17 | 18 | public class RestUtilities { 19 | 20 | public static String ENDPOINT; 21 | public static RequestSpecBuilder REQUEST_BUILDER; 22 | public static RequestSpecification REQUEST_SPEC; 23 | public static ResponseSpecBuilder RESPONSE_BUILDER; 24 | public static ResponseSpecification RESPONSE_SPEC; 25 | 26 | public static void setEndPoint(String epoint) { 27 | ENDPOINT = epoint; 28 | } 29 | 30 | public static RequestSpecification getRequestSpecification() { 31 | AuthenticationScheme authScheme = 32 | RestAssured.oauth(Auth.CONSUMER_KEY, Auth.CONSUMER_SECRET, Auth.ACCESS_TOKEN, 33 | Auth.ACCESS_SECRET); 34 | REQUEST_BUILDER = new RequestSpecBuilder(); 35 | REQUEST_BUILDER.setBaseUri(Path.BASE_URI); 36 | REQUEST_BUILDER.setAuth(authScheme); 37 | REQUEST_SPEC = REQUEST_BUILDER.build(); 38 | return REQUEST_SPEC; 39 | } 40 | 41 | public static ResponseSpecification getResponseSpecification() { 42 | RESPONSE_BUILDER = new ResponseSpecBuilder(); 43 | RESPONSE_BUILDER.expectStatusCode(200); 44 | RESPONSE_BUILDER.expectResponseTime(lessThan(3L), TimeUnit.SECONDS); 45 | RESPONSE_SPEC = RESPONSE_BUILDER.build(); 46 | return RESPONSE_SPEC; 47 | } 48 | 49 | public static RequestSpecification createQueryParam(RequestSpecification rspec, 50 | String param, String value) { 51 | return rspec.queryParam(param, value); 52 | } 53 | 54 | public static RequestSpecification createQueryParam(RequestSpecification rspec, 55 | Map queryMap) { 56 | return rspec.queryParams(queryMap); 57 | } 58 | 59 | public static RequestSpecification createPathParam(RequestSpecification rspec, 60 | String param, String value) { 61 | return rspec.pathParam(param, value); 62 | } 63 | 64 | public static Response getResponse() { 65 | return given().get(ENDPOINT); 66 | } 67 | 68 | public static Response getResponse(RequestSpecification reqSpec, String type) { 69 | REQUEST_SPEC.spec(reqSpec); 70 | Response response = null; 71 | if (type.equalsIgnoreCase("get")) { 72 | response = given().spec(REQUEST_SPEC).get(ENDPOINT); 73 | } else if (type.equalsIgnoreCase("post")) { 74 | response = given().spec(REQUEST_SPEC).post(ENDPOINT); 75 | } else if (type.equalsIgnoreCase("put")) { 76 | response = given().spec(REQUEST_SPEC).put(ENDPOINT); 77 | } else if (type.equalsIgnoreCase("delete")) { 78 | response = given().spec(REQUEST_SPEC).delete(ENDPOINT); 79 | } else { 80 | System.out.println("Type is not supported"); 81 | } 82 | response.then().log().all(); 83 | response.then().spec(RESPONSE_SPEC); 84 | return response; 85 | } 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | } 100 | -------------------------------------------------------------------------------- /S17/4-RestUtilities.java: -------------------------------------------------------------------------------- 1 | package com.letskodeit.common; 2 | 3 | import static org.hamcrest.Matchers.lessThan; 4 | import static io.restassured.RestAssured.given; 5 | import java.util.Map; 6 | import java.util.concurrent.TimeUnit; 7 | 8 | import com.letskodeit.constants.Auth; 9 | import com.letskodeit.constants.Path; 10 | import io.restassured.RestAssured; 11 | import io.restassured.authentication.AuthenticationScheme; 12 | import io.restassured.builder.RequestSpecBuilder; 13 | import io.restassured.builder.ResponseSpecBuilder; 14 | import io.restassured.http.ContentType; 15 | import io.restassured.path.json.JsonPath; 16 | import io.restassured.path.xml.XmlPath; 17 | import io.restassured.response.Response; 18 | import io.restassured.specification.RequestSpecification; 19 | import io.restassured.specification.ResponseSpecification; 20 | 21 | public class RestUtilities { 22 | 23 | public static String ENDPOINT; 24 | public static RequestSpecBuilder REQUEST_BUILDER; 25 | public static RequestSpecification REQUEST_SPEC; 26 | public static ResponseSpecBuilder RESPONSE_BUILDER; 27 | public static ResponseSpecification RESPONSE_SPEC; 28 | 29 | public static void setEndPoint(String epoint) { 30 | ENDPOINT = epoint; 31 | } 32 | 33 | public static RequestSpecification getRequestSpecification() { 34 | AuthenticationScheme authScheme = 35 | RestAssured.oauth(Auth.CONSUMER_KEY, Auth.CONSUMER_SECRET, Auth.ACCESS_TOKEN, 36 | Auth.ACCESS_SECRET); 37 | REQUEST_BUILDER = new RequestSpecBuilder(); 38 | REQUEST_BUILDER.setBaseUri(Path.BASE_URI); 39 | REQUEST_BUILDER.setAuth(authScheme); 40 | REQUEST_SPEC = REQUEST_BUILDER.build(); 41 | return REQUEST_SPEC; 42 | } 43 | 44 | public static ResponseSpecification getResponseSpecification() { 45 | RESPONSE_BUILDER = new ResponseSpecBuilder(); 46 | RESPONSE_BUILDER.expectStatusCode(200); 47 | RESPONSE_BUILDER.expectResponseTime(lessThan(3L), TimeUnit.SECONDS); 48 | RESPONSE_SPEC = RESPONSE_BUILDER.build(); 49 | return RESPONSE_SPEC; 50 | } 51 | 52 | public static RequestSpecification createQueryParam(RequestSpecification rspec, 53 | String param, String value) { 54 | return rspec.queryParam(param, value); 55 | } 56 | 57 | public static RequestSpecification createQueryParam(RequestSpecification rspec, 58 | Map queryMap) { 59 | return rspec.queryParams(queryMap); 60 | } 61 | 62 | public static RequestSpecification createPathParam(RequestSpecification rspec, 63 | String param, String value) { 64 | return rspec.pathParam(param, value); 65 | } 66 | 67 | public static Response getResponse() { 68 | return given().get(ENDPOINT); 69 | } 70 | 71 | public static Response getResponse(RequestSpecification reqSpec, String type) { 72 | REQUEST_SPEC.spec(reqSpec); 73 | Response response = null; 74 | if (type.equalsIgnoreCase("get")) { 75 | response = given().spec(REQUEST_SPEC).get(ENDPOINT); 76 | } else if (type.equalsIgnoreCase("post")) { 77 | response = given().spec(REQUEST_SPEC).post(ENDPOINT); 78 | } else if (type.equalsIgnoreCase("put")) { 79 | response = given().spec(REQUEST_SPEC).put(ENDPOINT); 80 | } else if (type.equalsIgnoreCase("delete")) { 81 | response = given().spec(REQUEST_SPEC).delete(ENDPOINT); 82 | } else { 83 | System.out.println("Type is not supported"); 84 | } 85 | response.then().log().all(); 86 | response.then().spec(RESPONSE_SPEC); 87 | return response; 88 | } 89 | 90 | public static JsonPath getJsonPath(Response res) { 91 | String path = res.asString(); 92 | return new JsonPath(path); 93 | } 94 | 95 | public static XmlPath getXmlPath(Response res) { 96 | String path = res.asString(); 97 | return new XmlPath(path); 98 | } 99 | 100 | public static void resetBathPath() { 101 | RestAssured.basePath = null; 102 | } 103 | 104 | public static void setContentType(ContentType type) { 105 | given().contentType(type); 106 | } 107 | } --------------------------------------------------------------------------------