Merge branch '1.2.x'

This commit is contained in:
Andy Wilkinson
2017-09-23 17:20:55 +01:00
36 changed files with 88 additions and 53 deletions

View File

@@ -103,7 +103,6 @@ final class CliOperationRequest implements OperationRequest {
}
}
return true;
}
@Override

View File

@@ -44,14 +44,12 @@ final class ConcatenatingCommandFormatter implements CommandFormatter {
if (CollectionUtils.isEmpty(elements)) {
return "";
}
StringBuilder result = new StringBuilder();
for (String element : elements) {
result.append(String.format(this.separator));
result.append(element);
}
return result.toString();
}
}

View File

@@ -161,7 +161,6 @@ public class CurlRequestSnippet extends TemplatedSnippet {
private void writePartsIfNecessary(OperationRequest request, List<String> lines) {
for (OperationRequestPart part : request.getParts()) {
StringBuilder oneLine = new StringBuilder();
oneLine.append(String.format("-F '%s=", part.getName()));
if (!StringUtils.hasText(part.getSubmittedFileName())) {
@@ -174,7 +173,6 @@ public class CurlRequestSnippet extends TemplatedSnippet {
oneLine.append(";type=");
oneLine.append(part.getHeaders().getContentType().toString());
}
oneLine.append("'");
lines.add(oneLine.toString());
}

View File

@@ -214,4 +214,5 @@ public class HttpieRequestSnippet extends TemplatedSnippet {
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,4 +31,5 @@ interface NestedConfigurer<PARENT> {
* @return the parent
*/
PARENT and();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ package org.springframework.restdocs.constraints;
* Resolves a description for a {@link Constraint}.
*
* @author Andy Wilkinson
*
*/
public interface ConstraintDescriptionResolver {
@@ -31,4 +30,5 @@ public interface ConstraintDescriptionResolver {
* @return the description
*/
String resolveDescription(Constraint constraint);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,4 +77,5 @@ public class ValidatorConstraintResolver implements ConstraintResolver {
}
return constraints;
}
}

View File

@@ -30,7 +30,6 @@ import org.springframework.restdocs.operation.OperationResponse;
* content type.
*
* @author Andy Wilkinson
*
*/
class ContentTypeLinkExtractor implements LinkExtractor {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -472,4 +472,5 @@ public abstract class HypermediaDocumentation {
public static LinkExtractor atomLinks() {
return new AtomLinkExtractor();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,4 +66,5 @@ class HeaderRemovingOperationPreprocessor implements OperationPreprocessor {
}
return processedHeaders;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -141,7 +141,9 @@ public class PrettyPrintingContentModifier implements ContentModifier {
public void fatalError(SAXParseException exception) throws SAXException {
// Suppress
}
}
}
private static final class JsonPrettyPrinter implements PrettyPrinter {
@@ -154,6 +156,7 @@ public class PrettyPrintingContentModifier implements ContentModifier {
return this.objectMapper
.writeValueAsBytes(this.objectMapper.readTree(original));
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,4 +34,5 @@ public class FieldTypeRequiredException extends RuntimeException {
public FieldTypeRequiredException(String message) {
super(message);
}
}

View File

@@ -124,15 +124,18 @@ final class JsonFieldPath {
return segments;
}
/**
* The type of a field path.
*/
static enum PathType {
/**
* The path identifies a single item in the payload
* The path identifies a single item in the payload.
*/
SINGLE,
/**
* The path identifies multiple items in the payload
* The path identifies multiple items in the payload.
*/
MULTI;

View File

@@ -327,13 +327,13 @@ final class JsonFieldProcessor {
}
private static class LeafCollectionMatch implements Match {
private static final class LeafCollectionMatch implements Match {
private final Collection<?> collection;
private final Match parent;
public LeafCollectionMatch(Collection<?> collection, Match parent) {
private LeafCollectionMatch(Collection<?> collection, Match parent) {
this.collection = collection;
this.parent = parent;
}
@@ -387,6 +387,7 @@ final class JsonFieldProcessor {
void remove();
void removeSubsection();
}
private static final class ProcessingContext {
@@ -432,8 +433,12 @@ final class JsonFieldProcessor {
return new ProcessingContext(payload, this.path,
this.segments.subList(1, this.segments.size()), match);
}
}
/**
* A field that has been extracted from a JSON payload.
*/
static class ExtractedField {
private final Object value;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -66,4 +66,5 @@ public enum JsonFieldType {
public String toString() {
return StringUtils.capitalize(this.name().toLowerCase(Locale.ENGLISH));
}
}

View File

@@ -77,4 +77,5 @@ class JsonFieldTypeResolver {
}
return JsonFieldType.NUMBER;
}
}

View File

@@ -289,7 +289,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
}
@Test
@@ -303,9 +303,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -319,8 +319,8 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -335,9 +335,9 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
}
@Test
@@ -349,7 +349,7 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils
.encodeToString("user:secret".getBytes()))
.build());
.build());
}
@Test
@@ -393,4 +393,5 @@ public class CurlRequestSnippetTests extends AbstractSnippetTests {
.request("http://localhost/foo").param("a", "alpha").method("POST")
.param("b", "bravo").content("Some content").build());
}
}

View File

@@ -47,7 +47,6 @@ import static org.springframework.restdocs.snippet.Attributes.key;
* @author Paul-Christian Volkmer
* @author Raman Gupta
* @author Tomasz Kopczynski
*
*/
@RunWith(Parameterized.class)
public class HttpieRequestSnippetTests extends AbstractSnippetTests {
@@ -288,7 +287,7 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
}
@Test
@@ -302,9 +301,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.header(HttpHeaders.CONTENT_TYPE, MediaType.IMAGE_PNG_VALUE)
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -317,8 +316,8 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").build());
}
@Test
@@ -332,9 +331,9 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
this.operationBuilder.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.MULTIPART_FORM_DATA_VALUE)
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
.part("image", new byte[0])
.submittedFileName("documents/images/example.png").and()
.param("a", "apple", "avocado").param("b", "banana").build());
}
@Test
@@ -346,7 +345,7 @@ public class HttpieRequestSnippetTests extends AbstractSnippetTests {
.header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64Utils
.encodeToString("user:secret".getBytes()))
.build());
.build());
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -102,6 +102,7 @@ public class ValidatorConstraintResolverTests {
@CompositeConstraint
private String composite;
}
@ConstraintComposition(CompositionType.OR)
@@ -158,5 +159,7 @@ public class ValidatorConstraintResolverTests {
description.appendText("Constraint named " + this.annotation.getName()
+ " with configuration " + this.configuration);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,4 +77,5 @@ public class ContentTypeLinkExtractorTests {
new ContentTypeLinkExtractor(extractors).extractLinks(response);
verify(extractor).extractLinks(response);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -121,4 +121,5 @@ public class LinkExtractorsPayloadTests {
return new File("src/test/resources/link-payloads/" + this.linkType + "/" + name
+ ".json");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -88,4 +88,5 @@ public class QueryStringParserTests {
.expectMessage(equalTo("The parameter 'a=apple=avocado' is malformed"));
this.queryStringParser.parse(URI.create("http://localhost?a=apple=avocado"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,4 +57,5 @@ public class DelegatingOperationResponsePreprocessorTests {
assertThat(result, is(preprocessedResponse3));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -155,4 +155,5 @@ public class LinkMaskingContentModifierTests {
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,7 +56,7 @@ public class PrettyPrintingContentModifierTests {
equalTo(String
.format("<?xml version=\"1.0\" encoding=\"UTF-8\"?>%n"
+ "<one a=\"alpha\">%n <two b=\"bravo\"/>%n</one>%n")
.getBytes()));
.getBytes()));
}
@Test
@@ -85,4 +85,5 @@ public class PrettyPrintingContentModifierTests {
objectMapper.writeValueAsBytes(input), null), Map.class);
assertThat(output, is(equalTo(input)));
}
}

View File

@@ -510,4 +510,5 @@ public class JsonFieldProcessorTests {
entry.put(key, value);
return entry;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -103,6 +103,7 @@ public final class MockMvcRestDocumentationConfigurer extends
context);
return request;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -46,4 +46,5 @@ public final class MockMvcSnippetConfigurer extends
ConfigurableMockMvcBuilder<?> builder, WebApplicationContext context) {
return and().beforeMockMvcCreated(builder, context);
}
}

