From 5f3bee6f2e5a51b1662e779bf44db7f4160ff364 Mon Sep 17 00:00:00 2001 From: "adrian.f.cole" Date: Tue, 15 Dec 2009 05:46:35 +0000 Subject: [PATCH] Issue 111: set filetype to directory when someone accidentally lists a file as a directory git-svn-id: http://jclouds.googlecode.com/svn/trunk@2431 3d8758e0-26b5-11de-8745-db77d3ebf521 --- .../saas/AtmosStorageAsyncClient.java | 2 + .../atmosonline/saas/AtmosStorageClient.java | 3 ++ .../saas/AtmosStorageResponseException.java | 8 ++-- .../functions/ObjectToBlobMetadata.java | 7 ++- .../saas/AtmosStorageClientTest.java | 5 +- .../functions/ObjectToBlobMetadataTest.java | 47 +++++++++++++++++++ 6 files changed, 65 insertions(+), 7 deletions(-) create mode 100644 atmos/src/test/java/org/jclouds/atmosonline/saas/blobstore/functions/ObjectToBlobMetadataTest.java diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClient.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClient.java index b857c81973..3bec084e23 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClient.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageAsyncClient.java @@ -52,6 +52,7 @@ import org.jclouds.atmosonline.saas.options.ListOptions; import org.jclouds.blobstore.attr.ConsistencyModel; import org.jclouds.blobstore.attr.ConsistencyModels; import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.http.functions.ReturnFalseOn404; import org.jclouds.http.options.GetOptions; @@ -96,6 +97,7 @@ public interface AtmosStorageAsyncClient { @GET @Path("/rest/namespace/{directoryName}/") @ResponseParser(ParseDirectoryListFromContentAndHeaders.class) + @ExceptionParser(ThrowContainerNotFoundOn404.class) @Consumes(MediaType.TEXT_XML) Future> listDirectory( @PathParam("directoryName") String directoryName, ListOptions... options); diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageClient.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageClient.java index f15b3fa5d5..971ac55d3b 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageClient.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageClient.java @@ -55,10 +55,13 @@ public interface AtmosStorageClient { URI createDirectory(String directoryName); + @Timeout(duration = 10, timeUnit = TimeUnit.MINUTES) URI createFile(String parent, AtmosObject object); + @Timeout(duration = 10, timeUnit = TimeUnit.MINUTES) void updateFile(String parent, AtmosObject object); + @Timeout(duration = 10, timeUnit = TimeUnit.MINUTES) AtmosObject readFile(String path, GetOptions... options); AtmosObject headFile(String path); diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageResponseException.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageResponseException.java index 7b2146eb5e..d3861d1f04 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageResponseException.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/AtmosStorageResponseException.java @@ -45,16 +45,16 @@ public class AtmosStorageResponseException extends HttpResponseException { public AtmosStorageResponseException(HttpCommand command, HttpResponse response, AtmosStorageError error) { - super(String.format("command %s failed with code %s, error: %s", command.toString(), response - .getStatusCode(), error.toString()), command, response); + super(String.format("command %s failed with code %s, error: %s", command.getRequest() + .getRequestLine(), response.getStatusCode(), error.toString()), command, response); this.setError(error); } public AtmosStorageResponseException(HttpCommand command, HttpResponse response, AtmosStorageError error, Throwable cause) { - super(String.format("command %1$s failed with error: %2$s", command.toString(), error - .toString()), command, response, cause); + super(String.format("command %1$s failed with error: %2$s", command.getRequest() + .getRequestLine(), error.toString()), command, response, cause); this.setError(error); } diff --git a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/functions/ObjectToBlobMetadata.java b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/functions/ObjectToBlobMetadata.java index 8e1491c44e..4fbc6650d5 100644 --- a/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/functions/ObjectToBlobMetadata.java +++ b/atmos/src/main/java/org/jclouds/atmosonline/saas/blobstore/functions/ObjectToBlobMetadata.java @@ -31,6 +31,7 @@ import javax.inject.Inject; import javax.inject.Singleton; import org.jclouds.atmosonline.saas.domain.AtmosObject; +import org.jclouds.atmosonline.saas.domain.FileType; import org.jclouds.atmosonline.saas.functions.AtmosObjectName; import org.jclouds.blobstore.domain.MutableBlobMetadata; import org.jclouds.blobstore.domain.ResourceType; @@ -69,7 +70,11 @@ public class ObjectToBlobMetadata implements Function lowerKeyMetadata = Maps.newHashMap(); for (Entry entry : from.getUserMetadata().getMetadata().entrySet()) { String key = entry.getKey().toLowerCase(); diff --git a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientTest.java b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientTest.java index 3c0c259622..7a03f2bf2a 100644 --- a/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientTest.java +++ b/atmos/src/test/java/org/jclouds/atmosonline/saas/AtmosStorageClientTest.java @@ -45,6 +45,7 @@ import org.jclouds.atmosonline.saas.reference.AtmosStorageConstants; import org.jclouds.blobstore.binders.BindBlobToMultipartFormTest; import org.jclouds.blobstore.config.BlobStoreObjectModule; import org.jclouds.blobstore.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.blobstore.functions.ThrowContainerNotFoundOn404; import org.jclouds.blobstore.functions.ThrowKeyNotFoundOn404; import org.jclouds.date.TimeStamp; import org.jclouds.encryption.internal.Base64; @@ -106,7 +107,7 @@ public class AtmosStorageClientTest extends RestClientTest + * + * ==================================================================== + * 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.atmosonline.saas.blobstore.functions; + +import static org.testng.Assert.assertEquals; + +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code ObjectToBlobMetadata} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "atmossaas.ObjectToBlobMetadataTest") +public class ObjectToBlobMetadataTest { + + public void testFromWhenTypeIsDirectory() { + Injector injector = Guice.createInjector(); + injector.getInstance(ObjectToBlobMetadata.class); + + assertEquals("", ""); + } +}