SlideShare a Scribd company logo
1 of 27
Testing RESTful Webservices using the REST-assured Framework
Table of Contents ,[object Object]
REST-assured and Maven
Verify JSON via GET
JsonPath
Groovy Closures – The JSON
Groovy Closures – The Test
Verifying XML, Xpath, Schema
Request Parameters
Status Codes, Headers ,[object Object]
Setting HTTP Headers
Verifying HTTP Header
Setting Cookies
Verifying Cookies
File Uploads
Registering Custom Parsers
Specification Reuse
Tutorial Sources
Prerequisites ,[object Object]
Java Development Kit >= 6
Maven 3
The full tutorial and the RESTful Webservice to test can be found at my  blog www.hascode.com
REST-assured and Maven ,[object Object]
<dependency>
<groupId>com.jayway.restassured</groupId>
<artifactId>rest-assured</artifactId>
<version>1.4</version>

More Related Content

What's hot

An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API TestingSauce Labs
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...Postman
 
API Test Automation
API Test Automation API Test Automation
API Test Automation SQALab
 
Getting started with karate dsl
Getting started with karate dslGetting started with karate dsl
Getting started with karate dslKnoldus Inc.
 
API Testing with Frisby and Mocha
API Testing with Frisby and MochaAPI Testing with Frisby and Mocha
API Testing with Frisby and MochaLyudmila Anisimova
 
Postman: An Introduction for Developers
Postman: An Introduction for DevelopersPostman: An Introduction for Developers
Postman: An Introduction for DevelopersPostman
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsQASymphony
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.Andrey Oleynik
 
Postman. From simple API test to end to end scenario
Postman. From simple API test to end to end scenarioPostman. From simple API test to end to end scenario
Postman. From simple API test to end to end scenarioHYS Enterprise
 
API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)Peter Thomas
 
Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?BugRaptors
 
Postman: An Introduction for Testers
Postman: An Introduction for TestersPostman: An Introduction for Testers
Postman: An Introduction for TestersPostman
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingRoman Liubun
 
Continuous Quality with Postman
Continuous Quality with PostmanContinuous Quality with Postman
Continuous Quality with PostmanPostman
 
B4USolution_API-Testing
B4USolution_API-TestingB4USolution_API-Testing
B4USolution_API-Testingb4usolution .
 
Space Camp June 2022 - API First.pdf
Space Camp June 2022 - API First.pdfSpace Camp June 2022 - API First.pdf
Space Camp June 2022 - API First.pdfPostman
 

What's hot (20)

Rest assured
Rest assuredRest assured
Rest assured
 
API Testing for everyone.pptx
API Testing for everyone.pptxAPI Testing for everyone.pptx
API Testing for everyone.pptx
 
An Introduction To Automated API Testing
An Introduction To Automated API TestingAn Introduction To Automated API Testing
An Introduction To Automated API Testing
 
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
POST/CON 2019 Workshop: Testing, Automated Testing, and Reporting APIs with P...
 
Api Testing
Api TestingApi Testing
Api Testing
 
API Test Automation
API Test Automation API Test Automation
API Test Automation
 
Karate DSL
Karate DSLKarate DSL
Karate DSL
 
Getting started with karate dsl
Getting started with karate dslGetting started with karate dsl
Getting started with karate dsl
 
API Testing with Frisby and Mocha
API Testing with Frisby and MochaAPI Testing with Frisby and Mocha
API Testing with Frisby and Mocha
 
Postman: An Introduction for Developers
Postman: An Introduction for DevelopersPostman: An Introduction for Developers
Postman: An Introduction for Developers
 
RESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and JenkinsRESTful API Testing using Postman, Newman, and Jenkins
RESTful API Testing using Postman, Newman, and Jenkins
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.
 
Postman. From simple API test to end to end scenario
Postman. From simple API test to end to end scenarioPostman. From simple API test to end to end scenario
Postman. From simple API test to end to end scenario
 
API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)API Test Automation Using Karate (Anil Kumar Moka)
API Test Automation Using Karate (Anil Kumar Moka)
 
Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?Introduction to APIs & how to automate APIs testing with selenium web driver?
Introduction to APIs & how to automate APIs testing with selenium web driver?
 
Postman: An Introduction for Testers
Postman: An Introduction for TestersPostman: An Introduction for Testers
Postman: An Introduction for Testers
 
Karate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testingKarate - powerful and simple framework for REST API automation testing
Karate - powerful and simple framework for REST API automation testing
 
Continuous Quality with Postman
Continuous Quality with PostmanContinuous Quality with Postman
Continuous Quality with Postman
 
B4USolution_API-Testing
B4USolution_API-TestingB4USolution_API-Testing
B4USolution_API-Testing
 
