Skip to content

Commit 16edf72

Browse files
committed
Test support for HTTP range requests to endpoints returning a Resource
Closes gh-9978
1 parent 2e01d90 commit 16edf72

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/AbstractWebEndpointIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public NullDeleteResponseEndpoint nullDeleteResponseEndpoint() {
447447

448448
@Configuration
449449
@Import(BaseConfiguration.class)
450-
static class ResourceEndpointConfiguration {
450+
protected static class ResourceEndpointConfiguration {
451451

452452
@Bean
453453
public ResourceEndpoint resourceEndpoint() {

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/reactive/WebFluxEndpointIntegrationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,15 @@
3131
import org.springframework.context.annotation.Bean;
3232
import org.springframework.context.annotation.Configuration;
3333
import org.springframework.core.env.Environment;
34+
import org.springframework.http.HttpStatus;
3435
import org.springframework.http.MediaType;
3536
import org.springframework.http.server.reactive.HttpHandler;
3637
import org.springframework.web.cors.CorsConfiguration;
3738
import org.springframework.web.reactive.config.EnableWebFlux;
3839
import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
3940

41+
import static org.assertj.core.api.Assertions.assertThat;
42+
4043
/**
4144
* Integration tests for web endpoints exposed using WebFlux.
4245
*
@@ -63,6 +66,18 @@ public void responseToOptionsRequestIncludesCorsHeaders() {
6366
.valueEquals("Access-Control-Allow-Methods", "GET,POST"));
6467
}
6568

69+
@Test
70+
public void readOperationsThatReturnAResourceSupportRangeRequests() {
71+
load(ResourceEndpointConfiguration.class, (client) -> {
72+
byte[] responseBody = client.get().uri("/resource")
73+
.header("Range", "bytes=0-3").exchange().expectStatus()
74+
.isEqualTo(HttpStatus.PARTIAL_CONTENT).expectHeader()
75+
.contentType(MediaType.APPLICATION_OCTET_STREAM)
76+
.returnResult(byte[].class).getResponseBodyContent();
77+
assertThat(responseBody).containsExactly(0, 1, 2, 3);
78+
});
79+
}
80+
6681
@Override
6782
protected ReactiveWebServerApplicationContext createApplicationContext(
6883
Class<?>... config) {

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/web/servlet/MvcWebEndpointIntegrationTests.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,14 @@
2828
import org.springframework.context.annotation.Bean;
2929
import org.springframework.context.annotation.Configuration;
3030
import org.springframework.core.env.Environment;
31+
import org.springframework.http.HttpStatus;
3132
import org.springframework.http.MediaType;
3233
import org.springframework.web.cors.CorsConfiguration;
3334
import org.springframework.web.servlet.DispatcherServlet;
3435
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
3536

37+
import static org.assertj.core.api.Assertions.assertThat;
38+
3639
/**
3740
* Integration tests for web endpoints exposed using Spring MVC.
3841
*
@@ -59,6 +62,18 @@ public void responseToOptionsRequestIncludesCorsHeaders() {
5962
.valueEquals("Access-Control-Allow-Methods", "GET,POST"));
6063
}
6164

65+
@Test
66+
public void readOperationsThatReturnAResourceSupportRangeRequests() {
67+
load(ResourceEndpointConfiguration.class, (client) -> {
68+
byte[] responseBody = client.get().uri("/resource")
69+
.header("Range", "bytes=0-3").exchange().expectStatus()
70+
.isEqualTo(HttpStatus.PARTIAL_CONTENT).expectHeader()
71+
.contentType(MediaType.APPLICATION_OCTET_STREAM)
72+
.returnResult(byte[].class).getResponseBodyContent();
73+
assertThat(responseBody).containsExactly(0, 1, 2, 3);
74+
});
75+
}
76+
6277
@Override
6378
protected AnnotationConfigServletWebServerApplicationContext createApplicationContext(
6479
Class<?>... config) {

0 commit comments

Comments
 (0)