Upgrade to Spring Java Format 0.0.38
Closes gh-890
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -123,8 +123,10 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void headersWithCustomAccept() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).header("Foo", "bar")
|
||||
.accept("application/json");
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.port(tomcat.getPort())
|
||||
.header("Foo", "bar")
|
||||
.accept("application/json");
|
||||
requestSpec.get("/");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getHeaders()).hasSize(3);
|
||||
@@ -136,8 +138,10 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void cookies() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).cookie("cookie1", "cookieVal1")
|
||||
.cookie("cookie2", "cookieVal2");
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.port(tomcat.getPort())
|
||||
.cookie("cookie1", "cookieVal1")
|
||||
.cookie("cookie2", "cookieVal2");
|
||||
requestSpec.get("/");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getCookies().size()).isEqualTo(2);
|
||||
@@ -155,8 +159,10 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void multipart() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort())
|
||||
.multiPart("a", "a.txt", "alpha", null).multiPart("b", new ObjectBody("bar"), "application/json");
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.port(tomcat.getPort())
|
||||
.multiPart("a", "a.txt", "alpha", null)
|
||||
.multiPart("b", new ObjectBody("bar"), "application/json");
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
Collection<OperationRequestPart> parts = request.getParts();
|
||||
@@ -164,9 +170,10 @@ public class RestAssuredRequestConverterTests {
|
||||
assertThat(parts).extracting("name").containsExactly("a", "b");
|
||||
assertThat(parts).extracting("submittedFileName").containsExactly("a.txt", "file");
|
||||
assertThat(parts).extracting("contentAsString").containsExactly("alpha", "{\"foo\":\"bar\"}");
|
||||
assertThat(parts).extracting("headers").extracting(HttpHeaders.CONTENT_TYPE).containsExactly(
|
||||
Collections.singletonList(MediaType.TEXT_PLAIN_VALUE),
|
||||
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
||||
assertThat(parts).extracting("headers")
|
||||
.extracting(HttpHeaders.CONTENT_TYPE)
|
||||
.containsExactly(Collections.singletonList(MediaType.TEXT_PLAIN_VALUE),
|
||||
Collections.singletonList(MediaType.APPLICATION_JSON_VALUE));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -194,8 +201,9 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void byteArrayInputStreamBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().body(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }))
|
||||
.port(tomcat.getPort());
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.body(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }))
|
||||
.port(tomcat.getPort());
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getContent()).isEqualTo(new byte[] { 1, 2, 3, 4 });
|
||||
@@ -203,8 +211,9 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void fileBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().body(new File("src/test/resources/body.txt"))
|
||||
.port(tomcat.getPort());
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.body(new File("src/test/resources/body.txt"))
|
||||
.port(tomcat.getPort());
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getContentAsString()).isEqualTo("file");
|
||||
@@ -222,8 +231,9 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void multipartWithByteArrayInputStreamBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).multiPart("foo", "foo.txt",
|
||||
new ByteArrayInputStream("foo".getBytes()));
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.port(tomcat.getPort())
|
||||
.multiPart("foo", "foo.txt", new ByteArrayInputStream("foo".getBytes()));
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("foo");
|
||||
@@ -239,8 +249,9 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void multipartWithByteArrayBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).multiPart("control", "file",
|
||||
"foo".getBytes());
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.port(tomcat.getPort())
|
||||
.multiPart("control", "file", "foo".getBytes());
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("foo");
|
||||
@@ -248,8 +259,9 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void multipartWithFileBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort())
|
||||
.multiPart(new File("src/test/resources/body.txt"));
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.port(tomcat.getPort())
|
||||
.multiPart(new File("src/test/resources/body.txt"));
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("file");
|
||||
@@ -258,8 +270,9 @@ public class RestAssuredRequestConverterTests {
|
||||
@Test
|
||||
public void multipartWithFileInputStreamBody() throws FileNotFoundException {
|
||||
FileInputStream inputStream = new FileInputStream("src/test/resources/body.txt");
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).multiPart("foo", "foo.txt",
|
||||
inputStream);
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.port(tomcat.getPort())
|
||||
.multiPart("foo", "foo.txt", inputStream);
|
||||
requestSpec.post();
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Cannot read content from input stream " + inputStream + " due to reset() failure");
|
||||
@@ -268,8 +281,9 @@ public class RestAssuredRequestConverterTests {
|
||||
|
||||
@Test
|
||||
public void multipartWithObjectBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).multiPart("control",
|
||||
new ObjectBody("bar"));
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.port(tomcat.getPort())
|
||||
.multiPart("control", new ObjectBody("bar"));
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("{\"foo\":\"bar\"}");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -67,9 +67,10 @@ public class RestAssuredRestDocumentationConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void configurationIsAddedToTheContext() {
|
||||
this.configurer.operationPreprocessors().withRequestDefaults(Preprocessors.prettyPrint())
|
||||
.withResponseDefaults(Preprocessors.removeHeaders("Foo"))
|
||||
.filter(this.requestSpec, this.responseSpec, this.filterContext);
|
||||
this.configurer.operationPreprocessors()
|
||||
.withRequestDefaults(Preprocessors.prettyPrint())
|
||||
.withResponseDefaults(Preprocessors.removeHeaders("Foo"))
|
||||
.filter(this.requestSpec, this.responseSpec, this.filterContext);
|
||||
@SuppressWarnings("rawtypes")
|
||||
ArgumentCaptor<Map> configurationCaptor = ArgumentCaptor.forClass(Map.class);
|
||||
verify(this.filterContext).setValue(eq(RestDocumentationFilter.CONTEXT_KEY_CONFIGURATION),
|
||||
@@ -79,11 +80,11 @@ public class RestAssuredRestDocumentationConfigurerTests {
|
||||
assertThat(configuration.get(TemplateEngine.class.getName())).isInstanceOf(TemplateEngine.class);
|
||||
assertThat(configuration.get(WriterResolver.class.getName())).isInstanceOf(WriterResolver.class);
|
||||
assertThat(configuration.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS))
|
||||
.isInstanceOf(List.class);
|
||||
.isInstanceOf(List.class);
|
||||
assertThat(configuration.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR))
|
||||
.isInstanceOf(OperationRequestPreprocessor.class);
|
||||
.isInstanceOf(OperationRequestPreprocessor.class);
|
||||
assertThat(configuration.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR))
|
||||
.isInstanceOf(OperationResponsePreprocessor.class);
|
||||
.isInstanceOf(OperationResponsePreprocessor.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -90,8 +90,12 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void defaultSnippetGeneration() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("default")).get("/").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("default"))
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/default"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc");
|
||||
}
|
||||
@@ -99,9 +103,15 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
@Test
|
||||
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")
|
||||
.contentType(contentType).post("/").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("curl-snippet-with-content"))
|
||||
.accept("application/json")
|
||||
.body("content")
|
||||
.contentType(contentType)
|
||||
.post("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
|
||||
assertThat(new File("build/generated-snippets/curl-snippet-with-content/curl-request.adoc")).has(content(
|
||||
codeBlock(TemplateFormats.asciidoctor(), "bash").withContent(String.format("$ curl 'http://localhost:"
|
||||
@@ -112,9 +122,15 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
@Test
|
||||
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)
|
||||
.cookie("cookieName", "cookieVal").get("/").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("curl-snippet-with-cookies"))
|
||||
.accept("application/json")
|
||||
.contentType(contentType)
|
||||
.cookie("cookieName", "cookieVal")
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertThat(new File("build/generated-snippets/curl-snippet-with-cookies/curl-request.adoc")).has(content(
|
||||
codeBlock(TemplateFormats.asciidoctor(), "bash").withContent(String.format("$ curl 'http://localhost:"
|
||||
+ tomcat.getPort() + "/' -i -X GET \\%n" + " -H 'Accept: application/json' \\%n"
|
||||
@@ -123,91 +139,132 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
|
||||
@Test
|
||||
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);
|
||||
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);
|
||||
assertThat(
|
||||
new File("build/generated-snippets/curl-snippet-with-empty-parameter-query-string/curl-request.adoc"))
|
||||
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
|
||||
.withContent(String.format("$ curl 'http://localhost:" + tomcat.getPort()
|
||||
+ "/?a=' -i -X GET \\%n -H 'Accept: application/json'"))));
|
||||
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
|
||||
.withContent(String.format("$ curl 'http://localhost:" + tomcat.getPort()
|
||||
+ "/?a=' -i -X GET \\%n -H 'Accept: application/json'"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
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);
|
||||
String contentType = "application/x-www-form-urlencoded; charset=ISO-8859-1";
|
||||
assertThat(new File("build/generated-snippets/curl-snippet-with-query-string/curl-request.adoc"))
|
||||
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
|
||||
.withContent(String.format("$ curl " + "'http://localhost:" + tomcat.getPort()
|
||||
+ "/?foo=bar' -i -X POST \\%n" + " -H 'Accept: application/json' \\%n"
|
||||
+ " -H 'Content-Type: " + contentType + "' \\%n" + " -d 'a=alpha'"))));
|
||||
.has(content(codeBlock(TemplateFormats.asciidoctor(), "bash")
|
||||
.withContent(String.format("$ curl " + "'http://localhost:" + tomcat.getPort()
|
||||
+ "/?foo=bar' -i -X POST \\%n" + " -H 'Accept: application/json' \\%n"
|
||||
+ " -H 'Content-Type: " + contentType + "' \\%n" + " -d 'a=alpha'"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("links", links(linkWithRel("rel").description("The description"))))
|
||||
.accept("application/json")
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/links"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "links.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathParametersSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("path-parameters",
|
||||
pathParameters(parameterWithName("foo").description("The description"))))
|
||||
.accept("application/json").get("/{foo}", "").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("path-parameters",
|
||||
pathParameters(parameterWithName("foo").description("The description"))))
|
||||
.accept("application/json")
|
||||
.get("/{foo}", "")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/path-parameters"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "path-parameters.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestParametersSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("request-parameters",
|
||||
requestParameters(parameterWithName("foo").description("The description"))))
|
||||
.accept("application/json").param("foo", "bar").get("/").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("request-parameters",
|
||||
requestParameters(parameterWithName("foo").description("The description"))))
|
||||
.accept("application/json")
|
||||
.param("foo", "bar")
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/request-parameters"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "request-parameters.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
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);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/request-fields"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "request-fields.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
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);
|
||||
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);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/request-parts"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "request-parts.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseFieldsSnippet() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("response-fields",
|
||||
responseFields(fieldWithPath("a").description("The description"),
|
||||
subsectionWithPath("links").description("Links to other resources"))))
|
||||
.accept("application/json").get("/").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("response-fields",
|
||||
responseFields(fieldWithPath("a").description("The description"),
|
||||
subsectionWithPath("links").description("Links to other resources"))))
|
||||
.accept("application/json")
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/response-fields"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "response-fields.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parameterizedOutputDirectory() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("{method-name}")).get("/").then().statusCode(200);
|
||||
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"),
|
||||
"http-request.adoc", "http-response.adoc", "curl-request.adoc");
|
||||
}
|
||||
@@ -215,8 +272,9 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
@Test
|
||||
public void multiStep() {
|
||||
RequestSpecification spec = new RequestSpecBuilder().setPort(tomcat.getPort())
|
||||
.addFilter(documentationConfiguration(this.restDocumentation))
|
||||
.addFilter(document("{method-name}-{step}")).build();
|
||||
.addFilter(documentationConfiguration(this.restDocumentation))
|
||||
.addFilter(document("{method-name}-{step}"))
|
||||
.build();
|
||||
given(spec).get("/").then().statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/multi-step-1/"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc");
|
||||
@@ -232,106 +290,137 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
public void additionalSnippets() {
|
||||
RestDocumentationFilter documentation = document("{method-name}-{step}");
|
||||
RequestSpecification spec = new RequestSpecBuilder().setPort(tomcat.getPort())
|
||||
.addFilter(documentationConfiguration(this.restDocumentation)).addFilter(documentation).build();
|
||||
given(spec).filter(documentation.document(
|
||||
responseHeaders(headerWithName("a").description("one"), headerWithName("Foo").description("two"))))
|
||||
.get("/").then().statusCode(200);
|
||||
.addFilter(documentationConfiguration(this.restDocumentation))
|
||||
.addFilter(documentation)
|
||||
.build();
|
||||
given(spec)
|
||||
.filter(documentation.document(
|
||||
responseHeaders(headerWithName("a").description("one"), headerWithName("Foo").description("two"))))
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/additional-snippets-1/"),
|
||||
"http-request.adoc", "http-response.adoc", "curl-request.adoc", "response-headers.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseWithCookie() {
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("set-cookie",
|
||||
preprocessResponse(removeHeaders(HttpHeaders.DATE, HttpHeaders.CONTENT_TYPE))))
|
||||
.get("/set-cookie").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("set-cookie",
|
||||
preprocessResponse(removeHeaders(HttpHeaders.DATE, HttpHeaders.CONTENT_TYPE))))
|
||||
.get("/set-cookie")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/set-cookie"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc");
|
||||
assertThat(new File("build/generated-snippets/set-cookie/http-response.adoc"))
|
||||
.has(content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK).header(HttpHeaders.SET_COOKIE,
|
||||
"name=value; Domain=localhost; HttpOnly")));
|
||||
.has(content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK).header(HttpHeaders.SET_COOKIE,
|
||||
"name=value; Domain=localhost; HttpOnly")));
|
||||
}
|
||||
|
||||
@Test
|
||||
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")
|
||||
.body("{\"a\":\"alpha\"}").filter(document("original-request"))
|
||||
.filter(document("preprocessed-request",
|
||||
preprocessRequest(prettyPrint(), replacePattern(pattern, "\"<<beta>>\""),
|
||||
modifyUris().removePort(), removeHeaders("a", HttpHeaders.CONTENT_LENGTH))))
|
||||
.get("/").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.header("a", "alpha")
|
||||
.header("b", "bravo")
|
||||
.contentType("application/json")
|
||||
.accept("application/json")
|
||||
.body("{\"a\":\"alpha\"}")
|
||||
.filter(document("original-request"))
|
||||
.filter(document("preprocessed-request",
|
||||
preprocessRequest(prettyPrint(), replacePattern(pattern, "\"<<beta>>\""), modifyUris().removePort(),
|
||||
removeHeaders("a", HttpHeaders.CONTENT_LENGTH))))
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
assertThat(new File("build/generated-snippets/original-request/http-request.adoc"))
|
||||
.has(content(httpRequest(TemplateFormats.asciidoctor(), RequestMethod.GET, "/").header("a", "alpha")
|
||||
.header("b", "bravo").header("Accept", MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("Content-Type", "application/json; charset=UTF-8")
|
||||
.header("Host", "localhost:" + tomcat.getPort()).header("Content-Length", "13")
|
||||
.content("{\"a\":\"alpha\"}")));
|
||||
.has(content(httpRequest(TemplateFormats.asciidoctor(), RequestMethod.GET, "/").header("a", "alpha")
|
||||
.header("b", "bravo")
|
||||
.header("Accept", MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("Content-Type", "application/json; charset=UTF-8")
|
||||
.header("Host", "localhost:" + tomcat.getPort())
|
||||
.header("Content-Length", "13")
|
||||
.content("{\"a\":\"alpha\"}")));
|
||||
String prettyPrinted = String.format("{%n \"a\" : \"<<beta>>\"%n}");
|
||||
assertThat(new File("build/generated-snippets/preprocessed-request/http-request.adoc"))
|
||||
.has(content(httpRequest(TemplateFormats.asciidoctor(), RequestMethod.GET, "/").header("b", "bravo")
|
||||
.header("Accept", MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("Content-Type", "application/json; charset=UTF-8").header("Host", "localhost")
|
||||
.content(prettyPrinted)));
|
||||
.has(content(httpRequest(TemplateFormats.asciidoctor(), RequestMethod.GET, "/").header("b", "bravo")
|
||||
.header("Accept", MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("Content-Type", "application/json; charset=UTF-8")
|
||||
.header("Host", "localhost")
|
||||
.content(prettyPrinted)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPreprocessedRequest() {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation).operationPreprocessors().withRequestDefaults(
|
||||
prettyPrint(), replacePattern(pattern, "\"<<beta>>\""), modifyUris().removePort(),
|
||||
.filter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withRequestDefaults(prettyPrint(), replacePattern(pattern, "\"<<beta>>\""), modifyUris().removePort(),
|
||||
removeHeaders("a", HttpHeaders.CONTENT_LENGTH)))
|
||||
.header("a", "alpha").header("b", "bravo").contentType("application/json").accept("application/json")
|
||||
.body("{\"a\":\"alpha\"}").filter(document("default-preprocessed-request")).get("/").then()
|
||||
.statusCode(200);
|
||||
.header("a", "alpha")
|
||||
.header("b", "bravo")
|
||||
.contentType("application/json")
|
||||
.accept("application/json")
|
||||
.body("{\"a\":\"alpha\"}")
|
||||
.filter(document("default-preprocessed-request"))
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
String prettyPrinted = String.format("{%n \"a\" : \"<<beta>>\"%n}");
|
||||
assertThat(new File("build/generated-snippets/default-preprocessed-request/http-request.adoc"))
|
||||
.has(content(httpRequest(TemplateFormats.asciidoctor(), RequestMethod.GET, "/").header("b", "bravo")
|
||||
.header("Accept", MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("Content-Type", "application/json; charset=UTF-8").header("Host", "localhost")
|
||||
.content(prettyPrinted)));
|
||||
.has(content(httpRequest(TemplateFormats.asciidoctor(), RequestMethod.GET, "/").header("b", "bravo")
|
||||
.header("Accept", MediaType.APPLICATION_JSON_VALUE)
|
||||
.header("Content-Type", "application/json; charset=UTF-8")
|
||||
.header("Host", "localhost")
|
||||
.content(prettyPrinted)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preprocessedResponse() {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("original-response"))
|
||||
.filter(document("preprocessed-response",
|
||||
preprocessResponse(prettyPrint(), maskLinks(),
|
||||
removeHeaders("a", "Transfer-Encoding", "Date", "Server"),
|
||||
replacePattern(pattern, "\"<<beta>>\""),
|
||||
modifyUris().scheme("https").host("api.example.com").removePort())))
|
||||
.get("/").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("original-response"))
|
||||
.filter(document("preprocessed-response", preprocessResponse(prettyPrint(), maskLinks(),
|
||||
removeHeaders("a", "Transfer-Encoding", "Date", "Server"), replacePattern(pattern, "\"<<beta>>\""),
|
||||
modifyUris().scheme("https").host("api.example.com").removePort())))
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
String prettyPrinted = String.format("{%n \"a\" : \"<<beta>>\",%n \"links\" : "
|
||||
+ "[ {%n \"rel\" : \"rel\",%n \"href\" : \"...\"%n } ]%n}");
|
||||
assertThat(new File("build/generated-snippets/preprocessed-response/http-response.adoc"))
|
||||
.has(content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK)
|
||||
.header("Foo", "https://api.example.com/foo/bar")
|
||||
.header("Content-Type", "application/json;charset=UTF-8")
|
||||
.header(HttpHeaders.CONTENT_LENGTH, prettyPrinted.getBytes().length).content(prettyPrinted)));
|
||||
.has(content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK)
|
||||
.header("Foo", "https://api.example.com/foo/bar")
|
||||
.header("Content-Type", "application/json;charset=UTF-8")
|
||||
.header(HttpHeaders.CONTENT_LENGTH, prettyPrinted.getBytes().length)
|
||||
.content(prettyPrinted)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPreprocessedResponse() {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withResponseDefaults(prettyPrint(), maskLinks(),
|
||||
removeHeaders("a", "Transfer-Encoding", "Date", "Server"),
|
||||
replacePattern(pattern, "\"<<beta>>\""),
|
||||
modifyUris().scheme("https").host("api.example.com").removePort()))
|
||||
.filter(document("default-preprocessed-response")).get("/").then().statusCode(200);
|
||||
.filter(documentationConfiguration(this.restDocumentation).operationPreprocessors()
|
||||
.withResponseDefaults(prettyPrint(), maskLinks(),
|
||||
removeHeaders("a", "Transfer-Encoding", "Date", "Server"),
|
||||
replacePattern(pattern, "\"<<beta>>\""),
|
||||
modifyUris().scheme("https").host("api.example.com").removePort()))
|
||||
.filter(document("default-preprocessed-response"))
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
String prettyPrinted = String.format("{%n \"a\" : \"<<beta>>\",%n \"links\" : "
|
||||
+ "[ {%n \"rel\" : \"rel\",%n \"href\" : \"...\"%n } ]%n}");
|
||||
assertThat(new File("build/generated-snippets/default-preprocessed-response/http-response.adoc"))
|
||||
.has(content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK)
|
||||
.header("Foo", "https://api.example.com/foo/bar")
|
||||
.header("Content-Type", "application/json;charset=UTF-8")
|
||||
.header(HttpHeaders.CONTENT_LENGTH, prettyPrinted.getBytes().length).content(prettyPrinted)));
|
||||
.has(content(httpResponse(TemplateFormats.asciidoctor(), HttpStatus.OK)
|
||||
.header("Foo", "https://api.example.com/foo/bar")
|
||||
.header("Content-Type", "application/json;charset=UTF-8")
|
||||
.header(HttpHeaders.CONTENT_LENGTH, prettyPrinted.getBytes().length)
|
||||
.content(prettyPrinted)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -342,34 +431,39 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
ClassLoader previous = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
try {
|
||||
given().port(tomcat.getPort()).accept("application/json")
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("custom-snippet-template")).get("/").then().statusCode(200);
|
||||
given().port(tomcat.getPort())
|
||||
.accept("application/json")
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("custom-snippet-template"))
|
||||
.get("/")
|
||||
.then()
|
||||
.statusCode(200);
|
||||
}
|
||||
finally {
|
||||
Thread.currentThread().setContextClassLoader(previous);
|
||||
}
|
||||
assertThat(new File("build/generated-snippets/custom-snippet-template/curl-request.adoc"))
|
||||
.hasContent("Custom curl request");
|
||||
.hasContent("Custom curl request");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionShouldBeThrownWhenCallDocumentRequestSpecificationNotConfigured() {
|
||||
assertThatThrownBy(() -> given().port(tomcat.getPort()).filter(document("default")).get("/"))
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessage("REST Docs configuration not found. Did you forget to add a "
|
||||
+ "RestAssuredRestDocumentationConfigurer as a filter when building the RequestSpecification?");
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessage("REST Docs configuration not found. Did you forget to add a "
|
||||
+ "RestAssuredRestDocumentationConfigurer as a filter when building the RequestSpecification?");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void exceptionShouldBeThrownWhenCallDocumentSnippetsRequestSpecificationNotConfigured() {
|
||||
RestDocumentationFilter documentation = document("{method-name}-{step}");
|
||||
assertThatThrownBy(() -> given().port(tomcat.getPort())
|
||||
.filter(documentation.document(responseHeaders(headerWithName("a").description("one")))).get("/"))
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessage("REST Docs configuration not found. Did you forget to add a "
|
||||
+ "RestAssuredRestDocumentationConfigurer as a filter when building the "
|
||||
+ "RequestSpecification?");
|
||||
.filter(documentation.document(responseHeaders(headerWithName("a").description("one"))))
|
||||
.get("/"))
|
||||
.isInstanceOf(IllegalStateException.class)
|
||||
.hasMessage("REST Docs configuration not found. Did you forget to add a "
|
||||
+ "RestAssuredRestDocumentationConfigurer as a filter when building the "
|
||||
+ "RequestSpecification?");
|
||||
}
|
||||
|
||||
private void assertExpectedSnippetFilesExist(File directory, String... snippets) {
|
||||
@@ -385,7 +479,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
public boolean matches(File value) {
|
||||
try {
|
||||
return delegate.matches(FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileInputStream(value), StandardCharsets.UTF_8)));
|
||||
.copyToString(new InputStreamReader(new FileInputStream(value), StandardCharsets.UTF_8)));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
fail("Failed to read '" + value + "'", ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2023 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.
|
||||
@@ -70,7 +70,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriPortCanBeModified() {
|
||||
this.preprocessor.port(23456);
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com:23456"));
|
||||
assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST)).isEqualTo("api.example.com:23456");
|
||||
}
|
||||
@@ -79,7 +79,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriPortCanBeRemoved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com"));
|
||||
assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST)).isEqualTo("api.example.com");
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345/foo/bar"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345/foo/bar"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com/foo/bar"));
|
||||
}
|
||||
|
||||
@@ -96,7 +96,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345?foo=bar"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345?foo=bar"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com?foo=bar"));
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestUriAnchorIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345#foo"));
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345#foo"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com#foo"));
|
||||
}
|
||||
|
||||
@@ -112,7 +112,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestContentUriSchemeCanBeModified() {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'https://localhost:12345' should be used");
|
||||
}
|
||||
|
||||
@@ -120,16 +120,16 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestContentUriHostCanBeModified() {
|
||||
this.preprocessor.host("api.example.com");
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestContentUriPortCanBeModified() {
|
||||
this.preprocessor.port(23456);
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost:23456' should be used");
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestContentUriPortCanBeRemoved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost' should be used");
|
||||
}
|
||||
|
||||
@@ -147,14 +147,14 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor.preprocess(createRequestWithContent(
|
||||
"Use 'http://localhost:12345' or 'https://localhost:23456' to access the service"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("Use 'http://localhost' or 'https://localhost' to access the service");
|
||||
.isEqualTo("Use 'http://localhost' or 'https://localhost' to access the service");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestContentUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345/foo/bar' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345/foo/bar' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost/foo/bar' should be used");
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestContentUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345?foo=bar' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345?foo=bar' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost?foo=bar' should be used");
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestContentUriAnchorIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345#foo' should be used"));
|
||||
.preprocess(createRequestWithContent("The uri 'http://localhost:12345#foo' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost#foo' should be used");
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriSchemeCanBeModified() {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'https://localhost:12345' should be used");
|
||||
}
|
||||
|
||||
@@ -186,16 +186,16 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriHostCanBeModified() {
|
||||
this.preprocessor.host("api.example.com");
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriPortCanBeModified() {
|
||||
this.preprocessor.port(23456);
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost:23456' should be used");
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriPortCanBeRemoved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost' should be used");
|
||||
}
|
||||
|
||||
@@ -213,14 +213,14 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationResponse processed = this.preprocessor.preprocess(createResponseWithContent(
|
||||
"Use 'http://localhost:12345' or 'https://localhost:23456' to access the service"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("Use 'http://localhost' or 'https://localhost' to access the service");
|
||||
.isEqualTo("Use 'http://localhost' or 'https://localhost' to access the service");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345/foo/bar' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345/foo/bar' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost/foo/bar' should be used");
|
||||
}
|
||||
|
||||
@@ -228,7 +228,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345?foo=bar' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345?foo=bar' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost?foo=bar' should be used");
|
||||
}
|
||||
|
||||
@@ -236,14 +236,14 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriAnchorIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345#foo' should be used"));
|
||||
.preprocess(createResponseWithContent("The uri 'http://localhost:12345#foo' should be used"));
|
||||
assertThat(new String(processed.getContent())).isEqualTo("The uri 'http://localhost#foo' should be used");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urisInRequestHeadersCanBeModified() {
|
||||
OperationRequest processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createRequestWithHeader("Foo", "https://locahost:12345"));
|
||||
.preprocess(createRequestWithHeader("Foo", "https://locahost:12345"));
|
||||
assertThat(processed.getHeaders().getFirst("Foo")).isEqualTo("https://api.example.com:12345");
|
||||
assertThat(processed.getHeaders().getFirst("Host")).isEqualTo("api.example.com");
|
||||
}
|
||||
@@ -251,31 +251,31 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
@Test
|
||||
public void urisInResponseHeadersCanBeModified() {
|
||||
OperationResponse processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createResponseWithHeader("Foo", "https://locahost:12345"));
|
||||
.preprocess(createResponseWithHeader("Foo", "https://locahost:12345"));
|
||||
assertThat(processed.getHeaders().getFirst("Foo")).isEqualTo("https://api.example.com:12345");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urisInRequestPartHeadersCanBeModified() {
|
||||
OperationRequest processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createRequestWithPartWithHeader("Foo", "https://locahost:12345"));
|
||||
.preprocess(createRequestWithPartWithHeader("Foo", "https://locahost:12345"));
|
||||
assertThat(processed.getParts().iterator().next().getHeaders().getFirst("Foo"))
|
||||
.isEqualTo("https://api.example.com:12345");
|
||||
.isEqualTo("https://api.example.com:12345");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void urisInRequestPartContentCanBeModified() {
|
||||
OperationRequest processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createRequestWithPartWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
.preprocess(createRequestWithPartWithContent("The uri 'https://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getParts().iterator().next().getContent()))
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
.isEqualTo("The uri 'https://api.example.com:12345' should be used");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void modifiedUriDoesNotGetDoubleEncoded() {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("http://localhost:12345?foo=%7B%7D"));
|
||||
.preprocess(createRequestWithUri("http://localhost:12345?foo=%7B%7D"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://localhost:12345?foo=%7B%7D"));
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user