Test support for HTTP range requests to endpoints returning a Resource

Closes gh-9978
pull/9635/head
Andy Wilkinson 7 years ago
parent 2e01d90660
commit 16edf72faa

@ -447,7 +447,7 @@ public abstract class AbstractWebEndpointIntegrationTests<T extends Configurable
@Configuration @Configuration
@Import(BaseConfiguration.class) @Import(BaseConfiguration.class)
static class ResourceEndpointConfiguration { protected static class ResourceEndpointConfiguration {
@Bean @Bean
public ResourceEndpoint resourceEndpoint() { public ResourceEndpoint resourceEndpoint() {

@ -31,12 +31,15 @@ import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.server.reactive.HttpHandler; import org.springframework.http.server.reactive.HttpHandler;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.reactive.config.EnableWebFlux; import org.springframework.web.reactive.config.EnableWebFlux;
import org.springframework.web.server.adapter.WebHttpHandlerBuilder; import org.springframework.web.server.adapter.WebHttpHandlerBuilder;
import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration tests for web endpoints exposed using WebFlux. * Integration tests for web endpoints exposed using WebFlux.
* *
@ -63,6 +66,18 @@ public class WebFluxEndpointIntegrationTests
.valueEquals("Access-Control-Allow-Methods", "GET,POST")); .valueEquals("Access-Control-Allow-Methods", "GET,POST"));
} }
@Test
public void readOperationsThatReturnAResourceSupportRangeRequests() {
load(ResourceEndpointConfiguration.class, (client) -> {
byte[] responseBody = client.get().uri("/resource")
.header("Range", "bytes=0-3").exchange().expectStatus()
.isEqualTo(HttpStatus.PARTIAL_CONTENT).expectHeader()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.returnResult(byte[].class).getResponseBodyContent();
assertThat(responseBody).containsExactly(0, 1, 2, 3);
});
}
@Override @Override
protected ReactiveWebServerApplicationContext createApplicationContext( protected ReactiveWebServerApplicationContext createApplicationContext(
Class<?>... config) { Class<?>... config) {

@ -28,11 +28,14 @@ import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebSe
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment; import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.web.cors.CorsConfiguration; import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.DispatcherServlet; import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration tests for web endpoints exposed using Spring MVC. * Integration tests for web endpoints exposed using Spring MVC.
* *
@ -59,6 +62,18 @@ public class MvcWebEndpointIntegrationTests extends
.valueEquals("Access-Control-Allow-Methods", "GET,POST")); .valueEquals("Access-Control-Allow-Methods", "GET,POST"));
} }
@Test
public void readOperationsThatReturnAResourceSupportRangeRequests() {
load(ResourceEndpointConfiguration.class, (client) -> {
byte[] responseBody = client.get().uri("/resource")
.header("Range", "bytes=0-3").exchange().expectStatus()
.isEqualTo(HttpStatus.PARTIAL_CONTENT).expectHeader()
.contentType(MediaType.APPLICATION_OCTET_STREAM)
.returnResult(byte[].class).getResponseBodyContent();
assertThat(responseBody).containsExactly(0, 1, 2, 3);
});
}
@Override @Override
protected AnnotationConfigServletWebServerApplicationContext createApplicationContext( protected AnnotationConfigServletWebServerApplicationContext createApplicationContext(
Class<?>... config) { Class<?>... config) {

Loading…
Cancel
Save