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 75432a6f36..841a86bea3 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() { 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 fb6273f675..b11fe1dbda 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"); + } } 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 365dc57e2d..03819096db 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 @@ -121,6 +121,11 @@ public class SwiftBlobIntegrationLiveTest extends BaseBlobIntegrationTest { } } + @Override + protected int getIncorrectContentMD5StatusCode() { + return 422; + } + protected void addMultipartBlobToContainer(String containerName, String key) throws IOException { File fileToUpload = createFileBiggerThan(PART_SIZE); 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 027c7d2aeb..5e5d3c9ec9 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; @@ -274,7 +276,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();