Break cycle caused by introduction of RestDocumentationHandler

This commit is contained in:
Andy Wilkinson
2016-02-05 21:15:33 +00:00
parent 712d785b95
commit c0fac14fdf
8 changed files with 63 additions and 41 deletions

View File

@@ -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);
}

View File

@@ -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 <REQ> the request type that can be handled
* @param <RESP> the response type that can be handled
* @author Andy Wilkinson
*/
public final class RestDocumentationHandler<REQ, RESP> {
public final class RestDocumentationGenerator<REQ, RESP> {
private final String identifier;
@@ -58,7 +58,7 @@ public final class RestDocumentationHandler<REQ, RESP> {
private final ResponseConverter<RESP> 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<REQ, RESP> {
* @param responseConverter the response converter
* @param snippets the snippets
*/
public RestDocumentationHandler(String identifier,
public RestDocumentationGenerator(String identifier,
RequestConverter<REQ> requestConverter,
ResponseConverter<RESP> responseConverter, Snippet... snippets) {
this(identifier, requestConverter, responseConverter,
@@ -78,7 +78,7 @@ public final class RestDocumentationHandler<REQ, RESP> {
}
/**
* 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<REQ, RESP> {
* @param requestPreprocessor the request preprocessor
* @param snippets the snippets
*/
public RestDocumentationHandler(String identifier,
public RestDocumentationGenerator(String identifier,
RequestConverter<REQ> requestConverter,
ResponseConverter<RESP> responseConverter,
OperationRequestPreprocessor requestPreprocessor, Snippet... snippets) {
@@ -101,7 +101,7 @@ public final class RestDocumentationHandler<REQ, RESP> {
}
/**
* 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<REQ, RESP> {
* @param responsePreprocessor the response preprocessor
* @param snippets the snippets
*/
public RestDocumentationHandler(String identifier,
public RestDocumentationGenerator(String identifier,
RequestConverter<REQ> requestConverter,
ResponseConverter<RESP> responseConverter,
OperationResponsePreprocessor responsePreprocessor, Snippet... snippets) {
@@ -125,7 +125,7 @@ public final class RestDocumentationHandler<REQ, RESP> {
}
/**
* 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<REQ, RESP> {
* @param responsePreprocessor the response preprocessor
* @param snippets the snippets
*/
public RestDocumentationHandler(String identifier,
public RestDocumentationGenerator(String identifier,
RequestConverter<REQ> requestConverter,
ResponseConverter<RESP> responseConverter,
OperationRequestPreprocessor requestPreprocessor,
@@ -167,7 +167,7 @@ public final class RestDocumentationHandler<REQ, RESP> {
* @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<String, Object> configuration) {
OperationRequest operationRequest = this.requestPreprocessor
@@ -184,7 +184,7 @@ public final class RestDocumentationHandler<REQ, RESP> {
}
}
catch (IOException ex) {
throw new RestDocumentationException(ex);
throw new RestDocumentationGenerationException(ex);
}
}

View File

@@ -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;

View File

@@ -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<Object> requestConverter = mock(RequestConverter.class);
@@ -75,7 +76,7 @@ public class RestDocumentationHandlerTests {
given(this.responseConverter.convert(this.response)).willReturn(
this.operationResponse);
HashMap<String, Object> 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<Object, Object> handler = new RestDocumentationHandler<>(
RestDocumentationGenerator<Object, Object> generator = new RestDocumentationGenerator<>(
"id", this.requestConverter, this.responseConverter, this.snippet);
handler.addSnippets(additionalSnippet1, additionalSnippet2);
generator.addSnippets(additionalSnippet1, additionalSnippet2);
HashMap<String, Object> 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);