|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2016 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
@ -23,7 +23,6 @@ import org.junit.Test; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import reactor.test.StepVerifier; |
|
|
|
import reactor.test.StepVerifier; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.ResolvableType; |
|
|
|
|
|
|
|
import org.springframework.core.io.ByteArrayResource; |
|
|
|
import org.springframework.core.io.ByteArrayResource; |
|
|
|
import org.springframework.core.io.InputStreamResource; |
|
|
|
import org.springframework.core.io.InputStreamResource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
@ -32,9 +31,8 @@ import org.springframework.core.io.buffer.DataBuffer; |
|
|
|
import org.springframework.util.MimeTypeUtils; |
|
|
|
import org.springframework.util.MimeTypeUtils; |
|
|
|
import org.springframework.util.StreamUtils; |
|
|
|
import org.springframework.util.StreamUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
|
import static org.junit.Assert.*; |
|
|
|
import static org.junit.Assert.assertTrue; |
|
|
|
import static org.springframework.core.ResolvableType.*; |
|
|
|
import static org.junit.Assert.fail; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @author Arjen Poutsma |
|
|
|
* @author Arjen Poutsma |
|
|
@ -44,25 +42,22 @@ public class ResourceDecoderTests extends AbstractDataBufferAllocatingTestCase { |
|
|
|
private final ResourceDecoder decoder = new ResourceDecoder(); |
|
|
|
private final ResourceDecoder decoder = new ResourceDecoder(); |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void canDecode() throws Exception { |
|
|
|
public void canDecode() { |
|
|
|
assertTrue(this.decoder.canDecode(ResolvableType.forClass(InputStreamResource.class), |
|
|
|
assertTrue(this.decoder.canDecode(forClass(InputStreamResource.class), MimeTypeUtils.TEXT_PLAIN)); |
|
|
|
MimeTypeUtils.TEXT_PLAIN)); |
|
|
|
assertTrue(this.decoder.canDecode(forClass(ByteArrayResource.class), MimeTypeUtils.TEXT_PLAIN)); |
|
|
|
assertTrue(this.decoder.canDecode(ResolvableType.forClass(ByteArrayResource.class), |
|
|
|
assertTrue(this.decoder.canDecode(forClass(Resource.class), MimeTypeUtils.TEXT_PLAIN)); |
|
|
|
MimeTypeUtils.TEXT_PLAIN)); |
|
|
|
assertTrue(this.decoder.canDecode(forClass(InputStreamResource.class), MimeTypeUtils.APPLICATION_JSON)); |
|
|
|
assertTrue(this.decoder.canDecode(ResolvableType.forClass(Resource.class), |
|
|
|
assertFalse(this.decoder.canDecode(forClass(Object.class), MimeTypeUtils.APPLICATION_JSON)); |
|
|
|
MimeTypeUtils.TEXT_PLAIN)); |
|
|
|
|
|
|
|
assertTrue(this.decoder.canDecode(ResolvableType.forClass(InputStreamResource.class), |
|
|
|
|
|
|
|
MimeTypeUtils.APPLICATION_JSON)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void decode() throws Exception { |
|
|
|
public void decode() { |
|
|
|
DataBuffer fooBuffer = stringBuffer("foo"); |
|
|
|
DataBuffer fooBuffer = stringBuffer("foo"); |
|
|
|
DataBuffer barBuffer = stringBuffer("bar"); |
|
|
|
DataBuffer barBuffer = stringBuffer("bar"); |
|
|
|
Flux<DataBuffer> source = Flux.just(fooBuffer, barBuffer); |
|
|
|
Flux<DataBuffer> source = Flux.just(fooBuffer, barBuffer); |
|
|
|
|
|
|
|
|
|
|
|
Flux<Resource> result = this.decoder |
|
|
|
Flux<Resource> result = this.decoder |
|
|
|
.decode(source, ResolvableType.forClass(Resource.class), null, Collections.emptyMap()); |
|
|
|
.decode(source, forClass(Resource.class), null, Collections.emptyMap()); |
|
|
|
|
|
|
|
|
|
|
|
StepVerifier.create(result) |
|
|
|
StepVerifier.create(result) |
|
|
|
.consumeNextWith(resource -> { |
|
|
|
.consumeNextWith(resource -> { |
|
|
|