S3DataTransferer implements DataTransfer { @Override public void transferProduct(Product product) throws DataTransferException, IOException { for (Reference ref : product.getProductReferences()) { String origRef = stripProtocol(ref.getOrigReference(), false); String dataStoreRef = stripProtocol(ref.getDataStoreReference(), true); try { PutObjectRequest request = new PutObjectRequest( bucketName, dataStoreRef, new File(origRef)); if (encrypt) { ObjectMetadata requestMetadata = new ObjectMetadata(); requestMetadata.setSSEAlgorithm(AES_256_SERVER_SIDE_ENCRYPTION); request.setMetadata(requestMetadata); } s3Client.putObject(request); } catch (AmazonClientException e) { throw new DataTransferException(String.format( "Failed to upload product reference %s to S3 at %s", origRef, dataStoreRef), e); } } } S3DataTransferer(AmazonS3 s3Client, String bucketName, boolean encrypt); @Override void setFileManagerUrl(URL url); @Override void transferProduct(Product product); @Override void retrieveProduct(Product product, File directory); @Override void deleteProduct(Product product);  }
@Test public void testTransferProduct() throws DataTransferException, IOException { dataTransferer.transferProduct(product); ArgumentCaptor<PutObjectRequest> argument = ArgumentCaptor.forClass(PutObjectRequest.class); verify(s3Client).putObject(argument.capture()); PutObjectRequest request = argument.getValue(); assertThat(request.getBucketName(), is(S3_BUCKET_NAME)); assertThat(request.getKey(), is(EXPECTED_DATA_STORE_REF)); assertThat(request.getFile().getAbsolutePath(), is(EXPECTED_ORGINAL_REF)); }