Fix content type issue in ResourceRegionHttpMessageWriter
ResourceRegionHttpMessageWriter no longer extends from EncoderHttpMessageWriter freeing it to pass the correct content type into the encoder. Considering that the main benefit of EncoderHttpMessageWriter is to deal with content type fallback cases, there is nothing to be missed. Furthermore ResourceRegionHttpMessageWriter is a package private class that is used internally within ResourceHttpMessageWriter and never exposed externally as a an actual HttpMessageWriter. Issue: SPR-15358
This commit is contained in:
@@ -23,7 +23,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
@@ -31,7 +30,6 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.ResourceRegion;
|
||||
@@ -41,8 +39,10 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.Assert.assertArrayEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ResourceRegionHttpMessageWriter}.
|
||||
@@ -67,19 +67,13 @@ public class ResourceRegionHttpMessageWriterTests {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void writableMediaTypes() throws Exception {
|
||||
assertThat(this.writer.getWritableMediaTypes(),
|
||||
containsInAnyOrder(MimeTypeUtils.APPLICATION_OCTET_STREAM, MimeTypeUtils.ALL));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldWriteResourceRegion() throws Exception {
|
||||
|
||||
ResourceRegion region = new ResourceRegion(this.resource, 0, 6);
|
||||
Map<String, Object> hints = Collections.emptyMap();
|
||||
|
||||
Mono<Void> mono = this.writer.write(Mono.just(region), ResolvableType.forClass(ResourceRegion.class),
|
||||
MediaType.TEXT_PLAIN, this.response, Collections.emptyMap());
|
||||
Mono<Void> mono = this.writer.writeRegions(Mono.just(region), MediaType.TEXT_PLAIN, this.response, hints);
|
||||
StepVerifier.create(mono).expectComplete().verify();
|
||||
|
||||
assertThat(this.response.getHeaders().getContentType(), is(MediaType.TEXT_PLAIN));
|
||||
@@ -91,7 +85,6 @@ public class ResourceRegionHttpMessageWriterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Until issue resolved: ResourceRegion should not use response content-type")
|
||||
public void shouldWriteMultipleResourceRegions() throws Exception {
|
||||
Flux<ResourceRegion> regions = Flux.just(
|
||||
new ResourceRegion(this.resource, 0, 6),
|
||||
@@ -103,8 +96,7 @@ public class ResourceRegionHttpMessageWriterTests {
|
||||
Map<String, Object> hints = new HashMap<>(1);
|
||||
hints.put(ResourceRegionHttpMessageWriter.BOUNDARY_STRING_HINT, boundary);
|
||||
|
||||
Mono<Void> mono = this.writer.write(regions, ResolvableType.forClass(ResourceRegion.class),
|
||||
MediaType.TEXT_PLAIN, this.response, hints);
|
||||
Mono<Void> mono = this.writer.writeRegions(regions, MediaType.TEXT_PLAIN, this.response, hints);
|
||||
StepVerifier.create(mono).expectComplete().verify();
|
||||
|
||||
HttpHeaders headers = this.response.getHeaders();
|
||||
|
||||
Reference in New Issue
Block a user