diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java index ce19ded82d..9f4a5ef2bd 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/DeprecateOptions.java @@ -18,104 +18,96 @@ package org.jclouds.googlecomputeengine.options; import java.net.URI; import java.util.Date; + import org.jclouds.googlecomputeengine.domain.Deprecated.State; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import com.google.auto.value.AutoValue; /** * Options to set the deprecation status of a resource. Currently only for images. * * @see */ -public class DeprecateOptions { +@AutoValue +public abstract class DeprecateOptions { - private State state; - private URI replacement; - private Date deprecated; - private Date obsolete; - private Date deleted; + @Nullable public abstract State state(); + @Nullable public abstract URI replacement(); + @Nullable public abstract Date deprecated(); + @Nullable public abstract Date obsolete(); + @Nullable public abstract Date deleted(); - /** - * The new deprecation state. - * - * @return the new deprecation state. - */ - public State getState() { - return state; + @SerializedNames({"state", "replacement", "deprecated", "obsolete", "deleted"}) + static DeprecateOptions create(State state, URI replacement, Date deprecated, + Date obsolete, Date deleted){ + return new AutoValue_DeprecateOptions(state, replacement, deprecated, obsolete, deleted); } - /** - * Optional URL for replacement of deprecated resource. - * - * @return the URL - */ - public URI getReplacement() { - return replacement; + DeprecateOptions(){ } - /** - * Optional RFC3339 timestamp for when the deprecation state was changed to DEPRECATED. - * - * @return the timestamp - */ - public Date getDeprecated() { - return deprecated; - } + public static class Builder { + private State state; + private URI replacement; + private Date deprecated; + private Date obsolete; + private Date deleted; - /** - * Optional RFC3339 timestamp for when the deprecation state was changed to OBSOLETE. - * - * @return the timestamp - */ - public Date getObsolete() { - return obsolete; - } + /** + * The new deprecation state. + * + * @return the new deprecation state. + */ + public Builder state(State state) { + this.state = state; + return this; + } - /** - * Optional RFC3339 timestamp for when the deprecation state was changed to DELETED. - * - * @return the timestamp - */ - public Date getDeleted() { - return deleted; - } + /** + * Optional URL for replacement of deprecated resource. + * + * @return the URL + */ + public Builder replacement(URI replacement) { + this.replacement = replacement; + return this; + } - /** - * @see DeprecateOptions#getState() - */ - public DeprecateOptions state(State state) { - this.state = state; - return this; - } + /** + * Optional RFC3339 timestamp for when the deprecation state was changed to DEPRECATED. + * + * @return the timestamp + */ + public Builder deprecated(Date deprecated) { + this.deprecated = deprecated; + return this; + } - /** - * @see DeprecateOptions#getReplacement() - */ - public DeprecateOptions replacement(URI replacement) { - this.replacement = replacement; - return this; - } + /** + * Optional RFC3339 timestamp for when the deprecation state was changed to OBSOLETE. + * + * @return the timestamp + */ + public Builder obsolete(Date obsolete) { + this.obsolete = obsolete; + return this; + } - /** - * @see DeprecateOptions#getDeprecated() - */ - public DeprecateOptions deprecated(Date deprecated) { - this.deprecated = deprecated; - return this; - } + /** + * Optional RFC3339 timestamp for when the deprecation state was changed to DELETED. + * + * @return the timestamp + */ + public Builder deleted(Date deleted) { + this.deleted = deleted; + return this; + } - /** - * @see DeprecateOptions#getObsolete() - */ - public DeprecateOptions obsolete(Date obsolete) { - this.obsolete = obsolete; - return this; + public DeprecateOptions build(){ + return create(state, replacement, deprecated, + obsolete, deleted); + } } - - /** - * @see DeprecateOptions#getDeleted() - */ - public DeprecateOptions deleted(Date deleted) { - this.deleted = deleted; - return this; - } - } diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java index 486e701250..3b6494d555 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiLiveTest.java @@ -96,11 +96,12 @@ public class ImageApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { URI replacement = URI.create("https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-2-v20120326test"); - DeprecateOptions deprecateOptions = new DeprecateOptions().state(State.DEPRECATED) + DeprecateOptions deprecateOptions = new DeprecateOptions.Builder().state(State.DEPRECATED) .replacement(replacement) .deprecated(new SimpleDateFormatDateService().iso8601DateParse(deprecated)) .obsolete(new SimpleDateFormatDateService().iso8601DateParse(obsolete)) - .deleted(new SimpleDateFormatDateService().iso8601DateParse(deleted)); + .deleted(new SimpleDateFormatDateService().iso8601DateParse(deleted)) + .build(); assertOperationDoneSuccessfully(api().deprecate(IMAGE_NAME, deprecateOptions)); diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java index 7d9e9c0de1..7af2b8e668 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ImageApiMockTest.java @@ -136,11 +136,12 @@ public class ImageApiMockTest extends BaseGoogleComputeEngineApiMockTest { String imageName = "test-image"; server.enqueue(jsonResponse("/operation.json")); - DeprecateOptions options = new DeprecateOptions().state(State.DEPRECATED) + DeprecateOptions options = new DeprecateOptions.Builder().state(State.DEPRECATED) .replacement(URI.create(url("/projects/centos-cloud/global/images/centos-6-2-v20120326test"))) .deprecated(new SimpleDateFormatDateService().iso8601DateParse("2014-07-16T22:16:13.468Z")) .obsolete(new SimpleDateFormatDateService().iso8601DateParse("2014-10-16T22:16:13.468Z")) - .deleted(new SimpleDateFormatDateService().iso8601DateParse("2015-01-16T22:16:13.468Z")); + .deleted(new SimpleDateFormatDateService().iso8601DateParse("2015-01-16T22:16:13.468Z")) + .build(); assertEquals(imageApi().deprecate(imageName, options), new ParseOperationTest().expected(url("/projects")));