Issue 108

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1943 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2009-10-04 00:25:12 +00:00
parent e95e8f3429
commit f78670f871
14 changed files with 185 additions and 116 deletions

View File

@ -23,7 +23,6 @@
*/ */
package org.jclouds.aws.s3.domain; package org.jclouds.aws.s3.domain;
import java.util.List;
import java.util.SortedSet; import java.util.SortedSet;
/** /**
@ -31,7 +30,7 @@ import java.util.SortedSet;
* @author Adrian Cole * @author Adrian Cole
* *
*/ */
public class ArrayListBucketResponse extends org.jclouds.rest.BoundedTreeSet<ObjectMetadata> public class TreeSetListBucketResponse extends org.jclouds.rest.BoundedTreeSet<ObjectMetadata>
implements ListBucketResponse { implements ListBucketResponse {
/** The serialVersionUID */ /** The serialVersionUID */
private static final long serialVersionUID = -4475709781001190244L; private static final long serialVersionUID = -4475709781001190244L;
@ -40,8 +39,8 @@ public class ArrayListBucketResponse extends org.jclouds.rest.BoundedTreeSet<Obj
private final SortedSet<String> commonPrefixes; private final SortedSet<String> commonPrefixes;
private final boolean truncated; private final boolean truncated;
public ArrayListBucketResponse(String bucketName, List<ObjectMetadata> contents, String prefix, public TreeSetListBucketResponse(String bucketName, SortedSet<ObjectMetadata> contents,
String marker, int maxResults, String delimiter, boolean isTruncated, String prefix, String marker, int maxResults, String delimiter, boolean isTruncated,
SortedSet<String> commonPrefixes) { SortedSet<String> commonPrefixes) {
super(contents, prefix, marker, maxResults); super(contents, prefix, marker, maxResults);
this.delimiter = delimiter; this.delimiter = delimiter;

View File

@ -23,29 +23,30 @@
*/ */
package org.jclouds.aws.s3.xml; package org.jclouds.aws.s3.xml;
import java.util.ArrayList; import java.util.SortedSet;
import java.util.List;
import javax.inject.Inject;
import org.jclouds.aws.s3.domain.CanonicalUser;
import org.jclouds.aws.s3.domain.BucketMetadata; import org.jclouds.aws.s3.domain.BucketMetadata;
import org.jclouds.aws.s3.domain.CanonicalUser;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.DateService; import org.jclouds.util.DateService;
import javax.inject.Inject; import com.google.common.collect.Sets;
/** /**
* Parses the following XML document: * Parses the following XML document:
* <p/> * <p/>
* ListAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01" * SortedSetAllMyBucketsResult xmlns="http://doc.s3.amazonaws.com/2006-03-01"
* *
* @see <a * @see <a
* href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html" * href="http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTServiceGET.html"
* /> * />
* @author Adrian Cole * @author Adrian Cole
*/ */
public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<List<BucketMetadata>> { public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<SortedSet<BucketMetadata>> {
private List<BucketMetadata> buckets = new ArrayList<BucketMetadata>(); private SortedSet<BucketMetadata> buckets = Sets.newTreeSet();
private BucketMetadata currentS3Bucket; private BucketMetadata currentS3Bucket;
private CanonicalUser currentOwner; private CanonicalUser currentOwner;
private StringBuilder currentText = new StringBuilder(); private StringBuilder currentText = new StringBuilder();
@ -57,7 +58,7 @@ public class ListAllMyBucketsHandler extends ParseSax.HandlerWithResult<List<Buc
this.dateParser = dateParser; this.dateParser = dateParser;
} }
public List<BucketMetadata> getResult() { public SortedSet<BucketMetadata> getResult() {
return buckets; return buckets;
} }

View File

@ -23,21 +23,20 @@
*/ */
package org.jclouds.aws.s3.xml; package org.jclouds.aws.s3.xml;
import java.util.List;
import java.util.SortedSet; import java.util.SortedSet;
import java.util.TreeSet;
import org.jclouds.aws.s3.domain.ArrayListBucketResponse; import javax.inject.Inject;
import org.jclouds.aws.s3.domain.CanonicalUser; import org.jclouds.aws.s3.domain.CanonicalUser;
import org.jclouds.aws.s3.domain.ListBucketResponse; import org.jclouds.aws.s3.domain.ListBucketResponse;
import org.jclouds.aws.s3.domain.ObjectMetadata; import org.jclouds.aws.s3.domain.ObjectMetadata;
import org.jclouds.aws.s3.domain.TreeSetListBucketResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.util.DateService; import org.jclouds.util.DateService;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import com.google.common.collect.Lists; import com.google.common.collect.Sets;
import javax.inject.Inject;
/** /**
* Parses the following XML document: * Parses the following XML document:
@ -50,7 +49,7 @@ import javax.inject.Inject;
* /> * />
*/ */
public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResponse> { public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResponse> {
private List<ObjectMetadata> contents; private SortedSet<ObjectMetadata> contents;
private SortedSet<String> commonPrefixes; private SortedSet<String> commonPrefixes;
private ObjectMetadata currentObjectMetadata; private ObjectMetadata currentObjectMetadata;
private CanonicalUser currentOwner; private CanonicalUser currentOwner;
@ -67,12 +66,12 @@ public class ListBucketHandler extends ParseSax.HandlerWithResult<ListBucketResp
@Inject @Inject
public ListBucketHandler(DateService dateParser) { public ListBucketHandler(DateService dateParser) {
this.dateParser = dateParser; this.dateParser = dateParser;
this.contents = Lists.newArrayList(); this.contents = Sets.newTreeSet();
this.commonPrefixes = new TreeSet<String>(); this.commonPrefixes = Sets.newTreeSet();
} }
public ListBucketResponse getResult() { public ListBucketResponse getResult() {
return new ArrayListBucketResponse(bucketName, contents, prefix, marker, maxResults, return new TreeSetListBucketResponse(bucketName, contents, prefix, marker, maxResults,
delimiter, isTruncated, commonPrefixes); delimiter, isTruncated, commonPrefixes);
} }

View File

@ -0,0 +1,88 @@
/**
*
* Copyright (C) 2009 Global Cloud Specialists, Inc. <info@globalcloudspecialists.com>
*
* ====================================================================
* 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.config;
import static org.testng.Assert.assertEquals;
import org.jclouds.aws.s3.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.s3.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.s3.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.s3.reference.S3Constants;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.util.Jsr330;
import org.testng.annotations.Test;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
/**
* @author Adrian Cole
*/
@Test(groups = "unit", testName = "s3.RestS3ConnectionModuleTest")
public class RestS3ConnectionModuleTest {
Injector createInjector() {
return Guice.createInjector(new RestS3ConnectionModule(), new ParserModule(), new AbstractModule() {
@Override
protected void configure() {
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_ACCESSKEYID)).to(
"user");
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_AWS_SECRETACCESSKEY))
.to("key");
bindConstant().annotatedWith(Jsr330.named(S3Constants.PROPERTY_S3_ENDPOINT)).to(
"http://localhost");
}
});
}
@Test
void testServerErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler().getClass(),
AWSClientErrorRetryHandler.class);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(),
AWSRedirectionRetryHandler.class);
}
}

