Break cycle caused by introduction of RestDocumentationHandler
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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<MockHttpServletRequest, MockHttpServletResponse> delegate;
|
||||
private final RestDocumentationGenerator<MockHttpServletRequest, MockHttpServletResponse> delegate;
|
||||
|
||||
RestDocumentationResultHandler(
|
||||
RestDocumentationHandler<MockHttpServletRequest, MockHttpServletResponse> delegate) {
|
||||
RestDocumentationGenerator<MockHttpServletRequest, MockHttpServletResponse> delegate) {
|
||||
Assert.notNull(delegate, "delegate must be non-null");
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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<FilterableRequestSpecification, Response> delegate;
|
||||
private final RestDocumentationGenerator<FilterableRequestSpecification, Response> delegate;
|
||||
|
||||
RestDocumentationFilter(
|
||||
RestDocumentationHandler<FilterableRequestSpecification, Response> delegate) {
|
||||
RestDocumentationGenerator<FilterableRequestSpecification, Response> delegate) {
|
||||
Assert.notNull(delegate, "delegate must be non-null");
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user