mirror of https://github.com/apache/jclouds.git
Add test for correct and incorrect contentMD5
Tested against atmos (skipped), aws-s3, azureblob, cloudfiles-us, and filesystem (skipped).
This commit is contained in:
parent
342ae65974
commit
6cc8e36f43
|
@ -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() {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
@ -275,6 +277,47 @@ public class BaseBlobIntegrationTest extends BaseBlobStoreIntegrationTest {
|
|||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue