From c0fac14fdf1f7628e83b24e93023357768009671 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Fri, 5 Feb 2016 21:15:33 +0000 Subject: [PATCH] Break cycle caused by introduction of RestDocumentationHandler --- ...RestDocumentationGenerationException.java} | 8 +++--- .../RestDocumentationGenerator.java} | 28 +++++++++---------- .../restdocs/generate/package-info.java | 21 ++++++++++++++ ...a => RestDocumentationGeneratorTests.java} | 15 +++++----- .../mockmvc/MockMvcRestDocumentation.java | 10 +++---- .../RestDocumentationResultHandler.java | 6 ++-- .../RestAssuredRestDocumentation.java | 10 +++---- .../restassured/RestDocumentationFilter.java | 6 ++-- 8 files changed, 63 insertions(+), 41 deletions(-) rename spring-restdocs-core/src/main/java/org/springframework/restdocs/{RestDocumentationException.java => generate/RestDocumentationGenerationException.java} (80%) rename spring-restdocs-core/src/main/java/org/springframework/restdocs/{RestDocumentationHandler.java => generate/RestDocumentationGenerator.java} (89%) create mode 100644 spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/package-info.java rename spring-restdocs-core/src/test/java/org/springframework/restdocs/{RestDocumentationHandlerTests.java => RestDocumentationGeneratorTests.java} (90%) diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/RestDocumentationException.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerationException.java similarity index 80% rename from spring-restdocs-core/src/main/java/org/springframework/restdocs/RestDocumentationException.java rename to spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerationException.java index 5bdf27c1..e1e76d8c 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/RestDocumentationException.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerationException.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.restdocs; +package org.springframework.restdocs.generate; /** * An exception that can be thrown when a failure occurs during REST documentation @@ -22,14 +22,14 @@ package org.springframework.restdocs; * * @author Andy Wilkinson */ -public class RestDocumentationException extends RuntimeException { +public class RestDocumentationGenerationException extends RuntimeException { /** * Creates a new {@code RestDocumentationException} with the given {@code cause}. * * @param cause the cause */ - public RestDocumentationException(Throwable cause) { + public RestDocumentationGenerationException(Throwable cause) { super(cause); } @@ -40,7 +40,7 @@ public class RestDocumentationException extends RuntimeException { * @param message the message * @param cause the cause */ - public RestDocumentationException(String message, Throwable cause) { + public RestDocumentationGenerationException(String message, Throwable cause) { super(message, cause); } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/RestDocumentationHandler.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerator.java similarity index 89% rename from spring-restdocs-core/src/main/java/org/springframework/restdocs/RestDocumentationHandler.java rename to spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerator.java index f8be483b..b60f5d9f 100644 --- a/spring-restdocs-core/src/main/java/org/springframework/restdocs/RestDocumentationHandler.java +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/RestDocumentationGenerator.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.restdocs; +package org.springframework.restdocs.generate; import java.io.IOException; import java.util.ArrayList; @@ -36,14 +36,14 @@ import org.springframework.restdocs.snippet.Snippet; import org.springframework.util.Assert; /** - * A {@code RestDocumentationHandler} is used to produce documentation snippets from the - * request and response of an operation performed on a service. + * A {@code RestDocumentationGenerator} is used to generate documentation snippets from + * the request and response of an operation performed on a service. * * @param the request type that can be handled * @param the response type that can be handled * @author Andy Wilkinson */ -public final class RestDocumentationHandler { +public final class RestDocumentationGenerator { private final String identifier; @@ -58,7 +58,7 @@ public final class RestDocumentationHandler { private final ResponseConverter responseConverter; /** - * Creates a new {@code RestDocumentationHandler} for the operation identified by the + * Creates a new {@code RestDocumentationGenerator} for the operation identified by the * given {@code identifier}. The given {@code requestConverter} and * {@code responseConverter} are used to convert the operation's request and response * into generic {@code OperationRequest} and {@code OperationResponse} instances that @@ -69,7 +69,7 @@ public final class RestDocumentationHandler { * @param responseConverter the response converter * @param snippets the snippets */ - public RestDocumentationHandler(String identifier, + public RestDocumentationGenerator(String identifier, RequestConverter requestConverter, ResponseConverter responseConverter, Snippet... snippets) { this(identifier, requestConverter, responseConverter, @@ -78,7 +78,7 @@ public final class RestDocumentationHandler { } /** - * Creates a new {@code RestDocumentationHandler} for the operation identified by the + * Creates a new {@code RestDocumentationGenerator} for the operation identified by the * given {@code identifier}. The given {@code requestConverter} and * {@code responseConverter} are used to convert the operation's request and response * into generic {@code OperationRequest} and {@code OperationResponse} instances that @@ -92,7 +92,7 @@ public final class RestDocumentationHandler { * @param requestPreprocessor the request preprocessor * @param snippets the snippets */ - public RestDocumentationHandler(String identifier, + public RestDocumentationGenerator(String identifier, RequestConverter requestConverter, ResponseConverter responseConverter, OperationRequestPreprocessor requestPreprocessor, Snippet... snippets) { @@ -101,7 +101,7 @@ public final class RestDocumentationHandler { } /** - * Creates a new {@code RestDocumentationHandler} for the operation identified by the + * Creates a new {@code RestDocumentationGenerator} for the operation identified by the * given {@code identifier}. The given {@code requestConverter} and * {@code responseConverter} are used to convert the operation's request and response * into generic {@code OperationRequest} and {@code OperationResponse} instances that @@ -115,7 +115,7 @@ public final class RestDocumentationHandler { * @param responsePreprocessor the response preprocessor * @param snippets the snippets */ - public RestDocumentationHandler(String identifier, + public RestDocumentationGenerator(String identifier, RequestConverter requestConverter, ResponseConverter responseConverter, OperationResponsePreprocessor responsePreprocessor, Snippet... snippets) { @@ -125,7 +125,7 @@ public final class RestDocumentationHandler { } /** - * Creates a new {@code RestDocumentationHandler} for the operation identified by the + * Creates a new {@code RestDocumentationGenerator} for the operation identified by the * given {@code identifier}. The given {@code requestConverter} and * {@code responseConverter} are used to convert the operation's request and response * into generic {@code OperationRequest} and {@code OperationResponse} instances that @@ -140,7 +140,7 @@ public final class RestDocumentationHandler { * @param responsePreprocessor the response preprocessor * @param snippets the snippets */ - public RestDocumentationHandler(String identifier, + public RestDocumentationGenerator(String identifier, RequestConverter requestConverter, ResponseConverter responseConverter, OperationRequestPreprocessor requestPreprocessor, @@ -167,7 +167,7 @@ public final class RestDocumentationHandler { * @param request the request * @param response the request * @param configuration the configuration - * @throws RestDocumentationException if a failure occurs during handling + * @throws RestDocumentationGenerationException if a failure occurs during handling */ public void handle(REQ request, RESP response, Map configuration) { OperationRequest operationRequest = this.requestPreprocessor @@ -184,7 +184,7 @@ public final class RestDocumentationHandler { } } catch (IOException ex) { - throw new RestDocumentationException(ex); + throw new RestDocumentationGenerationException(ex); } } diff --git a/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/package-info.java b/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/package-info.java new file mode 100644 index 00000000..6b6ba863 --- /dev/null +++ b/spring-restdocs-core/src/main/java/org/springframework/restdocs/generate/package-info.java @@ -0,0 +1,21 @@ +/* + * Copyright 2014-2015 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Classes that drive the generation of the documentaiton snippets. + */ +package org.springframework.restdocs.generate; + diff --git a/spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationHandlerTests.java b/spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationGeneratorTests.java similarity index 90% rename from spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationHandlerTests.java rename to spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationGeneratorTests.java index abfdafa5..d03aa6da 100644 --- a/spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationHandlerTests.java +++ b/spring-restdocs-core/src/test/java/org/springframework/restdocs/RestDocumentationGeneratorTests.java @@ -26,6 +26,7 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.springframework.http.HttpHeaders; import org.springframework.restdocs.config.SnippetConfigurer; +import org.springframework.restdocs.generate.RestDocumentationGenerator; import org.springframework.restdocs.operation.Operation; import org.springframework.restdocs.operation.OperationRequest; import org.springframework.restdocs.operation.OperationRequestFactory; @@ -43,11 +44,11 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; /** - * Tests for {@link RestDocumentationHandler}. + * Tests for {@link RestDocumentationGenerator}. * * @author Andy Wilkinson */ -public class RestDocumentationHandlerTests { +public class RestDocumentationGeneratorTests { @SuppressWarnings("unchecked") private final RequestConverter requestConverter = mock(RequestConverter.class); @@ -75,7 +76,7 @@ public class RestDocumentationHandlerTests { given(this.responseConverter.convert(this.response)).willReturn( this.operationResponse); HashMap configuration = new HashMap<>(); - new RestDocumentationHandler<>("id", this.requestConverter, + new RestDocumentationGenerator<>("id", this.requestConverter, this.responseConverter, this.snippet).handle(this.request, this.response, configuration); verifySnippetInvocation(this.snippet, configuration); @@ -92,7 +93,7 @@ public class RestDocumentationHandlerTests { Snippet defaultSnippet2 = mock(Snippet.class); configuration.put(SnippetConfigurer.ATTRIBUTE_DEFAULT_SNIPPETS, Arrays.asList(defaultSnippet1, defaultSnippet2)); - new RestDocumentationHandler<>("id", this.requestConverter, + new RestDocumentationGenerator<>("id", this.requestConverter, this.responseConverter, this.snippet).handle(this.request, this.response, configuration); verifySnippetInvocation(this.snippet, configuration); @@ -108,11 +109,11 @@ public class RestDocumentationHandlerTests { this.operationResponse); Snippet additionalSnippet1 = mock(Snippet.class); Snippet additionalSnippet2 = mock(Snippet.class); - RestDocumentationHandler handler = new RestDocumentationHandler<>( + RestDocumentationGenerator generator = new RestDocumentationGenerator<>( "id", this.requestConverter, this.responseConverter, this.snippet); - handler.addSnippets(additionalSnippet1, additionalSnippet2); + generator.addSnippets(additionalSnippet1, additionalSnippet2); HashMap configuration = new HashMap<>(); - handler.handle(this.request, this.response, configuration); + generator.handle(this.request, this.response, configuration); verifySnippetInvocation(this.snippet, configuration); verifySnippetInvocation(additionalSnippet1, configuration); verifySnippetInvocation(additionalSnippet2, configuration); diff --git a/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentation.java b/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentation.java index 64825f7e..cf1840cb 100644 --- a/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentation.java +++ b/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/MockMvcRestDocumentation.java @@ -17,7 +17,7 @@ package org.springframework.restdocs.mockmvc; import org.springframework.restdocs.RestDocumentation; -import org.springframework.restdocs.RestDocumentationHandler; +import org.springframework.restdocs.generate.RestDocumentationGenerator; import org.springframework.restdocs.operation.preprocess.OperationRequestPreprocessor; import org.springframework.restdocs.operation.preprocess.OperationResponsePreprocessor; import org.springframework.restdocs.snippet.Snippet; @@ -66,7 +66,7 @@ public abstract class MockMvcRestDocumentation { */ public static RestDocumentationResultHandler document(String identifier, Snippet... snippets) { - return new RestDocumentationResultHandler(new RestDocumentationHandler<>( + return new RestDocumentationResultHandler(new RestDocumentationGenerator<>( identifier, REQUEST_CONVERTER, RESPONSE_CONVERTER, snippets)); } @@ -84,7 +84,7 @@ public abstract class MockMvcRestDocumentation { */ public static RestDocumentationResultHandler document(String identifier, OperationRequestPreprocessor requestPreprocessor, Snippet... snippets) { - return new RestDocumentationResultHandler(new RestDocumentationHandler<>( + return new RestDocumentationResultHandler(new RestDocumentationGenerator<>( identifier, REQUEST_CONVERTER, RESPONSE_CONVERTER, requestPreprocessor, snippets)); } @@ -103,7 +103,7 @@ public abstract class MockMvcRestDocumentation { */ public static RestDocumentationResultHandler document(String identifier, OperationResponsePreprocessor responsePreprocessor, Snippet... snippets) { - return new RestDocumentationResultHandler(new RestDocumentationHandler<>( + return new RestDocumentationResultHandler(new RestDocumentationGenerator<>( identifier, REQUEST_CONVERTER, RESPONSE_CONVERTER, responsePreprocessor, snippets)); } @@ -125,7 +125,7 @@ public abstract class MockMvcRestDocumentation { public static RestDocumentationResultHandler document(String identifier, OperationRequestPreprocessor requestPreprocessor, OperationResponsePreprocessor responsePreprocessor, Snippet... snippets) { - return new RestDocumentationResultHandler(new RestDocumentationHandler<>( + return new RestDocumentationResultHandler(new RestDocumentationGenerator<>( identifier, REQUEST_CONVERTER, RESPONSE_CONVERTER, requestPreprocessor, responsePreprocessor, snippets)); } diff --git a/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/RestDocumentationResultHandler.java b/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/RestDocumentationResultHandler.java index 3194e826..d536da13 100644 --- a/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/RestDocumentationResultHandler.java +++ b/spring-restdocs-mockmvc/src/main/java/org/springframework/restdocs/mockmvc/RestDocumentationResultHandler.java @@ -20,7 +20,7 @@ import java.util.Map; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.restdocs.RestDocumentationHandler; +import org.springframework.restdocs.generate.RestDocumentationGenerator; import org.springframework.restdocs.snippet.Snippet; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.ResultHandler; @@ -35,10 +35,10 @@ import org.springframework.util.Assert; */ public class RestDocumentationResultHandler implements ResultHandler { - private final RestDocumentationHandler delegate; + private final RestDocumentationGenerator delegate; RestDocumentationResultHandler( - RestDocumentationHandler delegate) { + RestDocumentationGenerator delegate) { Assert.notNull(delegate, "delegate must be non-null"); this.delegate = delegate; } diff --git a/spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentation.java b/spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentation.java index 0e47cbd2..6f2c3f4c 100644 --- a/spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentation.java +++ b/spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestAssuredRestDocumentation.java @@ -17,7 +17,7 @@ package org.springframework.restdocs.restassured; import org.springframework.restdocs.RestDocumentation; -import org.springframework.restdocs.RestDocumentationHandler; +import org.springframework.restdocs.generate.RestDocumentationGenerator; import org.springframework.restdocs.operation.preprocess.OperationRequestPreprocessor; import org.springframework.restdocs.operation.preprocess.OperationResponsePreprocessor; import org.springframework.restdocs.snippet.Snippet; @@ -46,7 +46,7 @@ public abstract class RestAssuredRestDocumentation { * @return a {@link RestDocumentationFilter} that will produce the documentation */ public static RestDocumentationFilter document(String identifier, Snippet... snippets) { - return new RestDocumentationFilter(new RestDocumentationHandler<>(identifier, + return new RestDocumentationFilter(new RestDocumentationGenerator<>(identifier, REQUEST_CONVERTER, RESPONSE_CONVERTER, snippets)); } @@ -62,7 +62,7 @@ public abstract class RestAssuredRestDocumentation { */ public static RestDocumentationFilter document(String identifier, OperationRequestPreprocessor requestPreprocessor, Snippet... snippets) { - return new RestDocumentationFilter(new RestDocumentationHandler<>(identifier, + return new RestDocumentationFilter(new RestDocumentationGenerator<>(identifier, REQUEST_CONVERTER, RESPONSE_CONVERTER, requestPreprocessor, snippets)); } @@ -78,7 +78,7 @@ public abstract class RestAssuredRestDocumentation { */ public static RestDocumentationFilter document(String identifier, OperationResponsePreprocessor responsePreprocessor, Snippet... snippets) { - return new RestDocumentationFilter(new RestDocumentationHandler<>(identifier, + return new RestDocumentationFilter(new RestDocumentationGenerator<>(identifier, REQUEST_CONVERTER, RESPONSE_CONVERTER, responsePreprocessor, snippets)); } @@ -97,7 +97,7 @@ public abstract class RestAssuredRestDocumentation { public static RestDocumentationFilter document(String identifier, OperationRequestPreprocessor requestPreprocessor, OperationResponsePreprocessor responsePreprocessor, Snippet... snippets) { - return new RestDocumentationFilter(new RestDocumentationHandler<>(identifier, + return new RestDocumentationFilter(new RestDocumentationGenerator<>(identifier, REQUEST_CONVERTER, RESPONSE_CONVERTER, requestPreprocessor, responsePreprocessor, snippets)); } diff --git a/spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestDocumentationFilter.java b/spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestDocumentationFilter.java index f588ed16..29a0b257 100644 --- a/spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestDocumentationFilter.java +++ b/spring-restdocs-restassured/src/main/java/org/springframework/restdocs/restassured/RestDocumentationFilter.java @@ -20,7 +20,7 @@ import java.util.HashMap; import java.util.Map; import org.springframework.restdocs.RestDocumentationContext; -import org.springframework.restdocs.RestDocumentationHandler; +import org.springframework.restdocs.generate.RestDocumentationGenerator; import org.springframework.restdocs.snippet.Snippet; import org.springframework.util.Assert; @@ -37,10 +37,10 @@ import com.jayway.restassured.specification.FilterableResponseSpecification; */ public final class RestDocumentationFilter implements Filter { - private final RestDocumentationHandler delegate; + private final RestDocumentationGenerator delegate; RestDocumentationFilter( - RestDocumentationHandler delegate) { + RestDocumentationGenerator delegate) { Assert.notNull(delegate, "delegate must be non-null"); this.delegate = delegate; }