Merge branch '1.2.x'
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -62,105 +62,84 @@ public class RestAssuredRequestConverterTests {
|
||||
public void requestUri() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort());
|
||||
requestSpec.get("/foo/bar");
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getUri()).isEqualTo(
|
||||
URI.create("http://localhost:" + tomcat.getPort() + "/foo/bar"));
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getUri()).isEqualTo(URI.create("http://localhost:" + tomcat.getPort() + "/foo/bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestMethod() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort());
|
||||
requestSpec.head("/foo/bar");
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getMethod()).isEqualTo(HttpMethod.HEAD);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryStringParameters() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort())
|
||||
.queryParam("foo", "bar");
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).queryParam("foo", "bar");
|
||||
requestSpec.get("/");
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParameters()).hasSize(1);
|
||||
assertThat(request.getParameters()).containsEntry("foo",
|
||||
Collections.singletonList("bar"));
|
||||
assertThat(request.getParameters()).containsEntry("foo", Collections.singletonList("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void queryStringFromUrlParameters() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort());
|
||||
requestSpec.get("/?foo=bar&foo=qix");
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParameters()).hasSize(1);
|
||||
assertThat(request.getParameters()).containsEntry("foo",
|
||||
Arrays.asList("bar", "qix"));
|
||||
assertThat(request.getParameters()).containsEntry("foo", Arrays.asList("bar", "qix"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void formParameters() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort())
|
||||
.formParam("foo", "bar");
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).formParam("foo", "bar");
|
||||
requestSpec.get("/");
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParameters()).hasSize(1);
|
||||
assertThat(request.getParameters()).containsEntry("foo",
|
||||
Collections.singletonList("bar"));
|
||||
assertThat(request.getParameters()).containsEntry("foo", Collections.singletonList("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestParameters() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort())
|
||||
.param("foo", "bar");
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).param("foo", "bar");
|
||||
requestSpec.get("/");
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParameters()).hasSize(1);
|
||||
assertThat(request.getParameters()).containsEntry("foo",
|
||||
Collections.singletonList("bar"));
|
||||
assertThat(request.getParameters()).containsEntry("foo", Collections.singletonList("bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void headers() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort())
|
||||
.header("Foo", "bar");
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).header("Foo", "bar");
|
||||
requestSpec.get("/");
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getHeaders()).hasSize(2);
|
||||
assertThat(request.getHeaders()).containsEntry("Foo",
|
||||
Collections.singletonList("bar"));
|
||||
assertThat(request.getHeaders()).containsEntry("Foo", Collections.singletonList("bar"));
|
||||
assertThat(request.getHeaders()).containsEntry("Host",
|
||||
Collections.singletonList("localhost:" + tomcat.getPort()));
|
||||
}
|
||||
|
||||
@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);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getHeaders()).hasSize(3);
|
||||
assertThat(request.getHeaders()).containsEntry("Foo",
|
||||
Collections.singletonList("bar"));
|
||||
assertThat(request.getHeaders()).containsEntry("Accept",
|
||||
Collections.singletonList("application/json"));
|
||||
assertThat(request.getHeaders()).containsEntry("Foo", Collections.singletonList("bar"));
|
||||
assertThat(request.getHeaders()).containsEntry("Accept", Collections.singletonList("application/json"));
|
||||
assertThat(request.getHeaders()).containsEntry("Host",
|
||||
Collections.singletonList("localhost:" + tomcat.getPort()));
|
||||
}
|
||||
|
||||
@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);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getCookies().size()).isEqualTo(2);
|
||||
|
||||
Iterator<RequestCookie> cookieIterator = request.getCookies().iterator();
|
||||
@@ -177,115 +156,94 @@ 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");
|
||||
.multiPart("a", "a.txt", "alpha", null).multiPart("b", new ObjectBody("bar"), "application/json");
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
Collection<OperationRequestPart> parts = request.getParts();
|
||||
assertThat(parts).hasSize(2);
|
||||
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("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));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byteArrayBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().body("body".getBytes())
|
||||
.port(tomcat.getPort());
|
||||
RequestSpecification requestSpec = RestAssured.given().body("body".getBytes()).port(tomcat.getPort());
|
||||
requestSpec.post();
|
||||
this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stringBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().body("body")
|
||||
.port(tomcat.getPort());
|
||||
RequestSpecification requestSpec = RestAssured.given().body("body").port(tomcat.getPort());
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getContentAsString()).isEqualTo("body");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void objectBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().body(new ObjectBody("bar"))
|
||||
.port(tomcat.getPort());
|
||||
RequestSpecification requestSpec = RestAssured.given().body(new ObjectBody("bar")).port(tomcat.getPort());
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getContentAsString()).isEqualTo("{\"foo\":\"bar\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void byteArrayInputStreamBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given()
|
||||
.body(new ByteArrayInputStream(new byte[] { 1, 2, 3, 4 }))
|
||||
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);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getContent()).isEqualTo(new byte[] { 1, 2, 3, 4 });
|
||||
}
|
||||
|
||||
@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);
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getContentAsString()).isEqualTo("file");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fileInputStreamBody() throws FileNotFoundException {
|
||||
FileInputStream inputStream = new FileInputStream("src/test/resources/body.txt");
|
||||
RequestSpecification requestSpec = RestAssured.given().body(inputStream)
|
||||
.port(tomcat.getPort());
|
||||
RequestSpecification requestSpec = RestAssured.given().body(inputStream).port(tomcat.getPort());
|
||||
requestSpec.post();
|
||||
this.thrown.expect(IllegalStateException.class);
|
||||
this.thrown.expectMessage("Cannot read content from input stream " + inputStream
|
||||
+ " due to reset() failure");
|
||||
this.thrown.expectMessage("Cannot read content from input stream " + inputStream + " due to reset() failure");
|
||||
this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
}
|
||||
|
||||
@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");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipartWithStringBody() {
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort())
|
||||
.multiPart("control", "foo");
|
||||
RequestSpecification requestSpec = RestAssured.given().port(tomcat.getPort()).multiPart("control", "foo");
|
||||
requestSpec.post();
|
||||
OperationRequest request = this.factory
|
||||
.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString())
|
||||
.isEqualTo("foo");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@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");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -293,39 +251,34 @@ public class RestAssuredRequestConverterTests {
|
||||
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");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("file");
|
||||
}
|
||||
|
||||
@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");
|
||||
this.thrown.expectMessage("Cannot read content from input stream " + inputStream + " due to reset() failure");
|
||||
this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
}
|
||||
|
||||
@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\"}");
|
||||
OperationRequest request = this.factory.convert((FilterableRequestSpecification) requestSpec);
|
||||
assertThat(request.getParts().iterator().next().getContentAsString()).isEqualTo("{\"foo\":\"bar\"}");
|
||||
}
|
||||
|
||||
/**
|
||||
* Sample object body to verify JSON serialization.
|
||||
*/
|
||||
static class ObjectBody {
|
||||
public static class ObjectBody {
|
||||
|
||||
private final String foo;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -50,11 +50,9 @@ public class RestAssuredRestDocumentationConfigurerTests {
|
||||
@Rule
|
||||
public final JUnitRestDocumentation restDocumentation = new JUnitRestDocumentation();
|
||||
|
||||
private final FilterableRequestSpecification requestSpec = mock(
|
||||
FilterableRequestSpecification.class);
|
||||
private final FilterableRequestSpecification requestSpec = mock(FilterableRequestSpecification.class);
|
||||
|
||||
private final FilterableResponseSpecification responseSpec = mock(
|
||||
FilterableResponseSpecification.class);
|
||||
private final FilterableResponseSpecification responseSpec = mock(FilterableResponseSpecification.class);
|
||||
|
||||
private final FilterContext filterContext = mock(FilterContext.class);
|
||||
|
||||
@@ -69,30 +67,23 @@ public class RestAssuredRestDocumentationConfigurerTests {
|
||||
|
||||
@Test
|
||||
public void configurationIsAddedToTheContext() {
|
||||
this.configurer.operationPreprocessors()
|
||||
.withRequestDefaults(Preprocessors.prettyPrint())
|
||||
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),
|
||||
verify(this.filterContext).setValue(eq(RestDocumentationFilter.CONTEXT_KEY_CONFIGURATION),
|
||||
configurationCaptor.capture());
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> configuration = configurationCaptor.getValue();
|
||||
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);
|
||||
assertThat(configuration.get(
|
||||
RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR))
|
||||
.isInstanceOf(OperationRequestPreprocessor.class);
|
||||
assertThat(configuration.get(
|
||||
RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR))
|
||||
.isInstanceOf(OperationResponsePreprocessor.class);
|
||||
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);
|
||||
assertThat(configuration.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_REQUEST_PREPROCESSOR))
|
||||
.isInstanceOf(OperationRequestPreprocessor.class);
|
||||
assertThat(configuration.get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR))
|
||||
.isInstanceOf(OperationResponsePreprocessor.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2018 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -88,156 +88,113 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void defaultSnippetGeneration() {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
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");
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/default"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithContent() throws Exception {
|
||||
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:"
|
||||
+ tomcat.getPort() + "/' -i -X POST \\%n"
|
||||
+ " -H 'Accept: application/json' \\%n"
|
||||
+ " -H 'Content-Type: " + contentType
|
||||
+ "' \\%n" + " -d 'content'"))));
|
||||
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:"
|
||||
+ tomcat.getPort() + "/' -i -X POST \\%n" + " -H 'Accept: application/json' \\%n"
|
||||
+ " -H 'Content-Type: " + contentType + "' \\%n" + " -d 'content'"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithCookies() throws Exception {
|
||||
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);
|
||||
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"
|
||||
+ " -H 'Content-Type: " + contentType
|
||||
+ "' \\%n"
|
||||
+ " --cookie 'cookieName=cookieVal'"))));
|
||||
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"
|
||||
+ " -H 'Content-Type: " + contentType + "' \\%n" + " --cookie 'cookieName=cookieVal'"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void curlSnippetWithQueryStringOnPost() throws Exception {
|
||||
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'"))));
|
||||
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'"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linksSnippet() throws Exception {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("links",
|
||||
links(linkWithRel("rel").description("The description"))))
|
||||
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");
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/links"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "links.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pathParametersSnippet() throws Exception {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("path-parameters",
|
||||
pathParameters(
|
||||
parameterWithName("foo").description("The description"))))
|
||||
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",
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/path-parameters"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "path-parameters.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestParametersSnippet() throws Exception {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
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");
|
||||
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() throws Exception {
|
||||
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",
|
||||
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() throws Exception {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("request-parts",
|
||||
requestParts(partWithName("a").description("The description"))))
|
||||
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",
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/request-parts"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "request-parts.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseFieldsSnippet() throws Exception {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
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"))))
|
||||
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",
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/response-fields"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc", "response-fields.adoc");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parameterizedOutputDirectory() throws Exception {
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
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"),
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/parameterized-output-directory"),
|
||||
"http-request.adoc", "http-response.adoc", "curl-request.adoc");
|
||||
}
|
||||
|
||||
@@ -247,16 +204,13 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
.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",
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/multi-step-1/"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc");
|
||||
given(spec).get("/").then().statusCode(200);
|
||||
assertExpectedSnippetFilesExist(
|
||||
new File("build/generated-snippets/multi-step-2/"), "http-request.adoc",
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/multi-step-2/"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc");
|
||||
given(spec).get("/").then().statusCode(200);
|
||||
assertExpectedSnippetFilesExist(
|
||||
new File("build/generated-snippets/multi-step-3/"), "http-request.adoc",
|
||||
assertExpectedSnippetFilesExist(new File("build/generated-snippets/multi-step-3/"), "http-request.adoc",
|
||||
"http-response.adoc", "curl-request.adoc");
|
||||
}
|
||||
|
||||
@@ -264,172 +218,125 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
public void additionalSnippets() throws Exception {
|
||||
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"))))
|
||||
.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");
|
||||
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))
|
||||
given().port(tomcat.getPort()).filter(documentationConfiguration(this.restDocumentation))
|
||||
.filter(document("set-cookie",
|
||||
preprocessResponse(removeHeaders(HttpHeaders.DATE,
|
||||
HttpHeaders.CONTENT_TYPE))))
|
||||
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");
|
||||
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() throws Exception {
|
||||
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"))
|
||||
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))))
|
||||
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\"}")));
|
||||
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\"}")));
|
||||
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)));
|
||||
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)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPreprocessedRequest() throws Exception {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort())
|
||||
.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()
|
||||
.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);
|
||||
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)));
|
||||
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)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void preprocessedResponse() throws Exception {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation))
|
||||
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())))
|
||||
.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)));
|
||||
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)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void defaultPreprocessedResponse() throws Exception {
|
||||
Pattern pattern = Pattern.compile("(\"alpha\")");
|
||||
given().port(tomcat.getPort())
|
||||
.filter(documentationConfiguration(this.restDocumentation)
|
||||
.operationPreprocessors().withResponseDefaults(prettyPrint(),
|
||||
maskLinks(),
|
||||
.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);
|
||||
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)));
|
||||
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)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void customSnippetTemplate() throws Exception {
|
||||
ClassLoader classLoader = new URLClassLoader(new URL[] {
|
||||
new File("src/test/resources/custom-snippet-templates").toURI().toURL() },
|
||||
ClassLoader classLoader = new URLClassLoader(
|
||||
new URL[] { new File("src/test/resources/custom-snippet-templates").toURI().toURL() },
|
||||
getClass().getClassLoader());
|
||||
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);
|
||||
.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");
|
||||
assertThat(new File("build/generated-snippets/custom-snippet-template/curl-request.adoc"))
|
||||
.hasContent("Custom curl request");
|
||||
}
|
||||
|
||||
private void assertExpectedSnippetFilesExist(File directory, String... snippets) {
|
||||
@@ -444,9 +351,8 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
@Override
|
||||
public boolean matches(File value) {
|
||||
try {
|
||||
return delegate
|
||||
.matches(FileCopyUtils.copyToString(new InputStreamReader(
|
||||
new FileInputStream(value), StandardCharsets.UTF_8)));
|
||||
return delegate.matches(FileCopyUtils
|
||||
.copyToString(new InputStreamReader(new FileInputStream(value), StandardCharsets.UTF_8)));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
fail("Failed to read '" + value + "'", ex);
|
||||
@@ -461,8 +367,7 @@ public class RestAssuredRestDocumentationIntegrationTests {
|
||||
return SnippetConditions.codeBlock(format, language);
|
||||
}
|
||||
|
||||
private HttpRequestCondition httpRequest(TemplateFormat format,
|
||||
RequestMethod requestMethod, String uri) {
|
||||
private HttpRequestCondition httpRequest(TemplateFormat format, RequestMethod requestMethod, String uri) {
|
||||
return SnippetConditions.httpRequest(format, requestMethod, uri);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2017 the original author or authors.
|
||||
* Copyright 2014-2019 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.
|
||||
@@ -89,8 +89,7 @@ class TomcatServer extends ExternalResource {
|
||||
respondWithJson(response);
|
||||
}
|
||||
|
||||
private void respondWithJson(HttpServletResponse response)
|
||||
throws IOException, JsonProcessingException {
|
||||
private void respondWithJson(HttpServletResponse response) throws IOException, JsonProcessingException {
|
||||
response.setCharacterEncoding("UTF-8");
|
||||
response.setContentType("application/json");
|
||||
Map<String, Object> content = new HashMap<>();
|
||||
@@ -113,8 +112,7 @@ class TomcatServer extends ExternalResource {
|
||||
private static final class CookiesServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
|
||||
throws ServletException, IOException {
|
||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
Cookie cookie = new Cookie("name", "value");
|
||||
cookie.setDomain("localhost");
|
||||
cookie.setHttpOnly(true);
|
||||
|
||||
@@ -54,20 +54,16 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
@Test
|
||||
public void requestUriSchemeCanBeModified() {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("http://localhost:12345"));
|
||||
OperationRequest processed = this.preprocessor.preprocess(createRequestWithUri("http://localhost:12345"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://localhost:12345"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestUriHostCanBeModified() {
|
||||
this.preprocessor.host("api.example.com");
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.foo.com:12345"));
|
||||
assertThat(processed.getUri())
|
||||
.isEqualTo(URI.create("https://api.example.com:12345"));
|
||||
assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST))
|
||||
.isEqualTo("api.example.com:12345");
|
||||
OperationRequest processed = this.preprocessor.preprocess(createRequestWithUri("https://api.foo.com:12345"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com:12345"));
|
||||
assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST)).isEqualTo("api.example.com:12345");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,10 +71,8 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
this.preprocessor.port(23456);
|
||||
OperationRequest processed = this.preprocessor
|
||||
.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");
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com:23456"));
|
||||
assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST)).isEqualTo("api.example.com:23456");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,26 +81,23 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
OperationRequest processed = this.preprocessor
|
||||
.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");
|
||||
assertThat(processed.getHeaders().getFirst(HttpHeaders.HOST)).isEqualTo("api.example.com");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor.preprocess(
|
||||
createRequestWithUri("https://api.example.com:12345/foo/bar"));
|
||||
assertThat(processed.getUri())
|
||||
.isEqualTo(URI.create("https://api.example.com/foo/bar"));
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345/foo/bar"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com/foo/bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor.preprocess(
|
||||
createRequestWithUri("https://api.example.com:12345?foo=bar"));
|
||||
assertThat(processed.getUri())
|
||||
.isEqualTo(URI.create("https://api.example.com?foo=bar"));
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345?foo=bar"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com?foo=bar"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,26 +105,22 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("https://api.example.com:12345#foo"));
|
||||
assertThat(processed.getUri())
|
||||
.isEqualTo(URI.create("https://api.example.com#foo"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://api.example.com#foo"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestContentUriSchemeCanBeModified() {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent(
|
||||
"The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'https://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");
|
||||
}
|
||||
|
||||
@Test
|
||||
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");
|
||||
}
|
||||
@@ -142,78 +129,64 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void requestContentUriPortCanBeModified() {
|
||||
this.preprocessor.port(23456);
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent(
|
||||
"The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'http://localhost:23456' 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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestContentUriPortCanBeRemoved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithContent(
|
||||
"The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'http://localhost' 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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleRequestContentUrisCanBeModified() {
|
||||
this.preprocessor.removePort();
|
||||
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");
|
||||
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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestContentUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.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");
|
||||
.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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestContentUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.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");
|
||||
.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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void requestContentUriAnchorIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationRequest processed = this.preprocessor
|
||||
.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");
|
||||
.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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriSchemeCanBeModified() {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent(
|
||||
"The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'https://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");
|
||||
}
|
||||
|
||||
@Test
|
||||
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");
|
||||
}
|
||||
@@ -222,68 +195,56 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void responseContentUriPortCanBeModified() {
|
||||
this.preprocessor.port(23456);
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent(
|
||||
"The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'http://localhost:23456' 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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriPortCanBeRemoved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.preprocess(createResponseWithContent(
|
||||
"The uri 'http://localhost:12345' should be used"));
|
||||
assertThat(new String(processed.getContent()))
|
||||
.isEqualTo("The uri 'http://localhost' 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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleResponseContentUrisCanBeModified() {
|
||||
this.preprocessor.removePort();
|
||||
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");
|
||||
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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriPathIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.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");
|
||||
.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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriQueryIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.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");
|
||||
.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");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseContentUriAnchorIsPreserved() {
|
||||
this.preprocessor.removePort();
|
||||
OperationResponse processed = this.preprocessor
|
||||
.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");
|
||||
.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"));
|
||||
assertThat(processed.getHeaders().getFirst("Foo"))
|
||||
.isEqualTo("https://api.example.com:12345");
|
||||
assertThat(processed.getHeaders().getFirst("Foo")).isEqualTo("https://api.example.com:12345");
|
||||
assertThat(processed.getHeaders().getFirst("Host")).isEqualTo("api.example.com");
|
||||
}
|
||||
|
||||
@@ -291,14 +252,13 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
public void urisInResponseHeadersCanBeModified() {
|
||||
OperationResponse processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createResponseWithHeader("Foo", "https://locahost:12345"));
|
||||
assertThat(processed.getHeaders().getFirst("Foo"))
|
||||
.isEqualTo("https://api.example.com: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"));
|
||||
OperationRequest processed = this.preprocessor.host("api.example.com")
|
||||
.preprocess(createRequestWithPartWithHeader("Foo", "https://locahost:12345"));
|
||||
assertThat(processed.getParts().iterator().next().getHeaders().getFirst("Foo"))
|
||||
.isEqualTo("https://api.example.com:12345");
|
||||
}
|
||||
@@ -306,8 +266,7 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
@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");
|
||||
}
|
||||
@@ -317,61 +276,53 @@ public class UriModifyingOperationPreprocessorTests {
|
||||
this.preprocessor.scheme("https");
|
||||
OperationRequest processed = this.preprocessor
|
||||
.preprocess(createRequestWithUri("http://localhost:12345?foo=%7B%7D"));
|
||||
assertThat(processed.getUri())
|
||||
.isEqualTo(URI.create("https://localhost:12345?foo=%7B%7D"));
|
||||
assertThat(processed.getUri()).isEqualTo(URI.create("https://localhost:12345?foo=%7B%7D"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resultingRequestHasCookiesFromOriginalRequst() {
|
||||
List<RequestCookie> cookies = Arrays.asList(new RequestCookie("a", "alpha"));
|
||||
OperationRequest request = this.requestFactory.create(
|
||||
URI.create("http://localhost:12345"), HttpMethod.GET, new byte[0],
|
||||
new HttpHeaders(), new Parameters(),
|
||||
Collections.<OperationRequestPart>emptyList(), cookies);
|
||||
OperationRequest request = this.requestFactory.create(URI.create("http://localhost:12345"), HttpMethod.GET,
|
||||
new byte[0], new HttpHeaders(), new Parameters(), Collections.<OperationRequestPart>emptyList(),
|
||||
cookies);
|
||||
OperationRequest processed = this.preprocessor.preprocess(request);
|
||||
assertThat(processed.getCookies().size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
private OperationRequest createRequestWithUri(String uri) {
|
||||
return this.requestFactory.create(URI.create(uri), HttpMethod.GET, new byte[0],
|
||||
new HttpHeaders(), new Parameters(),
|
||||
Collections.<OperationRequestPart>emptyList());
|
||||
return this.requestFactory.create(URI.create(uri), HttpMethod.GET, new byte[0], new HttpHeaders(),
|
||||
new Parameters(), Collections.<OperationRequestPart>emptyList());
|
||||
}
|
||||
|
||||
private OperationRequest createRequestWithContent(String content) {
|
||||
return this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET,
|
||||
content.getBytes(), new HttpHeaders(), new Parameters(),
|
||||
Collections.<OperationRequestPart>emptyList());
|
||||
return this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET, content.getBytes(),
|
||||
new HttpHeaders(), new Parameters(), Collections.<OperationRequestPart>emptyList());
|
||||
}
|
||||
|
||||
private OperationRequest createRequestWithHeader(String name, String value) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add(name, value);
|
||||
return this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET,
|
||||
new byte[0], headers, new Parameters(),
|
||||
Collections.<OperationRequestPart>emptyList());
|
||||
return this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET, new byte[0], headers,
|
||||
new Parameters(), Collections.<OperationRequestPart>emptyList());
|
||||
}
|
||||
|
||||
private OperationRequest createRequestWithPartWithHeader(String name, String value) {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.add(name, value);
|
||||
return this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET,
|
||||
new byte[0], new HttpHeaders(), new Parameters(),
|
||||
Arrays.asList(new OperationRequestPartFactory().create("part", "fileName",
|
||||
new byte[0], headers)));
|
||||
return this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET, new byte[0],
|
||||
new HttpHeaders(), new Parameters(),
|
||||
Arrays.asList(new OperationRequestPartFactory().create("part", "fileName", new byte[0], headers)));
|
||||
}
|
||||
|
||||
private OperationRequest createRequestWithPartWithContent(String content) {
|
||||
return this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET,
|
||||
new byte[0], new HttpHeaders(), new Parameters(),
|
||||
Arrays.asList(new OperationRequestPartFactory().create("part", "fileName",
|
||||
content.getBytes(), new HttpHeaders())));
|
||||
return this.requestFactory.create(URI.create("http://localhost"), HttpMethod.GET, new byte[0],
|
||||
new HttpHeaders(), new Parameters(), Arrays.asList(new OperationRequestPartFactory().create("part",
|
||||
"fileName", content.getBytes(), new HttpHeaders())));
|
||||
}
|
||||
|
||||
private OperationResponse createResponseWithContent(String content) {
|
||||
return this.responseFactory.create(HttpStatus.OK, new HttpHeaders(),
|
||||
content.getBytes());
|
||||
return this.responseFactory.create(HttpStatus.OK, new HttpHeaders(), content.getBytes());
|
||||
}
|
||||
|
||||
private OperationResponse createResponseWithHeader(String name, String value) {
|
||||
|
||||
Reference in New Issue
Block a user