use of com.google.cloud.storage.StorageException in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testCopyBlobFail.
@Test
public void testCopyBlobFail() {
String sourceBlobName = "test-copy-blob-source-fail";
BlobId source = BlobId.of(BUCKET, sourceBlobName, -1L);
Blob remoteSourceBlob = storage.create(BlobInfo.newBuilder(source).build(), BLOB_BYTE_CONTENT);
assertNotNull(remoteSourceBlob);
String targetBlobName = "test-copy-blob-target-fail";
BlobInfo target = BlobInfo.newBuilder(BUCKET, targetBlobName).setContentType(CONTENT_TYPE).build();
Storage.CopyRequest req = Storage.CopyRequest.newBuilder().setSource(BUCKET, sourceBlobName).setSourceOptions(Storage.BlobSourceOption.generationMatch(-1L)).setTarget(target).build();
try {
storage.copy(req);
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
Storage.CopyRequest req2 = Storage.CopyRequest.newBuilder().setSource(source).setSourceOptions(Storage.BlobSourceOption.generationMatch()).setTarget(target).build();
try {
storage.copy(req2);
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
assertTrue(remoteSourceBlob.delete());
}
use of com.google.cloud.storage.StorageException in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testCreateBlobMd5Fail.
@Test
public void testCreateBlobMd5Fail() {
String blobName = "test-create-blob-md5-fail";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).setContentType(CONTENT_TYPE).setMd5("O1R4G1HJSDUISJjoIYmVhQ==").build();
ByteArrayInputStream stream = new ByteArrayInputStream(BLOB_STRING_CONTENT.getBytes(UTF_8));
try {
storage.create(blob, stream, Storage.BlobWriteOption.md5Match());
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
}
use of com.google.cloud.storage.StorageException 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.StorageException in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testWriteChannelFail.
@Test
public void testWriteChannelFail() throws IOException {
String blobName = "test-write-channel-blob-fail";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName, -1L).build();
try {
try (WriteChannel writer = storage.writer(blob, Storage.BlobWriteOption.generationMatch())) {
writer.write(ByteBuffer.allocate(42));
}
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
}
use of com.google.cloud.storage.StorageException in project google-cloud-java by GoogleCloudPlatform.
the class ITStorageTest method testDeleteBlobFail.
@Test
public void testDeleteBlobFail() {
String blobName = "test-delete-blob-fail";
BlobInfo blob = BlobInfo.newBuilder(BUCKET, blobName).build();
Blob remoteBlob = storage.create(blob);
assertNotNull(remoteBlob);
try {
storage.delete(BUCKET, blob.getName(), Storage.BlobSourceOption.generationMatch(-1L));
fail("StorageException was expected");
} catch (StorageException ex) {
// expected
}
assertTrue(remoteBlob.delete());
}
Aggregations