options.ifMatch(ifMatch);
options.ifMatch(ifMatch);
options.ifMatch(ifMatch);
builder.ifMatch(ifMatch);
@Test(groups = { "integration", "live" }) public void testCopyIfMatch() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { String eTag = blobStore.putBlob(fromContainer, blob); blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifMatch(eTag).build()); Blob toBlob = blobStore.getBlob(toContainer, toName); InputStream is = null; try { is = toBlob.getPayload().openStream(); assertEquals(ByteStreams.toByteArray(is), payload.read()); } finally { Closeables2.closeQuietly(is); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }
@Test(groups = { "integration", "live" }) public void testCopyIfMatchNegative() throws Exception { BlobStore blobStore = view.getBlobStore(); String fromName = "source"; String toName = "to"; ByteSource payload = TestUtils.randomByteSource().slice(0, 1024); Blob blob = blobStore .blobBuilder(fromName) .payload(payload) .contentLength(payload.size()) .build(); String fromContainer = getContainerName(); String toContainer = getContainerName(); try { blobStore.putBlob(fromContainer, blob); try { blobStore.copyBlob(fromContainer, fromName, toContainer, toName, CopyOptions.builder().ifMatch("fake-etag").build()); Fail.failBecauseExceptionWasNotThrown(HttpResponseException.class); } catch (HttpResponseException hre) { assertThat(hre.getResponse().getStatusCode()).isEqualTo(412); } } finally { returnContainer(toContainer); returnContainer(fromContainer); } }