From 0f67b6250579e7de749671bdfaacc2d8fba1e085 Mon Sep 17 00:00:00 2001 From: Daniel Broudy Date: Fri, 19 Dec 2014 13:29:09 -0800 Subject: [PATCH] Updated TargetHttpProxyOptions, TargetPoolCreationOptions, UrlMapOptions to AutoValue + Builder --- .../binders/TargetPoolCreationBinder.java | 75 ------ .../features/TargetHttpProxyApi.java | 1 + .../features/TargetPoolApi.java | 5 +- .../features/UrlMapApi.java | 1 + .../HttpHealthCheckCreationOptions.java | 2 +- .../options/TargetHttpProxyOptions.java | 76 +++--- .../options/TargetPoolCreationOptions.java | 195 +++++++-------- .../options/UrlMapOptions.java | 228 ++++++++---------- .../binders/TargetPoolCreationBinderTest.java | 72 ------ .../features/ForwardingRuleApiLiveTest.java | 7 +- .../GlobalForwardingRuleApiLiveTest.java | 4 +- .../features/HttpHealthCheckApiLiveTest.java | 2 +- .../features/HttpHealthCheckApiMockTest.java | 2 +- .../features/TargetHttpProxyApiLiveTest.java | 19 +- .../features/TargetHttpProxyApiMockTest.java | 15 ++ .../features/TargetPoolApiLiveTest.java | 19 +- .../features/TargetPoolApiMockTest.java | 4 +- .../features/UrlMapApiLiveTest.java | 38 +-- .../features/UrlMapApiMockTest.java | 13 +- .../resources/target_http_proxy_insert.json | 5 +- 20 files changed, 308 insertions(+), 475 deletions(-) delete mode 100644 providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java delete mode 100644 providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java deleted file mode 100644 index 1d5285990c..0000000000 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * 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.googlecomputeengine.binders; - -import java.net.URI; -import java.util.List; -import java.util.Map; - -import javax.inject.Inject; - -import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions; -import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue; -import org.jclouds.http.HttpRequest; -import org.jclouds.json.Json; -import org.jclouds.rest.binders.BindToJsonPayload; - - -public class TargetPoolCreationBinder extends BindToJsonPayload { - - @Inject TargetPoolCreationBinder(Json jsonBinder) { - super(jsonBinder); - } - - @Override public R bindToRequest(R request, Map postParams) { - TargetPoolCreationOptions options = (TargetPoolCreationOptions) postParams.get("options"); - String name = postParams.get("name").toString(); - TargetPoolBinderHelper targetPoolBinderHelper = new TargetPoolBinderHelper(name, options); - return super.bindToRequest(request, targetPoolBinderHelper); - } - - private class TargetPoolBinderHelper{ - - /** - * Values used to bind TargetPoolCreationOptions to json request. - */ - @SuppressWarnings("unused") - private String name; - @SuppressWarnings("unused") - private List healthChecks; - @SuppressWarnings("unused") - private List instances; - @SuppressWarnings("unused") - private SessionAffinityValue sessionAffinity; - @SuppressWarnings("unused") - private Float failoverRatio; - @SuppressWarnings("unused") - private URI backupPool; - @SuppressWarnings("unused") - private String description; - - private TargetPoolBinderHelper(String name, TargetPoolCreationOptions targetPoolCreationOptions){ - this.name = name; - this.healthChecks = targetPoolCreationOptions.getHealthChecks(); - this.instances = targetPoolCreationOptions.getInstances(); - this.sessionAffinity = targetPoolCreationOptions.getSessionAffinity(); - this.failoverRatio = targetPoolCreationOptions.getFailoverRatio(); - this.backupPool = targetPoolCreationOptions.getBackupPool(); - this.description = targetPoolCreationOptions.getDescription(); - } - } -} diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java index abb0bf4c31..97c45d4704 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java @@ -83,6 +83,7 @@ public interface TargetHttpProxyApi { @Path("/global/targetHttpProxies") Operation create(@BinderParam(BindToJsonPayload.class) TargetHttpProxyOptions targetHttpProxyOptions); + //TODO (broudy) : Should we remove this because it is redundant? /** * Creates a targetHttpProxy resource in the specified project using the given URI for the urlMap. * diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java index e623c121c7..6d57086295 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java @@ -38,7 +38,6 @@ import org.jclouds.googlecloud.domain.ListPage; import org.jclouds.googlecomputeengine.GoogleComputeEngineApi; import org.jclouds.googlecomputeengine.binders.TargetPoolChangeHealthChecksBinder; import org.jclouds.googlecomputeengine.binders.TargetPoolChangeInstancesBinder; -import org.jclouds.googlecomputeengine.binders.TargetPoolCreationBinder; import org.jclouds.googlecomputeengine.domain.HealthStatus; import org.jclouds.googlecomputeengine.domain.Operation; import org.jclouds.googlecomputeengine.domain.TargetPool; @@ -47,6 +46,7 @@ import org.jclouds.googlecomputeengine.options.ListOptions; import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions; import org.jclouds.javax.annotation.Nullable; import org.jclouds.oauth.v2.filters.OAuthFilter; +import org.jclouds.rest.annotations.BinderParam; import org.jclouds.rest.annotations.Fallback; import org.jclouds.rest.annotations.MapBinder; import org.jclouds.rest.annotations.PayloadParam; @@ -82,8 +82,7 @@ public interface TargetPoolApi { @Named("TargetPools:insert") @POST @Produces(APPLICATION_JSON) - @MapBinder(TargetPoolCreationBinder.class) - Operation create(@PayloadParam("name") String name, @PayloadParam("options") TargetPoolCreationOptions options); + Operation create(@BinderParam(BindToJsonPayload.class) TargetPoolCreationOptions options); /** Deletes a target pool by name and returns the operation in progress, or null if not found. */ @Named("TargetPools:delete") diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java index 25783d2a4f..d77c542447 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java @@ -113,6 +113,7 @@ public interface UrlMapApi { /** * Updates the specified urlMap resource, with patch semantics, with the data included in the request. + * Note:{@link UrlMapOptions.Builder#buildForPatch()} may be helpful. * * @param urlMapName the name urlMap to be updated. * @param urlMapOptions the new urlMap options. diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java index 1e49f2b5fc..69022321f8 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java @@ -161,7 +161,7 @@ public abstract class HttpHealthCheckCreationOptions { * Useful when performing a PATCH operation and you do not want to overwrite * unspecified values with the default values. */ - public HttpHealthCheckCreationOptions buildNoDefaults() { + public HttpHealthCheckCreationOptions buildForPatch() { return HttpHealthCheckCreationOptions.create(host, requestPath, port, checkIntervalSec, timeoutSec, unhealthyThreshold, healthyThreshold, description); } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java index 94dd75afe3..0fa01c9412 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java @@ -16,60 +16,52 @@ */ package org.jclouds.googlecomputeengine.options; +import static com.google.common.base.Preconditions.checkNotNull; + import java.net.URI; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; -public final class TargetHttpProxyOptions { +import com.google.auto.value.AutoValue; - private String name; - @Nullable private String description; - private URI urlMap; +@AutoValue +public abstract class TargetHttpProxyOptions { - /** - * Name of the TargetHttpProxy resource. - * @return name, provided by the client. - */ - public String getName(){ - return name; + public abstract String name(); + @Nullable public abstract String description(); + public abstract URI urlMap(); + + @SerializedNames({ "name", "description", "urlMap"}) + static TargetHttpProxyOptions create(String name, String description, URI urlMap) { + return new AutoValue_TargetHttpProxyOptions(name, description, urlMap); } - /** - * @see TargetHttpProxyOptions#getName() - */ - public TargetHttpProxyOptions name(String name) { - this.name = name; - return this; + TargetHttpProxyOptions() { } - /** - * An optional textual description of the TargetHttpProxy. - * @return description, provided by the client. - */ - public String getDescription(){ - return description; - } + public static class Builder { + private String name; + private String description; + private URI urlMap; - /** - * @see TargetHttpProxyOptions#getDescription() - */ - public TargetHttpProxyOptions description(String description) { - this.description = description; - return this; - } + public Builder(String name, URI urlMap) { + this.name = name; + this.urlMap = urlMap; + } - /** - * URL to the UrlMap resource that defines the mapping from URL to the BackendService. - */ - public URI getUrlMap() { - return urlMap; - } + /** + * @see TargetHttpProxyOptions#getDescription() + */ + public Builder description(String description) { + this.description = description; + return this; + } - /** - * @see TargetHttpProxyOptions#getUrlMap() - */ - public TargetHttpProxyOptions urlMap(URI urlMap) { - this.urlMap = urlMap; - return this; + public TargetHttpProxyOptions build() { + checkNotNull(name, "TargetHttpProxyOptions name cannot be null"); + checkNotNull(urlMap, "TargetHttpProxyOptions name cannot be null"); + return create(name, description, urlMap); + } } } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java index 486414897c..31ba738b96 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java @@ -16,17 +16,24 @@ */ package org.jclouds.googlecomputeengine.options; +import static com.google.common.base.Preconditions.checkNotNull; + import java.net.URI; import java.util.List; +import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; + +import com.google.auto.value.AutoValue; + /** * Options for creating a Target Pool - * */ -public class TargetPoolCreationOptions{ +@AutoValue +public abstract class TargetPoolCreationOptions{ /** - * Session affinity determines the hash method that + * Session affinity determines the hash method that * Google Compute Engine uses to distribute traffic. * @see */ @@ -36,116 +43,100 @@ public class TargetPoolCreationOptions{ NONE } - private List healthChecks; - private List instances; - private SessionAffinityValue sessionAffinity; - private Float failoverRatio; - private URI backupPool; - private String description; + public abstract String name(); + @Nullable public abstract List healthChecks(); + @Nullable public abstract List instances(); + @Nullable public abstract SessionAffinityValue sessionAffinity(); + @Nullable public abstract Float failoverRatio(); + @Nullable public abstract URI backupPool(); + @Nullable public abstract String description(); - /** - * The set of HealthChecks - * - * @return a set of HealthCheck URIs - */ - public List getHealthChecks(){ - return healthChecks; + @SerializedNames({ "name", "healthChecks", "instances", "sessionAffinity", "failoverRatio", + "backupPool", "description"}) + public static TargetPoolCreationOptions create(String name, List healthChecks, List instances, + SessionAffinityValue sessionAffinity, Float failoverRatio, URI backupPool, String description) { + return new AutoValue_TargetPoolCreationOptions(name, healthChecks, instances, sessionAffinity, failoverRatio, + backupPool, description); } - /** - * A List of resource URIs to the member VMs serving this pool. - * They must live in zones contained in the same region as this pool. - * - * @return set of instance URIs - */ - public List getInstances(){ - return instances; + TargetPoolCreationOptions() { } - /** - * Defines the session affinity option. - * Session affinity determines the hash method that Google Compute Engine uses to distribute traffic. - * @return - */ - public SessionAffinityValue getSessionAffinity(){ - return sessionAffinity; - } + public static class Builder { - /** - * This field is applicable only when the target pool is serving a forwarding rule as the primary pool - * (e.g. not as a backup pool to some other target pool). - * The value of the a float between [0, 1]. - * If set, backupPool must also be set. - * @return failoverRatio, a float between [0, 1] - */ - public Float getFailoverRatio(){ - return failoverRatio; - } + private String name; + private List healthChecks; + private List instances; + private SessionAffinityValue sessionAffinity; + private Float failoverRatio; + private URI backupPool; + private String description; - /** - * This field is applicable only when the target pool is serving a forwarding rule as the primary pool - * (e.g. not as a backup pool to some other target pool). Must be a fully-qualified URL to a target pool that is in the same region as the primary target pool. - * If set, failoverRatio must also be set - * @return backupPool, Fully-qualified URI to a target pool in the same region as primary target pool - */ - public URI getBackupPool(){ - return backupPool; - } - - /** - * An optional textual description of the TargetPool. - * @return description, provided by the client. - */ - public String getDescription(){ - return description; - } + public Builder(String name){ + checkNotNull(name, "TargetPoolCreationOptions name cannot be null"); + this.name = name; + } - /** - * @see TargetPoolCreationOptions#getHealthChecks() - */ - public TargetPoolCreationOptions healthChecks(List healthChecks){ - this.healthChecks = healthChecks; - return this; - } + /** The set of HealthChecks */ + public Builder healthChecks(List healthChecks){ + this.healthChecks = healthChecks; + return this; + } - /** - * @see TargetPoolCreationOptions#getInstances() - */ - public TargetPoolCreationOptions instances(List instances){ - this.instances = instances; - return this; - } + /** + * A List of resource URIs to the member VMs serving this pool. + * They must live in zones contained in the same region as this pool. + */ + public Builder instances(List instances){ + this.instances = instances; + return this; + } - /** - * @see TargetPoolCreationOptions#getSessionAffinity() - */ - public TargetPoolCreationOptions sessionAffinity(SessionAffinityValue sessionAffinity){ - this.sessionAffinity = sessionAffinity; - return this; - } + /** + * Defines the session affinity option. + * Session affinity determines the hash method that Google Compute Engine uses to distribute traffic. + */ + public Builder sessionAffinity(SessionAffinityValue sessionAffinity){ + this.sessionAffinity = sessionAffinity; + return this; + } - /** - * @see TargetPoolCreationOptions#getFailoverRatio() - */ - public TargetPoolCreationOptions failoverRatio(float failoverRatio){ - this.failoverRatio = failoverRatio; - return this; - } + /** + * This field is applicable only when the target pool is serving a forwarding rule as the primary pool + * (e.g. not as a backup pool to some other target pool). + * The value of the a float between [0, 1]. + * If set, backupPool must also be set. + * @return failoverRatio, a float between [0, 1] + */ + public Builder failoverRatio(float failoverRatio){ + this.failoverRatio = failoverRatio; + return this; + } - /** - * @see TargetPoolCreationOptions#getBackupPool() - */ - public TargetPoolCreationOptions backupPool(URI backupPool){ - this.backupPool = backupPool; - return this; - } - - /** - * @see TargetPoolCreationOptions#getDescription() - */ - public TargetPoolCreationOptions description(String description){ - this.description = description; - return this; - } + /** + * This field is applicable only when the target pool is serving a forwarding rule as the primary pool + * (e.g. not as a backup pool to some other target pool). Must be a fully-qualified URL to a target pool + * that is in the same region as the primary target pool. + * If set, failoverRatio must also be set + * @return backupPool, Fully-qualified URI to a target pool in the same region as primary target pool + */ + public Builder backupPool(URI backupPool){ + this.backupPool = backupPool; + return this; + } + /** + * An optional textual description of the TargetPool. + * @return description, provided by the client. + */ + public Builder description(String description){ + this.description = description; + return this; + } + + public TargetPoolCreationOptions build() { + return create(name, healthChecks, instances, sessionAffinity, failoverRatio, + backupPool, description); + } + } } diff --git a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java index b47aaf9c38..e569e79a27 100644 --- a/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java +++ b/providers/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java @@ -16,6 +16,8 @@ */ package org.jclouds.googlecomputeengine.options; +import static com.google.common.base.Preconditions.checkNotNull; + import java.net.URI; import java.util.List; @@ -23,151 +25,121 @@ import org.jclouds.googlecomputeengine.domain.UrlMap.HostRule; import org.jclouds.googlecomputeengine.domain.UrlMap.PathMatcher; import org.jclouds.googlecomputeengine.domain.UrlMap.UrlMapTest; import org.jclouds.javax.annotation.Nullable; +import org.jclouds.json.SerializedNames; -import com.google.common.collect.ImmutableList; +import com.google.auto.value.AutoValue; -public class UrlMapOptions { +@AutoValue +public abstract class UrlMapOptions { - private String name; - @Nullable private String description; - private List hostRules; - private List pathMatchers; - private List tests; - private URI defaultService; - private String fingerprint; + @Nullable public abstract String name(); + @Nullable public abstract String description(); + @Nullable public abstract List hostRules(); + @Nullable public abstract List pathMatchers(); + @Nullable public abstract List tests(); + @Nullable public abstract URI defaultService(); + @Nullable public abstract String fingerprint(); - /** - * Name of the UrlMap resource. - * @return name, provided by the client. - */ - public String getName(){ - return name; + @SerializedNames({ "name", "description", "hostRules", "pathMatchers", "tests", + "defaultService", "fingerprint"}) + static UrlMapOptions create(String name, String description, List hostRules, + List pathMatchers, List tests, URI defaultService, String fingerprint) { + return new AutoValue_UrlMapOptions(name, description, hostRules, + pathMatchers, tests, defaultService, fingerprint); } - /** - * @see UrlMapOptions#getName() - */ - public UrlMapOptions name(String name) { - this.name = name; - return this; + UrlMapOptions(){ } - /** - * An optional textual description of the UrlMap. - * @return description, provided by the client. - */ - public String getDescription(){ - return description; - } + public static class Builder { - /** - * @see UrlMapOptions#getDescription() - */ - public UrlMapOptions description(String description) { - this.description = description; - return this; - } + private String name; + private String description; + private List hostRules; + private List pathMatchers; + private List tests; + private URI defaultService; + private String fingerprint; - /** - * Rules for matching and directing incoming hosts. - */ - public List getHostRules() { - return hostRules; - } + /** + * Name of the UrlMap resource. + */ + public Builder name(String name) { + this.name = name; + return this; + } - /** - * @see UrlMapOptions#getHostRules() - */ - public UrlMapOptions hostRules(List hostRules) { - this.hostRules = hostRules; - return this; - } + /** + * An optional textual description of the UrlMap. + */ + public Builder description(String description) { + this.description = description; + return this; + } - /** - * @see UrlMapOptions#getHostRules() - */ - public UrlMapOptions hostRule(HostRule hostRule){ - this.hostRules = ImmutableList.of(hostRule); - return this; - } + /** + * Rules for matching and directing incoming hosts. + */ + public Builder hostRules(List hostRules) { + this.hostRules = hostRules; + return this; + } - /** - * The list of named PathMatchers to use against the URL. - */ - public List getPathMatchers() { - return pathMatchers; - } + /** + * The list of named PathMatchers to use against the URL. + */ + public Builder pathMatchers(List pathMatchers) { + this.pathMatchers = pathMatchers; + return this; + } - /** - * @see UrlMapOptions#getPathMatchers() - */ - public UrlMapOptions pathMatcher(PathMatcher pathMatcher) { - this.pathMatchers = ImmutableList.of(pathMatcher); - return this; - } + /** + * The list of expected URL mappings. Request to update this + * UrlMap will succeed only all of the test cases pass. + */ + public Builder tests(List tests) { + this.tests = tests; + return this; + } - /** - * @see UrlMapOptions#getPathMatchers() - */ - public UrlMapOptions pathMatchers(List pathMatchers) { - this.pathMatchers = pathMatchers; - return this; - } + /** + * The URL of the BackendService resource if none of the hostRules match. + */ + public Builder defaultService(URI defaultService) { + this.defaultService = defaultService; + return this; + } - /** - * The list of expected URL mappings. Request to update this - * UrlMap will succeed only all of the test cases pass. - */ - public List getTests() { - return tests; - } + /** + * Fingerprint of this resource. A hash of the contents stored in this object. + * This field is used in optimistic locking. This field will be ignored when + * inserting a UrlMap. An up-to-date fingerprint must be provided in order to + * update the UrlMap. + */ + public Builder fingerprint(String fingerprint) { + this.fingerprint = fingerprint; + return this; + } - /** - * @see UrlMapOptions#getTests() - */ - public UrlMapOptions test(UrlMapTest urlMapTest) { - this.tests = ImmutableList.of(urlMapTest); - return this; - } + /** + * Builds the UrlMapOptions. + * Note: This enforces that "name" and "defaultService" are not null as the GCE API expects. + * If you are patching an existing UrlMap you may wish to use {@link #buildForPatch()} instead. + */ + public UrlMapOptions build() { + checkNotNull(name, "In UrlMapOptions: A UrlMap name cannot be null, if patching an existing UrlMap use buildForPatch() instead of build()"); + checkNotNull(defaultService, "In UrlMapOptions: A UrlMap defaultService cannot be null, if patching an existing UrlMap use buildForPatch() instead of build()"); + return create(name, description, hostRules, pathMatchers, tests, + defaultService, fingerprint); + } - /** - * @see UrlMapOptions#getTests() - */ - public UrlMapOptions urlMapTests(List urlMapTests) { - this.tests = urlMapTests; - return this; - } - - /** - * The URL of the BackendService resource if none of the hostRules match. - */ - public URI getDefaultService() { - return defaultService; - } - - /** - * @see UrlMapOptions#getDefaultService() - */ - public UrlMapOptions defaultService(URI defaultService) { - this.defaultService = defaultService; - return this; - } - - /** - * Fingerprint of this resource. A hash of the contents stored in this object. - * This field is used in optimistic locking. This field will be ignored when - * inserting a UrlMap. An up-to-date fingerprint must be provided in order to - * update the UrlMap. - */ - public String getFingerprint() { - return fingerprint; - } - - /** - * @see UrlMapOptions#getFingerprint() - */ - public UrlMapOptions fingerprint(String fingerprint) { - this.fingerprint = fingerprint; - return this; + /** + * This build option is specifically for when patching an existing UrlMap. + * If not patching an existing urlMap it is recommended that you use {@link #build()}. + */ + public UrlMapOptions buildForPatch() { + return create(name, description, hostRules, pathMatchers, tests, + defaultService, fingerprint); + } } } diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java deleted file mode 100644 index f55e93864f..0000000000 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * 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.googlecomputeengine.binders; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; -import java.util.List; -import java.util.Map; - -import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest; -import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions; -import org.jclouds.googlecomputeengine.options.TargetPoolCreationOptions.SessionAffinityValue; -import org.jclouds.http.HttpRequest; -import org.jclouds.json.Json; -import org.jclouds.json.internal.GsonWrapper; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.gson.Gson; - -@Test(groups = "unit", testName = "TargetPoolCreationBinderTest") -public class TargetPoolCreationBinderTest extends BaseGoogleComputeEngineExpectTest{ - - private static final List FAKE_HEALTH_CHECKS = ImmutableList.of( - URI.create("https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/backports-debian-7-wheezy-v20141017")); - private static SessionAffinityValue SESSION_AFFINITY = SessionAffinityValue.CLIENT_IP_PROTO; - private static float FAILOVER_RATIO = (float) 0.4; - private static String DESCRIPTION = "This is a test!"; - - Json json = new GsonWrapper(new Gson()); - - @Test - public void testMap() throws SecurityException, NoSuchMethodException { - TargetPoolCreationBinder binder = new TargetPoolCreationBinder(json); - TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions() - .healthChecks(FAKE_HEALTH_CHECKS) - .sessionAffinity(SESSION_AFFINITY) - .failoverRatio(FAILOVER_RATIO) - .description(DESCRIPTION); - - HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build(); - Map postParams = ImmutableMap.of("name", "testTargetPoolName", "options", targetPoolCreationOptions); - - binder.bindToRequest(request, postParams); - - assertEquals(request.getPayload().getRawContent(), - "{\"" - + "name\":\"testTargetPoolName\"," - + "\"healthChecks\":[\"" + FAKE_HEALTH_CHECKS.toArray()[0] + "\"]," - + "\"sessionAffinity\":\"CLIENT_IP_PROTO\"," - + "\"failoverRatio\":0.4," - + "\"description\":\"This is a test!\"" - + "}"); - assertEquals(request.getPayload().getContentMetadata().getContentType(), "application/json"); - } -} diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java index 257c4bcb6d..2f036238cd 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java @@ -61,11 +61,12 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes @BeforeClass public void init() { - TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions(); - assertOperationDoneSuccessfully(targetPoolApi().create(TARGETPOOL_NAME, targetPoolCreationOptions)); + TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions.Builder(TARGETPOOL_NAME).build(); + assertOperationDoneSuccessfully(targetPoolApi().create(targetPoolCreationOptions)); targetPool = targetPoolApi().get(TARGETPOOL_NAME); - assertOperationDoneSuccessfully(targetPoolApi().create(TARGETPOOL_NAME_NEW, targetPoolCreationOptions)); + targetPoolCreationOptions = new TargetPoolCreationOptions.Builder(TARGETPOOL_NAME_NEW).build(); + assertOperationDoneSuccessfully(targetPoolApi().create(targetPoolCreationOptions)); newTargetPool = targetPoolApi().get(TARGETPOOL_NAME_NEW); assertOperationDoneSuccessfully(addressApi().create(ADDRESS_NAME)); diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java index 31df69868d..a3656a0c43 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java @@ -66,9 +66,9 @@ public class GlobalForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiL assertOperationDoneSuccessfully(api.backendServices() .create(b)); - UrlMapOptions map = new UrlMapOptions().name(GLOBAL_FORWARDING_RULE_URL_MAP_NAME) + UrlMapOptions map = new UrlMapOptions.Builder().name(GLOBAL_FORWARDING_RULE_URL_MAP_NAME) .description("simple url map") - .defaultService(getBackendServiceUrl(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)); + .defaultService(getBackendServiceUrl(GLOBAL_FORWARDING_RULE_BACKEND_SERVICE_NAME)).build(); assertOperationDoneSuccessfully(api.urlMaps() .create(map)); assertOperationDoneSuccessfully(api.targetHttpProxies() diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java index ec2cad8ad0..49e9cc5fca 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java @@ -78,7 +78,7 @@ public class HttpHealthCheckApiLiveTest extends BaseGoogleComputeEngineApiLiveTe .port(options.port() + OFFSET) .checkIntervalSec(options.checkIntervalSec() + OFFSET) .timeoutSec(options.timeoutSec() + OFFSET) - .buildNoDefaults(); + .buildForPatch(); assertOperationDoneSuccessfully(api().patch(HTTP_HEALTH_CHECK_NAME, newOptions)); // Check changes happened and others unchanged. diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java index ebc86fefbb..9efa8d9a4b 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java @@ -91,7 +91,7 @@ public class HttpHealthCheckApiMockTest extends BaseGoogleComputeEngineApiMockTe server.enqueue(jsonResponse("/global_operation.json")); HttpHealthCheckCreationOptions options = new HttpHealthCheckCreationOptions.Builder() - .timeoutSec(0).unhealthyThreshold(0).buildNoDefaults(); + .timeoutSec(0).unhealthyThreshold(0).buildForPatch(); assertEquals(httpHealthCheckApi().patch("http-health-check", options), new ParseGlobalOperationTest().expected(url("/projects"))); diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java index 2a4e517803..ef3abaeb43 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java @@ -57,12 +57,14 @@ public class TargetHttpProxyApiLiveTest extends BaseGoogleComputeEngineApiLiveTe assertOperationDoneSuccessfully(api.backendServices().create(b)); - UrlMapOptions map = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map") - .defaultService(getBackendServiceUrl(URL_MAP_DEFAULT_SERVICE_NAME)); + UrlMapOptions map = new UrlMapOptions.Builder().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map") + .defaultService(getBackendServiceUrl(URL_MAP_DEFAULT_SERVICE_NAME)).build(); assertOperationDoneSuccessfully(api.urlMaps().create(map)); - UrlMapOptions map2 = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2").description("a second simple url map") - .defaultService(getBackendServiceUrl(URL_MAP_DEFAULT_SERVICE_NAME)); + UrlMapOptions map2 = new UrlMapOptions.Builder().name(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2") + .description("a second simple url map") + .defaultService(getBackendServiceUrl(URL_MAP_DEFAULT_SERVICE_NAME)) + .build(); assertOperationDoneSuccessfully(api.urlMaps().create(map2)); @@ -78,13 +80,8 @@ public class TargetHttpProxyApiLiveTest extends BaseGoogleComputeEngineApiLiveTe @Test(groups = "live", dependsOnMethods = "testGetTargetHttpProxy") public void testSetUrlMapTargetHttpProxy() { - UrlMapOptions map = new UrlMapOptions().name(TARGET_HTTP_PROXY_URL_MAP_NAME).description("simple url map") - .defaultService(getBackendServiceUrl(URL_MAP_DEFAULT_SERVICE_NAME)); - assertOperationDoneSuccessfully(api.urlMaps() - .create(map)); - assertOperationDoneSuccessfully(api().setUrlMap(TARGET_HTTP_PROXY_NAME, - getUrlMapUrl(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2"))); + getUrlMapUrl(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2"))); } @Test(groups = "live", dependsOnMethods = "testSetUrlMapTargetHttpProxy") @@ -97,7 +94,7 @@ public class TargetHttpProxyApiLiveTest extends BaseGoogleComputeEngineApiLiveTe getUrlMapUrl(TARGET_HTTP_PROXY_URL_MAP_NAME + "-2")); } - @Test(groups = "live", dependsOnMethods = "testListTargetHttpProxy") + @Test(groups = "live", dependsOnMethods = "testListTargetHttpProxy", alwaysRun = true) public void testDeleteTargetHttpProxy() { assertOperationDoneSuccessfully(api().delete(TARGET_HTTP_PROXY_NAME)); diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiMockTest.java index 08d3e8577f..cd9a825f74 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiMockTest.java @@ -23,6 +23,7 @@ import static org.testng.AssertJUnit.assertNull; import java.net.URI; import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest; +import org.jclouds.googlecomputeengine.options.TargetHttpProxyOptions; import org.jclouds.googlecomputeengine.parse.ParseOperationTest; import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyListTest; import org.jclouds.googlecomputeengine.parse.ParseTargetHttpProxyTest; @@ -55,6 +56,20 @@ public class TargetHttpProxyApiMockTest extends BaseGoogleComputeEngineApiMockTe stringFromResource("/target_http_proxy_insert.json")); } + public void insert_options() throws Exception { + server.enqueue(jsonResponse("/operation.json")); + + URI urlMap = URI.create(url("/projects/myproject/global/urlMaps/jclouds-test")); + TargetHttpProxyOptions options = new TargetHttpProxyOptions.Builder("jclouds-test", urlMap).description("test").build(); + assertEquals(targetHttpProxyApi().create(options), new ParseOperationTest().expected(url("/projects"))); + assertSent(server, "POST", "/projects/party/global/targetHttpProxies", + "{" + + " \"name\": \"jclouds-test\"," + + " \"urlMap\": \"" + url("/projects/myproject/global/urlMaps/jclouds-test") + "\"," + + " \"description\": \"test\"" + + "}"); + } + public void delete() throws Exception { server.enqueue(jsonResponse("/operation.json")); diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java index d94a6160ea..c2423bc93a 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java @@ -126,10 +126,11 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live") public void testInsertTargetPool() { - TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions() + TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions.Builder(BACKUP_TARGETPOOL_NAME) .description(DESCRIPTION_BACKUP) - .sessionAffinity(SessionAffinityValue.CLIENT_IP); - assertOperationDoneSuccessfully(api().create(BACKUP_TARGETPOOL_NAME, targetPoolCreationOptions)); + .sessionAffinity(SessionAffinityValue.CLIENT_IP) + .build(); + assertOperationDoneSuccessfully(api().create(targetPoolCreationOptions)); } @Test(groups = "live", dependsOnMethods = "testInsertTargetPool") @@ -137,12 +138,13 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { TargetPool targetPool = api().get(BACKUP_TARGETPOOL_NAME); assertNotNull(targetPool); // Make a Target Pool with a backup and failoverRatio specified. - TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions() + TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions.Builder(TARGETPOOL_NAME) .description(DESCRIPTION) .sessionAffinity(SessionAffinityValue.CLIENT_IP) .backupPool(targetPool.selfLink()) - .failoverRatio((float) 0.5); - assertOperationDoneSuccessfully(api().create(TARGETPOOL_NAME, targetPoolCreationOptions)); + .failoverRatio((float) 0.5) + .build(); + assertOperationDoneSuccessfully(api().create(targetPoolCreationOptions)); TargetPool targetPool2 = api().get(TARGETPOOL_NAME); assertNotNull(targetPool2); assertEquals(targetPool2.name(), TARGETPOOL_NAME); @@ -222,8 +224,9 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { @Test(groups = "live", dependsOnMethods = {"testInsertTargetPool2"}) public void testListBackupTargetPool() { - TargetPoolCreationOptions options = new TargetPoolCreationOptions().description("A targetPool for testing setBackup."); - assertOperationDoneSuccessfully(api().create(THIRD_TARGETPOOL_NAME, options)); + TargetPoolCreationOptions options = new TargetPoolCreationOptions.Builder(THIRD_TARGETPOOL_NAME) + .description("A targetPool for testing setBackup.").build(); + assertOperationDoneSuccessfully(api().create(options)); TargetPool targetPool = api().get(THIRD_TARGETPOOL_NAME); assertNotNull(targetPool); assertEquals(targetPool.name(), THIRD_TARGETPOOL_NAME); diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiMockTest.java index f45a38409c..5f579ecc68 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiMockTest.java @@ -54,8 +54,8 @@ public class TargetPoolApiMockTest extends BaseGoogleComputeEngineApiMockTest { public void insert() throws Exception { server.enqueue(jsonResponse("/region_operation.json")); - TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions(); - assertEquals(targetPoolApi().create("test", targetPoolCreationOptions), + TargetPoolCreationOptions targetPoolCreationOptions = new TargetPoolCreationOptions.Builder("test").build(); + assertEquals(targetPoolApi().create(targetPoolCreationOptions), new ParseRegionOperationTest().expected(url("/projects"))); assertSent(server, "POST", "/projects/party/regions/us-central1/targetPools", stringFromResource("/targetpool_insert.json")); diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java index f47d96e234..f48e44a4d0 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java @@ -58,8 +58,8 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { .healthChecks(healthChecks); assertOperationDoneSuccessfully(api.backendServices().create(b)); - UrlMapOptions map = new UrlMapOptions().name(URL_MAP_NAME).description("simple url map") - .defaultService(getBackendServiceUrl(URL_MAP_BACKEND_SERVICE_NAME)); + UrlMapOptions map = new UrlMapOptions.Builder().name(URL_MAP_NAME).description("simple url map") + .defaultService(getBackendServiceUrl(URL_MAP_BACKEND_SERVICE_NAME)).build(); assertOperationDoneSuccessfully(api().create(map)); @@ -100,11 +100,11 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { ImmutableList hosts = ImmutableList.of("jclouds-test"); ImmutableList hostRules = ImmutableList.of(HostRule.create("", hosts, "test-path-matcher")); - UrlMapOptions options = new UrlMapOptions().name(URL_MAP_NAME) + UrlMapOptions options = new UrlMapOptions.Builder().name(URL_MAP_NAME) .pathMatchers(matchers) .hostRules(hostRules) .defaultService(service) - .fingerprint(fingerprint); + .fingerprint(fingerprint).build(); assertOperationDoneSuccessfully(api().update(URL_MAP_NAME, options)); @@ -119,8 +119,8 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { UrlMapTest urlMapTest = UrlMapTest.create(null, "jclouds-test", "/test/path", service); ImmutableList urlMapTests = ImmutableList.of(urlMapTest); - UrlMapOptions options = new UrlMapOptions().urlMapTests(urlMapTests) - .fingerprint(fingerprint); + UrlMapOptions options = new UrlMapOptions.Builder().tests(urlMapTests) + .fingerprint(fingerprint).buildForPatch(); assertOperationDoneSuccessfully(api().patch(URL_MAP_NAME, options)); // Update options with settings it should have for later assertions. @@ -132,11 +132,15 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { ImmutableList hosts = ImmutableList.of("jclouds-test"); ImmutableList hostRules = ImmutableList.of(HostRule.create("", hosts, "test-path-matcher")); - options.name(URL_MAP_NAME) + + options = new UrlMapOptions.Builder().name(URL_MAP_NAME) .description("simple url map") .pathMatchers(matchers) .hostRules(hostRules) - .defaultService(service); + .defaultService(service) + .tests(urlMapTests) + .fingerprint(fingerprint) + .build(); assertUrlMapEquals(api().get(URL_MAP_NAME), options); } @@ -163,14 +167,14 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { UrlMapTest urlMapTest = UrlMapTest.create(null, "jclouds-test", "/test/path", service); ImmutableList urlMapTests = ImmutableList.of(urlMapTest); - UrlMapOptions options = new UrlMapOptions(); - - options.pathMatchers(matchers) + UrlMapOptions options = new UrlMapOptions.Builder() + .pathMatchers(matchers) .name(URL_MAP_NAME) .hostRules(hostRules) - .urlMapTests(urlMapTests) + .tests(urlMapTests) .defaultService(service) - .description("simple url map"); + .description("simple url map") + .build(); UrlMapValidateResult results = api().validate(URL_MAP_NAME, options); UrlMapValidateResult expected = UrlMapValidateResult.allPass(); @@ -196,9 +200,9 @@ public class UrlMapApiLiveTest extends BaseGoogleComputeEngineApiLiveTest { } private void assertUrlMapEquals(UrlMap result, UrlMapOptions expected) { - assertEquals(result.name(), expected.getName()); - assertEquals(result.defaultService(), expected.getDefaultService()); - assertEquals(result.pathMatchers(), expected.getPathMatchers()); - assertEquals(result.hostRules(), expected.getHostRules()); + assertEquals(result.name(), expected.name()); + assertEquals(result.defaultService(), expected.defaultService()); + assertEquals(result.pathMatchers(), expected.pathMatchers()); + assertEquals(result.hostRules(), expected.hostRules()); } } diff --git a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiMockTest.java b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiMockTest.java index 11075570c5..7c6d639603 100644 --- a/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiMockTest.java +++ b/providers/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiMockTest.java @@ -119,17 +119,18 @@ public class UrlMapApiMockTest extends BaseGoogleComputeEngineApiMockTest { private UrlMapOptions createBasicMap() { URI service = URI.create(url("/projects/myproject/global/backendServices/jclouds-test")); - return new UrlMapOptions().name("jclouds-test") + return new UrlMapOptions.Builder().name("jclouds-test") .description("Sample url map") - .hostRule(HostRule.create(null, ImmutableList.of("jclouds-test"), "path")) - .pathMatcher(PathMatcher.create("path", + .hostRules(ImmutableList.of(HostRule.create(null, ImmutableList.of("jclouds-test"), "path"))) + .pathMatchers(ImmutableList.of(PathMatcher.create("path", null, service, ImmutableList.of( PathRule.create(ImmutableList.of("/"), - service)))) - .test(UrlMap.UrlMapTest.create(null, "jclouds-test", "/test/path", service)) - .defaultService(service); + service))))) + .tests(ImmutableList.of(UrlMap.UrlMapTest.create(null, "jclouds-test", "/test/path", service))) + .defaultService(service) + .build(); } UrlMapApi urlMapApi() { diff --git a/providers/google-compute-engine/src/test/resources/target_http_proxy_insert.json b/providers/google-compute-engine/src/test/resources/target_http_proxy_insert.json index b296e71b7f..991055af2d 100644 --- a/providers/google-compute-engine/src/test/resources/target_http_proxy_insert.json +++ b/providers/google-compute-engine/src/test/resources/target_http_proxy_insert.json @@ -1 +1,4 @@ -{"name":"jclouds-test","urlMap":"https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test"} \ No newline at end of file +{ + "name": "jclouds-test", + "urlMap": "https://www.googleapis.com/compute/v1/projects/myproject/global/urlMaps/jclouds-test" +} \ No newline at end of file