You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ev...@apache.org on 2014/04/04 01:13:36 UTC

git commit: Added ObjectApi.list() and ContainerApi.head() methods/tests

Repository: jclouds-labs-openstack
Updated Branches:
  refs/heads/master ab188ef80 -> a9ad08d7f


Added ObjectApi.list() and ContainerApi.head() methods/tests


Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/commit/a9ad08d7
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/tree/a9ad08d7
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/diff/a9ad08d7

Branch: refs/heads/master
Commit: a9ad08d7f2139dc2a2ad0cdeecf2c80f4fe5e346
Parents: ab188ef
Author: Jeremy Daggett <je...@rackspace.com>
Authored: Wed Apr 2 10:53:49 2014 -0700
Committer: Everett Toews <ev...@rackspace.com>
Committed: Thu Apr 3 18:13:32 2014 -0500

----------------------------------------------------------------------
 .../swift/v1/features/ContainerApi.java         | 17 +++++++
 .../openstack/swift/v1/features/ObjectApi.java  | 19 ++++++++
 .../swift/v1/features/ContainerApiLiveTest.java | 11 ++++-
 .../swift/v1/features/ContainerApiMockTest.java | 48 ++++++++++++++++++++
 .../swift/v1/features/ObjectApiLiveTest.java    | 12 ++++-
 .../swift/v1/features/ObjectApiMockTest.java    | 24 +++++++++-
 6 files changed, 128 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/a9ad08d7/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java
