Skip to content

Commit 4aac24a

Browse files
author
Bennett Lynch
committed
Add additional test coverage
1 parent ffc3deb commit 4aac24a

File tree

8 files changed

+350
-40
lines changed

8 files changed

+350
-40
lines changed
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,10 @@
1313
* permissions and limitations under the License.
1414
*/
1515

16-
package software.amazon.awssdk.transfer.s3.internal;
16+
package software.amazon.awssdk.transfer.s3;
1717

1818
import nl.jqno.equalsverifier.EqualsVerifier;
1919
import org.junit.Test;
20-
import software.amazon.awssdk.transfer.s3.CompletedDirectoryUpload;
2120

2221
public class CompletedDirectoryUploadTest {
2322

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.transfer.s3.internal;
17+
18+
import nl.jqno.equalsverifier.EqualsVerifier;
19+
import org.junit.Test;
20+
import software.amazon.awssdk.transfer.s3.UploadRequest;
21+
22+
public class DefaultDirectoryUploadTest {
23+
24+
@Test
25+
public void equals_hashcode() {
26+
EqualsVerifier.forClass(UploadRequest.class)
27+
.withNonnullFields("completionFuture")
28+
.verify();
29+
}
30+
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.transfer.s3.internal;
17+
18+
import nl.jqno.equalsverifier.EqualsVerifier;
19+
import org.junit.Test;
20+
21+
public class DefaultDownloadTest {
22+
23+
@Test
24+
public void equals_hashcode() {
25+
EqualsVerifier.forClass(DefaultDownload.class)
26+
.withNonnullFields("completionFuture", "progress")
27+
.verify();
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.transfer.s3.internal;
17+
18+
import nl.jqno.equalsverifier.EqualsVerifier;
19+
import org.junit.Test;
20+
21+
public class DefaultFileDownloadTest {
22+
23+
@Test
24+
public void equals_hashcode() {
25+
EqualsVerifier.forClass(DefaultFileDownload.class)
26+
.withNonnullFields("completionFuture", "progress")
27+
.verify();
28+
}
29+
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.transfer.s3.internal;
17+
18+
import nl.jqno.equalsverifier.EqualsVerifier;
19+
import org.junit.Test;
20+
21+
public class DefaultFileUploadTest {
22+
23+
@Test
24+
public void equals_hashcode() {
25+
EqualsVerifier.forClass(DefaultFileUpload.class)
26+
.withNonnullFields("completionFuture", "progress")
27+
.verify();
28+
}
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.transfer.s3.internal;
17+
18+
import nl.jqno.equalsverifier.EqualsVerifier;
19+
import org.junit.Test;
20+
21+
public class DefaultUploadTest {
22+
23+
@Test
24+
public void equals_hashcode() {
25+
EqualsVerifier.forClass(DefaultUpload.class)
26+
.withNonnullFields("completionFuture", "progress")
27+
.verify();
28+
}
29+
}

services-custom/s3-transfer-manager/src/test/java/software/amazon/awssdk/transfer/s3/internal/S3TransferManagerListenerTest.java

Lines changed: 94 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.junit.Test;
4343
import org.mockito.ArgumentCaptor;
4444
import org.mockito.stubbing.Answer;
45+
import software.amazon.awssdk.core.ResponseBytes;
4546
import software.amazon.awssdk.core.async.AsyncRequestBody;
4647
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
4748
import software.amazon.awssdk.core.async.DrainingSubscriber;
@@ -50,11 +51,15 @@
5051
import software.amazon.awssdk.services.s3.model.PutObjectRequest;
5152
import software.amazon.awssdk.services.s3.model.PutObjectResponse;
5253
import software.amazon.awssdk.transfer.s3.CompletedFileUpload;
54+
import software.amazon.awssdk.transfer.s3.Download;
5355
import software.amazon.awssdk.transfer.s3.DownloadFileRequest;
56+
import software.amazon.awssdk.transfer.s3.DownloadRequest;
5457
import software.amazon.awssdk.transfer.s3.FileDownload;
5558
import software.amazon.awssdk.transfer.s3.FileUpload;
5659
import software.amazon.awssdk.transfer.s3.S3TransferManager;
60+
import software.amazon.awssdk.transfer.s3.Upload;
5761
import software.amazon.awssdk.transfer.s3.UploadFileRequest;
62+
import software.amazon.awssdk.transfer.s3.UploadRequest;
5863
import software.amazon.awssdk.transfer.s3.progress.TransferListener;
5964

6065
public class S3TransferManagerListenerTest {
@@ -80,7 +85,7 @@ public void methodTeardown() {
8085
}
8186

8287
@Test
83-
public void upload_success_shouldInvokeListener() throws Exception {
88+
public void uploadFile_success_shouldInvokeListener() throws Exception {
8489
TransferListener listener = mock(TransferListener.class);
8590

8691
Path path = newTempFile();
@@ -124,7 +129,48 @@ public void upload_success_shouldInvokeListener() throws Exception {
124129
}
125130

126131
@Test
127-
public void download_success_shouldInvokeListener() throws Exception {
132+
public void upload_success_shouldInvokeListener() throws Exception {
133+
TransferListener listener = mock(TransferListener.class);
134+
135+
UploadRequest uploadRequest = UploadRequest.builder()
136+
.putObjectRequest(r -> r.bucket("bucket")
137+
.key("key"))
138+
.requestBody(AsyncRequestBody.fromString("foo"))
139+
.overrideConfiguration(b -> b.addListener(listener))
140+
.build();
141+
Upload upload = tm.upload(uploadRequest);
142+
143+
ArgumentCaptor<TransferListener.Context.TransferInitiated> captor1 =
144+
ArgumentCaptor.forClass(TransferListener.Context.TransferInitiated.class);
145+
verify(listener, timeout(1000).times(1)).transferInitiated(captor1.capture());
146+
TransferListener.Context.TransferInitiated ctx1 = captor1.getValue();
147+
assertThat(ctx1.request()).isSameAs(uploadRequest);
148+
assertThat(ctx1.progressSnapshot().transferSizeInBytes()).hasValue(3L);
149+
assertThat(ctx1.progressSnapshot().bytesTransferred()).isZero();
150+
151+
ArgumentCaptor<TransferListener.Context.BytesTransferred> captor2 =
152+
ArgumentCaptor.forClass(TransferListener.Context.BytesTransferred.class);
153+
verify(listener, timeout(1000).times(1)).bytesTransferred(captor2.capture());
154+
TransferListener.Context.BytesTransferred ctx2 = captor2.getValue();
155+
assertThat(ctx2.request()).isSameAs(uploadRequest);
156+
assertThat(ctx2.progressSnapshot().transferSizeInBytes()).hasValue(3L);
157+
assertThat(ctx2.progressSnapshot().bytesTransferred()).isPositive();
158+
159+
ArgumentCaptor<TransferListener.Context.TransferComplete> captor3 =
160+
ArgumentCaptor.forClass(TransferListener.Context.TransferComplete.class);
161+
verify(listener, timeout(1000).times(1)).transferComplete(captor3.capture());
162+
TransferListener.Context.TransferComplete ctx3 = captor3.getValue();
163+
assertThat(ctx3.request()).isSameAs(uploadRequest);
164+
assertThat(ctx3.progressSnapshot().transferSizeInBytes()).hasValue(3L);
165+
assertThat(ctx3.progressSnapshot().bytesTransferred()).isEqualTo(3L);
166+
assertThat(ctx3.completedTransfer()).isSameAs(upload.completionFuture().get());
167+
168+
upload.completionFuture().join();
169+
verifyNoMoreInteractions(listener);
170+
}
171+
172+
@Test
173+
public void downloadFile_success_shouldInvokeListener() throws Exception {
128174
TransferListener listener = mock(TransferListener.class);
129175

130176
DownloadFileRequest downloadRequest = DownloadFileRequest.builder()
@@ -167,7 +213,52 @@ public void download_success_shouldInvokeListener() throws Exception {
167213
}
168214

169215
@Test
170-
public void upload_failure_shouldInvokeListener() throws Exception {
216+
public void download_success_shouldInvokeListener() throws Exception {
217+
TransferListener listener = mock(TransferListener.class);
218+
219+
DownloadRequest<ResponseBytes<GetObjectResponse>> downloadRequest =
220+
DownloadRequest.builder()
221+
.getObjectRequest(r -> r.bucket(
222+
"bucket")
223+
.key("key"))
224+
.responseTransformer(AsyncResponseTransformer.toBytes())
225+
.overrideConfiguration(b -> b.addListener(listener))
226+
.build();
227+
Download<ResponseBytes<GetObjectResponse>> download = tm.download(downloadRequest);
228+
229+
ArgumentCaptor<TransferListener.Context.TransferInitiated> captor1 =
230+
ArgumentCaptor.forClass(TransferListener.Context.TransferInitiated.class);
231+
verify(listener, timeout(1000).times(1)).transferInitiated(captor1.capture());
232+
TransferListener.Context.TransferInitiated ctx1 = captor1.getValue();
233+
assertThat(ctx1.request()).isSameAs(downloadRequest);
234+
// transferSize is not known until we receive GetObjectResponse header
235+
assertThat(ctx1.progressSnapshot().transferSizeInBytes()).isNotPresent();
236+
assertThat(ctx1.progressSnapshot().bytesTransferred()).isZero();
237+
238+
ArgumentCaptor<TransferListener.Context.BytesTransferred> captor2 =
239+
ArgumentCaptor.forClass(TransferListener.Context.BytesTransferred.class);
240+
verify(listener, timeout(1000).times(1)).bytesTransferred(captor2.capture());
241+
TransferListener.Context.BytesTransferred ctx2 = captor2.getValue();
242+
assertThat(ctx2.request()).isSameAs(downloadRequest);
243+
// transferSize should now be known
244+
assertThat(ctx2.progressSnapshot().transferSizeInBytes()).hasValue(contentLength);
245+
assertThat(ctx2.progressSnapshot().bytesTransferred()).isPositive();
246+
247+
ArgumentCaptor<TransferListener.Context.TransferComplete> captor3 =
248+
ArgumentCaptor.forClass(TransferListener.Context.TransferComplete.class);
249+
verify(listener, timeout(1000).times(1)).transferComplete(captor3.capture());
250+
TransferListener.Context.TransferComplete ctx3 = captor3.getValue();
251+
assertThat(ctx3.request()).isSameAs(downloadRequest);
252+
assertThat(ctx3.progressSnapshot().transferSizeInBytes()).hasValue(contentLength);
253+
assertThat(ctx3.progressSnapshot().bytesTransferred()).isEqualTo(contentLength);
254+
assertThat(ctx3.completedTransfer()).isSameAs(download.completionFuture().get());
255+
256+
download.completionFuture().join();
257+
verifyNoMoreInteractions(listener);
258+
}
259+
260+
@Test
261+
public void uploadFile_failure_shouldInvokeListener() throws Exception {
171262
TransferListener listener = mock(TransferListener.class);
172263

173264
Path path = newTempFile();

0 commit comments

Comments
 (0)