But I’ve also learned that it allows you to easily validate less common data and complex data structures.An optional third argument could be supplied to customise the validation behaviour but I won’t be covering that in this post.For example given that a service located at import org.junit. Input Stream; import static com.jayway.restassured. Rest Assured.when; import static com.jayway.restassured.matcher. Rest Assured Matchers.matches Xsd; public class Car Records ITest import org.junit. Matchers.equal To; import static com.jayway.restassured. Rest Assured.given; import static com.jayway.restassured. Json Schema Validator.matches Json Schema In Classpath; public class Json Schema Validation ITest In (1) we check that the response body matches the JSON schema and in (2) and (3) we validate that the greeter service actually greeted the expected person.JSON Schema validator is not part of REST Assured core so in order to use it you need to add the module in REST Assured builds on top of the excellent json-schema-validator project by Francis Galiegue et al.The REST-assured library provides support for testing REST APIs, usually in JSON format.
To avoid this, we have the freedom to define our configuration just once and let it apply to all tests.Let’s take a look at an example of some data: property on form fields themselves for extra security.The address field, however, required additional consideration.But you won’t always be storing phone numbers as strings.Eventually, validation for number fields will need to written and Joi makes this just as direct.My most recent project, however, is entirely form- and data-driven and I needed a way to easily handle front-end validation. Joi is a validation library that allows you to build schemas to validate Java Script objects.And what that generally means to me is Joi provides methods to easily validate common data types, such as e-mail addresses and phone numbers.In this quick tutorial, we’ll take a look at how we can validate a JSON response based on a predefined JSON schema.The initial REST-assured setup is the same as our previous article.So how can data be validated against other data values?In this particular project, which deals with applying for a loan, the user is asked to specify both their total wealth as well as their total savings and investments.