Updated Branches: refs/heads/1.6.x 48a12b0ce -> 5527fae06
Add test for correct and incorrect contentMD5 Tested against atmos (skipped), aws-s3, azureblob, cloudfiles-us, and filesystem (skipped). Project: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/commit/5527fae0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/5527fae0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/5527fae0 Branch: refs/heads/1.6.x Commit: 5527fae0610a4e5693f7a240280c0e955a3e71b3 Parents: 48a12b0 Author: Andrew Gaul <[email protected]> Authored: Tue Sep 10 21:29:59 2013 -0700 Committer: Andrew Gaul <[email protected]> Committed: Wed Sep 11 16:14:35 2013 -0700 ---------------------------------------------------------------------- .../integration/AtmosIntegrationLiveTest.java | 6 +++ .../FilesystemBlobIntegrationTest.java | 5 +++ .../SwiftBlobIntegrationLiveTest.java | 5 +++ .../internal/BaseBlobIntegrationTest.java | 45 +++++++++++++++++++- 4 files changed, 60 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/5527fae0/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java ---------------------------------------------------------------------- diff --git a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java index 75432a6..841a86b 100644 --- a/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java +++ b/apis/atmos/src/test/java/org/jclouds/atmos/blobstore/integration/AtmosIntegrationLiveTest.java @@ -24,6 +24,7 @@ import java.util.concurrent.ExecutionException; import org.jclouds.blobstore.domain.Blob; import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.integration.internal.BaseBlobIntegrationTest; +import org.testng.SkipException; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; @@ -112,6 +113,11 @@ public class AtmosIntegrationLiveTest extends BaseBlobIntegrationTest { assertEquals(metadata.getContentMetadata().getContentMD5(), null); } + @Override + public void testPutIncorrectContentMD5() throws InterruptedException, IOException { + throw new SkipException("not yet implemented"); + } + @Test(enabled = false) // problem with the stub and md5, live is fine public void testMetadata() { http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/5527fae0/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTest.java ---------------------------------------------------------------------- diff --git a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTest.java b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTest.java index fb6273f..b11fe1d 100644 --- a/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTest.java +++ b/apis/filesystem/src/test/java/org/jclouds/filesystem/integration/FilesystemBlobIntegrationTest.java @@ -82,4 +82,9 @@ public class FilesystemBlobIntegrationTest extends BaseBlobIntegrationTest { public void testPutObjectStream() throws InterruptedException, IOException, ExecutionException { throw new SkipException("not yet implemented"); } + + @Override + public void testPutIncorrectContentMD5() throws InterruptedException, IOException { + throw new SkipException("not yet implemented"); + } } http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/5527fae0/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java ---------------------------------------------------------------------- diff --git a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java index 57e381a..819fe83 100644 --- a/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java +++ b/apis/swift/src/test/java/org/jclouds/openstack/swift/blobstore/integration/SwiftBlobIntegrationLiveTest.java @@ -105,4 +105,9 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest { returnContainer(containerName); } } + + @Override + protected int getIncorrectContentMD5StatusCode() { + return 422; + } } http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/5527fae0/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java ---------------------------------------------------------------------- diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java index a6bcb6d..d96393e 100644 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/BaseBlobIntegrationTest.java @@ -28,6 +28,7 @@ import static org.jclouds.io.ByteSources.asByteSource; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNotNull; import static org.testng.Assert.assertNull; +import static org.testng.Assert.fail; import java.io.ByteArrayInputStream; import java.io.File; @@ -79,6 +80,7 @@ import com.google.common.base.Throwables; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Iterables; import com.google.common.collect.Maps; +import com.google.common.hash.HashCode; import com.google.common.io.ByteStreams; import com.google.common.io.Files; import com.google.common.io.InputSupplier; @@ -267,7 +269,48 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest { returnContainer(container); } } - + + private void putBlobWithMd5(byte[] payload, HashCode contentMD5) throws InterruptedException, IOException { + String container = getContainerName(); + BlobStore blobStore = view.getBlobStore(); + try { + String blobName = "putBlobWithMd5-" + new Random().nextLong(); + Blob blob = blobStore + .blobBuilder(blobName) + .payload(payload) + .contentMD5(contentMD5.asBytes()) + .build(); + blobStore.putBlob(container, blob); + } finally { + returnContainer(container); + } + } + + protected int getIncorrectContentMD5StatusCode() { + return 400; + } + + @Test(groups = { "integration", "live" }) + public void testPutCorrectContentMD5() throws InterruptedException, IOException { + byte[] payload = ByteStreams.toByteArray(createTestInput(1024)); + HashCode contentMD5 = md5().hashBytes(payload); + putBlobWithMd5(payload, contentMD5); + } + + @Test(groups = { "integration", "live" }) + public void testPutIncorrectContentMD5() throws InterruptedException, IOException { + byte[] payload = ByteStreams.toByteArray(createTestInput(1024)); + HashCode contentMD5 = md5().hashBytes(new byte[0]); + try { + putBlobWithMd5(payload, contentMD5); + fail(); + } catch (HttpResponseException hre) { + if (hre.getResponse().getStatusCode() != getIncorrectContentMD5StatusCode()) { + throw hre; + } + } + } + @Test(groups = { "integration", "live" }) public void testGetIfUnmodifiedSince() throws InterruptedException { String container = getContainerName();
