Polish "Add support for configuring default request and response preprocessors"
Closes gh-424
This commit is contained in:
@@ -35,16 +35,19 @@ public class CustomDefaultOperationPreprocessors {
|
||||
|
||||
private WebApplicationContext context;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
// tag::custom-default-preprocessors[]
|
||||
// tag::custom-default-operation-preprocessors[]
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withDefaultRequestPreprocessors(removeHeaders("Foo"))
|
||||
.withDefaultResponsePreprocessors(prettyPrint()))
|
||||
.apply(documentationConfiguration(this.restDocumentation)
|
||||
.operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
// end::custom-default-preprocessors[]
|
||||
// end::custom-default-operation-preprocessors[]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,19 +45,18 @@ public class EveryTestPreprocessing {
|
||||
@Before
|
||||
public void setup() {
|
||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withDefaultRequestPreprocessors(removeHeaders("Foo"))
|
||||
.withDefaultResponsePreprocessors(prettyPrint()))
|
||||
.build();
|
||||
.apply(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
}
|
||||
|
||||
// end::setup[]
|
||||
|
||||
public void use() throws Exception {
|
||||
// tag::use[]
|
||||
this.mockMvc.perform(get("/")) // <1>
|
||||
this.mockMvc.perform(get("/"))
|
||||
.andExpect(status().isOk())
|
||||
.andDo(document("{method-name}",
|
||||
.andDo(document("index",
|
||||
links(linkWithRel("self").description("Canonical self link"))
|
||||
));
|
||||
// end::use[]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,7 +18,6 @@ package com.example.restassured;
|
||||
|
||||
import io.restassured.builder.RequestSpecBuilder;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
|
||||
@@ -38,12 +37,13 @@ public class CustomDefaultOperationPreprocessors {
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
// tag::custom-default-preprocessors[]
|
||||
// tag::custom-default-operation-preprocessors[]
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withDefaultRequestPreprocessors(removeHeaders("Foo"))
|
||||
.withDefaultResponsePreprocessors(prettyPrint()))
|
||||
.build();
|
||||
// end::custom-default-preprocessors[]
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
// end::custom-default-operation-preprocessors[]
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -43,19 +43,18 @@ public class EveryTestPreprocessing {
|
||||
@Before
|
||||
public void setup() {
|
||||
this.spec = new RequestSpecBuilder()
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withDefaultRequestPreprocessors(removeHeaders("Foo"))
|
||||
.withDefaultResponsePreprocessors(prettyPrint()))
|
||||
.build();
|
||||
.addFilter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(removeHeaders("Foo")) // <1>
|
||||
.withResponseDefaults(prettyPrint())) // <2>
|
||||
.build();
|
||||
}
|
||||
|
||||
// end::setup[]
|
||||
|
||||
public void use() throws Exception {
|
||||
// tag::use[]
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("{method-name]",
|
||||
links(linkWithRel("self").description("Canonical self link"))))
|
||||
.filter(document("index",
|
||||
links(linkWithRel("self").description("Canonical self link"))))
|
||||
.when().get("/")
|
||||
.then().assertThat().statusCode(is(200));
|
||||
// end::use[]
|
||||
|
||||
Reference in New Issue
Block a user