Updated Branches:
  refs/heads/master 342ae6597 -> 6cc8e36f4

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/6cc8e36f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/tree/6cc8e36f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-jclouds/diff/6cc8e36f

Branch: refs/heads/master
Commit: 6cc8e36f439ec317ba618a0aa41c2a0e11165098
Parents: 342ae65
Author: Andrew Gaul <[email protected]>
Authored: Tue Sep 10 21:29:59 2013 -0700
Committer: Andrew Gaul <[email protected]>
Committed: Wed Sep 11 16:10:45 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/6cc8e36f/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/6cc8e36f/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/6cc8e36f/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 365dc57..0381909 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);
 

http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/6cc8e36f/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 027c7d2..5e5d3c9 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();

Reply via email to