Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method S3Operations#createResource. #1223

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ public interface S3Operations {
*/
S3Resource store(String bucketName, String key, Object object);

/**
* Creates an {@link S3Resource} for given bucket name and object key using {@link S3OutputStreamProvider}
* configured on the implementation class ({@link S3Template}).
* <p>
* Note that calling this method does not create an actual object on S3.
*
* @param bucketName - the bucket name
* @param key - the object key
* @return the {@link S3Resource}
*/
S3Resource createResource(String bucketName, String key);

/**
* Reads a Java object from a S3 bucket. Uses {@link S3ObjectConverter} for deserialization.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ public S3Resource store(String bucketName, String key, Object object) {
return new S3Resource(bucketName, key, s3Client, s3OutputStreamProvider);
}

@Override
public S3Resource createResource(String bucketName, String key) {
return new S3Resource(bucketName, key, s3Client, s3OutputStreamProvider);
}

@Override
public <T> T read(String bucketName, String key, Class<T> clazz) {
Assert.notNull(bucketName, "bucketName is required");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -77,4 +78,17 @@ void throwsExceptionWhenReadFails() {
});
}

@Test
void createsS3Resource() throws IOException {
S3OutputStream outputStream = mock(S3OutputStream.class);
when(s3OutputStreamProvider.create(eq("bucket"), eq("key"), any())).thenReturn(outputStream);

S3Resource resource = s3Template.createResource("bucket", "key");

assertThat(resource).isNotNull();
assertThat(resource.getOutputStream()).isEqualTo(outputStream);
assertThat(resource.getLocation().getBucket()).isEqualTo("bucket");
assertThat(resource.getLocation().getObject()).isEqualTo("key");
}

}
Loading