-
Notifications
You must be signed in to change notification settings - Fork 863
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Suppot mocking of s3ClientConfiguration to build S3TransferManager for unit test Java #2898
Comments
Hi @balajikarthickkbk, currently it's not supported to swap out the underlying S3 client used by the transfer manager, so it looks like your test is actually sending requests to S3. Marking this as a feature request. Would mocking S3TransferManager work in your use-case? |
have also tried mocking s3Transfermanager but it returns only Nullpointerexception, unit tes tcode where I have mocked S3TransferManager, the Null Pointer Exception in actual code when I mock S3TransferManager, so if mocking of S3ClientConfiguration is not supported now, how could we unit test S3TransferManager upload functionality, |
Hi @zoewangg any update on my previous question? so if mocking of S3ClientConfiguration is not supported now, how could we unit test S3TransferManager upload functionality, |
I believe you would need to mock the response of the S3TransferManager s3TransferManager = Mockito.mock(S3TransferManager.class);
FileUpload fileUpload = Mockito.mock(FileUpload.class);
UploadFileRequest uploadRequest = UploadFileRequest.builder()
.putObjectRequest(PutObjectRequest.builder().bucket("bucket").key(
"key").build())
.source(Paths.get("."))
.build();
Mockito.when(s3TransferManager.uploadFile(uploadRequest)).thenReturn(fileUpload); |
Thanks @zoewangg this helps in testing the upload functionality of S3TransferManager, However the actual method which am testing returns null when I mock S3TransferManager, my actual method, test code, |
It seems the UploadRequest mocked in the Could you make sure the request parameters are the same? |
have made both the UploadRequest mocked in the Mokito.when(s3TrasnferManager.upload(uploadRequest)).thenReturn(fileUpload) and actual UploadRequest being used parameters as same now, but still null pointer exception occurs in this line, CompletedUpload completedUpload = upload.completionFuture().join(); in my actual method as seen below, any final advice on this? my actual code block, ``public void transferObject(UploadRequest uploadRequest) {
my unit test code, `@Test
|
Yeah, I think you would need to mock the response of |
…94ef52b8e Pull request: release <- staging/baeb5fd3-6689-4694-ba51-04c94ef52b8e
Describe the issue
am using java aws sdk v2 S3TransferManager to upload files to s3.
At the moment am mocking s3ClientConfiguration using mockito 2.0 as below,
`
S3ClientConfiguration s3ClientConfiguration =mock(S3ClientConfiguration.class);
`
which throws me the error,
**java.util.concurrent.CompletionException: software.amazon.awssdk.services.s3.model.S3Exception: Invalid response status from request**
This is my actual code which contains the method transferobject for which am writing the unit test,
and this is my unit test code,
and this is my exception,
so what is the solution to figure out what the root cause is? or what is the right way to mock "S3ClientConfiguration" for unit test in java using aws sak v2.
Help is appreciated. Thank you.
Steps to Reproduce
See snippet above
Current behavior
unit test fails due to the exception, ava.util.concurrent.CompletionException: software.amazon.awssdk.services.s3.model.S3Exception: Invalid response status from request
AWS Java SDK version used
V2
JDK version used
1.8
Operating System and version
Windows
The text was updated successfully, but these errors were encountered: