private OperationResponse createResponseWithContent(String content) { return this.responseFactory.create(HttpStatus.OK, new HttpHeaders(), content.getBytes()); }
private OperationResponse createResponseWithContent(String content) { return this.responseFactory.create(HttpStatus.OK, new HttpHeaders(), content.getBytes()); }
private OperationResponse createResponseWithHeader(String name, String value) { HttpHeaders headers = new HttpHeaders(); headers.add(name, value); return this.responseFactory.create(HttpStatus.OK, headers, new byte[0]); }
private OperationResponse createResponseWithHeader(String name, String value) { HttpHeaders headers = new HttpHeaders(); headers.add(name, value); return this.responseFactory.create(HttpStatus.OK, headers, new byte[0]); }
private OperationResponse buildResponse() { return new OperationResponseFactory().create(this.status, this.headers, this.content); }
private OperationResponse createResponse(String... extraHeaders) { return this.responseFactory.create(HttpStatus.OK, getHttpHeaders(extraHeaders), new byte[0]); }
private static OperationResponse createResponse() { return new OperationResponseFactory().create(null, null, null); }
@Override public OperationResponse convert(ExchangeResult result) { return new OperationResponseFactory().create(result.getStatus(), extractHeaders(result), result.getResponseBodyContent()); }
@Test public void extractorCalledWithMatchingContextType() throws IOException { Map<MediaType, LinkExtractor> extractors = new HashMap<>(); LinkExtractor extractor = mock(LinkExtractor.class); extractors.put(MediaType.APPLICATION_JSON, extractor); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.APPLICATION_JSON); OperationResponse response = this.responseFactory.create(HttpStatus.OK, httpHeaders, null); new ContentTypeLinkExtractor(extractors).extractLinks(response); verify(extractor).extractLinks(response); }
@Override public OperationResponse convert(MockHttpServletResponse mockResponse) { return new OperationResponseFactory().create( HttpStatus.valueOf(mockResponse.getStatus()), extractHeaders(mockResponse), mockResponse.getContentAsByteArray()); }
@Test public void extractorCalledWithCompatibleContextType() throws IOException { Map<MediaType, LinkExtractor> extractors = new HashMap<>(); LinkExtractor extractor = mock(LinkExtractor.class); extractors.put(MediaType.APPLICATION_JSON, extractor); HttpHeaders httpHeaders = new HttpHeaders(); httpHeaders.setContentType(MediaType.parseMediaType("application/json;foo=bar")); OperationResponse response = this.responseFactory.create(HttpStatus.OK, httpHeaders, null); new ContentTypeLinkExtractor(extractors).extractLinks(response); verify(extractor).extractLinks(response); }
@Test public void modifyResponseContent() { OperationResponse response = this.responseFactory.create(HttpStatus.OK, new HttpHeaders(), "content".getBytes()); OperationResponse preprocessed = this.preprocessor.preprocess(response); assertThat(preprocessed.getContent()).isEqualTo("modified".getBytes()); }
@Override public OperationResponse convert(Response response) { return new OperationResponseFactory().create( HttpStatus.valueOf(response.getStatusCode()), extractHeaders(response), extractContent(response)); }
private OperationResponse createResponse(String contentName) throws IOException { return this.responseFactory.create(HttpStatus.OK, null, FileCopyUtils.copyToByteArray(getPayloadFile(contentName))); }
@Override public OperationResponse preprocess(OperationResponse response) { return this.contentModifyingDelegate .preprocess(new OperationResponseFactory().create(response.getStatus(), modify(response.getHeaders()), response.getContent())); }
@Test public void extractionFailsWithNullContentType() throws IOException { this.thrown.expect(IllegalStateException.class); new ContentTypeLinkExtractor().extractLinks( this.responseFactory.create(HttpStatus.OK, new HttpHeaders(), null)); }
@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"); }
@Override public OperationResponse convert(MockHttpServletResponse mockResponse) { return new OperationResponseFactory().create( HttpStatus.valueOf(mockResponse.getStatus()), extractHeaders(mockResponse), mockResponse.getContentAsByteArray()); }