ResourceDecoder supports filename hint
Closes gh-22267
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 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.
|
||||
@@ -18,6 +18,7 @@ package org.springframework.core.codec;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -100,23 +101,28 @@ public class ResourceDecoderTests extends AbstractDecoderTestCase<ResourceDecode
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeToMono() throws Exception {
|
||||
public void decodeToMono() {
|
||||
Flux<DataBuffer> input = Flux.concat(
|
||||
dataBuffer(this.fooBytes),
|
||||
dataBuffer(this.barBytes));
|
||||
|
||||
testDecodeToMonoAll(input, Resource.class, step -> step
|
||||
.consumeNextWith(resource -> {
|
||||
try {
|
||||
byte[] bytes = StreamUtils.copyToByteArray(resource.getInputStream());
|
||||
assertEquals("foobar", new String(bytes));
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
})
|
||||
.expectComplete()
|
||||
.verify());
|
||||
testDecodeToMonoAll(input, ResolvableType.forClass(Resource.class),
|
||||
step -> step
|
||||
.consumeNextWith(value -> {
|
||||
Resource resource = (Resource) value;
|
||||
try {
|
||||
byte[] bytes = StreamUtils.copyToByteArray(resource.getInputStream());
|
||||
assertEquals("foobar", new String(bytes));
|
||||
assertEquals("testFile", resource.getFilename());
|
||||
}
|
||||
catch (IOException e) {
|
||||
fail(e.getMessage());
|
||||
}
|
||||
})
|
||||
.expectComplete()
|
||||
.verify(),
|
||||
null,
|
||||
Collections.singletonMap(ResourceDecoder.FILENAME_HINT, "testFile"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user