|
15 | 15 |
|
16 | 16 | package software.amazon.awssdk.core.async;
|
17 | 17 |
|
| 18 | +import static java.nio.charset.StandardCharsets.UTF_8; |
18 | 19 | import static org.assertj.core.api.Assertions.assertThat;
|
19 | 20 |
|
20 | 21 | import com.google.common.jimfs.Configuration;
|
21 | 22 | import com.google.common.jimfs.Jimfs;
|
22 | 23 | import io.reactivex.Flowable;
|
| 24 | +import java.io.File; |
| 25 | +import java.io.FileWriter; |
23 | 26 | import java.io.IOException;
|
| 27 | +import java.io.InputStream; |
24 | 28 | import java.nio.ByteBuffer;
|
25 | 29 | import java.nio.charset.StandardCharsets;
|
26 | 30 | import java.nio.file.FileSystem;
|
27 | 31 | import java.nio.file.Files;
|
28 | 32 | import java.nio.file.Path;
|
| 33 | +import java.time.Instant; |
| 34 | +import java.util.Collections; |
| 35 | +import java.util.List; |
| 36 | +import java.util.concurrent.Callable; |
29 | 37 | import java.util.concurrent.CountDownLatch;
|
| 38 | +import java.util.stream.Collectors; |
| 39 | +import org.assertj.core.util.Lists; |
| 40 | +import org.junit.Rule; |
30 | 41 | import org.junit.Test;
|
| 42 | +import org.junit.rules.TemporaryFolder; |
31 | 43 | import org.junit.runner.RunWith;
|
32 | 44 | import org.junit.runners.Parameterized;
|
| 45 | +import org.reactivestreams.Publisher; |
33 | 46 | import org.reactivestreams.Subscriber;
|
| 47 | +import software.amazon.awssdk.core.internal.util.Mimetype; |
34 | 48 | import software.amazon.awssdk.http.async.SimpleSubscriber;
|
35 | 49 | import software.amazon.awssdk.utils.BinaryUtils;
|
| 50 | +import software.amazon.awssdk.utils.StringInputStream; |
36 | 51 |
|
37 | 52 | @RunWith(Parameterized.class)
|
38 | 53 | public class AsyncRequestBodyTest {
|
@@ -96,6 +111,48 @@ public void onComplete() {
|
96 | 111 | assertThat(sb.toString()).isEqualTo(testString);
|
97 | 112 | }
|
98 | 113 |
|
| 114 | + @Test |
| 115 | + public void stringConstructorHasCorrectContentType() { |
| 116 | + AsyncRequestBody requestBody = AsyncRequestBody.fromString("hello world"); |
| 117 | + assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_TEXT_PLAIN); |
| 118 | + } |
| 119 | + |
| 120 | + @Test |
| 121 | + public void fileConstructorHasCorrectContentType() { |
| 122 | + AsyncRequestBody requestBody = AsyncRequestBody.fromFile(path); |
| 123 | + assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM); |
| 124 | + } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void bytesArrayConstructorHasCorrectContentType() { |
| 128 | + AsyncRequestBody requestBody = AsyncRequestBody.fromBytes("hello world".getBytes()); |
| 129 | + assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM); |
| 130 | + } |
| 131 | + |
| 132 | + @Test |
| 133 | + public void bytesBufferConstructorHasCorrectContentType() { |
| 134 | + ByteBuffer byteBuffer = ByteBuffer.wrap("hello world".getBytes()); |
| 135 | + AsyncRequestBody requestBody = AsyncRequestBody.fromByteBuffer(byteBuffer); |
| 136 | + assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM); |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + public void emptyBytesConstructorHasCorrectContentType() { |
| 141 | + AsyncRequestBody requestBody = AsyncRequestBody.empty(); |
| 142 | + assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + public void publisherConstructorHasCorrectContentType() { |
| 147 | + List<String> requestBodyStrings = Lists.newArrayList("A", "B", "C"); |
| 148 | + List<ByteBuffer> bodyBytes = requestBodyStrings.stream() |
| 149 | + .map(s -> ByteBuffer.wrap(s.getBytes(StandardCharsets.UTF_8))) |
| 150 | + .collect(Collectors.toList()); |
| 151 | + Publisher<ByteBuffer> bodyPublisher = Flowable.fromIterable(bodyBytes); |
| 152 | + AsyncRequestBody requestBody = AsyncRequestBody.fromPublisher(bodyPublisher); |
| 153 | + assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM); |
| 154 | + } |
| 155 | + |
99 | 156 | @Test
|
100 | 157 | public void fromBytes_byteArrayNotNull_createsCopy() {
|
101 | 158 | byte[] original = {0x1, 0x2, 0x3, 0x4};
|
|
0 commit comments