You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2017/05/08 18:10:14 UTC
[12/50] jclouds git commit: add rewrite to ObjectApi
add rewrite to ObjectApi
Project: http://git-wip-us.apache.org/repos/asf/jclouds/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds/commit/2abac7c1
Tree: http://git-wip-us.apache.org/repos/asf/jclouds/tree/2abac7c1
Diff: http://git-wip-us.apache.org/repos/asf/jclouds/diff/2abac7c1
Branch: refs/heads/master
Commit: 2abac7c11c0ae0995b089114b41aaaae6ee2aff3
Parents: 15a5dad
Author: Daniel Broudy <br...@google.com>
Authored: Tue Jun 23 11:10:13 2015 -0700
Committer: Andrew Gaul <ga...@apache.org>
Committed: Tue Jun 23 16:51:32 2015 -0700
----------------------------------------------------------------------
.../domain/RewriteResponse.java | 41 +++++
.../googlecloudstorage/features/ObjectApi.java | 51 ++++++
.../options/RewriteObjectOptions.java | 155 +++++++++++++++++++
.../features/ObjectApiLiveTest.java | 17 ++
.../features/ObjectApiMockTest.java | 21 +++
.../parse/ParseObjectRewriteResponse.java | 72 +++++++++
.../src/test/resources/object_rewrite.json | 28 ++++
7 files changed, 385 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2abac7c1/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/RewriteResponse.java
----------------------------------------------------------------------
diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/RewriteResponse.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/RewriteResponse.java
new file mode 100644
index 0000000..8f37193
--- /dev/null
+++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/domain/RewriteResponse.java
@@ -0,0 +1,41 @@
+/*
+ * 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.googlecloudstorage.domain;
+
+import org.jclouds.javax.annotation.Nullable;
+import org.jclouds.json.SerializedNames;
+
+import com.google.auto.value.AutoValue;
+
+@AutoValue
+public abstract class RewriteResponse {
+ // TODO(broudy): should these be UnsignedLong?
+ public abstract long totalBytesRewritten();
+ public abstract long objectSize();
+ public abstract boolean done();
+ @Nullable public abstract String rewriteToken();
+ public abstract GoogleCloudStorageObject resource();
+
+ @SerializedNames({"totalBytesRewritten", "objectSize", "done", "rewriteToken", "resource"})
+ public static RewriteResponse create(long totalBytesRewritten, long objectSize,
+ boolean done, String rewriteToken, GoogleCloudStorageObject resource) {
+ return new AutoValue_RewriteResponse(totalBytesRewritten, objectSize, done, rewriteToken, resource);
+ }
+
+ RewriteResponse() {
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2abac7c1/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java
----------------------------------------------------------------------
diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java
index f91a410..ff8dfde 100644
--- a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java
+++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/features/ObjectApi.java
@@ -35,6 +35,7 @@ import org.jclouds.googlecloudstorage.binders.MultipartUploadBinder;
import org.jclouds.googlecloudstorage.binders.UploadBinder;
import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject;
import org.jclouds.googlecloudstorage.domain.ListPageWithPrefixes;
+import org.jclouds.googlecloudstorage.domain.RewriteResponse;
import org.jclouds.googlecloudstorage.domain.templates.ComposeObjectTemplate;
import org.jclouds.googlecloudstorage.domain.templates.ObjectTemplate;
import org.jclouds.googlecloudstorage.options.ComposeObjectOptions;
@@ -43,6 +44,7 @@ import org.jclouds.googlecloudstorage.options.DeleteObjectOptions;
import org.jclouds.googlecloudstorage.options.GetObjectOptions;
import org.jclouds.googlecloudstorage.options.InsertObjectOptions;
import org.jclouds.googlecloudstorage.options.ListObjectOptions;
+import org.jclouds.googlecloudstorage.options.RewriteObjectOptions;
import org.jclouds.googlecloudstorage.options.UpdateObjectOptions;
import org.jclouds.googlecloudstorage.parser.ParseToPayloadEnclosing;
import org.jclouds.http.options.HttpRequestOptions;
@@ -473,4 +475,53 @@ public interface ObjectApi {
GoogleCloudStorageObject multipartUpload(@PathParam("bucket") String bucketName,
@PayloadParam("template") ObjectTemplate objectTemplate,
@PayloadParam("payload") Payload payload);
+
+ /**
+ * Rewrites a source object to a destination object.
+ *
+ * @param destinationBucket
+ * Name of the bucket in which the object to be stored
+ * @param destinationObject
+ * Name of the new object.
+ * @param sourceBucket
+ * Name of the bucket in which to find the source object.
+ * @param sourceObject
+ * Name of the source object.
+ *
+ * @return a {@link RewriteResponse}
+ */
+ @Named("Object:rewrite")
+ @POST
+ @Consumes(APPLICATION_JSON)
+ @Path("/storage/v1/b/{sourceBucket}/o/{sourceObject}/rewriteTo/b/{destinationBucket}/o/{destinationObject}")
+ RewriteResponse rewriteObjects(@PathParam("destinationBucket") String destinationBucket,
+ @PathParam("destinationObject") String destinationObject,
+ @PathParam("sourceBucket") String sourceBucket,
+ @PathParam("sourceObject") String sourceObject);
+
+ /**
+ * Rewrites a source object to a destination object.
+ *
+ * @param destinationBucket
+ * Name of the bucket in which the object to be stored
+ * @param destinationObject
+ * Name of the new object.
+ * @param sourceBucket
+ * Name of the bucket in which to find the source object.
+ * @param sourceObject
+ * Name of the source object.
+ * @param options
+ * Supply an {@link RewriteObjectOptions}
+ *
+ * @return a {@link RewriteResponse}
+ */
+ @Named("Object:rewrite")
+ @POST
+ @Consumes(APPLICATION_JSON)
+ @Path("/storage/v1/b/{sourceBucket}/o/{sourceObject}/rewriteTo/b/{destinationBucket}/o/{destinationObject}")
+ RewriteResponse rewriteObjects(@PathParam("destinationBucket") String destinationBucket,
+ @PathParam("destinationObject") String destinationObject,
+ @PathParam("sourceBucket") String sourceBucket,
+ @PathParam("sourceObject") String sourceObject,
+ RewriteObjectOptions options);
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2abac7c1/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/options/RewriteObjectOptions.java
----------------------------------------------------------------------
diff --git a/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/options/RewriteObjectOptions.java b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/options/RewriteObjectOptions.java
new file mode 100644
index 0000000..0e93546
--- /dev/null
+++ b/providers/google-cloud-storage/src/main/java/org/jclouds/googlecloudstorage/options/RewriteObjectOptions.java
@@ -0,0 +1,155 @@
+/*
+ * 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.googlecloudstorage.options;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.PredefinedAcl;
+import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.Projection;
+import org.jclouds.http.options.BaseHttpRequestOptions;
+
+/**
+ * Allows to optionally specify ifMetagenerationMatch,ifMetagenerationNotMatch and projection which used in Bucket
+ */
+public class RewriteObjectOptions extends BaseHttpRequestOptions {
+
+ // TODO(broudy): Refactor these redundant options out of every options class.
+
+ public RewriteObjectOptions ifGenerationMatch(Long ifGenerationMatch) {
+ this.queryParameters.put("ifGenerationMatch", checkNotNull(ifGenerationMatch, "ifGenerationMatch") + "");
+ return this;
+ }
+
+ public RewriteObjectOptions ifGenerationNotMatch(Long ifGenerationNotMatch) {
+ this.queryParameters.put("ifGenerationNotMatch", checkNotNull(ifGenerationNotMatch, "ifGenerationNotMatch") + "");
+ return this;
+ }
+
+ public RewriteObjectOptions ifMetagenerationMatch(Long ifMetagenerationMatch) {
+ this.queryParameters.put("ifMetagenerationMatch", checkNotNull(ifMetagenerationMatch, "ifMetagenerationMatch")
+ + "");
+ return this;
+ }
+
+ public RewriteObjectOptions ifMetagenerationNotMatch(Long ifMetagenerationNotMatch) {
+ this.queryParameters.put("ifMetagenerationNotMatch",
+ checkNotNull(ifMetagenerationNotMatch, "ifMetagenerationNotMatch") + "");
+ return this;
+ }
+ public RewriteObjectOptions ifSourceGenerationMatch(Long ifSourceGenerationMatch) {
+ this.queryParameters.put("ifSourceGenerationMatch", checkNotNull(ifSourceGenerationMatch, "ifSourceGenerationMatch") + "");
+ return this;
+ }
+
+ public RewriteObjectOptions ifSourceGenerationNotMatch(Long ifSourceGenerationNotMatch) {
+ this.queryParameters.put("ifSourceGenerationNotMatch", checkNotNull(ifSourceGenerationNotMatch, "ifSourceGenerationNotMatch") + "");
+ return this;
+ }
+
+ public RewriteObjectOptions ifSourceMetagenerationMatch(Long ifSourceMetagenerationMatch) {
+ this.queryParameters.put("ifSourceMetagenerationMatch", checkNotNull(ifSourceMetagenerationMatch, "ifSourceMetagenerationMatch")
+ + "");
+ return this;
+ }
+
+ public RewriteObjectOptions ifSourceMetagenerationNotMatch(Long ifSourceMetagenerationNotMatch) {
+ this.queryParameters.put("ifSourceMetagenerationNotMatch",
+ checkNotNull(ifSourceMetagenerationNotMatch, "ifSourceMetagenerationNotMatch") + "");
+ return this;
+ }
+
+ public RewriteObjectOptions sourceGeneration(Long sourceGeneration) {
+ this.queryParameters.put("sourceGeneration", checkNotNull(sourceGeneration, "sourceGeneration") + "");
+ return this;
+ }
+
+ public RewriteObjectOptions predefinedAcl(PredefinedAcl predefinedAcl) {
+ this.queryParameters.put("predefinedAcl", checkNotNull(predefinedAcl, "predefinedAcl").toString());
+ return this;
+ }
+
+ public RewriteObjectOptions projection(Projection projection) {
+ this.queryParameters.put("projection", checkNotNull(projection, "projection").toString());
+ return this;
+ }
+
+ public RewriteObjectOptions rewriteToken(String rewriteToken) {
+ this.queryParameters.put("rewriteToken", checkNotNull(rewriteToken, "rewriteToken").toString());
+ return this;
+ }
+
+ public RewriteObjectOptions maxBytesRewrittenPerCall(Long maxBytesRewrittenPerCall) {
+ this.queryParameters.put("maxBytesRewrittenPerCall",
+ checkNotNull(maxBytesRewrittenPerCall, "maxBytesRewrittenPerCall").toString());
+ return this;
+ }
+
+ public static class Builder {
+
+ public RewriteObjectOptions ifGenerationMatch(Long ifGenerationMatch) {
+ return new RewriteObjectOptions().ifGenerationMatch(ifGenerationMatch);
+ }
+
+ public RewriteObjectOptions ifGenerationNotMatch(Long ifGenerationNotMatch) {
+ return new RewriteObjectOptions().ifGenerationNotMatch(ifGenerationNotMatch);
+ }
+
+ public RewriteObjectOptions ifMetagenerationMatch(Long ifMetagenerationMatch) {
+ return new RewriteObjectOptions().ifMetagenerationMatch(ifMetagenerationMatch);
+ }
+
+ public RewriteObjectOptions ifMetagenerationNotMatch(Long ifMetagenerationNotMatch) {
+ return new RewriteObjectOptions().ifMetagenerationNotMatch(ifMetagenerationNotMatch);
+ }
+
+ public RewriteObjectOptions ifSourceGenerationMatch(Long ifSourceGenerationMatch) {
+ return new RewriteObjectOptions().ifSourceGenerationMatch(ifSourceGenerationMatch);
+ }
+
+ public RewriteObjectOptions ifSourceGenerationNotMatch(Long ifSourceGenerationNotMatch) {
+ return new RewriteObjectOptions().ifSourceGenerationNotMatch(ifSourceGenerationNotMatch);
+ }
+
+ public RewriteObjectOptions ifSourceMetagenerationMatch(Long ifSourceMetagenerationMatch) {
+ return new RewriteObjectOptions().ifSourceMetagenerationMatch(ifSourceMetagenerationMatch);
+ }
+
+ public RewriteObjectOptions ifSourceMetagenerationNotMatch(Long ifSourceMetagenerationNotMatch) {
+ return new RewriteObjectOptions().ifSourceMetagenerationNotMatch(ifSourceMetagenerationNotMatch);
+ }
+
+ public RewriteObjectOptions sourceGeneration(Long sourceGeneration) {
+ return new RewriteObjectOptions().sourceGeneration(sourceGeneration);
+ }
+
+ public RewriteObjectOptions predefinedAcl(PredefinedAcl predefinedAcl) {
+ return new RewriteObjectOptions().predefinedAcl(predefinedAcl);
+ }
+
+ public RewriteObjectOptions projection(Projection projection) {
+ return new RewriteObjectOptions().projection(projection);
+ }
+
+ public RewriteObjectOptions rewriteToken(String rewriteToken) {
+ return new RewriteObjectOptions().rewriteToken(rewriteToken);
+ }
+
+ public RewriteObjectOptions maxBytesRewrittenPerCall(Long maxBytesRewrittenPerCall) {
+ return new RewriteObjectOptions().maxBytesRewrittenPerCall(maxBytesRewrittenPerCall);
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2abac7c1/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java
index 44232a1..4bf48cb 100644
--- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java
+++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiLiveTest.java
@@ -37,6 +37,7 @@ import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.Projection
import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject;
import org.jclouds.googlecloudstorage.domain.ListPageWithPrefixes;
import org.jclouds.googlecloudstorage.domain.ObjectAccessControls;
+import org.jclouds.googlecloudstorage.domain.RewriteResponse;
import org.jclouds.googlecloudstorage.domain.templates.BucketTemplate;
import org.jclouds.googlecloudstorage.domain.templates.ComposeObjectTemplate;
import org.jclouds.googlecloudstorage.domain.templates.ObjectTemplate;
@@ -76,6 +77,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
private static final String COMPOSED_OBJECT = "ComposedObject1.txt";
private static final String COMPOSED_OBJECT2 = "ComposedObject2.json";
private static final String NONEXISTENT_OBJECT_NAME = "noSuchObject.txt";
+ private static final String REWRITE_OBJECT_NAME = "rewriteObject.txt";
private PayloadEnclosing testPayload;
private Long RANDOM_LONG = 100L;
@@ -124,6 +126,20 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
}
@Test(groups = "live", dependsOnMethods = "testSimpleUpload")
+ public void testRewrite() throws IOException {
+ GoogleCloudStorageObject gcsObject = api().getObject(BUCKET_NAME, UPLOAD_OBJECT_NAME);
+ System.out.println(gcsObject);
+
+ RewriteResponse response = api().rewriteObjects(BUCKET_NAME, REWRITE_OBJECT_NAME, BUCKET_NAME, UPLOAD_OBJECT_NAME);
+ assertNotNull(response);
+ assertTrue(response.done());
+ assertEquals(response.objectSize(), 512);
+ assertEquals(response.totalBytesRewritten(), 512);
+ assertEquals(response.rewriteToken(), null);
+ assertNotNull(response.resource());
+ }
+
+ @Test(groups = "live", dependsOnMethods = "testRewrite")
public void testDownload() throws IOException {
PayloadEnclosing impl = api().download(BUCKET_NAME, UPLOAD_OBJECT_NAME);
ContentMetadata meta = impl.getPayload().getContentMetadata();
@@ -443,6 +459,7 @@ public class ObjectApiLiveTest extends BaseGoogleCloudStorageApiLiveTest {
assertFalse(api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME));
assertTrue(api().deleteObject(BUCKET_NAME, UPLOAD_OBJECT_NAME2));
assertTrue(api().deleteObject(BUCKET_NAME, MULTIPART_UPLOAD_OBJECT));
+ assertTrue(api().deleteObject(BUCKET_NAME, REWRITE_OBJECT_NAME));
assertFalse(api().deleteObject(BUCKET_NAME, NONEXISTENT_OBJECT_NAME));
}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2abac7c1/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java
----------------------------------------------------------------------
diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java
index d30deac..9906a90 100644
--- a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java
+++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/features/ObjectApiMockTest.java
@@ -34,8 +34,10 @@ import org.jclouds.googlecloudstorage.options.CopyObjectOptions;
import org.jclouds.googlecloudstorage.options.GetObjectOptions;
import org.jclouds.googlecloudstorage.options.InsertObjectOptions;
import org.jclouds.googlecloudstorage.options.ListObjectOptions;
+import org.jclouds.googlecloudstorage.options.RewriteObjectOptions;
import org.jclouds.googlecloudstorage.parse.ParseGoogleCloudStorageObject;
import org.jclouds.googlecloudstorage.parse.ParseGoogleCloudStorageObjectListTest;
+import org.jclouds.googlecloudstorage.parse.ParseObjectRewriteResponse;
import org.jclouds.http.internal.PayloadEnclosingImpl;
import org.jclouds.io.PayloadEnclosing;
import org.testng.annotations.Test;
@@ -259,6 +261,25 @@ public class ObjectApiMockTest extends BaseGoogleCloudStorageApiMockTest {
//TODO: this should be a more robust assertion about the formatting of the payload
}
+ public void rewrite() throws Exception {
+ server.enqueue(jsonResponse("/object_rewrite.json"));
+
+ assertEquals(objectApi().rewriteObjects("destinationBucket", "destinationObject", "sourceBucket", "sourceObject"),
+ new ParseObjectRewriteResponse().expected());
+
+ assertSent(server, "POST", "/storage/v1/b/sourceBucket/o/sourceObject/rewriteTo/b/destinationBucket/o/destinationObject");
+ }
+
+ public void rewriteWithOptions() throws Exception {
+ server.enqueue(jsonResponse("/object_rewrite.json"));
+
+ RewriteObjectOptions options = new RewriteObjectOptions.Builder().rewriteToken("rewriteToken");
+ assertEquals(objectApi().rewriteObjects("destinationBucket", "destinationObject", "sourceBucket", "sourceObject", options),
+ new ParseObjectRewriteResponse().expected());
+
+ assertSent(server, "POST",
+ "/storage/v1/b/sourceBucket/o/sourceObject/rewriteTo/b/destinationBucket/o/destinationObject?rewriteToken=rewriteToken");
+ }
public ObjectApi objectApi(){
return api().getObjectApi();
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2abac7c1/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ParseObjectRewriteResponse.java
----------------------------------------------------------------------
diff --git a/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ParseObjectRewriteResponse.java b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ParseObjectRewriteResponse.java
new file mode 100644
index 0000000..2b4a2e3
--- /dev/null
+++ b/providers/google-cloud-storage/src/test/java/org/jclouds/googlecloudstorage/parse/ParseObjectRewriteResponse.java
@@ -0,0 +1,72 @@
+/*
+ * 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.googlecloudstorage.parse;
+
+import java.net.URI;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.core.MediaType;
+
+import org.jclouds.googlecloudstorage.domain.DomainResourceReferences.StorageClass;
+import org.jclouds.googlecloudstorage.domain.Owner;
+import org.jclouds.googlecloudstorage.domain.GoogleCloudStorageObject;
+import org.jclouds.googlecloudstorage.domain.RewriteResponse;
+import org.jclouds.googlecloudstorage.internal.BaseGoogleCloudStorageParseTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ParseObjectRewriteResponse")
+public class ParseObjectRewriteResponse extends BaseGoogleCloudStorageParseTest<RewriteResponse> {
+
+ @Override
+ public String resource() {
+ return "/object_rewrite.json";
+ }
+
+ @Override
+ @Consumes(MediaType.APPLICATION_JSON)
+ public RewriteResponse expected() {
+ return RewriteResponse.create(16, // totalBytesRewritten
+ 16, // objectSize
+ true, // done
+ "rewriteToken", // rewriteToken
+ GoogleCloudStorageObject.create(
+ "test/file_name/1000", //id
+ URI.create("https://www.googleapis.com/storage/v1/b/test/o/file_name"), //selfLink
+ "etag", // etag
+ "file_name", // name
+ "test", // bucket
+ (long) 1000, //generation
+ (long) 8, // metageneration
+ "application/x-tar", // contentType
+ parse("2014-09-27T00:01:44.819"), // updated
+ null, // timeDeleted
+ StorageClass.STANDARD, // storageClass
+ (long) 1000, //size,
+ "md5Hash", // md5Hash
+ URI.create("https://www.googleapis.com/download/storage/v1/b/test/o/file_name?generation=1000&alt=media"), // mediaLink
+ null, // metadata
+ null, // contentEncoding
+ null, // contentDisposition,
+ null, // contentLanguage
+ null, // cacheControl
+ null, // acl
+ Owner.create("entity", "entityId"), // owner,
+ "crc32c", // crc32c,
+ null) //componentCount
+ );
+ }
+}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/2abac7c1/providers/google-cloud-storage/src/test/resources/object_rewrite.json
----------------------------------------------------------------------
diff --git a/providers/google-cloud-storage/src/test/resources/object_rewrite.json b/providers/google-cloud-storage/src/test/resources/object_rewrite.json
new file mode 100644
index 0000000..189b9b8
--- /dev/null
+++ b/providers/google-cloud-storage/src/test/resources/object_rewrite.json
@@ -0,0 +1,28 @@
+{
+ "kind": "storage#rewriteResponse",
+ "totalBytesRewritten": "16",
+ "objectSize": "16",
+ "rewriteToken": "rewriteToken",
+ "done": true,
+ "resource": {
+ "kind": "storage#object",
+ "id": "test/file_name/1000",
+ "selfLink": "https://www.googleapis.com/storage/v1/b/test/o/file_name",
+ "name": "file_name",
+ "bucket": "test",
+ "generation": "1000",
+ "metageneration": "8",
+ "contentType": "application/x-tar",
+ "updated": "2014-09-27T00:01:44.819",
+ "storageClass": "STANDARD",
+ "size": "1000",
+ "md5Hash": "md5Hash",
+ "mediaLink": "https://www.googleapis.com/download/storage/v1/b/test/o/file_name?generation=1000&alt=media",
+ "owner": {
+ "entity": "entity",
+ "entityId": "entityId"
+ },
+ "crc32c": "crc32c",
+ "etag": "etag"
+ }
+}
\ No newline at end of file