----------------------------------------------------------------------
diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java
index c98f2bc..6f5aa97 100644
--- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java
+++ b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ContainerApi.java
@@ -111,6 +111,23 @@ public interface ContainerApi {
    boolean createIfAbsent(@PathParam("containerName") String containerName, CreateContainerOptions options);
 
    /**
+    * Gets the {@link Container} metadata, including the number of objects in the container and 
+    * the total bytes for all objects stored in the container.
+    * 
+    * @param containerName
+    *           corresponds to {@link Container#getName()}.
+    * 
+    * @return the {@link Container}, or {@code null} if not found.
+    */
+   @Named("container:get")
+   @HEAD
+   @ResponseParser(ParseContainerFromHeaders.class)
+   @Fallback(NullOnNotFoundOr404.class)
+   @Path("/{containerName}")
+   @Nullable
+   Container head(@PathParam("containerName") String containerName);
+
+   /**
     * Gets the {@link Container}.
     * 
     * @param containerName

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/a9ad08d7/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
----------------------------------------------------------------------
diff --git a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
index ec0217b..0320542 100644
--- a/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
+++ b/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java
@@ -87,6 +87,25 @@ public interface ObjectApi {
    @Fallback(NullOnNotFoundOr404.class)
    @Path("/")
    @Nullable
+   ObjectList list();
+
+   /**
+    * Lists up to 10,000 objects. To control a large list of containers beyond
+    * 10,000 objects, use the {@code marker} and {@code endMarker} parameters in the
+    * {@link ListContainerOptions} class.
+    * 
+    * @param options  
+    *           the {@link ListContainerOptions} for controlling the returned list.
+    * 
+    * @return an {@link ObjectList} of {@link SwiftObject} ordered by name or {@code null}.
+    */
+   @Named("object:list")
+   @GET
+   @QueryParams(keys = "format", values = "json")
+   @ResponseParser(ParseObjectListFromResponse.class)
+   @Fallback(NullOnNotFoundOr404.class)
+   @Path("/")
+   @Nullable
    ObjectList list(ListContainerOptions options);
 
    /**

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/a9ad08d7/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java
----------------------------------------------------------------------
diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java
index 31ff231..19e0d14 100644
--- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java
+++ b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiLiveTest.java
@@ -68,7 +68,16 @@ public class ContainerApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
          assertTrue(container.getBytesUsed() == 0);
       }
    }
-   
+
+   public void testHead() throws Exception {
+      for (String regionId : regions) {
+         Container container = api.containerApiInRegion(regionId).head(name);
+         assertEquals(container.getName(), name);
+         assertTrue(container.getObjectCount() == 0);
+         assertTrue(container.getBytesUsed() == 0);
+      }
+   }
+
    public void testGet() throws Exception {
       for (String regionId : regions) {
          Container container = api.containerApiInRegion(regionId).get(name);

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/a9ad08d7/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java
----------------------------------------------------------------------
diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java
index 752b4b7..a595686 100644
--- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java
+++ b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ContainerApiMockTest.java
@@ -26,11 +26,14 @@ import static org.jclouds.openstack.swift.v1.reference.SwiftHeaders.CONTAINER_RE
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertFalse;
 import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertNull;
 import static org.testng.Assert.assertTrue;
 
 import java.util.Map;
 import java.util.Map.Entry;
 
+import org.jclouds.blobstore.ContainerNotFoundException;
+import org.jclouds.openstack.swift.v1.CopyObjectException;
 import org.jclouds.openstack.swift.v1.SwiftApi;
 import org.jclouds.openstack.swift.v1.domain.Container;
 import org.jclouds.openstack.swift.v1.options.CreateContainerOptions;
@@ -102,6 +105,51 @@ public class ContainerApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
       }
    }
 
+   public void testContainerExists() throws Exception {
+      MockWebServer server = mockOpenStackServer();
+      server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
+      server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(201)));
+      server.enqueue(addCommonHeaders(containerResponse()
+            .addHeader(CONTAINER_METADATA_PREFIX + "ApiName", "swift")
+            .addHeader(CONTAINER_METADATA_PREFIX + "ApiVersion", "v1.1")));
+
+      try {
+         SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
+         assertTrue(api.containerApiInRegion("DFW").createIfAbsent("myContainer", anybodyRead().metadata(metadata)));
+         
+         Container container = api.containerApiInRegion("DFW").head("myContainer");
+         assertEquals(container.getName(), "myContainer");
+         assertEquals(container.getObjectCount(), 42l);
+         assertEquals(container.getBytesUsed(), 323479l);
+         for (Entry<String, String> entry : container.getMetadata().entrySet()) {
+            assertEquals(container.getMetadata().get(entry.getKey().toLowerCase()), entry.getValue());
+         }
+         assertEquals(server.getRequestCount(), 3);
+         assertAuthentication(server);
+         assertRequest(server.takeRequest(), "PUT", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer");
+         assertRequest(server.takeRequest(), "HEAD", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer");
+      } finally {
+         server.shutdown();
+      }
+   }
+
+   @Test(expectedExceptions = ContainerNotFoundException.class)
+   public void testContainerDoesNotExist() throws Exception {
+      MockWebServer server = mockOpenStackServer();
+      server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
+      server.enqueue(addCommonHeaders(new MockResponse().setResponseCode(404)));
+
+      try {
+         SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
+         assertTrue(api.containerApiInRegion("DFW").createIfAbsent("myContainer", anybodyRead().metadata(metadata)));
+
+         // the head call will throw the ContainerNotFoundException
+         api.containerApiInRegion("DFW").head("myContainer");
+      } finally {
+         server.shutdown();
+      }
+   }
+
    public void testCreateIfAbsent() throws Exception {
       MockWebServer server = mockOpenStackServer();
       server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/a9ad08d7/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java
index db835fd..907afb6 100644
--- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java
+++ b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiLiveTest.java
@@ -123,9 +123,19 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
    public void testList() throws Exception {
       for (String regionId : regions) {
          ObjectApi objectApi = api.objectApiInRegionForContainer(regionId, containerName);
+         ObjectList response = objectApi.list();
+         assertEquals(response.getContainer(), api.containerApiInRegion(regionId).get(containerName));
+         for (SwiftObject object : response) {
+            checkObject(object);
+         }
+      }
+   }
+
+   public void testListWithOptions() throws Exception {
+      for (String regionId : regions) {
+         ObjectApi objectApi = api.objectApiInRegionForContainer(regionId, containerName);
          ObjectList response = objectApi.list(ListContainerOptions.NONE);
          assertEquals(response.getContainer(), api.containerApiInRegion(regionId).get(containerName));
-         assertNotNull(response);
          for (SwiftObject object : response) {
             checkObject(object);
          }

http://git-wip-us.apache.org/repos/asf/jclouds-labs-openstack/blob/a9ad08d7/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java
----------------------------------------------------------------------
diff --git a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java
index d44e308..7fe10b7 100644
--- a/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java
+++ b/openstack-swift/src/test/java/org/jclouds/openstack/swift/v1/features/ObjectApiMockTest.java
@@ -89,7 +89,7 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
 
       try {
          SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
-         ObjectList objects = api.objectApiInRegionForContainer("DFW", "myContainer").list(new ListContainerOptions());
+         ObjectList objects = api.objectApiInRegionForContainer("DFW", "myContainer").list();
          assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString()));
          assertEquals(objects.getContainer().getName(), "myContainer");
          assertTrue(objects.getContainer().getAnybodyRead().get());
@@ -102,6 +102,28 @@ public class ObjectApiMockTest extends BaseOpenStackMockTest<SwiftApi> {
       }
    }
 
+   public void testListWithOptions() throws Exception {
+      MockWebServer server = mockOpenStackServer();
+      server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));
+      server.enqueue(addCommonHeaders(containerResponse()
+            .addHeader(CONTAINER_READ, CONTAINER_ACL_ANYBODY_READ)
+            .setBody(stringFromResource("/object_list.json"))));
+
+      try {
+         SwiftApi api = api(server.getUrl("/").toString(), "openstack-swift");
+         ObjectList objects = api.objectApiInRegionForContainer("DFW", "myContainer").list(new ListContainerOptions());
+         assertEquals(objects, parsedObjectsForUrl(server.getUrl("/").toString()));
+         assertEquals(objects.getContainer().getName(), "myContainer");
+         assertTrue(objects.getContainer().getAnybodyRead().get());
+
+         assertEquals(server.getRequestCount(), 2);
+         assertAuthentication(server);
+         assertRequest(server.takeRequest(), "GET", "/v1/MossoCloudFS_5bcf396e-39dd-45ff-93a1-712b9aba90a9/myContainer/?format=json");
+      } finally {
+         server.shutdown();
+      }
+   }
+   
    public void testListOptions() throws Exception {
       MockWebServer server = mockOpenStackServer();
       server.enqueue(addCommonHeaders(new MockResponse().setBody(stringFromResource("/access.json"))));