Space Camp June 2022 - API First.pdf
Space Camp June 2022 - API First.pdfSpace Camp June 2022 - API First.pdf
Space Camp June 2022 - API First.pdf
 

Similar to Testing RESTful Webservices using the REST-assured framework

Introduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsIntroduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsJohannes Geppert
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restfulknight1128
 
Surfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSurfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSeanMcTex
 
Zend framework 05 - ajax, json and j query
Zend framework 05 - ajax, json and j queryZend framework 05 - ajax, json and j query
Zend framework 05 - ajax, json and j queryTricode (part of Dept)
 
Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7Pranav Prakash
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaJevgeni Kabanov
 
JavaServer Faces Anti-Patterns and Pitfalls
JavaServer Faces Anti-Patterns and PitfallsJavaServer Faces Anti-Patterns and Pitfalls
JavaServer Faces Anti-Patterns and PitfallsDennis Byrne
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQueryDoncho Minkov
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax componentsIgnacio Coloma
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSCarol McDonald
 
Introduction to AJAX and DWR
Introduction to AJAX and DWRIntroduction to AJAX and DWR
Introduction to AJAX and DWRSweNz FixEd
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate BustersHamletDRC
 

Similar to Testing RESTful Webservices using the REST-assured framework (20)

Spring Capitulo 05
Spring Capitulo 05Spring Capitulo 05
Spring Capitulo 05
 
J s-o-n-120219575328402-3
J s-o-n-120219575328402-3J s-o-n-120219575328402-3
J s-o-n-120219575328402-3
 
Introduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid TagsIntroduction into Struts2 jQuery Grid Tags
Introduction into Struts2 jQuery Grid Tags
 
My java file
My java fileMy java file
My java file
 
DevDays09 Internet Explorer 8
DevDays09 Internet Explorer 8DevDays09 Internet Explorer 8
DevDays09 Internet Explorer 8
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
 
Surfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSurfacing External Data Through Magnolia
Surfacing External Data Through Magnolia
 
Zend framework 05 - ajax, json and j query
Zend framework 05 - ajax, json and j queryZend framework 05 - ajax, json and j query
Zend framework 05 - ajax, json and j query
 
Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
Ajax
AjaxAjax
Ajax
 
Ajax
AjaxAjax
Ajax
 
JavaServer Faces Anti-Patterns and Pitfalls
JavaServer Faces Anti-Patterns and PitfallsJavaServer Faces Anti-Patterns and Pitfalls
JavaServer Faces Anti-Patterns and Pitfalls
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
 
Developing and testing ajax components
Developing and testing ajax componentsDeveloping and testing ajax components
Developing and testing ajax components
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
 
Introduction to AJAX and DWR
Introduction to AJAX and DWRIntroduction to AJAX and DWR
Introduction to AJAX and DWR
 
WordPress APIs
WordPress APIsWordPress APIs
WordPress APIs
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
 

Recently uploaded

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 

Recently uploaded (20)

Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 

