use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testUpdateBlobMergeMetadata.
@Test
public void testUpdateBlobMergeMetadata() {
String blobName = "test-update-blob-merge-metadata";
ImmutableMap<String, String> metadata = ImmutableMap.of("k1", "a");
ImmutableMap<String, String> newMetadata = ImmutableMap.of("k2", "b");
ImmutableMap<String, String> expectedMetadata = ImmutableMap.of("k1", "a", "k2", "b");
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).setContentType(CONTENT_TYPE).setMetadata(metadata).build();
Blob remoteBlob = storage.create(blob);
assertNotNull(remoteBlob);
Blob updatedBlob = remoteBlob.toBuilder().setMetadata(newMetadata).build().update();
assertNotNull(updatedBlob);
assertEquals(blob.getName(), updatedBlob.getName());
assertEquals(blob.getBucket(), updatedBlob.getBucket());
assertEquals(expectedMetadata, updatedBlob.getMetadata());
assertTrue(updatedBlob.delete());
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testComposeBlobFail.
@Test
public void testComposeBlobFail() {
String sourceBlobName1 = "test-compose-blob-fail-source-1";
String sourceBlobName2 = "test-compose-blob-fail-source-2";
BlobInfo sourceBlob1 = BlobInfo.newBuilder(BUCKET, sourceBlobName1).build();
BlobInfo sourceBlob2 = BlobInfo.newBuilder(BUCKET, sourceBlobName2).build();
Blob remoteSourceBlob1 = storage.create(sourceBlob1);
Blob remoteSourceBlob2 = storage.create(sourceBlob2);
assertNotNull(remoteSourceBlob1);
assertNotNull(remoteSourceBlob2);
String targetBlobName = "test-compose-blob-fail-target";
BlobInfo targetBlob = BlobInfo.newBuilder(BUCKET, targetBlobName).build();
Storage.ComposeRequest req = Storage.ComposeRequest.newBuilder().addSource(sourceBlobName1, -1L).addSource(sourceBlobName2, -1L).setTarget(targetBlob).build();
try {
storage.compose(req);
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
assertTrue(remoteSourceBlob1.delete());
assertTrue(remoteSourceBlob2.delete());
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testGetBlobFailNonExistingGeneration.
@Test
public void testGetBlobFailNonExistingGeneration() {
String blobName = "test-get-blob-fail-non-existing-generation";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
Blob remoteBlob = storage.create(blob);
assertNotNull(remoteBlob);
BlobId wrongGenerationBlob = BlobId.of(BUCKET, blobName, -1L);
assertNull(storage.get(wrongGenerationBlob));
assertTrue(remoteBlob.delete());
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testCopyBlobWithEncryptionKeys.
@Test
public void testCopyBlobWithEncryptionKeys() {
String sourceBlobName = "test-copy-blob-encryption-key-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
Blob remoteBlob = storage.create(BlobInfo.newBuilder(source).build(), BLOB_BYTE_CONTENT, Storage.BlobTargetOption.encryptionKey(KEY));
assertNotNull(remoteBlob);
String targetBlobName = "test-copy-blob-encryption-key-target";
BlobInfo target = BlobInfo.newBuilder(BUCKET, targetBlobName).setContentType(CONTENT_TYPE).setMetadata(metadata).build();
Storage.CopyRequest req = Storage.CopyRequest.newBuilder().setSource(source).setTarget(target, Storage.BlobTargetOption.encryptionKey(OTHER_BASE64_KEY)).setSourceOptions(Storage.BlobSourceOption.decryptionKey(BASE64_KEY)).build();
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertArrayEquals(BLOB_BYTE_CONTENT, copyWriter.getResult().getContent(Blob.BlobSourceOption.decryptionKey(OTHER_BASE64_KEY)));
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
req = Storage.CopyRequest.newBuilder().setSource(source).setTarget(target).setSourceOptions(Storage.BlobSourceOption.decryptionKey(BASE64_KEY)).build();
copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertArrayEquals(BLOB_BYTE_CONTENT, copyWriter.getResult().getContent());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testCopyBlobUpdateMetadata.
@Test
public void testCopyBlobUpdateMetadata() {
String sourceBlobName = "test-copy-blob-update-metadata-source";
BlobId source = BlobId.of(BUCKET, sourceBlobName);
Blob remoteSourceBlob = storage.create(BlobInfo.newBuilder(source).build(), BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
String targetBlobName = "test-copy-blob-update-metadata-target";
ImmutableMap<String, String> metadata = ImmutableMap.of("k", "v");
BlobInfo target = BlobInfo.newBuilder(BUCKET, targetBlobName).setContentType(CONTENT_TYPE).setMetadata(metadata).build();
Storage.CopyRequest req = Storage.CopyRequest.of(source, target);
CopyWriter copyWriter = storage.copy(req);
assertEquals(BUCKET, copyWriter.getResult().getBucket());
assertEquals(targetBlobName, copyWriter.getResult().getName());
assertEquals(CONTENT_TYPE, copyWriter.getResult().getContentType());
assertEquals(metadata, copyWriter.getResult().getMetadata());
assertTrue(copyWriter.isDone());
assertTrue(remoteSourceBlob.delete());
assertTrue(storage.delete(BUCKET, targetBlobName));
}
Aggregations