[Java] Test S3 upload / download using "S3 ninja"

The test dummy server for S3 is Fake S3. I heard that it seems to be Ruby, and since I am a Java shop, I searched for Java, and found S3 ninja.

S3 ninja


So let's use it. Let's do so. Fake S3 is coming again.

Write a test code

Normally it seems to download and use it, but since it is troublesome, this time I will install it with maven and force it to start with Junit.




JUnit code


	static {
		//Dig the required folder
		try {
		} catch (IOException e) {

		//Start s3ninja
		Thread thread = new Thread(() -> {
			try {
				Method main = Class.forName("IPL").getMethod("main", new Class[] { String[].class });
				main.invoke(null, (Object) new String[0]);
			} catch (Exception e) {
				throw new RuntimeException(e);

		try {
			Thread.sleep(1000);//Just in case
		} catch (InterruptedException e) {


	public void test() throws IOException {
		AmazonS3 s3 = AmazonS3Client.builder()
				.withEndpointConfiguration(new EndpointConfiguration("http://localhost:9444/s3", null))
				.withCredentials(new AWSStaticCredentialsProvider(
				.withClientConfiguration(new ClientConfiguration().withSignerOverride("S3SignerType"))

		s3.putObject(new PutObjectRequest("bucket", "s3test.txt", new File("test.txt")));

		try (S3Object s3Object = s3.getObject(new GetObjectRequest("bucket", "s3test.txt"));
				InputStream input = s3Object.getObjectContent()) {
			assertThat(IOUtils.toByteArray(input), is(Files.readAllBytes(Paths.get("test.txt"))));



reference: I put in a local S3 ninja

Recommended Posts

[Java] Test S3 upload / download using "S3 ninja"
Upload and download notes in java on S3
Image upload using CarrierWave ~ Rspec test ~
[Note] Download from S3, upload to S3
Upload a file using Java HttpURLConnection
Upload / download / bulk delete data to S3 using Amazon S3 Client Builder with AWS SDK for Java
Primality test Java
Try using JobScheduler's REST-API --Java RestClient Test class-
Story of test automation using Appium [Android / java]
Sorting using java comparator
Comfortable download with JAVA
Scraping practice using Java ②
Java Unit Test Library-Artery-Sample
Scraping practice using Java ①
Download Java with Ansible