Merge branch '2.0.x'
Closes gh-829
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.headers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -41,7 +40,7 @@ public class RequestHeadersSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void missingRequestHeader() throws IOException {
|
||||
public void missingRequestHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestHeadersSnippet(Arrays.asList(headerWithName("Accept").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
@@ -49,7 +48,7 @@ public class RequestHeadersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestHeaderAndMissingRequestHeader() throws IOException {
|
||||
public void undocumentedRequestHeaderAndMissingRequestHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestHeadersSnippet(Arrays.asList(headerWithName("Accept").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").header("X-Test", "test").build()))
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.headers;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Rule;
|
||||
@@ -41,7 +40,7 @@ public class ResponseHeadersSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void missingResponseHeader() throws IOException {
|
||||
public void missingResponseHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new ResponseHeadersSnippet(Arrays.asList(headerWithName("Content-Type").description("one")))
|
||||
.document(this.operationBuilder.response().build()))
|
||||
@@ -49,7 +48,7 @@ public class ResponseHeadersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedResponseHeaderAndMissingResponseHeader() throws IOException {
|
||||
public void undocumentedResponseHeaderAndMissingResponseHeader() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new ResponseHeadersSnippet(Arrays.asList(headerWithName("Content-Type").description("one")))
|
||||
.document(this.operationBuilder.response().header("X-Test", "test").build()))
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.hypermedia;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -41,7 +40,7 @@ public class LinksSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedLink() throws IOException {
|
||||
public void undocumentedLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "bar")),
|
||||
Collections.<LinkDescriptor>emptyList()).document(this.operationBuilder.build()))
|
||||
@@ -49,7 +48,7 @@ public class LinksSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingLink() throws IOException {
|
||||
public void missingLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor(),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar")))
|
||||
@@ -58,7 +57,7 @@ public class LinksSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedLinkAndMissingLink() throws IOException {
|
||||
public void undocumentedLinkAndMissingLink() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("a", "alpha")),
|
||||
Arrays.asList(new LinkDescriptor("foo").description("bar")))
|
||||
@@ -68,7 +67,7 @@ public class LinksSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linkWithNoDescription() throws IOException {
|
||||
public void linkWithNoDescription() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new LinksSnippet(new StubLinkExtractor().withLinks(new Link("foo", "bar")),
|
||||
Arrays.asList(new LinkDescriptor("foo"))).document(this.operationBuilder.build()))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,7 +34,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class PatternReplacingContentModifierTests {
|
||||
|
||||
@Test
|
||||
public void patternsAreReplaced() throws Exception {
|
||||
public void patternsAreReplaced() {
|
||||
Pattern pattern = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(pattern, "<<uuid>>");
|
||||
@@ -44,7 +44,7 @@ public class PatternReplacingContentModifierTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void contentThatDoesNotMatchIsUnchanged() throws Exception {
|
||||
public void contentThatDoesNotMatchIsUnchanged() {
|
||||
Pattern pattern = Pattern.compile("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
|
||||
Pattern.CASE_INSENSITIVE);
|
||||
PatternReplacingContentModifier contentModifier = new PatternReplacingContentModifier(pattern, "<<uuid>>");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -39,13 +39,13 @@ public class PrettyPrintingContentModifierTests {
|
||||
public OutputCaptureRule outputCapture = new OutputCaptureRule();
|
||||
|
||||
@Test
|
||||
public void prettyPrintJson() throws Exception {
|
||||
public void prettyPrintJson() {
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent("{\"a\":5}".getBytes(), null))
|
||||
.isEqualTo(String.format("{%n \"a\" : 5%n}").getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void prettyPrintXml() throws Exception {
|
||||
public void prettyPrintXml() {
|
||||
assertThat(new PrettyPrintingContentModifier()
|
||||
.modifyContent("<one a=\"alpha\"><two b=\"bravo\"/></one>".getBytes(), null))
|
||||
.isEqualTo(String.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
|
||||
@@ -53,12 +53,12 @@ public class PrettyPrintingContentModifierTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void empytContentIsHandledGracefully() throws Exception {
|
||||
public void empytContentIsHandledGracefully() {
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent("".getBytes(), null)).isEqualTo("".getBytes());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonJsonAndNonXmlContentIsHandledGracefully() throws Exception {
|
||||
public void nonJsonAndNonXmlContentIsHandledGracefully() {
|
||||
String content = "abcdefg";
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null))
|
||||
.isEqualTo(content.getBytes());
|
||||
@@ -66,7 +66,7 @@ public class PrettyPrintingContentModifierTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonJsonContentThatInitiallyLooksLikeJsonIsHandledGracefully() throws Exception {
|
||||
public void nonJsonContentThatInitiallyLooksLikeJsonIsHandledGracefully() {
|
||||
String content = "\"abc\",\"def\"";
|
||||
assertThat(new PrettyPrintingContentModifier().modifyContent(content.getBytes(), null))
|
||||
.isEqualTo(content.getBytes());
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -99,8 +99,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractMapSubsectionWithVaryingStructureFromMultiElementArrayInAJsonMap()
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
public void extractMapSubsectionWithVaryingStructureFromMultiElementArrayInAJsonMap() {
|
||||
this.thrown.expect(PayloadHandlingException.class);
|
||||
this.thrown.expectMessage("The following non-optional uncommon paths were found: [a.[].b.d]");
|
||||
new FieldPathPayloadSubsectionExtractor("a.[].b").extractSubsection(
|
||||
@@ -108,8 +107,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMap()
|
||||
throws JsonParseException, JsonMappingException, IOException {
|
||||
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMap() {
|
||||
this.thrown.expect(PayloadHandlingException.class);
|
||||
this.thrown.expectMessage("The following non-optional uncommon paths were found: [*.d, *.d.e, *.d.f]");
|
||||
new FieldPathPayloadSubsectionExtractor("*.d").extractSubsection(
|
||||
@@ -117,8 +115,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMapWhereAllSubsectionFieldsAreOptional()
|
||||
throws IOException {
|
||||
public void extractMapSubsectionWithVaryingStructureFromInconsistentJsonMapWhereAllSubsectionFieldsAreOptional() {
|
||||
this.thrown.expect(PayloadHandlingException.class);
|
||||
this.thrown.expectMessage("The following non-optional uncommon paths were found: [*.d]");
|
||||
new FieldPathPayloadSubsectionExtractor("*.d").extractSubsection(
|
||||
@@ -176,7 +173,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractNonExistentSubsection() throws JsonParseException, JsonMappingException, IOException {
|
||||
public void extractNonExistentSubsection() {
|
||||
assertThatThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a.c")
|
||||
.extractSubsection("{\"a\":{\"b\":{\"c\":5}}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
@@ -184,7 +181,7 @@ public class FieldPathPayloadSubsectionExtractorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractEmptyArraySubsection() throws JsonParseException, JsonMappingException, IOException {
|
||||
public void extractEmptyArraySubsection() {
|
||||
assertThatThrownBy(() -> new FieldPathPayloadSubsectionExtractor("a")
|
||||
.extractSubsection("{\"a\":[]}}".getBytes(), MediaType.APPLICATION_JSON))
|
||||
.isInstanceOf(PayloadHandlingException.class)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -102,7 +101,7 @@ public class JsonContentHandlerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typeForFieldWithSometimesPresentOptionalAncestorCanBeProvidedExplicitly() throws IOException {
|
||||
public void typeForFieldWithSometimesPresentOptionalAncestorCanBeProvidedExplicitly() {
|
||||
FieldDescriptor descriptor = new FieldDescriptor("a.[].b.c").type(JsonFieldType.NUMBER);
|
||||
FieldDescriptor ancestor = new FieldDescriptor("a.[].b").optional();
|
||||
Object fieldType = new JsonContentHandler("{\"a\":[ { \"d\": 4}, {\"b\":{\"c\":5}, \"d\": 4}]}".getBytes(),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2019 the original author or authors.
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -306,7 +306,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void extractNestedEntryWithDotInKeys() throws IOException {
|
||||
public void extractNestedEntryWithDotInKeys() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a.key", alpha);
|
||||
@@ -316,7 +316,7 @@ public class JsonFieldProcessorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void extractNestedEntriesUsingTopLevelWildcard() throws IOException {
|
||||
public void extractNestedEntriesUsingTopLevelWildcard() {
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
Map<String, Object> alpha = new LinkedHashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -330,7 +330,7 @@ public class JsonFieldProcessorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void extractNestedEntriesUsingMidLevelWildcard() throws IOException {
|
||||
public void extractNestedEntriesUsingMidLevelWildcard() {
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
Map<String, Object> alpha = new LinkedHashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -344,7 +344,7 @@ public class JsonFieldProcessorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void extractUsingLeafWildcardMatchingSingleItem() throws IOException {
|
||||
public void extractUsingLeafWildcardMatchingSingleItem() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -357,7 +357,7 @@ public class JsonFieldProcessorTests {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void extractUsingLeafWildcardMatchingMultipleItems() throws IOException {
|
||||
public void extractUsingLeafWildcardMatchingMultipleItems() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -368,7 +368,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUsingLeafWildcard() throws IOException {
|
||||
public void removeUsingLeafWildcard() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -379,7 +379,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUsingTopLevelWildcard() throws IOException {
|
||||
public void removeUsingTopLevelWildcard() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> alpha = new HashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -390,7 +390,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeUsingMidLevelWildcard() throws IOException {
|
||||
public void removeUsingMidLevelWildcard() {
|
||||
Map<String, Object> payload = new LinkedHashMap<>();
|
||||
Map<String, Object> alpha = new LinkedHashMap<>();
|
||||
payload.put("a", alpha);
|
||||
@@ -407,28 +407,28 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsTrueForNonNullFieldInMap() throws Exception {
|
||||
public void hasFieldIsTrueForNonNullFieldInMap() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("a", "alpha");
|
||||
assertThat(this.fieldProcessor.hasField("a", payload)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsTrueForNullFieldInMap() throws Exception {
|
||||
public void hasFieldIsTrueForNullFieldInMap() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("a", null);
|
||||
assertThat(this.fieldProcessor.hasField("a", payload)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsFalseForAbsentFieldInMap() throws Exception {
|
||||
public void hasFieldIsFalseForAbsentFieldInMap() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
payload.put("a", null);
|
||||
assertThat(this.fieldProcessor.hasField("b", payload)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsTrueForNeverNullFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsTrueForNeverNullFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("b", "bravo");
|
||||
@@ -437,7 +437,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsTrueForAlwaysNullFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsTrueForAlwaysNullFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("b", null);
|
||||
@@ -446,7 +446,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsFalseForAlwaysAbsentFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsFalseForAlwaysAbsentFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("b", "bravo");
|
||||
@@ -455,7 +455,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsFalseForOccasionallyAbsentFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsFalseForOccasionallyAbsentFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> nested = new HashMap<>();
|
||||
nested.put("b", "bravo");
|
||||
@@ -464,7 +464,7 @@ public class JsonFieldProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hasFieldIsFalseForOccasionallyNullFieldBeneathArray() throws Exception {
|
||||
public void hasFieldIsFalseForOccasionallyNullFieldBeneathArray() {
|
||||
Map<String, Object> payload = new HashMap<>();
|
||||
Map<String, Object> fieldPresent = new HashMap<>();
|
||||
fieldPresent.put("b", "bravo");
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -44,7 +43,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestField() throws IOException {
|
||||
public void undocumentedRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost").content("{\"a\": 5}").build()))
|
||||
@@ -52,7 +51,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingRequestField() throws IOException {
|
||||
public void missingRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").content("{}").build()))
|
||||
@@ -60,14 +59,14 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingOptionalRequestFieldWithNoTypeProvided() throws IOException {
|
||||
public void missingOptionalRequestFieldWithNoTypeProvided() {
|
||||
assertThatExceptionOfType(FieldTypeRequiredException.class).isThrownBy(
|
||||
() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one").optional()))
|
||||
.document(this.operationBuilder.request("http://localhost").content("{ }").build()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestFieldAndMissingRequestField() throws IOException {
|
||||
public void undocumentedRequestFieldAndMissingRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one"))).document(
|
||||
this.operationBuilder.request("http://localhost").content("{ \"a\": { \"c\": 5 }}").build()))
|
||||
@@ -76,7 +75,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void attemptToDocumentFieldsWithNoRequestBody() throws IOException {
|
||||
public void attemptToDocumentFieldsWithNoRequestBody() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
@@ -84,7 +83,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldWithExplicitTypeThatDoesNotMatchThePayload() throws IOException {
|
||||
public void fieldWithExplicitTypeThatDoesNotMatchThePayload() {
|
||||
assertThatExceptionOfType(FieldTypesDoNotMatchException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a").description("one").type(JsonFieldType.OBJECT))).document(
|
||||
@@ -93,7 +92,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldWithExplicitSpecificTypeThatActuallyVaries() throws IOException {
|
||||
public void fieldWithExplicitSpecificTypeThatActuallyVaries() {
|
||||
assertThatExceptionOfType(FieldTypesDoNotMatchException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("[].a").description("one").type(JsonFieldType.OBJECT)))
|
||||
@@ -103,7 +102,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedXmlRequestField() throws IOException {
|
||||
public void undocumentedXmlRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost").content("<a><b>5</b></a>")
|
||||
@@ -112,7 +111,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlDescendentsAreNotDocumentedByFieldDescriptor() throws IOException {
|
||||
public void xmlDescendentsAreNotDocumentedByFieldDescriptor() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(
|
||||
() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").type("a").description("one")))
|
||||
@@ -122,7 +121,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlRequestFieldWithNoType() throws IOException {
|
||||
public void xmlRequestFieldWithNoType() {
|
||||
assertThatExceptionOfType(FieldTypeRequiredException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").content("<a>5</a>")
|
||||
@@ -130,7 +129,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingXmlRequestField() throws IOException {
|
||||
public void missingXmlRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a/b").description("one"), fieldWithPath("a").description("one")))
|
||||
@@ -140,7 +139,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedXmlRequestFieldAndMissingXmlRequestField() throws IOException {
|
||||
public void undocumentedXmlRequestFieldAndMissingXmlRequestField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a/b").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").content("<a><c>5</c></a>")
|
||||
@@ -150,7 +149,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsupportedContent() throws IOException {
|
||||
public void unsupportedContent() {
|
||||
assertThatExceptionOfType(PayloadHandlingException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost").content("Some plain text")
|
||||
@@ -159,7 +158,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesNull() throws IOException {
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesNull() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a[].b").description("one").type(JsonFieldType.NUMBER),
|
||||
@@ -172,7 +171,7 @@ public class RequestFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesAbsent() throws IOException {
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesAbsent() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a[].b").description("one").type(JsonFieldType.NUMBER),
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -43,7 +42,7 @@ public class RequestPartFieldsSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedRequestPartField() throws IOException {
|
||||
public void undocumentedRequestPartField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestPartFieldsSnippet("part", Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost")
|
||||
@@ -52,7 +51,7 @@ public class RequestPartFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingRequestPartField() throws IOException {
|
||||
public void missingRequestPartField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(
|
||||
() -> new RequestPartFieldsSnippet("part", Arrays.asList(fieldWithPath("b").description("one")))
|
||||
@@ -62,7 +61,7 @@ public class RequestPartFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingRequestPart() throws IOException {
|
||||
public void missingRequestPart() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new RequestPartFieldsSnippet("another", Arrays.asList(fieldWithPath("a.b").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost")
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.payload;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -44,7 +43,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void attemptToDocumentFieldsWithNoResponseBody() throws IOException {
|
||||
public void attemptToDocumentFieldsWithNoResponseBody() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")))
|
||||
.document(this.operationBuilder.build()))
|
||||
@@ -52,7 +51,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldWithExplicitTypeThatDoesNotMatchThePayload() throws IOException {
|
||||
public void fieldWithExplicitTypeThatDoesNotMatchThePayload() {
|
||||
assertThatExceptionOfType(FieldTypesDoNotMatchException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a").description("one").type(JsonFieldType.OBJECT)))
|
||||
@@ -61,7 +60,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fieldWithExplicitSpecificTypeThatActuallyVaries() throws IOException {
|
||||
public void fieldWithExplicitSpecificTypeThatActuallyVaries() {
|
||||
assertThatExceptionOfType(FieldTypesDoNotMatchException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("[].a").description("one").type(JsonFieldType.OBJECT))).document(
|
||||
@@ -70,7 +69,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedXmlResponseField() throws IOException {
|
||||
public void undocumentedXmlResponseField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.response().content("<a><b>5</b></a>")
|
||||
@@ -79,7 +78,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingXmlAttribute() throws IOException {
|
||||
public void missingXmlAttribute() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(
|
||||
() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one").type("b"),
|
||||
@@ -93,7 +92,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void documentedXmlAttributesAreRemoved() throws IOException {
|
||||
public void documentedXmlAttributesAreRemoved() {
|
||||
assertThatExceptionOfType(SnippetException.class).isThrownBy(
|
||||
() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a/@id").description("one").type("a")))
|
||||
.document(this.operationBuilder.response().content("<a id=\"foo\">bar</a>")
|
||||
@@ -102,7 +101,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void xmlResponseFieldWithNoType() throws IOException {
|
||||
public void xmlResponseFieldWithNoType() {
|
||||
assertThatExceptionOfType(FieldTypeRequiredException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a").description("one")))
|
||||
.document(this.operationBuilder.response().content("<a>5</a>")
|
||||
@@ -110,7 +109,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingXmlResponseField() throws IOException {
|
||||
public void missingXmlResponseField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a/b").description("one"), fieldWithPath("a").description("one")))
|
||||
@@ -120,7 +119,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedXmlResponseFieldAndMissingXmlResponseField() throws IOException {
|
||||
public void undocumentedXmlResponseFieldAndMissingXmlResponseField() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a/b").description("one")))
|
||||
.document(this.operationBuilder.response().content("<a><c>5</c></a>")
|
||||
@@ -130,7 +129,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unsupportedContent() throws IOException {
|
||||
public void unsupportedContent() {
|
||||
assertThatExceptionOfType(PayloadHandlingException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(Collections.<FieldDescriptor>emptyList())
|
||||
.document(this.operationBuilder.response().content("Some plain text")
|
||||
@@ -139,7 +138,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesNull() throws IOException {
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesNull() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a[].b").description("one").type(JsonFieldType.NUMBER),
|
||||
@@ -152,7 +151,7 @@ public class ResponseFieldsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesAbsent() throws IOException {
|
||||
public void nonOptionalFieldBeneathArrayThatIsSometimesAbsent() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new ResponseFieldsSnippet(
|
||||
Arrays.asList(fieldWithPath("a[].b").description("one").type(JsonFieldType.NUMBER),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2021 the original author or authors.
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.request;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -43,7 +42,7 @@ public class PathParametersSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedPathParameter() throws IOException {
|
||||
public void undocumentedPathParameter() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new PathParametersSnippet(Collections.<ParameterDescriptor>emptyList())
|
||||
.document(this.operationBuilder
|
||||
@@ -52,7 +51,7 @@ public class PathParametersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingPathParameter() throws IOException {
|
||||
public void missingPathParameter() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one")))
|
||||
.document(this.operationBuilder
|
||||
@@ -61,7 +60,7 @@ public class PathParametersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedAndMissingPathParameters() throws IOException {
|
||||
public void undocumentedAndMissingPathParameters() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one")))
|
||||
.document(this.operationBuilder
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.request;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -42,7 +41,7 @@ public class RequestParametersSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedParameter() throws IOException {
|
||||
public void undocumentedParameter() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestParametersSnippet(Collections.<ParameterDescriptor>emptyList())
|
||||
.document(this.operationBuilder.request("http://localhost").param("a", "alpha").build()))
|
||||
@@ -50,7 +49,7 @@ public class RequestParametersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingParameter() throws IOException {
|
||||
public void missingParameter() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestParametersSnippet(Arrays.asList(parameterWithName("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
@@ -58,7 +57,7 @@ public class RequestParametersSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedAndMissingParameters() throws IOException {
|
||||
public void undocumentedAndMissingParameters() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestParametersSnippet(Arrays.asList(parameterWithName("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").param("b", "bravo").build()))
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.springframework.restdocs.request;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -42,7 +41,7 @@ public class RequestPartsSnippetFailureTests {
|
||||
public OperationBuilder operationBuilder = new OperationBuilder(TemplateFormats.asciidoctor());
|
||||
|
||||
@Test
|
||||
public void undocumentedPart() throws IOException {
|
||||
public void undocumentedPart() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestPartsSnippet(Collections.<RequestPartDescriptor>emptyList()).document(
|
||||
this.operationBuilder.request("http://localhost").part("a", "alpha".getBytes()).build()))
|
||||
@@ -50,7 +49,7 @@ public class RequestPartsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void missingPart() throws IOException {
|
||||
public void missingPart() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestPartsSnippet(Arrays.asList(partWithName("a").description("one")))
|
||||
.document(this.operationBuilder.request("http://localhost").build()))
|
||||
@@ -58,7 +57,7 @@ public class RequestPartsSnippetFailureTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void undocumentedAndMissingParts() throws IOException {
|
||||
public void undocumentedAndMissingParts() {
|
||||
assertThatExceptionOfType(SnippetException.class)
|
||||
.isThrownBy(() -> new RequestPartsSnippet(Arrays.asList(partWithName("a").description("one"))).document(
|
||||
this.operationBuilder.request("http://localhost").part("b", "bravo".getBytes()).build()))
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2020 the original author or authors.
|
||||
* Copyright 2014-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,79 +33,79 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class RestDocumentationContextPlaceholderResolverTests {
|
||||
|
||||
@Test
|
||||
public void kebabCaseMethodName() throws Exception {
|
||||
public void kebabCaseMethodName() {
|
||||
assertThat(createResolver("dashSeparatedMethodName").resolvePlaceholder("method-name"))
|
||||
.isEqualTo("dash-separated-method-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kebabCaseMethodNameWithUpperCaseOpeningSection() throws Exception {
|
||||
public void kebabCaseMethodNameWithUpperCaseOpeningSection() {
|
||||
assertThat(createResolver("URIDashSeparatedMethodName").resolvePlaceholder("method-name"))
|
||||
.isEqualTo("uri-dash-separated-method-name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kebabCaseMethodNameWithUpperCaseMidSection() throws Exception {
|
||||
public void kebabCaseMethodNameWithUpperCaseMidSection() {
|
||||
assertThat(createResolver("dashSeparatedMethodNameWithURIInIt").resolvePlaceholder("method-name"))
|
||||
.isEqualTo("dash-separated-method-name-with-uri-in-it");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kebabCaseMethodNameWithUpperCaseEndSection() throws Exception {
|
||||
public void kebabCaseMethodNameWithUpperCaseEndSection() {
|
||||
assertThat(createResolver("dashSeparatedMethodNameWithURI").resolvePlaceholder("method-name"))
|
||||
.isEqualTo("dash-separated-method-name-with-uri");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseMethodName() throws Exception {
|
||||
public void snakeCaseMethodName() {
|
||||
assertThat(createResolver("underscoreSeparatedMethodName").resolvePlaceholder("method_name"))
|
||||
.isEqualTo("underscore_separated_method_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseMethodNameWithUpperCaseOpeningSection() throws Exception {
|
||||
public void snakeCaseMethodNameWithUpperCaseOpeningSection() {
|
||||
assertThat(createResolver("URIUnderscoreSeparatedMethodName").resolvePlaceholder("method_name"))
|
||||
.isEqualTo("uri_underscore_separated_method_name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseMethodNameWithUpperCaseMidSection() throws Exception {
|
||||
public void snakeCaseMethodNameWithUpperCaseMidSection() {
|
||||
assertThat(createResolver("underscoreSeparatedMethodNameWithURIInIt").resolvePlaceholder("method_name"))
|
||||
.isEqualTo("underscore_separated_method_name_with_uri_in_it");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseMethodNameWithUpperCaseEndSection() throws Exception {
|
||||
public void snakeCaseMethodNameWithUpperCaseEndSection() {
|
||||
assertThat(createResolver("underscoreSeparatedMethodNameWithURI").resolvePlaceholder("method_name"))
|
||||
.isEqualTo("underscore_separated_method_name_with_uri");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void camelCaseMethodName() throws Exception {
|
||||
public void camelCaseMethodName() {
|
||||
assertThat(createResolver("camelCaseMethodName").resolvePlaceholder("methodName"))
|
||||
.isEqualTo("camelCaseMethodName");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kebabCaseClassName() throws Exception {
|
||||
public void kebabCaseClassName() {
|
||||
assertThat(createResolver().resolvePlaceholder("class-name"))
|
||||
.isEqualTo("rest-documentation-context-placeholder-resolver-tests");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void snakeCaseClassName() throws Exception {
|
||||
public void snakeCaseClassName() {
|
||||
assertThat(createResolver().resolvePlaceholder("class_name"))
|
||||
.isEqualTo("rest_documentation_context_placeholder_resolver_tests");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void camelCaseClassName() throws Exception {
|
||||
public void camelCaseClassName() {
|
||||
assertThat(createResolver().resolvePlaceholder("ClassName"))
|
||||
.isEqualTo("RestDocumentationContextPlaceholderResolverTests");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void stepCount() throws Exception {
|
||||
public void stepCount() {
|
||||
assertThat(createResolver("stepCount").resolvePlaceholder("step")).isEqualTo("1");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.restdocs.templates;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -41,7 +42,7 @@ public class StandardTemplateResourceResolverTests {
|
||||
private final TestClassLoader classLoader = new TestClassLoader();
|
||||
|
||||
@Test
|
||||
public void formatSpecificCustomSnippetHasHighestPrecedence() throws Exception {
|
||||
public void formatSpecificCustomSnippetHasHighestPrecedence() throws IOException {
|
||||
this.classLoader.addResource("org/springframework/restdocs/templates/asciidoctor/test.snippet",
|
||||
getClass().getResource("test-format-specific-custom.snippet"));
|
||||
this.classLoader.addResource("org/springframework/restdocs/templates/test.snippet",
|
||||
@@ -61,7 +62,7 @@ public class StandardTemplateResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generalCustomSnippetIsUsedInAbsenceOfFormatSpecificCustomSnippet() throws Exception {
|
||||
public void generalCustomSnippetIsUsedInAbsenceOfFormatSpecificCustomSnippet() throws IOException {
|
||||
this.classLoader.addResource("org/springframework/restdocs/templates/test.snippet",
|
||||
getClass().getResource("test-custom.snippet"));
|
||||
this.classLoader.addResource("org/springframework/restdocs/templates/asciidoctor/default-test.snippet",
|
||||
@@ -95,19 +96,22 @@ public class StandardTemplateResourceResolverTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void failsIfCustomAndDefaultSnippetsDoNotExist() throws Exception {
|
||||
public void failsIfCustomAndDefaultSnippetsDoNotExist() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> doWithThreadContextClassLoader(this.classLoader,
|
||||
() -> StandardTemplateResourceResolverTests.this.resolver.resolveTemplateResource("test")))
|
||||
.withMessage("Template named 'test' could not be resolved");
|
||||
}
|
||||
|
||||
private <T> T doWithThreadContextClassLoader(ClassLoader classLoader, Callable<T> action) throws Exception {
|
||||
private <T> T doWithThreadContextClassLoader(ClassLoader classLoader, Callable<T> action) {
|
||||
ClassLoader previous = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(classLoader);
|
||||
try {
|
||||
return action.call();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
finally {
|
||||
Thread.currentThread().setContextClassLoader(previous);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user