Updated JetS3t impl tests to follow new testing procedure (see Issue 57)

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1452 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
jamurty 2009-06-21 00:29:12 +00:00
parent be824d757f
commit 8ea84a656a
1 changed files with 350 additions and 308 deletions

View File

@ -99,358 +99,400 @@ public class JCloudsS3ServiceIntegrationTest extends S3IntegrationTest {
@Test @Test
public void testCreateBucketImpl() throws S3ServiceException, InterruptedException, public void testCreateBucketImpl() throws S3ServiceException, InterruptedException,
ExecutionException { ExecutionException, TimeoutException
S3Bucket bucket = service.createBucket(new S3Bucket(bucketName)); {
assertEquals(bucket.getName(), bucketName); String bucketName = getScratchBucketName();
assertTrue(client.bucketExists(bucketName).get()); try {
S3Bucket bucket = service.createBucket(new S3Bucket(bucketName));
assertEquals(bucket.getName(), bucketName);
assertTrue(client.bucketExists(bucketName).get());
} finally {
returnScratchBucket(bucketName);
}
} }
@Test @Test
@AfterSuite @AfterSuite
public void testDeleteBucketImpl() throws S3ServiceException, InterruptedException, public void testDeleteBucketImpl() throws S3ServiceException, InterruptedException,
ExecutionException, TimeoutException { ExecutionException, TimeoutException {
emptyBucket(bucketName); String bucketName = getScratchBucketName();
try {
service.deleteBucket(bucketName); service.deleteBucket(bucketName);
assertFalse(client.bucketExists(bucketName).get(10, TimeUnit.SECONDS)); assertFalse(client.bucketExists(bucketName).get(10, TimeUnit.SECONDS));
} finally {
returnScratchBucket(bucketName);
}
} }
@Test(dependsOnMethods = "testCreateBucketImpl") @Test(dependsOnMethods = "testCreateBucketImpl")
public void testDeleteObjectImpl() throws InterruptedException, ExecutionException, public void testDeleteObjectImpl() throws InterruptedException, ExecutionException,
TimeoutException, S3ServiceException, IOException { TimeoutException, S3ServiceException, IOException
String objectKey = "key-testDeleteObjectImpl"; {
String objectValue = "test"; String bucketName = getBucketName();
try {
org.jclouds.aws.s3.domain.S3Object s3Object = new org.jclouds.aws.s3.domain.S3Object( String objectKey = "key-testDeleteObjectImpl";
objectKey, objectValue); String objectValue = "test";
addObjectToBucket(bucketName, s3Object);
org.jclouds.aws.s3.domain.S3Object s3Object = new org.jclouds.aws.s3.domain.S3Object(
service.deleteObject(bucketName, objectKey); objectKey, objectValue);
addObjectToBucket(bucketName, s3Object);
assertEquals(client.headObject(bucketName, objectKey).get(10, TimeUnit.SECONDS),
org.jclouds.aws.s3.domain.S3Object.Metadata.NOT_FOUND); service.deleteObject(bucketName, objectKey);
assertEquals(client.headObject(bucketName, objectKey).get(10, TimeUnit.SECONDS),
org.jclouds.aws.s3.domain.S3Object.Metadata.NOT_FOUND);
} finally {
returnBucket(bucketName);
}
} }
@Test(dependsOnMethods = "testCreateBucketImpl") @Test(dependsOnMethods = "testCreateBucketImpl")
public void testGetObjectDetailsImpl() throws InterruptedException, ExecutionException, public void testGetObjectDetailsImpl() throws InterruptedException, ExecutionException,
TimeoutException, S3ServiceException, IOException { TimeoutException, S3ServiceException, IOException
String objectKey = "key-testGetObjectDetailsImpl"; {
String objectValue = "test"; String bucketName = getBucketName();
String metadataName = "metadata-name-1"; try {
String metadataValue = "metadata-value-1"; String objectKey = "key-testGetObjectDetailsImpl";
String objectValue = "test";
org.jclouds.aws.s3.domain.S3Object s3Object = new org.jclouds.aws.s3.domain.S3Object( String metadataName = "metadata-name-1";
objectKey, objectValue); String metadataValue = "metadata-value-1";
s3Object.getMetadata().getUserMetadata().put(S3Constants.USER_METADATA_PREFIX + metadataName,
metadataValue); org.jclouds.aws.s3.domain.S3Object s3Object = new org.jclouds.aws.s3.domain.S3Object(
addObjectToBucket(bucketName, s3Object); objectKey, objectValue);
s3Object.getMetadata().getUserMetadata().put(S3Constants.USER_METADATA_PREFIX + metadataName,
S3Object objectDetails = service.getObjectDetails(new S3Bucket(bucketName), objectKey); metadataValue);
addObjectToBucket(bucketName, s3Object);
assertEquals(objectDetails.getKey(), objectKey);
assertEquals(objectDetails.getContentLength(), 4); S3Object objectDetails = service.getObjectDetails(new S3Bucket(bucketName), objectKey);
assertNull(objectDetails.getDataInputStream());
assertEquals(objectDetails.getMetadata(metadataName), metadataValue); assertEquals(objectDetails.getKey(), objectKey);
assertEquals(objectDetails.getContentLength(), 4);
emptyBucket(bucketName); assertNull(objectDetails.getDataInputStream());
assertEquals(objectDetails.getMetadata(metadataName), metadataValue);
} finally {
returnBucket(bucketName);
}
} }
@Test(dependsOnMethods = "testCreateBucketImpl") @Test(dependsOnMethods = "testCreateBucketImpl")
public void testGetObjectImpl() throws InterruptedException, ExecutionException, public void testGetObjectImpl() throws InterruptedException, ExecutionException,
TimeoutException, S3ServiceException, IOException { TimeoutException, S3ServiceException, IOException
String objectKey = "key-testGetObjectImpl"; {
String objectValue = "test"; String bucketName = getBucketName();
String metadataName = "metadata-name-2"; try {
String metadataValue = "metadata-value-2"; String objectKey = "key-testGetObjectImpl";
String objectValue = "test";
org.jclouds.aws.s3.domain.S3Object s3Object = new org.jclouds.aws.s3.domain.S3Object( String metadataName = "metadata-name-2";
objectKey, objectValue); String metadataValue = "metadata-value-2";
s3Object.getMetadata().getUserMetadata().put(S3Constants.USER_METADATA_PREFIX + metadataName,
metadataValue); org.jclouds.aws.s3.domain.S3Object s3Object = new org.jclouds.aws.s3.domain.S3Object(
addObjectToBucket(bucketName, s3Object); objectKey, objectValue);
s3Object.getMetadata().getUserMetadata().put(S3Constants.USER_METADATA_PREFIX + metadataName,
S3Object object = service.getObject(new S3Bucket(bucketName), objectKey); metadataValue);
addObjectToBucket(bucketName, s3Object);
assertEquals(object.getKey(), objectKey);
assertNotNull(object.getDataInputStream()); S3Object object = service.getObject(new S3Bucket(bucketName), objectKey);
assertEquals(IOUtils.toString(object.getDataInputStream()), objectValue);
assertEquals(object.getContentLength(), objectValue.length()); assertEquals(object.getKey(), objectKey);
assertEquals(object.getMetadata(metadataName), metadataValue); assertNotNull(object.getDataInputStream());
assertEquals(IOUtils.toString(object.getDataInputStream()), objectValue);
// TODO: Test conditional gets assertEquals(object.getContentLength(), objectValue.length());
assertEquals(object.getMetadata(metadataName), metadataValue);
emptyBucket(bucketName);
// TODO: Test conditional gets
} finally {
returnBucket(bucketName);
}
} }
@Test(dependsOnMethods = "testCreateBucketImpl") @Test(dependsOnMethods = "testCreateBucketImpl")
public void testListAllBucketsImpl() throws InterruptedException, ExecutionException, public void testListAllBucketsImpl() throws InterruptedException, ExecutionException,
TimeoutException, S3ServiceException { TimeoutException, S3ServiceException
// Ensure there is at least 1 bucket in S3 account to list and compare. {
S3Bucket[] jsBuckets = service.listAllBuckets(); String bucketName = getBucketName();
try {
List<org.jclouds.aws.s3.domain.S3Bucket.Metadata> jcBuckets = client.listOwnedBuckets().get( // Ensure there is at least 1 bucket in S3 account to list and compare.
10, TimeUnit.SECONDS); S3Bucket[] jsBuckets = service.listAllBuckets();
assert jsBuckets.length == jcBuckets.size(); List<org.jclouds.aws.s3.domain.S3Bucket.Metadata> jcBuckets = client.listOwnedBuckets().get(
10, TimeUnit.SECONDS);
Iterator<org.jclouds.aws.s3.domain.S3Bucket.Metadata> jcBucketsIter = jcBuckets.iterator();
for (S3Bucket jsBucket : jsBuckets) { assert jsBuckets.length == jcBuckets.size();
assert jcBucketsIter.hasNext();
Iterator<org.jclouds.aws.s3.domain.S3Bucket.Metadata> jcBucketsIter = jcBuckets.iterator();
org.jclouds.aws.s3.domain.S3Bucket.Metadata jcBucket = jcBucketsIter.next(); for (S3Bucket jsBucket : jsBuckets) {
assert jsBucket.getName().equals(jcBucket.getName()); assert jcBucketsIter.hasNext();
org.jclouds.aws.s3.domain.S3Bucket.Metadata jcBucket = jcBucketsIter.next();
assert jsBucket.getName().equals(jcBucket.getName());
}
} finally {
returnBucket(bucketName);
} }
} }
@Test(dependsOnMethods = "testCreateBucketImpl") @Test(dependsOnMethods = "testCreateBucketImpl")
public void testListObjectsChunkedImpl() throws InterruptedException, ExecutionException, public void testListObjectsChunkedImpl() throws InterruptedException, ExecutionException,
TimeoutException, IOException, S3ServiceException { TimeoutException, IOException, S3ServiceException {
addObjectToBucket(bucketName, "item1/subobject2"); String bucketName = getBucketName();
addObjectToBucket(bucketName, "item2"); try {
addObjectToBucket(bucketName, "object1"); addObjectToBucket(bucketName, "item1/subobject2");
addObjectToBucket(bucketName, "object2/subobject1"); addObjectToBucket(bucketName, "item2");
addObjectToBucket(bucketName, "object1");
S3ObjectsChunk chunk; addObjectToBucket(bucketName, "object2/subobject1");
// Normal complete listing S3ObjectsChunk chunk;
chunk = service.listObjectsChunked(bucketName, null, null, 1000, null, true);
assertEquals(chunk.getObjects().length, 4); // Normal complete listing
assertEquals(chunk.getCommonPrefixes().length, 0); chunk = service.listObjectsChunked(bucketName, null, null, 1000, null, true);
assertNull(chunk.getDelimiter()); assertEquals(chunk.getObjects().length, 4);
assertNull(chunk.getPrefix()); assertEquals(chunk.getCommonPrefixes().length, 0);
assertNull(chunk.getPriorLastKey()); assertNull(chunk.getDelimiter());
assertNull(chunk.getPrefix());
// Partial listing assertNull(chunk.getPriorLastKey());
chunk = service.listObjectsChunked(bucketName, null, null, 2, null, false);
assertEquals(chunk.getObjects().length, 2); // Partial listing
assertEquals(chunk.getCommonPrefixes().length, 0); chunk = service.listObjectsChunked(bucketName, null, null, 2, null, false);
assertNull(chunk.getDelimiter()); assertEquals(chunk.getObjects().length, 2);
assertNull(chunk.getPrefix()); assertEquals(chunk.getCommonPrefixes().length, 0);
assertEquals(chunk.getPriorLastKey(), "item2"); assertNull(chunk.getDelimiter());
assertNull(chunk.getPrefix());
// Complete listing, in two chunks assertEquals(chunk.getPriorLastKey(), "item2");
chunk = service.listObjectsChunked(bucketName, null, null, 2, null, true);
assertEquals(chunk.getObjects().length, 4); // Complete listing, in two chunks
assertEquals(chunk.getCommonPrefixes().length, 0); chunk = service.listObjectsChunked(bucketName, null, null, 2, null, true);
assertNull(chunk.getDelimiter()); assertEquals(chunk.getObjects().length, 4);
assertNull(chunk.getPrefix()); assertEquals(chunk.getCommonPrefixes().length, 0);
assertNull(chunk.getPriorLastKey()); assertNull(chunk.getDelimiter());
assertNull(chunk.getPrefix());
// Partial listing with marker assertNull(chunk.getPriorLastKey());
chunk = service.listObjectsChunked(bucketName, null, null, 1000, "item1/subobject2", true);
assertEquals(chunk.getObjects().length, 3); // Partial listing with marker
assertEquals(chunk.getCommonPrefixes().length, 0); chunk = service.listObjectsChunked(bucketName, null, null, 1000, "item1/subobject2", true);
assertNull(chunk.getDelimiter()); assertEquals(chunk.getObjects().length, 3);
assertNull(chunk.getPrefix()); assertEquals(chunk.getCommonPrefixes().length, 0);
assertNull(chunk.getPriorLastKey()); assertNull(chunk.getDelimiter());
assertNull(chunk.getPrefix());
// Partial listing with marker assertNull(chunk.getPriorLastKey());
chunk = service.listObjectsChunked(bucketName, null, null, 1000, "object1", true);
assertEquals(chunk.getObjects().length, 1); // Partial listing with marker
assertEquals(chunk.getCommonPrefixes().length, 0); chunk = service.listObjectsChunked(bucketName, null, null, 1000, "object1", true);
assertNull(chunk.getDelimiter()); assertEquals(chunk.getObjects().length, 1);
assertNull(chunk.getPrefix()); assertEquals(chunk.getCommonPrefixes().length, 0);
assertNull(chunk.getPriorLastKey()); assertNull(chunk.getDelimiter());
assertNull(chunk.getPrefix());
// Prefix test assertNull(chunk.getPriorLastKey());
chunk = service.listObjectsChunked(bucketName, "item", null, 1000, null, true);
assertEquals(chunk.getObjects().length, 2); // Prefix test
assertEquals(chunk.getCommonPrefixes().length, 0); chunk = service.listObjectsChunked(bucketName, "item", null, 1000, null, true);
assertNull(chunk.getDelimiter()); assertEquals(chunk.getObjects().length, 2);
assertEquals(chunk.getPrefix(), "item"); assertEquals(chunk.getCommonPrefixes().length, 0);
assertNull(chunk.getPriorLastKey()); assertNull(chunk.getDelimiter());
assertEquals(chunk.getPrefix(), "item");
// Delimiter test assertNull(chunk.getPriorLastKey());
chunk = service.listObjectsChunked(bucketName, null, "/", 1000, null, true);
assertEquals(chunk.getObjects().length, 2); // Delimiter test
assertEquals(chunk.getCommonPrefixes().length, 2); chunk = service.listObjectsChunked(bucketName, null, "/", 1000, null, true);
assertEquals(chunk.getDelimiter(), "/"); assertEquals(chunk.getObjects().length, 2);
assertNull(chunk.getPrefix()); assertEquals(chunk.getCommonPrefixes().length, 2);
assertNull(chunk.getPriorLastKey()); assertEquals(chunk.getDelimiter(), "/");
assertNull(chunk.getPrefix());
// Prefix & delimiter test assertNull(chunk.getPriorLastKey());
chunk = service.listObjectsChunked(bucketName, "item", "/", 1000, null, true);
assertEquals(chunk.getObjects().length, 1); // Prefix & delimiter test
assertEquals(chunk.getCommonPrefixes().length, 1); chunk = service.listObjectsChunked(bucketName, "item", "/", 1000, null, true);
assertEquals(chunk.getDelimiter(), "/"); assertEquals(chunk.getObjects().length, 1);
assertEquals(chunk.getPrefix(), "item"); assertEquals(chunk.getCommonPrefixes().length, 1);
assertNull(chunk.getPriorLastKey()); assertEquals(chunk.getDelimiter(), "/");
assertEquals(chunk.getPrefix(), "item");
emptyBucket(bucketName); assertNull(chunk.getPriorLastKey());
} finally {
returnBucket(bucketName);
}
} }
@Test(dependsOnMethods = "testCreateBucketImpl") @Test(dependsOnMethods = "testCreateBucketImpl")
public void testListObjectsImpl() throws InterruptedException, ExecutionException, public void testListObjectsImpl() throws InterruptedException, ExecutionException,
TimeoutException, IOException, S3ServiceException { TimeoutException, IOException, S3ServiceException {
addObjectToBucket(bucketName, "item1/subobject2"); String bucketName = null;
addObjectToBucket(bucketName, "item2"); try {
addObjectToBucket(bucketName, "object1"); bucketName = getScratchBucketName();
addObjectToBucket(bucketName, "object2/subobject1"); addObjectToBucket(bucketName, "item1/subobject2");
addObjectToBucket(bucketName, "item2");
S3Object[] objects; addObjectToBucket(bucketName, "object1");
addObjectToBucket(bucketName, "object2/subobject1");
// Normal complete listing
objects = service.listObjects(bucketName, null, null, 1000); S3Object[] objects;
assertEquals(objects.length, 4);
// Normal complete listing
// Complete listing, in two chunks objects = service.listObjects(bucketName, null, null, 1000);
objects = service.listObjects(bucketName, null, null, 2); assertEquals(objects.length, 4);
assertEquals(objects.length, 4);
assertEquals(objects[0].getKey(), "item1/subobject2"); // Complete listing, in two chunks
assertEquals(objects[3].getKey(), "object2/subobject1"); objects = service.listObjects(bucketName, null, null, 2);
assertEquals(objects.length, 4);
// Prefix test assertEquals(objects[0].getKey(), "item1/subobject2");
objects = service.listObjects(bucketName, "item", null, 1000); assertEquals(objects[3].getKey(), "object2/subobject1");
assertEquals(objects.length, 2);
// Prefix test
// Delimiter test objects = service.listObjects(bucketName, "item", null, 1000);
objects = service.listObjects(bucketName, null, "/", 1000); assertEquals(objects.length, 2);
assertEquals(objects.length, 2);
assertEquals(objects[0].getKey(), "item2"); // Delimiter test
assertEquals(objects[1].getKey(), "object1"); objects = service.listObjects(bucketName, null, "/", 1000);
assertEquals(objects.length, 2);
// Prefix & delimiter test assertEquals(objects[0].getKey(), "item2");
objects = service.listObjects(bucketName, "item", "/", 1000); assertEquals(objects[1].getKey(), "object1");
assertEquals(objects.length, 1);
assertEquals(objects[0].getKey(), "item2"); // Prefix & delimiter test
objects = service.listObjects(bucketName, "item", "/", 1000);
emptyBucket(bucketName); assertEquals(objects.length, 1);
assertEquals(objects[0].getKey(), "item2");
} finally {
returnBucket(bucketName);
}
} }
@Test(dependsOnMethods = "testCreateBucketImpl") @Test(dependsOnMethods = "testCreateBucketImpl")
public void testPutObjectImpl() throws S3ServiceException, InterruptedException, public void testPutObjectImpl() throws S3ServiceException, InterruptedException,
ExecutionException, TimeoutException, NoSuchAlgorithmException, IOException { ExecutionException, TimeoutException, NoSuchAlgorithmException, IOException {
String objectKey = "putObject"; String bucketName = getBucketName();
try {
S3Object requestObject, jsResultObject; String objectKey = "putObject";
org.jclouds.aws.s3.domain.S3Object jcObject;
S3Object requestObject, jsResultObject;
// Upload empty object org.jclouds.aws.s3.domain.S3Object jcObject;
requestObject = new S3Object(objectKey);
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject); // Upload empty object
jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS); requestObject = new S3Object(objectKey);
assertEquals(jcObject.getKey(), objectKey); jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
assertEquals(jcObject.getMetadata().getSize(), 0); jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS);
assertEquals(jcObject.getMetadata().getContentType(), ContentTypes.BINARY); assertEquals(jcObject.getKey(), objectKey);
assertEquals(jsResultObject.getKey(), requestObject.getKey()); assertEquals(jcObject.getMetadata().getSize(), 0);
assertEquals(jsResultObject.getContentLength(), 0); assertEquals(jcObject.getMetadata().getContentType(), ContentTypes.BINARY);
assertEquals(jsResultObject.getContentType(), ContentTypes.BINARY); assertEquals(jsResultObject.getKey(), requestObject.getKey());
assertEquals(jsResultObject.getContentLength(), 0);
// Upload unicode-named object assertEquals(jsResultObject.getContentType(), ContentTypes.BINARY);
requestObject = new S3Object("Ÿn<EFBFBD>˜dŽ-object");
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject); // Upload unicode-named object
jcObject = client.getObject(bucketName, requestObject.getKey()).get(10, TimeUnit.SECONDS); requestObject = new S3Object("Ÿn<EFBFBD>˜dŽ-object");
assertEquals(jcObject.getKey(), requestObject.getKey()); jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
assertEquals(jcObject.getMetadata().getSize(), 0); jcObject = client.getObject(bucketName, requestObject.getKey()).get(10, TimeUnit.SECONDS);
assertEquals(jcObject.getMetadata().getContentType(), ContentTypes.BINARY); assertEquals(jcObject.getKey(), requestObject.getKey());
assertEquals(jsResultObject.getKey(), requestObject.getKey()); assertEquals(jcObject.getMetadata().getSize(), 0);
assertEquals(jsResultObject.getContentLength(), 0); assertEquals(jcObject.getMetadata().getContentType(), ContentTypes.BINARY);
assertEquals(jsResultObject.getContentType(), ContentTypes.BINARY); assertEquals(jsResultObject.getKey(), requestObject.getKey());
assertEquals(jsResultObject.getContentLength(), 0);
// Upload string object assertEquals(jsResultObject.getContentType(), ContentTypes.BINARY);
String data = "This is my Ÿn<6E>˜dŽ data";
requestObject = new S3Object(objectKey, data); // Upload string object
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject); String data = "This is my Ÿn<6E>˜dŽ data";
jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS); requestObject = new S3Object(objectKey, data);
assertEquals(jcObject.getMetadata().getSize(), data.getBytes("UTF-8").length); jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
assertTrue(jcObject.getMetadata().getContentType().startsWith("text/plain")); jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS);
assertEquals(jsResultObject.getContentLength(), data.getBytes("UTF-8").length); assertEquals(jcObject.getMetadata().getSize(), data.getBytes("UTF-8").length);
assertTrue(jsResultObject.getContentType().startsWith("text/plain")); assertTrue(jcObject.getMetadata().getContentType().startsWith("text/plain"));
assertEquals(jsResultObject.getContentLength(), data.getBytes("UTF-8").length);
// Upload object with metadata assertTrue(jsResultObject.getContentType().startsWith("text/plain"));
requestObject = new S3Object(objectKey);
requestObject.addMetadata(S3Constants.USER_METADATA_PREFIX + "my-metadata-1", "value-1"); // Upload object with metadata
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject); requestObject = new S3Object(objectKey);
jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS); requestObject.addMetadata(S3Constants.USER_METADATA_PREFIX + "my-metadata-1", "value-1");
assertEquals(Iterables.getLast(jcObject.getMetadata().getUserMetadata().get( jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
S3Constants.USER_METADATA_PREFIX + "my-metadata-1")), "value-1"); jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS);
assertEquals(jsResultObject.getMetadata(S3Constants.USER_METADATA_PREFIX + "my-metadata-1"), assertEquals(Iterables.getLast(jcObject.getMetadata().getUserMetadata().get(
"value-1"); S3Constants.USER_METADATA_PREFIX + "my-metadata-1")), "value-1");
assertEquals(jsResultObject.getMetadata(S3Constants.USER_METADATA_PREFIX + "my-metadata-1"),
// Upload object with public-read ACL "value-1");
requestObject = new S3Object(objectKey);
requestObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ); // Upload object with public-read ACL
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject); requestObject = new S3Object(objectKey);
jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS); requestObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
// TODO: No way yet to get/lookup ACL from jClouds object jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
// assertEquals(jcObject.getAcl(), CannedAccessPolicy.PUBLIC_READ); jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS);
assertEquals(jsResultObject.getAcl(), AccessControlList.REST_CANNED_PUBLIC_READ); // TODO: No way yet to get/lookup ACL from jClouds object
// assertEquals(jcObject.getAcl(), CannedAccessPolicy.PUBLIC_READ);
// TODO : Any way to test a URL lookup that works for live and stub testing? assertEquals(jsResultObject.getAcl(), AccessControlList.REST_CANNED_PUBLIC_READ);
// URL publicUrl = new URL(
// "http://" + bucketName + ".s3.amazonaws.com:80/" + requestObject.getKey()); // TODO : Any way to test a URL lookup that works for live and stub testing?
// assertEquals(((HttpURLConnection) publicUrl.openConnection()).getResponseCode(), 200); // URL publicUrl = new URL(
// "http://" + bucketName + ".s3.amazonaws.com:80/" + requestObject.getKey());
// Upload object and check MD5 // assertEquals(((HttpURLConnection) publicUrl.openConnection()).getResponseCode(), 200);
requestObject = new S3Object(objectKey);
data = "Here is some d‡tˆ for you"; // Upload object and check MD5
requestObject.setDataInputStream(new ByteArrayInputStream(data.getBytes("UTF-8"))); requestObject = new S3Object(objectKey);
jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject); data = "Here is some d‡tˆ for you";
jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS); requestObject.setDataInputStream(new ByteArrayInputStream(data.getBytes("UTF-8")));
assertTrue(jsResultObject.verifyData(data.getBytes("UTF-8"))); jsResultObject = service.putObject(new S3Bucket(bucketName), requestObject);
assertEquals(jsResultObject.getMd5HashAsHex(), S3Utils.toHexString(jcObject.getMetadata() jcObject = client.getObject(bucketName, objectKey).get(10, TimeUnit.SECONDS);
.getMd5())); assertTrue(jsResultObject.verifyData(data.getBytes("UTF-8")));
assertEquals(jsResultObject.getMd5HashAsHex(), S3Utils.toHexString(jcObject.getMetadata()
emptyBucket(bucketName); .getMd5()));
} finally {
returnBucket(bucketName);
}
} }
@Test(dependsOnMethods = "testCreateBucketImpl") @Test(dependsOnMethods = "testCreateBucketImpl")
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testCopyObjectImpl() throws InterruptedException, ExecutionException, public void testCopyObjectImpl() throws InterruptedException, ExecutionException,
TimeoutException, IOException, S3ServiceException { TimeoutException, IOException, S3ServiceException {
String data = "This is my data"; String bucketName = getBucketName();
String sourceObjectKey = "šriginalObject"; // Notice the use of non-ASCII try {
String destinationObjectKey = "dŽstinationObject"; // characters here. String data = "This is my data";
String metadataName = "metadata-name"; String sourceObjectKey = "šriginalObject"; // Notice the use of non-ASCII
String sourceMetadataValue = "souce-metadata-value"; String destinationObjectKey = "dŽstinationObject"; // characters here.
String destinationMetadataValue = "destination-metadata-value"; String metadataName = "metadata-name";
String sourceMetadataValue = "souce-metadata-value";
org.jclouds.aws.s3.domain.S3Object sourceObject = new org.jclouds.aws.s3.domain.S3Object( String destinationMetadataValue = "destination-metadata-value";
sourceObjectKey, data);
sourceObject.getMetadata().getUserMetadata().put( org.jclouds.aws.s3.domain.S3Object sourceObject = new org.jclouds.aws.s3.domain.S3Object(
S3Constants.USER_METADATA_PREFIX + metadataName, sourceMetadataValue); sourceObjectKey, data);
addObjectToBucket(bucketName, sourceObject); sourceObject.getMetadata().getUserMetadata().put(
S3Constants.USER_METADATA_PREFIX + metadataName, sourceMetadataValue);
S3Object destinationObject; addObjectToBucket(bucketName, sourceObject);
Map copyResult;
org.jclouds.aws.s3.domain.S3Object jcDestinationObject; S3Object destinationObject;
Map copyResult;
// Copy with metadata and ACL retained org.jclouds.aws.s3.domain.S3Object jcDestinationObject;
destinationObject = new S3Object(destinationObjectKey);
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject, // Copy with metadata and ACL retained
false); destinationObject = new S3Object(destinationObjectKey);
jcDestinationObject = client.getObject(bucketName, destinationObject.getKey()).get(10, copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject,
TimeUnit.SECONDS); false);
assertEquals(jcDestinationObject.getKey(), destinationObjectKey); jcDestinationObject = client.getObject(bucketName, destinationObject.getKey()).get(10,
assertEquals(Iterators.getLast(jcDestinationObject.getMetadata().getUserMetadata().get( TimeUnit.SECONDS);
S3Constants.USER_METADATA_PREFIX + metadataName).iterator()), sourceMetadataValue); assertEquals(jcDestinationObject.getKey(), destinationObjectKey);
assertEquals(copyResult.get("ETag"), S3Utils.toHexString(jcDestinationObject.getMetadata() assertEquals(Iterators.getLast(jcDestinationObject.getMetadata().getUserMetadata().get(
.getMd5())); S3Constants.USER_METADATA_PREFIX + metadataName).iterator()), sourceMetadataValue);
// TODO: Test destination ACL is unchanged (ie private) assertEquals(copyResult.get("ETag"), S3Utils.toHexString(jcDestinationObject.getMetadata()
.getMd5()));
// Copy with metadata replaced // TODO: Test destination ACL is unchanged (ie private)
destinationObject = new S3Object(destinationObjectKey);
destinationObject.addMetadata(S3Constants.USER_METADATA_PREFIX + metadataName, // Copy with metadata replaced
destinationMetadataValue); destinationObject = new S3Object(destinationObjectKey);
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject, destinationObject.addMetadata(S3Constants.USER_METADATA_PREFIX + metadataName,
true); destinationMetadataValue);
jcDestinationObject = client.getObject(bucketName, destinationObject.getKey()).get(10, copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject,
TimeUnit.SECONDS); true);
assertEquals(Iterators.getLast(jcDestinationObject.getMetadata().getUserMetadata().get( jcDestinationObject = client.getObject(bucketName, destinationObject.getKey()).get(10,
S3Constants.USER_METADATA_PREFIX + metadataName).iterator()), TimeUnit.SECONDS);
destinationMetadataValue); assertEquals(Iterators.getLast(jcDestinationObject.getMetadata().getUserMetadata().get(
// TODO: Test destination ACL is unchanged (ie private) S3Constants.USER_METADATA_PREFIX + metadataName).iterator()),
destinationMetadataValue);
// Copy with ACL modified // TODO: Test destination ACL is unchanged (ie private)
destinationObject = new S3Object(destinationObjectKey);
destinationObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ); // Copy with ACL modified
copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject, destinationObject = new S3Object(destinationObjectKey);
false); destinationObject.setAcl(AccessControlList.REST_CANNED_PUBLIC_READ);
jcDestinationObject = client.getObject(bucketName, destinationObject.getKey()).get(10, copyResult = service.copyObject(bucketName, sourceObjectKey, bucketName, destinationObject,
TimeUnit.SECONDS); false);
// TODO: Test destination ACL is changed (ie public-read) jcDestinationObject = client.getObject(bucketName, destinationObject.getKey()).get(10,
TimeUnit.SECONDS);
emptyBucket(bucketName); // TODO: Test destination ACL is changed (ie public-read)
} finally {
returnBucket(bucketName);
}
} }
@Test(enabled = false) @Test(enabled = false)