REST Assured 2.5.0
REST Assured
Section titled “REST Assured”Highlights
Section titled “Highlights”-
REST Assured now show all failing body assertions when using multiple expectations in the same body clause. For example:
.. then().body("x.y", equalTo("z"), "y.z", is(2)). ..If both “x.y” and “y.z” fails REST Assured will print both errors. Before only the error of “x.y” was shown.
-
Possible to sign the request with an oauth2 access token (in the header) without using Scribe
Other Notable Changes
Section titled “Other Notable Changes”-
It’s now possible to set default filename and control name for multiparts. Before they were always equal to “file” but this is now configurable using the new MultiPartConfig. For example:
given().config(config().multiPartConfig(multiPartConfig().with().defaultFileName("custom1").and().defaultControlName("custom2"))). .. -
Added new a new
NumberReturnTypethat can be used withJsonPathConfigin order to always return non-integer numbers as doubles. This also you to for example use thecloseToHamcrest matcher. For example:RestAssured.config = RestAssured.config().jsonConfig(jsonConfig().numberReturnType(DOUBLE)); -
REST Assured can now resolve multiple path parameters inside the same URI “path parameter” (for example
/somewhere/{x}{y}/z) -
It’s now possible to specify how content for a specific content-type should be serialized using
com.jayway.restassured.config.EncoderConfig#encodeContentTypeAs(..). For example let’s say that you want to serialized content-typemy-custom-content-typeas text:given().config(RestAssured.config().encoderConfig(encoderConfig().encodeContentTypeAs("my-custom-content-type", ContentType.TEXT))).contentType("my-custom-content-type").content("Some text content").when().post("/somewhere"). .. -
Pretty-printing of JSON now displays unicode characters correctly
-
Multipart file uploading now supports specifying an empty filename.
Non-backward compatible changes
Section titled “Non-backward compatible changes”-
Changed
com.jayway.restassured.matcher.ResponseAwareMatcherfrom an abstract class to a (functional) interface. The reason is to allow for creating ResponseAwareMatchers as lambda expressions in Java 8. Before you had to do like this (even in Java 8):when().get("/game").then().body("_links.self.href", new ResponseAwareMatcher<Response>() {public Matcher<?> matcher(Response response) {return equalTo("http://localhost:8080/" + response.path("id"));}});but with the new change you can now do (if using Java 8):
when().get("/game").then().body("_links.self.href", response -> equalTo("http://localhost:8080/" + response.path("id")));which is much less verbose. This change should be backward compatible unless you use composition of matchers. Before you composed ResponseAwareMatchers like this:
when().get("/game").then().body("_links.self.href", responseAwareMatcher1.and(responseAwareMatcher2));This now longer works (since we cannot implement default methods in the
ResponseAwareMatcherinterface in order to be compatible with older Java versions) so now you use the newcom.jayway.restassured.matcher.ResponseAwareMatcherComposerclass to compose ResponseAwareMatchers instead:when().get("/game").then().body("_links.self.href", and(responseAwareMatcher1, responseAwareMatcher2));where
andis statically imported fromResponseAwareMatcherComposer. These can also be nested and combined with regular Hamcrest matchers, for example:when().get("/game").then().body("_links.self.href", and(responseAwareMatcher1, containsString("something"), or(responseAwareMatcher2, responseAwareMatcher3, endsWith("x")))); -
multiPartmethods takingjava.io.Fileas argument now uses the filename of the File instead of just “file”. You can change the default filename by using the MultiPartConfig.
Spring Mock MVC module
Section titled “Spring Mock MVC module”Highlights
Section titled “Highlights”-
MockMvc module now supports async requests. For example:
given().body(..).when().async().post("/x").then(). ..Big thanks to Marcin Grzejszczak (@mgrzejszczak) for helping out.
-
Added support for RequestPostProcessor authentication. For example:
given().auth().with(httpBasic("username", "password")). ..where
httpBasicis statically imported fromorg.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors. This requires that you havespring-security-testin your classpath. This also means that you can make use of Spring Security test annotations such as @WithMockUser and @WithUserDetails. -
Added support for RequestPostProcessors to the Spring Mock MVC module, for example:
given().postProcessors(myRequestPostProcessor1, myRequestPostProcessor2). ..
Other Notable Changes
Section titled “Other Notable Changes”-
It’s now possible to set default filename and control name for multiparts. Before they were always equal to “file” but this is now configurable using the new MultiPartConfig. For example:
given().config(config().multiPartConfig(multiPartConfig().with().defaultFileName("custom1").and().defaultControlName("custom2"))). .. -
It’s now possible to supply MockMvcConfigurers when calling webAppContextSetup in the Spring Mock MVC module. For example:
given().webAppContextSetup(context, springSecurity()). .. -
Added
RestAssuredMockMvc#config()method that returns the assign static config or a new config if no static config has been assigned -
Spring Mock MVC module automatically registers
org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigureras request post processor ifspring-security-testis available in classpath and you’ve supplied an instance of AbstractMockMvcBuilder to Rest Assured. This means that you don’t have to create a custom MockMvc instance with aSecurityMockMvcConfigurermanually which means easier setup. For example if you havespring-security-testin classpath it’s enough to just do:given().webAppContextSetup(webAppContext). ..instead of:
given().mockMvc(MockMvcBuilders.webAppContextSetup(context).apply(springSecurity()).build()). ..which you had to do before. You can disable this using the new MockMvcConfig.
Non-backward compatible changes
Section titled “Non-backward compatible changes”-
The field
RestAssuredMockMvc.mockMvchas been replaced by the methodRestAssuredMockMvc.mockMvc(..). Before you did:RestAssuredMockMvc.mockMvc = myMockMvcInstance;but now you need to do:
RestAssuredMockMvc.mockMvc(myMockMvcInstance);
Minor changes
Section titled “Minor changes”See change log for more details.

