Updated DeprecateOptions to AutoValue + Builder

This commit is contained in:
Daniel Broudy 2015-01-30 17:13:52 -08:00 committed by Ignasi Barrera
parent a9eecfad81
commit adf6999899
3 changed files with 78 additions and 84 deletions

View File

@ -18,104 +18,96 @@ package org.jclouds.googlecomputeengine.options;
import java.net.URI; import java.net.URI;
import java.util.Date; import java.util.Date;
import org.jclouds.googlecomputeengine.domain.Deprecated.State; 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. * Options to set the deprecation status of a resource. Currently only for images.
* *
* @see <a href="https://developers.google.com/compute/docs/reference/latest/images/deprecate" /> * @see <a href="https://developers.google.com/compute/docs/reference/latest/images/deprecate" />
*/ */
public class DeprecateOptions { @AutoValue
public abstract class DeprecateOptions {
private State state; @Nullable public abstract State state();
private URI replacement; @Nullable public abstract URI replacement();
private Date deprecated; @Nullable public abstract Date deprecated();
private Date obsolete; @Nullable public abstract Date obsolete();
private Date deleted; @Nullable public abstract Date deleted();
/** @SerializedNames({"state", "replacement", "deprecated", "obsolete", "deleted"})
* The new deprecation state. static DeprecateOptions create(State state, URI replacement, Date deprecated,
* Date obsolete, Date deleted){
* @return the new deprecation state. return new AutoValue_DeprecateOptions(state, replacement, deprecated, obsolete, deleted);
*/
public State getState() {
return state;
} }
/** DeprecateOptions(){
* Optional URL for replacement of deprecated resource.
*
* @return the URL
*/
public URI getReplacement() {
return replacement;
} }
/** public static class Builder {
* Optional RFC3339 timestamp for when the deprecation state was changed to DEPRECATED. private State state;
* private URI replacement;
* @return the timestamp private Date deprecated;
*/ private Date obsolete;
public Date getDeprecated() { private Date deleted;
return deprecated;
}
/** /**
* Optional RFC3339 timestamp for when the deprecation state was changed to OBSOLETE. * The new deprecation state.
* *
* @return the timestamp * @return the new deprecation state.
*/ */
public Date getObsolete() { public Builder state(State state) {
return obsolete; this.state = state;
} return this;
}
/** /**
* Optional RFC3339 timestamp for when the deprecation state was changed to DELETED. * Optional URL for replacement of deprecated resource.
* *
* @return the timestamp * @return the URL
*/ */
public Date getDeleted() { public Builder replacement(URI replacement) {
return deleted; this.replacement = replacement;
} return this;
}
/** /**
* @see DeprecateOptions#getState() * Optional RFC3339 timestamp for when the deprecation state was changed to DEPRECATED.
*/ *
public DeprecateOptions state(State state) { * @return the timestamp
this.state = state; */
return this; public Builder deprecated(Date deprecated) {
} this.deprecated = deprecated;
return this;
}
/** /**
* @see DeprecateOptions#getReplacement() * Optional RFC3339 timestamp for when the deprecation state was changed to OBSOLETE.
*/ *
public DeprecateOptions replacement(URI replacement) { * @return the timestamp
this.replacement = replacement; */
return this; public Builder obsolete(Date obsolete) {
} this.obsolete = obsolete;
return this;
}
/** /**
* @see DeprecateOptions#getDeprecated() * Optional RFC3339 timestamp for when the deprecation state was changed to DELETED.
*/ *
public DeprecateOptions deprecated(Date deprecated) { * @return the timestamp
this.deprecated = deprecated; */
return this; public Builder deleted(Date deleted) {
} this.deleted = deleted;
return this;
}
/** public DeprecateOptions build(){
* @see DeprecateOptions#getObsolete() return create(state, replacement, deprecated,
*/ obsolete, deleted);
public DeprecateOptions obsolete(Date obsolete) { }
this.obsolete = obsolete;
return this;
} }
/**
* @see DeprecateOptions#getDeleted()
*/
public DeprecateOptions deleted(Date deleted) {
this.deleted = deleted;
return this;
}
} }

View File

@ -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"); 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) .replacement(replacement)
.deprecated(new SimpleDateFormatDateService().iso8601DateParse(deprecated)) .deprecated(new SimpleDateFormatDateService().iso8601DateParse(deprecated))
.obsolete(new SimpleDateFormatDateService().iso8601DateParse(obsolete)) .obsolete(new SimpleDateFormatDateService().iso8601DateParse(obsolete))
.deleted(new SimpleDateFormatDateService().iso8601DateParse(deleted)); .deleted(new SimpleDateFormatDateService().iso8601DateParse(deleted))
.build();
assertOperationDoneSuccessfully(api().deprecate(IMAGE_NAME, deprecateOptions)); assertOperationDoneSuccessfully(api().deprecate(IMAGE_NAME, deprecateOptions));

View File

@ -136,11 +136,12 @@ public class ImageApiMockTest extends BaseGoogleComputeEngineApiMockTest {
String imageName = "test-image"; String imageName = "test-image";
server.enqueue(jsonResponse("/operation.json")); 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"))) .replacement(URI.create(url("/projects/centos-cloud/global/images/centos-6-2-v20120326test")))
.deprecated(new SimpleDateFormatDateService().iso8601DateParse("2014-07-16T22:16:13.468Z")) .deprecated(new SimpleDateFormatDateService().iso8601DateParse("2014-07-16T22:16:13.468Z"))
.obsolete(new SimpleDateFormatDateService().iso8601DateParse("2014-10-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), assertEquals(imageApi().deprecate(imageName, options),
new ParseOperationTest().expected(url("/projects"))); new ParseOperationTest().expected(url("/projects")));