View File

@ -26,20 +26,13 @@ package org.jclouds.aws.s3.config;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
import org.jclouds.aws.s3.S3BlobStore; import org.jclouds.aws.s3.S3BlobStore;
import org.jclouds.aws.s3.S3Context;
import org.jclouds.aws.s3.config.S3ContextModule.S3ContextImpl;
import org.jclouds.aws.s3.domain.BucketMetadata; import org.jclouds.aws.s3.domain.BucketMetadata;
import org.jclouds.aws.s3.domain.ObjectMetadata; import org.jclouds.aws.s3.domain.ObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.handlers.AWSClientErrorRetryHandler;
import org.jclouds.aws.s3.handlers.AWSRedirectionRetryHandler;
import org.jclouds.aws.s3.handlers.ParseAWSErrorFromXmlContent;
import org.jclouds.aws.s3.reference.S3Constants; import org.jclouds.aws.s3.reference.S3Constants;
import org.jclouds.blobstore.BlobStoreMapsModule; import org.jclouds.blobstore.BlobStoreMapsModule;
import org.jclouds.concurrent.WithinThreadExecutorService;
import org.jclouds.concurrent.config.ExecutorServiceModule;
import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule;
import org.jclouds.http.functions.config.ParserModule;
import org.jclouds.http.handlers.DelegatingErrorHandler;
import org.jclouds.http.handlers.DelegatingRetryHandler;
import org.jclouds.util.Jsr330; import org.jclouds.util.Jsr330;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -54,7 +47,7 @@ import com.google.inject.TypeLiteral;
public class S3ContextModuleTest { public class S3ContextModuleTest {
Injector createInjector() { Injector createInjector() {
return Guice.createInjector(new RestS3ConnectionModule(), BlobStoreMapsModule.Builder return Guice.createInjector(new StubS3BlobStoreModule(), BlobStoreMapsModule.Builder
.newBuilder(new TypeLiteral<S3BlobStore>() { .newBuilder(new TypeLiteral<S3BlobStore>() {
}, new TypeLiteral<BucketMetadata>() { }, new TypeLiteral<BucketMetadata>() {
}, new TypeLiteral<ObjectMetadata>() { }, new TypeLiteral<ObjectMetadata>() {
@ -70,34 +63,13 @@ public class S3ContextModuleTest {
"http://localhost"); "http://localhost");
super.configure(); super.configure();
} }
}, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), });
new ExecutorServiceModule(new WithinThreadExecutorService()));
} }
@Test @Test
void testServerErrorHandler() { void testContextImpl() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); S3Context handler = createInjector().getInstance(S3Context.class);
assertEquals(handler.getServerErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class); assertEquals(handler.getClass(), S3ContextImpl.class);
}
@Test
void testClientErrorHandler() {
DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class);
assertEquals(handler.getClientErrorHandler().getClass(), ParseAWSErrorFromXmlContent.class);
}
@Test
void testClientRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getClientErrorRetryHandler().getClass(),
AWSClientErrorRetryHandler.class);
}
@Test
void testRedirectionRetryHandler() {
DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class);
assertEquals(handler.getRedirectionRetryHandler().getClass(),
AWSRedirectionRetryHandler.class);
} }
} }

