Java Code Examples for com.google.cloud.storage.Storage#BlobWriteOption
The following examples show how to use
com.google.cloud.storage.Storage#BlobWriteOption .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PutGCSObjectTest.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testSuccessfulPutOperationNoParameters() throws Exception { reset(storage, blob); final PutGCSObject processor = getProcessor(); final TestRunner runner = buildNewRunner(processor); addRequiredPropertiesToRunner(runner); runner.assertValid(); when(storage.create(blobInfoArgumentCaptor.capture(), inputStreamArgumentCaptor.capture(), blobWriteOptionArgumentCaptor.capture())).thenReturn(blob); runner.enqueue("test"); runner.run(); runner.assertAllFlowFilesTransferred(PutGCSObject.REL_SUCCESS); runner.assertTransferCount(PutGCSObject.REL_SUCCESS, 1); /** Can't do this any more due to the switch to Java InputStreams which close after an operation **/ /* String text; try (final Reader reader = new InputStreamReader(inputStreamArgumentCaptor.getValue())) { text = CharStreams.toString(reader); } assertEquals( "FlowFile content should be equal to the Blob content", "test", text ); */ final List<Storage.BlobWriteOption> blobWriteOptions = blobWriteOptionArgumentCaptor.getAllValues(); assertEquals("No BlobWriteOptions should be set", 0, blobWriteOptions.size()); final BlobInfo blobInfo = blobInfoArgumentCaptor.getValue(); assertNull(blobInfo.getMd5()); assertNull(blobInfo.getContentDisposition()); assertNull(blobInfo.getCrc32c()); }
Example 2
Source File: PutGCSObjectTest.java From localization_nifi with Apache License 2.0 | 4 votes |
@Test public void testSuccessfulPutOperation() throws Exception { reset(storage, blob); final PutGCSObject processor = getProcessor(); final TestRunner runner = buildNewRunner(processor); addRequiredPropertiesToRunner(runner); runner.setProperty(PutGCSObject.KEY, KEY); runner.setProperty(PutGCSObject.CONTENT_TYPE, CONTENT_TYPE); runner.setProperty(PutGCSObject.MD5, MD5); runner.setProperty(PutGCSObject.CRC32C, CRC32C); runner.setProperty(PutGCSObject.ACL, ACL.name()); runner.setProperty(PutGCSObject.ENCRYPTION_KEY, ENCRYPTION_KEY); runner.setProperty(PutGCSObject.OVERWRITE, String.valueOf(OVERWRITE)); runner.setProperty(PutGCSObject.CONTENT_DISPOSITION_TYPE, CONTENT_DISPOSITION_TYPE); runner.assertValid(); when(storage.create(blobInfoArgumentCaptor.capture(), inputStreamArgumentCaptor.capture(), blobWriteOptionArgumentCaptor.capture())).thenReturn(blob); runner.enqueue("test", ImmutableMap.of(CoreAttributes.FILENAME.key(), FILENAME)); runner.run(); runner.assertAllFlowFilesTransferred(PutGCSObject.REL_SUCCESS); runner.assertTransferCount(PutGCSObject.REL_SUCCESS, 1); /* String text; try (final Reader reader = new InputStreamReader(inputStreamArgumentCaptor.getValue())) { text = CharStreams.toString(reader); } assertEquals( "FlowFile content should be equal to the Blob content", "test", text ); */ final BlobInfo blobInfo = blobInfoArgumentCaptor.getValue(); assertEquals( BUCKET, blobInfo.getBucket() ); assertEquals( KEY, blobInfo.getName() ); assertEquals( CONTENT_DISPOSITION_TYPE + "; filename=" + FILENAME, blobInfo.getContentDisposition() ); assertEquals( CONTENT_TYPE, blobInfo.getContentType() ); assertEquals( MD5, blobInfo.getMd5() ); assertEquals( CRC32C, blobInfo.getCrc32c() ); assertNull(blobInfo.getMetadata()); final List<Storage.BlobWriteOption> blobWriteOptions = blobWriteOptionArgumentCaptor.getAllValues(); final Set<Storage.BlobWriteOption> blobWriteOptionSet = ImmutableSet.copyOf(blobWriteOptions); assertEquals( "Each of the BlobWriteOptions should be unique", blobWriteOptions.size(), blobWriteOptionSet.size() ); assertTrue("The doesNotExist BlobWriteOption should be set if OVERWRITE is false", blobWriteOptionSet.contains(Storage.BlobWriteOption.doesNotExist())); assertTrue("The md5Match BlobWriteOption should be set if MD5 is non-null", blobWriteOptionSet.contains(Storage.BlobWriteOption.md5Match())); assertTrue("The crc32cMatch BlobWriteOption should be set if CRC32C is non-null", blobWriteOptionSet.contains(Storage.BlobWriteOption.crc32cMatch())); assertTrue("The predefinedAcl BlobWriteOption should be set if ACL is non-null", blobWriteOptionSet.contains(Storage.BlobWriteOption.predefinedAcl(ACL))); assertTrue("The encryptionKey BlobWriteOption should be set if ENCRYPTION_KEY is non-null", blobWriteOptionSet.contains(Storage.BlobWriteOption.encryptionKey(ENCRYPTION_KEY))); }
Example 3
Source File: PutGCSObjectTest.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testSuccessfulPutOperationNoParameters() throws Exception { reset(storage, blob); final PutGCSObject processor = getProcessor(); final TestRunner runner = buildNewRunner(processor); addRequiredPropertiesToRunner(runner); runner.assertValid(); when(storage.create(blobInfoArgumentCaptor.capture(), inputStreamArgumentCaptor.capture(), blobWriteOptionArgumentCaptor.capture())).thenReturn(blob); runner.enqueue("test"); runner.run(); runner.assertAllFlowFilesTransferred(PutGCSObject.REL_SUCCESS); runner.assertTransferCount(PutGCSObject.REL_SUCCESS, 1); /** Can't do this any more due to the switch to Java InputStreams which close after an operation **/ /* String text; try (final Reader reader = new InputStreamReader(inputStreamArgumentCaptor.getValue())) { text = CharStreams.toString(reader); } assertEquals( "FlowFile content should be equal to the Blob content", "test", text ); */ final List<Storage.BlobWriteOption> blobWriteOptions = blobWriteOptionArgumentCaptor.getAllValues(); assertEquals("No BlobWriteOptions should be set", 0, blobWriteOptions.size()); final BlobInfo blobInfo = blobInfoArgumentCaptor.getValue(); assertNull(blobInfo.getMd5()); assertNull(blobInfo.getContentDisposition()); assertNull(blobInfo.getCrc32c()); }
Example 4
Source File: PutGCSObjectTest.java From nifi with Apache License 2.0 | 4 votes |
@Test public void testSuccessfulPutOperation() throws Exception { reset(storage, blob); final PutGCSObject processor = getProcessor(); final TestRunner runner = buildNewRunner(processor); addRequiredPropertiesToRunner(runner); runner.setProperty(PutGCSObject.KEY, KEY); runner.setProperty(PutGCSObject.CONTENT_TYPE, CONTENT_TYPE); runner.setProperty(PutGCSObject.MD5, MD5); runner.setProperty(PutGCSObject.CRC32C, CRC32C); runner.setProperty(PutGCSObject.ACL, ACL.name()); runner.setProperty(PutGCSObject.ENCRYPTION_KEY, ENCRYPTION_KEY); runner.setProperty(PutGCSObject.OVERWRITE, String.valueOf(OVERWRITE)); runner.setProperty(PutGCSObject.CONTENT_DISPOSITION_TYPE, CONTENT_DISPOSITION_TYPE); runner.assertValid(); when(storage.create(blobInfoArgumentCaptor.capture(), inputStreamArgumentCaptor.capture(), blobWriteOptionArgumentCaptor.capture())).thenReturn(blob); runner.enqueue("test", ImmutableMap.of(CoreAttributes.FILENAME.key(), FILENAME)); runner.run(); runner.assertAllFlowFilesTransferred(PutGCSObject.REL_SUCCESS); runner.assertTransferCount(PutGCSObject.REL_SUCCESS, 1); /* String text; try (final Reader reader = new InputStreamReader(inputStreamArgumentCaptor.getValue())) { text = CharStreams.toString(reader); } assertEquals( "FlowFile content should be equal to the Blob content", "test", text ); */ final BlobInfo blobInfo = blobInfoArgumentCaptor.getValue(); assertEquals( BUCKET, blobInfo.getBucket() ); assertEquals( KEY, blobInfo.getName() ); assertEquals( CONTENT_DISPOSITION_TYPE + "; filename=" + FILENAME, blobInfo.getContentDisposition() ); assertEquals( CONTENT_TYPE, blobInfo.getContentType() ); assertEquals( MD5, blobInfo.getMd5() ); assertEquals( CRC32C, blobInfo.getCrc32c() ); assertNull(blobInfo.getMetadata()); final List<Storage.BlobWriteOption> blobWriteOptions = blobWriteOptionArgumentCaptor.getAllValues(); final Set<Storage.BlobWriteOption> blobWriteOptionSet = ImmutableSet.copyOf(blobWriteOptions); assertEquals( "Each of the BlobWriteOptions should be unique", blobWriteOptions.size(), blobWriteOptionSet.size() ); assertTrue("The doesNotExist BlobWriteOption should be set if OVERWRITE is false", blobWriteOptionSet.contains(Storage.BlobWriteOption.doesNotExist())); assertTrue("The md5Match BlobWriteOption should be set if MD5 is non-null", blobWriteOptionSet.contains(Storage.BlobWriteOption.md5Match())); assertTrue("The crc32cMatch BlobWriteOption should be set if CRC32C is non-null", blobWriteOptionSet.contains(Storage.BlobWriteOption.crc32cMatch())); assertTrue("The predefinedAcl BlobWriteOption should be set if ACL is non-null", blobWriteOptionSet.contains(Storage.BlobWriteOption.predefinedAcl(ACL))); assertTrue("The encryptionKey BlobWriteOption should be set if ENCRYPTION_KEY is non-null", blobWriteOptionSet.contains(Storage.BlobWriteOption.encryptionKey(ENCRYPTION_KEY))); }