Skip to content

Commit

Permalink
Add a method to get S3 URI from a SimpleStorageResource.
Browse files Browse the repository at this point in the history
  • Loading branch information
tmnuwan12 authored and maciejwalkowiak committed Jun 7, 2020
1 parent 52f2fc5 commit 1d0b6fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -147,6 +149,15 @@ public URL getURL() throws IOException {
"/" + this.bucketName + "/" + encodedObjectName);
}

public URI getS3Uri() {
try {
return new URI("s3", "//" + this.bucketName + "/" + this.objectName, null);
}
catch (URISyntaxException e) {
throw new RuntimeException("Failed to resolve s3:// uri", e);
}
}

@Override
public File getFile() throws IOException {
throw new UnsupportedOperationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,21 @@ public void getUrl_existingObject_returnsUrlWithS3Prefix() throws Exception {

}

@Test
public void getUrl_existingObject_returnsUrlWithS3Scheme() throws Exception {

AmazonS3Client amazonS3 = mock(AmazonS3Client.class);

// Act
SimpleStorageResource simpleStorageResource = new SimpleStorageResource(amazonS3,
"bucket", "object", new SyncTaskExecutor());

// Assert
assertThat(simpleStorageResource.getS3Uri())
.isEqualTo(new URI("s3://bucket/object"));

}

@Test
public void getFile_existingObject_throwsMeaningFullException() throws Exception {

Expand Down

0 comments on commit 1d0b6fa

Please sign in to comment.