View File

@ -36,12 +36,12 @@ import javax.inject.Provider;
import org.jclouds.aws.s3.S3BlobStore; import org.jclouds.aws.s3.S3BlobStore;
import org.jclouds.aws.s3.domain.AccessControlList; import org.jclouds.aws.s3.domain.AccessControlList;
import org.jclouds.aws.s3.domain.ArrayListBucketResponse;
import org.jclouds.aws.s3.domain.BucketMetadata; import org.jclouds.aws.s3.domain.BucketMetadata;
import org.jclouds.aws.s3.domain.CannedAccessPolicy; import org.jclouds.aws.s3.domain.CannedAccessPolicy;
import org.jclouds.aws.s3.domain.ListBucketResponse; import org.jclouds.aws.s3.domain.ListBucketResponse;
import org.jclouds.aws.s3.domain.ObjectMetadata; import org.jclouds.aws.s3.domain.ObjectMetadata;
import org.jclouds.aws.s3.domain.S3Object; import org.jclouds.aws.s3.domain.S3Object;
import org.jclouds.aws.s3.domain.TreeSetListBucketResponse;
import org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee; import org.jclouds.aws.s3.domain.AccessControlList.CanonicalUserGrantee;
import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee; import org.jclouds.aws.s3.domain.AccessControlList.EmailAddressGrantee;
import org.jclouds.aws.s3.domain.AccessControlList.Grant; import org.jclouds.aws.s3.domain.AccessControlList.Grant;
@ -61,7 +61,6 @@ import org.joda.time.DateTime;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.base.Predicate; import com.google.common.base.Predicate;
import com.google.common.collect.Iterables; import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.google.inject.internal.Nullable; import com.google.inject.internal.Nullable;
@ -167,8 +166,8 @@ public class StubS3BlobStore extends StubBlobStore<BucketMetadata, ObjectMetadat
} }
contents = contentsSlice; contents = contentsSlice;
} }
return new ArrayListBucketResponse(name, Lists.newArrayList(contents), prefix, marker, return new TreeSetListBucketResponse(name, contents, prefix, marker, maxResults,
maxResults, delimiter, truncated, commonPrefixes); delimiter, truncated, commonPrefixes);
} }
}; };
} }