View File

@@ -85,6 +85,7 @@ public class RestDocumentationResultHandler implements ResultHandler {
getDelegate().handle(result.getRequest(), result.getResponse(),
configuration);
}
};
}
@@ -96,4 +97,5 @@ public class RestDocumentationResultHandler implements ResultHandler {
protected final RestDocumentationGenerator<MockHttpServletRequest, MockHttpServletResponse> getDelegate() {
return this.delegate;
}
}

View File

@@ -70,4 +70,5 @@ public class MockMvcResponseConverterTests {
assertThat(operationResponse.getHeaders().get(HttpHeaders.SET_COOKIE), equalTo(
Collections.singletonList("name=value; Domain=localhost; HttpOnly")));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2015 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -157,4 +157,5 @@ public class RestDocumentationRequestBuildersTests {
assertThat(request.getRequestURI(), is(equalTo("/uri")));
assertThat(request.getMethod(), is(equalTo(httpMethod.name())));
}
}

View File

@@ -165,4 +165,5 @@ class RestAssuredRequestConverter
}
return parts;
}
}

View File

@@ -65,4 +65,5 @@ public final class RestAssuredRestDocumentationConfigurer extends
apply(configuration, context);
return filterContext.next(requestSpec, responseSpec);
}
}

View File

@@ -249,5 +249,7 @@ public final class UriModifyingOperationPreprocessor implements OperationPreproc
}
return "";
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -85,4 +85,5 @@ public class RestAssuredRestDocumentationConfigurerTests {
equalTo(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_SNIPPETS),
instanceOf(List.class)));
}
}

View File

@@ -121,6 +121,7 @@ class TomcatServer extends ExternalResource {
resp.addCookie(cookie);
}
}
}