Skip to content

Commit cdee4d6

Browse files
committed
Improve test coverage
1 parent db4cffa commit cdee4d6

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

test/codegen-generated-classes-test/src/test/java/software/amazon/awssdk/services/useragent/StreamingBodyAndTransformerImplTrackingTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
import static org.assertj.core.api.Assertions.assertThat;
1919
import static org.assertj.core.api.Assertions.assertThatThrownBy;
2020

21+
import java.io.BufferedOutputStream;
2122
import java.io.ByteArrayInputStream;
2223
import java.io.IOException;
24+
import java.io.OutputStream;
2325
import java.util.concurrent.Executors;
2426
import org.junit.jupiter.api.BeforeEach;
2527
import org.junit.jupiter.api.Test;
2628
import software.amazon.awssdk.core.ResponseBytes;
2729
import software.amazon.awssdk.core.async.AsyncRequestBody;
30+
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
2831
import software.amazon.awssdk.core.interceptor.Context;
2932
import software.amazon.awssdk.core.interceptor.ExecutionAttributes;
3033
import software.amazon.awssdk.core.interceptor.ExecutionInterceptor;
@@ -97,6 +100,37 @@ public void streamingOutputOperation_syncClient_file_recordsMetadata() throws IO
97100
assertThat(interceptor.userAgent()).contains("md/rt#f");
98101
}
99102

103+
@Test
104+
public void streamingOutputOperation_syncClient_stream_recordsMetadata() throws IOException {
105+
callStreamingOutputOperation(syncClient(), ResponseTransformer.toOutputStream(new OutputStream() {
106+
@Override
107+
public void write(int b) throws IOException {
108+
109+
}
110+
}));
111+
assertThat(interceptor.userAgent()).contains("md/rt#s");
112+
}
113+
114+
@Test
115+
public void streamingOutputOperation_asyncClient_bytes_recordsMetadata() {
116+
callStreamingOutputOperation(asyncClient(), AsyncResponseTransformer.toBytes());
117+
assertThat(interceptor.userAgent()).contains("md/rt#b");
118+
}
119+
120+
@Test
121+
public void streamingOutputOperation_asyncClient_file_recordsMetadata() throws IOException {
122+
callStreamingOutputOperation(asyncClient(), AsyncResponseTransformer.toFile(new RandomTempFile(0)));
123+
assertThat(interceptor.userAgent()).contains("md/rt#f");
124+
}
125+
126+
@Test
127+
public void streamingOutputOperation_asyncClient_publisher_recordsMetadata() {
128+
callStreamingOutputOperation(asyncClient(), AsyncResponseTransformer.toPublisher());
129+
assertThat(interceptor.userAgent()).contains("md/rt#p");
130+
}
131+
132+
133+
100134
private ProtocolRestJsonWithConfigClient syncClient() {
101135
return ProtocolRestJsonWithConfigClient
102136
.builder()
@@ -133,6 +167,12 @@ private static void callStreamingInputOperation(ProtocolRestJsonWithConfigAsyncC
133167
}).hasMessageContaining("stop");
134168
}
135169

170+
private void callStreamingOutputOperation(
171+
ProtocolRestJsonWithConfigAsyncClient client, AsyncResponseTransformer<StreamingOutputOperationResponse, ?> transformer) {
172+
assertThatThrownBy(() -> client.streamingOutputOperation(r -> {}, transformer).join())
173+
.hasMessageContaining("stop");
174+
}
175+
136176
public static class CapturingInterceptor implements ExecutionInterceptor {
137177
private Context.BeforeTransmission context;
138178
private ExecutionAttributes executionAttributes;

0 commit comments

Comments
 (0)