Issue 75: Fixed options for listing CDN containers

git-svn-id: http://jclouds.googlecode.com/svn/trunk@1836 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
jamurty 2009-08-09 02:14:58 +00:00
parent cbb0050d43
commit def8a44348
2 changed files with 73 additions and 10 deletions

View File

@ -23,23 +23,69 @@
*/
package org.jclouds.rackspace.cloudfiles.options;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import org.jclouds.http.options.BaseHttpRequestOptions;
/**
* Contains options supported in the REST API for the GET container operation. <h2>
* Contains options supported in the REST API for the GET CDN containers operation.
*/
public class ListCdnContainerOptions extends ListContainerOptions {
public class ListCdnContainerOptions extends BaseHttpRequestOptions {
public static final ListCdnContainerOptions NONE = new ListCdnContainerOptions();
public ListCdnContainerOptions isCdnEnabled(boolean enabledOnly) {
queryParameters.put("enabled_only", (enabledOnly ? "true" : "false"));
public ListCdnContainerOptions enabledOnly() {
queryParameters.put("enabled_only", "true");
return this;
}
public static class Builder extends ListContainerOptions.Builder {
public static ListCdnContainerOptions isCdnEnabled(boolean enabledOnly) {
ListCdnContainerOptions options = new ListCdnContainerOptions();
return options.isCdnEnabled(enabledOnly);
}
/**
* Indicates where to begin listing the account's containers. The list will only include
* containers whose names occur lexicographically after the marker. This is convenient for
* pagination: To get the next page of results use the last container name of the current
* page as the marker.
*/
public ListCdnContainerOptions afterMarker(String marker) {
queryParameters.put("marker", checkNotNull(marker, "marker"));
return this;
}
/**
* The maximum number of containers that will be included in the response body.
* The server might return fewer than this many containers, but will not return more.
*/
public ListCdnContainerOptions maxResults(int limit) {
checkState(limit >= 0, "limit must be >= 0");
checkState(limit <= 10000, "limit must be <= 10000");
queryParameters.put("limit", Integer.toString(limit));
return this;
}
public static class Builder {
public static ListCdnContainerOptions enabledOnly() {
ListCdnContainerOptions options = new ListCdnContainerOptions();
return options.enabledOnly();
}
/**
* @see ListCdnContainerOptions#afterMarker(String)
*/
public static ListCdnContainerOptions afterMarker(String marker) {
ListCdnContainerOptions options = new ListCdnContainerOptions();
return options.afterMarker(marker);
}
/**
* @see ListCdnContainerOptions#limit(int)
*/
public static ListCdnContainerOptions maxResults(int limit) {
ListCdnContainerOptions options = new ListCdnContainerOptions();
return options.maxResults(limit);
}
}
}

View File

@ -32,6 +32,7 @@ import java.util.List;
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
import org.jclouds.rackspace.cloudfiles.domain.ContainerCDNMetadata;
import org.jclouds.rackspace.cloudfiles.options.ListCdnContainerOptions;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
@ -92,6 +93,7 @@ public class CloudFilesCDNConnectionLiveTest {
// List CDN metadata for containers, and ensure all CDN info is available for enabled container
List<ContainerCDNMetadata> cdnMetadataList = cdnConnection.listCDNContainers();
assertTrue(cdnMetadataList.size() >= 1);
assertTrue(Iterables.any(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
public boolean apply(ContainerCDNMetadata cdnMetadata) {
return (
@ -101,6 +103,21 @@ public class CloudFilesCDNConnectionLiveTest {
cdnMetadata.getCdnUri().equals(cdnUri));
}
}));
// Test listing with options
cdnMetadataList = cdnConnection.listCDNContainers(
ListCdnContainerOptions.Builder.enabledOnly());
assertTrue(Iterables.all(cdnMetadataList, new Predicate<ContainerCDNMetadata>() {
public boolean apply(ContainerCDNMetadata cdnMetadata) {
return cdnMetadata.isCdnEnabled();
}
}));
cdnMetadataList = cdnConnection.listCDNContainers(ListCdnContainerOptions.Builder
.afterMarker(containerNameWithCDN.substring(0, containerNameWithCDN.length() - 1))
.maxResults(1));
assertEquals(cdnMetadataList.size(), 1);
assertEquals(cdnMetadataList.get(0).getName(), containerNameWithCDN);
// Enable CDN with PUT for the same container, this time with a custom TTL
long ttl = 4000;