ReleaseNotes25

Johan Haleby edited this page Aug 9, 2015 · 13 revisions

Release Notes for REST Assured 2.5.0

Contents

  1. REST Assured
    1. Highlights
    2. Other Notable Changes
    3. Non-backward compatible changes
  2. Spring Mock MVC Module
    1. Highlights
    2. Other Notable Changes
    3. Non-backward compatible changes
  3. Minor Changes

REST Assured

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

  • 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 NumberReturnType that can be used with JsonPathConfig in order to always return non-integer numbers as doubles. This also you to for example use the closeTo Hamcrest 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-type my-custom-content-type as 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

  • Changed com.jayway.restassured.matcher.ResponseAwareMatcher from 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 ResponseAwareMatcher interface in order to be compatible with older Java versions) so now you use the new com.jayway.restassured.matcher.ResponseAwareMatcherComposer class to compose ResponseAwareMatchers instead:

    when().
           get("/game").
    then().
           body("_links.self.href", and(responseAwareMatcher1, responseAwareMatcher2));

    where and is statically imported from ResponseAwareMatcherComposer. 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"))));
  • multiPart methods taking java.io.File as 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

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 httpBasic is statically imported from org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors. This requires that you have spring-security-test in 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

  • 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.SecurityMockMvcConfigurer as request post processor if spring-security-test is 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 a SecurityMockMvcConfigurer manually which means easier setup. For example if you have spring-security-test in 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

  • The field RestAssuredMockMvc.mockMvc has been replaced by the method RestAssuredMockMvc.mockMvc(..). Before you did:

    RestAssuredMockMvc.mockMvc = myMockMvcInstance;

    but now you need to do:

    RestAssuredMockMvc.mockMvc(myMockMvcInstance);

    Minor changes

    See change log for more details.