Polish "Add content buffering support to MockServerRestTemplateCustomizer"

See gh-34833
pull/34508/head
Andy Wilkinson 2 years ago
parent b065e04be7
commit 3f93a4ece6

@ -1,5 +1,5 @@
/*
* Copyright 2012-2022 the original author or authors.
* Copyright 2012-2023 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.
@ -102,10 +102,13 @@ public class MockServerRestTemplateCustomizer implements RestTemplateCustomizer
}
/**
* Use the {@link BufferingClientHttpRequestFactory} wrapper to buffer the input and
* output streams, and for example, allow multiple reads of the response body.
* Set if the {@link BufferingClientHttpRequestFactory} wrapper should be used to
* buffer the input and output streams, and for example, allow multiple reads of the
* response body.
* @param bufferContent if request and response content should be buffered
* @since 3.1.0
*/
public void bufferContent(boolean bufferContent) {
public void setBufferContent(boolean bufferContent) {
this.bufferContent = bufferContent;
}

@ -106,7 +106,23 @@ class MockServerRestTemplateCustomizerTests {
this.customizer.customize(new RestTemplateBuilder().rootUri("https://example.com").build());
assertThat(this.customizer.getServer()).extracting("expectationManager")
.isInstanceOf(SimpleRequestExpectationManager.class);
}
@Test
void bufferContentShouldDefaultToFalse() {
MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer();
RestTemplate restTemplate = new RestTemplate();
customizer.customize(restTemplate);
assertThat(restTemplate.getRequestFactory()).isInstanceOf(ClientHttpRequestFactory.class);
}
@Test
void setBufferContentShouldEnableContentBuffering() {
MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer();
RestTemplate restTemplate = new RestTemplate();
customizer.setBufferContent(true);
customizer.customize(restTemplate);
assertThat(restTemplate.getRequestFactory()).isInstanceOf(BufferingClientHttpRequestFactory.class);
}
@Test
@ -180,21 +196,4 @@ class MockServerRestTemplateCustomizerTests {
assertThat(this.customizer.getServer(template2)).extracting("expectationManager").isEqualTo(manager2);
}
@Test
void bufferContentShouldBeFalseByDefault() {
MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer();
RestTemplate restTemplate = new RestTemplate();
customizer.customize(restTemplate);
assertThat(restTemplate.getRequestFactory()).isInstanceOf(ClientHttpRequestFactory.class);
}
@Test
void enableBufferContent() {
MockServerRestTemplateCustomizer customizer = new MockServerRestTemplateCustomizer();
RestTemplate restTemplate = new RestTemplate();
customizer.bufferContent(true);
customizer.customize(restTemplate);
assertThat(restTemplate.getRequestFactory()).isInstanceOf(BufferingClientHttpRequestFactory.class);
}
}

Loading…
Cancel
Save