You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/01/09 23:21:16 UTC
[1/3] jclouds-labs-google git commit: Updated TargetHttpProxyOptions,
TargetPoolCreationOptions, UrlMapOptions to AutoValue + Builder
Repository: jclouds-labs-google
Updated Branches:
refs/heads/master bc0d8a141 -> 0391f699e
Updated TargetHttpProxyOptions, TargetPoolCreationOptions, UrlMapOptions to AutoValue + Builder
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/98840ab6
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/98840ab6
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/98840ab6
Branch: refs/heads/master
Commit: 98840ab62e7cbf83e9cda49497124a986ae807cd
Parents: bc0d8a1
Author: Daniel Broudy <br...@google.com>
Authored: Fri Dec 19 13:29:09 2014 -0800
Committer: Ignasi Barrera <na...@apache.org>
Committed: Fri Jan 9 23:14:14 2015 +0100
----------------------------------------------------------------------
.../binders/TargetPoolCreationBinder.java | 75 ------
.../features/TargetHttpProxyApi.java | 1 +
.../features/TargetPoolApi.java | 5 +-
.../googlecomputeengine/features/UrlMapApi.java | 1 +
.../options/HttpHealthCheckCreationOptions.java | 2 +-
.../options/TargetHttpProxyOptions.java | 76 +++---
.../options/TargetPoolCreationOptions.java | 195 +++++++-------
.../options/UrlMapOptions.java | 264 +++++++++----------
.../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, 326 insertions(+), 493 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinder.java
deleted file mode 100644
index 1d52859..0000000
--- a/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 extends HttpRequest> R bindToRequest(R request, Map<String, Object> 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<URI> healthChecks;
- @SuppressWarnings("unused")
- private List<URI> 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();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java
index abb0bf4..97c45d4 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApi.java
+++ b/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.
*
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java
index e623c12..6d57086 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/TargetPoolApi.java
+++ b/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")
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java
index 25783d2..d77c542 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/UrlMapApi.java
+++ b/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.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java
index 1e49f2b..6902232 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/HttpHealthCheckCreationOptions.java
+++ b/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);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java
index 94dd75a..0fa01c9 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetHttpProxyOptions.java
+++ b/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();
- /**
- * @see TargetHttpProxyOptions#getName()
- */
- public TargetHttpProxyOptions name(String name) {
- this.name = name;
- return this;
+ @SerializedNames({ "name", "description", "urlMap"})
+ static TargetHttpProxyOptions create(String name, String description, URI urlMap) {
+ return new AutoValue_TargetHttpProxyOptions(name, description, urlMap);
}
- /**
- * An optional textual description of the TargetHttpProxy.
- * @return description, provided by the client.
- */
- public String getDescription(){
- return description;
+ TargetHttpProxyOptions() {
}
- /**
- * @see TargetHttpProxyOptions#getDescription()
- */
- public TargetHttpProxyOptions description(String description) {
- this.description = description;
- return this;
- }
+ public static class Builder {
+ private String name;
+ private String description;
+ private URI urlMap;
- /**
- * URL to the UrlMap resource that defines the mapping from URL to the BackendService.
- */
- public URI getUrlMap() {
- return urlMap;
- }
+ public Builder(String name, URI urlMap) {
+ this.name = name;
+ this.urlMap = 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);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java
index 4864148..31ba738 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/TargetPoolCreationOptions.java
+++ b/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 <a href="https://cloud.google.com/compute/docs/reference/latest/targetPools#resource"/>
*/
@@ -36,116 +43,100 @@ public class TargetPoolCreationOptions{
NONE
}
- private List<URI> healthChecks;
- private List<URI> instances;
- private SessionAffinityValue sessionAffinity;
- private Float failoverRatio;
- private URI backupPool;
- private String description;
+ public abstract String name();
+ @Nullable public abstract List<URI> healthChecks();
+ @Nullable public abstract List<URI> 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<URI> getHealthChecks(){
- return healthChecks;
+ @SerializedNames({ "name", "healthChecks", "instances", "sessionAffinity", "failoverRatio",
+ "backupPool", "description"})
+ public static TargetPoolCreationOptions create(String name, List<URI> healthChecks, List<URI> 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<URI> 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<URI> healthChecks;
+ private List<URI> 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<URI> healthChecks){
- this.healthChecks = healthChecks;
- return this;
- }
+ /** The set of HealthChecks */
+ public Builder healthChecks(List<URI> healthChecks){
+ this.healthChecks = healthChecks;
+ return this;
+ }
- /**
- * @see TargetPoolCreationOptions#getInstances()
- */
- public TargetPoolCreationOptions instances(List<URI> 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<URI> 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);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java
index b47aaf9..e569e79 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/options/UrlMapOptions.java
+++ b/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 com.google.common.collect.ImmutableList;
-
-public class UrlMapOptions {
-
- private String name;
- @Nullable private String description;
- private List<HostRule> hostRules;
- private List<PathMatcher> pathMatchers;
- private List<UrlMapTest> tests;
- private URI defaultService;
- private String fingerprint;
-
- /**
- * Name of the UrlMap resource.
- * @return name, provided by the client.
- */
- public String getName(){
- return name;
- }
-
- /**
- * @see UrlMapOptions#getName()
- */
- public UrlMapOptions name(String name) {
- this.name = name;
- return this;
- }
-
- /**
- * An optional textual description of the UrlMap.
- * @return description, provided by the client.
- */
- public String getDescription(){
- return description;
- }
-
- /**
- * @see UrlMapOptions#getDescription()
- */
- public UrlMapOptions description(String description) {
- this.description = description;
- return this;
- }
-
- /**
- * Rules for matching and directing incoming hosts.
- */
- public List<HostRule> getHostRules() {
- return hostRules;
- }
-
- /**
- * @see UrlMapOptions#getHostRules()
- */
- public UrlMapOptions hostRules(List<HostRule> hostRules) {
- this.hostRules = hostRules;
- return this;
- }
-
- /**
- * @see UrlMapOptions#getHostRules()
- */
- public UrlMapOptions hostRule(HostRule hostRule){
- this.hostRules = ImmutableList.of(hostRule);
- return this;
- }
-
- /**
- * The list of named PathMatchers to use against the URL.
- */
- public List<PathMatcher> getPathMatchers() {
- return pathMatchers;
- }
-
- /**
- * @see UrlMapOptions#getPathMatchers()
- */
- public UrlMapOptions pathMatcher(PathMatcher pathMatcher) {
- this.pathMatchers = ImmutableList.of(pathMatcher);
- return this;
- }
-
- /**
- * @see UrlMapOptions#getPathMatchers()
- */
- public UrlMapOptions pathMatchers(List<PathMatcher> pathMatchers) {
- this.pathMatchers = pathMatchers;
- return this;
- }
-
- /**
- * The list of expected URL mappings. Request to update this
- * UrlMap will succeed only all of the test cases pass.
- */
- public List<UrlMapTest> getTests() {
- return tests;
- }
-
- /**
- * @see UrlMapOptions#getTests()
- */
- public UrlMapOptions test(UrlMapTest urlMapTest) {
- this.tests = ImmutableList.of(urlMapTest);
- return this;
- }
-
- /**
- * @see UrlMapOptions#getTests()
- */
- public UrlMapOptions urlMapTests(List<UrlMapTest> 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;
+import org.jclouds.json.SerializedNames;
+
+import com.google.auto.value.AutoValue;
+
+@AutoValue
+public abstract class UrlMapOptions {
+
+ @Nullable public abstract String name();
+ @Nullable public abstract String description();
+ @Nullable public abstract List<HostRule> hostRules();
+ @Nullable public abstract List<PathMatcher> pathMatchers();
+ @Nullable public abstract List<UrlMapTest> tests();
+ @Nullable public abstract URI defaultService();
+ @Nullable public abstract String fingerprint();
+
+ @SerializedNames({ "name", "description", "hostRules", "pathMatchers", "tests",
+ "defaultService", "fingerprint"})
+ static UrlMapOptions create(String name, String description, List<HostRule> hostRules,
+ List<PathMatcher> pathMatchers, List<UrlMapTest> tests, URI defaultService, String fingerprint) {
+ return new AutoValue_UrlMapOptions(name, description, hostRules,
+ pathMatchers, tests, defaultService, fingerprint);
+ }
+
+ UrlMapOptions(){
+ }
+
+ public static class Builder {
+
+ private String name;
+ private String description;
+ private List<HostRule> hostRules;
+ private List<PathMatcher> pathMatchers;
+ private List<UrlMapTest> tests;
+ private URI defaultService;
+ private String fingerprint;
+
+ /**
+ * Name of the UrlMap resource.
+ */
+ public Builder name(String name) {
+ this.name = name;
+ return this;
+ }
+
+ /**
+ * An optional textual description of the UrlMap.
+ */
+ public Builder description(String description) {
+ this.description = description;
+ return this;
+ }
+
+ /**
+ * Rules for matching and directing incoming hosts.
+ */
+ public Builder hostRules(List<HostRule> hostRules) {
+ this.hostRules = hostRules;
+ return this;
+ }
+
+ /**
+ * The list of named PathMatchers to use against the URL.
+ */
+ public Builder pathMatchers(List<PathMatcher> pathMatchers) {
+ this.pathMatchers = pathMatchers;
+ 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<UrlMapTest> tests) {
+ this.tests = tests;
+ return this;
+ }
+
+ /**
+ * The URL of the BackendService resource if none of the hostRules match.
+ */
+ public Builder 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 Builder fingerprint(String fingerprint) {
+ this.fingerprint = fingerprint;
+ 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);
+ }
+
+ /**
+ * 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);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/binders/TargetPoolCreationBinderTest.java
deleted file mode 100644
index f55e938..0000000
--- a/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<Object>{
-
- private static final List<URI> 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<String, Object> 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");
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
index 257c4bc..2f03623 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ForwardingRuleApiLiveTest.java
+++ b/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));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
index 31df698..a3656a0 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/GlobalForwardingRuleApiLiveTest.java
+++ b/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()
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
index ec2cad8..49e9cc5 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiLiveTest.java
+++ b/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.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
index ebc86fe..9efa8d9 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/HttpHealthCheckApiMockTest.java
+++ b/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")));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java
index 2a4e517..ef3abae 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiLiveTest.java
+++ b/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));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiMockTest.java
index 08d3e85..cd9a825 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetHttpProxyApiMockTest.java
+++ b/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"));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
index d94a616..c2423bc 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiLiveTest.java
+++ b/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);
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiMockTest.java
index f45a384..5f579ec 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/TargetPoolApiMockTest.java
+++ b/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"));
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java
index f47d96e..f48e44a 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiLiveTest.java
+++ b/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<String> hosts = ImmutableList.<String>of("jclouds-test");
ImmutableList<HostRule> hostRules = ImmutableList.<HostRule>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<UrlMap.UrlMapTest> urlMapTests = ImmutableList.<UrlMap.UrlMapTest>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<String> hosts = ImmutableList.<String>of("jclouds-test");
ImmutableList<HostRule> hostRules = ImmutableList.<HostRule>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<UrlMap.UrlMapTest> urlMapTests = ImmutableList.<UrlMap.UrlMapTest>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());
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiMockTest.java
index 1107557..7c6d639 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/UrlMapApiMockTest.java
+++ b/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() {
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/98840ab6/google-compute-engine/src/test/resources/target_http_proxy_insert.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/target_http_proxy_insert.json b/google-compute-engine/src/test/resources/target_http_proxy_insert.json
index b296e71..991055a 100644
--- a/google-compute-engine/src/test/resources/target_http_proxy_insert.json
+++ b/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
[2/3] jclouds-labs-google git commit: Added
Project:setUsageExportBucket and ProjectApiMockTest
Posted by na...@apache.org.
Added Project:setUsageExportBucket and ProjectApiMockTest
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/fff69b6c
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/fff69b6c
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/fff69b6c
Branch: refs/heads/master
Commit: fff69b6cad82435d4d879bdfc0b89f697f35cc7a
Parents: 98840ab
Author: Daniel Broudy <br...@google.com>
Authored: Mon Nov 24 17:51:37 2014 -0800
Committer: Ignasi Barrera <na...@apache.org>
Committed: Fri Jan 9 23:19:15 2015 +0100
----------------------------------------------------------------------
.../googlecomputeengine/domain/Project.java | 27 +++++-
.../features/ProjectApi.java | 10 +++
.../features/ProjectApiExpectTest.java | 88 --------------------
.../features/ProjectApiLiveTest.java | 13 +++
.../features/ProjectApiMockTest.java | 72 ++++++++++++++++
.../BaseGoogleComputeEngineApiLiveTest.java | 5 --
.../parse/ParseProjectTest.java | 13 ++-
.../src/test/resources/project.json | 6 +-
8 files changed, 135 insertions(+), 99 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/fff69b6c/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java
index 480f23f..ecec9e4 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Project.java
@@ -19,6 +19,7 @@ package org.jclouds.googlecomputeengine.domain;
import static org.jclouds.googlecloud.internal.NullSafeCopies.copyOf;
import java.net.URI;
+import java.util.Date;
import java.util.List;
import org.jclouds.javax.annotation.Nullable;
@@ -30,6 +31,22 @@ import com.google.auto.value.AutoValue;
@AutoValue
public abstract class Project {
+ @AutoValue
+ public abstract static class UsageExportLocation {
+
+ public abstract String bucketName();
+
+ public abstract String reportNamePrefix();
+
+ @SerializedNames({"bucketName", "reportNamePrefix"})
+ public static UsageExportLocation create(String bucketName, String reporNamePrefix) {
+ return new AutoValue_Project_UsageExportLocation(bucketName, reporNamePrefix);
+ }
+
+ UsageExportLocation () {
+ }
+ }
+
public abstract String id();
public abstract URI selfLink();
@@ -46,12 +63,16 @@ public abstract class Project {
/** Available IP addresses available for use in this project. */
public abstract List<String> externalIpAddresses();
+ public abstract Date creationTimestamp();
+
+ @Nullable public abstract UsageExportLocation usageExportLocation();
+
@SerializedNames(
- { "id", "selfLink", "name", "description", "commonInstanceMetadata", "quotas", "externalIpAddresses" })
+ { "id", "selfLink", "name", "description", "commonInstanceMetadata", "quotas", "externalIpAddresses", "creationTimestamp", "usageExportLocation"})
public static Project create(String id, URI selfLink, String name, String description,
- Metadata commonInstanceMetadata, List<Quota> quotas, List<String> externalIpAddresses) {
+ Metadata commonInstanceMetadata, List<Quota> quotas, List<String> externalIpAddresses, Date creationTimestamp, UsageExportLocation usageExportLocation) {
return new AutoValue_Project(id, selfLink, name, description, commonInstanceMetadata, copyOf(quotas),
- copyOf(externalIpAddresses));
+ copyOf(externalIpAddresses), creationTimestamp, usageExportLocation);
}
Project() {
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/fff69b6c/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
index 1f5aac3..c33aced 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/features/ProjectApi.java
@@ -32,6 +32,8 @@ import org.jclouds.googlecomputeengine.domain.Project;
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;
import org.jclouds.rest.annotations.RequestFilters;
import org.jclouds.rest.annotations.SkipEncoding;
import org.jclouds.rest.binders.BindToJsonPayload;
@@ -67,4 +69,12 @@ public interface ProjectApi {
@Path("/setCommonInstanceMetadata")
@Produces(APPLICATION_JSON)
Operation setCommonInstanceMetadata(@BinderParam(BindToJsonPayload.class) Metadata metadata);
+
+ @Named("Projects:setUsageExportBucket")
+ @POST
+ @Path("/setUsageExportBucket")
+ @Produces(APPLICATION_JSON)
+ @MapBinder(BindToJsonPayload.class)
+ Operation setUsageExportBucket(@PayloadParam("bucketName") String bucketName,
+ @PayloadParam("reportNamePrefix") String reportNamePrefix);
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/fff69b6c/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
deleted file mode 100644
index fd945e8..0000000
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiExpectTest.java
+++ /dev/null
@@ -1,88 +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.features;
-
-import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-
-import org.jclouds.googlecomputeengine.GoogleComputeEngineApi;
-import org.jclouds.googlecomputeengine.domain.Metadata;
-import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineExpectTest;
-import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
-import org.jclouds.googlecomputeengine.parse.ParseMetadataTest;
-import org.jclouds.googlecomputeengine.parse.ParseProjectTest;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpResponse;
-import org.testng.annotations.Test;
-
-@Test(groups = "unit", testName = "ProjectApiExpectTest")
-public class ProjectApiExpectTest extends BaseGoogleComputeEngineExpectTest<GoogleComputeEngineApi> {
-
- public static final HttpRequest GET_PROJECT_REQUEST = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party")
- .addHeader("Accept", APPLICATION_JSON)
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- public static final HttpResponse GET_PROJECT_RESPONSE = HttpResponse.builder().statusCode(200)
- .payload(staticPayloadFromResource("/project.json")).build();
-
- public void testGetProjectResponseIs2xx() throws Exception {
- ProjectApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE,
- GET_PROJECT_REQUEST, GET_PROJECT_RESPONSE).project();
-
- assertEquals(api.get(), new ParseProjectTest().expected());
- }
-
- public void testGetProjectResponseIs4xx() throws Exception {
- HttpRequest getProjectRequest = HttpRequest
- .builder()
- .method("GET")
- .endpoint(BASE_URL + "/party")
- .addHeader("Accept", APPLICATION_JSON)
- .addHeader("Authorization", "Bearer " + TOKEN).build();
-
- HttpResponse getProjectResponse = HttpResponse.builder().statusCode(404).build();
-
- ProjectApi api = requestsSendResponses(requestForScopes(COMPUTE_READONLY_SCOPE), TOKEN_RESPONSE,
- getProjectRequest, getProjectResponse).project();
-
- assertNull(api.get());
- }
-
- public void testSetCommonInstanceMetadata() {
- HttpRequest setMetadata = HttpRequest
- .builder()
- .method("POST")
- .endpoint(BASE_URL + "/party/setCommonInstanceMetadata")
- .addHeader("Accept", APPLICATION_JSON)
- .addHeader("Authorization", "Bearer " + TOKEN)
- .payload(payloadFromResourceWithContentType("/metadata.json", APPLICATION_JSON))
- .build();
-
- HttpResponse setMetadataResponse = HttpResponse.builder().statusCode(200)
- .payload(payloadFromResource("/global_operation.json")).build();
-
- ProjectApi api = requestsSendResponses(requestForScopes(COMPUTE_SCOPE), TOKEN_RESPONSE, setMetadata,
- setMetadataResponse).project();
-
- Metadata expected = new ParseMetadataTest().expected();
- assertEquals(api.setCommonInstanceMetadata(expected), new ParseGlobalOperationTest().expected());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/fff69b6c/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
index 8aeb7de..e4e9038 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiLiveTest.java
@@ -22,6 +22,8 @@ import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import org.jclouds.googlecomputeengine.domain.Metadata;
+import org.jclouds.googlecomputeengine.domain.Operation;
+import org.jclouds.googlecomputeengine.domain.Operation.Status;
import org.jclouds.googlecomputeengine.domain.Project;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiLiveTest;
import org.testng.annotations.Test;
@@ -66,4 +68,15 @@ public class ProjectApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
assertEquals(project.commonInstanceMetadata().size(), initialMetadataSize);
assertEquals(project.commonInstanceMetadata().fingerprint(), initialFingerprint);
}
+
+ @Test(groups = "live", dependsOnMethods = "getProject")
+ public void testSetUsageExportBucket() {
+ Operation o = api.project().setUsageExportBucket("test-bucket", "test-");
+
+ while (o.status() == Status.PENDING) {
+ o = api.operations().get(o.selfLink());
+ }
+ assertEquals(o.error().errors().get(0).code(), "PERMISSIONS_ERROR");
+ assertEquals(o.error().errors().get(0).message(), "Required 'owner' permission for 'test-bucket'");
+ }
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/fff69b6c/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiMockTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiMockTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiMockTest.java
new file mode 100644
index 0000000..b9142e2
--- /dev/null
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/ProjectApiMockTest.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.googlecomputeengine.features;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNull;
+
+import org.jclouds.googlecomputeengine.domain.Metadata;
+import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineApiMockTest;
+import org.jclouds.googlecomputeengine.parse.ParseGlobalOperationTest;
+import org.jclouds.googlecomputeengine.parse.ParseMetadataTest;
+import org.jclouds.googlecomputeengine.parse.ParseProjectTest;
+import org.testng.annotations.Test;
+
+@Test(groups = "unit", testName = "ProjectApiMockTest", singleThreaded = true)
+public class ProjectApiMockTest extends BaseGoogleComputeEngineApiMockTest {
+
+ public void get() throws Exception {
+ server.enqueue(jsonResponse("/project.json"));
+
+ assertEquals(projectApi().get(), new ParseProjectTest().expected(url("/projects")));
+
+ assertSent(server, "GET", "/projects/party");
+ }
+
+ public void get_4xx() throws Exception {
+ server.enqueue(response404());
+
+ assertNull(projectApi().get());
+
+ assertSent(server, "GET", "/projects/party");
+ }
+
+ public void setCommonInstanceMetadata() throws Exception {
+ server.enqueue(jsonResponse("/global_operation.json"));
+
+ Metadata expected = new ParseMetadataTest().expected();
+ assertEquals(projectApi().setCommonInstanceMetadata(expected), new ParseGlobalOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/setCommonInstanceMetadata",
+ stringFromResource("/metadata.json"));
+ }
+
+ public void setUsageExportBucket() throws Exception {
+ server.enqueue(jsonResponse("/global_operation.json"));
+
+ assertEquals(projectApi().setUsageExportBucket("bucket-name", "report-name-prefix"),
+ new ParseGlobalOperationTest().expected(url("/projects")));
+
+ assertSent(server, "POST", "/projects/party/setUsageExportBucket",
+ "{\"bucketName\": \"bucket-name\",\"reportNamePrefix\": \"report-name-prefix\"}");
+ }
+
+ ProjectApi projectApi() {
+ return api().project();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/fff69b6c/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
index b61c840..8378b22 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/internal/BaseGoogleComputeEngineApiLiveTest.java
@@ -63,11 +63,6 @@ public class BaseGoogleComputeEngineApiLiveTest extends BaseApiLiveTest<GoogleCo
protected Predicate<AtomicReference<Operation>> operationDone;
protected URI projectUrl;
- protected Supplier<String> userProject;
- protected Predicate<AtomicReference<Operation>> globalOperationDonePredicate;
- protected Predicate<AtomicReference<Operation>> regionOperationDonePredicate;
- protected Predicate<AtomicReference<Operation>> zoneOperationDonePredicate;
-
public BaseGoogleComputeEngineApiLiveTest() {
provider = "google-compute-engine";
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/fff69b6c/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java
index a3dffdc..fcc3e00 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java
@@ -22,9 +22,11 @@ import java.net.URI;
import javax.ws.rs.Consumes;
+import org.jclouds.date.internal.SimpleDateFormatDateService;
import org.jclouds.googlecomputeengine.domain.Metadata;
import org.jclouds.googlecomputeengine.domain.Project;
import org.jclouds.googlecomputeengine.domain.Quota;
+import org.jclouds.googlecomputeengine.domain.Project.UsageExportLocation;
import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest;
import org.testng.annotations.Test;
@@ -40,9 +42,14 @@ public class ParseProjectTest extends BaseGoogleComputeEngineParseTest<Project>
@Override @Consumes(APPLICATION_JSON)
public Project expected() {
+ return expected(BASE_URL);
+ }
+
+ @Consumes(APPLICATION_JSON)
+ public Project expected(String baseUrl) {
return Project.create( //
"13024414184846275913", // id
- URI.create(BASE_URL + "/761326798069"), // selfLink
+ URI.create(baseUrl + "/761326798069"), // selfLink
"party", // name
"", // description
Metadata.create("efgh").put("propA", "valueA").put("propB", "valueB"), // commonInstanceMetadata
@@ -56,7 +63,9 @@ public class ParseProjectTest extends BaseGoogleComputeEngineParseTest<Project>
Quota.create("NETWORKS", 1, 5), //
Quota.create("FIREWALLS", 2, 100), //
Quota.create("IMAGES", 0, 100)), // quotas
- null // externalIpAddresses
+ null, // externalIpAddresses
+ new SimpleDateFormatDateService().iso8601DateParse("2012-10-24T20:13:16.252"), // creationTimestamp
+ UsageExportLocation.create("test-bucket", "report-prefix")// usageExportLocation
);
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/fff69b6c/google-compute-engine/src/test/resources/project.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/project.json b/google-compute-engine/src/test/resources/project.json
index 2cb56f0..24ac767 100644
--- a/google-compute-engine/src/test/resources/project.json
+++ b/google-compute-engine/src/test/resources/project.json
@@ -65,5 +65,9 @@
"usage": 0,
"limit": 100
}
- ]
+ ],
+ "usageExportLocation": {
+ "bucketName": "test-bucket",
+ "reportNamePrefix": "report-prefix"
+ }
}
\ No newline at end of file
[3/3] jclouds-labs-google git commit: Fixed InstanceApiLiveTest,
made Instance.status @Nullable
Posted by na...@apache.org.
Fixed InstanceApiLiveTest, made Instance.status @Nullable
Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/repo
Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/commit/0391f699
Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/tree/0391f699
Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/diff/0391f699
Branch: refs/heads/master
Commit: 0391f699e9c4a71b5b4625ab82af8cae99f472e2
Parents: fff69b6
Author: Daniel Broudy <br...@google.com>
Authored: Tue Jan 6 15:25:41 2015 -0800
Committer: Ignasi Barrera <na...@apache.org>
Committed: Fri Jan 9 23:19:33 2015 +0100
----------------------------------------------------------------------
.../java/org/jclouds/googlecomputeengine/domain/Instance.java | 2 +-
.../googlecomputeengine/features/InstanceApiLiveTest.java | 7 ++++++-
2 files changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/0391f699/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
index cdc2ee4..dcbc344 100644
--- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
+++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/domain/Instance.java
@@ -225,7 +225,7 @@ public abstract class Instance {
public abstract URI machineType();
- public abstract Status status();
+ @Nullable public abstract Status status();
/** Human-readable explanation of the status. */
@Nullable public abstract String statusMessage();
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/0391f699/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
index 9add978..1910282 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/features/InstanceApiLiveTest.java
@@ -126,9 +126,14 @@ public class InstanceApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
@Test(groups = "live", dependsOnMethods = "testInsertInstance")
public void testAddAccessConfig() {
+ Instance instance = api().get(INSTANCE_NAME);
+ assertNotNull(instance);
+ assertOperationDoneSuccessfully(api().deleteAccessConfigFromNic(INSTANCE_NAME,
+ instance.networkInterfaces().get(0).accessConfigs().get(0).name(), "nic0"));
+
AccessConfig config = AccessConfig.create("test-config", Type.ONE_TO_ONE_NAT, null);
assertOperationDoneSuccessfully(api().addAccessConfigToNic(INSTANCE_NAME, config, "nic0"));
- Instance instance = api().get(INSTANCE_NAME);
+ instance = api().get(INSTANCE_NAME);
assertNotNull(instance);
assertEquals(instance.networkInterfaces().get(0).accessConfigs().get(0).name(), "test-config");
}