@Test public void getObjectShouldCreateFileWithData() throws Exception { // given testee.putObject(PutObjectRequest.builder() .bucket("someBucket") .key("someKey") .build(), RequestBody.fromString("testdata")); //when Path tempFile = Files.createTempFile("test", "tmp"); testee.getObject(GetObjectRequest.builder() .bucket("someBucket") .key("someKey") .build(), tempFile); //then List<String> lines = Files.readAllLines(tempFile); assertThat(lines.get(0), is("testdata")); }
@Override public void setFeatureState(final FeatureState featureState) { try { final FeatureStateStorageWrapper storageWrapper = FeatureStateStorageWrapper.wrapperForFeatureState(featureState); final String json = objectMapper.writeValueAsString(storageWrapper); final PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucket(s3TogglzProperties.getBucketName()) .key(keyForFeature(featureState.getFeature())) .serverSideEncryption(ServerSideEncryption.AES256) .build(); final RequestBody requestBody = RequestBody.fromString(json); s3Client.putObject(putObjectRequest, requestBody); } catch (S3Exception | JsonProcessingException e) { throw new RuntimeException("Failed to set the feature state", e); } }
return putObject(PutObjectRequest.builder().applyMutation(putObjectRequest).build(), requestBody);
return putObject(PutObjectRequest.builder().applyMutation(putObjectRequest).build(), filePath);
return putObject(PutObjectRequest.builder().applyMutation(putObjectRequest).build(), requestBody);
return putObject(PutObjectRequest.builder().applyMutation(putObjectRequest).build(), sourcePath);
@Test public void deleteShouldRemoveItemsFromBucket() { // given PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucket("someBucket") .key("someObject") .build(); RequestBody requestBody = RequestBody.fromString("content"); testee.putObject(putObjectRequest, requestBody); testee.deleteObjects(DeleteObjectsRequest.builder().bucket("someBucket").delete(Delete.builder().objects (ObjectIdentifier.builder().key("someObject").build()).build()).build()); // when ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder() .bucket("someBucket") .build(); ListObjectsV2Response listObjectsV2Response = testee.listObjectsV2(listObjectsV2Request); //then assertThat(listObjectsV2Response.contents().size(), is(0)); }
@Test public void getObjectShouldReturnStreamWithData() throws Exception { // given testee.putObject(PutObjectRequest.builder() .bucket("someBucket") .key("someKey") .build(), RequestBody.fromString("testdata")); //when ResponseInputStream<GetObjectResponse> inputStream = testee.getObject(GetObjectRequest.builder() .bucket("someBucket") .key("someKey") .build()); //then String data = IoUtils.toUtf8String(inputStream); assertThat(data, is("testdata")); }
@Test public void shouldListObjectsInBucket() { // given PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucket("someBucket") .key("someObject") .build(); RequestBody requestBody = RequestBody.fromString("content"); testee.putObject(putObjectRequest, requestBody); // when ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder() .bucket("someBucket") .build(); ListObjectsV2Response listObjectsV2Response = testee.listObjectsV2(listObjectsV2Request); //then assertThat(listObjectsV2Response.contents().size(), is(1)); assertThat(listObjectsV2Response.contents().get(0).key(), is("someObject")); }
public void persistFeatureStateToS3(final FeatureState featureState) { try { final FeatureStateStorageWrapper storageWrapper = FeatureStateStorageWrapper.wrapperForFeatureState(featureState); final String json = objectMapper.writeValueAsString(storageWrapper); final PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucket(togglzProperties.getS3().getBucketName()) .key(keyForFeature(featureState.getFeature())) .serverSideEncryption(ServerSideEncryption.AES256) .build(); final RequestBody requestBody = RequestBody.fromString(json); s3Client.putObject(putObjectRequest, requestBody); } catch (final S3Exception | JsonProcessingException e) { throw new RuntimeException("Failed to set the feature state", e); } }
public void upload(final String bucketName, final File file) { final PutObjectResponse putObjectResponse = s3Client.putObject(PutObjectRequest.builder() .bucket(bucketName) .key(file.getName()) .build(), file.toPath()); LOG.debug("upload {} to bucket {}: ", file.getName(), bucketName, putObjectResponse.toString()); }