Merge branch '2.0.x'
Closes gh-829
This commit is contained in:
@@ -50,7 +50,7 @@ public class EveryTestPreprocessing {
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
public void use() throws Exception {
|
||||
public void use() {
|
||||
// tag::use[]
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("index", links(linkWithRel("self").description("Canonical self link")))).when()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -29,7 +29,7 @@ public class HttpHeaders {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void headers() throws Exception {
|
||||
public void headers() {
|
||||
// tag::headers[]
|
||||
RestAssured.given(this.spec).filter(document("headers", requestHeaders(// <1>
|
||||
headerWithName("Authorization").description("Basic auth credentials")), // <2>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -29,7 +29,7 @@ public class Hypermedia {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void defaultExtractor() throws Exception {
|
||||
public void defaultExtractor() {
|
||||
// tag::links[]
|
||||
RestAssured.given(this.spec).accept("application/json").filter(document("index", links(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"), // <2>
|
||||
@@ -38,7 +38,7 @@ public class Hypermedia {
|
||||
// end::links[]
|
||||
}
|
||||
|
||||
public void explicitExtractor() throws Exception {
|
||||
public void explicitExtractor() {
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
// tag::explicit-extractor[]
|
||||
.filter(document("index", links(halLinks(), // <1>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -26,7 +26,7 @@ public class InvokeService {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void invokeService() throws Exception {
|
||||
public void invokeService() {
|
||||
// tag::invoke-service[]
|
||||
RestAssured.given(this.spec) // <1>
|
||||
.accept("application/json") // <2>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -28,7 +28,7 @@ public class PathParameters {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void pathParametersSnippet() throws Exception {
|
||||
public void pathParametersSnippet() {
|
||||
// tag::path-parameters[]
|
||||
RestAssured.given(this.spec).filter(document("locations", pathParameters(// <1>
|
||||
parameterWithName("latitude").description("The location's latitude"), // <2>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -37,7 +37,7 @@ public class Payload {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void response() throws Exception {
|
||||
public void response() {
|
||||
// tag::response[]
|
||||
RestAssured.given(this.spec).accept("application/json").filter(document("user", responseFields(// <1>
|
||||
fieldWithPath("contact.name").description("The user's name"), // <2>
|
||||
@@ -46,7 +46,7 @@ public class Payload {
|
||||
// end::response[]
|
||||
}
|
||||
|
||||
public void subsection() throws Exception {
|
||||
public void subsection() {
|
||||
// tag::subsection[]
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("user",
|
||||
@@ -55,7 +55,7 @@ public class Payload {
|
||||
// end::subsection[]
|
||||
}
|
||||
|
||||
public void explicitType() throws Exception {
|
||||
public void explicitType() {
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
// tag::explicit-type[]
|
||||
.filter(document("user", responseFields(fieldWithPath("contact.email").type(JsonFieldType.STRING) // <1>
|
||||
@@ -64,7 +64,7 @@ public class Payload {
|
||||
.when().get("/user/5").then().assertThat().statusCode(is(200));
|
||||
}
|
||||
|
||||
public void constraints() throws Exception {
|
||||
public void constraints() {
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
// tag::constraints[]
|
||||
.filter(document("create-user",
|
||||
@@ -77,7 +77,7 @@ public class Payload {
|
||||
.when().post("/users").then().assertThat().statusCode(is(200));
|
||||
}
|
||||
|
||||
public void descriptorReuse() throws Exception {
|
||||
public void descriptorReuse() {
|
||||
FieldDescriptor[] book = new FieldDescriptor[] { fieldWithPath("title").description("Title of the book"),
|
||||
fieldWithPath("author").description("Author of the book") };
|
||||
|
||||
@@ -94,7 +94,7 @@ public class Payload {
|
||||
// end::book-array[]
|
||||
}
|
||||
|
||||
public void fieldsSubsection() throws Exception {
|
||||
public void fieldsSubsection() {
|
||||
// tag::fields-subsection[]
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("location", responseFields(beneathPath("weather.temperature"), // <1>
|
||||
@@ -104,7 +104,7 @@ public class Payload {
|
||||
// end::fields-subsection[]
|
||||
}
|
||||
|
||||
public void bodySubsection() throws Exception {
|
||||
public void bodySubsection() {
|
||||
// tag::body-subsection[]
|
||||
RestAssured.given(this.spec).accept("application/json")
|
||||
.filter(document("location", responseBody(beneathPath("weather.temperature")))) // <1>
|
||||
|
||||
@@ -30,7 +30,7 @@ public class PerTestPreprocessing {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void general() throws Exception {
|
||||
public void general() {
|
||||
// tag::preprocessing[]
|
||||
RestAssured.given(this.spec).filter(document("index", preprocessRequest(modifyHeaders().remove("Foo")), // <1>
|
||||
preprocessResponse(prettyPrint()))) // <2>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -28,7 +28,7 @@ public class RequestParameters {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void getQueryStringSnippet() throws Exception {
|
||||
public void getQueryStringSnippet() {
|
||||
// tag::request-parameters-query-string[]
|
||||
RestAssured.given(this.spec).filter(document("users", requestParameters(// <1>
|
||||
parameterWithName("page").description("The page to retrieve"), // <2>
|
||||
@@ -38,7 +38,7 @@ public class RequestParameters {
|
||||
// end::request-parameters-query-string[]
|
||||
}
|
||||
|
||||
public void postFormDataSnippet() throws Exception {
|
||||
public void postFormDataSnippet() {
|
||||
// tag::request-parameters-form-data[]
|
||||
RestAssured.given(this.spec)
|
||||
.filter(document("create-user",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -33,7 +33,7 @@ public class RequestPartPayload {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void fields() throws Exception {
|
||||
public void fields() {
|
||||
// tag::fields[]
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("version", "1.0");
|
||||
@@ -45,7 +45,7 @@ public class RequestPartPayload {
|
||||
// end::fields[]
|
||||
}
|
||||
|
||||
public void body() throws Exception {
|
||||
public void body() {
|
||||
// tag::body[]
|
||||
Map<String, String> metadata = new HashMap<>();
|
||||
metadata.put("version", "1.0");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -28,7 +28,7 @@ public class RequestParts {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void upload() throws Exception {
|
||||
public void upload() {
|
||||
// tag::request-parts[]
|
||||
RestAssured.given(this.spec).filter(document("users", requestParts(// <1>
|
||||
partWithName("file").description("The file to upload")))) // <2>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -28,7 +28,7 @@ public class RestAssuredSnippetReuse extends SnippetReuse {
|
||||
|
||||
private RequestSpecification spec;
|
||||
|
||||
public void documentation() throws Exception {
|
||||
public void documentation() {
|
||||
// tag::use[]
|
||||
RestAssured.given(this.spec).accept("application/json").filter(document("example", this.pagingLinks.and(// <1>
|
||||
linkWithRel("alpha").description("Link to the alpha resource"),
|
||||
|
||||
@@ -54,7 +54,7 @@ public class EveryTestPreprocessing {
|
||||
}
|
||||
// end::setup[]
|
||||
|
||||
public void use() throws Exception {
|
||||
public void use() {
|
||||
// tag::use[]
|
||||
this.webTestClient.get().uri("/").exchange().expectStatus().isOk()
|
||||
.expectBody().consumeWith(document("index",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -29,7 +29,7 @@ public class HttpHeaders {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void headers() throws Exception {
|
||||
public void headers() {
|
||||
// tag::headers[]
|
||||
this.webTestClient
|
||||
.get().uri("/people").header("Authorization", "Basic dXNlcjpzZWNyZXQ=") // <1>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -28,7 +28,7 @@ public class Hypermedia {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void defaultExtractor() throws Exception {
|
||||
public void defaultExtractor() {
|
||||
// tag::links[]
|
||||
this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk()
|
||||
.expectBody().consumeWith(document("index", links(// <1>
|
||||
@@ -37,7 +37,7 @@ public class Hypermedia {
|
||||
// end::links[]
|
||||
}
|
||||
|
||||
public void explicitExtractor() throws Exception {
|
||||
public void explicitExtractor() {
|
||||
this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk()
|
||||
.expectBody()
|
||||
// tag::explicit-extractor[]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -25,7 +25,7 @@ public class InvokeService {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void invokeService() throws Exception {
|
||||
public void invokeService() {
|
||||
// tag::invoke-service[]
|
||||
this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON) // <1>
|
||||
.exchange().expectStatus().isOk() // <2>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -28,7 +28,7 @@ public class PathParameters {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void pathParametersSnippet() throws Exception {
|
||||
public void pathParametersSnippet() {
|
||||
// tag::path-parameters[]
|
||||
this.webTestClient.get().uri("/locations/{latitude}/{longitude}", 51.5072, 0.1275) // <1>
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -37,7 +37,7 @@ public class Payload {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void response() throws Exception {
|
||||
public void response() {
|
||||
// tag::response[]
|
||||
this.webTestClient.get().uri("user/5").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
@@ -48,7 +48,7 @@ public class Payload {
|
||||
// end::response[]
|
||||
}
|
||||
|
||||
public void subsection() throws Exception {
|
||||
public void subsection() {
|
||||
// tag::subsection[]
|
||||
this.webTestClient.get().uri("user/5").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
@@ -58,7 +58,7 @@ public class Payload {
|
||||
// end::subsection[]
|
||||
}
|
||||
|
||||
public void explicitType() throws Exception {
|
||||
public void explicitType() {
|
||||
this.webTestClient.get().uri("user/5").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
// tag::explicit-type[]
|
||||
@@ -70,7 +70,7 @@ public class Payload {
|
||||
// end::explicit-type[]
|
||||
}
|
||||
|
||||
public void constraints() throws Exception {
|
||||
public void constraints() {
|
||||
this.webTestClient.get().uri("user/5").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
// tag::constraints[]
|
||||
@@ -86,7 +86,7 @@ public class Payload {
|
||||
// end::constraints[]
|
||||
}
|
||||
|
||||
public void descriptorReuse() throws Exception {
|
||||
public void descriptorReuse() {
|
||||
FieldDescriptor[] book = new FieldDescriptor[] {
|
||||
fieldWithPath("title").description("Title of the book"),
|
||||
fieldWithPath("author").description("Author of the book") };
|
||||
@@ -109,7 +109,7 @@ public class Payload {
|
||||
// end::book-array[]
|
||||
}
|
||||
|
||||
public void fieldsSubsection() throws Exception {
|
||||
public void fieldsSubsection() {
|
||||
// tag::fields-subsection[]
|
||||
this.webTestClient.get().uri("/locations/1").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
@@ -120,7 +120,7 @@ public class Payload {
|
||||
// end::fields-subsection[]
|
||||
}
|
||||
|
||||
public void bodySubsection() throws Exception {
|
||||
public void bodySubsection() {
|
||||
// tag::body-subsection[]
|
||||
this.webTestClient.get().uri("/locations/1").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -31,7 +31,7 @@ public class RequestParameters {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void getQueryStringSnippet() throws Exception {
|
||||
public void getQueryStringSnippet() {
|
||||
// tag::request-parameters-query-string[]
|
||||
this.webTestClient.get().uri("/users?page=2&per_page=100") // <1>
|
||||
.exchange().expectStatus().isOk().expectBody()
|
||||
@@ -42,7 +42,7 @@ public class RequestParameters {
|
||||
// end::request-parameters-query-string[]
|
||||
}
|
||||
|
||||
public void postFormDataSnippet() throws Exception {
|
||||
public void postFormDataSnippet() {
|
||||
// tag::request-parameters-form-data[]
|
||||
MultiValueMap<String, String> formData = new LinkedMultiValueMap<>();
|
||||
formData.add("username", "Tester");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -37,7 +37,7 @@ public class RequestPartPayload {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void fields() throws Exception {
|
||||
public void fields() {
|
||||
// tag::fields[]
|
||||
MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
|
||||
Resource imageResource = new ByteArrayResource("<<png data>>".getBytes()) {
|
||||
@@ -59,7 +59,7 @@ public class RequestPartPayload {
|
||||
// end::fields[]
|
||||
}
|
||||
|
||||
public void body() throws Exception {
|
||||
public void body() {
|
||||
// tag::body[]
|
||||
MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
|
||||
Resource imageResource = new ByteArrayResource("<<png data>>".getBytes()) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -31,7 +31,7 @@ public class RequestParts {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void upload() throws Exception {
|
||||
public void upload() {
|
||||
// tag::request-parts[]
|
||||
MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
|
||||
multipartData.add("file", "example".getBytes());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -30,7 +30,7 @@ public class WebTestClientSnippetReuse extends SnippetReuse {
|
||||
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
public void documentation() throws Exception {
|
||||
public void documentation() {
|
||||
// tag::use[]
|
||||
this.webTestClient.get().uri("/").accept(MediaType.APPLICATION_JSON).exchange()
|
||||
.expectStatus().isOk().expectBody()
|
||||
|
||||
@@ -59,7 +59,7 @@ public class SampleRestAssuredApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sample() throws Exception {
|
||||
public void sample() {
|
||||
given(this.documentationSpec)
|
||||
.accept("text/plain")
|
||||
.filter(document("sample",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -51,7 +51,7 @@ public class SampleWebTestClientApplicationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sample() throws Exception {
|
||||
public void sample() {
|
||||
this.webTestClient.get().uri("/").exchange()
|
||||
.expectStatus().isOk().expectBody()
|
||||
.consumeWith(document("sample"));
|
||||
|
||||
@@ -49,7 +49,7 @@ public class SnippetsDirectoryResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illegalStateExceptionWhenMavenPomCannotBeFound() throws IOException {
|
||||
public void illegalStateExceptionWhenMavenPomCannotBeFound() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
String docdir = new File(this.temporaryFolder.getRoot(), "src/main/asciidoc").getAbsolutePath();
|
||||
attributes.put("docdir", docdir);
|
||||
@@ -58,14 +58,14 @@ public class SnippetsDirectoryResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illegalStateWhenDocdirAttributeIsNotSetInMavenProject() throws IOException {
|
||||
public void illegalStateWhenDocdirAttributeIsNotSetInMavenProject() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
assertThatIllegalStateException().isThrownBy(() -> getMavenSnippetsDirectory(attributes))
|
||||
.withMessage("docdir attribute not found");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathGradleProjectdir() throws IOException {
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathGradleProjectdir() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put("gradle-projectdir", "project/dir");
|
||||
File snippetsDirectory = new SnippetsDirectoryResolver().getSnippetsDirectory(attributes);
|
||||
@@ -73,8 +73,7 @@ public class SnippetsDirectoryResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathGradleProjectdirWhenBothItAndProjectdirAreSet()
|
||||
throws IOException {
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathGradleProjectdirWhenBothItAndProjectdirAreSet() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put("gradle-projectdir", "project/dir");
|
||||
attributes.put("projectdir", "fallback/dir");
|
||||
@@ -83,8 +82,7 @@ public class SnippetsDirectoryResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathProjectdirWhenGradleProjectdirIsNotSet()
|
||||
throws IOException {
|
||||
public void gradleProjectsUseBuildGeneratedSnippetsBeneathProjectdirWhenGradleProjectdirIsNotSet() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
attributes.put("projectdir", "project/dir");
|
||||
File snippetsDirectory = new SnippetsDirectoryResolver().getSnippetsDirectory(attributes);
|
||||
@@ -92,7 +90,7 @@ public class SnippetsDirectoryResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void illegalStateWhenGradleProjectdirAndProjectdirAttributesAreNotSetInGradleProject() throws IOException {
|
||||
public void illegalStateWhenGradleProjectdirAndProjectdirAttributesAreNotSetInGradleProject() {
|
||||
Map<String, Object> attributes = new HashMap<>();
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> new SnippetsDirectoryResolver().getSnippetsDirectory(attributes))
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.headers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -41,7 +40,7 @@ public class RequestHeadersSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void missingRequestHeader() throws IOException {
|
||||
public void missingRequestHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestHeadersSnippet(Arrays.asList(headerWithName("Accept").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
@@ -49,7 +48,7 @@ public class RequestHeadersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestHeaderAndMissingRequestHeader() throws IOException {
|
||||
public void undocumentedRequestHeaderAndMissingRequestHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestHeadersSnippet(Arrays.asList(headerWithName("Accept").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").header("X-Test", "test").build()))
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.headers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -41,7 +40,7 @@ public class ResponseHeadersSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void missingResponseHeader() throws IOException {
|
||||
public void missingResponseHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new ResponseHeadersSnippet(Arrays.asList(headerWithName("Content-Type").description("one")))
|
||||
.document(this.operationBuilder.response().build()))
|
||||
@@ -49,7 +48,7 @@ public class ResponseHeadersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedResponseHeaderAndMissingResponseHeader() throws IOException {
|
||||
public void undocumentedResponseHeaderAndMissingResponseHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new ResponseHeadersSnippet(Arrays.asList(headerWithName("Content-Type").description("one")))
|
||||
.document(this.operationBuilder.response().header("X-Test", "test").build()))
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.hypermedia;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -41,7 +40,7 @@ public class LinksSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedLink() throws IOException {
|
||||
public void undocumentedLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "bar")),
|
||||
Collections.<LinkDescriptor>emptyList()).document(this.operationBuilder.build()))
|
||||
@@ -49,7 +48,7 @@ public class LinksSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingLink() throws IOException {
|
||||
public void missingLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor(),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar")))
|
||||
@@ -58,7 +57,7 @@ public class LinksSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedLinkAndMissingLink() throws IOException {
|
||||
public void undocumentedLinkAndMissingLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha")),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar")))
|
||||
@@ -68,7 +67,7 @@ public class LinksSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linkWithNoDescription() throws IOException {
|
||||
public void linkWithNoDescription() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "bar")),
|
||||
Arrays.asList(new LinkDescriptor("foo"))).document(this.operationBuilder.build()))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class PatternReplacingContentModifierTests {
|
||||
|
||||
@Test
|
||||
public void patternsAreReplaced() throws Exception {
|
||||
public void patternsAreReplaced() {
|
||||
Pattern pattern = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(pattern, "<<uuid>>");
|
||||
@@ -44,7 +44,7 @@ public class PatternReplacingContentModifierTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentThatDoesNotMatchIsUnchanged() throws Exception {
|
||||
public void contentThatDoesNotMatchIsUnchanged() {
|
||||
Pattern pattern = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(pattern, "<<uuid>>");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -39,13 +39,13 @@ public class PrettyPrintingContentModifierTests {
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
@Test
|
||||
public void prettyPrintJson() throws Exception {
|
||||
public void prettyPrintJson() {
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent("{\"a\":5}".getBytes(), null))
|
||||
.isEqualTo(String.format("{%n \"a\" : 5%n}").getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prettyPrintXml() throws Exception {
|
||||
public void prettyPrintXml() {
|
||||
assertThat(new PrettyPrintingContentModifier()
|
||||
.modifyContent("<one a=\"alpha\"><two b=\"bravo\"/></one>".getBytes(), null))
|
||||
.isEqualTo(String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
|
||||
@@ -53,12 +53,12 @@ public class PrettyPrintingContentModifierTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void empytContentIsHandledGracefully() throws Exception {
|
||||
public void empytContentIsHandledGracefully() {
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent("".getBytes(), null)).isEqualTo("".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonJsonAndNonXmlContentIsHandledGracefully() throws Exception {
|
||||
public void nonJsonAndNonXmlContentIsHandledGracefully() {
|
||||
String content = "abcdefg";
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null))
|
||||
.isEqualTo(content.getBytes());
|
||||
@@ -66,7 +66,7 @@ public class PrettyPrintingContentModifierTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonJsonContentThatInitiallyLooksLikeJsonIsHandledGracefully() throws Exception {
|
||||
public void nonJsonContentThatInitiallyLooksLikeJsonIsHandledGracefully() {
|
||||
String content = "\"abc\",\"def\"";
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null))
|
||||
.isEqualTo(content.getBytes());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -99,8 +99,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractMapSubsectionWithVaryingStructureFromMultiElementArrayInAJsonMap()
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
public void extractMapSubsectionWithVaryingStructureFromMultiElementArrayInAJsonMap() {
|
||||
this.thrown.expect(PayloadHandlingException.class);
|
||||
this.thrown.expectMessage("The following non-optional uncommon paths were found: [a.[].b.d]");
|
||||
new FieldPathPayloadSubsectionExtractor("a.[].b").extractSubsection(
|
||||
@@ -108,8 +107,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMap()
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMap() {
|
||||
this.thrown.expect(PayloadHandlingException.class);
|
||||
this.thrown.expectMessage("The following non-optional uncommon paths were found: [*.d, *.d.e, *.d.f]");
|
||||
new FieldPathPayloadSubsectionExtractor("*.d").extractSubsection(
|
||||
@@ -117,8 +115,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMapWhereAllSubsectionFieldsAreOptional()
|
||||
throws IOException {
|
||||
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMapWhereAllSubsectionFieldsAreOptional() {
|
||||
this.thrown.expect(PayloadHandlingException.class);
|
||||
this.thrown.expectMessage("The following non-optional uncommon paths were found: [*.d]");
|
||||
new FieldPathPayloadSubsectionExtractor("*.d").extractSubsection(
|
||||
@@ -176,7 +173,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractNonExistentSubsection() throws JsonParseException, JsonMappingException, IOException {
|
||||
public void extractNonExistentSubsection() {
|
||||
assertThatThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a.c")
|
||||
.extractSubsection("{\"a\":{\"b\":{\"c\":5}}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
@@ -184,7 +181,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractEmptyArraySubsection() throws JsonParseException, JsonMappingException, IOException {
|
||||
public void extractEmptyArraySubsection() {
|
||||
assertThatThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a")
|
||||
.extractSubsection("{\"a\":[]}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -102,7 +101,7 @@ public class JsonContentHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typeForFieldWithSometimesPresentOptionalAncestorCanBeProvidedExplicitly() throws IOException {
|
||||
public void typeForFieldWithSometimesPresentOptionalAncestorCanBeProvidedExplicitly() {
|
||||
FieldDescriptor descriptor = new FieldDescriptor("a.[].b.c").type(JsonFieldType.NUMBER);
|
||||
FieldDescriptor ancestor = new FieldDescriptor("a.[].b").optional();
|
||||
Object fieldType = new JsonContentHandler("{\"a\":[ { \"d\": 4}, {\"b\":{\"c\":5}, \"d\": 4}]}".getBytes(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -306,7 +306,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractNestedEntryWithDotInKeys() throws IOException {
|
||||
public void extractNestedEntryWithDotInKeys() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a.key", alpha);
|
||||
@@ -316,7 +316,7 @@ public class JsonFieldProcessorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void extractNestedEntriesUsingTopLevelWildcard() throws IOException {
|
||||
public void extractNestedEntriesUsingTopLevelWildcard() {
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
Map<String, Object> alpha = new LinkedHashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -330,7 +330,7 @@ public class JsonFieldProcessorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void extractNestedEntriesUsingMidLevelWildcard() throws IOException {
|
||||
public void extractNestedEntriesUsingMidLevelWildcard() {
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
Map<String, Object> alpha = new LinkedHashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -344,7 +344,7 @@ public class JsonFieldProcessorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void extractUsingLeafWildcardMatchingSingleItem() throws IOException {
|
||||
public void extractUsingLeafWildcardMatchingSingleItem() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -357,7 +357,7 @@ public class JsonFieldProcessorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void extractUsingLeafWildcardMatchingMultipleItems() throws IOException {
|
||||
public void extractUsingLeafWildcardMatchingMultipleItems() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -368,7 +368,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUsingLeafWildcard() throws IOException {
|
||||
public void removeUsingLeafWildcard() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -379,7 +379,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUsingTopLevelWildcard() throws IOException {
|
||||
public void removeUsingTopLevelWildcard() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -390,7 +390,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUsingMidLevelWildcard() throws IOException {
|
||||
public void removeUsingMidLevelWildcard() {
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
Map<String, Object> alpha = new LinkedHashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -407,28 +407,28 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsTrueForNonNullFieldInMap() throws Exception {
|
||||
public void hasFieldIsTrueForNonNullFieldInMap() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("a", "alpha");
|
||||
assertThat(this.fieldProcessor.hasField("a", payload)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsTrueForNullFieldInMap() throws Exception {
|
||||
public void hasFieldIsTrueForNullFieldInMap() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("a", null);
|
||||
assertThat(this.fieldProcessor.hasField("a", payload)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsFalseForAbsentFieldInMap() throws Exception {
|
||||
public void hasFieldIsFalseForAbsentFieldInMap() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("a", null);
|
||||
assertThat(this.fieldProcessor.hasField("b", payload)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsTrueForNeverNullFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsTrueForNeverNullFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("b", "bravo");
|
||||
@@ -437,7 +437,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsTrueForAlwaysNullFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsTrueForAlwaysNullFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("b", null);
|
||||
@@ -446,7 +446,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsFalseForAlwaysAbsentFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsFalseForAlwaysAbsentFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("b", "bravo");
|
||||
@@ -455,7 +455,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsFalseForOccasionallyAbsentFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsFalseForOccasionallyAbsentFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("b", "bravo");
|
||||
@@ -464,7 +464,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsFalseForOccasionallyNullFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsFalseForOccasionallyNullFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> fieldPresent = new HashMap<>();
|
||||
fieldPresent.put("b", "bravo");
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -44,7 +43,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestField() throws IOException {
|
||||
public void undocumentedRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost").content("{\"a\": 5}").build()))
|
||||
@@ -52,7 +51,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingRequestField() throws IOException {
|
||||
public void missingRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").content("{}").build()))
|
||||
@@ -60,14 +59,14 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingOptionalRequestFieldWithNoTypeProvided() throws IOException {
|
||||
public void missingOptionalRequestFieldWithNoTypeProvided() {
|
||||
assertThatExceptionOfType(FieldTypeRequiredException.class).isThrownBy(
|
||||
() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one").optional()))
|
||||
.document(this.operationBuilder.request("http://localhost").content("{ }").build()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestFieldAndMissingRequestField() throws IOException {
|
||||
public void undocumentedRequestFieldAndMissingRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one"))).document(
|
||||
this.operationBuilder.request("http://localhost").content("{ \"a\": { \"c\": 5 }}").build()))
|
||||
@@ -76,7 +75,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attemptToDocumentFieldsWithNoRequestBody() throws IOException {
|
||||
public void attemptToDocumentFieldsWithNoRequestBody() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
@@ -84,7 +83,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldWithExplicitTypeThatDoesNotMatchThePayload() throws IOException {
|
||||
public void fieldWithExplicitTypeThatDoesNotMatchThePayload() {
|
||||
assertThatExceptionOfType(FieldTypesDoNotMatchException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a").description("one").type(JsonFieldType.OBJECT))).document(
|
||||
@@ -93,7 +92,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldWithExplicitSpecificTypeThatActuallyVaries() throws IOException {
|
||||
public void fieldWithExplicitSpecificTypeThatActuallyVaries() {
|
||||
assertThatExceptionOfType(FieldTypesDoNotMatchException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("[].a").description("one").type(JsonFieldType.OBJECT)))
|
||||
@@ -103,7 +102,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedXmlRequestField() throws IOException {
|
||||
public void undocumentedXmlRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost").content("<a><b>5</b></a>")
|
||||
@@ -112,7 +111,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlDescendentsAreNotDocumentedByFieldDescriptor() throws IOException {
|
||||
public void xmlDescendentsAreNotDocumentedByFieldDescriptor() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(
|
||||
() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").type("a").description("one")))
|
||||
@@ -122,7 +121,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlRequestFieldWithNoType() throws IOException {
|
||||
public void xmlRequestFieldWithNoType() {
|
||||
assertThatExceptionOfType(FieldTypeRequiredException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").content("<a>5</a>")
|
||||
@@ -130,7 +129,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingXmlRequestField() throws IOException {
|
||||
public void missingXmlRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a/b").description("one"), fieldWithPath("a").description("one")))
|
||||
@@ -140,7 +139,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedXmlRequestFieldAndMissingXmlRequestField() throws IOException {
|
||||
public void undocumentedXmlRequestFieldAndMissingXmlRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a/b").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").content("<a><c>5</c></a>")
|
||||
@@ -150,7 +149,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsupportedContent() throws IOException {
|
||||
public void unsupportedContent() {
|
||||
assertThatExceptionOfType(PayloadHandlingException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost").content("Some plain text")
|
||||
@@ -159,7 +158,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesNull() throws IOException {
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesNull() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a[].b").description("one").type(JsonFieldType.NUMBER),
|
||||
@@ -172,7 +171,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesAbsent() throws IOException {
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesAbsent() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a[].b").description("one").type(JsonFieldType.NUMBER),
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -43,7 +42,7 @@ public class RequestPartFieldsSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestPartField() throws IOException {
|
||||
public void undocumentedRequestPartField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestPartFieldsSnippet("part", Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost")
|
||||
@@ -52,7 +51,7 @@ public class RequestPartFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingRequestPartField() throws IOException {
|
||||
public void missingRequestPartField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(
|
||||
() -> new RequestPartFieldsSnippet("part", Arrays.asList(fieldWithPath("b").description("one")))
|
||||
@@ -62,7 +61,7 @@ public class RequestPartFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingRequestPart() throws IOException {
|
||||
public void missingRequestPart() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new RequestPartFieldsSnippet("another", Arrays.asList(fieldWithPath("a.b").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost")
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -44,7 +43,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void attemptToDocumentFieldsWithNoResponseBody() throws IOException {
|
||||
public void attemptToDocumentFieldsWithNoResponseBody() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")))
|
||||
.document(this.operationBuilder.build()))
|
||||
@@ -52,7 +51,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldWithExplicitTypeThatDoesNotMatchThePayload() throws IOException {
|
||||
public void fieldWithExplicitTypeThatDoesNotMatchThePayload() {
|
||||
assertThatExceptionOfType(FieldTypesDoNotMatchException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a").description("one").type(JsonFieldType.OBJECT)))
|
||||
@@ -61,7 +60,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldWithExplicitSpecificTypeThatActuallyVaries() throws IOException {
|
||||
public void fieldWithExplicitSpecificTypeThatActuallyVaries() {
|
||||
assertThatExceptionOfType(FieldTypesDoNotMatchException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("[].a").description("one").type(JsonFieldType.OBJECT))).document(
|
||||
@@ -70,7 +69,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedXmlResponseField() throws IOException {
|
||||
public void undocumentedXmlResponseField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.response().content("<a><b>5</b></a>")
|
||||
@@ -79,7 +78,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingXmlAttribute() throws IOException {
|
||||
public void missingXmlAttribute() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(
|
||||
() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one").type("b"),
|
||||
@@ -93,7 +92,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void documentedXmlAttributesAreRemoved() throws IOException {
|
||||
public void documentedXmlAttributesAreRemoved() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a/@id").description("one").type("a")))
|
||||
.document(this.operationBuilder.response().content("<a id=\"foo\">bar</a>")
|
||||
@@ -102,7 +101,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlResponseFieldWithNoType() throws IOException {
|
||||
public void xmlResponseFieldWithNoType() {
|
||||
assertThatExceptionOfType(FieldTypeRequiredException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")))
|
||||
.document(this.operationBuilder.response().content("<a>5</a>")
|
||||
@@ -110,7 +109,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingXmlResponseField() throws IOException {
|
||||
public void missingXmlResponseField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a/b").description("one"), fieldWithPath("a").description("one")))
|
||||
@@ -120,7 +119,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedXmlResponseFieldAndMissingXmlResponseField() throws IOException {
|
||||
public void undocumentedXmlResponseFieldAndMissingXmlResponseField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a/b").description("one")))
|
||||
.document(this.operationBuilder.response().content("<a><c>5</c></a>")
|
||||
@@ -130,7 +129,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsupportedContent() throws IOException {
|
||||
public void unsupportedContent() {
|
||||
assertThatExceptionOfType(PayloadHandlingException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.response().content("Some plain text")
|
||||
@@ -139,7 +138,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesNull() throws IOException {
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesNull() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a[].b").description("one").type(JsonFieldType.NUMBER),
|
||||
@@ -152,7 +151,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesAbsent() throws IOException {
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesAbsent() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a[].b").description("one").type(JsonFieldType.NUMBER),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.request;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -43,7 +42,7 @@ public class PathParametersSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedPathParameter() throws IOException {
|
||||
public void undocumentedPathParameter() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new PathParametersSnippet(Collections.<ParameterDescriptor>emptyList())
|
||||
.document(this.operationBuilder
|
||||
@@ -52,7 +51,7 @@ public class PathParametersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingPathParameter() throws IOException {
|
||||
public void missingPathParameter() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one")))
|
||||
.document(this.operationBuilder
|
||||
@@ -61,7 +60,7 @@ public class PathParametersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedAndMissingPathParameters() throws IOException {
|
||||
public void undocumentedAndMissingPathParameters() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one")))
|
||||
.document(this.operationBuilder
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.request;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -42,7 +41,7 @@ public class RequestParametersSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedParameter() throws IOException {
|
||||
public void undocumentedParameter() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestParametersSnippet(Collections.<ParameterDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost").param("a", "alpha").build()))
|
||||
@@ -50,7 +49,7 @@ public class RequestParametersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingParameter() throws IOException {
|
||||
public void missingParameter() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestParametersSnippet(Arrays.asList(parameterWithName("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
@@ -58,7 +57,7 @@ public class RequestParametersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedAndMissingParameters() throws IOException {
|
||||
public void undocumentedAndMissingParameters() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestParametersSnippet(Arrays.asList(parameterWithName("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").param("b", "bravo").build()))
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.request;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -42,7 +41,7 @@ public class RequestPartsSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedPart() throws IOException {
|
||||
public void undocumentedPart() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestPartsSnippet(Collections.<RequestPartDescriptor>emptyList()).document(
|
||||
this.operationBuilder.request("http://localhost").part("a", "alpha".getBytes()).build()))
|
||||
@@ -50,7 +49,7 @@ public class RequestPartsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingPart() throws IOException {
|
||||
public void missingPart() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestPartsSnippet(Arrays.asList(partWithName("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
@@ -58,7 +57,7 @@ public class RequestPartsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedAndMissingParts() throws IOException {
|
||||
public void undocumentedAndMissingParts() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestPartsSnippet(Arrays.asList(partWithName("a").description("one"))).document(
|
||||
this.operationBuilder.request("http://localhost").part("b", "bravo".getBytes()).build()))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -33,79 +33,79 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class RestDocumentationContextPlaceholderResolverTests {
|
||||
|
||||
@Test
|
||||
public void kebabCaseMethodName() throws Exception {
|
||||
public void kebabCaseMethodName() {
|
||||
assertThat(createResolver("dashSeparatedMethodName").resolvePlaceholder("method-name"))
|
||||
.isEqualTo("dash-separated-method-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kebabCaseMethodNameWithUpperCaseOpeningSection() throws Exception {
|
||||
public void kebabCaseMethodNameWithUpperCaseOpeningSection() {
|
||||
assertThat(createResolver("URIDashSeparatedMethodName").resolvePlaceholder("method-name"))
|
||||
.isEqualTo("uri-dash-separated-method-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kebabCaseMethodNameWithUpperCaseMidSection() throws Exception {
|
||||
public void kebabCaseMethodNameWithUpperCaseMidSection() {
|
||||
assertThat(createResolver("dashSeparatedMethodNameWithURIInIt").resolvePlaceholder("method-name"))
|
||||
.isEqualTo("dash-separated-method-name-with-uri-in-it");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kebabCaseMethodNameWithUpperCaseEndSection() throws Exception {
|
||||
public void kebabCaseMethodNameWithUpperCaseEndSection() {
|
||||
assertThat(createResolver("dashSeparatedMethodNameWithURI").resolvePlaceholder("method-name"))
|
||||
.isEqualTo("dash-separated-method-name-with-uri");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseMethodName() throws Exception {
|
||||
public void snakeCaseMethodName() {
|
||||
assertThat(createResolver("underscoreSeparatedMethodName").resolvePlaceholder("method_name"))
|
||||
.isEqualTo("underscore_separated_method_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseMethodNameWithUpperCaseOpeningSection() throws Exception {
|
||||
public void snakeCaseMethodNameWithUpperCaseOpeningSection() {
|
||||
assertThat(createResolver("URIUnderscoreSeparatedMethodName").resolvePlaceholder("method_name"))
|
||||
.isEqualTo("uri_underscore_separated_method_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseMethodNameWithUpperCaseMidSection() throws Exception {
|
||||
public void snakeCaseMethodNameWithUpperCaseMidSection() {
|
||||
assertThat(createResolver("underscoreSeparatedMethodNameWithURIInIt").resolvePlaceholder("method_name"))
|
||||
.isEqualTo("underscore_separated_method_name_with_uri_in_it");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseMethodNameWithUpperCaseEndSection() throws Exception {
|
||||
public void snakeCaseMethodNameWithUpperCaseEndSection() {
|
||||
assertThat(createResolver("underscoreSeparatedMethodNameWithURI").resolvePlaceholder("method_name"))
|
||||
.isEqualTo("underscore_separated_method_name_with_uri");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void camelCaseMethodName() throws Exception {
|
||||
public void camelCaseMethodName() {
|
||||
assertThat(createResolver("camelCaseMethodName").resolvePlaceholder("methodName"))
|
||||
.isEqualTo("camelCaseMethodName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kebabCaseClassName() throws Exception {
|
||||
public void kebabCaseClassName() {
|
||||
assertThat(createResolver().resolvePlaceholder("class-name"))
|
||||
.isEqualTo("rest-documentation-context-placeholder-resolver-tests");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseClassName() throws Exception {
|
||||
public void snakeCaseClassName() {
|
||||
assertThat(createResolver().resolvePlaceholder("class_name"))
|
||||
.isEqualTo("rest_documentation_context_placeholder_resolver_tests");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void camelCaseClassName() throws Exception {
|
||||
public void camelCaseClassName() {
|
||||
assertThat(createResolver().resolvePlaceholder("ClassName"))
|
||||
.isEqualTo("RestDocumentationContextPlaceholderResolverTests");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stepCount() throws Exception {
|
||||
public void stepCount() {
|
||||
assertThat(createResolver("stepCount").resolvePlaceholder("step")).isEqualTo("1");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.restdocs.templates;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -41,7 +42,7 @@ public class StandardTemplateResourceResolverTests {
|
||||
private final TestClassLoader classLoader = new TestClassLoader();
|
||||
|
||||
@Test
|
||||
public void formatSpecificCustomSnippetHasHighestPrecedence() throws Exception {
|
||||
public void formatSpecificCustomSnippetHasHighestPrecedence() throws IOException {
|
||||
this.classLoader.addResource("org/springframework/restdocs/templates/asciidoctor/test.snippet",
|
||||
getClass().getResource("test-format-specific-custom.snippet"));
|
||||
this.classLoader.addResource("org/springframework/restdocs/templates/test.snippet",
|
||||
@@ -61,7 +62,7 @@ public class StandardTemplateResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generalCustomSnippetIsUsedInAbsenceOfFormatSpecificCustomSnippet() throws Exception {
|
||||
public void generalCustomSnippetIsUsedInAbsenceOfFormatSpecificCustomSnippet() throws IOException {
|
||||
this.classLoader.addResource("org/springframework/restdocs/templates/test.snippet",
|
||||
getClass().getResource("test-custom.snippet"));
|
||||
this.classLoader.addResource("org/springframework/restdocs/templates/asciidoctor/default-test.snippet",
|
||||
@@ -95,19 +96,22 @@ public class StandardTemplateResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failsIfCustomAndDefaultSnippetsDoNotExist() throws Exception {
|
||||
public void failsIfCustomAndDefaultSnippetsDoNotExist() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> doWithThreadContextClassLoader(this.classLoader,
|
||||
() -> StandardTemplateResourceResolverTests.this.resolver.resolveTemplateResource("test")))
|
||||
.withMessage("Template named 'test' could not be resolved");
|
||||
}
|
||||
|
||||
private <T> T doWithThreadContextClassLoader(ClassLoader classLoader, Callable<T> action) throws Exception {
|
||||
private <T> T doWithThreadContextClassLoader(ClassLoader classLoader, Callable<T> action) {
|
||||
ClassLoader previous = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
try {
|
||||
return action.call();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
finally {
|
||||
Thread.currentThread().setContextClassLoader(previous);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -48,7 +48,7 @@ public class RestDocumentationResultHandler implements ResultHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(MvcResult result) throws Exception {
|
||||
public void handle(MvcResult result) {
|
||||
this.delegate.handle(result.getRequest(), result.getResponse(), retrieveConfiguration(result));
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ public class RestDocumentationResultHandler implements ResultHandler {
|
||||
return new RestDocumentationResultHandler(this.delegate.withSnippets(snippets)) {
|
||||
|
||||
@Override
|
||||
public void handle(MvcResult result) throws Exception {
|
||||
public void handle(MvcResult result) {
|
||||
Map<String, Object> configuration = new HashMap<>(retrieveConfiguration(result));
|
||||
configuration.remove(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS);
|
||||
getDelegate().handle(result.getRequest(), result.getResponse(), configuration);
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.springframework.restdocs.mockmvc;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
@@ -49,14 +50,14 @@ public class MockMvcRequestConverterTests {
|
||||
private final MockMvcRequestConverter factory = new MockMvcRequestConverter();
|
||||
|
||||
@Test
|
||||
public void httpRequest() throws Exception {
|
||||
public void httpRequest() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.get("/foo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
assertThat(request.getMethod()).isEqualTo(HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpRequestWithCustomPort() throws Exception {
|
||||
public void httpRequestWithCustomPort() {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
mockRequest.setServerPort(8080);
|
||||
OperationRequest request = this.factory.convert(mockRequest);
|
||||
@@ -65,14 +66,14 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithContextPath() throws Exception {
|
||||
public void requestWithContextPath() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.get("/foo/bar").contextPath("/foo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo/bar"));
|
||||
assertThat(request.getMethod()).isEqualTo(HttpMethod.GET);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithHeaders() throws Exception {
|
||||
public void requestWithHeaders() {
|
||||
OperationRequest request = createOperationRequest(
|
||||
MockMvcRequestBuilders.get("/foo").header("a", "alpha", "apple").header("b", "bravo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
@@ -82,7 +83,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithCookies() throws Exception {
|
||||
public void requestWithCookies() {
|
||||
OperationRequest request = createOperationRequest(
|
||||
MockMvcRequestBuilders.get("/foo").cookie(new jakarta.servlet.http.Cookie("cookieName1", "cookieVal1"),
|
||||
new jakarta.servlet.http.Cookie("cookieName2", "cookieVal2")));
|
||||
@@ -102,7 +103,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpsRequest() throws Exception {
|
||||
public void httpsRequest() {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
mockRequest.setScheme("https");
|
||||
mockRequest.setServerPort(443);
|
||||
@@ -112,7 +113,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpsRequestWithCustomPort() throws Exception {
|
||||
public void httpsRequestWithCustomPort() {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
mockRequest.setScheme("https");
|
||||
mockRequest.setServerPort(8443);
|
||||
@@ -122,7 +123,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithParametersProducesUriWithQueryString() throws Exception {
|
||||
public void getRequestWithParametersProducesUriWithQueryString() {
|
||||
OperationRequest request = createOperationRequest(
|
||||
MockMvcRequestBuilders.get("/foo").param("a", "alpha", "apple").param("b", "br&vo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo?a=alpha&a=apple&b=br%26vo"));
|
||||
@@ -133,7 +134,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryStringPopulatesParameters() throws Exception {
|
||||
public void getRequestWithQueryStringPopulatesParameters() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.get("/foo?a=alpha&b=bravo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo?a=alpha&b=bravo"));
|
||||
assertThat(request.getParameters().size()).isEqualTo(2);
|
||||
@@ -143,7 +144,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithParameters() throws Exception {
|
||||
public void postRequestWithParameters() {
|
||||
OperationRequest request = createOperationRequest(
|
||||
MockMvcRequestBuilders.post("/foo").param("a", "alpha", "apple").param("b", "br&vo"));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
@@ -154,7 +155,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockMultipartFileUpload() throws Exception {
|
||||
public void mockMultipartFileUpload() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.multipart("/foo")
|
||||
.file(new MockMultipartFile("file", new byte[] { 1, 2, 3, 4 })));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
@@ -169,7 +170,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mockMultipartFileUploadWithContentType() throws Exception {
|
||||
public void mockMultipartFileUploadWithContentType() {
|
||||
OperationRequest request = createOperationRequest(MockMvcRequestBuilders.multipart("/foo")
|
||||
.file(new MockMultipartFile("file", "original", "image/png", new byte[] { 1, 2, 3, 4 })));
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
|
||||
@@ -183,7 +184,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithPart() throws Exception {
|
||||
public void requestWithPart() throws IOException {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
Part mockPart = mock(Part.class);
|
||||
given(mockPart.getHeaderNames()).willReturn(Arrays.asList("a", "b"));
|
||||
@@ -205,7 +206,7 @@ public class MockMvcRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithPartWithContentType() throws Exception {
|
||||
public void requestWithPartWithContentType() throws IOException {
|
||||
MockHttpServletRequest mockRequest = MockMvcRequestBuilders.get("/foo").buildRequest(new MockServletContext());
|
||||
Part mockPart = mock(Part.class);
|
||||
given(mockPart.getHeaderNames()).willReturn(Arrays.asList("a", "b"));
|
||||
@@ -227,7 +228,7 @@ public class MockMvcRequestConverterTests {
|
||||
assertThat(part.getContent()).isEqualTo(new byte[] { 1, 2, 3, 4 });
|
||||
}
|
||||
|
||||
private OperationRequest createOperationRequest(MockHttpServletRequestBuilder builder) throws Exception {
|
||||
private OperationRequest createOperationRequest(MockHttpServletRequestBuilder builder) {
|
||||
return this.factory.convert(builder.buildRequest(new MockServletContext()));
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
@@ -96,7 +97,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithContent() throws Exception {
|
||||
public void curlSnippetWithContent() {
|
||||
String contentType = "text/plain; charset=UTF-8";
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("curl-snippet-with-content")).accept("application/json").body("content")
|
||||
@@ -109,7 +110,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithCookies() throws Exception {
|
||||
public void curlSnippetWithCookies() {
|
||||
String contentType = "text/plain; charset=UTF-8";
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("curl-snippet-with-cookies")).accept("application/json").contentType(contentType)
|
||||
@@ -121,7 +122,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithEmptyParameterQueryString() throws Exception {
|
||||
public void curlSnippetWithEmptyParameterQueryString() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("curl-snippet-with-empty-parameter-query-string")).accept("application/json")
|
||||
.param("a", "").get("/").then().statusCode(200);
|
||||
@@ -133,7 +134,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithQueryStringOnPost() throws Exception {
|
||||
public void curlSnippetWithQueryStringOnPost() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("curl-snippet-with-query-string")).accept("application/json").param("foo", "bar")
|
||||
.param("a", "alpha").post("/?foo=bar").then().statusCode(200);
|
||||
@@ -146,7 +147,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linksSnippet() throws Exception {
|
||||
public void linksSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("links", links(linkWithRel("rel").description("The description"))))
|
||||
.accept("application/json").get("/").then().statusCode(200);
|
||||
@@ -155,7 +156,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathParametersSnippet() throws Exception {
|
||||
public void pathParametersSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("path-parameters",
|
||||
pathParameters(parameterWithName("foo").description("The description"))))
|
||||
@@ -165,7 +166,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestParametersSnippet() throws Exception {
|
||||
public void requestParametersSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("request-parameters",
|
||||
requestParameters(parameterWithName("foo").description("The description"))))
|
||||
@@ -175,7 +176,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestFieldsSnippet() throws Exception {
|
||||
public void requestFieldsSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("request-fields", requestFields(fieldWithPath("a").description("The description"))))
|
||||
.accept("application/json").body("{\"a\":\"alpha\"}").post("/").then().statusCode(200);
|
||||
@@ -184,7 +185,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestPartsSnippet() throws Exception {
|
||||
public void requestPartsSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("request-parts", requestParts(partWithName("a").description("The description"))))
|
||||
.multiPart("a", "foo").post("/upload").then().statusCode(200);
|
||||
@@ -193,7 +194,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseFieldsSnippet() throws Exception {
|
||||
public void responseFieldsSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("response-fields",
|
||||
responseFields(fieldWithPath("a").description("The description"),
|
||||
@@ -204,7 +205,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parameterizedOutputDirectory() throws Exception {
|
||||
public void parameterizedOutputDirectory() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("{method-name}")).get("/").then().statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/parameterized-output-directory"),
|
||||
@@ -212,7 +213,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multiStep() throws Exception {
|
||||
public void multiStep() {
|
||||
RequestSpecification spec = new RequestSpecBuilder().setPort(tomcat.getPort())
|
||||
.addFilter(documentationConfiguration(this.restDocumentation))
|
||||
.addFilter(document("{method-name}-{step}")).build();
|
||||
@@ -228,7 +229,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void additionalSnippets() throws Exception {
|
||||
public void additionalSnippets() {
|
||||
RestDocumentationFilter documentation = document("{method-name}-{step}");
|
||||
RequestSpecification spec = new RequestSpecBuilder().setPort(tomcat.getPort())
|
||||
.addFilter(documentationConfiguration(this.restDocumentation)).addFilter(documentation).build();
|
||||
@@ -254,7 +255,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preprocessedRequest() throws Exception {
|
||||
public void preprocessedRequest() {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation)).header("a", "alpha")
|
||||
.header("b", "bravo").contentType("application/json").accept("application/json")
|
||||
@@ -277,7 +278,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPreprocessedRequest() throws Exception {
|
||||
public void defaultPreprocessedRequest() {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation).operationPreprocessors().withRequestDefaults(
|
||||
@@ -294,7 +295,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preprocessedResponse() throws Exception {
|
||||
public void preprocessedResponse() {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("original-response"))
|
||||
@@ -315,7 +316,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPreprocessedResponse() throws Exception {
|
||||
public void defaultPreprocessedResponse() {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
@@ -335,7 +336,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customSnippetTemplate() throws Exception {
|
||||
public void customSnippetTemplate() throws MalformedURLException {
|
||||
ClassLoader classLoader = new URLClassLoader(
|
||||
new URL[] { new File("src/test/resources/custom-snippet-templates").toURI().toURL() },
|
||||
getClass().getClassLoader());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -103,7 +103,7 @@ public class WebTestClientRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getRequestWithQueryStringPopulatesParameters() throws Exception {
|
||||
public void getRequestWithQueryStringPopulatesParameters() {
|
||||
ExchangeResult result = WebTestClient.bindToRouterFunction(RouterFunctions.route(GET("/foo"), (req) -> null))
|
||||
.configureClient().baseUrl("http://localhost").build().get().uri("/foo?a=alpha&b=bravo").exchange()
|
||||
.expectBody().returnResult();
|
||||
@@ -116,7 +116,7 @@ public class WebTestClientRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithFormDataParameters() throws Exception {
|
||||
public void postRequestWithFormDataParameters() {
|
||||
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
|
||||
parameters.addAll("a", Arrays.asList("alpha", "apple"));
|
||||
parameters.addAll("b", Arrays.asList("br&vo"));
|
||||
@@ -134,7 +134,7 @@ public class WebTestClientRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithQueryStringParameters() throws Exception {
|
||||
public void postRequestWithQueryStringParameters() {
|
||||
ExchangeResult result = WebTestClient.bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> {
|
||||
req.body(BodyExtractors.toFormData()).block();
|
||||
return null;
|
||||
@@ -150,7 +150,7 @@ public class WebTestClientRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithQueryStringAndFormDataParameters() throws Exception {
|
||||
public void postRequestWithQueryStringAndFormDataParameters() {
|
||||
MultiValueMap<String, String> parameters = new LinkedMultiValueMap<>();
|
||||
parameters.addAll("a", Arrays.asList("apple"));
|
||||
ExchangeResult result = WebTestClient.bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> {
|
||||
@@ -168,7 +168,7 @@ public class WebTestClientRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void postRequestWithNoContentType() throws Exception {
|
||||
public void postRequestWithNoContentType() {
|
||||
ExchangeResult result = WebTestClient
|
||||
.bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> ServerResponse.ok().build()))
|
||||
.configureClient().baseUrl("http://localhost").build().post().uri("/foo").exchange().expectBody()
|
||||
@@ -179,7 +179,7 @@ public class WebTestClientRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartUpload() throws Exception {
|
||||
public void multipartUpload() {
|
||||
MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
|
||||
multipartData.add("file", new byte[] { 1, 2, 3, 4 });
|
||||
ExchangeResult result = WebTestClient
|
||||
@@ -205,7 +205,7 @@ public class WebTestClientRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartUploadFromResource() throws Exception {
|
||||
public void multipartUploadFromResource() {
|
||||
MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
|
||||
multipartData.add("file", new ByteArrayResource(new byte[] { 1, 2, 3, 4 }) {
|
||||
|
||||
@@ -241,7 +241,7 @@ public class WebTestClientRequestConverterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestWithCookies() throws Exception {
|
||||
public void requestWithCookies() {
|
||||
ExchangeResult result = WebTestClient.bindToRouterFunction(RouterFunctions.route(GET("/foo"), (req) -> null))
|
||||
.configureClient().baseUrl("http://localhost").build().get().uri("/foo")
|
||||
.cookie("cookieName1", "cookieVal1").cookie("cookieName2", "cookieVal2").exchange().expectBody()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 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.
|
||||
@@ -133,7 +133,7 @@ public class WebTestClientRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipart() throws Exception {
|
||||
public void multipart() {
|
||||
MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
|
||||
multipartData.add("a", "alpha");
|
||||
multipartData.add("b", "bravo");
|
||||
@@ -147,7 +147,7 @@ public class WebTestClientRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithSetCookie() throws Exception {
|
||||
public void responseWithSetCookie() {
|
||||
this.webTestClient.get().uri("/set-cookie").exchange().expectStatus().isOk().expectBody()
|
||||
.consumeWith(document("set-cookie"));
|
||||
assertThat(new File("build/generated-snippets/set-cookie/http-response.adoc"))
|
||||
@@ -156,7 +156,7 @@ public class WebTestClientRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithCookies() throws Exception {
|
||||
public void curlSnippetWithCookies() {
|
||||
this.webTestClient.get().uri("/").cookie("cookieName", "cookieVal").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody().consumeWith(document("curl-snippet-with-cookies"));
|
||||
assertThat(new File("build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc"))
|
||||
@@ -166,7 +166,7 @@ public class WebTestClientRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithEmptyParameterQueryString() throws Exception {
|
||||
public void curlSnippetWithEmptyParameterQueryString() {
|
||||
this.webTestClient.get().uri("/?a=").accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isOk()
|
||||
.expectBody().consumeWith(document("curl-snippet-with-empty-parameter-query-string"));
|
||||
assertThat(
|
||||
@@ -177,7 +177,7 @@ public class WebTestClientRestDocumentationIntegrationTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void httpieSnippetWithCookies() throws Exception {
|
||||
public void httpieSnippetWithCookies() {
|
||||
this.webTestClient.get().uri("/").cookie("cookieName", "cookieVal").accept(MediaType.APPLICATION_JSON)
|
||||
.exchange().expectStatus().isOk().expectBody().consumeWith(document("httpie-snippet-with-cookies"));
|
||||
assertThat(new File("build/generated-snippets/httpie-snippet-with-cookies/httpie-request.adoc"))
|
||||
|
||||
Reference in New Issue
Block a user