简体   繁体   English

创建模拟 S3Response object

[英]Creating a mock S3Response object

I have a piece of code that calls S3 API and it returns an object of [S3Response][1Ω type.我有一段代码调用 S3 API,它返回 [S3Response][1Ω 类型的 object。 But I want to create this S3Response object manually without calling the S3 API. How can I do that?但是我想在不调用 S3 API 的情况下手动创建此S3Response object。我该怎么做?

As far as I tested, the S3Response class does not expose any methods that you can use to instantiate an object and populate the values.据我测试, S3Response class 没有公开任何可用于实例化 object 和填充值的方法。 But at the end of the day, this is just another Java object so I'm guessing there is some way of creating an S3Response object from scratch without dealing with the S3 API.但归根结底,这只是另一个 Java object 所以我猜想有一些方法可以从头开始创建S3Response object 而无需处理 S3 API。

I'm not sure why you want to do this, but there are many implementations using the builder pattern you can use for example:我不确定你为什么要这样做,但是有许多使用你可以使用的构建器模式的实现,例如:

S3Response response = CreateBucketResponse.builder(). /*...*/ .build();
S3Response response = CopyObjectResponse.builder(). /*...*/ .build();
S3Response response = AbortMultipartUploadResponse.builder(). /*...*/ .build();
...
...

You can find the full list of implementations in the documentation Package software.amazon.awssdk.services.s3.model您可以在文档Package software.amazon.awssdk.services.s3.model中找到完整的实施列表

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM