forked from awslabs/aws-java-nio-spi-for-s3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(Files): Add integration tests for Files.copy / read* from issue a…
…wslabs#236 [skip ci]
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/integrationTest/java/software/amazon/nio/spi/s3/FilesCopyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package software.amazon.nio.spi.s3; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static software.amazon.nio.spi.s3.Containers.localStackConnectionEndpoint; | ||
import static software.amazon.nio.spi.s3.Containers.putObject; | ||
|
||
@DisplayName("Files$copy should load file contents from localstack") | ||
public class FilesCopyTest | ||
{ | ||
@TempDir | ||
Path tempDir; | ||
|
||
@Test | ||
@DisplayName("when doing copy of existing file") | ||
public void fileCopyShouldCopyFileWhenFileFound() throws IOException { | ||
Containers.createBucket("sink"); | ||
putObject("sink", "files-copy.txt", "some content"); | ||
final Path path = Paths.get(URI.create(localStackConnectionEndpoint() + "/sink/files-copy.txt")); | ||
Path copiedFile = Files.copy(path, tempDir.resolve("sample-file-local.txt")); | ||
assertThat(copiedFile).hasContent("some content"); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/integrationTest/java/software/amazon/nio/spi/s3/FilesReadTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package software.amazon.nio.spi.s3; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
import static org.assertj.core.api.BDDAssertions.then; | ||
import static software.amazon.nio.spi.s3.Containers.localStackConnectionEndpoint; | ||
import static software.amazon.nio.spi.s3.Containers.putObject; | ||
|
||
@DisplayName("Files$read* should load file contents from localstack") | ||
public class FilesReadTest | ||
{ | ||
private final Path path = Paths.get(URI.create(localStackConnectionEndpoint() + "/sink/files-read.txt")); | ||
|
||
@BeforeAll | ||
public static void createBucketAndFile(){ | ||
Containers.createBucket("sink"); | ||
putObject("sink", "files-read.txt", "some content"); | ||
} | ||
|
||
@Test | ||
@DisplayName("when doing readAllBytes from existing file in s3") | ||
public void fileReadAllBytesShouldReturnFileContentsWhenFileFound() throws IOException { | ||
then(Files.readAllBytes(path)).isEqualTo("some content".getBytes()); | ||
} | ||
|
||
@Test | ||
@DisplayName("when doing readAllLines from existing file in s3") | ||
public void fileReadAllLinesShouldReturnFileContentWhenFileFound() throws IOException { | ||
then(String.join("", Files.readAllLines(path))).isEqualTo("some content"); | ||
} | ||
|
||
} |