S3BinaryStore extends AbstractBinaryStore { @Override public void storeExtractedText(BinaryValue binaryValue, String extractedText) throws BinaryStoreException { if (extractedText.length() > 2000) { throw new BinaryStoreException("S3 objects cannot store associated data that is larger than 2KB"); } setS3ObjectUserProperty(binaryValue.getKey().toString(), EXTRACTED_TEXT_KEY, extractedText); } S3BinaryStore(String accessKey, String secretKey, String bucketName);  S3BinaryStore(String accessKey, String secretKey, String bucketName, String endPoint);  S3BinaryStore( String accessKey,
                          String secretKey,
                          String bucketName,
                          String endPoint,
                          Boolean deleteUnusedNatively ); protected  S3BinaryStore(String bucketName, AmazonS3 s3Client, boolean deleteUnusedNatively); @Override void storeExtractedText(BinaryValue binaryValue, String extractedText); @Override String getExtractedText(BinaryValue binaryValue); @Override BinaryValue storeValue(InputStream stream, boolean markAsUnused); @Override InputStream getInputStream(BinaryKey key); @Override void markAsUsed(Iterable<BinaryKey> keys); @Override void markAsUnused(Iterable<BinaryKey> keys); @Override void removeValuesUnusedLongerThan(long minimumAge, TimeUnit timeUnit); @Override Iterable<BinaryKey> getAllBinaryKeys(); void migrateUnusedMetadataToTags();  }
@Test public void testStoreExtractedTextTooLong() { StringBuilder textBuilder = new StringBuilder(); for (int i = 0; i < 2001; i++) { textBuilder.append("a"); } String extractedText = textBuilder.toString(); replayAll(); BinaryValue binaryValue = createBinaryValue(TEST_KEY, TEST_CONTENT); try { s3BinaryStore.storeExtractedText(binaryValue, extractedText); fail("Exception expected due to long extracted text value"); } catch(BinaryStoreException e) { assertNotNull(e); } }
@Test public void testStoreExtractedText() throws BinaryStoreException { String extractedText = "text-that-has-been-extracted"; expect(s3Client.getObjectMetadata(BUCKET, TEST_KEY)) .andReturn(new ObjectMetadata()); Capture<CopyObjectRequest> copyRequestCapture = Capture.newInstance(); expect(s3Client.copyObject(capture(copyRequestCapture))).andReturn(null); replayAll(); BinaryValue binaryValue = createBinaryValue(TEST_KEY, TEST_CONTENT); s3BinaryStore.storeExtractedText(binaryValue, extractedText); CopyObjectRequest copyRequest = copyRequestCapture.getValue(); assertEquals(BUCKET, copyRequest.getSourceBucketName()); assertEquals(BUCKET, copyRequest.getDestinationBucketName()); assertEquals(TEST_KEY, copyRequest.getSourceKey()); assertEquals(TEST_KEY, copyRequest.getDestinationKey()); assertEquals(extractedText, copyRequest.getNewObjectMetadata() .getUserMetadata() .get(S3BinaryStore.EXTRACTED_TEXT_KEY)); }