diff --git a/core/src/main/java/org/jclouds/http/HttpRequest.java b/core/src/main/java/org/jclouds/http/HttpRequest.java index 3d51b40904..0d44d03918 100644 --- a/core/src/main/java/org/jclouds/http/HttpRequest.java +++ b/core/src/main/java/org/jclouds/http/HttpRequest.java @@ -42,8 +42,8 @@ import com.google.common.collect.Multimap; */ public class HttpRequest { - String method; - String uri; + private final String method; + private final String uri; Multimap headers = HashMultimap.create(); Object content; String contentType; @@ -75,18 +75,10 @@ public class HttpRequest { return method; } - public void setMethod(String method) { - this.method = method; - } - public String getUri() { return uri; } - public void setUri(String uri) { - this.uri = uri; - } - public Multimap getHeaders() { return headers; } diff --git a/repo/org/jclouds/jclouds-core/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-core/1.0-SNAPSHOT/maven-metadata.xml index 08d5c56d78..e6000ba73e 100644 --- a/repo/org/jclouds/jclouds-core/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-core/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-core/maven-metadata.xml b/repo/org/jclouds/jclouds-core/maven-metadata.xml index 5d3956bc14..86aa929d03 100644 --- a/repo/org/jclouds/jclouds-core/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-core/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-gae/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-gae/1.0-SNAPSHOT/maven-metadata.xml index 0ea6a2b384..2b42f63fc8 100644 --- a/repo/org/jclouds/jclouds-gae/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-gae/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-gae/maven-metadata.xml b/repo/org/jclouds/jclouds-gae/maven-metadata.xml index bfc1089158..dd1662e492 100644 --- a/repo/org/jclouds/jclouds-gae/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-gae/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-httpnio/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-httpnio/1.0-SNAPSHOT/maven-metadata.xml index 5351f87e13..ecfff26938 100644 --- a/repo/org/jclouds/jclouds-httpnio/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-httpnio/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-httpnio/maven-metadata.xml b/repo/org/jclouds/jclouds-httpnio/maven-metadata.xml index 7b5c598a7f..894278f4cc 100644 --- a/repo/org/jclouds/jclouds-httpnio/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-httpnio/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-log4j/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-log4j/1.0-SNAPSHOT/maven-metadata.xml index 1d428496d7..7fd9615a00 100644 --- a/repo/org/jclouds/jclouds-log4j/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-log4j/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-log4j/maven-metadata.xml b/repo/org/jclouds/jclouds-log4j/maven-metadata.xml index 6fab627287..c4457e1dc4 100644 --- a/repo/org/jclouds/jclouds-log4j/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-log4j/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-s3/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-s3/1.0-SNAPSHOT/maven-metadata.xml index a4d2c1fee4..4b0ecc66d2 100644 --- a/repo/org/jclouds/jclouds-s3/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-s3/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-s3/maven-metadata.xml b/repo/org/jclouds/jclouds-s3/maven-metadata.xml index 24ea625bf9..800960dbec 100644 --- a/repo/org/jclouds/jclouds-s3/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-s3/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-s3nio/1.0-SNAPSHOT/maven-metadata.xml b/repo/org/jclouds/jclouds-s3nio/1.0-SNAPSHOT/maven-metadata.xml index c0e37d8452..ee92c204be 100644 --- a/repo/org/jclouds/jclouds-s3nio/1.0-SNAPSHOT/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-s3nio/1.0-SNAPSHOT/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/repo/org/jclouds/jclouds-s3nio/maven-metadata.xml b/repo/org/jclouds/jclouds-s3nio/maven-metadata.xml index 06f2bbb4db..73fcba2e72 100644 --- a/repo/org/jclouds/jclouds-s3nio/maven-metadata.xml +++ b/repo/org/jclouds/jclouds-s3nio/maven-metadata.xml @@ -1,4 +1,29 @@ + org.jclouds diff --git a/s3/src/main/java/org/jclouds/aws/s3/S3Connection.java b/s3/src/main/java/org/jclouds/aws/s3/S3Connection.java index 164c31d852..d8dabe5edd 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/S3Connection.java +++ b/s3/src/main/java/org/jclouds/aws/s3/S3Connection.java @@ -26,6 +26,7 @@ package org.jclouds.aws.s3; import java.util.List; import java.util.concurrent.Future; +import org.jclouds.aws.s3.commands.options.GetBucketOptions; import org.jclouds.aws.s3.commands.options.PutBucketOptions; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; @@ -132,5 +133,7 @@ public interface S3Connection { */ Future getBucket(String name); + Future getBucket(String name, GetBucketOptions options); + Future> getMetaDataOfOwnedBuckets(); } diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/GetBucket.java b/s3/src/main/java/org/jclouds/aws/s3/commands/GetBucket.java index b1668ffc24..9733bc942d 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/GetBucket.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/GetBucket.java @@ -23,6 +23,7 @@ */ package org.jclouds.aws.s3.commands; +import org.jclouds.aws.s3.commands.options.GetBucketOptions; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.xml.ListBucketHandler; import org.jclouds.http.commands.callables.xml.ParseSax; @@ -36,9 +37,18 @@ public class GetBucket extends S3FutureCommand { @Inject public GetBucket(@Named("jclouds.http.address") String amazonHost, - ParseSax callable, @Assisted String bucket) { - super("GET", "/", callable, amazonHost, bucket); - ListBucketHandler handler = (ListBucketHandler) callable.getHandler(); + ParseSax bucketParser, @Assisted String bucket) { + this(amazonHost, bucketParser, bucket, new GetBucketOptions()); + } + + @Inject + public GetBucket(@Named("jclouds.http.address") String amazonHost, + ParseSax bucketParser, @Assisted String bucket, + @Assisted GetBucketOptions options) { + super("GET", "/" + options.toQueryString(), bucketParser, amazonHost, + bucket); + ListBucketHandler handler = (ListBucketHandler) bucketParser + .getHandler(); handler.setBucketName(bucket); } } \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/S3CommandFactory.java b/s3/src/main/java/org/jclouds/aws/s3/commands/S3CommandFactory.java index 2f1cecaa27..c5a1fa0e7f 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/S3CommandFactory.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/S3CommandFactory.java @@ -23,6 +23,7 @@ */ package org.jclouds.aws.s3.commands; +import org.jclouds.aws.s3.commands.options.GetBucketOptions; import org.jclouds.aws.s3.commands.options.PutBucketOptions; import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.xml.S3ParserFactory; @@ -144,7 +145,12 @@ public class S3CommandFactory { return new GetBucket(amazonHost, parserFactory.createListBucketParser(), bucket); } - + + public GetBucket createGetBucket(String bucket, GetBucketOptions options) { + return new GetBucket(amazonHost, + parserFactory.createListBucketParser(), bucket, options); + } + public CopyObject createCopyObject(String sourceBucket, String sourceObject, String destinationBucket, String destinationObject) { @@ -153,4 +159,6 @@ public class S3CommandFactory { destinationBucket, destinationObject); } + + } \ No newline at end of file diff --git a/s3/src/main/java/org/jclouds/aws/s3/commands/options/GetBucketOptions.java b/s3/src/main/java/org/jclouds/aws/s3/commands/options/GetBucketOptions.java index 9a72cec178..510d9452f7 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/commands/options/GetBucketOptions.java +++ b/s3/src/main/java/org/jclouds/aws/s3/commands/options/GetBucketOptions.java @@ -26,6 +26,8 @@ package org.jclouds.aws.s3.commands.options; import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.base.Preconditions.checkState; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -72,16 +74,21 @@ public class GetBucketOptions { builder.append("&"); } } - return builder.toString(); + String returnVal = builder.toString(); + return returnVal; } /** * Limits the response to keys which begin with the indicated prefix. You * can use prefixes to separate a bucket into different sets of keys in a * way similar to how a file system uses folders. + * + * @throws UnsupportedEncodingException */ - public GetBucketOptions prefix(String prefix) { - options.put("prefix", checkNotNull(prefix, "prefix")); + public GetBucketOptions prefix(String prefix) + throws UnsupportedEncodingException { + options.put("prefix", URLEncoder.encode(checkNotNull(prefix, "prefix"), + "UTF-8")); return this; } @@ -97,9 +104,13 @@ public class GetBucketOptions { * include keys that occur lexicographically after marker. This is * convenient for pagination: To get the next page of results use the last * key of the current page as the marker. + * + * @throws UnsupportedEncodingException */ - public GetBucketOptions marker(String marker) { - options.put("marker", checkNotNull(marker, "marker")); + public GetBucketOptions marker(String marker) + throws UnsupportedEncodingException { + options.put("marker", URLEncoder.encode(checkNotNull(marker, "marker"), + "UTF-8")); return this; } @@ -132,9 +143,13 @@ public class GetBucketOptions { * occurrence of the delimiter to be rolled up into a single result element * in the CommonPrefixes collection. These rolled-up keys are not returned * elsewhere in the response. + * + * @throws UnsupportedEncodingException */ - public GetBucketOptions delimiter(String delimiter) { - options.put("delimiter", checkNotNull(delimiter, "delimiter")); + public GetBucketOptions delimiter(String delimiter) + throws UnsupportedEncodingException { + options.put("delimiter", URLEncoder.encode(checkNotNull(delimiter, + "delimiter"), "UTF-8")); return this; } @@ -148,17 +163,21 @@ public class GetBucketOptions { public static class Builder { /** + * @throws UnsupportedEncodingException * @see GetBucketOptions#prefix */ - public static GetBucketOptions prefix(String prefix) { + public static GetBucketOptions prefix(String prefix) + throws UnsupportedEncodingException { GetBucketOptions options = new GetBucketOptions(); return options.prefix(prefix); } /** + * @throws UnsupportedEncodingException * @see GetBucketOptions#marker */ - public static GetBucketOptions marker(String marker) { + public static GetBucketOptions marker(String marker) + throws UnsupportedEncodingException { GetBucketOptions options = new GetBucketOptions(); return options.marker(marker); } @@ -172,9 +191,11 @@ public class GetBucketOptions { } /** + * @throws UnsupportedEncodingException * @see GetBucketOptions#delimiter */ - public static GetBucketOptions delimiter(String delimiter) { + public static GetBucketOptions delimiter(String delimiter) + throws UnsupportedEncodingException { GetBucketOptions options = new GetBucketOptions(); return options.delimiter(delimiter); } diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java index 042e0fc079..a898658fb2 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java +++ b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Bucket.java @@ -32,161 +32,225 @@ import java.util.Set; /** * A container that provides namespace, access control and aggregation of * {@link S3Object}s - * + * * @author Adrian Cole * @see http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html */ public class S3Bucket { @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("S3Bucket"); - sb.append("{metaData=").append(metaData); - sb.append(", isComplete=").append(isComplete); - sb.append('}'); - return sb.toString(); + final StringBuilder sb = new StringBuilder(); + sb.append("S3Bucket"); + sb.append("{metaData=").append(metaData); + sb.append(", isComplete=").append(isComplete); + sb.append('}'); + return sb.toString(); } @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof S3Bucket)) return false; + if (this == o) + return true; + if (!(o instanceof S3Bucket)) + return false; - S3Bucket s3Bucket = (S3Bucket) o; + S3Bucket s3Bucket = (S3Bucket) o; - if (isComplete != s3Bucket.isComplete) return false; - if (!metaData.equals(s3Bucket.metaData)) return false; - if (objects != null ? !objects.equals(s3Bucket.objects) : s3Bucket.objects != null) return false; + if (isComplete != s3Bucket.isComplete) + return false; + if (!metaData.equals(s3Bucket.metaData)) + return false; + if (objects != null ? !objects.equals(s3Bucket.objects) + : s3Bucket.objects != null) + return false; - return true; + return true; } @Override public int hashCode() { - int result = objects != null ? objects.hashCode() : 0; - result = 31 * result + metaData.hashCode(); - result = 31 * result + (isComplete ? 1 : 0); - return result; + int result = objects != null ? objects.hashCode() : 0; + result = 31 * result + metaData.hashCode(); + result = 31 * result + (isComplete ? 1 : 0); + return result; } public static class MetaData { - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("MetaData"); - sb.append("{name='").append(name).append('\''); - sb.append(", creationDate=").append(creationDate); - sb.append(", canonicalUser=").append(canonicalUser); - sb.append(", locationConstraint=").append(locationConstraint); - sb.append('}'); - return sb.toString(); - } + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("MetaData"); + sb.append("{name='").append(name).append('\''); + sb.append(", creationDate=").append(creationDate); + sb.append(", canonicalUser=").append(canonicalUser); + sb.append(", locationConstraint=").append(locationConstraint); + sb.append('}'); + return sb.toString(); + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MetaData)) return false; + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof MetaData)) + return false; - MetaData metaData = (MetaData) o; + MetaData metaData = (MetaData) o; - if (canonicalUser != null ? !canonicalUser.equals(metaData.canonicalUser) : metaData.canonicalUser != null) - return false; - if (creationDate != null ? !creationDate.equals(metaData.creationDate) : metaData.creationDate != null) - return false; - if (locationConstraint != metaData.locationConstraint) return false; - if (!name.equals(metaData.name)) return false; + if (canonicalUser != null ? !canonicalUser + .equals(metaData.canonicalUser) + : metaData.canonicalUser != null) + return false; + if (creationDate != null ? !creationDate + .equals(metaData.creationDate) + : metaData.creationDate != null) + return false; + if (locationConstraint != metaData.locationConstraint) + return false; + if (!name.equals(metaData.name)) + return false; - return true; - } + return true; + } - @Override - public int hashCode() { - int result = name.hashCode(); - result = 31 * result + (creationDate != null ? creationDate.hashCode() : 0); - result = 31 * result + (canonicalUser != null ? canonicalUser.hashCode() : 0); - result = 31 * result + (locationConstraint != null ? locationConstraint.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = name.hashCode(); + result = 31 * result + + (creationDate != null ? creationDate.hashCode() : 0); + result = 31 * result + + (canonicalUser != null ? canonicalUser.hashCode() : 0); + result = 31 + * result + + (locationConstraint != null ? locationConstraint + .hashCode() : 0); + return result; + } - public static enum LocationConstraint { - EU - } + public static enum LocationConstraint { + EU + } - private final String name; - private DateTime creationDate; - private S3Owner canonicalUser; - private LocationConstraint locationConstraint; + private final String name; + private DateTime creationDate; + private S3Owner canonicalUser; + private LocationConstraint locationConstraint; - public MetaData(String name) { - this.name = checkNotNull(name, "name").toLowerCase(); - } + public MetaData(String name) { + this.name = checkNotNull(name, "name").toLowerCase(); + } - public String getName() { - return name; - } + public String getName() { + return name; + } - public DateTime getCreationDate() { - return creationDate; - } + public DateTime getCreationDate() { + return creationDate; + } - public void setCreationDate(DateTime creationDate) { - this.creationDate = creationDate; - } + public void setCreationDate(DateTime creationDate) { + this.creationDate = creationDate; + } - public S3Owner getCanonicalUser() { - return canonicalUser; - } + public S3Owner getCanonicalUser() { + return canonicalUser; + } - public void setCanonicalUser(S3Owner canonicalUser) { - this.canonicalUser = canonicalUser; - } + public void setCanonicalUser(S3Owner canonicalUser) { + this.canonicalUser = canonicalUser; + } - public LocationConstraint getLocationConstraint() { - return locationConstraint; - } + public LocationConstraint getLocationConstraint() { + return locationConstraint; + } - public void setLocationConstraint(LocationConstraint locationConstraint) { - this.locationConstraint = locationConstraint; - } + public void setLocationConstraint(LocationConstraint locationConstraint) { + this.locationConstraint = locationConstraint; + } } public static final S3Bucket NOT_FOUND = new S3Bucket("NOT_FOUND"); private Set objects = new HashSet(); + private Set commonPrefixes = new HashSet(); + private String prefix; + private String marker; + private String delimiter; + private long maxKeys; private final MetaData metaData; private boolean isComplete; public S3Bucket(String name) { - this.metaData = new MetaData(name); + this.metaData = new MetaData(name); } public String getName() { - return this.metaData.getName(); + return this.metaData.getName(); } public S3Bucket(MetaData metaData) { - this.metaData = checkNotNull(metaData, "metaData"); + this.metaData = checkNotNull(metaData, "metaData"); } public Set getContents() { - return objects; + return objects; } public void setContents(Set objects) { - this.objects = objects; + this.objects = objects; } public boolean isComplete() { - return isComplete; + return isComplete; } public void setComplete(boolean complete) { - isComplete = complete; + isComplete = complete; } public MetaData getMetaData() { - return metaData; + return metaData; + } + + public void setCommonPrefixes(Set commonPrefixes) { + this.commonPrefixes = commonPrefixes; + } + + public Set getCommonPrefixes() { + return commonPrefixes; + } + + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getPrefix() { + return prefix; + } + + public void setMaxKeys(long maxKeys) { + this.maxKeys = maxKeys; + } + + public long getMaxKeys() { + return maxKeys; + } + + public void setMarker(String marker) { + this.marker = marker; + } + + public String getMarker() { + return marker; + } + + public void setDelimiter(String delimiter) { + this.delimiter = delimiter; + } + + public String getDelimiter() { + return delimiter; } } diff --git a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java index 7203d1ce31..6e74b9c638 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java +++ b/s3/src/main/java/org/jclouds/aws/s3/domain/S3Object.java @@ -23,163 +23,184 @@ */ package org.jclouds.aws.s3.domain; -import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Preconditions.*; import org.joda.time.DateTime; import java.util.Arrays; /** * // TODO: Adrian: Document this! - * + * * @author Adrian Cole */ public class S3Object { @Override public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("S3Object"); - sb.append("{metaData=").append(metaData); - sb.append('}'); - return sb.toString(); + final StringBuilder sb = new StringBuilder(); + sb.append("S3Object"); + sb.append("{metaData=").append(metaData); + sb.append('}'); + return sb.toString(); } public static final S3Object NOT_FOUND = new S3Object(MetaData.NOT_FOUND); @Override public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof S3Object)) return false; + if (this == o) + return true; + if (!(o instanceof S3Object)) + return false; - S3Object s3Object = (S3Object) o; + S3Object s3Object = (S3Object) o; - if (data != null ? !data.equals(s3Object.data) : s3Object.data != null) return false; - if (!metaData.equals(s3Object.metaData)) return false; + if (data != null ? !data.equals(s3Object.data) : s3Object.data != null) + return false; + if (!metaData.equals(s3Object.metaData)) + return false; - return true; + return true; } @Override public int hashCode() { - int result = data != null ? data.hashCode() : 0; - result = 31 * result + metaData.hashCode(); - return result; + int result = data != null ? data.hashCode() : 0; + result = 31 * result + metaData.hashCode(); + return result; } public static class MetaData { - public static final MetaData NOT_FOUND = new MetaData("NOT_FOUND"); - public static final String UNKNOWN_MIME_TYPE = "application/x-unknown-mime-type"; + public static final MetaData NOT_FOUND = new MetaData("NOT_FOUND"); + public static final String UNKNOWN_MIME_TYPE = "application/x-unknown-mime-type"; - @Override - public String toString() { - final StringBuilder sb = new StringBuilder(); - sb.append("MetaData"); - sb.append("{key='").append(key).append('\''); - sb.append(", lastModified=").append(lastModified); - sb.append(", md5=").append(getMd5() == null ? "null" : Arrays.asList(getMd5()).toString()); - sb.append(", size=").append(size); - sb.append(", owner=").append(owner); - sb.append(", contentType='").append(contentType).append('\''); - sb.append(", storageClass='").append(storageClass).append('\''); - sb.append(", server='").append(server).append('\''); - sb.append('}'); - return sb.toString(); - } + @Override + public String toString() { + final StringBuilder sb = new StringBuilder(); + sb.append("MetaData"); + sb.append("{key='").append(key).append('\''); + sb.append(", lastModified=").append(lastModified); + sb.append(", md5=").append( + getMd5() == null ? "null" : Arrays.asList(getMd5()) + .toString()); + sb.append(", size=").append(size); + sb.append(", owner=").append(owner); + sb.append(", contentType='").append(contentType).append('\''); + sb.append(", storageClass='").append(storageClass).append('\''); + sb.append(", server='").append(server).append('\''); + sb.append('}'); + return sb.toString(); + } - private final String key; - private DateTime lastModified; - private byte[] md5; + private final String key; + private DateTime lastModified; + private byte[] md5; - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof MetaData)) return false; + @Override + public boolean equals(Object o) { + if (this == o) + return true; + if (!(o instanceof MetaData)) + return false; - MetaData metaData = (MetaData) o; + MetaData metaData = (MetaData) o; - if (size != metaData.size) return false; - if (contentType != null ? !contentType.equals(metaData.contentType) : metaData.contentType != null) - return false; - if (!key.equals(metaData.key)) return false; - if (lastModified != null ? !lastModified.equals(metaData.lastModified) : metaData.lastModified != null) - return false; - if (!Arrays.equals(getMd5(), metaData.getMd5())) return false; - if (owner != null ? !owner.equals(metaData.owner) : metaData.owner != null) return false; + if (size != metaData.size) + return false; + if (contentType != null ? !contentType.equals(metaData.contentType) + : metaData.contentType != null) + return false; + if (!key.equals(metaData.key)) + return false; + if (lastModified != null ? !lastModified + .equals(metaData.lastModified) + : metaData.lastModified != null) + return false; + if (!Arrays.equals(getMd5(), metaData.getMd5())) + return false; + if (owner != null ? !owner.equals(metaData.owner) + : metaData.owner != null) + return false; - return true; - } + return true; + } - @Override - public int hashCode() { - int result = key.hashCode(); - result = 31 * result + (lastModified != null ? lastModified.hashCode() : 0); - result = 31 * result + (getMd5() != null ? Arrays.hashCode(getMd5()) : 0); - result = 31 * result + (int) (size ^ (size >>> 32)); - result = 31 * result + (owner != null ? owner.hashCode() : 0); - result = 31 * result + (contentType != null ? contentType.hashCode() : 0); - return result; - } + @Override + public int hashCode() { + int result = key.hashCode(); + result = 31 * result + + (lastModified != null ? lastModified.hashCode() : 0); + result = 31 * result + + (getMd5() != null ? Arrays.hashCode(getMd5()) : 0); + result = 31 * result + (int) (size ^ (size >>> 32)); + result = 31 * result + (owner != null ? owner.hashCode() : 0); + result = 31 * result + + (contentType != null ? contentType.hashCode() : 0); + return result; + } - private long size = -1; - private S3Owner owner; - private String contentType = UNKNOWN_MIME_TYPE; - private String storageClass = "STANDARD"; - private String server; + private long size = -1; + private S3Owner owner; + private String contentType = UNKNOWN_MIME_TYPE; + private String storageClass = "STANDARD"; + private String server; - public MetaData(String key) { - this.key = checkNotNull(key, "key"); - } + public MetaData(String key) { + checkNotNull(key, "key"); + checkArgument(!key.startsWith("/"), "keys cannot start with /"); + this.key = key; + } - public String getKey() { - return key; - } + public String getKey() { + return key; + } - public DateTime getLastModified() { - return lastModified; - } + public DateTime getLastModified() { + return lastModified; + } - public void setLastModified(DateTime lastModified) { - this.lastModified = lastModified; - } + public void setLastModified(DateTime lastModified) { + this.lastModified = lastModified; + } - public long getSize() { - return size; - } + public long getSize() { + return size; + } - public void setSize(long size) { - this.size = size; - } + public void setSize(long size) { + this.size = size; + } - public S3Owner getOwner() { - return owner; - } + public S3Owner getOwner() { + return owner; + } - public void setOwner(S3Owner owner) { - this.owner = owner; - } + public void setOwner(S3Owner owner) { + this.owner = owner; + } - public String getContentType() { - return contentType; - } + public String getContentType() { + return contentType; + } - public void setContentType(String contentType) { - this.contentType = contentType; - } + public void setContentType(String contentType) { + this.contentType = contentType; + } - public String getStorageClass() { - return storageClass; - } + public String getStorageClass() { + return storageClass; + } - public void setStorageClass(String storageClass) { - this.storageClass = storageClass; - } + public void setStorageClass(String storageClass) { + this.storageClass = storageClass; + } - public String getServer() { - return server; - } + public String getServer() { + return server; + } - public void setServer(String server) { - this.server = server; - } + public void setServer(String server) { + this.server = server; + } public void setMd5(byte[] md5) { this.md5 = md5; @@ -194,36 +215,41 @@ public class S3Object { private MetaData metaData; public S3Object(String key) { - this(new MetaData(key)); + this(new MetaData(key)); } public S3Object(MetaData metaData) { - this.metaData = metaData; + this.metaData = metaData; } public S3Object(MetaData metaData, Object data) { - this(metaData); - this.data = data; + this(metaData); + this.data = data; + } + + public S3Object(String key, Object data) { + this(key); + this.data = data; } public String getKey() { - return metaData.getKey(); + return metaData.getKey(); } public void setData(Object data) { - this.data = data; + this.data = data; } public Object getData() { - return data; + return data; } public void setMetaData(MetaData metaData) { - this.metaData = metaData; + this.metaData = metaData; } public MetaData getMetaData() { - return metaData; + return metaData; } } diff --git a/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3Connection.java b/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3Connection.java index cba16cf6c3..3fbd43c161 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3Connection.java +++ b/s3/src/main/java/org/jclouds/aws/s3/internal/LiveS3Connection.java @@ -38,6 +38,7 @@ import org.jclouds.aws.s3.commands.HeadMetaData; import org.jclouds.aws.s3.commands.PutBucket; import org.jclouds.aws.s3.commands.PutObject; import org.jclouds.aws.s3.commands.S3CommandFactory; +import org.jclouds.aws.s3.commands.options.GetBucketOptions; import org.jclouds.aws.s3.commands.options.PutBucketOptions; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; @@ -183,6 +184,17 @@ public class LiveS3Connection implements S3Connection { return getBucket; } + /** + * {@inheritDoc} + * + * @see GetBucket + */ + public Future getBucket(String s3Bucket, GetBucketOptions options) { + GetBucket getBucket = factory.createGetBucket(s3Bucket, options); + client.submit(getBucket); + return getBucket; + } + /** * {@inheritDoc} */ diff --git a/s3/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java b/s3/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java index a53192a39c..6dda6fed2e 100644 --- a/s3/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java +++ b/s3/src/main/java/org/jclouds/aws/s3/xml/ListBucketHandler.java @@ -57,11 +57,13 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult { private StringBuilder currentText = new StringBuilder(); @Inject private DateService dateParser; + private boolean inCommonPrefixes; @Override public void startDocument() throws SAXException { checkNotNull(s3Bucket, "s3Bucket"); s3Bucket.getContents().clear(); + s3Bucket.getCommonPrefixes().clear(); super.startDocument(); } @@ -70,6 +72,8 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult { if (qName.equals("Contents")) { } else if (qName.equals("Owner")) { currentOwner = new S3Owner(); + } else if (qName.equals("CommonPrefixes")) { + inCommonPrefixes = true; } } @@ -98,12 +102,20 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult { } else if (qName.equals("Contents")) { s3Bucket.getContents().add(currentObjectMetaData); } else if (qName.equals("Name")) {// bucket stuff last, as least likely - // } else if (qName.equals("Prefix")) { - // // no-op - // } else if (qName.equals("Marker")) { - // // no-op - // } else if (qName.equals("MaxKeys")) { - // // no-op + } else if (qName.equals("Prefix")) { + String prefix = currentText.toString().trim(); + if (inCommonPrefixes) + s3Bucket.getCommonPrefixes().add(prefix); + else + s3Bucket.setPrefix(prefix); + } else if (qName.equals("Delimiter")) { + if (!currentText.toString().equals("")) + s3Bucket.setDelimiter(currentText.toString().trim()); + } else if (qName.equals("Marker")) { + if (!currentText.toString().equals("")) + s3Bucket.setMarker(currentText.toString()); + } else if (qName.equals("MaxKeys")) { + s3Bucket.setMaxKeys(Long.parseLong(currentText.toString())); } else if (qName.equals("IsTruncated")) { boolean isTruncated = Boolean.parseBoolean(currentText.toString()); s3Bucket.setComplete(!isTruncated); diff --git a/s3/src/test/java/org/jclouds/aws/s3/AmazonS3Test.java b/s3/src/test/java/org/jclouds/aws/s3/AmazonS3Test.java index 7288eab1e9..1102cab279 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/AmazonS3Test.java +++ b/s3/src/test/java/org/jclouds/aws/s3/AmazonS3Test.java @@ -29,10 +29,15 @@ import static org.testng.Assert.assertNotNull; import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.UnsupportedEncodingException; import java.util.List; +import java.util.Properties; +import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.apache.commons.io.IOUtils; +import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.*; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; import org.testng.annotations.DataProvider; @@ -75,25 +80,25 @@ public class AmazonS3Test extends S3IntegrationTest { @Test(dataProvider = "putTests") void testPutObject(String key, String type, Object content, Object realObject) throws Exception { - String s3Bucket = bucketPrefix + "filetestsforadrian"; - client.createBucketIfNotExists(s3Bucket).get(10, TimeUnit.SECONDS); - context.createS3ObjectMap(s3Bucket).clear(); - assertEquals(client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS) + String bucketName = bucketPrefix + "filetestsforadrian"; + client.createBucketIfNotExists(bucketName).get(10, TimeUnit.SECONDS); + context.createS3ObjectMap(bucketName).clear(); + assertEquals(client.getBucket(bucketName).get(10, TimeUnit.SECONDS) .getContents().size(), 0); S3Object object = new S3Object(key); object.getMetaData().setContentType(type); object.setData(content); - assertNotNull(client.addObject(s3Bucket, object).get(10, + assertNotNull(client.addObject(bucketName, object).get(10, TimeUnit.SECONDS)); - object = client.getObject(s3Bucket, object.getKey()).get(10, + object = client.getObject(bucketName, object.getKey()).get(10, TimeUnit.SECONDS); returnedString = S3Utils.getContentAsStringAndClose(object); assertEquals(returnedString, realObject); - assertEquals(client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS) + assertEquals(client.getBucket(bucketName).get(10, TimeUnit.SECONDS) .getContents().size(), 1); } - @Test + @Test() void testCopyObject() throws Exception { String realObject = IOUtils.toString(new FileInputStream("pom.xml")); @@ -136,40 +141,111 @@ public class AmazonS3Test extends S3IntegrationTest { } S3Object.MetaData headObject() throws Exception { - String s3Bucket = bucketPrefix + "adrianjbosstest"; - return client.getObjectMetaData(s3Bucket, "3366").get(10, + String bucketName = bucketPrefix + "adrianjbosstest"; + return client.getObjectMetaData(bucketName, "3366").get(10, TimeUnit.SECONDS); } - @Test - void bucketExists() throws Exception { - String s3Bucket = bucketPrefix + "needstoexist"; - assert !client.bucketExists(s3Bucket).get(10, TimeUnit.SECONDS); - assert client.createBucketIfNotExists(s3Bucket).get(10, + @Test() + void testGetBucketDelimiter() throws InterruptedException, + ExecutionException, TimeoutException, UnsupportedEncodingException { + String bucketName = bucketPrefix + "delimiter"; + assert client.createBucketIfNotExists(bucketName).get(10, TimeUnit.SECONDS); - assert client.bucketExists(s3Bucket).get(10, TimeUnit.SECONDS); + String prefix = "apps"; + addTenObjectsUnderPrefix(bucketName, prefix); + add15UnderRoot(bucketName); + S3Bucket bucket = client.getBucket(bucketName, delimiter("/")).get(10, + TimeUnit.SECONDS); + assertEquals(bucket.getDelimiter(), "/"); + assertEquals(bucket.getContents().size(), 15); + assertEquals(bucket.getCommonPrefixes().size(), 1); + } + + private void addAlphabetUnderRoot(String bucketName) + throws InterruptedException, ExecutionException, TimeoutException { + for (char letter = 'a'; letter <= 'z'; letter++) { + client.addObject(bucketName, + new S3Object(letter + "", letter + "content")).get(10, + TimeUnit.SECONDS); + } + } + + @Test + void testGetBucketMarker() throws InterruptedException, ExecutionException, + TimeoutException, UnsupportedEncodingException { + String bucketName = bucketPrefix + "marker"; + assert client.createBucketIfNotExists(bucketName).get(10, + TimeUnit.SECONDS); + addAlphabetUnderRoot(bucketName); + S3Bucket bucket = client.getBucket(bucketName, marker("y")).get(10, + TimeUnit.SECONDS); + assertEquals(bucket.getMarker(), "y"); + assertEquals(bucket.getContents().size(), 1); + } + + @Test() + void testGetBucketPrefix() throws InterruptedException, ExecutionException, + TimeoutException, UnsupportedEncodingException { + String bucketName = bucketPrefix + "prefix"; + assert client.createBucketIfNotExists(bucketName).get(10, + TimeUnit.SECONDS); + String prefix = "apps"; + addTenObjectsUnderPrefix(bucketName, prefix); + add15UnderRoot(bucketName); + + S3Bucket bucket = client.getBucket(bucketName, prefix("apps/")).get(10, + TimeUnit.SECONDS); + assertEquals(bucket.getContents().size(), 10); + assertEquals(bucket.getPrefix(), "apps/"); + + } + + private void add15UnderRoot(String bucketName) throws InterruptedException, + ExecutionException, TimeoutException { + for (int i = 0; i < 15; i++) + client.addObject(bucketName, new S3Object(i + "", i + "content")) + .get(10, TimeUnit.SECONDS); + } + + private void addTenObjectsUnderPrefix(String bucketName, String prefix) + throws InterruptedException, ExecutionException, TimeoutException { + for (int i = 0; i < 10; i++) + client.addObject(bucketName, + new S3Object(prefix + "/" + i, i + "content")).get(10, + TimeUnit.SECONDS); + } + + @Test() + void bucketExists() throws Exception { + String bucketName = bucketPrefix + "needstoexist"; + assert !client.bucketExists(bucketName).get(10, TimeUnit.SECONDS); + assert client.createBucketIfNotExists(bucketName).get(10, + TimeUnit.SECONDS); + assert client.bucketExists(bucketName).get(10, TimeUnit.SECONDS); } Boolean deleteBucket() throws Exception { - String s3Bucket = bucketPrefix + "adrianjbosstest"; - return client.deleteBucketIfEmpty(s3Bucket).get(10, TimeUnit.SECONDS); + String bucketName = bucketPrefix + "adrianjbosstest"; + return client.deleteBucketIfEmpty(bucketName).get(10, TimeUnit.SECONDS); } Boolean deleteObject() throws Exception { - String s3Bucket = bucketPrefix + "adrianjbosstest"; - return client.deleteObject(s3Bucket, "3366").get(10, TimeUnit.SECONDS); + String bucketName = bucketPrefix + "adrianjbosstest"; + return client.deleteObject(bucketName, "3366") + .get(10, TimeUnit.SECONDS); } Boolean createBucketIfNotExists() throws Exception { - String s3Bucket = bucketPrefix + "adrianjbosstest"; - return client.createBucketIfNotExists(s3Bucket).get(10, + String bucketName = bucketPrefix + "adrianjbosstest"; + return client.createBucketIfNotExists(bucketName).get(10, TimeUnit.SECONDS); } S3Bucket getBucket() throws Exception { - String s3Bucket = bucketPrefix + "adrianjbosstest"; - return client.getBucket(s3Bucket).get(10, TimeUnit.SECONDS); + String bucketName = bucketPrefix + "adrianjbosstest"; + return client.getBucket(bucketName).get(10, TimeUnit.SECONDS); } } \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java b/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java index c27a42e59b..926a5495bf 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java +++ b/s3/src/test/java/org/jclouds/aws/s3/StubS3Connection.java @@ -34,6 +34,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import org.jclouds.aws.s3.commands.options.GetBucketOptions; import org.jclouds.aws.s3.commands.options.PutBucketOptions; import org.jclouds.aws.s3.domain.S3Bucket; import org.jclouds.aws.s3.domain.S3Object; @@ -218,4 +219,8 @@ public class StubS3Connection implements S3Connection { throw new UnsupportedOperationException("todo"); } + public Future getBucket(String name, GetBucketOptions options) { + throw new UnsupportedOperationException("todo"); + } + } diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java index 68726e9b01..43e7de7d2e 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/commands/S3ParserTest.java @@ -64,7 +64,7 @@ public class S3ParserTest extends PerformanceTest { Injector injector = null; public static final String listAllMyBucketsResultOn200 = "e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0adrianjbosstest2009-03-12T02:00:07.000Zadrianjbosstest22009-03-12T02:00:09.000Z"; - + S3ParserFactory parserFactory = null; @BeforeMethod diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/options/CopyObjectOptionsTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/options/CopyObjectOptionsTest.java index ba4d64a58b..711e2da1cc 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/options/CopyObjectOptionsTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/commands/options/CopyObjectOptionsTest.java @@ -17,7 +17,7 @@ * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the - * specifSourceic language governing permissions and limitations + * specific language governing permissions and limitations * under the License. * ==================================================================== */ diff --git a/s3/src/test/java/org/jclouds/aws/s3/commands/options/GetBucketOptionsTest.java b/s3/src/test/java/org/jclouds/aws/s3/commands/options/GetBucketOptionsTest.java index ceccd92d20..316eaeadde 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/commands/options/GetBucketOptionsTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/commands/options/GetBucketOptionsTest.java @@ -23,6 +23,7 @@ */ package org.jclouds.aws.s3.commands.options; +import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.delimiter; import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.marker; import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.maxKeys; @@ -30,6 +31,8 @@ import static org.jclouds.aws.s3.commands.options.GetBucketOptions.Builder.prefi import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertNull; +import java.io.UnsupportedEncodingException; + import org.testng.annotations.Test; /** @@ -40,7 +43,7 @@ import org.testng.annotations.Test; public class GetBucketOptionsTest { @Test - public void testPrefix() { + public void testPrefix() throws UnsupportedEncodingException { GetBucketOptions options = new GetBucketOptions(); options.prefix("test"); assertEquals(options.getPrefix(), "test"); @@ -53,21 +56,46 @@ public class GetBucketOptionsTest { } @Test - public void testOneOptionQueryString() { + public void testOneOptionQueryString() throws UnsupportedEncodingException { GetBucketOptions options = new GetBucketOptions(); options.prefix("test"); assertEquals(options.toQueryString(), "?prefix=test"); } @Test - public void testTwoOptionQueryString() { + public void testTwoOptionQueryString() throws UnsupportedEncodingException { GetBucketOptions options = new GetBucketOptions(); options.prefix("test").maxKeys(1); - try { - assertEquals(options.toQueryString(), "?prefix=test&max-keys=1"); - } catch (AssertionError e) { - assertEquals(options.toQueryString(), "?max-keys=1&prefix=test"); + String query = options.toQueryString(); + checkQuery(query); + checkQuery(checkNotNull(query)); + } + + private void checkQuery(String query) { + try { + assertEquals(query, "?prefix=test&max-keys=1"); + } catch (AssertionError e) { + assertEquals(query, "?max-keys=1&prefix=test"); + } + } + + @Test + public void testPrefixAndDelimiterUrlEncodingQueryString() + throws UnsupportedEncodingException { + GetBucketOptions options = new GetBucketOptions(); + options.prefix("/test").delimiter("/"); + String query = options.toQueryString(); + checkEncodedQuery(query); + checkEncodedQuery(checkNotNull(query)); + + } + + private void checkEncodedQuery(String query) { + try { + assertEquals(query, "?prefix=%2Ftest&delimiter=%2F"); + } catch (AssertionError e) { + assertEquals(query, "?delimiter=%2F&prefix=%2Ftest"); } } @@ -78,18 +106,18 @@ public class GetBucketOptionsTest { } @Test - public void testPrefixStatic() { + public void testPrefixStatic() throws UnsupportedEncodingException { GetBucketOptions options = prefix("test"); assertEquals(options.getPrefix(), "test"); } @Test(expectedExceptions = NullPointerException.class) - public void testPrefixNPE() { + public void testPrefixNPE() throws UnsupportedEncodingException { prefix(null); } @Test - public void testMarker() { + public void testMarker() throws UnsupportedEncodingException { GetBucketOptions options = new GetBucketOptions(); options.marker("test"); assertEquals(options.getMarker(), "test"); @@ -102,13 +130,13 @@ public class GetBucketOptionsTest { } @Test - public void testMarkerStatic() { + public void testMarkerStatic() throws UnsupportedEncodingException { GetBucketOptions options = marker("test"); assertEquals(options.getMarker(), "test"); } @Test(expectedExceptions = NullPointerException.class) - public void testMarkerNPE() { + public void testMarkerNPE() throws UnsupportedEncodingException { marker(null); } @@ -137,7 +165,7 @@ public class GetBucketOptionsTest { } @Test - public void testDelimiter() { + public void testDelimiter() throws UnsupportedEncodingException { GetBucketOptions options = new GetBucketOptions(); options.delimiter("test"); assertEquals(options.getDelimiter(), "test"); @@ -150,13 +178,13 @@ public class GetBucketOptionsTest { } @Test - public void testDelimiterStatic() { + public void testDelimiterStatic() throws UnsupportedEncodingException { GetBucketOptions options = delimiter("test"); assertEquals(options.getDelimiter(), "test"); } @Test(expectedExceptions = NullPointerException.class) - public void testDelimiterNPE() { + public void testDelimiterNPE() throws UnsupportedEncodingException { delimiter(null); } } diff --git a/s3/src/test/java/org/jclouds/aws/s3/xml/BaseHandlerTest.java b/s3/src/test/java/org/jclouds/aws/s3/xml/BaseHandlerTest.java new file mode 100644 index 0000000000..6b9988bd40 --- /dev/null +++ b/s3/src/test/java/org/jclouds/aws/s3/xml/BaseHandlerTest.java @@ -0,0 +1,55 @@ +/** + * + * Copyright (C) 2009 Adrian Cole + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.aws.s3.xml; + +import org.jclouds.aws.s3.xml.config.S3ParserModule; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +public class BaseHandlerTest { + + protected S3ParserFactory parserFactory = null; + private Injector injector; + + public BaseHandlerTest() { + super(); + } + + @BeforeMethod + protected void setUpInjector() { + injector = Guice.createInjector(new S3ParserModule()); + parserFactory = injector.getInstance(S3ParserFactory.class); + assert parserFactory != null; + } + + @AfterMethod + protected void tearDownInjector() { + parserFactory = null; + injector = null; + } + +} \ No newline at end of file diff --git a/s3/src/test/java/org/jclouds/aws/s3/xml/ErrorHandlerTest.java b/s3/src/test/java/org/jclouds/aws/s3/xml/ErrorHandlerTest.java index bd91733fd9..da5bf64ea9 100644 --- a/s3/src/test/java/org/jclouds/aws/s3/xml/ErrorHandlerTest.java +++ b/s3/src/test/java/org/jclouds/aws/s3/xml/ErrorHandlerTest.java @@ -27,34 +27,13 @@ import static org.testng.Assert.*; import org.apache.commons.io.IOUtils; import org.jclouds.aws.s3.domain.S3Error; -import org.jclouds.aws.s3.xml.config.S3ParserModule; import org.jclouds.http.HttpException; import org.jclouds.http.commands.callables.xml.ParseSax; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; -import com.google.inject.Guice; -import com.google.inject.Injector; @Test -public class ErrorHandlerTest { - private S3ParserFactory parserFactory = null; - private Injector injector; - - @BeforeMethod - protected void setUpInjector() { - injector = Guice.createInjector(new S3ParserModule()); - parserFactory = injector.getInstance(S3ParserFactory.class); - assert parserFactory != null; - } - - @AfterMethod - protected void tearDownInjector() { - parserFactory = null; - injector = null; - } - +public class ErrorHandlerTest extends BaseHandlerTest { public static final String errorFromAmazonIfYouDontRemoveTransferEncodingHeader = "NotImplementedA header you provided implies functionality that is not implemented
Transfer-Encoding
7C59925D75D15561fbskVU51OZJg2yZS/wNIxoE2PmCf0ZqFd0iH6Vrzw0uKG3KmokswBytL/Bfp/GWb
"; @Test diff --git a/s3/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java b/s3/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java new file mode 100644 index 0000000000..a6200633a4 --- /dev/null +++ b/s3/src/test/java/org/jclouds/aws/s3/xml/ListBucketHandlerTest.java @@ -0,0 +1,69 @@ +/** + * + * Copyright (C) 2009 Adrian Cole + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + * ==================================================================== + */ +package org.jclouds.aws.s3.xml; + +import static org.testng.Assert.assertEquals; + +import org.apache.commons.io.IOUtils; +import org.jclouds.aws.s3.domain.S3Bucket; +import org.jclouds.http.HttpException; +import org.jclouds.http.commands.callables.xml.ParseSax; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +@Test +public class ListBucketHandlerTest extends BaseHandlerTest { + public static final String listBucketWithPrefixAppsSlash = "adriancole.org.jclouds.aws.s3.amazons3testdelimiterapps/1000falseapps/02009-05-07T18:27:08.000Z"c82e6a0025c31c5de5947fda62ac51ab"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/12009-05-07T18:27:09.000Z"944fab2c5a9a6bacf07db5e688310d7a"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/22009-05-07T18:27:09.000Z"a227b8888045c8fd159fb495214000f0"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/32009-05-07T18:27:09.000Z"c9caa76c3dec53e2a192608ce73eef03"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/42009-05-07T18:27:09.000Z"1ce5d0dcc6154a647ea90c7bdf82a224"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/52009-05-07T18:27:09.000Z"79433524d87462ee05708a8ef894ed55"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/62009-05-07T18:27:10.000Z"dd00a060b28ddca8bc5a21a49e306f67"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/72009-05-07T18:27:10.000Z"8cd06eca6e819a927b07a285d750b100"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/82009-05-07T18:27:10.000Z"174495094d0633b92cbe46603eee6bad"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARDapps/92009-05-07T18:27:10.000Z"cd8a19b26fea8a827276df0ad11c580d"8e1a5f66a480ca99a4fdfe8e318c3020446c9989d7004e7778029fbcc5d990fa0ferncamSTANDARD"; + public static final String listBucketWithSlashDelimiterAndCommonPrefixApps = " / apps/"; + ParseSax parser; + + @BeforeMethod + void setUpParser() { + parser = parserFactory.createListBucketParser(); + ((ListBucketHandler) parser.getHandler()).setBucketName("test"); + } + + @Test + public void testListMyBucketsWithDelimiterSlashAndCommonPrefixesAppsSlash() + throws HttpException { + + S3Bucket bucket = parser.parse(IOUtils + .toInputStream(listBucketWithSlashDelimiterAndCommonPrefixApps)); + assertEquals(bucket.getCommonPrefixes().iterator().next(), "apps/"); + assertEquals(bucket.getDelimiter(), "/"); + assert bucket.getMarker() == null; + } + + @Test + public void testListMyBucketsWithPrefixAppsSlash() throws HttpException { + + S3Bucket bucket = parser.parse(IOUtils + .toInputStream(listBucketWithPrefixAppsSlash)); + assertEquals(bucket.getPrefix(), "apps/"); + assertEquals(bucket.getMaxKeys(), 1000); + assert bucket.getMarker() == null; + + } + +}