SlideShare a Scribd company logo
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

Postman & API Testing by Amber Race
Postman & API Testing by Amber RacePostman & API Testing by Amber Race
Postman & API Testing by Amber Race
Postman
 
Belajar Postman test runner
Belajar Postman test runnerBelajar Postman test runner
Belajar Postman test runner
Fachrul Choliluddin
 
Postman.ppt
Postman.pptPostman.ppt
Postman.ppt
ParrotBAD
 
Selenium IDE LOCATORS
Selenium IDE LOCATORSSelenium IDE LOCATORS
Selenium IDE LOCATORS
Mindfire Solutions
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
Prem Sanil
 
Api Testing
Api TestingApi Testing
Api Testing
Vishwanath KC
 
API Testing for everyone.pptx
API Testing for everyone.pptxAPI Testing for everyone.pptx
API Testing for everyone.pptx
Pricilla Bilavendran
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
Archana Krushnan
 
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
 
Testing microservices with rest assured
Testing microservices with rest assuredTesting microservices with rest assured
Testing microservices with rest assured
Kushan Shalindra Amarasiri - Technical QE Specialist
 
Api testing
Api testingApi testing
Api testing
Keshav Kashyap
 
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
 
Rest API Testing
Rest API TestingRest API Testing
Rest API Testing
upadhyay_25
 
Postman
PostmanPostman
Introduction to jest
Introduction to jestIntroduction to jest
Introduction to jest
pksjce
 
Selenium Architecture
Selenium ArchitectureSelenium Architecture
Selenium Architecture
rohitnayak
 
Introduction to APIs (Application Programming Interface)
Introduction to APIs (Application Programming Interface) Introduction to APIs (Application Programming Interface)
Introduction to APIs (Application Programming Interface)
Vibhawa Nirmal
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
Anirudh Raja
 
Apache jMeter
Apache jMeterApache jMeter

What's hot (20)

Postman & API Testing by Amber Race
Postman & API Testing by Amber RacePostman & API Testing by Amber Race
Postman & API Testing by Amber Race
 
Rest assured
Rest assuredRest assured
Rest assured
 
Belajar Postman test runner
Belajar Postman test runnerBelajar Postman test runner
Belajar Postman test runner
 
Postman.ppt
Postman.pptPostman.ppt
Postman.ppt
 
Selenium IDE LOCATORS
Selenium IDE LOCATORSSelenium IDE LOCATORS
Selenium IDE LOCATORS
 
REST API and CRUD
REST API and CRUDREST API and CRUD
REST API and CRUD
 
Api Testing
Api TestingApi Testing
Api Testing
 
API Testing for everyone.pptx
API Testing for everyone.pptxAPI Testing for everyone.pptx
API Testing for everyone.pptx
 
Introduction to selenium
Introduction to seleniumIntroduction to selenium
Introduction to selenium
 
API Testing. Streamline your testing process.
API Testing. Streamline your testing process.API Testing. Streamline your testing process.
API Testing. Streamline your testing process.
 
Testing microservices with rest assured
Testing microservices with rest assuredTesting microservices with rest assured
Testing microservices with rest assured
 
Api testing
Api testingApi testing
Api testing
 
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?
 
Rest API Testing
Rest API TestingRest API Testing
Rest API Testing
 
Postman
PostmanPostman
Postman
 
Introduction to jest
Introduction to jestIntroduction to jest
Introduction to jest
 
Selenium Architecture
Selenium ArchitectureSelenium Architecture
Selenium Architecture
 
Introduction to APIs (Application Programming Interface)
Introduction to APIs (Application Programming Interface) Introduction to APIs (Application Programming Interface)
Introduction to APIs (Application Programming Interface)
 
Selenium ppt
Selenium pptSelenium ppt
Selenium ppt
 
Apache jMeter
Apache jMeterApache jMeter
Apache jMeter
 

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 Tags
Johannes Geppert
 
DevDays09 Internet Explorer 8
DevDays09 Internet Explorer 8DevDays09 Internet Explorer 8
DevDays09 Internet Explorer 8
Konstantinos Pantos
 
Spring MVC 3 Restful
Spring MVC 3 RestfulSpring MVC 3 Restful
Spring MVC 3 Restful
knight1128
 
Surfacing External Data Through Magnolia
Surfacing External Data Through MagnoliaSurfacing External Data Through Magnolia
Surfacing External Data Through Magnolia
SeanMcTex
 
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
Tricode (part of Dept)
 
Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7Implementing Ajax In ColdFusion 7
Implementing Ajax In ColdFusion 7
Pranav 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
 
Ajax
AjaxAjax
Ajax
AjaxAjax
JavaServer Faces Anti-Patterns and Pitfalls
JavaServer Faces Anti-Patterns and PitfallsJavaServer Faces Anti-Patterns and Pitfalls
JavaServer Faces Anti-Patterns and Pitfalls
Dennis 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 components
Ignacio Coloma
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
ipolevoy
 
Interoperable Web Services with JAX-WS
Interoperable Web Services with JAX-WSInteroperable Web Services with JAX-WS
Interoperable Web Services with JAX-WS
Carol McDonald
 
Introduction to AJAX and DWR
Introduction to AJAX and DWRIntroduction to AJAX and DWR
Introduction to AJAX and DWR
SweNz FixEd
 
Java Boilerplate Busters
Java Boilerplate BustersJava Boilerplate Busters
Java Boilerplate Busters
HamletDRC
 

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

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
Bhaskar Mitra
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Search and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical FuturesSearch and Society: Reimagining Information Access for Radical Futures
Search and Society: Reimagining Information Access for Radical Futures
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 

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