private OperationResponse preprocess(OperationResponsePreprocessor preprocessor, OperationResponse response) { return preprocessor.preprocess(response); }
@Test public void customDefaultOperationResponsePreprocessor() { Map<String, Object> configuration = new HashMap<>(); this.configurer.operationPreprocessors() .withResponseDefaults(Preprocessors.prettyPrint(), Preprocessors.removeHeaders("Foo")) .apply(configuration, createContext()); OperationResponsePreprocessor preprocessor = (OperationResponsePreprocessor) configuration .get(RestDocumentationGenerator.ATTRIBUTE_NAME_DEFAULT_OPERATION_RESPONSE_PREPROCESSOR); HttpHeaders headers = new HttpHeaders(); headers.add("Foo", "value"); OperationResponse response = new OperationResponseFactory().create(HttpStatus.OK, headers, null); assertThat(preprocessor.preprocess(response).getHeaders()) .doesNotContainKey("Foo"); }
@Test public void newGeneratorOnlyCallsItsSnippets() throws IOException { OperationRequestPreprocessor requestPreprocessor = mock( OperationRequestPreprocessor.class); OperationResponsePreprocessor responsePreprocessor = mock( OperationResponsePreprocessor.class); given(this.requestConverter.convert(this.request)) .willReturn(this.operationRequest); given(this.responseConverter.convert(this.response)) .willReturn(this.operationResponse); given(requestPreprocessor.preprocess(this.operationRequest)) .willReturn(this.operationRequest); given(responsePreprocessor.preprocess(this.operationResponse)) .willReturn(this.operationResponse); Snippet additionalSnippet1 = mock(Snippet.class); Snippet additionalSnippet2 = mock(Snippet.class); RestDocumentationGenerator<Object, Object> generator = new RestDocumentationGenerator<>( "id", this.requestConverter, this.responseConverter, requestPreprocessor, responsePreprocessor, this.snippet); HashMap<String, Object> configuration = new HashMap<>(); generator.withSnippets(additionalSnippet1, additionalSnippet2) .handle(this.request, this.response, configuration); verifyNoMoreInteractions(this.snippet); verifySnippetInvocation(additionalSnippet1, configuration); verifySnippetInvocation(additionalSnippet2, configuration); }