use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testCreateEmptyBlob.
@Test
public void testCreateEmptyBlob() {
String blobName = "test-create-empty-blob";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
Blob remoteBlob = storage.create(blob);
assertNotNull(remoteBlob);
assertEquals(blob.getBucket(), remoteBlob.getBucket());
assertEquals(blob.getName(), remoteBlob.getName());
byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
assertArrayEquals(new byte[0], readBytes);
assertTrue(remoteBlob.delete());
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testCreateBlob.
@Test
public void testCreateBlob() {
String blobName = "test-create-blob";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
Blob remoteBlob = storage.create(blob, BLOB_BYTE_CONTENT);
assertNotNull(remoteBlob);
assertEquals(blob.getBucket(), remoteBlob.getBucket());
assertEquals(blob.getName(), remoteBlob.getName());
byte[] readBytes = storage.readAllBytes(BUCKET, blobName);
assertArrayEquals(BLOB_BYTE_CONTENT, readBytes);
assertTrue(remoteBlob.delete());
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testListBlobsEmptySelectedFields.
@Test(timeout = 5000)
public void testListBlobsEmptySelectedFields() throws InterruptedException {
String[] blobNames = { "test-list-blobs-empty-selected-fields-blob1", "test-list-blobs-empty-selected-fields-blob2" };
BlobInfo blob1 = BlobInfo.newBuilder(BUCKET, blobNames[0]).setContentType(CONTENT_TYPE).build();
BlobInfo blob2 = BlobInfo.newBuilder(BUCKET, blobNames[1]).setContentType(CONTENT_TYPE).build();
Blob remoteBlob1 = storage.create(blob1);
Blob remoteBlob2 = storage.create(blob2);
assertNotNull(remoteBlob1);
assertNotNull(remoteBlob2);
Page<Blob> page = storage.list(BUCKET, Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"), Storage.BlobListOption.fields());
// test fails if timeout is reached.
while (Iterators.size(page.iterateAll().iterator()) != 2) {
Thread.sleep(500);
page = storage.list(BUCKET, Storage.BlobListOption.prefix("test-list-blobs-empty-selected-fields-blob"), Storage.BlobListOption.fields());
}
Set<String> blobSet = ImmutableSet.of(blobNames[0], blobNames[1]);
Iterator<Blob> iterator = page.iterateAll().iterator();
while (iterator.hasNext()) {
Blob remoteBlob = iterator.next();
assertEquals(BUCKET, remoteBlob.getBucket());
assertTrue(blobSet.contains(remoteBlob.getName()));
assertNull(remoteBlob.getContentType());
}
assertTrue(remoteBlob1.delete());
assertTrue(remoteBlob2.delete());
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testComposeBlobWithContentType.
@Test
public void testComposeBlobWithContentType() {
String sourceBlobName1 = "test-compose-blob-with-content-type-source-1";
String sourceBlobName2 = "test-compose-blob-with-content-type-source-2";
BlobInfo sourceBlob1 = BlobInfo.newBuilder(BUCKET, sourceBlobName1).build();
BlobInfo sourceBlob2 = BlobInfo.newBuilder(BUCKET, sourceBlobName2).build();
Blob remoteSourceBlob1 = storage.create(sourceBlob1, BLOB_BYTE_CONTENT);
Blob remoteSourceBlob2 = storage.create(sourceBlob2, BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob1);
assertNotNull(remoteSourceBlob2);
String targetBlobName = "test-compose-blob-with-content-type-target";
BlobInfo targetBlob = BlobInfo.newBuilder(BUCKET, targetBlobName).setContentType(CONTENT_TYPE).build();
Storage.ComposeRequest req = Storage.ComposeRequest.of(ImmutableList.of(sourceBlobName1, sourceBlobName2), targetBlob);
Blob remoteTargetBlob = storage.compose(req);
assertNotNull(remoteTargetBlob);
assertEquals(targetBlob.getName(), remoteTargetBlob.getName());
assertEquals(targetBlob.getBucket(), remoteTargetBlob.getBucket());
assertEquals(CONTENT_TYPE, remoteTargetBlob.getContentType());
byte[] readBytes = storage.readAllBytes(BUCKET, targetBlobName);
byte[] composedBytes = Arrays.copyOf(BLOB_BYTE_CONTENT, BLOB_BYTE_CONTENT.length * 2);
System.arraycopy(BLOB_BYTE_CONTENT, 0, composedBytes, BLOB_BYTE_CONTENT.length, BLOB_BYTE_CONTENT.length);
assertArrayEquals(composedBytes, readBytes);
assertTrue(remoteSourceBlob1.delete());
assertTrue(remoteSourceBlob2.delete());
assertTrue(remoteTargetBlob.delete());
}
use of com.google.cloud.storage.BlobInfo in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testDeleteBlobNonExistingGeneration.
@Test
public void testDeleteBlobNonExistingGeneration() {
String blobName = "test-delete-blob-non-existing-generation";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
assertNotNull(storage.create(blob));
assertFalse(storage.delete(BlobId.of(BUCKET, blobName, -1L)));
}
Aggregations