Testing RESTful Webservices using the REST-assured framework

  • 1. Testing RESTful Webservices using the REST-assured Framework
  • 2.
  • 10.
  • 19.
  • 22. The full tutorial and the RESTful Webservice to test can be found at my blog www.hascode.com
  • 23.
  • 30. Verify JSON via GET { &quot;email&quot;:&quot;test@hascode.com&quot;, &quot;firstName&quot;:&quot;Tim&quot;, &quot;id&quot;:&quot;1&quot;, &quot;lastName&quot;:&quot;Testerman&quot; } @Test public void testGetSingleUser() { expect(). statusCode(200). body( &quot;email&quot;, equalTo(&quot;test@hascode.com&quot;), &quot;firstName&quot;, equalTo(&quot;Tim&quot;), &quot;lastName&quot;, equalTo(&quot;Testerman&quot;), &quot;id&quot;, equalTo(&quot;1&quot;)). when(). get(&quot;/service/single-user&quot;); }
  • 31. JsonPath { &quot;email&quot;:&quot;test@hascode.com&quot;, &quot;firstName&quot;:&quot;Tim&quot;, &quot;id&quot;:&quot;1&quot;, &quot;lastName&quot;:&quot;Testerman&quot; } @Test public void testGetSingleUserProgrammatic() { Response res = get(&quot;/service/single-user&quot;); assertEquals(200, res.getStatusCode()); String json = res.asString(); JsonPath jp = new JsonPath(json); assertEquals(&quot;test@hascode.com&quot;, jp.get(&quot;email&quot;)); assertEquals(&quot;Tim&quot;, jp.get(&quot;firstName&quot;)); assertEquals(&quot;Testerman&quot;, jp.get(&quot;lastName&quot;)); assertEquals(&quot;1&quot;, jp.get(&quot;id&quot;)); }
  • 32. Groovy Closures – The JSON { &quot;person&quot;:[ { &quot;@id&quot;:&quot;1&quot;, &quot;email&quot;:&quot;test@hascode.com&quot;, &quot;firstName&quot;:&quot;Tim&quot;, &quot;lastName&quot;:&quot;Testerman&quot; },{ &quot;@id&quot;:&quot;20&quot;, &quot;email&quot;:&quot;dev@hascode.com&quot;, &quot;firstName&quot;:&quot;Sara&quot;, &quot;lastName&quot;:&quot;Stevens&quot; },{ &quot;@id&quot;:&quot;11&quot;, &quot;email&quot;:&quot;devnull@hascode.com&quot;, &quot;firstName&quot;:&quot;Mark&quot;, &quot;lastName&quot;:&quot;Mustache&quot; } ] }
  • 33. Groovy Closures – The Test @Test public void testFindUsingGroovyClosure() { String json = get(&quot;/service/persons/json&quot;).asString(); JsonPath jp = new JsonPath(json); jp.setRoot(&quot;person&quot;); Map person = jp.get(&quot;find {e -> e.email =~ /test@/}&quot;); assertEquals(&quot;test@hascode.com&quot;, person.get(&quot;email&quot;)); assertEquals(&quot;Tim&quot;, person.get(&quot;firstName&quot;)); assertEquals(&quot;Testerman&quot;, person.get(&quot;lastName&quot;)); }
  • 34. Verifying XML – The XML <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?> <user> <email>test@hascode.com</email> <firstName>Tim</firstName> <id>1</id> <lastName>Testerman</lastName> </user>
  • 35. Verifying XML – The Test @Test public void testGetSingleUserAsXml() { expect(). statusCode(200). body( &quot;user.email&quot;, equalTo(&quot;test@hascode.com&quot;), &quot;user.firstName&quot;, equalTo(&quot;Tim&quot;), &quot;user.lastName&quot;, equalTo(&quot;Testerman&quot;), &quot;user.id&quot;, equalTo(&quot;1&quot;)). when(). get(&quot;/service/single-user/xml&quot;); }
  • 36. Verifying using Xpath – The XML <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?> <people> <person id=&quot;1&quot;> <email>test@hascode.com</email> <firstName>Tim</firstName> <lastName>Testerman</lastName> </person> <person id=&quot;20&quot;> <email>dev@hascode.com</email> <firstName>Sara</firstName> <lastName>Stevens</lastName> </person> <person id=&quot;11&quot;> <email>devnull@hascode.com</email> <firstName>Mark</firstName> <lastName>Mustache</lastName> </person> </people>
  • 37. Verifying using XPath – the Test @Test public void testGetPersons() { expect(). statusCode(200). body( hasXPath(&quot;//person[@id='1']/email[.='test@hascode.com'] and firstName='Tim' and lastName='Testerman'&quot;), hasXPath(&quot;//person[@id='20']/email[.='dev@hascode.com'] and firstName='Sara' and lastName='Stevens'&quot;), hasXPath(&quot;//person[@id='1']/email[.='devnull@hascode.com'] and firstName='Mark' and lastName='Mustache'&quot;)). when(). get(&quot;/service/persons/xml&quot;); }
  • 38. Verify using Schema – The XML <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;yes&quot;?> <user> <email>test@hascode.com</email> <firstName>Tim</firstName> <id>1</id> <lastName>Testerman</lastName> </user>
  • 39. Verifying using Schema – The XSD <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <schema xmlns=&quot;http://www.w3.org/2001/XMLSchema&quot;> <element name=&quot;user&quot;> <complexType> <sequence> <element name=&quot;email&quot;> <simpleType> <restriction base=&quot;string&quot;> <pattern value=&quot;.+@.+&quot;></pattern> </restriction> </simpleType> </element> <element name=&quot;firstName&quot; type=&quot;string&quot;></element> <element name=&quot;id&quot; type=&quot;int&quot;></element> <element name=&quot;lastName&quot; type=&quot;string&quot;></element> </sequence> </complexType> </element> </schema>
  • 40. Verifying using Schema – The Test @Test public void testGetSingleUserAgainstSchema() { InputStream xsd = getClass().getResourceAsStream(&quot;/user.xsd&quot;); assertNotNull(xsd); expect(). statusCode(200). body( matchesXsd(xsd)). when(). get(&quot;/service/single-user/xml&quot;); }
  • 41. Handling Request Parameters @Test public void testCreateuser() { final String email = &quot;test@hascode.com&quot;; final String firstName = &quot;Tim&quot;; final String lastName = &quot;Tester&quot;; given(). parameters( &quot;email&quot;, email, &quot;firstName&quot;, firstName, &quot;lastName&quot;, lastName). expect(). body(&quot;email&quot;, equalTo(email)). body(&quot;firstName&quot;, equalTo(firstName)). body(&quot;lastName&quot;, equalTo(lastName)). when(). get(&quot;/service/user/create&quot;); }
  • 42. Verifying HTTP Status Codes @Test public void testStatusNotFound() { expect(). statusCode(404). when(). get(&quot;/service/status/notfound&quot;); }
  • 43. Handling Basic Authentication @Test public void testAuthenticationWorking() { // we're not authenticated, service returns &quot;401 Unauthorized&quot; expect(). statusCode(401). when(). get(&quot;/service/secure/person&quot;); // with authentication it is working expect(). statusCode(200). when(). with(). authentication().basic(&quot;admin&quot;, &quot;admin&quot;). get(&quot;/service/secure/person&quot;); }
  • 44. Setting HTTP Headers @Test public void testSetRequestHeaders() { expect(). body(equalTo(&quot;TEST&quot;)). when(). with(). header(&quot;myparam&quot;, &quot;TEST&quot;). get(&quot;/service/header/print&quot;); expect(). body(equalTo(&quot;foo&quot;)). when(). with(). header(&quot;myparam&quot;, &quot;foo&quot;). get(&quot;/service/header/print&quot;); }
  • 45. Verifying HTTP Header @Test public void testReturnedHeaders() { expect(). headers(&quot;customHeader1&quot;, &quot;foo&quot;, &quot;anotherHeader&quot;, &quot;bar&quot;). when(). get(&quot;/service/header/multiple&quot;); }
  • 46. Setting Cookies @Test public void testAccessSecuredByCookie() { expect(). statusCode(403). when(). get(&quot;/service/access/cookie-token-secured&quot;); given(). cookie(&quot;authtoken&quot;, &quot;abcdef&quot;). expect(). statusCode(200). when(). get(&quot;/service/access/cookie-token-secured&quot;); }
  • 47. Verifying Cookies @Test public void testModifyCookie() { expect(). cookie(&quot;userName&quot;, equalTo(&quot;Ted&quot;)). when(). with().param(&quot;name&quot;, &quot;Ted&quot;). get(&quot;/service/cookie/modify&quot;); expect(). cookie(&quot;userName&quot;, equalTo(&quot;Bill&quot;)). when(). with().param(&quot;name&quot;, &quot;Bill&quot;). get(&quot;/service/cookie/modify&quot;); }
  • 48. File Uploads @Test public void testFileUpload() { final File file = new File(getClass().getClassLoader() .getResource(&quot;test.txt&quot;).getFile()); assertNotNull(file); assertTrue(file.canRead()); given(). multiPart(file). expect(). body(equalTo(&quot;This is an uploaded test file.&quot;)). when(). post(&quot;/service/file/upload&quot;); }
  • 49. Registering Custom Parsers @Test public void testRegisterParserForUnknownContentType() { RestAssured.registerParser(&quot;text/json&quot;, Parser.JSON); expect(). body(&quot;test&quot;, equalTo(true)). when(). get(&quot;/service/detail/json&quot;); }
  • 50. Specification Reuse @Test public void testSpecReuse() { ResponseSpecBuilder builder = new ResponseSpecBuilder(); builder.expectStatusCode(200); builder.expectBody(&quot;email&quot;, equalTo(&quot;test@hascode.com&quot;)); builder.expectBody(&quot;firstName&quot;, equalTo(&quot;Tim&quot;)); builder.expectBody(&quot;lastName&quot;, equalTo(&quot;Testerman&quot;)); builder.expectBody(&quot;id&quot;, equalTo(&quot;1&quot;)); ResponseSpecification responseSpec = builder.build(); // now we're able to use this specification for this test expect(). spec(responseSpec). when(). get(&quot;/service/single-user&quot;); // now re-use for another test that returns similar data .. you may // extend the specification with further tests as you wish final String email = &quot;test@hascode.com&quot;; final String firstName = &quot;Tim&quot;; final String lastName = &quot;Testerman&quot;; expect(). spec(responseSpec). when(). with(). parameters( &quot;email&quot;, email, &quot;firstName&quot;, firstName, &quot;lastName&quot;,lastName). get(&quot;/service/user/create&quot;); }
  • 51.
  • 52. Clone with Mercurial: hg clone https://bitbucket.org/hascode/rest-assured-sample
  • 53.
  • 54. Please feel free to read further tutorials of mine on www.hascode.com
  • 55. I'm also on Twitter: http://twitter.com/hascode