@Test public void testInterceptWithConfiguration() throws Exception { prepareExecution("http://localhost:8080", "TestResponse", "markdown"); ClientHttpRequestExecution configureExecution = Mockito.mock(ClientHttpRequestExecution.class); when(configureExecution.execute(any(HttpRequest.class), any(byte[].class))) .thenAnswer( new Answer<ClientHttpResponse>() { @Override public ClientHttpResponse answer(InvocationOnMock invocation) throws Throwable { interceptor.intercept( (HttpRequest) invocation.getArguments()[0], (byte[]) invocation.getArguments()[1], execution); return response; } }); CitrusRestDocsSupport.restDocsConfigurer(restDocumentation) .snippets() .withTemplateFormat(TemplateFormats.markdown()) .intercept(request, "TestMessage".getBytes(), configureExecution); assertExpectedSnippetFilesExist( "markdown", "http-request.md", "http-response.md", "curl-request.md"); }
private void prepareExecution( String uri, String responseBody, String identifier, Snippet... snippets) throws IOException { when(execution.execute(any(HttpRequest.class), any(byte[].class))).thenReturn(response); when(request.getURI()).thenReturn(URI.create(uri)); when(request.getMethod()).thenReturn(HttpMethod.GET); when(request.getHeaders()).thenReturn(new HttpHeaders()); when(response.getHeaders()).thenReturn(new HttpHeaders()); when(response.getStatusCode()).thenReturn(HttpStatus.OK); when(response.getBody()).thenReturn(new ByteArrayInputStream(responseBody.getBytes())); this.interceptor = CitrusRestDocsSupport.restDocsInterceptor(identifier, snippets); }