Issue 47: fixed stub

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1438 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-06-17 18:03:20 +00:00
parent 42da7e537d
commit b6f129eaa4
2 changed files with 12 additions and 7 deletions

View File

@ -81,6 +81,9 @@ import com.thoughtworks.xstream.XStream;
* @author Adrian Cole
*/
public class StubS3Connection implements S3Connection {
public static final String TEST_ACL_ID = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c";
public static final String TEST_ACL_EMAIL = "james@misterm.org";
private static Map<String, Map<String, S3Object>> bucketToContents = new ConcurrentHashMap<String, Map<String, S3Object>>();
private static Map<String, Metadata.LocationConstraint> bucketToLocation = new ConcurrentHashMap<String, Metadata.LocationConstraint>();
@ -588,8 +591,10 @@ public class StubS3Connection implements S3Connection {
// the acl's owner ID as the surrogate replacement.
for (Grant grant : acl.getGrants()) {
if (grant.getGrantee() instanceof EmailAddressGrantee) {
grant.setGrantee(new CanonicalUserGrantee(acl.getOwner().getId(), acl.getOwner()
.getDisplayName()));
EmailAddressGrantee emailGrantee = (EmailAddressGrantee) grant.getGrantee();
String id = emailGrantee.getEmailAddress().equals(TEST_ACL_EMAIL) ? TEST_ACL_ID : acl
.getOwner().getId();
grant.setGrantee(new CanonicalUserGrantee(id, acl.getOwner().getDisplayName()));
}
}
return acl;

View File

@ -38,6 +38,7 @@ import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee;
import org.jclouds.aws.s3.domain.AccessControlList.GroupGranteeURI;
import org.jclouds.aws.s3.domain.AccessControlList.Permission;
import org.testng.annotations.Test;
import static org.jclouds.aws.s3.StubS3Connection.*;
/**
* Tests integrated functionality of all commands that retrieve Access Control Lists (ACLs).
@ -46,7 +47,6 @@ import org.testng.annotations.Test;
*/
@Test(groups = { "integration", "live" }, testName = "s3.PutAccessControlListIntegrationTest")
public class PutAccessControlListIntegrationTest extends S3IntegrationTest {
String jamesId = "1a405254c932b52e5b5caaa88186bc431a1bacb9ece631f835daddaf0c47677c";
@Test
void testUpdateBucketACL() throws InterruptedException, ExecutionException, TimeoutException,
@ -91,8 +91,8 @@ public class PutAccessControlListIntegrationTest extends S3IntegrationTest {
* Revoke all of owner's permissions!
*/
acl.revokeAllPermissions(new CanonicalUserGrantee(ownerId));
if (!ownerId.equals(jamesId))
acl.revokeAllPermissions(new CanonicalUserGrantee(jamesId));
if (!ownerId.equals(TEST_ACL_ID))
acl.revokeAllPermissions(new CanonicalUserGrantee(TEST_ACL_ID));
assertEquals(acl.getGrants().size(), 1);
// Only public read permission should remain...
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ));
@ -116,13 +116,13 @@ public class PutAccessControlListIntegrationTest extends S3IntegrationTest {
assertTrue(acl.hasPermission(GroupGranteeURI.ALL_USERS, Permission.READ), acl.toString());
assertTrue(acl.hasPermission(ownerId, Permission.WRITE_ACP), acl.toString());
// EmailAddressGrantee is replaced by a CanonicalUserGrantee, so we cannot test by email addr
assertTrue(acl.hasPermission(jamesId, Permission.READ_ACP), acl.toString());
assertTrue(acl.hasPermission(TEST_ACL_ID, Permission.READ_ACP), acl.toString());
}
private void addGrantsToACL(AccessControlList acl) {
String ownerId = acl.getOwner().getId();
acl.addPermission(GroupGranteeURI.ALL_USERS, Permission.READ);
acl.addPermission(new EmailAddressGrantee("james@misterm.org"), Permission.READ_ACP);
acl.addPermission(new EmailAddressGrantee(TEST_ACL_EMAIL), Permission.READ_ACP);
acl.addPermission(new CanonicalUserGrantee(ownerId), Permission.WRITE_ACP);
}