View File

@ -27,7 +27,7 @@ import static org.testng.Assert.assertEquals;
import java.io.IOException; import java.io.IOException;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.List; import java.util.SortedSet;
import java.util.concurrent.Callable; import java.util.concurrent.Callable;
import java.util.concurrent.CompletionService; import java.util.concurrent.CompletionService;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -84,8 +84,8 @@ public class S3ParserTest extends PerformanceTest {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private List<BucketMetadata> runParseListAllMyBuckets() throws HttpException { private SortedSet<BucketMetadata> runParseListAllMyBuckets() throws HttpException {
return (List<BucketMetadata>) factory.create( return (SortedSet<BucketMetadata>) factory.create(
injector.getInstance(ListAllMyBucketsHandler.class)).parse( injector.getInstance(ListAllMyBucketsHandler.class)).parse(
IOUtils.toInputStream(listAllMyBucketsResultOn200)); IOUtils.toInputStream(listAllMyBucketsResultOn200));
} }
@ -93,11 +93,11 @@ public class S3ParserTest extends PerformanceTest {
@Test @Test
void testParseListAllMyBucketsParallelResponseTime() throws InterruptedException, void testParseListAllMyBucketsParallelResponseTime() throws InterruptedException,
ExecutionException { ExecutionException {
CompletionService<List<BucketMetadata>> completer = new ExecutorCompletionService<List<BucketMetadata>>( CompletionService<SortedSet<BucketMetadata>> completer = new ExecutorCompletionService<SortedSet<BucketMetadata>>(
exec); exec);
for (int i = 0; i < LOOP_COUNT; i++) for (int i = 0; i < LOOP_COUNT; i++)
completer.submit(new Callable<List<BucketMetadata>>() { completer.submit(new Callable<SortedSet<BucketMetadata>>() {
public List<BucketMetadata> call() throws IOException, SAXException, HttpException { public SortedSet<BucketMetadata> call() throws IOException, SAXException, HttpException {
return runParseListAllMyBuckets(); return runParseListAllMyBuckets();
} }
}); });
@ -107,13 +107,13 @@ public class S3ParserTest extends PerformanceTest {
@Test @Test
public void testCanParseListAllMyBuckets() throws HttpException { public void testCanParseListAllMyBuckets() throws HttpException {
List<BucketMetadata> s3Buckets = runParseListAllMyBuckets(); SortedSet<BucketMetadata> s3Buckets = runParseListAllMyBuckets();
BucketMetadata container1 = s3Buckets.get(0); BucketMetadata container1 = s3Buckets.first();
assert container1.getName().equals("adrianjbosstest"); assert container1.getName().equals("adrianjbosstest");
DateTime expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z"); DateTime expectedDate1 = new DateTime("2009-03-12T02:00:07.000Z");
DateTime date1 = container1.getCreationDate(); DateTime date1 = container1.getCreationDate();
assert date1.equals(expectedDate1); assert date1.equals(expectedDate1);
BucketMetadata container2 = s3Buckets.get(1); BucketMetadata container2 = (BucketMetadata) s3Buckets.toArray()[1];
assert container2.getName().equals("adrianjbosstest2"); assert container2.getName().equals("adrianjbosstest2");
DateTime expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z"); DateTime expectedDate2 = new DateTime("2009-03-12T02:00:09.000Z");
DateTime date2 = container2.getCreationDate(); DateTime date2 = container2.getCreationDate();

View File

@ -24,8 +24,7 @@
package org.jclouds.mezeo.pcs2.xml; package org.jclouds.mezeo.pcs2.xml;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.SortedSet;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
@ -36,13 +35,15 @@ import org.joda.time.DateTime;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class FileListToContainerMetadataListHandler extends public class FileListToContainerMetadataListHandler extends
ParseSax.HandlerWithResult<List<ContainerMetadata>> { ParseSax.HandlerWithResult<SortedSet<ContainerMetadata>> {
private List<ContainerMetadata> containerMetadata = new ArrayList<ContainerMetadata>(); private SortedSet<ContainerMetadata> containerMetadata = Sets.newTreeSet();
private URI currentUrl; private URI currentUrl;
private String currentName; private String currentName;
private DateTime currentCreated; private DateTime currentCreated;
@ -63,7 +64,7 @@ public class FileListToContainerMetadataListHandler extends
this.dateParser = dateParser; this.dateParser = dateParser;
} }
public List<ContainerMetadata> getResult() { public SortedSet<ContainerMetadata> getResult() {
return containerMetadata; return containerMetadata;
} }

View File

@ -24,8 +24,7 @@
package org.jclouds.mezeo.pcs2.xml; package org.jclouds.mezeo.pcs2.xml;
import java.net.URI; import java.net.URI;
import java.util.ArrayList; import java.util.SortedSet;
import java.util.List;
import javax.inject.Inject; import javax.inject.Inject;
@ -34,20 +33,22 @@ import org.jclouds.util.DateService;
import org.xml.sax.Attributes; import org.xml.sax.Attributes;
import org.xml.sax.SAXException; import org.xml.sax.SAXException;
import com.google.common.collect.Sets;
/** /**
* @author Adrian Cole * @author Adrian Cole
*/ */
public class FileListToFileMetadataListHandler extends public class FileListToFileMetadataListHandler extends
BaseFileMetadataHandler<List<FileMetadata>> { BaseFileMetadataHandler<SortedSet<FileMetadata>> {
private List<FileMetadata> containerMetadata = new ArrayList<FileMetadata>(); private SortedSet<FileMetadata> containerMetadata = Sets.newTreeSet();
@Inject @Inject
public FileListToFileMetadataListHandler(DateService dateParser) { public FileListToFileMetadataListHandler(DateService dateParser) {
super(dateParser); super(dateParser);
} }
public List<FileMetadata> getResult() { public SortedSet<FileMetadata> getResult() {
return containerMetadata; return containerMetadata;
} }

View File

@ -27,7 +27,7 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.SortedSet;
import org.jclouds.http.functions.BaseHandlerTest; import org.jclouds.http.functions.BaseHandlerTest;
import org.jclouds.mezeo.pcs2.domain.ContainerMetadata; import org.jclouds.mezeo.pcs2.domain.ContainerMetadata;
@ -35,7 +35,7 @@ import org.jclouds.util.DateService;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedSet;
/** /**
* Tests behavior of {@code FileListToContainerMetadataListHandler} * Tests behavior of {@code FileListToContainerMetadataListHandler}
@ -58,7 +58,7 @@ public class FileListToContainerMetadataListHandlerTest extends BaseHandlerTest
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_file_list.xml"); InputStream is = getClass().getResourceAsStream("/test_file_list.xml");
List<ContainerMetadata> list = ImmutableList SortedSet<ContainerMetadata> list = ImmutableSortedSet
.of(new ContainerMetadata( .of(new ContainerMetadata(
"test1", "test1",
URI URI
@ -67,7 +67,7 @@ public class FileListToContainerMetadataListHandlerTest extends BaseHandlerTest
dateService.fromSeconds(1254008227), "adrian@jclouds.org", true, false, 1, dateService.fromSeconds(1254008227), "adrian@jclouds.org", true, false, 1,
1024)); 1024));
List<ContainerMetadata> result = (List<ContainerMetadata>) factory.create( SortedSet<ContainerMetadata> result = (SortedSet<ContainerMetadata>) factory.create(
injector.getInstance(FileListToContainerMetadataListHandler.class)).parse(is); injector.getInstance(FileListToContainerMetadataListHandler.class)).parse(is);
assertEquals(result, list); assertEquals(result, list);

View File

@ -27,7 +27,7 @@ import static org.testng.Assert.assertEquals;
import java.io.InputStream; import java.io.InputStream;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.SortedSet;
import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MediaType;
@ -37,10 +37,10 @@ import org.jclouds.util.DateService;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSortedSet;
/** /**
* Tests behavior of {@code FileListToFileMetadataListHandler} * Tests behavior of {@code FileSortedSetToFileMetadataSortedSetHandler}
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
@ -60,7 +60,7 @@ public class FileListToFileMetadataListHandlerTest extends BaseHandlerTest {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void testApplyInputStream() { public void testApplyInputStream() {
InputStream is = getClass().getResourceAsStream("/test_file_list.xml"); InputStream is = getClass().getResourceAsStream("/test_file_list.xml");
List<FileMetadata> list = ImmutableList.of(new FileMetadata("more", URI SortedSet<FileMetadata> list = ImmutableSortedSet.of(new FileMetadata("more", URI
.create("https://pcsbeta.mezeo.net/v2/files/5C81DADC-AAEE-11DE-9D55-B39340AEFF3A"), .create("https://pcsbeta.mezeo.net/v2/files/5C81DADC-AAEE-11DE-9D55-B39340AEFF3A"),
dateService.fromSeconds(1254005157), dateService.fromSeconds(1254005158), dateService.fromSeconds(1254005157), dateService.fromSeconds(1254005158),
dateService.fromSeconds(1254005159), "adrian@jclouds.org", false, false, 1, 254288, dateService.fromSeconds(1254005159), "adrian@jclouds.org", false, false, 1, 254288,
@ -72,7 +72,7 @@ public class FileListToFileMetadataListHandlerTest extends BaseHandlerTest {
dateService.fromSeconds(1254000182), "adrian@jclouds.org", false, true, 3, 5, dateService.fromSeconds(1254000182), "adrian@jclouds.org", false, true, 3, 5,
MediaType.TEXT_PLAIN, false)); MediaType.TEXT_PLAIN, false));
List<FileMetadata> result = (List<FileMetadata>) factory.create( SortedSet<FileMetadata> result = (SortedSet<FileMetadata>) factory.create(
injector.getInstance(FileListToFileMetadataListHandler.class)).parse(is); injector.getInstance(FileListToFileMetadataListHandler.class)).parse(is);
assertEquals(result, list); assertEquals(result, list);

View File

@ -27,7 +27,9 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List; import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.blobstore.domain.BlobMetadata; import org.jclouds.blobstore.domain.BlobMetadata;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
@ -35,24 +37,24 @@ import org.jclouds.http.functions.ParseJson;
import org.joda.time.DateTime; import org.joda.time.DateTime;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Lists; import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import javax.inject.Inject;
/** /**
* This parses {@link BlobMetadata} from a gson string. * This parses {@link BlobMetadata} from a gson string.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class ParseBlobMetadataListFromJsonResponse extends ParseJson<List<BlobMetadata>> { public class ParseBlobMetadataListFromJsonResponse extends ParseJson<SortedSet<BlobMetadata>> {
@Inject @Inject
public ParseBlobMetadataListFromJsonResponse(Gson gson) { public ParseBlobMetadataListFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
public static class CloudFilesMetadata { public static class CloudFilesMetadata implements Comparable<CloudFilesMetadata> {
public CloudFilesMetadata() { public CloudFilesMetadata() {
} }
@ -61,16 +63,21 @@ public class ParseBlobMetadataListFromJsonResponse extends ParseJson<List<BlobMe
long bytes; long bytes;
String content_type; String content_type;
DateTime last_modified; DateTime last_modified;
public int compareTo(CloudFilesMetadata o) {
return (this == o) ? 0 : name.compareTo(o.name);
}
} }
public List<BlobMetadata> apply(InputStream stream) { public SortedSet<BlobMetadata> apply(InputStream stream) {
Type listType = new TypeToken<List<CloudFilesMetadata>>() { Type listType = new TypeToken<SortedSet<CloudFilesMetadata>>() {
}.getType(); }.getType();
try { try {
List<CloudFilesMetadata> list = gson.fromJson(new InputStreamReader(stream, "UTF-8"), SortedSet<CloudFilesMetadata> list = gson.fromJson(new InputStreamReader(stream, "UTF-8"),
listType); listType);
return Lists.transform(list, new Function<CloudFilesMetadata, BlobMetadata>() { return Sets.newTreeSet(Iterables.transform(list,
new Function<CloudFilesMetadata, BlobMetadata>() {
public BlobMetadata apply(CloudFilesMetadata from) { public BlobMetadata apply(CloudFilesMetadata from) {
BlobMetadata metadata = new BlobMetadata(from.name); BlobMetadata metadata = new BlobMetadata(from.name);
metadata.setSize(from.bytes); metadata.setSize(from.bytes);
@ -79,7 +86,7 @@ public class ParseBlobMetadataListFromJsonResponse extends ParseJson<List<BlobMe
metadata.setETag(HttpUtils.fromHexString(from.hash)); metadata.setETag(HttpUtils.fromHexString(from.hash));
return metadata; return metadata;
} }
}); }));
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
throw new RuntimeException("jclouds requires UTF-8 encoding", e); throw new RuntimeException("jclouds requires UTF-8 encoding", e);

View File

@ -27,21 +27,22 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List; import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata; import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import javax.inject.Inject;
/** /**
* This parses {@link ContainerCDNMetadata} from a gson string. * This parses {@link ContainerCDNMetadata} from a gson string.
* *
* @author James Murty * @author James Murty
*/ */
public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson<List<ContainerCDNMetadata>> public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson<SortedSet<ContainerCDNMetadata>>
{ {
@Inject @Inject
@ -49,8 +50,8 @@ public class ParseContainerCDNMetadataListFromGsonResponse extends ParseJson<Lis
super(gson); super(gson);
} }
public List<ContainerCDNMetadata> apply(InputStream stream) { public SortedSet<ContainerCDNMetadata> apply(InputStream stream) {
Type listType = new TypeToken<List<ContainerCDNMetadata>>() { Type listType = new TypeToken<SortedSet<ContainerCDNMetadata>>() {
}.getType(); }.getType();
try { try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType); return gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType);

View File

@ -27,29 +27,30 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.List; import java.util.SortedSet;
import javax.inject.Inject;
import org.jclouds.http.functions.ParseJson; import org.jclouds.http.functions.ParseJson;
import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata; import org.jclouds.rackspace.cloudfiles.domain.ContainerMetadata;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import javax.inject.Inject;
/** /**
* This parses {@link ContainerMetadata} from a gson string. * This parses {@link ContainerMetadata} from a gson string.
* *
* @author Adrian Cole * @author Adrian Cole
*/ */
public class ParseContainerListFromJsonResponse extends ParseJson<List<ContainerMetadata>> { public class ParseContainerListFromJsonResponse extends ParseJson<SortedSet<ContainerMetadata>> {
@Inject @Inject
public ParseContainerListFromJsonResponse(Gson gson) { public ParseContainerListFromJsonResponse(Gson gson) {
super(gson); super(gson);
} }
public List<ContainerMetadata> apply(InputStream stream) { public SortedSet<ContainerMetadata> apply(InputStream stream) {
Type listType = new TypeToken<List<ContainerMetadata>>() { Type listType = new TypeToken<SortedSet<ContainerMetadata>>() {
}.getType(); }.getType();
try { try {
return gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType); return gson.fromJson(new InputStreamReader(stream, "UTF-8"), listType);