我已采用参考表here来实现集成测试的S3模拟
我的困惑和我没有得到的部分是我如何在这里使用docker?
我需要安装一些东西吗?
我刚刚在Maven中添加了以下代码
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-datapipeline</artifactId>
<version>1.11.295</version>
</dependency>
并写了下课
package com.amazonaws.lambda.demo;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.AnonymousAWSCredentials;
import com.amazonaws.client.builder.AwsClientBuilder;
import com.amazonaws.client.builder.AwsClientBuilder.EndpointConfiguration;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Builder;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import io.findify.s3mock.S3Mock;
public class S3Mock {
S3Mock api = new S3Mock.Builder().withPort(8001).withInMemoryBackend().build();
api.start();
AmazonS3Client client = new AmazonS3Client(new AnonymousAWSCredentials());
// use local API mock, not the AWS one
client.setEndpoint("http://127.0.0.1:8001");
client.createBucket("testbucket");
client.putObject("testbucket", "file/name", "contents");
}
但是我自己不能自己上课。
可以帮我理解做这项工作的其他事情吗。
最佳答案
我相信您已经错过了Maven随附的S3Mock依赖项:
<dependency>
<groupId>io.findify</groupId>
<artifactId>s3mock_2.12</artifactId>
<version>0.2.5</version>
<scope>test</scope>
</dependency>
另外,我建议您将类从
S3Mock
重命名为AmazonS3Mock
之类,以避免名称空间混乱