mirror of https://github.com/apache/jclouds.git
Adds live test.
This commit is contained in:
parent
a1cbec1092
commit
576005a335
|
@ -85,8 +85,8 @@ public class BindMetadataToHeaders implements Binder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class BindHeaderMetadataToHeaders extends BindMetadataToHeaders {
|
public static class BindRawMetadataToHeaders extends BindMetadataToHeaders {
|
||||||
BindHeaderMetadataToHeaders() {
|
BindRawMetadataToHeaders() {
|
||||||
super("");
|
super("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,8 +41,8 @@ import org.jclouds.http.options.GetOptions;
|
||||||
import org.jclouds.io.Payload;
|
import org.jclouds.io.Payload;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
import org.jclouds.openstack.keystone.v2_0.filters.AuthenticateRequest;
|
||||||
import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindHeaderMetadataToHeaders;
|
|
||||||
import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindObjectMetadataToHeaders;
|
import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindObjectMetadataToHeaders;
|
||||||
|
import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindRawMetadataToHeaders;
|
||||||
import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindRemoveObjectMetadataToHeaders;
|
import org.jclouds.openstack.swift.v1.binders.BindMetadataToHeaders.BindRemoveObjectMetadataToHeaders;
|
||||||
import org.jclouds.openstack.swift.v1.binders.SetPayload;
|
import org.jclouds.openstack.swift.v1.binders.SetPayload;
|
||||||
import org.jclouds.openstack.swift.v1.domain.ObjectList;
|
import org.jclouds.openstack.swift.v1.domain.ObjectList;
|
||||||
|
@ -207,6 +207,26 @@ public interface ObjectApi {
|
||||||
boolean updateMetadata(@PathParam("objectName") String objectName,
|
boolean updateMetadata(@PathParam("objectName") String objectName,
|
||||||
@BinderParam(BindObjectMetadataToHeaders.class) Map<String, String> metadata);
|
@BinderParam(BindObjectMetadataToHeaders.class) Map<String, String> metadata);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates or updates the metadata for a {@link SwiftObject} without escaping the key.
|
||||||
|
* This will also update metadata such as content-disposition.
|
||||||
|
*
|
||||||
|
* @param objectName
|
||||||
|
* corresponds to {@link SwiftObject#getName()}.
|
||||||
|
* @param metadata
|
||||||
|
* the metadata to create or update.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the metadata was successfully created or updated,
|
||||||
|
* {@code false} if not.
|
||||||
|
*/
|
||||||
|
@Named("object:updateMetadata")
|
||||||
|
@POST
|
||||||
|
@Path("/{objectName}")
|
||||||
|
@Produces("")
|
||||||
|
@Fallback(FalseOnNotFoundOr404.class)
|
||||||
|
boolean updateRawMetadata(@PathParam("objectName") String objectName,
|
||||||
|
@BinderParam(BindRawMetadataToHeaders.class) Map<String, String> metadata);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the metadata from a {@link SwiftObject}.
|
* Deletes the metadata from a {@link SwiftObject}.
|
||||||
*
|
*
|
||||||
|
@ -293,6 +313,6 @@ public interface ObjectApi {
|
||||||
@PathParam("sourceContainer") String sourceContainer,
|
@PathParam("sourceContainer") String sourceContainer,
|
||||||
@PathParam("sourceObject") String sourceObject,
|
@PathParam("sourceObject") String sourceObject,
|
||||||
@BinderParam(BindObjectMetadataToHeaders.class) Map<String, String> userMetadata,
|
@BinderParam(BindObjectMetadataToHeaders.class) Map<String, String> userMetadata,
|
||||||
@BinderParam(BindHeaderMetadataToHeaders.class) Map<String, String> objectMetadata);
|
@BinderParam(BindRawMetadataToHeaders.class) Map<String, String> objectMetadata);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,6 +45,7 @@ import org.testng.annotations.BeforeClass;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Multimap;
|
||||||
import com.google.common.io.ByteSource;
|
import com.google.common.io.ByteSource;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,6 +97,7 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
|
||||||
api.getObjectApi(regionId, containerName).delete(objectName);
|
api.getObjectApi(regionId, containerName).delete(objectName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCopyObject() throws Exception {
|
public void testCopyObject() throws Exception {
|
||||||
for (String regionId : regions) {
|
for (String regionId : regions) {
|
||||||
// source
|
// source
|
||||||
|
@ -153,6 +155,85 @@ public class ObjectApiLiveTest extends BaseSwiftApiLiveTest<SwiftApi> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testCopyObjectWithMetadata() throws Exception {
|
||||||
|
for (String regionId : regions) {
|
||||||
|
// source
|
||||||
|
String sourceContainer = "src" + containerName;
|
||||||
|
String sourceObjectName = "original.txt";
|
||||||
|
String badSource = "badSource";
|
||||||
|
|
||||||
|
// destination
|
||||||
|
String destinationContainer = "dest" + containerName;
|
||||||
|
String destinationObject = "copy.txt";
|
||||||
|
String destinationPath = "/" + destinationContainer + "/" + destinationObject;
|
||||||
|
|
||||||
|
ContainerApi containerApi = api.getContainerApi(regionId);
|
||||||
|
|
||||||
|
// create source and destination dirs
|
||||||
|
containerApi.create(sourceContainer);
|
||||||
|
containerApi.create(destinationContainer);
|
||||||
|
|
||||||
|
// get the api for this region and container
|
||||||
|
ObjectApi srcApi = api.getObjectApi(regionId, sourceContainer);
|
||||||
|
ObjectApi destApi = api.getObjectApi(regionId, destinationContainer);
|
||||||
|
|
||||||
|
// Create source object
|
||||||
|
assertNotNull(srcApi.put(sourceObjectName, PAYLOAD));
|
||||||
|
SwiftObject sourceObject = srcApi.get(sourceObjectName);
|
||||||
|
checkObject(sourceObject);
|
||||||
|
|
||||||
|
srcApi.updateMetadata(sourceObjectName,
|
||||||
|
ImmutableMap.of("userProvidedMetadataKey", "userProvidedMetadataValue"));
|
||||||
|
|
||||||
|
// Create the destination object
|
||||||
|
assertNotNull(destApi.put(destinationObject, PAYLOAD));
|
||||||
|
SwiftObject object = destApi.get(destinationObject);
|
||||||
|
checkObject(object);
|
||||||
|
|
||||||
|
// check the copy operation
|
||||||
|
assertTrue(destApi.copy(destinationObject, sourceContainer, sourceObjectName,
|
||||||
|
ImmutableMap.<String, String>of("additionalUserMetakey", "additionalUserMetavalue"),
|
||||||
|
ImmutableMap.of("Content-Disposition", "attachment; filename=\"updatedname.txt\"")));
|
||||||
|
assertNotNull(destApi.get(destinationObject));
|
||||||
|
|
||||||
|
// now get a real SwiftObject
|
||||||
|
SwiftObject destSwiftObject = destApi.get(destinationObject);
|
||||||
|
assertEquals(toStringAndClose(destSwiftObject.getPayload().openStream()), "swifty");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make sure all src metadata is in dest
|
||||||
|
* Make sure the new content disposition is in dest
|
||||||
|
*/
|
||||||
|
Multimap<String, String> srcHeaders = null;
|
||||||
|
Multimap<String, String> destHeaders = null;
|
||||||
|
srcHeaders = srcApi.get(sourceObjectName).getHeaders();
|
||||||
|
destHeaders = destApi.get(destinationObject).getHeaders();
|
||||||
|
for (Entry<String, String> header : srcHeaders.entries()) {
|
||||||
|
if (header.getKey().equals("Date"))continue;
|
||||||
|
if (header.getKey().equals("Last-Modified"))continue;
|
||||||
|
if (header.getKey().equals("X-Trans-Id"))continue;
|
||||||
|
if (header.getKey().equals("X-Timestamp"))continue;
|
||||||
|
assertTrue(destHeaders.containsEntry(header.getKey(), header.getValue()), "Could not find: " + header);
|
||||||
|
}
|
||||||
|
assertEquals(destApi.get(destinationObject).getPayload().getContentMetadata().getContentDisposition(), "attachment; filename=\"updatedname.txt\"");
|
||||||
|
|
||||||
|
// test exception thrown on bad source name
|
||||||
|
try {
|
||||||
|
destApi.copy(destinationObject, badSource, sourceObjectName);
|
||||||
|
fail("Expected CopyObjectException");
|
||||||
|
} catch (CopyObjectException e) {
|
||||||
|
assertEquals(e.getSourcePath(), "/" + badSource + "/" + sourceObjectName);
|
||||||
|
assertEquals(e.getDestinationPath(), destinationPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAllObjectsInContainer(regionId, sourceContainer);
|
||||||
|
containerApi.deleteIfEmpty(sourceContainer);
|
||||||
|
|
||||||
|
deleteAllObjectsInContainer(regionId, destinationContainer);
|
||||||
|
containerApi.deleteIfEmpty(destinationContainer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void testList() throws Exception {
|
public void testList() throws Exception {
|
||||||
for (String regionId : regions) {
|
for (String regionId : regions) {
|
||||||
ObjectApi objectApi = api.getObjectApi(regionId, containerName);
|
ObjectApi objectApi = api.getObjectApi(regionId, containerName);
|
||||||
|
|
Loading…
Reference in New Issue